O'Reilly logo

Embedded Systems Architecture by Daniele Lacamera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cooperative scheduler

Different policies can be defined to alternate the execution of the tasks in the system. In the simplest case, the main functions of each task voluntarily suspend its execution, by invoking the schedule macro.

In this example implementation, two threads are defined. Both will turn on an LED and hold the CPU in a busy-loop for one second, then turn off the LED, and explicitly call the schedule() function to trigger a context switch:

void task_test0(void *arg){    uint32_t now = jiffies;    blue_led_on();    while(1) {        if ((jiffies - now) > 1000) {            blue_led_off();            schedule();            now = jiffies;            blue_led_on();        }    }}void task_test1(void *arg){    uint32_t now = jiffies;    red_led_on();    while(1) {        if ((jiffies - now) > 1000) { red_led_off(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required