53
Embedded Systems Software Architectures C.-Z. Yang http://syslab.cse.yzu.edu.tw/~czyang Sept.-Dec. 2001

Embedded Systems Software Architectures C.-Z. Yang czyang Sept.-Dec. 2001

  • View
    215

  • Download
    1

Embed Size (px)

Citation preview

Embedded SystemsSoftware Architectures

C.-Z. Yanghttp://syslab.cse.yzu.edu.tw/~czyang

Sept.-Dec. 2001

[email protected] 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?

[email protected] 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

[email protected] 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.

[email protected] 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

[email protected] 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

[email protected] 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

[email protected] Embedded Systems - Software Architectures 8

元智大學資訊工程系

Some Examples

• The state diagram for the controls activate behavior

[email protected] 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

[email protected] 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

[email protected] Embedded Systems - Software Architectures 11

元智大學資訊工程系

Round-Robin

[email protected] Embedded Systems - Software Architectures 12

元智大學資訊工程系

Round-Robin Architecture

• The simplest architecture

Device A

Device B

Device Z

[email protected] Embedded Systems - Software Architectures 13

元智大學資訊工程系

The Simplest Architecture

• No interrupts

• No shared data

• No latency concerns

[email protected] Embedded Systems - Software Architectures 14

元智大學資訊工程系

An Application

• Digital multimeter– R, I, and V readings

– Two probes

– A rotary switch

[email protected] Embedded Systems - Software Architectures 15

元智大學資訊工程系

Digital Multimeter

• The possible pseudo-code

[email protected] 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

[email protected] Embedded Systems - Software Architectures 17

元智大學資訊工程系

Discussion

• Advantages– Simplicity

– Low development cost

– Short development cycle

• Shortcomings– This architecture cannot handle complex problems.

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 19

元智大學資訊工程系

Round-Robin with Interrupts

[email protected] 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.

[email protected] 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

[email protected] Embedded Systems - Software Architectures 22

元智大學資訊工程系

The Architecture

• Two main partsInterrupt Service Routines The main loop

[email protected] Embedded Systems - Software Architectures 23

元智大學資訊工程系

RR vs. RR-INT

• Priority levels

[email protected] 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.

[email protected] 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.

[email protected] 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

[email protected] 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.

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 29

元智大學資訊工程系

Possible Code

• Data structures

[email protected] Embedded Systems - Software Architectures 30

元智大學資訊工程系

Possible Code

• Interrupt service routines

Interrupts upon receiving characters

Interrupts upon sending characters

[email protected] Embedded Systems - Software Architectures 31

元智大學資訊工程系

Possible Code

• The main loop

[email protected] Embedded Systems - Software Architectures 32

元智大學資訊工程系

Possible Code

• encrypt() and decrypt()

[email protected] Embedded Systems - Software Architectures 33

元智大學資訊工程系

Another Example: Cordless Bar-code Scanner

• The cordless bar-code scanner

[email protected] Embedded Systems - Software Architectures 34

元智大學資訊工程系

Characteristics of RR-INT

• The primary shortcoming – All of the task code executes at the same priority

[email protected] 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.

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 37

元智大學資訊工程系

Function-Queue-Scheduling Architecture

[email protected] 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(){

}

[email protected] Embedded Systems - Software Architectures 39

元智大學資訊工程系

The Framework of FQS

• Three parts

[email protected] 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

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 42

元智大學資訊工程系

Real-Time Operating System Architecture

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 44

元智大學資訊工程系

A Paradigm

• The sample code

[email protected] 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.

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 47

元智大學資訊工程系

Priority Levels

• A comparison

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 49

元智大學資訊工程系

Selecting an Architecture

[email protected] 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.

[email protected] 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.

[email protected] Embedded Systems - Software Architectures 52

元智大學資訊工程系

The Summary

[email protected] Embedded Systems - Software Architectures 53

元智大學資訊工程系

A Characteristic Table

• Four architectures