Hi Henry,
For MQXLite, you can find examples in the following path:
CW MCU v10.x_install_path\MCU\CodeWarrior_Examples\Processor_Expert\MQXLite
For MQX, at the next path you can find sample codes that may help you. Freescale_MQX_4_0\mqx\examples
For example the mutex code is used to demonstrate how to use a mutex to synchronize two tasks. It creates a mutex and two tasks. Both tasks use STDOUT to print out messages. Each task will lock the mutex before printing and unlock it after printing to ensure that the outputs from tasks are not mixed together. In this code the main task first initializes the mutex with the following line:
_mutex_init(&print_mutex, &mutexattr)
Then the main task creates a print task with parameter sting1, and creates a second print task with parameter strings with the following line:
_task_create(0, PRINT_TASK, (uint_32)string1);
_task_create(0, PRINT_TASK, (uint_32)string2);
Then the main task blocks itself.
The two print tasks both use the STDOUT. If they used it in the same time, there would be conflicts, so a mutex is used to synchronize the two tasks.
Each print task will try to lock the mutex before printing the message; it will wait for the mutex as long as needed. Once the mutex is locked it prints the message and then unlocks the mutex so that the other task can lock it. This process is repeated indefinitely.
I hope this helps,
Regards
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------