The State-Event Executive

The State-Event Executive

The State-Event Executive is a co-operative scheduling system which can be adapted to run on any suitable microprocessor. It is particularly suited to microcontrollers where RAM and particularly stack space is very limited, and a deterministic real-time response is required.

The key feature that distinguishes this from other kernels is that all procedures must run to completion without calls to any ‘wait’ function to wait for an event or a time delay. This is the same as the normal practice used to design interrupt routines. It requires an object-orientated approach to design, in much the same way that modern Windows programs are designed, except that this system is much simpler, and the implementation is in C rather than C++.

The advantage of this approach is that it is very efficient in its use of the stack and RAM. Task ‘waiting’ mid-way through in order to allow processing by a lower priority task, would require a significantly more complex context switch. On microcontrollers with very small stacks, this would entail significant manipulation of the stack, which may involve the shifting of stack segments in memory, making pointers to local variables become invalid without warning (a source of latent or unpredictable bugs).

A further advantage is that all events are processed via a central point in the system, which makes for powerful tracing and debugging without the need to write special code.

The system is table-driven which makes event response times very short.

The executive revolves around event queues which exist at different priority levels. Processes post events which are then routed through the system and handled by the appropriate procedures which depend on the state machine to which that event belongs, and the state of that state machine.

Thus, in a system where all the event functions are relatively small, and the longest is of a predictable length, then time-critical functions can be performed deterministically without the need to resort to pre-emptive scheduling.

In a typical system, therefore, information is gathered in interrupt routines, and then processed at the appropriate priority by state-event processing routines. Note that it is possible to run a system completely without interrupts, though it usually preferable to have at least one timer interrupt routine for accurate scheduling of events.

There are multiple versions of the executive compiled with different combinations of compile options. The options are:

  • 8 or 16-bit events (define WORDQ to enable 16-bit events)
  • Constant or variable structure (define VCONST= for variable structure)
  • 8 or 16-bit control variables (define BIGAPP for 16-bit variables)
  • Down counting timer (define COUNTDOWN for down counting)
  • Data queues of greater than 255 bytes (define BIGDATA)