OsEventsT OsSetEvents( OsEventsT events );
Function OsSetEvents() may be called by the client application to set a pattern of events in the task that is running now. A task should use this function to send events to itself. The function argument is the pattern of events to be set (made true). This is combined with the currently running task's existing event pattern using a logical OR operation and replaces that event pattern. The function returns the new event pattern. This return value may be discarded. The function can not fail.
The example below shows part of a task that processes some input data, buffers it and passes it to an output of some sort. Input data is processed when both events ENABLE_INPUT and DO_INPUT are set. Note that since these are defined to be events 0 and 1, the standard ready condition means that the task will not run until they are both set (unless readied by other events for other purposes). If processing this input results in buffered data, the task sets its own event DO_OUTPUT. This will make the task ready if ENABLE_OUTPUT is also set and the task then (when subsequently run) passes the buffered data to the output. A similar mechanism sets ENABLE_INPUT when the data buffer is not full.
#define ENABLE_INPUT OS_EVENT_0
#define DO_INPUT OS_EVENT_1
#define ENABLE_OUTPUT OS_EVENT_2
#define DO_OUTPUT OS_EVENT_3
if ( OsAllEvents( ENABLE_INPUT | DO_INPUT ) )
{
/* ... process input ... */
if ( bufferCount > 0 )
OsSetEvents( DO_OUTPUT );
OsAcceptEvents( ENABLE_INPUT | DO_INPUT );
}
else if ( OsAllEvents( ENABLE_OUTPUT | DO_OUTPUT ) )
{
/* ... pass data to output ... */
if ( bufferCount < BUFFER_SIZE )
OsSetEvents( ENABLE_INPUT );
OsAcceptEvents( ENABLE_OUTPUT | DO_OUTPUT );
}