OsResultE OsDestroyTimer( OsHndlT timer );
Function OsDestroyTimer() may be called by the client application to destroy a timer of any type. The argument is the timer's handle, obtained when the timer was created. The function returns OsResult_SUCCESS if the timer was found in the active timer list and successfully destroyed. If the timer was not found, the function returns a negative error code. In some cases, this is not actually an error as the timer may have expired. Destroying a timer prevents it from firing and returns the timer resource to ECROS for reuse.
The example below shows a section of a task function that uses a timer to set a timeout on some process (which is not detailed in the example) When the task receives event DONE_EVENT, indicating that the process is done, the timer is no longer needed. An attempt is made to accept the event the timer sends to the task. If this returns non-zero (the event was set), the timer fired and has been automatically destroyed by ECROS. The timeout event has now been cleared. If it returns zero (the event was not set), the timer is explicitly destroyed using the timer handle saved when it was created.
if ( OsAcceptEvents( START_EVENT ) )
{
StartMyProcess();
TimeoutTimer = OsNewTimer( 100, MyTask, TIMEOUT_EVENT );
}
else if ( OsAcceptEvents( DONE_EVENT ) )
{
if ( !OsAcceptEvents( TIMEOUT_EVENT ) )
OsDestroyTimer( TimeoutTimer );
GetMyProcessResults();
}
else if ( OsAcceptEvents( TIMEOUT_EVENT ) )
{
AbortMyProcess();
}