[En-Nut-Discussion] Message Que

Ayman Hendawy ayman.hendawy at gmail.com
Wed Jan 18 09:01:53 CET 2012


Dear Nathan,

I think you mean that I created the threads after creating the msg que, any
way now I created the msg que after creating  the threads, I didn't notice
any change, by some way I managed to successfully send the msg and this msg
received by the other thread, the problem is that the thread which receive
the msg, goes to sleep then I found that the system hung up, stop running
and never return to the other threads even not return to main thread, find
below my code,
kindly notice my comments below on the code,

#include "MCU.h"


NUTMSGQ * MsgQDSUCCU = NULL;     //if I didn't initialize the Que, there
will be always an error that the que is full.


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\n");
 /************************************************************************/

MsgQDSUCCU =  NutMsgQCreate(256);
 if(MsgQDSUCCU)
{
 puts("Msg created successfully\n");
 }
 else
 {
puts("Error msg create\n");
 }

 NutThreadCreate("DSU", DSU, NULL, 512);
 NutThreadCreate("CCU", CCU, NULL, 512);
 for (;;)
{
 puts("Main sleep\n");
NutSleep(1000);
 }
  return (0);
}



THREAD(CCU, arg)
{
char statccu = 0;
 NUTMSG *MsgDDSUCCU = 0;
 NutThreadSetPriority(CCUPri);
 while (1)
{
 puts("CCU start\n");
 if(!(NutMsgQGetMessage(&MsgQDSUCCU, &MsgDDSUCCU, 1 )))
{
 //DDSUCCU =*((char*)MsgDDSUCCU->data);
puts("CCU received a message from DSU");
 //puts("Message");
puts("\n");
  statccu = NutMsgQFull(&MsgQDSUCCU);
 if(statccu == -1)
{
 puts("msg Q is full\n");
}
 else
{
 puts("msg empty\n");
}
 NutMsgQFlush(&MsgQDSUCCU);
 }
 puts("CCU leave\n");
 NutSleep(1000);
}


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



THREAD(DSU, arg)
{
char counter = 0;
 char * MsgDDSUCCU;
char stat = 0;
 NutThreadSetPriority(DSUPri);
 while(1)
{
puts("DSU start\n");

counter ++;
  if (counter == 5)
 {
counter = 0;
  NutMsgQFlush(&MsgQDSUCCU);
 stat = NutMsgQFull(&MsgQDSUCCU);
 if(stat == -1)
{
 puts("msg Q is full\n");
}
 else
puts("msg empty\n");
  if(!(NutMsgQSend(&MsgQDSUCCU , 1, 1, &MsgDDSUCCU)))    // it supposed
that this thread yield after executing this line, but this never happen, it
continue executing till it sleep.
 {
puts("DSU successfully sent \n");
 }
 else
 {
puts("Error DSU sending\n");
 }
counter = 0;
  }
   puts("DSU leave\n");
  NutSleep(1000);
 }


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

}





 Thanks

On Sun, Jan 15, 2012 at 6:53 PM, Nathan Moore <nategoose at gmail.com> wrote:

> One error is that you are creating the threads after you create the message
> queue, which presents the opportunity for the threads to try to use a
> garbage or null value for the queue handle/pointer.
>
> Nathan
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
>



-- 
Best regards

Ayman Hendawy
Embedded system engineer

Cairo,Egypt

Phone: +20110406659



More information about the En-Nut-Discussion mailing list