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.

Parameters:<br />

[in] muterID<br />

the designated mutex section ID<br />

Returns:<br />

E_CALL, be called in the interrupt service program<br />

E_INVALID_ID, the mutex section ID that was incomed is invalid<br />

E_OK,<br />

enter the mutex section successfully<br />

Example usage:<br />

#include "CCRTOS.h"<br />

OS_MutexID mutex;<br />

void TaskN (void *pdata)<br />

{<br />

...<br />

/* Create a mutex */<br />

mutex = CoCreateMutex ();<br />

/* Enter critical region */<br />

CoEnterMutexSection(mutex);<br />

…<br />

/*Process here */<br />

…<br />

/* Exit critical region */<br />

CoLeaveMutexSection(mutex);<br />

...<br />

}<br />

Note:<br />

1) If high-priority task A attempts to enter the mutex region,the system will<br />

promote the priority of task B which has entered the mutex region<br />

currently to the same level of task A, and change task A’ state to the<br />

waiting state (TASK_WAITING),then do a task scheduling so that the<br />

task B which has entered the mutex region could leave the mutex region<br />

as soon as possible. Task B’ s priority will be back to the original priority.<br />

2)This function can not be used in interrupt service routine.<br />

3)It should be used in pairs with Co LeaveMutexSection().<br />

6.6.3 CoLeaveMutexSection()<br />

Function Prototype:<br />

StatusType CoLeaveMutexSection(<br />

OS_MutexID mutexID<br />

);<br />

Descriptions:<br />

Leave the mutex section whose ID was designated.<br />

Parameters:<br />

78

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

Saved successfully!

Ooh no, something went wrong!