From bare metal C to an industry grade Open Source Real-Time Operating System.
Course Objectives
A “know-how upgrade” for a bare-metal microcontroller C programmer to an industry-grade Open Source real-time operating system.
- What are the advantages?
- What is the trade-off?
Hands-on exercises provide you with the necessary practical experience to go ahead and use a real-time operating system with your own embedded system after successfully completing this training.
Description
This 3-day class illustrates the concepts of a real-time operating system. FreeRTOS will be used as an example. It is designed to bring you quickly up to speed. The concepts and commands necessary to make effective use of FreeRTOS are described through a combination of theory and practical examples. Don’t reinvent the wheel, but learn from an experienced trainer and take home a working knowledge of FreeRTOS and the ability to use it effectively in your own embedded development project.
Prerequisites
- depending on host
- basic familiarity with using a GNU/Linux system as an end-user
- (Trainer will use Ubuntu as a host system)
- basic C programming knowledge
Course Roadmap
Who should attend?
People with interest in or tasked with the development of a resource-constrained real-time system like software engineers, field engineers, (project) managers,. . .
Course Outline
Day 1
Introduction
- Introduction
|
Licensing|
FreeRTOS Licensing|
Real-Time Intro (Time/Utility
functions|
What is real-time?|
Determinism|
What is hard real-time?)|
RTOS vs. Linux|
IDE/Board
Task Management
- Intro (What is a
task
?|
Task
creation)Example01
– crude loopExample02
–task
parametersExample03
–task
priorities (starvation
)Example04
–vTaskDelay()
(idle task
)Example05
–vTaskDelayUntil()
Example06
– “continuous processing” andvTaskDelayUntil()
Example07
–idle hook
Example08
– play with prioritiesExample09
–task
delete
Scheduling
(What’s an OS?|
What’s atask
?|
What’s ascheduler
?)Schedulers
(loop|
cyclic executives
|
limitations ofcyclic executives
|
manual
preemption
|
with interrupts|
non-/preemptive|
prioritized preemptive|
rate monotonic
|
deadline
|
cooperative
|
hybrid
)
Queue Management
- Intro (What is a queue?
|
Queue as a data type)|
Queue Management (Data storage|
Accessed by multipletasks
|
blocking on read/write|
InterTask
Communication|
Example Queue Access)Example10
– queue send/receive (Client/Server pattern)Example11
– queues/idle task
- Working with Large Data
|
Message Passing Generic (Indirect/Direct Synchronous/Asynchronous)
Day 2
Interrupt Management
- Intro (
Interrupt
vs.Polling
|
How does anInterrupt
work?|
Hardware/SoftwareInterrupts
|
What if twointerrupts
arrive at the same time?|
Program Sections|
What is reentrant code?|
What is anevent
?|
What kind of “events” do you know?) - Concurrency Intro
- Semaphores Intro (Mutual exclusion
|
Synchronization)|
Mutex vs. Synchronization|
Sempahore Types (Signal/Wait
Pattern|
Binary Semaphore|
FreeRTOS Binary Semaphore|
Counting Semaphore)
- Semaphores Intro (Mutual exclusion
Events
Intro|
Interrupt
Handlers|
Interrupt
Processing (Deferred)|
Synchronize aTask
with an “Interrupt”Example12
– deferred ISR + Binary Semaphore (Binary Semaphore API)Example13
– deferred ISR + Counting Semaphore (Binary Semaphore vs. Counting Semaphore – Events latched|
Counting Semaphore API)Example14
– deferred ISR + Queues (Queues and ISRs – API|
Inefficient Queue Usage|
More efficient Queue usage)
Interrupt nesting
(NVIC Cortex M3|
LPX17xx NVIC|
CMSIS|
FreeRTOS andinterrupt nesting
|
priorites)
Resource Management
- Intro (concurrency
|
critical regions/sections|
atomic|
race condition
|
Thread safety
|
the single variable|
locking|
Kinds/Causes of Concurrency|
What does need/not need protection?|
Deadlock|
order ofLocks
|
Contention
) - Resource Management (Potential conflict – accessing things concurrently
|
read/modify/write|
non-atomic access|
reentrancy
|
shared resource protection) - Protecting critical regions/sections (Dis-/enabling interrupts
|
suspending/locking the scheduler|
Mutex)Example15
– Mutex (Mutex API)
- Priority inversion (Unbounded/
Bounded
|
Sources of unbounded priority inversion|
Solutions?|
Priority Inversion and FreeRTOS)|
Deadlock (Conditions for Deadlock|
Prevention)|
Gate-keeper
Tasks
Example16
–Gate-keeper
(vApplicationIdleHook()
vs. priority 0)
- Mutex vs. Semaphore (Ownership/Recursive Mutex)
|
History
Memory Management
- Memory types
|
Fragmentation|
Memory exhaustion
|
Memory allocation patterns (Fixed/Static|
Variable/Dynamic|
Stack Allocation, Scratch-pad|
Memory Pool)|
FreeRTOS Static Allocation|
FreeRTOS Dynamic Allocation – FreeRTOS Heap|
(Why notmalloc()
/free()
|
Memory Management Portingheap_1/3/3/4/5.c
)|
xPortGetFreeHeapSize()
Day 3
Trouble Shooting
- Intro (What’s a bug/debugging
|
Types ofbugs
|
Debugging strategy)|
Preventing Bugs (Coding Wars|
Productive Working Environment|
Build Environment
|
Reuse)|
Spelunking (find(1)
,grep(1)
,cscope(1)
,global(1)
,…)|
Modeling/Abstraction|
Prototypes|
Training|
Requirements/Architecture/Design (Design for Test|
Firmware Standard|
Code Review)|
Debugging (GNU toolchain) - Debugging by Stopping (Simulator
|
JTAG Debugging|
RTOS aware debugger)Example17
–Queue Table
- Debugging Running System (Hardware Exceptions
|
Stack
)Example18
–vApplicationStackOverflowHook()
/uxTaskGetStackHighWaterMark()
Example19
– FreeRTOS HeapMallocFailedHook()
Example20
– FreeRTOStask
statisticsExample21
– FreeRTOS run-time statictics
- Profiling (
gprof | gcov
)|
Other methods (Hardware Trace|
Software controlled LEDs|
Oscilloscope|
Logic Analyzer|
7-Segment Display|
Character-based LCD|
Graphic Display)|
FreeRTOSTrace hook macros
Example22
– FreeRTOS trace hook macros 1Example23
– FreeRTOS trace hook macros 2
- FreeRTOS: Common sources of error
FreeRTOS-MPU
- Intro (Memory Management
|
Processor Modes)|
FreeRTOS MPU (LPC17xx MPU|
Access Permissions|
FreeRTOS-MPU API|
from Privileged to User mode|
Linker Configuration|
Practical Usage Tips|
intertask
communication)Example24
– FreeRTOS MPU (Where was the crash?)
Traffic Light controller
- Traffic light controller – use what we learned so far
Example40
– Traffic light controller (Compile and execute|
Heartbeat task|
FSM task|
UserInput-Val|
Pedestrian)
Related Courses
- ”Embedded Linux – From System Architecture to Real-Time (5 days)”
- ”Refresher to Embedded Linux & Intro to the Yocto Project (5 days)”
- ”Embedded Linux Kernel Internals and Device Drivers (5 days)”
- “The Yocto Project – A thorough Overview (4 days)”
- ”Introduction to Embedded Linux & Real-Time, bird’s eye view of the Yocto Project (4 days)”
- ”Introduction to Embedded Linux in Theory and Practice – a Crash Course (3 days)”
- ”(Embedded) Linux debugging (3 days)”