Download AVIX User Guide & Reference Guide
Transcript
AVIX User Guide & Reference Guide AVIX-RT How to control the value of flags Two parameters to the event group wait function avixEventGroup_Wait require special attention; these are the preClearMask and the postClearMask. These parameters allow for a very large degree of flexibility when using event groups. Parameter preClearMask specifies event flags that are cleared as the very first action of the wait function before doing anything else. Suppose a thread wants to wait for flag 0 to be set. The thread is not interested whether the flag is already set when executing the wait function. By specifying flag 0 in the preClearMask, whatever the value of this flag, it will be cleared as part of the function call and the thread will start waiting for the flag to become set again. Parameter postClearMask specifies event flags that are cleared once the wait condition is fulfilled. Suppose one thread periodically sets a flag for another thread to react on. In this case it is likely the waiting thread will clear the flag once it became set. Not doing so will result in a subsequent wait operation to continue immediately whether or not the generating thread set the flag again or not. This most likely is not desired and can be solved by the waiting thread to specify the flag in the postClearMask. When the wait function returns because the desired flags are set, before returning to the caller the flags identified by postClearMask are cleared. No relation exists between the values of preClearMask, postClearMask and the mask with the flags actually waited for. In one wait call it is possible to specify flag 0 to be cleared at the start of the function call, flag 1 to be the flag actually waiting for and once this flag is set and the wait function is ready, clear flag 2. Event flags can be used to represent an absolute condition or a transient condition, depending on the requirements of the application. When a flag is neither cleared through the preClearMask or the postClearMask, it will be controlled only by some other thread. An example of this is when a thread sets a flag when a temperature exceeds a certain value and clears the flag when the temperature drops below that value. In that case the semantics of the flag are ‘temperature above threshold’. In this case the value of the flag contains the desired information. These types of flags represent an absolute condition. When on the other hand a flag represents the occurrence of a user of the system pressing a button, it makes sense to clear the flag as part of the wait function using postClearMask. Would this not be done, the flag remains set and no new key pressed could be detected. These types of flag represent a transient condition. Note that whether an event group flag represents an absolute or a transient condition is entirely application dependant. ► AVIX event groups combined with the richness of controlling the value of event group flags offer the ultimate flexibility to solve any possible situation when the value of application parameters can be expressed in (a combination) of binary values. Event Groups and ISR’s Event flags in an event group can be changed directly from ISR’s For this purpose function avixEventGroup_ChangeFromISR exists. Do note that ISR’s should be as short as possible. Instead of directly changing event flags from an ISR, the ISR can enqueue a DIH where the flags are passed as the DIH parameter. The DIH will then call avixEventGroup_Change to change the desired event flags. Note the DIH uses the regular function and not the ‘…FromISR’ function. AVIX Product Version 5.0.0 - 56 -