What can µCOS-II do for you?
µCOS-II (pronounced "micro C OS two") is a multi-threaded real-time operating system that underpins the On-Chip SDK stack - your application can use it on an LTC5800-based device without paying a license fee. The main features it provides:
- Timers - the OS has been modified for low power operation, and timers have a granularity of 1 ms in the OCSDK (rather than 32 kHz ticks).
- Tasks - the OS allows you to create multiple asynchronous tasks. There is only one core, so only one task runs at a time.
- Semaphores/Mutexes/Flags - the OS provides several mechanisms for synchronizing tasks.
Some features are not used in the SDK but are available for your use:
- Mailboxes
- Queues
Features marked as not to be used at a task level are not available to your code.
We recommend against using the OSMem functions to dynamically allocate memory, as they may fail with future stacks. We recommend using static allocation, i.e. no malloc().
Important Design Considerations
A typical sample program is laid out as following:
- Global (to the app) variables are declared in a struct for easy debugging.
- CLI commands are defined.
- p2_init (init process 2) is the entry point for your code - you can initialize memory and semaphores here, and start your tasks. See proper use of p2_init() for further details.
- tasks - If you are relying on task priority to coordinate activity, you're probably doing it wrong. To be low power, tasks need to be sleepy, idling most of the time by pending on a semaphore (or similar mechanism) and only waking to perform short tasks. Polling wastes a lot of CPU time - it is far better to use an OS timer than a busy loop to manage timing.
- functions - functions should be kept as short as possible to avoid blocking tasks unnecessarily. This includes your Rx Callback function (if applicable). For example, when sending a packet, it is often better (particularly as your applications grow more complex) to store the packet in a global variable, and use a semaphore to signal an asynchronous "send task" that a packet is available.
- kernel header - the kernel header provides version information about your application for the stack. By default it contains the OCSDK version.
ISRs
The OCSDK does not currently expose interrupt handlers to your application, which means that you can expect some OS latency (could be 10s of ms) in handling an event such as a GPIO level change.