RTOS Selection Guide
Contact Microchip
Development Tool Selector
Microchip Advanced Parts Selector (MAPS)
CiSAR (Service Request)
RTOS Selection Guide

Real-Time Operating System (RTOS) Selection Guide

A number of third party vendors offer real-time operating systems (RTOS) for Microchip PIC® MCUs and dsPIC® DSCs. Many of these are excellent products that provide a full range of features and are designed to be run on PIC32, dsPIC, PIC24 and even PIC18 processors. With such a large number of choices it can be difficult to select an RTOS for a new application.

Whilst this article does not identify (or recommend) any particular RTOS, it is designed to highlight features, concepts, and questions that you should consider when performing this selection.

When choosing an RTOS, consider the following questions:

Applicability: Is an RTOS an appropriate for my project?

Features: What Features does a typical RTOS support?

Performance: What factors influence RTOS performance?

Commercial Considerations: What kind of company stands behind an RTOS?

Licensing Model: Under what terms can I distribute an RTOS-based application?

Cost: How much does an RTOS cost?

Applicability: Is an RTOS an appropriate for my project?

Before choosing an RTOS, it is worthwhile to be sure that one is actually required. Here are some points to consider:

<> An RTOS will use system resources, both FLASH and RAM, and take up processor bandwidth. Because of this they are best used on larger processor families such as the PIC24, dsPIC and PIC32. Using an RTOS on a PIC18 or smaller part may be an unlikely choice.

<> Software re-use and modular design is aided by the use of an RTOS. Applications which are modular and integrate elements written by multiple authors can benefit from their use.

<> Conversion and integration of existing commercial software can also be simplified with an RTOS. Many Microchip software libraries are provided with standalone examples. If the final application is just a simple modification of one of these samples then it may not be worthwhile. However, once multiple complex libraries are being used then the final application can be more easily written using an RTOS, speeding development time and justifying any additional costs.

Once the decision to use an RTOS has been taken there are number of factors that will come into effect that can influence the choice of which one to buy (or license). Firstly, we will look at the purely technical aspects in Features and Performance, and then move on to commercial considerations.

Back to the top

Features: What Features does a typical RTOS support?

The vendors will tell you that there are substantial differences between their product and that of the competitors. Even given this ‘apparent and obvious’ superiority of product A over product B there are still common features that a customer might use in order to compare the products. Listed below are the main features of any RTOS (or micro-kernel).

Memory Allocation

An RTOS typically needs a mechanism to manage memory. Since a number of objects (such as tasks and queues) are created at run-time each RTOS provides a scheme to ensure correct allocation of memory. Since it is not ‘thread’ safe the standard C malloc function cannot simply be called and a custom method is provided. The efficiency and capability of these memory managers can vary between products. This could be an issue if your program dynamically creates and destroys a lot of objects at run-time.

Tasks

One of the most basic elements of an RTOS, the user’s code is written inside a task. Depending upon the RTOS the code may be written in a linear fashion (running once through to completion) or it may enter the typical while(1) loop. Some RTOSs allow for the dynamic creation and deletion of tasks whilst in others they must all be created at compilation time.

Another area of difference is task priorities. In order to select the next task to run the user assigns each task a priority, and the RTOS selects the highest one. Depending on the RTOS these priorities may be in ascending or descending order and may or may not be unique. In the latter case the user must ensure that each task has a different priority.

Different RTOS vendors may place restrictions on the total number of tasks that can be created (and this may vary between full and evaluation versions). As a guideline a typical RTOS based program may have up to 10-15 tasks operating at any one time although the primary limiting factor is usually the available memory on the device and response time.

Each task that is created will consume memory and this usually has to be defined when the task is created. The task’s stack is used to store all of its local variables, function parameters, return addresses and a copy of the processor registers when the tasks is ‘swapped out’. This can consume a considerable amount of memory and the different vendors have invented various methods to improve the situation.

One common solution is the use of ‘lightweight’ tasks which are variously called ‘co-routines’, ‘lightweight tasks’ or ‘fibres’ These simple tasks typically share a single stack and may be restricted in the functions that can be performed inside them or the way in which they have to be written.

Task Scheduling

Different RTOSs may use different scheduling systems and algorithms. The casual user often assumes that an RTOS will take of much of the detail of switching between tasks however this is only generally true in the case of a fully pre-emptive RTOS. In a co-operative RTOS the user must write their software so that the tasks execute and then yield control to other tasks at suitable points. An RTOS where many tasks can share the same priority will typically use a ‘round-robin’ scheduling algorithm to ensure that each one gets a share of the processors resources.

As stated most people want a pre-emptive RTOS but a co-operative one can operate just as efficiently and may use less processor resources.

Queues

Once the customer has broken the program down into suitable elements then they can be put into separate tasks. However, there is usually little benefit in doing this unless the tasks can communicate with each other.

A queue provides a simple first-in first-out structure that permits a programmer to send data from one task to another in a ‘safe’ manner. Since a task could be interrupted at any point it would be dangerous if task A tried to read data from a queue whilst task B was in the middle of writing data to it. The RTOS provides functions to ensure the integrity of the data.

The program can normally specify the size of the queue and also the size of each element in the queue at creation time. So you might create a queue that contains 100 chars OR you might create a queue that can contain 10 strings each one of which is 10 chars in length. In the first case you would read and write a single character to the queue whilst in the second case entire strings would be sent.

Different RTOSs may place restrictions on the number of queues that can be created as well as the maximum permissible size of data elements and the flexibility with which objects can be added or removed from queues.

Semaphores

When state information needs to be signaled between tasks this is usually done by a semaphore. The best way to think of it is as a flag (hence the name semaphore) that allows another task to become active. A task will typically wait, or pend, on a semaphore until it is set by another part of the system. Once signaled the RTOS will convey the state information and may cause the pending task to become active. The RTOS ensures that this is done in a reliable manner.

A related use for semaphores is when a resource is shared between multiple tasks. In an RTOS based system this is very common and multiple tasks may have to share many resources such as, displays, communication channels, memory objects and so on. A problem occurs when one task is accessing a resource and another task pre-empts it and changes that resource in some way. By using semaphores in this way we can prevent unwanted interactions and form a mutually exclusive operation.

An alternative option offered by some RTOSs is the mutex. Like a semaphore it is used to guard accesses to common resources or protect particular sequences of code so that they cannot be interrupted. A problem occurs if a high priority task enters a section of code and needs to access a resource currently locked by a lower priority tasks. A mutex can solve this problem by temporarily changing the priority of the task so that it can complete (called priority inheritance). Different RTOS vendors implement semaphores and mutexes in different ways and may only offer a restricted set of features.

Events/Flags

Events or event flags are a more complex way of signaling to a task from other places that a section of code should be executed. In the case of semaphores discussed previously setting one semaphore would allow one piece of code to execute. With event flags the setting of multiple items in combination can be used to trigger an action. It is possible to have a task pend upon several flags and only when they are all set will it become active and continue executing.

The degree of flexibility that can be used with events varies between RTOS vendors and they may not even exist in certain products, their functionality being replicated with alternative programming styles.

Ticks and Timers

Fundamental to the operation of most pre-emptive RTOSs is the concept of a tick timer or heartbeat. This timer operates at a moderate frequency (typically a few hundred hertz) and at each interval it interrupts the currently running task and allows the RTOS to switch to another higher priority task. This does not prevent a task completing in the meantime and causing a switch but it does provide the basic pre-emptive mechanism. If the heartbeat is set too fast then the application could spend all of its time switching in and out of the kernel whilst too slow and the system response may be impaired.

Most RTOSs contain the ability to run tasks and then cause them to delay or wait for a finite period of time. An extra option is the ability to run tasks at a predefined interval related to the tick rate. This provides the basic elements allowing timed operation of a program. In addition many RTOSs provide the capability for multiple software timers although they may be limited to the resolution of the tick timer. These timers can be used anywhere in the program and are typically used for timing longer events.

Hook Functions

Rather than directly editing the RTOS source code (which may not be possible if it is not provided) many RTOSs provide the ability to attach functions or code into parts of the kernel itself. These software hooks or callback functions are typically used to implement simple blocks of commands that may not require the creation of a separate task.

For instance, the debouncing of switch inputs may be more simply done by attaching a small piece of code to the periodic heartbeat function rather than creating a separate task to perform this function.

Software Compliance

Most RTOSs have a unique application programming interface that is specific to that product. Even given this there is still a large degree of commonality between the products and functions so whilst the names may vary it is often possible to migrate an application to another RTOS with little difficulty.

As this migration is so often desirable large software organizations have adopted standards to which software should be written so that applications can be easily ported. An example here is the POSIX® software API standard found on Linux based systems. Whilst not often found on an embedded RTOS, the POSIX call standard can be helpful when porting large public domain applications onto the smaller platforms (an example might be a web application written for ucLinux for instance).

Back to the top

Performance: What factors influence RTOS performance?

Several factors can influence the performance of a particular RTOS but perhaps more important is what does the user require when they ask for high performance? In some cases a programmer might require an application that fits into a certain memory sized device, in other cases the application must operate with tightly defined latencies and response times between tasks.

An RTOS with a large memory footprint may appear low performance because of code size yet it can provide a large range of functions that reduce programming overhead yielding a better solution than a small fast kernel. In all instances it is necessary for the customer to define what they require from high performance and select accordingly and if possible performing tests on various products.

Speed

At its most basic level a RTOS provides the capability to switch between various software modules to make it appear that they have the full resources of the processor at their disposal. A modern RTOS also provides a large number of functions that can be used in flexible ways to create a program. But the trade-off is that as an RTOS becomes more flexible the final application may spend more time executing the kernel rather than the user’s code. In this case it is obviously important that the RTOS is fast and any functions it contains are efficient.

A more insidious problem is that an RTOS can disable interrupts whilst it is switching between executing tasks. If a high priority interrupt arrives it may not get serviced until the RTOS re-enables interrupts again. This introduces unwanted jitter in the application response time. As stated previously this may not be a problem but the user should calculate the minimum acceptable values for their application.

Some modern RTOSs feature what is called a segmented architecture where they do not disable interrupts. It is still possible to get delays in these cases due to the inherent interrupt latency of the microcontroller but it is minimized. Whilst this is a good feature it can come with certain trade-offs such as allowing only limited function calls from within interrupt service routines. Again testing is required in the specific application.

Memory

All RTOSs need to save the state of a running task when switching to another task. This saved stack typically consists of the call stack for the task, its automatic variables and the contents of all of the used processor registers. Fundamentally all RTOSs must save this information somewhere when switching tasks however various products have adopted clever tricks to reduce the amount of space used.

If we consider a PIC32 application then each function call or frame will consume a minimum of about 60 bytes (return address + function arguments + caller preserved registers). More importantly when a task is switched the majority of the processor registers must also be saved and this can exceed 130 bytes. If the application then has ten tasks each one would require an equivalent stack size consuming much of the total memory.

Some RTOSs implement a system stack where much of the common information used in the kernel is stored in a single place saving RAM.

Back to the top

Commercial Considerations: What kind of company (or entity) stands behind an RTOS?

With so many different products from different vendors it can be difficult to arrive at the most suitable product choice based upon technical capability alone. The customer will need to consider the commercial aspects of the product choice.

At one end of the spectrum there are free RTOS products that are free to download, use and deploy with no royalties. One argument against these is that support may be difficult to obtain since they are not provided by a single company. The reverse of this argument is that the most common open source operating system Linux is completely public domain and supported by a worldwide community of programmers so free code is not always a problem (we are not suggesting here that Linux can be made to fit inside a PIC Microcontroller!).

With a product backed by a single company or organization it is simpler to arrange for support and know who to contact with questions. Of course this does not come for free and a user should expect to pay for such products.

At the other end of the spectrum large companies produce very high performance products with a large installed user base and a great many product add-ons (such as RTOS compliant TCP/IP and USB stacks). These may be the most suitable choice for the project but again a user should expect to pay proportionally more.

With most RTOS products that are backed by companies a limited demo version is usually available. These may be limited by the amount of time that the program will operate for or they may be restricted in the maximum number of tasks that can be created. It may not be possible to complete the project in these demo versions but they can be used to aid evaluation before making a product decision.

Back to the top

Licensing Model: Under what terms can I distribute an RTOS-based application?

Just as varied as the commercial considerations are the license terms under which the products are distributed. At the free end of the range a user should expect to acknowledge the use of the RTOS in their product and comply with any intrinsic license terms (BSD, GPL or modified GPL).

With the more expensive products comes a range of licensing options. It is possible to purchase the RTOS product for use on a particular project and expect to pay one fee whilst if it is licensed for all the products that a user designs then a larger licensing fee may be involved.

Some RTOS vendors will charge a flat fee for the kernel based upon how many different products it goes into whilst others may negotiate license fees based upon expected sales and charge a fee per unit shipped. Still other vendors may charge different fees for the same product but base it upon the complexity of the design, so a design with 20 tasks might cost more to license the RTOS than one with 5.

The only way to be clear on these choices is by negotiating directly with the vendors.

Back to the top

Cost: How much does an RTOS cost?

Because of the wide range of licensing choices it is extremely difficult to publish prices but we can provide a guideline. Obviously the free products are free but the typical fee for a middle range RTOS is $2000-$4000 (USD). For the more popular commercial products commensurately higher prices can be charged and a user may expect to pay up to $8000-$10000 to license.

At the higher end a critical design choice may be the availability of third party software libraries that are fully integrated with the RTOS (TCP/IP, USB, File Systems). It is not uncommon for these to be chargeable extras and a good quality software library may cost an additional $2000-$4000 extra.

Back to the top


POSIX is a registered trademark of the IEEE Inc.

Downloads