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.

2 Task Management<br />

2.1 Task<br />

During OS-based application development, an application is usually<br />

seperated into a number of tasks. In <strong>CooCox</strong> <strong>CoOS</strong>, a task is a C function whose<br />

inside is a infinite loop, it also has the return values and parameters. However,<br />

since a task will never return, the returned type must be defined as void. Code<br />

1 shows a typical task structure.<br />

Code 1 An infinite loop task<br />

void myTask (void* pdata)<br />

{<br />

for(;;)<br />

{<br />

}<br />

}<br />

Which is different from the C function, the quit of a task is achieved by<br />

calling system API function. Once you quit the task only through the ending of<br />

the code execution, the system would breakdown.<br />

You can delete a task by calling CoExitTask () or CoDelTask (taskID) in<br />

<strong>CooCox</strong> <strong>CoOS</strong>. CoExitTask () is called to delete the current running task while<br />

CoDelTask (taskID) to delete others. If the incoming parameter is the current<br />

task ID, CoDelTask (taskID) can also delete the current task. The concrete use<br />

is shown in Code 2.<br />

Code 2 Deleting a task<br />

void myTask0 (void* pdata)<br />

{<br />

CoExitTask();<br />

}<br />

void myTask1 (void* pdata)<br />

{<br />

CoDelTask(taskID);<br />

}<br />

9

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

Saved successfully!

Ooh no, something went wrong!