View
215
Download
1
Category
Preview:
Citation preview
Embedded SystemsSoftware Architectures
C.-Z. Yanghttp://syslab.cse.yzu.edu.tw/~czyang
Sept.-Dec. 2001
czyang@acm.org Embedded Systems - Software Architectures 2
元智大學資訊工程系
Software Architectures
• When you are designing the embedded software, which architecture will be the most appropriate for the given system?
czyang@acm.org Embedded Systems - Software Architectures 3
元智大學資訊工程系
Decision Factors
• The most important factor– how much control you need to have over system response.
• Good response – Absolute response time requirements
– The speed of your microprocessor
– and the other processing requirements
czyang@acm.org Embedded Systems - Software Architectures 4
元智大學資訊工程系
Some Examples
• The control of an air conditioner– This system can be written with a very simple software
architecture.
– The response time can be within a number of tens of seconds.
– The major function is to monitor the temperature readings and turn on and off the air conditioner.
– A timer may be needed to provide the turn-on and turn-off time.
czyang@acm.org Embedded Systems - Software Architectures 5
元智大學資訊工程系
Some Examples
• The software design of the control of an air conditioner– A simple assembly program for a low-end microprocessor
– Inputs
• Input buttons
• Temperature readings
• Timer readings
– Output
• The on-off control of the air conditioner
• The power control
czyang@acm.org Embedded Systems - Software Architectures 6
元智大學資訊工程系
Some Examples
• Digital telephone answering machine– A telephone answering machine with digital memory,
using speech compression.
– The performance and functions
• It should be able to record about 30 minutes of total voice.
• Voice data are sampled at the standard telephone rate of 8kHz.
• OGM of up to 10 seconds
• Three basic modes– default/play back/OGM editing mode
czyang@acm.org Embedded Systems - Software Architectures 7
元智大學資訊工程系
Some Examples
• The class diagram for the answering machine
Microphone
Line-in
Line-out
Buttons
Speaker
Record
Lights
Controls
Playback Incoming Message
Outgoing Message
czyang@acm.org Embedded Systems - Software Architectures 8
元智大學資訊工程系
Some Examples
• The state diagram for the controls activate behavior
czyang@acm.org Embedded Systems - Software Architectures 9
元智大學資訊工程系
Some Examples
• The software design for the answering machine– It must respond rapidly to many different events.
– It has various processing requirements.
– It has different deadlines and different priorities.
• A more complex architecture
czyang@acm.org Embedded Systems - Software Architectures 10
元智大學資訊工程系
In This Unit ...
• Four basic software architectures will be discussed:– Round-robin
– Round-robin with interrupts
– Function-queue-scheduling
– Real-time operating system
czyang@acm.org Embedded Systems - Software Architectures 12
元智大學資訊工程系
Round-Robin Architecture
• The simplest architecture
Device A
Device B
Device Z
czyang@acm.org Embedded Systems - Software Architectures 13
元智大學資訊工程系
The Simplest Architecture
• No interrupts
• No shared data
• No latency concerns
czyang@acm.org Embedded Systems - Software Architectures 14
元智大學資訊工程系
An Application
• Digital multimeter– R, I, and V readings
– Two probes
– A rotary switch
czyang@acm.org Embedded Systems - Software Architectures 15
元智大學資訊工程系
Digital Multimeter
• The possible pseudo-code
czyang@acm.org Embedded Systems - Software Architectures 16
元智大學資訊工程系
Discussion
• Timing requirement– Only three I/O devices
– No particularly lengthy processing
– No tight response requirements
• Emergency control– No such requirements
– Users are unlikely to notice the few fractions of a second it takes for the microprocessor to get around the loop
czyang@acm.org Embedded Systems - Software Architectures 17
元智大學資訊工程系
Discussion
• Advantages– Simplicity
– Low development cost
– Short development cycle
• Shortcomings– This architecture cannot handle complex problems.
czyang@acm.org Embedded Systems - Software Architectures 18
元智大學資訊工程系
Shortcomings
• If any one device needs response in less time– Two possible improvements for the RR architecture
• Squeezing the loop
• Carefully arranging the sequence (A,Z,B,Z,C,Z,D,Z,…)
• If there is any lengthy processing to do– Every other event is also postponed.
• This architecture is fragile– A single additional device or requirement may break
everything.
czyang@acm.org Embedded Systems - Software Architectures 20
元智大學資訊工程系
Round-Robin with Interrupts
• A little bit more control– In this architecture,
• ISR deal with the very urgent needs of the hardware and the set flags.
• the main loop polls the flags and does any follow-up processing.
• The ISR can get good response.
• All of the processing that you put into the ISR has a higher priority than the task code.
czyang@acm.org Embedded Systems - Software Architectures 21
元智大學資訊工程系
A Little Bit More Control
• You can control the priorities among the ISR as well.
• The software is more event-driven.
Task Code ISRISR
Shared Variables
czyang@acm.org Embedded Systems - Software Architectures 22
元智大學資訊工程系
The Architecture
• Two main partsInterrupt Service Routines The main loop
czyang@acm.org Embedded Systems - Software Architectures 23
元智大學資訊工程系
RR vs. RR-INT
• Priority levels
czyang@acm.org Embedded Systems - Software Architectures 24
元智大學資訊工程系
Discussion
• Advantage– The processing is more effectively.
• Disadvantage– All of the shared-data problems can potentially jump and
bite you.
czyang@acm.org Embedded Systems - Software Architectures 25
元智大學資訊工程系
An Example of A Simple Bridge
• A device with two ports on it that forwards data traffic received on the first port to the second and vice versa.
czyang@acm.org Embedded Systems - Software Architectures 26
元智大學資訊工程系
Some Assumptions
• Whenever a character is received on one of the communication links, it causes an interrupt.
• The Interrupt must be serviced reasonably quickly.
Interrupt
czyang@acm.org Embedded Systems - Software Architectures 27
元智大學資訊工程系
Some Assumptions
• The microprocessor must write characters to the I/O hardware one at a time.
• The I/O transmitter hardware on that communication ink will be busy while it sends the character.
• Then it will interrupt to indicate that it is ready for the next character.
czyang@acm.org Embedded Systems - Software Architectures 28
元智大學資訊工程系
Some Assumptions
• We have routines that will – read characters from and write characters to queues and
– test whether a queue is empty or not.
• These routines can be called from ISRs as well as from the task code.
• They deal correctly with the shared-data problems.
czyang@acm.org Embedded Systems - Software Architectures 29
元智大學資訊工程系
Possible Code
• Data structures
czyang@acm.org Embedded Systems - Software Architectures 30
元智大學資訊工程系
Possible Code
• Interrupt service routines
Interrupts upon receiving characters
Interrupts upon sending characters
czyang@acm.org Embedded Systems - Software Architectures 32
元智大學資訊工程系
Possible Code
• encrypt() and decrypt()
czyang@acm.org Embedded Systems - Software Architectures 33
元智大學資訊工程系
Another Example: Cordless Bar-code Scanner
• The cordless bar-code scanner
czyang@acm.org Embedded Systems - Software Architectures 34
元智大學資訊工程系
Characteristics of RR-INT
• The primary shortcoming – All of the task code executes at the same priority
czyang@acm.org Embedded Systems - Software Architectures 35
元智大學資訊工程系
Characteristics of RR-INT
• A possible solution– Putting code into the interrupt service routines
– However, this may lengthen the response times for the ISRs for low-priority devices.
• Alternative solution– Changing the testing sequence
• A,C,B,C,D,C,E,C,…
– However, the code is more fragile.
czyang@acm.org Embedded Systems - Software Architectures 36
元智大學資訊工程系
Inappropriate Cases for RR-INT
• A laser printer– Calculating the locations where the black dots go is very
time-consuming.
– In RR-INT architecture, the only code that will get good response is code in ISR.
– Any task code may potentially be stuck while the system calculates more locations for black dots.
• The underground tank-monitoring system– The code that calculates how much gasoline is in the tanks
is very time-consuming.
czyang@acm.org Embedded Systems - Software Architectures 37
元智大學資訊工程系
Function-Queue-Scheduling Architecture
czyang@acm.org Embedded Systems - Software Architectures 38
元智大學資訊工程系
FQS Architecture
• In this architecture, the interrupt service routines add function pointers to a queue of function pointers.
*foo()foo(){
}
foo(){
}
czyang@acm.org Embedded Systems - Software Architectures 39
元智大學資訊工程系
The Framework of FQS
• Three parts
czyang@acm.org Embedded Systems - Software Architectures 40
元智大學資訊工程系
The FQS Architecture
• The advantages– No rule says main has to call the functions in the order that
the interrupt routines occurred.
– Any task code functions that need quicker response can be executed earlier.
– All this rakes is a little clever coding in the routines that queue up the function pointers.
• The worst wait– the length of the longest of the task code function
czyang@acm.org Embedded Systems - Software Architectures 41
元智大學資訊工程系
The FQS Architecture
• The trade-off– The response for the lower-priority task code functions
may get worse.
– Lower-priority functions may never execute if the interrupt service schedule the higher-priority functions frequently enough to use up all of the microprocessor’s available time.
czyang@acm.org Embedded Systems - Software Architectures 42
元智大學資訊工程系
Real-Time Operating System Architecture
czyang@acm.org Embedded Systems - Software Architectures 43
元智大學資訊工程系
RTOS Architecture
• The most sophisticated architecture
• In this architecture, the ISRs take care of the most urgent operations.
• Then they “signal” that there is work for the task code to do.
czyang@acm.org Embedded Systems - Software Architectures 45
元智大學資訊工程系
The Processing
• The necessary signaling between the interrupt routines and the task code is handled by RTOS.– No shared variable needs to be used.
• No loop in our code decides what needs to be done next.– RTOS knows about the various task-code subroutines and will
run whichever of them is more urgent.
• RTOS can suspend a task-code subroutine in the middle of its processing in order to run another.
czyang@acm.org Embedded Systems - Software Architectures 46
元智大學資訊工程系
A Priority-based Scheduling
• RTOS can control task code response as well as ISR response.
• The worst-case wait for the highest-priority task code is zero.
• Therefore, your system’s response will be relatively stable.
• Another advantage is that RTOSs are widely available for purchase.
czyang@acm.org Embedded Systems - Software Architectures 47
元智大學資訊工程系
Priority Levels
• A comparison
czyang@acm.org Embedded Systems - Software Architectures 48
元智大學資訊工程系
Disadvantages
• The RTOS itself uses a certain amount of processing time.– You are getting better response at the expense of a little bit
of throughput.
• Also, the software architecture is much more complex.
czyang@acm.org Embedded Systems - Software Architectures 50
元智大學資訊工程系
Some Suggestions
• Select the simplest architecture that will meet your response requirements.– Writing embedded-system software is complicated enough
without choosing an unnecessarily complex architecture for your software.
• if your system has response requirements that might necessitate using a RTOS, you should lean toward using a RTOS.
czyang@acm.org Embedded Systems - Software Architectures 51
元智大學資訊工程系
Some Suggestions
• If it makes sense for your system, you can create hybrids of the architectures.– Even if you are using a RTOS, you can have a low-priority
task that polls those parts of the hardware that do not need fast response.
• Hybrid architectures make sense for some systems.
Recommended