Cooperative multitasking, Blocking delay timers – Wavetronix Click 500 (programmable controller) (CLK-500) - Developer Guide User Manual
Page 61
60
CHAPTER 6 • TIMERS AND CLOCKS
Note
By default, the interrupt timer is scheduled to fire about 90 times per second. How-
ever, this is not guaranteed because it is not the highest priority interrupt. The OS
has some higher priority interrupts that service other timers and serial direct memory
access transfers.
Cooperative Multitasking
While a single operating mode or task function is executing, it is actually possible to do
some multitasking. In other words, multiple processes can be accomplished at the same
time because of the powerful processor that runs the Click 500.
Using the interrupt timer is one way to accomplish cooperative multitasking. Another way
is to code multiple processes so that they execute based upon non-blocking timers, instead
of blocking delay timer routines. The section below explores the pros and cons of blocking
and non-blocking wait timers.
Blocking Delay Timers
Mode 2 in the code below uses the Click utility ClickUtilPause and ClickUtilCondition-
alPause functions. The ClickUtilPause function is used to provide a delay for a specified
number of milliseconds. The function will return as soon as the specified time has elapsed.
Similarly, the ClickUtilConditionalPause function will delay for a specified amount of time,
but will terminate early if a specified event occurs. The specified event function is called
continuously and an event will occur if the event function returns TRUE. In the code below,
the ClickBtnPressed event function is used so that the wait time will be preempted if the
push-button is pressed.
The pause functions provide a simple way to wait for something external to happen before
the main process continues executing. In the example below, these functions are used to
create a startup delay of several seconds. During the startup time, the red LEDs will be on
and the push-button cannot be used to start and stop the progress indications on the yellow
LED bank. Unfortunately, during the pause time, nothing else can be processed by the main
idle loop. In other words, the UpdateProgress function in this example is “blocked” from
executing until the wait time is reached.