Pumpkin, Inc.

Pumpkin User Forums

SB-22: Salvo: Timing Errors when Violating Timing Requirements

Service Bulletins -- outlining known problems and how to handle them -- are posted here.

SB-22: Salvo: Timing Errors when Violating Timing Requirements

Postby Salvo Tech Support » Wed Jan 07, 2004 11:33 am

Applies To

All Salvo distributions.

Description of Problem

Salvo's timer requires that OSSched() be called at least once every system tick. In normal situations, this is easily accomplished -- a typical Salvo application calls OSSched() hundreds of times per system tick (i.e. per call to OSTimer()).

In situations where context-switching is delayed by more than a single tick, e,g, when a tight loop requiring thousands of instruction cycles is embedded in a Salvo task, the timer's delay performance will degrade. Specifically, the number of ticks of delay will be reduced by the number of ticks (Salvo's "lost ticks") during which OSSched() was unable to run.

For example:

void TaskBlink( void )
static int16_t someTime;

for (;;)
while (someTime < 20000);

PORT ^= 0x01;

OS_Delay(20, TaskBlink1);

In TaskBlink(), the do-while loop consumes several system ticks during which a context switch (and therefore a call to OSSched()) cannot occur. As a result, the time between successive PORT bit togglings is 20 system ticks, not 20 ticks + time(do-while loop). The delay of 20 ticks is achieved because Salvo (as of v3.2) tracks "lost ticks" that occur when OSSched() does not follow successive calls to OSTimer().

NOTE: In a Salvo application that does not violate the timing rules (i.e. context switches always occur within a system tick, or time(between tasks's context switches) << system tick), this timing error will not occur.

NOTE: This timing error applies to all types of delays, including those used when waiting on an event with a timeout.

Suggested Workaround

In Salvo tasks that do violate the timing rules, there are two solutions available:

1. Call OS_Yield() before calling OS_Delay(). This allows Salvo's timing system to "catch up", and a subsequent delay will have the standard (minimal) timing error.

2. Use saturation addition with OSlostTicks when passing the delay parameter to OS_Delay(), e.g.(for 8-bit delays):

OS_Delay((unsigned char)20+OSlostTicks<20 ? 255 : 20+OSlostTicks);

Either of these solutions will result in the task delay lasting the specified number of system ticks (+/- standard error). Note that when using method 2 above, desired delays near the upper limit may be "clipped" when OSlostTicks is large.

Fixed In

It is likely that a future release will include a service for performing the saturation addition, e.g. OS_Delay(OSXyz(20));

Salvo Technical Support
Please request all tech support through the Forums.

Salvo Technical Support
Please request all tech support through the Forums.
Salvo Tech Support
Posts: 173
Joined: Sun Nov 19, 2000 12:00 am

Return to Service Bulletins

Who is online

Users browsing this forum: No registered users and 1 guest