Embedded Software Design: Peter R. Wihl
Embedded Software Design: Peter R. Wihl
Peter R. Wihl
(former Guest Lecturer)
Overview
• Data flow practices (Throughput)
• Real time systems
• Software design overview
• Communication protocols
• An example software design
ADC
DRdy 16
Fr = 20 – 20 KHz
Vpp = 1 V Data_Ready
Voff = 0 V
ECC
Enable1 En 2
Controller Error
En
SM
Enable2
En Error 16
Enable3 Detect
DAC_Load ED_Enable
Load EnError
DAC
16 Correct
Fr = 20 – 20 KHz
Vpp = 1 V
Voff = 0 V
Physical Architecture Mapping
FS = 44.1 KHz
ADC_Data[15:0]
ADC
DRdy 16
Fr = 20 – 20 KHz
Vpp = 1 V Data_Ready
Voff = 0 V ECC
Error
ADC
DRdy 16
Fr = 20 – 20 KHz
Vpp = 1 V Data_Ready
Voff = 0 V
ECC
Enable1 En 2
Controller Error
En
SM
Enable2
En Error 16
Enable3 Detect
DAC_Load ED_Enable
Load EnError
DAC
16 Correct
Fr = 20 – 20 KHz
Vpp = 1 V
Voff = 0 V Mapped to microcontroller
Role of Microcontroller
• Read 16-bit word from ADC
• Calculate Error Correction Code (2-bit)
• Inject possible error
• Detect if there is an error
• If there is an error correct it
• Write new 16-bit word to DAC
Execution Flow Diagram
Initialize Calculate if there
is error
Calculate ECC
Error
Detected?
Read ADC Byte
(Register)
Calculate correct
ADC word value
Write ADC Byte to
memory
Inject possible
error Write Byte to DAC
Last byte in No
word?
Yes
Last byte in No
word?
Yes
Data Throughput in SW
• What is synchronous data flow?
– Data arrives at regular intervals
• What is asynchronous data flow?
– Data does not arrive at regular intervals
• What is isochronous data flow?
– Data must be delivered within certain time
constraints
Data Flow Practices
• Polling
• Interrupt triggered (blocking)
• Interrupt triggered (non-blocking)
• Event driven
– Often referred to as interrupt driven
Sample Problem
• Need to receive 16 bytes into a buffer and
then process the buffer
• Bytes arrive asynchronously
Polling Overview
Enter Loop
No
Buffer Full?
Yes
Process Buffer
Polling
main
do forever
count = 0
while count < 16
while byte not ready
nop
get byte
buffer[count] = byte
incr count
process buffer
Interrupt (Blocking) Overview
IRQ Loop
Enter IRQ
Main Loop
Enable Interrupts
No Loop Forever
Buffer Full?
Yes
Process Buffer
Enable Interrupts
Exit IRQ
Interrupt Triggered
(Blocking)
interrupt rx_byte main
disable interrupts enable interrupts
count = 0 do forever
while count < 16 nop
get byte
buffer[count] = byte
incr count
process buffer
enable interrupts
return
Interrupt (Non-Blocking) Overview
IRQ Loop
Main Loop
Enter IRQ
Enter Main
Yes
Buffer Full?
No
Enable Interrupts
Process Buffer
Count = 0
Store ADC Value
Increment Count
Increment Count
Loop Forever
Exit IRQ
Interrupt Triggered
(Non-blocking)
interrupt rx_byte main
if count < 16 count = 0
get byte enable interrupts
buffer[count] = byte do forever
incr count nop
else if count = 16
process buffer
count = 0
return
Event Driven Overview
IRQ Loop Main Loop
No Count = 0
Count <16
Yes
Enable Interrupts
Process = 1
Process Buffer
Increment Count
Process = 0
Exit IRQ
Event Driven
interrupt rx_byte main
if count < 16 count = 0
get byte enable interrupts
buffer[count] = byte do forever
incr count if count = 16
return process buffer
count = 0
Real Time
• Hard real time
– Absolute deterministic response to an
event
• Soft real time
– Average response to an event
Embedded Software Practices
Peter R. Wihl
ECE 164 Spring 2004
Overview
• Data flow practices
• Real time systems
• Communication protocols
• Software design overview
• An example software design
Processor /
microcontroller
Heads Up
Display
Software Architecture
Vehicle Vehicle data
Serial vehicle data
data interface
Display processing
Display image
Send wake up
Receive block Timer
signal
Data block
Data type?
RPM MPG
Integer to text
conversion
Text formatting
Integer to floating
point conversion
Floating point to
text conversion
Text formatting
Display image
generation
Display image
Mirror image
Image to
command
conversion
Display command
Command send