DioneOS
Encyclopedia
DioneOS is multitasking preemptive
Preemption (computing)
In computing, preemption is the act of temporarily interrupting a task being carried out by a computer system, without requiring its cooperation, and with the intention of resuming the task at a later time. Such a change is known as a context switch...

, real-time operating system
Real-time operating system
A real-time operating system is an operating system intended to serve real-time application requests.A key characteristic of a RTOS is the level of its consistency concerning the amount of time it takes to accept and complete an application's task; the variability is jitter...

. The system is designed for Texas Instruments MSP430x
TI MSP430
The MSP430 is a mixed-signal microcontroller family from Texas Instruments. Built around a 16-bit CPU, the MSP430 is designed for low cost, and specifically, low power consumption embedded applications. The architecture dates from the 1990s and is reminiscent of the DEC PDP-11.-Applications:The...

 microcontrollers.

Target microcontroller platform has limited resources,
i.e. system clock frequency in tens of MHz and memories amount from tens to a few hundreds KB.
The system is adapted to such conditions by providing its compact and efficient image.
The efficiency term means here minimization of additional CPU
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

 load caused by the system usage. According to this definition, the system is more effective when it consumes less CPU time for execution of its internal parts (e.g. threads management).

The DioneOS system is intended for autonomic devices where user interface has limited functions. The core functionality provided by the system is an environment for building multitasking firmware by means of standard, well known concepts (e.g. semaphores, timers, etc.).
Because of the target domain of application, the system has not graphic user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

.

Memory Model

Texas Instruments company manufactures wide range of microcontrollers that use msp430 core. Depending on the version, the chip contains different amount of Flash memory
Flash memory
Flash memory is a non-volatile computer storage chip that can be electrically erased and reprogrammed. It was developed from EEPROM and must be erased in fairly large blocks before these can be rewritten with new data...

 and RAM
Random-access memory
Random access memory is a form of computer data storage. Today, it takes the form of integrated circuits that allow stored data to be accessed in any order with a worst case performance of constant time. Strictly speaking, modern types of DRAM are therefore not random access, as data is read in...

 (e.g. msp430f2201 has 1KB/128B correspondingly, but msp430f5438 - 256KB/16KB). When the size of the memory exceeds 64KB limit, 16 bits addressing is insufficient. Due to this constraint, chips with larger memory are equipped with extended core (msp430x). This version of the processor has wider registers (20 bits) and new instructions for processing them.

At the time of compilation programmer selects the type of memory model ('near' or 'far') that is used for FLASH and RAM memories. This choice determines accessible memory range, hence when the FLASH above 64KB limit is programmed, 'far' model must be used.

The DioneOS supports 'far' model for code modules, so large firmware that uses extended FLASH can be developed and run under the system control. The system uses 'near' memory model for data segments.

Threads Management

The firmware started under the DioneOS system consists of threads that are executed in pseudo-parallel way. Each thread has its own, unique priority used for ordering the threads from the most important to the least one. The thread priority value defines a precedence for running over others.

In the DioneOS system the thread can be in one of following states:
  • RUNNING - the thread is currently executed by processor,
  • READY - the thread is ready to be run,
  • WAITING - the thread is blocked and waits on some synchronization object.

Because there is only one core in the processor, only one thread can be in RUNNING state. This is the thread that has the highest priority from all threads that are not in WAITING state. Change of the thread state can be caused by:
  • triggering an object, that hold the thread,
  • unsuccessful acquiring the object that is already locked (e.g. a mutex that is owned by someone else),
  • elapsing timeout,
  • state change of another thread, that may lead to preemption.

The system handles up to 16 threads, including idle one with the lowest priority. The idle thread should be always ready to be run, and never switched to 'waiting' state, so it not permitted to call any functions that would block from inside this thread. The idle thread can be used to determine total system load.

Features of the System

The DioneOS system provides:
  • items for synchronisation: mutexes
    Mutual exclusion
    Mutual exclusion algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code in which a process or thread accesses a common resource...

     and counting semaphores
    Semaphore (programming)
    In computer science, a semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access by multiple processes to a common resource in a parallel programming environment....

    , used for thread synchtonization, signalling from ISR to a thread and guarding shared resources,
  • methods for time management: timers, thread sleeping, timeouts,
  • communications items implemented by events and queues available as circular buffer
    Circular buffer
    A circular buffer, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end.This structure lends itself easily to buffering data streams.-Uses:...

    s,
  • memory management by memory pool
    Memory pool
    Memory pools, also called fixed-size-blocks allocation, allow dynamic memory allocation comparable to malloc or C++'s operator new. As those implementations suffer from fragmentation because of variable block sizes, it can be impossible to use them in a real time system due to performance...

     that allocates memory only in fixed-size blocks but is free of fragmentation issues that may appear when heap
    Heap (data structure)
    In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if B is a child node of A, then key ≥ key. This implies that an element with the greatest key is always in the root node, and so such a heap is sometimes called a max-heap...

     is used. Regular allocation by malloc/free on heap is also available, it is provided by standard C libraries.
  • testing support objects: signaling events on chip pins, critical exceptions, objects marking that helps is detection of errors like usage of deleted object or double memory deallocation, etc.

Context Switch

As it was stated in 'Threads Management' chapter, the firmware consists of pseudo-parallel threads. Each thread has its own context, that contains core registers of the processor, last execution address and private stack. During the switch between threads the system saves the context of stopped thread and recovers the context of the one being run. This state saving makes possible breaking the thread execution and further continuation, even if between them other thread has been executed. Note that preemption followed by context switch
Context switch
A context switch is the computing process of storing and restoring the state of a CPU so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU. The context switch is an essential feature of a multitasking operating system...

 may happen in any moment, even if no system function is called in the thread. Although it may happen in unexpected location in the executed code, the thread work is not distorted due to the system and the context saving. From the thread point of view, the switch can be done in background.

The context switch is critical operation in the system and the time of its execution determines if how effective the system is. Because of that the context switch in the DioneOS system was optimized for short time. The most important parts were written in assembler
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

, so the switch can be done in 12-17us (for fosc=25 MHz).

In the DioneOS system the context switch can be initiated from interrupt service routine
Interrupt handler
An interrupt handler, also known as an interrupt service routine , is a callback subroutine in microcontroller firmware, operating system or device driver whose execution is triggered by the reception of an interrupt...

. This property is useful for moving an event handling to the thread and commonly implemented in two-layer architecture:
  1. the interrupt handler - is called after hardware interrupt has occurred. In this part interrupts are disabled, so execution cannot be continued for long time, otherwise the system responsiveness is compromised. In this layer only jobs that require fast response for interrupt should be processed, any others should be passed to higher layer,
  2. higher layer - processing in separated thread without blocking interrupts; this thread can be preempted. Constraints are not so tight here as in the interrupt handler. The code execution does not block the system.

The context switch measured from signaling point in ISR to other thread recovery takes 10us (for fosc=25 MHz) in the DioneOS system.

Configuration

The DioneOS has multiple configuration options that affects features inserted in the compiled image of the system. A lot of them are source code switches that are gathered in configuration file and can be altered by a developer of firmware. By this means it is possible to control additional testing parts. If they are enabled the system is built in a version that provides more detection of unusual conditions and run-time information that helps in debugging process. When the errors are found and eliminated these extra features can be disabled for having full performance of the system.

Example of a fragment of configuration file:

[...]
#define CFG_CHECK_OVERFLOW /* overflow testing in semaphores/mutexes */
#define CFG_CHECK_LOCK /* lock issue detection caused by preemption conditions during scheduler lock */
#define CFG_LISTDEL_WITH_POISON /* marking deleted items on the list in os_list1_del*/
#define CFG_MEM_POOL_POISON_FILL 0xDAAB /* pattern for marking de-allocated memory items */
#define CFG_LISTDEL_POISON 0xABBA /* pattern for marking removed list items */
#define CFG_CHECK_EMPTY_SEM_DESTROY /* testing semaphore before destroy in os_sleep*/
#define CFG_FILL_EMPTY_MEM_POOL /* free memory fill with pattern */
[...]

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK