Task Mechanics
In this first eCos example, we reuse the Blinking LED program that was covered previously. The first thing to learn is how to create a task. This example creates a task to handle the toggling of the LED at a constant rate. First, we declare the task-specific variables such as the stack and its size, the task priority, and OS-specific variables.
Tip
eCos uses the term thread instead of task in its API and variable types. These terms mean the same thing in the embedded systems context.
The example program provides two variables to eCos to allow it to
track the task. The variable ledTaskObj stores information about the task,
such as its current state; ledTaskHdl
is a unique value assigned to the task.
The stack for our task is statically declared as the array
ledTaskStack, which is 4,096 bytes in
size. An arbitrary priority of 12 is assigned for this task. The code
also defines the number of clock ticks per second, a value specific to
the Arcom board’s eCos setup. This makes it easy to change the tick
interval to tune system performance.
#define TICKS_PER_SECOND (100) #define LED_TASK_STACK_SIZE (4096) #define LED_TASK_PRIORITY (12) /* Declare the task variables. */ unsigned char ledTaskStack[LED_TASK_STACK_SIZE]; cyg_thread ledTaskObj; cyg_handle_t ledTaskHdl;
Next we show the code for performing the toggle. We have attempted
to reuse code from the original Blinking LED example. The ledInit and ledToggle LED driver functions remain
unchanged from the code described in