11.07.2015 Views

CrossWorks for ARM User Guide

CrossWorks for ARM User Guide

CrossWorks for ARM User Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This example posts the integer 45 onto the message queue.if (ctl_message_queue_post(&m1, (void *)45, 1, ctl_get_current_time()+1000)== 0){// timeout occured}This example uses a timeout and tests the return result to see if the timeout occured.If you want to post a message and you dont want to block (e.g from an interrupt serviceroutine) you can use the ctl_message_queue_post_nb function.if (ctl_message_queue_post_nb(&m1, (void *)45)==0){// queue is full}This example tests the return result to see if the post failed.You can receive a message with an optional timeout using thectl_message_queue_receive function.void *msg;ctl_message_queue_receive(&m1, &msg, 0, 0);This example receives the oldest message in the message queue.if (ctl_message_queue_receive(&m1, &msg, 1, ctl_get_current_time()+1000) ==0){// timeout occured}This example uses a timeout and tests the return result to see if the timeout occured.If you want to receive a message and you dont want to block (e.g from an interruptservice routine) you can use the ctl_message_queue_receive_nb function.if (ctl_message_queue_receive_nb(&m1, &msg)==0){// queue is empty}ExampleThe following example illustrates usage of a message queue to implement theproducer-consumer problem.CTL_MESSAGE_QUEUE_t m1;void *queue[20];void task1(void){…ctl_message_queue_post(&m1,(void *)i, 0, 0);…}222 Chapter 21 Message queues

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!