This document contains notes from a lecture on real-time operating systems and embedded systems. Some key points:
- A real-time operating system manages resources like memory, I/O, tasks and threads to guarantee timing constraints and meet deadlines.
- The lecture will cover topics like I/O, thread management, synchronization, scheduling, interrupts and file systems through a series of labs using a Tiva microcontroller and education booster pack.
- An overview of the ARM architecture is provided, including registers, memory mapping, instruction set, conditional branches, loops and calling conventions for passing parameters between functions.
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
What Is a Real Time Operating System
1. Fall 2018 - ECE 5436
Lecture 1
Harry Le, PhD
Valvano, Le
2. What Is a Real Time Operating System
• Involved from a collection of executives
• Complexity grows
• Becomes a manager of resources. Manages memory, I/O, tasks, threads
• Performance metrics:
• Deadline
• Reliability
• Threat synchronization
• Software evolution
• Porting
• Different from the general purpose OS
Valvano, Le
3. Overview of the labs
1. Introduction to I/O using the BSP and debugging,
• Learn about Keil compiler and debugger
• Understand what the MK-II boosterpack measures
• Learn how to perform timing profiles of the software system
2. Thread management for a personal fitness device
• Multiple threads
• Real-time periodic threads
• Spinlock semaphores
• Round robin scheduler
3. Thread synchronization and scheduling for a personal fitness device
• Timer-based real-time threads
• Thread sleeping
• Blocking semaphores with first come first serve scheduler
Valvano, Le
4. Overview (cont.)
4. Real-time operating system for a hand-held video game
• Edge triggered interrupts
• Blocking semaphores with priority scheduler
5. File system using the flash ROM of the microcontroller,
• Logging data onto flash/playback of data
6. Bluetooth personal area network.
• Interacting with the device from a smart phone
• Wifi
• IoT
Valvano, Le
5. Keil
• Keil version 5: https://www.keil.com/demo/eval/arm.htm
Since Keil version 5 does not support Stellaris ICDI interface, you need to
install this addon to use it with the Tiva C
http://www.keil.com//files/download/MDK_Stellaris_ICDI_AddOn.exe
6. Lab Parts
• Many electronic stores like TI, Mouser, etc. carry the following parts
• Education Booster Pack BOOSTXL-EDUMKII
https://www.ti.com/store/ti/en/p/product/?p=BOOSTXL-EDUMKII
• Tiva C EK-TM4C123GXL
• https://www.ti.com/store/ti/en/p/product/?p=EK-TM4C123GXL
• You need to remove resistor R9 and R10 of the Tiva C for it to work properly
with the Education Booster Pack
• BOOSTXL-CC2650MA
https://www.ti.com/store/ti/en/p/product/?p=BOOSTXL-CC2650MA
Valvano, Le
8. RTOS
• Computer Architecture: memory, I/O, data, processors
• RTOS:
• manages those resources
• Guarantee timing constraints
• Support synchronization and communication between tasks
• Portability: build a new system by changing an old one.
• A software layer between the application software and the hardware
Valvano, Le
9. Regular OS versus RTOS
Regular OS Real-time OS
Complex Simple
Best effort Guaranteed response
Fairness Strict timing constraints
Average bandwidth Minimum and maximum limits
Unknown components Known components
Unpredictable behavior Predictable behavior
Plug and play Upgradable
Valvano, Le
11. Common Misconceptions
• Real-time systems are synonymous with “fast” systems.
• Rate-monotonic analysis has solved “the real-time problem.”
• There are universal, widely accepted methodologies for real-time
systems, specification and design.
• There is never a need to build a real-time operating system, because
many commercial products exist.
• The study of real-time systems is mostly about scheduling theory.
Laplante, Valvano, Le
12. Lecture 1 (cont.)
• An embedded system is a smart device with a processor that has a special
and dedicated purpose. The user usually does not or cannot upgrade the
hardware/software or change what the system does.
• Real time means that the embedded system must respond to critical
events within a strictly defined time, called the deadline.
• Five types of software functions the processor can perform in an
embedded system.
• Mathematical and/or data processing operation and analyze data and make decisions
based on the data.
• Handling and managing time: as an input (e.g., measure period), an output (e.g.,
output waveforms), and a means to synchronize tasks (e.g., run 1000 times a
second).
• Real-time input/output for the purpose of measurement or control.
• Digital signal processing (DSP), which are mathematical calculations on data streams.
• Communication and networking.
Valvano, Le
14. Lecture 1 (cont.)
• Constraints of an embedded system:
• Test and verify
• Safety critical systems
• Low cost
• Low power
• Handheld
• Small weight
• Performance: correct and in time
• Harsh environment
Valvano, Le
17. Microcontroller
• Contains all components of a computer on a single chip
• Example: TivaC TI TM4C123, MSP432
• Have instruction pipeline
• ARM Cortex-M: Harvard architecture
Valvano, Le
19. ARM Architecture Procedure Call Standard,
AAPCS
• The ARM Architecture Procedure Call Standard, AAPCS, part of the
ARM Application Binary Interface (ABI),
• Uses registers R0, R1, R2, and R3 to pass input parameters into a C function or
an assembly subroutine. Also according to AAPCS we place the return
parameter in Register R0.
• Functions save R4-R11, use R4-R11, and then restore R4-R11 before returning.
• Keep the stack aligned to 64 bits, by pushing and popping an even number of
registers.
Valvano, Le
21. Stacks
• Last-in-first-out temporary storage
• To push data we first decrement the SP by 4 then store 32-bit data at
the SP.
• To pop data from the stack, the 32-bit information pointed to by SP is
first retrieved, and then the stack pointer is incremented by 4.
Valvano, Le
22. ARM ISA: Registers, Memory-map
TI TM4C123
Microcontroller
Condition Code Bits Indicates
N negative Result is negative
Z zero Result is zero
V overflow Signed overflow
C carry Unsigned overflow
23. ARM Assembly Language
• Four fields
• Labels (optional)
• Opcodes or pseudo-ops:
• LDR STR MOV PUSH POP B BL BX ADD SUB CPSID and CPSIE
• AREA EQU IMPORT EXPORT and ALIGN
• Operands
• Comments (optional)
Valvano, Le
24. Conditional Branch Instructions
❑Unsigned conditional branch
❖follow SUBS CMN or CMP
BLO target ; Branch if unsigned less than (if C=0, same as BCC)
BLS target ; Branch if unsigned less than or equal to (if C=0 or Z=1)
BHS target ; Branch if unsigned greater than or equal to
(if C=1, same as BCS)
BHI target ; Branch if unsigned greater than (if C=1 and Z=0)
CMP R0,R1
BLO
R0<R1
target
Next instruction
R0≥R1
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
25. Conditional Branch Instructions
❑Signed conditional branch
❖follow SUBS CMN or CMP
BLT target ; if signed less than (if (~N&V | N&~V)=1, i.e. if N≠V)
BGE target ; if signed greater than or equal to (if (~N&V | N&~V)=0, i.e. if N=V)
BGT target ; if signed greater than (if (Z | ~N&V | N&~V)=0, i.e. if Z=0 and N=V)
BLE target ; if signed less than or equal to
(if (Z | ~N&V | N&~V)=1, i.e. if Z=1 or N≠V)
CMP R0,R1
BLT
R0<R1
target
Next instruction
R0≥R1
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
26. Equality Test
Program 5.8. Conditional structures that test for equality.
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
27. Unsigned Conditional Structures
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Program 5.9. Unsigned conditional structures.
Valvano, Le
28. Signed Conditional Structures
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Program 5.11. Signed conditional structures.
Valvano, Le
30. While Loops
LDR R4, =G1 ; R4 -> G1
LDR R5, =G2 ; R5 -> G2
loop LDR R0, [R5] ; R0 = G2
LDR R1, [R4] ; R1 = G1
CMP R0, R1 ; is G2 <= G1?
BLS next ; if so, skip to next
BL Body ; body of the loop
B loop
next
uint32_t G1,G2;
while(G2 > G1){
Body();
}
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
31. For Loops
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
32. For Loops
MOV R4, #0 ; R4 = 0
loop CMP R4, #100 ; index >= 100?
BHS done ; if so, skip to done
BL Process ; process function*
ADD R4, R4, #1 ; R4 = R4 + 1
B loop
done
for(i=0; i<100; i++){
Process();
}
MOV R4, #100 ; R4 = 100
loop BL Process ; process function
SUBS R4, R4, #1 ; R4 = R4 - 1
BNE loop
done
for(i=100; i!=0; i--){
Process();
}
Count up
Count down
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
33. Registers to pass parameters
Subroutine
3) Sees the inputs in
registers
4) Performs the
action of the
subroutine
5) Places the
outputs in registers
High level program
1) Sets Registers to
contain inputs
2) Calls subroutine
6) Registers contain
outputs
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
34. Stack to pass parameters
Subroutine
3) Sees the inputs
on stack (pops)
4) Performs the
action of the
subroutine
5) Pushes outputs
on the stack
High level program
1) Pushes inputs on
the Stack
2) Calls subroutine
6) Stack contain
outputs (pop)
7) Balance stack
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
35. Assembly Parameter Passing
❑ Parameters passed using registers/stack
❑ Parameter passing need not be done using only
registers or only stack
❖Some inputs could come in registers and
some on stack and outputs could be returned
in registers and some on the stack
❑ Calling Convention
❖Application Binary Interface (ABI)
❖ARM: use registers for first 4 parameters,
use stack beyond, return using R0
❑ Keep in mind that you may want your assembly
subroutine to someday be callable from C or
callable from someone else’s software
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
36. ARM Arch. Procedure Call Standard
(AAPCS)
❑ ABI standard for all ARM architectures
❑ Use registers R0, R1, R2, and R3 to pass the
first four input parameters (in order) into any
function, C or assembly.
❑ We place the return parameter in Register R0.
❑ Functions can freely modify registers R0–R3
and R12. If a function needs to use R4 through
R11, it is necessary to push their current
register values onto the stack, use the register,
and then pop the old value off the stack before
returning.
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
37. Parameter-Passing: Registers
Caller
;--call a subroutine that
;uses registers for parameter passing
MOV R0,#7
MOV R1,#3
BL Exp
;; R2 becomes 7^3 = 343 (0x157)
Callee
;---------Exp-----------
; Input: R0 and R1 have inputs XX an YY
; Output: R2 has the result XX raised to YY
; Comments: R1 and R2 and non-negative
; Destroys input R1
XX RN 0
YY RN 1
Pow RN 2
Exp
ADDS XX,#0
BEQ Zero
ADDS YY,#0 ; check if YY is zero
BEQ One
MOV pow, #1 ; Initial product is 1
More MUL pow,XX ; multiply product with XX
SUBS YY,#1 ; Decrement YY
BNE More
B Retn ; Done, so return
Zero MOV pow,#0 ; XX is 0 so result is 0
B Retn
One MOV pow,#1 ; YY is 0 so result is 1
Retn BX LR
❑ Suggest changes
to make it AAPCS
Return by value
Call by value
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
38. Parameter-Passing: Stack
Caller
;-------- call a subroutine that
; uses stack for parameter passing
MOV R0,#12
MOV R1,#5
MOV R2,#22
MOV R3,#7
MOV R4,#18
PUSH {R0-R4}
; Stack has 12,5,22,7 and 18
; (with 12 on top)
BL Max5
; Call Max5 to find the maximum
;of the five numbers
POP {R5}
;; R5 has the max element (22)
Callee
;---------Max5-----------
; Input: 5 signed numbers pushed on the stack
; Output: put only the maximum number on the stack
; Comments: The input numbers are removed from stack
numM RN 1 ; current number
max RN 2 ; maximum so far
count RN 0 ; how many elements
Max5
POP {max} ; get top element (top of stack)
; store it in max
MOV count,#4 ; 4 more to go
Again POP {numM} ; get next element
CMP numM,max
BLT Next
MOV max, numM ; new numM is the max
Next SUBS count,#1 ; one more checked
BNE Again
PUSH {max} ; found max so push it on stack
BX LR
❑ Flexible style, but not AAPCS
Return by value
Call by value
Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi, Tiwari
Valvano, Le
39. Parameter-Passing: Stack & Regs
Caller
;------call a subroutine that uses
;both stack and registers for
;parameter passing
MOV R0,#6 ; R0 elem count
MOV R1,#-14
MOV R2,#5
MOV R3,#32
MOV R4,#-7
MOV R5,#0
MOV R6,#-5
PUSH {R4-R6} ; rest on stack
; R0 has element count
; R1-R3 have first 3 elements;
; remaining on Stack
BL MinMax
;; R0 has -14 and R1 has 32
;; upon return
❑ Not AAPCS
Callee
;---------MinMax-----------
; Input: N numbers reg+stack; N passed in R0
; Output: Return in R0 the min and R1 the max
; Comments: The input numbers are removed from stack
numMM RN 3; hold the current number in numMM
max RN 1 ; hold maximum so far in max
min RN 2
N RN 0 ; how many elements
MinMax
PUSH {R1-R3} ; put all elements on stack
CMP N,#0 ; if N is zero nothing to do
BEQ DoneMM
POP {min} ; pop top and set it
MOV max,min ; as the current min and max
loop SUBS N,#1 ; decrement and check
BEQ DoneMM
POP {numMM}
CMP numMM,max
BLT Chkmin
MOV max,numMM ; new num is the max
Chkmin CMP numMM,min
BGT NextMM
MOV min,numMM ; new num is the min
NextMM B loop
DoneMM MOV R0,min ; R0 has min
BX LR
Valvano, Le
40. Object code
• Assembler translate source code into object code, which are machine
instructions executed by the processor
• Object code is halfword-aligned.
• Thumb-2 instructions can be 16 or 32 bits wide. Program counter (PC)
bit 0 is always 0.
Valvano, Le
41. Booster Pack
• Button 1 function
• Button 2 function
• Joystick
• Beeping
• Sensors: accelerometer, microphone, LCD, Light, temperature
Valvano, Le
56. Valvano, Le
Figure 6.20 shows a CC2650 BoosterPack. This board comes preprogrammed with the simple network processor
described in the next section. With a JTAG debugger, other programs can be loaded onto this CC2650. For more
information see
http://www.ti.com/tool/boostxl-cc2650ma
57. Figure 6.21. CC2650 LaunchPad (LAUNCHXL-CC2650).
Figure 6.21 shows a CC2650 LaunchPad. The top part of the PCB is the debugger and the bottom part implements the CC2650 target
system. Figure 6.22 shows the pin connections to the booster pack headers. More details on the connections we will use are given in Lab
6. For more information, see
http://www.ti.com/ww/en/launchpad/launchpads-connected-launchxl-cc2650.html