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.

Figure 1 ) Sleep Based Periodic Loop<br />

The SLEEP_10HZ constant used in this example is adjusted based on the expected system loading,<br />

including CPU dwell within the Activity_10Hz procedure. This would require some timing<br />

measurements to be made during the program's development.<br />

Precisely Periodic<br />

A precisely periodic loop can be controlled with an <strong>RTOS</strong> timer. This will result in a periodic loop<br />

which on average tracks the CPU quartz clock. A <strong>RTOS</strong> timer periodically wakes up the periodic task<br />

loop as illustrated below in Figure 2.<br />

static int TaskID_10Hz ;<br />

void huge Task_10Hz(void)<br />

{<br />

while (1) // 10 Hz loop<br />

{<br />

RTX_Sleep_Request () ;<br />

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

}<br />

}<br />

static void huge Timer_Callback(void) // Clean 10 Hz<br />

{<br />

RTX_Wakeup (TaskID_10Hz) ;<br />

}<br />

static TimerID ;<br />

static TimerProc_Structure Timer_Spec = {<br />

&TimerID,<br />

Timer_Callback,<br />

0,<br />

{ '1', '0', 'H', 'z'},<br />

100 // .interval = 100 milliseconds<br />

} ;<br />

void Initialize(void)<br />

{<br />

extern TaskDefBlock Task_10Hz_Def ;<br />

RTX_Create_Task (&TaskID_10Hz, &Task_10Hz_Def) ;<br />

RTX_Install_Timer (&Timer_Spec) ;<br />

RTX_Start_Timer (TimerID) ;<br />

}<br />

Figure 2 ) Timer Based Periodic Loop<br />

An alternative method here would be to use RTX_Suspend_Task in Task_10Hz and<br />

RTX_Resume_Task in Timer_Callback. However, the RTX_Wakeup has the advantage of a wakeup<br />

pending flag used in the implementation which covers for the case where, due to CPU loading, the<br />

Task_10Hz may not yet have reached the RTX_Sleep_Request call before the RTX_Wakeup is<br />

executed in the Timer_Callback. In this case when the RTX_Sleep_Request is later called in<br />

Task_10Hz, the API will return immediately after clearing the task's internal wakeup pending flag,<br />

which had been set when Timer_Callback called RTX_Wakeup before Task_10Hz reached its sleep.<br />

Page 225 / 400

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

Saved successfully!

Ooh no, something went wrong!