CO3053 - Lecture 5 - Embedded Programming Paradigms
CO3053 - Lecture 5 - Embedded Programming Paradigms
§ Round Robin
§ Round Robin with Interrupt
Event-Driven and Time-Driven
§ Real Time Operating System
CO3053 – Lecture Notes 2
Contents
§ Round Robin & Round Robin with Interrupts
§ Real-Time Operating System
[email protected]
CO3053 – Lecture Notes 3
Round Robin
§ Simplest architecture, a single loop checks devices in predefined sequence and
performs I/O right away
§ Works well for system with few devices, trivial timing constraints,
proportionally small processing costs
§ Response time of device i equal to WCET (Worst Case of Execution Time) of
the body of the loop
[email protected]
CO3053 – Lecture Notes 4
Round Robin
§ Periodic Round Robin
In case the system must perform operations at different frequencies
Add code to wait a variable amount of time
§ Exercise
Think how to implement a loop that runs every 10ms and measures the drift
[email protected]
CO3053 – Lecture Notes 5
Round Robin
§ Limitations
If some devices require small response times, while other have large WCET
it will not be possible to guarantee that all timing constraints will be met.
The architecture is fragile, adding a new task can easily cause missed
deadlines.
§ Question
Is the order in which devices appear significant?
Same above question, but with code for devices having different processing
times and timing constraints?
[email protected]
CO3053 – Lecture Notes 6
[email protected]
CO3053 – Lecture Notes 7
§ Drawbacks
Shared-data problems arise
Time response for a non-urgent task
duration of the main loop + interrupts
[email protected]
CO3053 – Lecture Notes 8
Shared-data problems
[email protected]
CO3053 – Lecture Notes 9
[email protected]
CO3053 – Lecture Notes 10
[email protected]
CO3053 – Lecture Notes 11
[email protected]
CO3053 – Lecture Notes 12
[email protected]
CO3053 – Lecture Notes 14
Selection Strategy
§ We want to obtain the greatest amount of control over the
system response time ➠ Select the simplest architecture that
will meet your response requirements.
[email protected]
CO3053 – Lecture Notes 15
Discussion
§ Simple video game (such as PONG)
What has to be considered?
Display the image (PAL signal: 625 lines @ 50Hz)
Game management (i.e. compute the position of the ball)
Game control (buttons, controller)
[email protected]
CO3053 – Lecture Notes 16
Discussion
§ Vending Machine
What has to be considered?
Display information
Handle buttons & coin acceptor
Check sensors
Motors control
[email protected]
CO3053 – Lecture Notes 17
Discussion
§ Vehicle embedded electronics
What has to be considered?
Sensor measurement (pedal, speed, switches, …)
Engine control (ignition, turbo, injection, cooling system, …)
Cruise-control
Display
GPS
[email protected]
CO3053 – Lecture Notes 18
[email protected]
Miscellaneous Topics for
Efficient C Programming
CO3053 – Lecture Notes 20
[email protected]
CO3053 – Lecture Notes 21
[email protected]
CO3053 – Lecture Notes 22
[email protected]
CO3053 – Lecture Notes 23
[email protected]
CO3053 – Lecture Notes 24
[email protected]
CO3053 – Lecture Notes 25
[email protected]
CO3053 – Lecture Notes 26
Pointers
§ Reference to a data object or a
function
Pointers Example
firstvalue = ?
secondvalue = ?
[email protected]
CO3053 – Lecture Notes 28
Pointers Example
[email protected]
CO3053 – Lecture Notes 29
[email protected]
CO3053 – Lecture Notes 30
[email protected]
CO3053 – Lecture Notes 31
[email protected]
CO3053 – Lecture Notes 32
[email protected]
CO3053 – Lecture Notes 33
Efficient C Programming
§ How to write C code in a style that will compile efficiently (increased
speed and reduced code size) on ARM architecture?
References
§ A.N. Sloss, D. Symes, and C. Wright, “ARM System Developers Guide”
[email protected]
Debugging
David J. Agans
CO3053 – Lecture Notes 36
Debugging
David J. Agans
[email protected]
CO3053 – Lecture Notes 37
[email protected]
CO3053 – Lecture Notes 38
[email protected]
CO3053 – Lecture Notes 39
[email protected]
CO3053 – Lecture Notes 40
§ Isolate factors, because that is how you get experiments that tell you
something.
[email protected]
CO3053 – Lecture Notes 42
[email protected]
CO3053 – Lecture Notes 43
[email protected]
CO3053 – Lecture Notes 45
§ A bug is not done until the fix is in place and confirmed to actually fix
the problem.
You might have just understood a symptom, not the underlying problem
[email protected]
CO3053 – Lecture Notes 46
Summary
1. Understand the system
2. Make It Fail
3. Quit Thinking and Look
4. Divide and Conquer
5. Change One Thing at a Time
6. Keep An Audit Trail
7. Check The Plug
8. Get A Fresh View
9. If You Didn’t Fix It, It ain’t Fixed