1
5/21/2008 1
Getting started with RTOSLotta Frimanson, IAR Systems
2
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
2
3
Company profile
• Headquarters in Uppsala, Sweden
• Sales offices in the US, China, Japan, the UK, Belgium, Germany, Brazil and Sweden
• About 140 employees• Part of the Nocom Group since 2005, public limited
company in Stockholm’s Stock Exchange • 80.000 application developers• Partner with 16 of the top semiconductor companies
4
Company background• Founded in 1983 in Uppsala, Sweden• Vision was to provide new, efficient tools for
embedded system development • 1986 - the first C compiler for a
microcontroller was launched, probably the first product of its kind in the world
• C-SPY, the high-level-language debugger, was introduced in 1987
• IAR Embedded Workbench IDE introduced in 1996
• VisualSTATETM acquired 1999• IAR KickStart kitsTM introduced 2004• IAR PowerPacTM launched November 2006
3
5
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
6
What is a Real Time Operating System ?
“Software that manages the time and other resources of a microprocessor or microcontroller”
4
7
What is a Real Time Operating System ?
Allows Multitasking:– Allows to do more than one thing at the same time.– Breaks down the application into multiple tasks each
handling one aspect of the application– It’s like having multiple CPUs!
8
Provides valuable services to the application– Task management– Time delays/timers– Semaphore management– Inter-task communication and
synchronization
What is a Real Time Operating System?
5
9
What is a Real Time Operating System?
High priority task
Medium priority task
Low priority task(idle task)
Push of a button Push of a button
10
Why use an RTOS ?
• More responsive to real time events• Ensure that the microcontroller (MCU)
runs the task that has the highest priority
• Deterministic response• Polling is avoided because tasks only run
when events occur, and tasks waiting for events do not consume CPU cycles.
• Saves power!
6
11
Why use an RTOS ?
• The processors gets more and more advanced and is expected to handle more complex tasks -- it's not possible to hand-write everything any more.
• A complete tool box. No need to write semaphores etc. by hand any more.
• Saves development time• Reduces time to market• Correctness -- it's easier to understand a complex
system if you can study one aspect (task) at a time. • An operating system gives you an entire eco-system --
easier use of middleware like communication protocols, file systems etc.
12
Why use an RTOS ?
• Makes programming more efficient and better structured, 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
• Allows the application to be broken down into smaller pieces
• Using an RTOS can make the program smaller• An RTOS abstracts the hardware-dependence, porting
the application to a different target is easier• Makes it easier to structure and divide the coding work
between multiple developers.
7
13
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
14
What is a File System
• Software for storing and organizing data on storage devices
• Can be used on any media for which you can provide basic hardware access function– Internal flash– NAND flash via SPI– SD card
8
15
What is a FAT File System
• Access to FAT (File Allocation Table ) 12/16/32 compatible Media
• It is the primary file system for various operating systems including MS-DOS, Microsoft Windows, etc
• Optional support for long files names
16
File System features
• Wear leveling – makes sure that the number of erase cycles remains
approximately equal for each sector• Fail-safe operations
– The driver makes only atomic actions and takes the responsibility that the data managed by the file system is always valid.
– In case of a power loss or a power reset during a write operation, it is always assured that only valid data is stored in the flash.
– If the power loss interrupts the write operation, the old data will be kept and the block will not be corrupted.
9
17
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
18
Task oriented design
Time
Superloop
ISR
ISR (nested)
Task level Interrupt level
ISR
Single-task system with super loop
10
19
Task oriented design
Multitasking system - each task can be seen as one program
Time
ISR
Low priority task
High priority taskISR puts high prioritytask in READY state;task switch occurs
Executing task is interrupted
Interrupted taskis completed
Higher priority taskIs executed
20
Scheduling
• The algorithms that determine which task to execute
• Distinguish between tasks that are ready to be executed and other tasks that are suspended
• The task which is currently executing is referred to as the active task
11
21
Pre-emptive scheduling Non pre-emptive scheduling
Priority controlled scheduling
22
Priority controlled Multitasking
Execution of Multiple Threads
Execution of Multiple Threads
Priority ControlledScheduler
Priority ControlledScheduler
Round RobinScheduler
Round RobinScheduler
A preemptive scheduler allows interrupts and higher priority tasks to interrupt the currently running task
All tasks are on the same level; the possession of the CPU changes periodically after a predefined execution time.
12
23
Tasks switching
• Each task consist of:– The program code, which usually resides in ROM– A stack, residing in a RAM area that can be accessed
by the stack pointer– A task control block (TCB), residing in RAM. The TCB
is only accessed by the RTOS• Switching stacks• Change of task status
24
Communication between tasks
• As tasks run in the same application, they sometimes need to communicate with each other to:– exchange data with other tasks– synchronize with other tasks– make sure that a resource is used by no more than one
task at a time
• Can be achieved by:– Global variables..... – RTOS communication mechanisms ☺
13
25
Communication mechanisms
• Mailboxes– A buffer that is managed by the real-time operating system – Fixed message size
• Queues– Similar to mailboxes, but enable inter task communication
with larger messages– Messages of various sizes
• Semaphores– Used for managing resources by avoiding conflicts caused
by simultaneous use of a resource– Resource semaphore– Counting semaphore
• Events– task events are messages to a single, specified recipient
26
Task oriented design
• Polling is avoided because tasks only run when events occur, and tasks waiting for events do not consume CPU cycles.
• Benefits:– Clearer design– Adding a lower priority task will not affect the responsiveness of
the system to high priority tasks – Code can be modularized, making things easier to maintain and
debug– Saves power
14
27
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS/ File system
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
28
Why use a commercial RTOS ?
Priority controlled
Mulititasking
Priority Priority controlledcontrolled
MulititaskingMulititaskingProven codeProvenProven codecode
VisualizationVisualizationVisualization
DocumentationDocumentationDocumentation
CostsCostsCosts
UniversalUniversalUniversal
Commercial RTOS?Commercial RTOS?Commercial RTOS?Hard real timeHard real timeHard real time
Shorter timeto market
Shorter Shorter timetimeto to marketmarket
15
29
Why use a commercial RTOS ?
• Quality– Proven code - used by hundreds of users in a multiplicity of ways – Continuously used and tested– Developer can focus on application program instead of wasting
time on finding bugs– Code is more organized
• Hard real-time:– Zero latency– Short interrupt latency– Fast context switch
• Provides a compleet tool box
30
Why use a commercial RTOS ?
Visualization:– Kernel aware debugging
• Task lists• Mail boxes• Timers • System information
• Documentation: – Technical support– In case of crew change: Well documented code/manual– Makes porting to different hardware easier
16
31
Why use a commercial RTOS ?
• Shorter time to market:– Reliability lets developer focus on application– Training on RTOS takes less time than inventing it from
scratch – Writing the documentation is very time consuming
• Costs:– Less expensive than costs for developer when inventing
from scratch– Less expensive when changing to a different processor– Developers costs are higher than buying a commercial
RTOS
32
Why use a commercial File System?
• Quality - proven code• Documentation• Portable to different CPU• Crew change• Performance• Functionality:
– Wear leveling– Error correction algorithm?– Support for different media types
17
33
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
34
Decision process
• You need to identify the individual components that are required in your project– development tools suite – C/C++ compiler, debugger– state machine verification if used – RTOS– other middleware such as communications stacks
– as well as the processor itself.
• An RTOS needs to be seen as just one component of a complete development eco-system
18
35
Factors to be considered when selecting RTOS and middleware
• Performance– code size and reliability, interrupt latency, context switch times,
service overhead
• Completeness– suitability for the application, both in power and resources
• Development tool compatibility – does it work with familiar tools or those already in house
• Ease of use– intuitive user interface, documentation, getting started examples
• Financial factors– total cost of ownership, including license fee, royalties or other
payment models and any maintenance subscription
36
Decision process
• A pre-integrated development solution:– Saves time and money – someone else has made the
integration work for you– Provides ready made projects and examples where all
components are included– One-stop-shopping– Gives support from one place
19
37
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
38
Complete suite of tools
DesignVerify,
Validate,Implement
Compile Debug DeployTarget
applicationIdea
visualSTATEIAR
EmbeddedWorkbench
IAR J-Link& IAR J-Trace
IAR Development
Kits
RTOS & Middleware
IAR PowerPac
20
39
IAR PowerPacTM
• Fully featured real-time operating system
• High performance file system
• USB device communication stack
• TCP/IP protocol stack
• Innovative business model similar to that of IAR Embedded Workbench
• Tight integration with IAR Embedded Workbench
• Easy to get started
• Board support packagesIAR PowerPac Base
(RTOS + File System)
IAR PowerPac Source
Additional components
IAR PowerPac TCP/IP
IAR PowerPac USB
40
Operating systemKey features• Small memory footprint (1.5 KByte for typical MSP430
implementation)• Pre-emptive multi-tasking • Round-robin scheduling • Up to 255 priorities• Unlimited number of tasks, semaphores, mailboxes and
software timers • Full interrupt support• Nested interrupts permitted • Zero interrupt latency time• Very fast context switch times
21
41
RTOS performance
typ. 1 ms, min. 100 µs (10 kHz interrupt frequency)Basic time unit (TICK)
less than 1% of total calculation time at 1000 Interrupts/second (1ms TICK)Kernel CPU usage/TICK
max. 151 clock cycles (37.8 µs)Interrupt latency time
270 clock cycles (67.5 µs), independent of number of tasksContext switch time
Timing
48 bytesMin. stack-size per task (RAM)
0 bytesRAM usage event
10 bytesRAM usage per software timer
12 bytesRAM usage per mailbox
2 bytesRAM usage per counting semaphore
4 bytesRAM usage per resource semaphore
18 bytesRAM usage per task control block
28 bytesKernel RAM usage
1587 bytesKernel size (ROM)
Memory usage
42
Support for MSP430 low power modes
• Task oriented design is very useful if you want to save power
• Peripherals can be switched of when not used• Wake up is possible through all enabled interrupts• Efficient OS causes minimum CPU overhead ->
maximizing idle time -> reducing power consumption
22
43
Support for MSP430 low power modes
• PowerPac 430 comes with an OS which fully supports all low power modes.
• OS brings CPU always in lowest power mode possible whenever CPU is idle
• Peripheral clock requirements are taken into account
• Lifts a lot of the burden for power management from the programmer
44
Support for MSP430 low power modes
• The idle task– The idle task will only be active when no other task has
something to do.– Other tasks need to make operating systems calls to let
the system know when shared resources are or are not in use.
• OS_POWER_IncUsage(int Level)• OS_POWER_DecUsage(int Level)
– The idle task will depending on which resources are used, enter the lowest possible power mode.
23
45
IAR PowerPac file system
• Small footprint, e.g. 12 KByte ROM / 1.6 KByte RAM
• MS-DOS/MS-Windows compatible FAT12, FAT16 and FAT32 support
• Multiple device driver support • Multiple media support• Caching functionality• Check disk functionality• Format functionality Device drivers
available: RAM disk, MMC, SD, CompactFlash , IDE, SMC, NOR/NAND flashes
IAR PowerPacTM
File system
46
File System Layer(FAT)
Storage Layer
Device Driver(CF / IDE / MMC / NAND / NOR / SD /...)
Low level routines to access sectors of a device and check
status.
Synchronisation of device operations for different file
operations.
Translation of file operationsto sector operations.
<stdio.h> like functions like FS_FOpen(), FS_FRead(),
FS_FWrite().
ApplicationApp. Program using
Storage API or FS API.Responsibility of app.
programmer
Hardware Layer
Pow
erP
acFi
le S
yste
m
Low level routines to accessyour hardware.
Responsibility of app.programmer
File System APIStorage APIFile System API:API Layer
24
47
PowerPac File System API layers
• File System API layer– Contains file functions in ANSI C stdio style, such as
FS_FOpen(), FS_FWrite() etc.– Translates file operations to logical block (sector) operations.
• Storage API layer– Contains the functions which are required to initialize and
access a storage medium– Allows sector read and write operations– Optimized for applications which do not require file system
functionality. – A typical application: USB mass storage device,
data has to be stored on a medium, but all file system functionality is handled by the host PC.
48
Ready to go start project
25
49
Integration with IAR Embedded Workbench
• Example projects available from the startup screen
• Links to IAR PowerPac documentation in the Help menu
• Template projects within IDE for new library projects
• RTOS aware debugging via C-SPY plug-in
• Board Support packages for IAR KickStart kits
50
IAR PowerPac for MSP430 - evaluation version
• Available in all EW430 product variants with the following limitations:– IAR PowerPac RTOS can create a maximum of three tasks – IAR PowerPac File System can only handle one open file at
any given time
• Time limited version will also be available
26
51
IAR PowerPac business model
• Principle– Base product in object code format
• Licensing model– Seat license - per developer and CPU– Full source code upgrade– Group license (up to 20 developers)– Site license (unlimited on the same site)– No royalty fees
• Result– Low-risk licensing model– A license can be used in unlimited number of projects and
products – Affordable site license for unlimited number of developers
52
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
27
53
Getting started
Simple steps to get started with IAR PowerPac for MSP430:
• Use the board support examples to verify that a simple application can be downloaded on the target board.
• Use the board support examples as a foundation for you application project.
• Add new tasks
• The existing code can be easily integrated into a single task and split into separate tasks later
• New code can benefit from the RTOS
54
Getting started example
int main(void) {OS_IncDI(); /* Initially disable interrupts */OS_InitKern(); /* initialize OS */OS_InitHW(); /* initialize Hardware for OS */BSP_Init(); /* initialize LED ports */
/* You need to create at least one task before calling OS_Start() */OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP);OS_Start(); /* Start multitasking */return 0;
}
28
55
Agenda
• Short introduction to IAR Systems
• What is a Real Time Operating System
• What is a file system
• Task oriented design
• Why use a commercial RTOS
• Decision process
• IAR PowerPac for MSP430
• Live demonstration
• Summary
56
SummaryOur offering
• A tightly integrated RTOS, file system, and tools for developing embedded applications
• Perfect compliment to IAR Embedded Workbench
• Innovative ”low-risk” price model
• Continuous ”add-ons” for more middlewares
• Upgrade path
• Same license management system as IAR Embedded Workbench
• Local support across the globe
29
57
Thank you