Forum Discussion
Altera_Forum
Honored Contributor
20 years agoMessage boxes in eCos
Hi all, cyg_mbox_peek (), is always returning the count 1 less than the actual number of messages in the message box. When the message box is empty, then count is returned as 0. Why this is so?...
Altera_Forum
Honored Contributor
20 years agoHi,
Thanks Sepp for your suggestion. The program is giving correct results now, using cyg_mbox_tryget () instead of cyg_mbox_get (). But still I have one doubt. The reason that you had specified for cyg_mbox_get () is okay, but then using that concept cyg_mbox_peek () would always had returned the count as 0? With regards, Sanjay Sanjay, I am not using the function cyg_mbox_peek () so I have no idea. What I am doing is something like this and it works fine: sending thread: while(1) { ... // when a message should be sent: if(!cyg_mbox_timed_put(mbox_hdl,(void *)psMsg1,1000)) { psMsg1 = NULL; // Do something to resend the message } else { // wait for acknowledge ret = cyg_flag_wait(&FlgAckMsg,FLG_MBOX_ACK,CYG_FLAG_WAITMODE_AND | CYG_FLAG_WAITMODE_CLR); } ... } receiving thread: while(1) { ... // allways have a look if there is a new message pMsg= cyg_mbox_tryget(mbox_hdl); if(pMsg2 != NULL) { save message: // Saving the message data into a local struct acknowledge: cyg_flag_setbits(&FlgAckMsg,FLG_MBOX_ACK); work with received data: // Decoding the received message and do some action with it } ... } Regards, Sepp