Revision as of 15:59, 3 August 2022 by Registered User

1. Introduction

The integration cost of a real time operating system can be penalizing in the case of a simple application:

  • Required RTOS skill
  • Increase the complexity of the application
  • Impact on sizing of RAM/ROM

The sequencer utility has been designed as a simple alternative to real time OS use, for such simple application cases. However, it does not cover all the services provided by an operating system. For example, this software solution doesn’t provide preemption mechanism, this must be taken in account in the application design (Instead of tasks designed with a risk of freezing the system, we recommend using reentrant functions based on state machines). The following graphic shows how the sequencer handles the execution of an application. "Image to download"

  • Task creation: allow to initialize the task and render it callable by the internal scheduler of the sequencer.
  • Task enable: through a task or an interrupt, the task is enabled, and so could be executed by the scheduler.
  • Task Pause/Resume: allows to pause/Resume the task execution from scheduler point of view independent whether the task is enabled or not.
  • Idle Task: if the scheduler has not task to execute it call an optional hook function to manage entry in idle mode.
  • Task execution: call the function associated to the task, the scheduler is locked until function return.
  • Sequencer: embed a task scheduler which sequences the tasks execution and also allows the task to stop until an event reception

2. Important things to know

  1. The sequencer is NOT an operating system
  2. It does not intend to compete versus standard OS but versus standard bare metal implementation
  3. It is an optimized packaging of a while loop bare metal classic implementation
  4. It allows to avoid race conditions which are most of the time faced in bare metal implementation especially when low power mode are implemented

The sequencer provides the following features:

  • Up to 32 tasks registered
  • Request a task to be executed
  • Pause and Resume a task
  • Wait for a specific event (might be not blocking)
  • Priority on tasks

3. detailed implementation

The sequencer is a simple utility to manage tasks scheduling without embedding the complexity of an RTOS. This software runs with major concepts:

  • TASK: a simple function called by the sequencer
  • TAKS id: number between 0 and 31 (task coded on 32bit)
  • EVENT: event management to wake up a task
  • SCHEDULER: manager which order the tasks execution

3.1. Internal state of the sequencer

This section describes the usage of global variables within the sequencer.

TaskSet This variable is the list of the task executable by the sequencer.
Read by UTIL_SEQ_Run, UTIL_SEQ_IsScheduleableTask
Write by UTIL_SEQ_Init, UTIL_SEQ_SetTask, UTIL_SEQ_Run
Default Value UTIL_SEQ_NO_BIT_SET

3.2. Task life cycle

This figure represents how a task live during the application execution. File:task lfie cycle.JPG

  • IDLE: the task has been initialized and ready to run
  • RUNNING: the task has been inserted in the scheduler activity, and become running according to the scheduler rule.
  • WAIT: the task is stopped and a new scheduler instance is called to run the tasks, until the event reception.
  • PAUSE: the task is could be paused in the state IDLE or RUNNING, this feature could be used to delay a task treatment.

3.3. Event Management

The sequencer offers a feature to put a task waiting for an event, but this feature has consequences, it is important to understand the mechanism:

  1. A wait on an event will call a second instance of the scheduler, which will become recursive, the application will need to ensure the impact on its call stack sizing.
  2. When the scheduler is running and waiting for an event, it still allows entering stop mode except if the waited event is set.

Below there is an example of the stack execution when an event is waited

UTIL_SEQ_Run(~0U);              Sequencer running to schedule all the task       
--> Task_1                                  Process A running
----> UTIL_SEQ_WaitEvt(1);      Process A wait for an event 1
------> UTIL_SEQ_EvtIdle(1,1);  Sequencer task 1 is waiting for an event 1 
--------> UTIL_SEQ_Run(~1);     Run all the task except 1 which is waiting for an event

The SEQ_UTIL_EvtIdle() function provided inside the sequencer is restrictive because when a task is waiting for an event it can no longer be executed.

The application can rewrite this function according its needs and the sequencer allows all the cases. It is therefore possible that a pending task waiting for an event runs inside a sub scheduler. This use case is possible but not recommended so please use carefully the event feature.

3.4. Scheduler

The flowchart below shows the algorithm used by the function UTIL_SEQ_Run() to schedule the tasks execution. The goals of the scheduler are:

  • Ensure a good repartition of the task execution
  • Manage entry in the IDLE task

File:scheduler.jpg The “SuperMask” is used to prevent the re-activation of a task during the recursive call of UTIL_SEQ_Run(), otherwise the system could stay frozen or become incoherent.

(*) the system enters in the task execution state according two conditions:

  • a mask status (TaskSet & TaskMask & SuperMask) which indicates if a task shall run
  • an event waited (EvtSet & EvtWaited), used to exit the function UTIL_SEQ_Run() if a waited event is detected.

(**) the system used the same condition as (*) to control if we can enter the ILDE task, taking into account the actions of the interrupts.
(***) When a task has been executed, the task ID is removed from the round robin mask to avoid a second task call. This means that a task can be executing only the next call of the function UTIL_SEQ_Run().

4. API description

4.1. Initialization

4.2. Task creation

4.3. Task Enable

4.4. Task Pause/Resume

5. Example

5.1. LED toggling

The two MSC below present how to implement a simple LED toggle using the sequencer.

5.2. Show priority management

5.3. Show wait event