Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of...
Transcript of Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of...
![Page 1: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/1.jpg)
Embedded Software
Koen Langendoen(Stefan Dulman, Arjan v. Gemund)
Embedded Software Group
TI2725‐C
1. Introduction
![Page 2: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/2.jpg)
Embedded System – Definition Many different definitions, some of them:
a computer system with a dedicated function within a larger mechanical or electrical system
…, often with real‐time computing constraints A computing system that fulfills the task of monitoring and controlling the technical context
Without the computing system, the whole system is useless
2
![Page 3: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/3.jpg)
Examples
3
![Page 4: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/4.jpg)
In use by the ES group
4
NEAT power logger
PowerCastQuadcopter / Emb. RTS
SOWNet G‐Node
![Page 5: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/5.jpg)
Embedded Software – Definition
Many different definitions, some of them: computer software written to control machines or devices that are not typically thought of as computers
A computer program that fulfills the task of monitoring and controlling the technical context
Without the right firmware, the whole system is useless
5
![Page 6: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/6.jpg)
In this course …
You will learn about: Programming of embedded system Real‐time programming with RTOSs
We will explore: Principles of “good” embedded systems design Time and complexity
Use the tool chain for X32 on an FPGA
6
![Page 7: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/7.jpg)
Course setup2012-2013 TI2720-C 2013-2014 TI2725-C
Credit points 4 EC 5 ECLectures 6 8Lab work FPGA C + FPGAExam Chap 1, 4-10 Chap 1, 4-10
7
![Page 8: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/8.jpg)
The book
Chapter 1,2,3 – Introduction to embedded systems (today) Chapter 4 – Interrupts Chapter 5 – Survey of software architectures Chapter 6 – Introduction to RTOS Chapter 7 – More OS services Chapter 8 – Basic design with RTOS (Chapter 9 – Toolchain)
8
![Page 9: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/9.jpg)
ES Example – Telegraph
9
![Page 10: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/10.jpg)
ES Example – Telegraph
Out‐of‐order data Negotiate with multiple clients (print jobs) + status reqs. Adapt to different printers Response time to certain requests Data throughput / buffering Debugging and software updates
Telegraph is more
complex than anticipated!
10
![Page 11: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/11.jpg)
Underground Tank Monitoring Sys.
Guard levels, detect leaks Extremely low‐cost design (proc) Very simple arithmetic CPU ‐ response time problem Model of normal drainage vs. leaking drainage
tank 1 tank N
Emb Sys
buttons LCDdisp
printer. . .
level CHlevel H2Otemperature
11
![Page 12: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/12.jpg)
Cruise Control System (Lab Project)
Stabilize car speed when engaged Extremely low processor cycle budget Small control loop jitter due to other activities Reliable operation
speedometer
gas pedal
EmbeddedCC System
buttons SSD
Current speed
Set/release ccStep up/down
current speedset speed
Motor/Drivetrain
AdjustSpeed
Throttle
Speed
12
![Page 13: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/13.jpg)
Characteristics of Embedded Sys.
No / restricted user interface Specific connectors for sensors/actuators Restricted memory size and processing power Predictable timing behavior Suitable for extreme operation environments
13
![Page 14: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/14.jpg)
Typical Platform for ES
Microcontroller 8 bit RISC Processor EEPROM & RAM UART (serial line) Timer A/D converter Digital I/O Lines
14
![Page 15: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/15.jpg)
Typical Platform for ES
PC/104 Typical PC platform Flash, RAM, Drives Many possible connectors and interfaces
Many available OSs
15
![Page 16: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/16.jpg)
A different example ‐ kilobot
16M. Rubenstein - KiloBot: A Robotic Modules for Demonstrating Collective Behaviors, ICRA2010
![Page 17: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/17.jpg)
Another Typical Platform for ES
17
![Page 18: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/18.jpg)
Advantages of FPGA
Flexibility Build your own hardware (I/O) Dedicated platform for changing contexts
High‐level programming Soft‐Core X32 www.opencores.org
Soft‐Cores for arithmetic, communication controllers, cryptography, digital signal processing, microprocessors, etc ...
18
![Page 19: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/19.jpg)
Break
![Page 20: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/20.jpg)
Embedded Systems Boom Provides functionality (intelligence) of almost everything Annual growth 25‐60% (Emb Linux > 60%) 100 x PC market Accounts for 25‐40% costs in automotive Very large societal dependence Very high performance demands More and more integration of systems
www.linuxdevices.com
20
![Page 21: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/21.jpg)
Embedded Software Boom
Software is more and more executed on standard hardware
Accounts to a large extent for the Product functionality Intelligence / smartness User ergonomics & look and feel
Has an increasing added value Increased volume and complexity
50% DevelopmentCost for Software
alone!
90% of the InnovationsComing from Electronics
& Software21
![Page 22: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/22.jpg)
CAN‐Netw. Devices in a VW Phaeton
22
![Page 23: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/23.jpg)
Embedded Software Crisis Functionality migrates from HW to SW Standard cores combined with FPGAs, rather than ASICs Programming‐centred design (incl. HDLs) TV, mobile, car, .. 10+ MLOC code, exp. growth! Despite SW engineering: 1 – 10 bug / KLOC 100 Billion $ / yr on bugs (Mars Polar Lander, Mars Climate Orbiter, Ariane 5, Patriot, USS Yorktown, Therac‐25, ... )
23
![Page 24: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/24.jpg)
A new Embedded Software crisis?
24
![Page 25: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/25.jpg)
Embedded Programming
More difficult than “classical” programming Interaction with hardware Real‐time issues (timing) Concurrency (multiple threads, scheduling, deadlock) Need to understand underlying RTOS principles Event‐driven programming (interrupts)
Lots of (novice) errors (hence the crisis) That’s why we have this course already in 2nd year!
25
![Page 26: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/26.jpg)
Embedded Programming Example Automatic sliding gate task (thread):
for (;;) {// wait to openwhile (inp(sensor) != 1) ; out(door,OPEN);// wait to closewhile (inp(sensor) == 1) ; sleep(1000);// close after timeoutout(door,CLOSE);
}
Any issues with this code?
26
![Page 27: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/27.jpg)
Specification: Finite State Machine
Red arc missing from the specification Door can slam in your face!
s’sss’ s’
t
out(door,open)
out(door,close)
sleep(1000)//wait to close
//wait to open
standby open timings
27
![Page 28: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/28.jpg)
Door Controller in VHDL VHDL: FSM in entity door_controller Advantages
Separate hardware: no sharing of a processor(no scheduling, no priorities)
Fast and synchronous programming model: high frequency clocked process with simple polling for s and t
Disadvantages VHDL too cumbersome / prohibitive for large applications Lots of legacy code written in C
28
![Page 29: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/29.jpg)
A VHDL Solutionprocess -- fsmbegin
wait until rising_edge(clk);case state is
when S0 => if (s = ‘1’) thenstate <= S1;
when S1 => if (s = ‘0’) thenstate <= S2;
when S2 => if (s = ‘1’) then – red arc in FSMstate <= S1;
if (t = ‘1’ and s = ‘0’) thenstate <= S0;
end case;door <= ‘1’ when (state != S0) else ‘0’;timer_enable <= ‘1’ when (state = S2) else ‘0’;
end process; 29
![Page 30: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/30.jpg)
A C Implementation C: FSM in a task door_controller Advantages
simple (sequential) programming model Disadvantages
can’t be invoked periodically by a high‐frequency clock (timer) because of polling overhead
busy waiting (polling) is not an option (see above) ‐> concurrent (event) programming (e.g., using interrupts and semaphores)
So the while loops in the example code are wrong Only use a delay that is not based on busy wait Ergo: interrupt programming, using an RTOS
30
![Page 31: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/31.jpg)
A better (but not ideal) C Solutionvoid isr_sensor(void) // process sensor IRQ{ OS_Post(semaphore_event_on_s); // signal s changed
}
void task_door_controller(void) {for (;;) {OS_Pend(semaphore_event_on_s); // wait for s = 1out(door,OPEN);do {OS_Pend(semaphore_event_on_s); // wait for s = 0OS_Delay(1000);
} while (inp(sensor) != 0); // timeoutout(door,CLOSE);
}}
31
![Page 32: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/32.jpg)
Issues
Efficient, no busy waiting any more (OS_Pend, OS_Delay) Still, code is not correct: interrupts (entering/leaving persons within delay period are not properly handled, and are only accumulated in semaphore (wrong)
Cannot afford to just “sit” in a delay, AND ... The ability to simultaneously wait for two events (s or t):
void isr_sensor_and_timer(void) { // handle both IRQsOS_Post(s_or_t); // either s or t
} // changed32
![Page 33: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/33.jpg)
Alternative C Solutionvoid task_door_controller(void) {
for (;;) {switch (state) {
STDBY: OS_Pend(s_or_t); // wait for 0-1out(door,OPEN);state = OPEN;
OPEN: OS_Pend(s_or_t); // wait for 1-0timer_enable();state = TIMING;
TIMING: OS_Pend(s_or_t); // wait 0-1 || tif (inp(sensor) == 0) { // timeoutout(door,CLOSE);timer_disable();state = STDBY;
} else state = OPEN;}}} 33
![Page 34: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/34.jpg)
Course Organization Grade = 0.7 exam + 0.3 lab
Lectures (tutti) – weeks 3.1, 3.2, 3.3, 3.4 Monday, 13.45 – 15.30 Tuesday, 10.45 – 13.30
C programming (solo) – weeks 3.1, 3.2, 3.3 Thursday, 08.45 – 12.30
FPGA Lab (duet) – weeks 3.4, 3.5, 3.6 Mandatory presence! Wednesday 13:45 – 17:30 XOR Thursday 08:45 – 12:30
34
![Page 35: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/35.jpg)
Example exam question
The “Embedded Software Crisis” refers to:a) the “year 2000” bug b) the rising price of the embedded systems c) the lack of correct code for the increasing number of
embedded systems d) the decrease in the number of manufactured
embedded systems
35
![Page 36: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/36.jpg)
Lab: C programming Language
C‐syntax, pointers, memory management, …
Tools Gdb, valgrind
Assignment (graded) Hash table with bucket lists
36
![Page 37: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/37.jpg)
Lab: Cruise Control http://auto.howstuffworks.com/cruise‐control.htm Engage button: engage cruise control Inc button: increment throttle or cruising speed Dec button: decrement throttle or cruising speed Speed and throttle on SSD Monitor link to PC terminal (status, logging, ..)
throttle
speed
vehiclecontroller
inc/dec
engage
37
![Page 38: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/38.jpg)
Cruise Control Setupm
(speed)
(vehicle)
Embed. Syst.
(FPGA board)ab
(throttle)
PC host(Linux)
encoder(HEDL 5540)
DC motor
38
![Page 39: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/39.jpg)
Conclusion Embedded programming is not so easy Neither in C nor VHDL C:
Concurrency needed (seq. prog. model): RTOS support Event programming needed: interrupts + RTOS support
Learn the basics of interrupt programming & RTOS (in C) Learning is (lots of) programming! Lab: simple Cruise Control subsystem Hardware: FPGA board with 32 bit soft core + C tools
39
![Page 40: Embedded Software - TU Delft · Embedded System –Definition Many different definitions, some of them: a computer system with a dedicated function within a larger mechanical or electrical](https://reader033.fdocuments.net/reader033/viewer/2022060421/5f17be835161820b62179e52/html5/thumbnails/40.jpg)
Enrollment Register at Blackboard
Lecture slides, etc. Announcements
C programming (solo) Tutorial (wk 1) – WebLab, self registration Tools (wk 2) + assignment (wk 3) – CPM, mail (name, NetID) to [email protected]
FPGA programming (duet) CPM submission system mail (names, NetIDs, wed/thu blackouts) to [email protected]
40