Contact IAR Systems
Home Products Support Resources Downloads About us Contact My Pages
Developer's Toolbox Webinars IAR Solution Selector Viewpoints Video Presentations Further reading LEGO MINDSTORMS NXT
 
Resources   >   Viewpoints   >  
Lotta Frimanson




by Lotta Frimanson, IAR Systems

Getting started with RTOS

For a variety of reasons, a high proportion of embedded systems still do not incorporate any kind of operating system. But developers beginning a new system development should seriously ask themselves whether it would be beneficial to include a real-time operating system (RTOS). With 32-bit microcontrollers now becoming affordable, and real-time applications appearing even in relatively small embedded systems, the range of systems for which an RTOS might be appropriate is on the increase. The prospect need not be formidable: this article explains just how simple it can be to get started with an RTOS, and what are the benefits of selecting an integrated solution.

An RTOS, sometimes called a real-time multitasking kernel, is a software component that ensures the efficient processing of time-critical events, by allowing the application to be divided into multiple independent elements called tasks. Operating systems make programming more efficient and better structured, and their use is now frequently justified even in embedded solutions that are relatively small. Many of them feature useful extensions that are tailored to the needs of code-size or resource limited systems.

These days, the additional performance and memory available with an ARM- or Cortex-based MCU—now available for around the same cost as an 8- or 16-bit MCU—means that the target system can cope well with running an RTOS, and the increased complexity of applications will almost certainly benefit from a design that uses one.

RTOS benefits

An RTOS provides the developer with a framework on which to build and organize the features of the system. The toolbox that accompanies the RTOS should also provide services such as inter-task communication and time management. Even for systems that have no need of the real-time capability, the code can be cleaner and better organized if based on an RTOS, partly because it promotes code reuse. The integration of an RTOS can solve a variety of problems that can occur in application code, since it provides multitasking capability and allows the application to be broken down into smaller pieces. Each task is assigned its own priority based on its importance, and pre-emptive scheduling tries to ensure that the microcontroller (MCU) runs the task that has the highest priority among those that are ready-to-run. In most cases, adding a lower priority task will not affect the responsiveness of the system to high priority tasks.

A clear benefit of using an RTOS is that it reduces time to market, because it simplifies development without consuming a lot of CPU time and memory. IAR PowerPac, for instance, only occupies 2kB of memory. An RTOS generally offers a deterministic response, which means that it is possible that a given critical set of tasks can all be made to meet their deadlines. Polling is avoided because tasks only run when events occur, and tasks waiting for events do not consume CPU cycles.

How to choose

An RTOS needs to be seen as just one component of a complete development ecosystem, which includes the development tools suite – C/C++ compiler, debugger, state machine verification if used – and other middleware such as communications stacks, as well as the processor itself. This means that the developer must consider not only which is the ideal RTOS for the application, but also which best suits the device, and which development tools will make it simple to incorporate a particular RTOS and middleware selection. Additionally for a more complex application it will be necessary to work out how best to debug it when running under an RTOS. Choosing a pre-integrated solution, with development tools optimized for both the microcontroller and the RTOS, and with other middleware designed to work with it, can provide a new user with an easier route than buying the individual components from different vendors.

Multitasking and scheduling

Multitasking – scheduling and switching the CPU time between several sequential tasks that share the processor – allows the application programmer to manage the increasing complexity within applications. Real-time kernels, or RTOS, can make application programs much easier to design and maintain, by managing tasks and the communication between them.

The order in which tasks are performed, and their timing, are both determined by the scheduler or dispatcher. There are two types of scheduler: non pre-emptive and pre-emptive. Pre-emptive scheduling is the more sophisticated approach – when an event or ISR makes a higher priority task ready-to-run, the current task is immediately suspended and the higher priority task is given control of the CPU. Most real-time systems use pre-emptive schedulers because they are more responsive than non pre-emptive kernels.

Evaluating an RTOS

 
Figure 1: IAR PowerPac is a fully-featured real-time operating system (RTOS) combined with a high performance file system, a USB device stack, and a TCP/IP communication stack.
 
Some companies use an in-house RTOS, but – as well as consuming time that is better spent on developing the product – this approach can suffer due to the lack of both documentation and extensive testing. A proprietary RTOS is generally not portable to different CPUs, and code is rarely complete. Additionally if the designer who created it leaves the company it may become impossible to support.

Assuming one has decided against writing one’s own RTOS, the choice is then between an open source or commercialised open source RTOS and a fully commercial one. Factors that need to be considered include:

Performance: code size and reliability, interrupt latency, context switch times, service overhead. IAR PowerPac RTOS has been specifically developed to address small embedded systems, the kind that might previously have been developed without an OS. It features pre-emptive scheduling as well as round-robin scheduling, and handles up to 255 priorities with an unlimited number of tasks, semaphores, mailboxes and software timers. The highly modular structure helps to minimise memory consumption.
Completeness: suitability for the application, both in power and resources, and whether communications stacks (TCP/IP, USB) middleware, and other software such as Flash file systems are available.
Development tool compatibility: whether it works with familiar tools or those already in house, and whether development boards and starter kits are available. IAR PowerPac is tightly integrated with IAR Embedded Workbench, the company’s flagship compiler with integral C-SPY debugger. IAR KickStart Kits and Advanced Development Kits provide everything the developer needs to get started straight out of the box.
Ease of use: is the user interface intuitive and easy to install, and is the documentation easy to follow? Full integration with IAR Embedded Workbench ensures that IAR PowerPac presents the user with a familiar interface that is inherently easy to use.
Financial factors: assess the total cost of ownership, including licence fee, royalties or other payment models and any maintenance subscription that might be incurred. The innovative per-seat business model under which IAR PowerPac is licensed offers a low-risk option, since all costs are known in advance.
Future proofing: how scaleable the RTOS is, and whether it is portable within the processor family, or to other processors. IAR PowerPac is available in versions for both ARM (including Cortex M-3) and ColdFire processors.

It is also necessary to choose a supplier with a good reputation, and one that provides a high quality of on-demand support, training, and consultancy, especially for a developer new to using an RTOS. This is something that may be overlooked if opting for an open source RTOS – although cost savings may be made on the licence fee, the total cost may be high if it takes a lot of the developer’s time to understand, or if consultants have to be employed to get it working properly.

There are several compelling reasons for opting for a commercial RTOS. In addition to providing real-time multitasking capability, the task-oriented design process imposed by an RTOS is cleaner and better organised than in a system without an RTOS; the RTOS promotes code reuse, and provides a useful service to the application by offering clean hooks to middleware and by shortening development time. The quality of the application is also ensured by the predictable response times that are achieved in time-critical applications. A commercial RTOS is used in hundreds, or even thousands, of designs, and is based on proven code, thus giving confidence in its integrity.

Implementation

 
Figure 2: A starter kit such as IAR KickStart Kit, shown here for Luminary Stellaris, provides everything the developer needs to get started straight out of the box.
 
Having decided on a commercial RTOS, the next step is evaluation of the needs of the particular project. It is necessary for the developer to identify the individual components that will be required: build tools; RTOS; communication stacks. It is best to attempt to source a complete offering, rather than buying bits and pieces. Evaluation is made much easier if a starter kit such as IAR KickStart Kit and the evaluation version of IAR Embedded Workbench and IAR PowerPac is used. It is worth beginning with sample projects and board support packages supplied with the product for the specific target device in order to become rapidly acquainted with the product. Support provision can also be tested out at this stage.

Next comes implementation, again best achieved using the sample projects and board support packages supplied with the product as a starting point. In the case of IAR KickStart Kits, all the required files are included in the device specific IAR Embedded Workbench projects that are provided with the product. Even project setting is already set up for the selected target device.

The board support package should provide all the hardware specific drivers and routines that are needed to run the application on your hardware board. Task oriented design can then take place. USB and TCP/IP example applications from the kit can easily be included in the application, and will assist with setting up of the communication channels.

RTOS (kernel) awareness can be a great help while debugging the application, and with a zero compile-time configuration, the system is configurable only at run-time. A high performance compiler should also include a MISRA C checker.

Conclusion

Although using an RTOS for the first time can seem like a major step, the right choice of commercial partner can make it reassuringly easy to get started. With a pre-integrated solution, familiar tools, an intuitive starter kit and the right level of high-quality technical support, even an RTOS beginner can reap the benefits and get the best from their system design with a minimum of either risk or hassle.

References

[1] “Real-time operating systems – does your system need one?”, Jean Labrosse and Mike Skrtic, Elektronik & Entwicklung, November 2006
[2] “Choosing an RTOS”, Dick Selwood, Sevensandnines.com