02.01.2015 Views

CooCox CoOS User's Guide

CooCox CoOS User's Guide

CooCox CoOS User's 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.

task code is as followings:<br />

void taskA (void* pdata)<br />

{<br />

/*!< Create a mutex for uart print */<br />

uart_mutex = CoCreateMutex ();<br />

if (uart_mutex == E_CREATE_FAIL)<br />

{ /*!< If failed to create, print message */<br />

printf (" Failed to create Mutex! \n\r");<br />

}<br />

/*!< Create two flags to communicate between taskA and taskB */<br />

a_flag = CoCreateFlag (TRUE,0);<br />

if (a_flag == E_CREATE_FAIL)<br />

{<br />

printf (" Failed to create the Flag! \n\r");<br />

}<br />

b_flag = CoCreateFlag (TRUE,0);<br />

if (b_flag == E_CREATE_FAIL)<br />

{<br />

printf (" Failed to create the Flag ! \n\r");<br />

}<br />

for (;;)<br />

{<br />

CoWaitForSingleFlag (a_flag,0);<br />

CoEnterMutexSection (uart_mutex);<br />

printf (" taskA is running \n\r");<br />

CoLeaveMutexSection (uart_mutex);<br />

}<br />

}<br />

taskB: taskB waits for b_flag to be set, print 'taskB is running' after activating,,<br />

and then continue to wait for the flag, and the cycle repeats. task code is as<br />

followings:<br />

6

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

Saved successfully!

Ooh no, something went wrong!