OsResultE OsSendEvents( OsHndlT task, OsEventsT events );
Function OsSendEvents() may be called by the client application to send a pattern of events to any task. The first function argument is the handle of the target task. The second argument is the pattern of events to be set in that task, that is the events to be made true. If the target task is not ready and therefore not scheduled for execution, the function evaluates readiness. If after setting the new events it is ready, ECROS adds the task to the execution queue appropriate to its priority. The function returns OsResult_SUCCESS (zero) if no problems are encountered. If the operation cannot be performed, it returns an error code (with a negative value). For example, if the supplied handle does not correspond to a defined task, the function returns OsResult_BAD_HANDLE.
The example below shows the general outline of a software sub-system that accepts data from outside and processes it in some way using an ECROS task. To properly encapsulate the sub-system, the task handle and the events it uses to trigger processing are not visible to clients and are declared static. Clients call an externally visible function InputData() to pass data to the sub-system. In this function, the data is copied to some internal buffer (details not shown) and the task is sent an event to ready it so that it can process the data. Because function InputData() is to be called from another task, it must use the ECROS API function OsSendEvents() to send the event. Using OsSetEvents() in this case would be an error as the events would be set in the task calling the function, not the task of the data processing sub-system.
static OsHndlT myTask = OsHndl_NONE;
static void myTaskFunc( OsEventsT events );
void InitMySubSystem( void )
{
myTask = OsNewTask( OsPrior_MEDIUM );
OsTaskBindFunction( myTask, myTaskFunc );
return;
}
void InputData( char * data )
{
/* ... copy data to buffer ... */
OsSendEvents( myTask, OS_EVENT_4 );
return;
}
static void myTaskFunc( OsEventsT events )
{
if ( events & OS_EVENT_4 )
/* ... process input data ... */
OsAcceptEvents( OS_EVENTS_ALL );
return;
}