CooCox CoOS User's Guide
CooCox CoOS User's Guide
CooCox CoOS User's Guide
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
6.7 Semaphores<br />
6.7.1 CoCreateSem()<br />
Function Prototype:<br />
OS_EventID CoCreateSem(<br />
Descriptions:<br />
Create a semaphore.<br />
Parameters:<br />
[in] initCnt<br />
U16 initCnt,<br />
U16 maxCnt,<br />
U8 sortType<br />
);<br />
the initial volume of the effective number of semaphores<br />
[in] maxCnt<br />
The maximum value of the semaphore<br />
[in] sortType<br />
arrangement types:<br />
EVENT_SORT_TYPE_FIFO,<br />
EVENT_SORT_TYPE_PRIO,<br />
Returns:<br />
Semaphore ID, create successfully<br />
-1, create failed<br />
Example usage:<br />
#include "CCRTOS.h"<br />
OS_EventID semaphore;<br />
void TaskN (void *pdata)<br />
{<br />
}<br />
...<br />
/* Create a semaphore */<br />
FIFO order<br />
Preemptive Priority order<br />
semaphore = CoCreateSem (1, 10, EVENT_SORT_TYPE_FIFO);<br />
if (semaphore == E_CREATE_FAIL)<br />
{<br />
}<br />
else<br />
{<br />
}<br />
printf("Create semaphore failed !\n");<br />
printf("Semaphore ID : %d \n", semaphore);<br />
...<br />
80