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.

Example usage:<br />

#include "CCRTOS.h"<br />

OS_EventID semaphore;;<br />

void TaskN (void *pdata)<br />

{<br />

StatusType result;<br />

...<br />

/* Pend a semaphore, Time out: 20 */<br />

result = CoPendSem (semaphore, 20);<br />

if (result != E_OK)<br />

{<br />

if (result == E_INVALID_ID)<br />

{<br />

printf("Invalid event ID !\n");<br />

}<br />

else if (result == E_CALL)<br />

{<br />

printf("Error call in ISR !\n");<br />

}<br />

else if (result == E_TIMEOUT)<br />

{<br />

printf("Semaphore was not received within the specified timeout time !\n");<br />

}<br />

}<br />

else<br />

{<br />

…<br />

/* Process semaphore here */<br />

…<br />

}<br />

...<br />

}<br />

Note:<br />

1)This function runs a task sheduling while waiting and give the system<br />

execution time to the highest priority task.<br />

2)The number of the semaphore resources substract 1 after getting the<br />

resources successfully.<br />

3)The function cann’t be used in the interrupt service program.<br />

85

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

Saved successfully!

Ooh no, something went wrong!