renesas electronics america inc. “© 2010 renesas electronics america inc. all rights reserved.”...
TRANSCRIPT
Renesas Electronics America Inc.
“© 2010 Renesas Electronics America Inc. All rights reserved.”
ID 720L: Software Development with an Open Source Real-Time Operating System
Fatih PeksenarSenior Manager, Applications Engineering
14 October 2010
Version: 1.1
2 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Mr. Fatih Peksenar
Manager, Applications Engineering
Responsible for integrated firmware
development environment framework
within the Renesas America Applications Group.
Ported FreeRTOS to various Renesas platforms.
Examples are: RSKH8S1668, RSKSH7216,
RSKRX62N, RDKRX62N
PREVIOUS EXPERIENCE:
Lead software engineer for telecom companies where used
various RTOS frameworks including: VxWorks, eCos, MQX,
and other home grown kernels
MSEE from the University of Minnesota
3 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Renesas Technology and Solution Portfolio
Microcontrollers& Microprocessors
#1 Market shareworldwide *
Analog andPower Devices#1 Market share
in low-voltageMOSFET**
Solutionsfor
Innovation
Solutionsfor
InnovationASIC, ASSP& Memory
Advanced and proven technologies
* MCU: 31% revenue basis from Gartner "Semiconductor Applications Worldwide Annual Market Share: Database" 25 March 2010
** Power MOSFET: 17.1% on unit basis from Marketing Eye 2009 (17.1% on unit basis).
4 “© 2010 Renesas Electronics America Inc. All rights reserved.”
4
Renesas Technology and Solution Portfolio
Microcontrollers& Microprocessors
#1 Market shareworldwide *
Analog andPower Devices#1 Market share
in low-voltageMOSFET**
ASIC, ASSP& Memory
Advanced and proven technologies
* MCU: 31% revenue basis from Gartner "Semiconductor Applications Worldwide Annual Market Share: Database" 25 March 2010
** Power MOSFET: 17.1% on unit basis from Marketing Eye 2009 (17.1% on unit basis).
Solutionsfor
Innovation
Solutionsfor
Innovation
5 “© 2010 Renesas Electronics America Inc. All rights reserved.”
5
Microcontroller and Microprocessor Line-up
Superscalar, MMU, Multimedia Up to 1200 DMIPS, 45, 65 & 90nm process Video and audio processing on Linux Server, Industrial & Automotive
Up to 500 DMIPS, 150 & 90nm process 600uA/MHz, 1.5 uA standby Medical, Automotive & Industrial
Legacy Cores Next-generation migration to RX
High Performance CPU, FPU, DSC
Embedded Security
Up to 10 DMIPS, 130nm process350 uA/MHz, 1uA standbyCapacitive touch
Up to 25 DMIPS, 150nm process190 uA/MHz, 0.3uA standbyApplication-specific integration
Up to 25 DMIPS, 180, 90nm process 1mA/MHz, 100uA standby Crypto engine, Hardware security
Up to 165 DMIPS, 90nm process 500uA/MHz, 2.5 uA standby Ethernet, CAN, USB, Motor Control, TFT Display
High Performance CPU, Low Power
Ultra Low PowerGeneral Purpose
6 “© 2010 Renesas Electronics America Inc. All rights reserved.”
6
Microcontroller and Microprocessor Line-up
Superscalar, MMU, Multimedia Up to 1200 DMIPS, 45, 65 & 90nm process Video and audio processing on Linux Server, Industrial & Automotive
Up to 500 DMIPS, 150 & 90nm process 600uA/MHz, 1.5 uA standby Medical, Automotive & Industrial
Legacy Cores Next-generation migration to RX
High Performance CPU, FPU, DSC
Embedded Security
Up to 10 DMIPS, 130nm process350 uA/MHz, 1uA standbyCapacitive touch
Up to 25 DMIPS, 150nm process190 uA/MHz, 0.3uA standbyApplication-specific integration
Up to 25 DMIPS, 180, 90nm process 1mA/MHz, 100uA standby Crypto engine, Hardware security
Up to 165 DMIPS, 90nm process 500uA/MHz, 2.5 uA standby Ethernet, CAN, USB, Motor Control, TFT Display
High Performance CPU, Low Power
Ultra Low PowerGeneral Purpose
RX
Ethernet, CAN, USB, UART, SPI, IIC
7 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Innovation
DVR
Game Console
Smart Phones Navigation Systems
Music Players
Tablet PC
8 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Our RTOS Solutions
Renesas provides you a complete set of FREE tools and several
MCUs with different peripherals. We work with FreeRTOS and
other partner companies to arm you with a full set of software
solutions so you can build the next Space Shuttle!
9 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Agenda
Definitions
Why RTOS?
Why FreeRTOS?
Lab Exercises
Questions
Feedback Form
10 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Key Takeaways
By the end of this session you will be able to:
Identify the basic RTOS concepts
Find out how RTOS can help you
Recite why FreeRTOS may be good solution for you
Identify what other RTOS vendor we partner with
11 “© 2010 Renesas Electronics America Inc. All rights reserved.”
What is Your RTOS Experience?
I have previously used an RTOS in a commercial product
I am using an RTOS in my current project
I am considering using an RTOS in the near future and
would like to get as much info as possible
I am a “Super-Loop” user and here to burn you down
12 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Some Definitions
REAL-TIME: Computing with a deadline
Hard real-time (Air bag)
Soft real-time (Adaptive volume)
TASK: Self contained code that handles a singular
functionality or semi-independent portion of an application
Process
Thread
SCHEDULER: Implements the scheduling policy
Kernel
Operating system (OS)
PRIORTY: Used in arbitration mechanism
13 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Why Use an RTOS? (1)
Abstracting timing information
Kernel is responsible for system time
Modularity
Tasks are independent modules with well defined purpose
Team development
Designers can work on different tasks simultaneously
Code reuse
Modules allow code re-use with less effort
Improved efficiency
Event driven software
Code executes only when it is needed
14 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Why Use an RTOS? (2)
Flexible interrupt handling
Short interrupt routines that detects events
Most of the work deferred to a task
Mixed processing requirements
Periodic execution
Continuous functions
Event driven processing
Real-time requirement ordering with priorities
Control over peripherals
Shared resources
Gatekeeper tasks
15 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Why FreeRTOS?
Widely used and known
Open source
Free use and distribute
Simple and easy to port
Feature rich but small size
Path to commercial versions
OpenRTOS: Full support, additional components
SafeRTOS: Functional safety, IEC 61508 compliant
More on: http://www.freertos.org/
16 “© 2010 Renesas Electronics America Inc. All rights reserved.”
What is our role with FreeRTOS?
Port FreeRTOS to Renesas MCUs
Work with FreeRTOS to qualify ports
Provide sample projects with FreeRTOS
Direct Drive LCD
Integrated Firmware Development Platform
Support by FreeRTOS
Partner with other RTOS vendors for full support
Micrium: uc/OS
Segger: embOS
CMX: CMX-RTX
18 “© 2010 Renesas Electronics America Inc. All rights reserved.”
General Notes on Lab Exercises
Refer to lab handout
Total of 8 lab exercises
Short description up
front
About 10 minutes each
Recap at end
LEDs show running task
LED4 System Tick
LED5 Task1
LED6 Task2
LED7 Task3
LED8 Task 4
LED9 Run time stats
LED10 Idle Task
“© 2010 Renesas Electronics America Inc. All rights reserved.”
19
Lab Exercise 1 - Tasks, Priorities, Task States
20 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 1 - Tasks, Priorities, Task States
APIs: xTaskCreate(), vTaskDelay(), vTaskDelayUntil(), vTaskStartScheduler()
Pre-emptive scheduling Highest priority ready task
Time slice same priority tasks
Idle task Low priority background or
continuous tasks
Spare processing time
System in low power
MUST NOT BLOCK!
Suspended
Ready
Blocked
Running
vTaskSuspend()
vTaskSuspend() vTaskResume()
vTaskSuspend()Event
Blocking API function
“© 2010 Renesas Electronics America Inc. All rights reserved.”
21
Lab Exercise 1 – You can start the lab now
22 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 1 – Recap
Time
Priority
Task1 Task2
t1 t2 t3 t4
Time
Task1 Task2
t1 t2 tn
Task3
Idle
Priority
2tn
2 tasks with same priority running to completion
3 tasks with different priorities that block
24 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 2 – Task Properties
APIs: uxTaskPriorityGet(), vTaskPrioritySet(), vTaskDelete(),
vTaskSuspend(), vTaskResume()
Task handle
Used to access to a task
Query properties
Modify properties
Suspend
Resume
Delete
“© 2010 Renesas Electronics America Inc. All rights reserved.”
25
Lab Exercise 2 – You can start the lab now
26 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 2 – Recap
Task1 is the highest priority task.
How do Task2 run?
Task1 raises priority of Task2 so it
can run. Task2 lowers its priority.
What does happen when task
priorities not changed?
Task1 becomes the only running
task
Adding a delay allows Task2 to
run. In this case Task2 runs once
because it deletes itself.
27 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 2 – Recap
Hard real time -> Higher priority
Soft real time -> Lower priority
Execution times
Processor utilization
Rate Monotonic Scheduling (RMS)
Unique priority based on the periodic execution rate
The higher periodic execution the higher the priority
Better scheduling of tasks
Not all tasks are periodic
Execution times must be considered
29 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 3 – Queue Management
APIs: xQueueCreate(), xQueueSendToBack(), xQueueSendToFront(), xQueueReceive(), uxQueueMessagesWaiting()
Communication between tasks and interrupts
Blocking API call
Not owned by a particular task Any task can write to a queue
Any task can read from a queue
Byte by byte copy of the data
Tail
Head
Tail
Head
20
Send 20
Tail
Head
2010
Send 10
Tail
10
Head
Receive 20
30 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 3 – More on Queues
Use pointers for large data Pointers queued
Some rules must be followed
Clearly define the owner of RAM Avoid simultaneous memory
modifications
Sending task accesses the memory until pointer is queued
Receiving task accesses the memory after the pointer is received from the queue
NO ACCESS IN BETWEEN!
Make sure RAM being pointed is valid DO NOT USE STACK!
Tail
Head
2010
RAM
“© 2010 Renesas Electronics America Inc. All rights reserved.”
31
Lab Exercise 3 – You can start the lab now
32 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 3 – Recap
Receiver task is the highest
priority task so it runs as soon as
data is sent to queue and
removes it. Therefore, the items
in queue is always zero.
Receiver task priority is lower
than the sender task. Sender
tasks fills the queue and can not
send anymore.
All tasks are at the same priority
so they are time-sliced.
“© 2010 Renesas Electronics America Inc. All rights reserved.”
33
Lab Exercise 4 – Interrupt Management
34 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 4 – Interrupt Management
Events Message reception
Button push
Exceeding a threshold
Detection methods Polled
Interrupt driven
Timing In the ISR
In the handler task
Semaphores links events to tasks
Let’s look at a sequence of events
Time
Task1
t1 t2 t3
ISR
Priority
Handler Task
35 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 4 – Semaphores
APIs: vSemaphoreCreateBinary(),
xSemaphoreCreateCounting(),
xSemaphoreGiveFromISR(), xSemaphoreTake()
Binary semaphore
Queue with a length of one
Always either empty or full
Counting semaphore
Event count, initial value = zero
Resource management, initial count = number of resource
TaskInterrupt gives the
semaphorexSemaphoreGiveFromISR()
TaskTaskSemaphore is available. Task
unblocks.
Another interrupt event gives the semaphore
xSemaphoreGiveFromISR()xSemaphoreTake()
Task
“© 2010 Renesas Electronics America Inc. All rights reserved.”
36
Lab Exercise 4 – You can start the lab now
37 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 4 – Recap
Binary semaphores are available after created.
Sequence of events: Periodic task causes an interrupt ISR runs and gives the semaphore ISR pends a context switch Context switches and handler
task runs Context switches back to periodic
task
Same sequence of events with counting semaphore but multiple events are captured.
“© 2010 Renesas Electronics America Inc. All rights reserved.”
38
Lab Exercise 5 – Queues and Interrupts
39 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 5 – Queues and Interrupts
APIs: xQueueReceiveFromISR(),
xQueueSendToBackFromISR(),
xQueueSendToFrontFromISR()
FromISR() APIs
Do not specify block time therefore they do not block
Do not perform context switch
Indicate if a higher priority task moves to ready state
A port specific macro causes immediate context switch
If the macro is not called in ISR:
– context switch happens at the next timer tick
“© 2010 Renesas Electronics America Inc. All rights reserved.”
40
Lab Exercise 5 – You can start the lab now
41 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 5 – Recap
Generator task sends 5 integer values to integer queue and causes an interrupt
ISR receives the integers, uses them to select strings and sends them to string queue
String tasks receives the strings and prints them out
If context switch is not scheduled within ISR, generator task runs to completion before string task runs
42 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 5 – Recap
xQueueSendToFrontFromISR() API
Back / Front same as FIFO / LIFO
Notice the difference in the sequence of strings
SendToBack SendToFront
“© 2010 Renesas Electronics America Inc. All rights reserved.”
43
Lab Exercise 6 – Resource Management
44 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 6 – Resource Management
Resource sharing/Peripheral access
LCD, standard IO, memory
Read/Modify/Write operation
Non-atomic operations
Non-atomic access to variables
Multiple member of a structure
32-bit access on a 16-bit device
Reentrant Functions
Safe to call from more than one task/interrupt
No data access other than on the stack or registers
45 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 6 – Best Practices
Do not share resources
Use mutual exclusion when accessing a shared
resource
Access a resource only from a single task
RTOS tools for resource management
Creating critical sections
– taskENTER_CRITICAL()
Suspending the scheduler
– vTaskSuspendAll()
Make use of mutexes
Designing gatekeeper tasks
46 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 6 – Mutual Exclusion = Mutexes
APIs: xSemaphoreCreateMutex(), xSemaphoreTake(),
xSemaphoreGive()
Special type of binary semaphore
Used to control a shared resource
A task “takes” the mutex before accessing the resource
No other tasks can use the resource when mutex is taken
The task “gives” the mutex back after it is done
Resource is now available to other tasks
Works as longs as all agree with these rules
DO NOT COME IN FROM THE BACK DOOR!
“© 2010 Renesas Electronics America Inc. All rights reserved.”
47
Lab Exercise 6 – You can start the lab now
48 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 6 – Recap
Print 2 is a higher priority
tasks and preempts Print 1
task corrupting the output
Why we did not see this in
previous exercises?
No corruption in the output
when mutex is used
“© 2010 Renesas Electronics America Inc. All rights reserved.”
49
Lab Exercise 7 – Priority Inversion, Inheritance
50 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 7 – Priority Inversion, Inheritance
Time
LP Task
t1 t2 t3
HP Task
MP Task
t5 t6
Priority Inversion: HP task delayed by LP and MP tasks
Time
LP Task
t1 t2 t3
HP Task
MP Task
t5t4
Priority Inheritance: LP task raises its priority to HP task priority
“© 2010 Renesas Electronics America Inc. All rights reserved.”
51
Lab Exercise 7 – You can start the lab now
52 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 7 – Recap
Initially, LP task takes the
resource, and resumes MP task
MP task takes 8 seconds to
complete
HP task attempts to run every 1
second but it blocks waiting for
the resource
LP task’s priority raises to HP
task level and gives the resource
back with no delay
HP task runs every 1 second
8 seconds delay
HP task runs about 8
times between LP
task executions
No delay
54 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 8 – Gatekeeper Tasks
Gatekeeper tasks has sole ownership of a resource
Only the gatekeeper tasks accesses the resource
Other tasks access the recourse through the services
provided by the gatekeeper
Things to consider when creating gatekeeper tasks
Up front system design
Agree on services and interfaces
Allow for future expansion/changes
Always use the services to access the resource
“© 2010 Renesas Electronics America Inc. All rights reserved.”
55
Lab Exercise 8 – You can start the lab now
56 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Lab Exercise 8 – Recap
Print 1, Print 2 tasks and an interrupt service routine
use the services of a gatekeeper task
Gatekeeper task uses a queue as an interface
No corruption with the print out
57 “© 2010 Renesas Electronics America Inc. All rights reserved.”
Innovation
Renesas is here to help you to create your next
innovation. Let’s build it together!