[En-Nut-Discussion] Message Que

Ayman Hendawy ayman.hendawy at gmail.com
Wed Jan 11 15:15:24 CET 2012


Dear All,

I try to make a test simple code for the message que, but actually it's not
working and I don't know why, the code is as following:




#include "MCU.h"


NUTMSGQ * MsgQDSUCCU;  //define a message que

int main(void)
{

/************************************************************************/
/* Register UART and Set Baud rate                                      */
 /************************************************************************/
u_long baud = BaudRate; //Set the UART baud rate
  NutRegisterDevice(&DEV_DEBUG, 0, 0);
         freopen(DEV_DEBUG_NAME, "w", stdout);
         _ioctl(_fileno(stdout), UART_SETSPEED, &baud);

 puts("\nMCU Threads Test");
 /************************************************************************/
////Create two threads, one will send the msg and the other will receive it
 NutThreadCreate("CCU", CCU, NULL, 512);
NutThreadCreate("DSU", DSU, NULL, 512);
   MsgQDSUCCU =  NutMsgQCreate(512);  //create the msg that will be sent by
DSU Thread and received by CCU thread
  for (;;)
 {
NutSleep(1000);
}
  return (0);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///1st thread that will send the msg

#include "DSU.h"

extern MsgQDSUCCU;  //to be seen by that file which contain that thread

THREAD(DSU, arg)
{
char counter = 0;
 char *MsgDDSUCCU  = 0;

 NutThreadSetPriority(36);
 while(1)
{
 puts("DSU start\n");

counter ++;
  if (counter == 3)
 {
 counter = 0;
 if(!(NutMsgQPost(&MsgQDSUCCU , 1, 1, &MsgDDSUCCU)))
 {
puts("DSU successfully sent \n");
}
 else
puts("Error DSU sending\n");
  }
 NutSleep(1000);
 }
 for(;;)
NutSleep(1000);

}





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///2nd thread that will receive the msg

#include "CCU.h"
extern MsgQDSUCCU;


THREAD(CCU, arg)
{
NUTMSG *MsgDDSUCCU;
 NutThreadSetPriority(CCUPri);

while (1)
 {
puts("CCU start\n");
 if(!(NutMsgQGetMessage(MsgQDSUCCU, MsgDDSUCCU, 25 )))
{

puts("CCU received a message from DSU\n");
 }

 NutSleep(1000);
}
 for(;;)
NutSleep(1000);
 }




I always read form the serial port the following:

MCU Threads Test
CCU start
DSU start

CCU start
DSU start

CCU start
DSU start

Error DSU sending

I don't know why it always display Error DSU sending,
why sending the msg failed, any help will be appreciated

Thanks



-- 
Best regards

Ayman Hendawy
Embedded system engineer

Cairo,Egypt

Phone: +20110406659



More information about the En-Nut-Discussion mailing list