OsResultE OsInit( void );
Function OsInit() must be called by the client application before any other API functions. In this function, ECROS performs internal initialization. The function returns OsResult_SUCCESS if initialization was successful. If a problem was encountered, the function returns a negative error code and the application should abort. It is not safe to continue to use ECROS if OsInit() fails.
The example below shows the initialization of a simple application. It has a single task that is readied at intervals of 25 ticks by a repeating timer using event 4. OsInit() is called as the first C language statement. It is assumed that the processing platform is ready to run on entry to main(). The returned result is tested for negative error codes before calling further ECROS API functions. This test can be read as "if the result of calling OsInit() is less than success, bail out, otherwise carry on." which helps to make the program self-documenting.
#include "ECROS.h"
int main( void )
{
if ( OsInit() < OsResult_SUCCESS )
{
return ( 1 );
}
else
{
OsHndlT task;
task = OsNewTask( OsPrior_MEDIUM );
OsTaskBindFunction( task, MyTask );
OsNewRepeatingTimer( 25, task, OS_EVENT_4 );
OsStart();
return ( 0 );
}
}