This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
cyg_flag_timed_wait doesn't seem to work as expected
- From: "Michael W. Ellis" <mellis at pesa dot com>
- To: <ecos-discuss at ecos dot sourceware dot org>
- Date: Fri, 27 May 2016 08:30:46 -0500
- Subject: cyg_flag_timed_wait doesn't seem to work as expected
- Authentication-results: sourceware.org; auth=none
I'm running an old version of eCos (2.0.98) from eCosCentric and I'm attempting to use cyg_flag_timed_wait to periodically update a display (see code, below). My event flag variable g_flags is initialized elsewhere before this thread is created. Other threads access the same event flag but use their own bits within the flag.
My problem is with the timed wait behavior of the event flag. At startup I see an initial wait of 30 seconds before the first display update occurs, but the update occurs continually after the initial timeout. The local variable flags always reads 0, indicating timeout has occurred. My understanding is that calling cyg_flag_timed_wait at the top of the loop restarts the timer, but this does not seem to be the case. What am I missing here? Is there something I must do to clear the timeout event?
Variable allocation and initialization:
static cyg_flag_t g_flags; // thread sync event flags
cyg_flag_init(&g_flags); // init thread sync flag
// ogDisplayThread - update display
static void ogDisplayThread(cyg_addrword_t data)
{
diag_printf("Entering ogDisplayThread...\r\n");
cyg_flag_setbits(&g_flags, OG_FLAG_DISP_RDY); // say this thread is ready
while (1)
{
cyg_flag_value_t flags;
flags = cyg_flag_timed_wait(&g_flags, // timed wait
OG_FLAG_DISP_EXIT, // wait for EXIT flag or timeout
CYG_FLAG_WAITMODE_AND,
3000); // 30 second timeout
diag_printf("ogDisplayThread flag = %08X\r\n", flags);
if (flags & OG_FLAG_DISP_EXIT) // if EXIT event occurred
{
diag_printf("Exiting ogDisplayThread\r\n");
cyg_flag_maskbits(&g_flags, // say this thread is no longer ready
OG_FLAG_DISP_RDY|OG_FLAG_DISP_EXIT);
cyg_thread_exit(); // and exit thread
}
else if (!flags) // if timeout occurred (normal condition)
{
diag_printf("ogDisplayThread sending data\r\n");
ogp_msg_t *msg;
// send IP address
if (NULL == (msg = malloc(sizeof(ogp_msg_t)))) // allocate a message buffer
diag_printf("ogDisplayThread malloc error\r\n");
else
{
msg->sync = htonl(OGP_SYNC_WORD); // build message
msg->src = LOCAL_CMD_SRC;
msg->dst = LOCAL_CMD_DST_SET_IPADDR;
msg->mtype = LOCAL_CMD_MTYPE;
api_eth_get_ip(msg->data, 16); // get IP address string
msg->len = htons(strlen(msg->data)+1); // set length
ogpPutTxQ(msg); // send message
}
}
else // should never get here
diag_printf("ogDisplayThread unexpected event flag\r\n");
}
}
Debug output (continual after 30 seconds):
ogDisplayThread flag = 00000000
ogDisplayThread sending data
ogDisplayThread flag = 00000000
ogDisplayThread sending data
ogDisplayThread flag = 00000000
ogDisplayThread sending data
ogDisplayThread flag = 00000000
ogDisplayThread sending data
ogDisplayThread flag = 00000000
ogDisplayThread sending data
ogDisplayThread flag = 00000000
ogDisplayThread sending data
ogDisplayThread flag = 00000000
ogDisplayThread sending data
Thanks,
Michael
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss