_lwmsgq_receive check for message

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

_lwmsgq_receive check for message

Jump to solution
1,741 Views
barbercolman
Contributor III

I am new to using MQX and its documentation. The _lwmsgq_receive function in the reference manual, has a LWMSGQ_RECEIVE_BLOCK_ON_EMPTY with an error code of LWMSGQ_EMPTY. However, a block task never returns. How do I check to see if there is an message?

 

I have been looking at the MQX reference guide, the users guide and the guide. Like I said I am new at this but where is the documentation? I am thinking there should be a documented way to find the number of messages or the status and I have not found it YET. Hope springs eternal!

 

Thanks

 

1 Solution
483 Views
DavidS
NXP Employee
NXP Employee

Hi Barber,

I've taken the default FSLMQX/mqx/examples/lwmsgq project and modified it to operate in several ways by changine #if / #elif statements.

1)_lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_TIMEOUT_FOR, 0, 0);    //blocks while waiting for message...default code

2)_lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 1, &ticks);   //blocks only 1 tick duration waiting for message

3) if (!LWMSGQ_IS_EMPTY(server_queue)){     //checks for message in queue

 

Server.c snippet:

   while (TRUE) {
#if 1 //DES test code
     if (!LWMSGQ_IS_EMPTY(server_queue)){     //checks for message in queue
       printf("Queue has message....go get it... ");
      _lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_TIMEOUT_FOR, 0, 0);
      printf(" %c \n", msg[0]);
      _lwmsgq_send((pointer)client_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
     }
     else {
      printf("\t\t***NO MESSAGE IN QUEUE***\n");
      _time_delay_ticks(1);     //DES block to give other task(s) chance to run
     }

#elif 0     //DES test code
      result = _lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 1, &ticks);   //blocks only 1 tick duration waiting for message
      if(result == MQX_OK){
        printf(" %c \n", msg[0]);
        _lwmsgq_send((pointer)client_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
      }
      else if(result == LWMSGQ_TIMEOUT){
        printf("LWMSGQ_TIMEOUT\n");
      }
      else{
        printf("error=0x%08X\n", result);
      }
     
#else     //DES default code
      _lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_TIMEOUT_FOR, 0, 0);    //blocks while waiting for message
      printf(" %c \n", msg[0]);
      _lwmsgq_send((pointer)client_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
     
#endif     
   }

 

 

Client.c snippet:

      _time_delay_ticks(5);
//DES      _time_delay_ticks(1);

 

I tried attaching the files but system wasn't letting me do that :smileysad:

 

Hope this helps.

Regards,

David

View solution in original post

3 Replies
484 Views
DavidS
NXP Employee
NXP Employee

Hi Barber,

I've taken the default FSLMQX/mqx/examples/lwmsgq project and modified it to operate in several ways by changine #if / #elif statements.

1)_lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_TIMEOUT_FOR, 0, 0);    //blocks while waiting for message...default code

2)_lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 1, &ticks);   //blocks only 1 tick duration waiting for message

3) if (!LWMSGQ_IS_EMPTY(server_queue)){     //checks for message in queue

 

Server.c snippet:

   while (TRUE) {
#if 1 //DES test code
     if (!LWMSGQ_IS_EMPTY(server_queue)){     //checks for message in queue
       printf("Queue has message....go get it... ");
      _lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_TIMEOUT_FOR, 0, 0);
      printf(" %c \n", msg[0]);
      _lwmsgq_send((pointer)client_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
     }
     else {
      printf("\t\t***NO MESSAGE IN QUEUE***\n");
      _time_delay_ticks(1);     //DES block to give other task(s) chance to run
     }

#elif 0     //DES test code
      result = _lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 1, &ticks);   //blocks only 1 tick duration waiting for message
      if(result == MQX_OK){
        printf(" %c \n", msg[0]);
        _lwmsgq_send((pointer)client_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
      }
      else if(result == LWMSGQ_TIMEOUT){
        printf("LWMSGQ_TIMEOUT\n");
      }
      else{
        printf("error=0x%08X\n", result);
      }
     
#else     //DES default code
      _lwmsgq_receive((pointer)server_queue, msg, LWMSGQ_TIMEOUT_FOR, 0, 0);    //blocks while waiting for message
      printf(" %c \n", msg[0]);
      _lwmsgq_send((pointer)client_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
     
#endif     
   }

 

 

Client.c snippet:

      _time_delay_ticks(5);
//DES      _time_delay_ticks(1);

 

I tried attaching the files but system wasn't letting me do that :smileysad:

 

Hope this helps.

Regards,

David

483 Views
barbercolman
Contributor III

Thanks for the help. I am still learning where to find documentation on the MQX functions. It appears there a lot of information in the header files that is not included in the MQX manual.  I never did find LWMSGQ_IS_EMPTY in the MQX documentation. Is this typical for all the MQX functions or specific to the the light weight message functions?

 

Again thanks

0 Kudos
483 Views
DavidS
NXP Employee
NXP Employee

Hi Barber,

Yes to the question that not every function or macro call is fully documented.  The doc's to a good high level of implementation, understanding, and advice for porting but one must roll-up the shirt sleeves and review code to find answers to questions not in the documentation.

I often start by using one of the FSLMQX/mqx/examples projects then look at headers and/or do searches on keywords.  That is the path I took for creating the lwmsgq example.

As time passes we/Freescale will keep adding to the documentation to improve.  Sorry for any hassles.

Regards,

David

0 Kudos