OsHndlT OsNewRepeatingTimer( OsTicksT period, OsHndlT task, OsEventsT events );
Function OsNewRepeatingTimer() may be called by the client application to create a new repeating event timer. The first argument is the repeat period, in time ticks, at which the timer should fire. It is also the delay time to the first firing of the timer. The second argument is the task to which events should be sent each time the timer fires. The third argument is the pattern of events to be sent to the task. Any number of events may be set in this pattern. If no events are set, the timer will have no effect when it fires and is therefore useless.
The function returns a handle to the new repeating timer if it was created successfully. Unless the application needs the option to destroy the timer, there is no need to save this handle. If a new timer cannot be created, for example due to the exhaustion of timer resources, the function returns OsHndl_NONE.
The example below shows a section of a task function that uses a repeating timer to perform some operation 50 times at intervals of 200 time ticks. Event START_EVENT sets this in motion and causes the operation to be performed for the first time. A repeating timer is created which sends the event NEXT_EVENT to the task every 200 time ticks. When the task receives this event, it performs the operation for the next time. After 50 times, the timer is destroyed and activity ceases.
OsHndlT Timer;
if ( OsAcceptEvents( START_EVENT ) )
{
count = 1;
DoOperation( count );
Timer = OsNewRepeatingTimer( 200, MyTask, NEXT_EVENT );
}
else if ( OsAcceptEvents( NEXT_EVENT ) )
{
count += 1;
DoOperation( count );
if ( count >= 50 )
OsDestroyTimer( Timer );
}