01.06.2013 Views

IPC@CHIP Documentation - SC12 @CHIP-RTOS V1.10

IPC@CHIP Documentation - SC12 @CHIP-RTOS V1.10

IPC@CHIP Documentation - SC12 @CHIP-RTOS V1.10

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Time-Slicing<br />

For the tasks created within DOS programs by the user, a time-slicing feature is available. This feature is<br />

enabled for a specific task by specifying a non-zero number of milliseconds in the time_slice member of the<br />

TaskDefBlock structure passed to the RTX_Task_Create() or RTX_Task_Create_Without_Run() functions.<br />

A time-sliced task will be permitted to execute for time_slice milliseconds (RTI ticks) after which time it will<br />

be cycled to the end of the list of tasks at this task's user priority. (The task is not charged for ticks during<br />

which it was blocked, suspended or active-pending preempted by some higher priority task.) In the special<br />

case where it is the only active task at that user priority, it would then on time-out immediately be given<br />

another time_slice milliseconds execution time budget and allowed to continue execution. Otherwise one of<br />

the other active tasks pending execution at this same user priority will begin execution and the previously<br />

executing task whose time-slice expired will be cycled to the end of the priority queue in a round-robin<br />

fashion. Note that the next task to execute may or may not be configured for time_slice operation.<br />

The time-slice operation would apply primarily to fully independent tasks which do not pass any data<br />

between each other. Time-slicing can introduce chaos into a program which could execute more orderly<br />

using explicit yields (e.g. RTX_Sleep_Time API). The extra task switching due to time-slice operation can<br />

cause critical sections to appear where they otherwise would not if the task was permitted to execute up to<br />

where the program yields voluntarily.<br />

There may be times where time-slicing is the graceful design solution, but reliance on this technique raises<br />

the suspicion that the software design was not thought out thoroughly. Also keep in mind that any task with<br />

lower user priority than the time-sliced tasks will never be executed so long as any of the time-sliced tasks<br />

are active. During execution of a time-sliced task, there is a very slight additional load placed on the<br />

system's 1000 Hz RTI.<br />

Periodic Tasks<br />

Periodic tasks can be created in either of two ways, depending on how accurate the execution period is<br />

required to be for the respective application.<br />

Roughly Periodic<br />

The simplest form for a periodic task uses a RTX_Sleep_Time call within a loop as shown below in<br />

Figure 1. The period of this loop will not be exact, but would be close enough for many applications.<br />

#define SLEEP_10HZ (90) // Assuming 10 ms CPU load per 100 ms<br />

void huge Task_Roughly_10Hz(void)<br />

{<br />

while (1)<br />

{<br />

Activity_10Hz() ; // Get here about each 100 ms<br />

RTX_Sleep_Time(SLEEP_10HZ) ;<br />

}<br />

}<br />

Page 224 / 400

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

Saved successfully!

Ooh no, something went wrong!