From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115102 invoked by alias); 27 May 2016 13:29:47 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 114947 invoked by uid 89); 27 May 2016 13:29:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.2 required=5.0 tests=AWL,BAYES_05,RDNS_DYNAMIC,TVD_RCVD_IP autolearn=no version=3.3.2 spammy=indicating, H*r:sk:exchang, H*RU:sk:exchang, HX-HELO:sk:exchang X-HELO: exchange.hsv.pesa.com Received: from 67-63-150-35.arpa.kmcmail.net (HELO exchange.hsv.pesa.com) (67.63.150.35) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 May 2016 13:29:44 +0000 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Fri, 27 May 2016 13:29:00 -0000 Message-ID: <07FFDDED6CBCCE4E9FBD46AEC3EBFD4F02C50652@exchange> From: "Michael W. Ellis" To: X-IsSubscribed: yes Subject: [ECOS] cyg_flag_timed_wait doesn't seem to work as expected X-SW-Source: 2016-05/txt/msg00000.txt.bz2 I'm running an old version of eCos (2.0.98) from eCosCentric and I'm attemp= ting to use cyg_flag_timed_wait to periodically update a display (see code,= below).=A0 My event flag variable g_flags is initialized elsewhere before = this thread is created.=A0 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.=A0 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.=A0 The local= variable flags always reads 0, indicating timeout has occurred.=A0 My unde= rstanding is that calling cyg_flag_timed_wait at the top of the loop restar= ts the timer, but this does not seem to be the case.=A0 What am I missing h= ere?=A0 Is there something I must do to clear the timeout event? Variable allocation and initialization: static cyg_flag_t g_flags;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 // thread sync event flags cyg_flag_init(&g_flags);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 // init thread sync flag // ogDisplayThread - update display static void ogDisplayThread(cyg_addrword_t data) { =A0=A0=A0 diag_printf("Entering ogDisplayThread...\r\n"); =A0=A0=A0 cyg_flag_setbits(&g_flags, OG_FLAG_DISP_RDY);=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0// say this thread is ready =A0=A0=A0 while (1) =A0=A0=A0 { =A0=A0=A0=A0=A0=A0=A0 cyg_flag_value_t flags; =A0=A0=A0=A0=A0=A0=A0 flags =3D cyg_flag_timed_wait(&g_flags,=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0// timed= wait =A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0OG_FLAG_DISP_EXIT,=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 // wait for EXIT flag or timeout =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 CYG_FLAG_WAITMODE_AND, =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 3000);=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0// 30 second timeout =A0=A0=A0=A0=A0=A0=A0 diag_printf("ogDisplayThread flag =3D %08X\r\n", flag= s); =A0=A0=A0=A0=A0=A0=A0 if (flags & OG_FLAG_DISP_EXIT)=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0 // if EXIT event occurred =A0=A0=A0=A0=A0=A0=A0 { =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 diag_printf("Exiting ogDisplayThread\r\n"= ); =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cyg_flag_maskbits(&g_flags,=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0// say this thread is no longer ready =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 OG_FLAG_DISP_RDY|= OG_FLAG_DISP_EXIT); =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cyg_thread_exit();=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0 // and exit thread =A0=A0=A0=A0=A0=A0=A0 } =A0=A0=A0=A0=A0=A0=A0 else if (!flags)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // if timeout occurred (normal condition) =A0=A0=A0=A0=A0=A0=A0 { =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 diag_printf("ogDisplayThread sending data= \r\n"); =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ogp_msg_t *msg; =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // send IP address =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (NULL =3D=3D (msg =3D malloc(sizeof(og= p_msg_t))))=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // allocate a message buffer =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0diag_printf("ogDisplayThread = malloc error\r\n"); =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 { =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 msg->sync =3D htonl(OGP_SYNC_= WORD);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // bu= ild message =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0msg->src =3D LOCAL_CMD_SRC; =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 msg->dst =3D LOCAL_CMD_DST_SE= T_IPADDR; =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 msg->mtype =3D LOCAL_CMD_MTYP= E; =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 api_eth_get_ip(msg->data, 16)= ;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /= / get IP address string =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 msg->len =3D htons(strlen(msg= ->data)+1);=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // set length =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ogpPutTxQ(msg);=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // send message =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 } =A0=A0=A0=A0=A0=A0=A0 } =A0=A0=A0=A0=A0=A0=A0 else =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0// should never get here =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 diag_printf("ogDisplayThread unexpected e= vent flag\r\n"); =A0=A0=A0 } } Debug output (continual after 30 seconds): ogDisplayThread flag =3D 00000000 ogDisplayThread sending data ogDisplayThread flag =3D 00000000 ogDisplayThread sending data ogDisplayThread flag =3D 00000000 ogDisplayThread sending data ogDisplayThread flag =3D 00000000 ogDisplayThread sending data ogDisplayThread flag =3D 00000000 ogDisplayThread sending data ogDisplayThread flag =3D 00000000 ogDisplayThread sending data ogDisplayThread flag =3D 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