The event flags that we saw in the last recipe can only been used to trigger the execution of tasks. In contrast to this, mailboxes support the exchange of program data between tasks. CMSIS-RTOS provides a mailbox system that buffers messages into mail slots and queues them between the sending and receiving tasks. This recipe, RTOS_Blinky_c8v1
, provides an introduction to sending fixed-length messages between tasks using mailboxes.
Clone the
RTOS_Blinky_c8v0
folder in the Multithreaded programs using event flags recipe that we described earlier.Replace
taskA( )
with the following function definition:void taskA (void const *argument) { uint32_t i=0; for (;;) { mail_t *mail = (mail_t*)osMailAlloc(mail_box, osWaitForever); mail->counter = i++; osMailPut(mail_box, mail); osDelay(1000); } }
Replace
taskB( )
with the following function definition:void taskB (void const *argument...