AMX Event Manager
K
A
DAK
107
7.3 Event Flag ApplicationThe following example, coded in C, is provided to illustrate the use of the AMX Event
Manager for event synchronization.
The example shows two tasks, A and B, which must be synchronized to the state of a
motor. Task A must wait for the motor to be turned on. Task B must wait for the motor
to be on and up to its maximum speed.
A 100 millisecond interval timer samples a motor control status register to determine the
state of the motor. Whenever the motor state changes, the Timer Procedure signals the
event. Note that the Timer Procedure signals both the on/off state and the motor speed
simultaneously. It only signals changes in the motor state so that event synchronization
overhead is minimized.
Note that the Timer Procedure receives its timer's id timerid and a parameter unused,
neither of which is used by the procedure.
A Restart Procedure allocates an event group for motor control. Two of the event flags in
the group are initialized to reflect the state of the motor at the time the system was
started. The remaining event flags in the group are unused. A 100 millisecond periodic
interval timer is created and started.
The creation and starting of Tasks A and B is outside the scope of this example. It is
assumed that if the Restart Procedure is unable to create an event group for motor control,
Tasks A and B will not be started. In our example, Tasks A and B assume that a valid
event group id has been provided in variable motorgroup.
Note that bit 0 of the motor control status register determines if the motor is on or off.
Bit 1 of the motor control status register determines if the motor is at maximum speed.
For convenience, event flags 0 and 1 (bits 0 and 1 in the event group) are assigned to
mirror the corresponding bits in the motor control status register.