You are viewing an older revision! See the latest version

CMSIS RTOS

Table of Contents

    RTOS

    1. mbed RTOS
    2. CMSIS RTOS

    The CMSIS-RTOS is a common API for Real-Time operating systems. It provides a standardized programming interface that is portable to many RTOS and enables therefore software templates, middleware, libraries, and other components that can work across supported the RTOS systems.

    CMSIS-RTOS Library URL: http://mbed.org/projects/libraries-testing/svn/rtos

    Thread

    The Thread Management function group allow defining, creating, and controlling thread functions in the system. The function main is a special thread function that is started at system initialization and has the initial priority osPriorityNormal.

    [Not converted]

    main

    The main function is already the first thread scheduled by the rtos.

    Mutex

    The Mutex Management function group is used to synchronize the execution of threads. This is for example used to protect access to a shared resource, for example a shared memory image.

    ISR

    Mutex Management functions cannot be called from interrupt service routines (ISR).

    /media/uploads/emilmont/mutex.png

    [Not converted]

    C standard library mutexes

    The ARM C standard library has already mutexes in place to protect the access to stdio, therefore on the M3 mbed the above example is not necessary. On the contrary, ARM microlib (used on the M0 mbed) does not provide default stdio mutexes making the above example a necessity.

    printf in ISR

    Because of the mutexes in the ARM C standard library you can not use printf in ISR!

    Semaphore

    The Semaphore Management function group is used to manage and protect access to shared resources. For example, with a Semaphore the access to a group of identical peripherals can be managed. The number of available resources is specified as parameter of the osSemaphoreCreate function.

    /media/uploads/emilmont/semaphore.png

    [Not converted]

    Signals

    The Signal Management function group allow to control or wait signal flags. Each thread has assigned signal flags.

    [Not converted]

    Message Queue

    The Message Queue Management function group allow to control, send, receive, or wait for messages. A message can be a integer or pointer value that is send to a thread or interrupt service routine.

    /media/uploads/emilmont/messagequeue.png

    Memory Pool

    [Not converted]

    Mail Queue

    The Mail Queue Management function group allow to control, send, receive, or wait for mail. A mail is a memory block that is send to a thread or interrupt service routine.

    /media/uploads/emilmont/mailqueue.png

    [Not converted]

    Timer

    The Timer Management function group allow creating and and controlling of timer functions in the system. A timer function is called when a time period expires whereby both on-shot and periodic timers are possible. A timer can be started, restarted, or stopped.

    Timers are handled in the thread osTimerThread. Callback functions run under control of this thread and may use CMSIS-RTOS API calls.

    /media/uploads/emilmont/timer.png

    [Not converted]

    Interrupt Service Routines

    The same CMSIS-RTOS can be used in ISR. The only two warnings are:

    • Mutexes can not be used.
    • Wait in ISR is not allowed: all the timeouts in method parameters have to be set to 0 (no wait).

    [Not converted]

    No wait in ISR

    When calling an rtos object method in an ISR all the timeout parameters have to be set to 0 (no wait): waiting in ISR is not allowed.

    Stack Configuration

    The stack configuration is very dependent from the underling CMSIS-RTOS implementation.

    As first reference implementation we are using RTX. One of the limitation of the RTX implementation is that it requires to statically configure the maximum number of threads and the size of the memory pool for their stacks.

    Our initial RTX configuration choices are likely to change in response to the mbed users feedback:

    mbed NXP LPC11U24mbed NXP LPC1768
    Max number of user threads + (timer)3 + (1)7 + (1)
    Default stack size in bytes0.5 Kb1 Kb

    RAM Usage

    Importing the rtos library you will immediately consume 25% of the available RAM on your mbed for stack usage.

    configuration

    We will soon release the sources of our current RTX implementation and you will be able to edit the configuration as you like.

    Additionally, in the future we will favour CMSIS-RTOS implementations that do not require the editing of a configuration file to specify the maximum number of threads.

    The current stack configuration is a temporary implementation detail.

    Status and Error Codes

    The Status and Error Codes section lists all the return values that the CMSIS-RTOS functions will return:

    • osOK: function completed; no event occurred.
    • osEventSignal: function completed; signal event occurred.
    • osEventMessage: function completed; message event occurred.
    • osEventMail: function completed; mail event occurred.
    • osEventTimeout: function completed; timeout occurred.
    • osErrorParameter: parameter error: a mandatory parameter was missing or specified an incorrect object.
    • osErrorResource: resource not available: a specified resource was not available.
    • osErrorTimeoutResource: resource not available within given time: a specified resource was not available within the timeout period.
    • osErrorISR: not allowed in ISR context: the function cannot be called from interrupt service routines.
    • osErrorISRRecursive: function called multiple times from ISR with same object.
    • osErrorPriority: system cannot determine priority or thread has illegal priority.
    • osErrorNoMemory: system is out of memory: it was impossible to allocate or reserve memory for the operation.
    • osErrorValue: value of a parameter is out of range.
    • osErrorOS: unspecified RTOS error: run-time error but no other error message fits.

    osEvent

    The osEvent data structure is returned by get methods of Queue and Mail objects. This data structure contains both an error code and a pointer to the actual data:

    osEvent

      * status       [osStatus    ]: status code (event or error information)
    
    union: either {
      * value
        * v          [uint32_t    ]: message as 32-bit value 
        * p          [void *      ]: message or mail as void pointer 
    } or {
      * def
        * mail_id    [osMailQId   ]: mail id obtained by osMailCreate 
        * message_id [osMessageQId]: message id obtained by osMessageCreate
    }
    

    All wikipages