Example to use Separate Task to Execute a Command
Posted: 01 March 2008, 13:54 PM
Here is a simple example of how to use a separate task to perform some operation; in this case flip a I/O port bit to sound a buzzer (zero turns on the buzzer). If the buzzer is already on then no action is taken. The example shows how to wake up a sleeping task so that it can start the action right away and then control is passed back to the caller. At a later time the task asynchronously ends the action.
Here is some of the example output:The corresponding annotated timing diagram is shown below. Note that the various sleep periods in this example have been chosen to show how the program works rather than what might be used in reality. For example the buzzer may only be turned on for 250ms rather than 5 seconds. The task sleep time can be set to a very large value because it is woken up when needed by the SoundBuzzerNoWait() routine.
Here is some of the example output:
Code: Select all
0.1 Sleeping
2.1 Sleeping
4.1 Wakeup
4.1 Buzz
8.1 Already awake
9.1 Sleeping
11.1 Sleeping
12.1 Wakeup
12.1 Buzz
16.1 Already awake
17.1 Sleeping
19.1 Sleeping
20.1 Wakeup
20.1 Buzz