Simple Sleep Task / Blinking LED

This is a simple task that blinks an LED:

 

void task1(unsigned arg0)

      {

      … // setup LED

      while (1)

            {

            LED_On();

            REXIS_TaskSleepMilliSecs(700);

            LED_Off();

            REXIS_ TaskSleepMilliSecs(300);

            }

      }

 

Typically, a REXIS task function runs a forever loop. If a task function ever returns, the task “dies”, and its resources will be reclaimed by REXIS.

 

In this example, the task turns on an LED, sleeps for 700 milliseconds, turns off the LED, sleeps for 300 milliseconds, and then repeats forever. When run, the LED will blink on and off according to the defined schedule. In this example, as there is only one task, the entirety can also be written without REXIS and the code will look pretty much the same.

 

The key takeaway is that a task is simply a function running a forever loop. Nothing else other than a call to the REXIS_TaskCreate function is needed to make a function into a task. A task function can do anything that a normal C function can do without limitation. Unlike some scheduling models (e.g. cooperative multitasking), there is no need for a task function to cause scheduling to happen – it just does.