Skip to Main Content
Programming Embedded Systems, 2nd Edition
book

Programming Embedded Systems, 2nd Edition

by Michael Barr, Anthony Massa
October 2006
Intermediate to advanced content levelIntermediate to advanced
336 pages
9h 13m
English
O'Reilly Media, Inc.
Content preview from Programming Embedded Systems, 2nd Edition

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming with STM32: Getting Started with the Nucleo Board and C/C++

Programming with STM32: Getting Started with the Nucleo Board and C/C++

Donald Norris

Publisher Resources

ISBN: 0596009836Supplemental ContentErrata Page