public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Richard Rauch" <rrauch@itrgmbh.de>
To: "'Michael W. Ellis'" <mellis@pesa.com>,
	<ecos-discuss@ecos.sourceware.org>
Subject: AW: [ECOS] cyg_flag_timed_wait doesn't seem to work as expected
Date: Fri, 27 May 2016 15:53:00 -0000	[thread overview]
Message-ID: <01fb01d1b82f$e61c8ee0$b255aca0$@itrgmbh.de> (raw)
In-Reply-To: <07FFDDED6CBCCE4E9FBD46AEC3EBFD4F02C50652@exchange>

Hi Michael,

do you initialize the flags somewhere with cyg_flag_init() ?
This initialisation needs to be made before the first access of the event
flag variable.

Best Regards
Richard
www.itrgmbh.com


> -----Ursprüngliche Nachricht-----
> Von: ecos-discuss-owner@ecos.sourceware.org [mailto:ecos-discuss-
> owner@ecos.sourceware.org] Im Auftrag von Michael W. Ellis
> Gesendet: Freitag, 27. Mai 2016 15:31
> An: ecos-discuss@ecos.sourceware.org
> Betreff: [ECOS] cyg_flag_timed_wait doesn't seem to work as expected
> 
> 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


  reply	other threads:[~2016-05-27 15:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 13:29 Michael W. Ellis
2016-05-27 15:53 ` Richard Rauch [this message]
2016-05-27 16:31 ` Nick Garnett
2016-05-27 20:46   ` Michael W. Ellis
2016-06-16 13:26 ` [ECOS] eCos Configuration Tool clewan and rebuild Michael W. Ellis
2016-06-16 17:09   ` [ECOS] " Grant Edwards
2016-06-16 21:18     ` Michael W. Ellis
2016-06-16 21:41       ` Grant Edwards
2016-06-16 23:05         ` Alex Schuilenburg
2016-06-17  4:05           ` AW: " Richard Rauch
2016-06-17 10:10             ` Alex Schuilenburg
2016-06-18 12:01               ` AW: " Richard Rauch
2016-06-18 13:20                 ` Alex Schuilenburg
2016-06-30 14:53         ` [ECOS] Input from debug console Michael W. Ellis
2016-06-30 16:01           ` Michael W. Ellis
2016-06-30 16:09             ` Evgeniy Dushistov
2016-06-30 17:52             ` [ECOS] " Grant Edwards

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='01fb01d1b82f$e61c8ee0$b255aca0$@itrgmbh.de' \
    --to=rrauch@itrgmbh.de \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=mellis@pesa.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).