Embedded Systems Basic Design Using a Real- Time Operating System C.-Z. Yang Sept.-Dec. 2001.

Slides:



Advertisements
Similar presentations
I/O Management and Disk Scheduling
Advertisements

Computer Architecture
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Computer Architecture
Mark Schaumburg.  Dash Module for Formula Car  Sample pulse from engine for RPM  Display Information  Control gui  Can network interface  Request.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Microprocessor and Microcontroller
I/O Unit.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Embedded Systems Introduction to Real-Time Operating Systems C.-Z. Yang Sept.-Dec
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
1 Computer System Overview OS-1 Course AA
Computer System Overview
Chapter 7 Interupts DMA Channels Context Switching.
Basic Input/Output Operations
Embedded Systems Software Architectures C.-Z. Yang Sept.-Dec
Embedded Systems An Overview to Embedded Software C.-Z. Yang Sept.-Dec
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
Device Management.
CHAPTER 9: Input / Output
Embedded Systems Interrupts C.-Z. Yang Sept.-Dec
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Software design and development Marcus Hunt. Application and limits of procedural programming Procedural programming is a powerful language, typically.
CHAPTER 5 I/O PRINCIPLE Understand the principles of System Bus
Real-Time Software Design Yonsei University 2 nd Semester, 2014 Sanghyun Park.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
MICROPROCESSOR INPUT/OUTPUT
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
1 System Clock and Clock Synchronization.. System Clock Background Although modern computers are quite fast and getting faster all the time, they still.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
Computer Organization Instruction Set Architecture (ISA) Instruction Set Architecture (ISA), or simply Architecture, of a computer is the.
IT3002 Computer Architecture
6.0 INTRODUCTION TO REAL-TIME OPERATING SYSTEMS (RTOS) 6.0 Introduction A more complex software architecture is needed to handle multiple tasks, coordination,
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
1 8. Basic Design Using a Real-Time Operating System Kim jung kil.
Lecture 4 Page 1 CS 111 Summer 2013 Scheduling CS 111 Operating Systems Peter Reiher.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
1 Computer System Overview Chapter 1. 2 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system.
Tutorial 2: Homework 1 and Project 1
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Chapter 2 Memory and process management
Microprocessor Systems Design I
Topics Covered What is Real Time Operating System (RTOS)
6.0 INTRODUCTION TO REAL-TIME OPERATING SYSTEMS (RTOS/RTK)
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Swapping Segmented paging allows us to have non-contiguous allocations
Real-time Software Design
An Embedded Software Primer
Interrupts, Tasks and Timers
An Embedded Software Primer
CS703 - Advanced Operating Systems
EE 472 – Embedded Systems Dr. Shwetak Patel.
Embedded System Development Lecture 7 2/21/2007
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Embedded System Development Lecture 12 4/4/2007
Presentation transcript:

Embedded Systems Basic Design Using a Real- Time Operating System C.-Z. Yang Sept.-Dec. 2001

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System2 Something You Must Be Aware This unit assumes that your system will include an RTOS. You have to decide whether the RTOS architecture is the appropriate one. The embedded-system software design is an endeavor that has as many exceptions as it has rules.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System3 Real-Time Requirements

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System4 Overview Two fundamental questions –What must the system do? –How fast must it do it? You must know how critical each timing is. Two categories –Hard real-time System with absolute deadlines –Soft real-time Systems that demand good response but that allow some fudge in the deadlines.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System5 Overview To design effectively, you must know something about the hardware. You must have some feel for the speed of your microprocessor. –Unfortunately, only experience and experimentation can help you with this.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System6 Design Principles

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System7 General Operation Embedded systems very commonly have nothing to do until the passage of time or some external event requires a response. Interrupts tend to be the driving force of embedded software.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System8 A Telegraph System The insight of the system

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System9 Interrupt Routines Write short interrupt routines –Since even the lowest-priority interrupt routine is executed in preference to the highest-priority task code, writing longer interrupt routines translates directly slower task- code response. –Interrupt routines tend to be more bug-prone and harder to debug than task code. Since the timing requirements vary, it makes sense for the interrupt routine to do the immediate actions and then to signal a task to do the rest.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System10 An Example The system has the following characteristics –The system must respond to commands coming from a serial port. –Commands always end with a carriage return. –Commands arrive one at a time; the next command will not arrive until the system responds to the previous one. –The serial port hardware can only store one received character at a time, and characters may arrive quickly. –The system can respond to commands relatively slowly.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System11 Two Programming Extremes One way is to do all of the work in the interrupt routine that receives characters. –Long and complex –Difficult to debug –Slow response Another extreme is to simply forward every character in an RTOS message to a command parsing task.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System12 Short ISR Theoretically Forwarding messages to a task is an excellent architecture. However, –The ISR will send a lot of messages. –Putting messages onto an RTOS queue is not instantaneous. –If the characters arrive quickly enough, the ISR might not be able to keep up.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System13 One Possible Compromise Design An interrupt routine saves the received characters in a buffer and watches for the carriage return that ends each command. –When the carriage return arrives, the ISR sends a single message to the command parsing task, which reads the characters out of the buffer. –Therefore, the ISR is short enough, but the system need not send so many messages.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System14 The Code MailBox

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System15 How Many Tasks? One of the first problems in an embedded- system design is to divide your system’s work into RTOS tasks. Am I better off with more tasks or with fewer tasks?

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System16 A Large Number of Tasks The advantages –With more tasks you have better control of the relative response times of the different parts of your system’s work. –With more tasks your system can be somewhat more modular. –With more tasks you can sometimes encapsulate data more effectively.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System17 A Large Number of Tasks The disadvantages –With more tasks you are likely to have more data shared among two or more tasks. –With more tasks you are likely to have more requirements to pass messages from one task to another through pipes, mailboxes, queues, and so on. –Each task requires a stack; therefore, with more tasks you will probably need more memory, at least for stack space, and perhaps for intertask messages as well. –Each time the RTOS switches tasks, a certain amount of microprocessor time evaporates for context switching.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System18 A Large Number of Tasks The disadvantages –More tasks probably means more calls to the RTOS. –Your system runs faster if it avoids calling the RTOS functions. –The irony rule Once you decide to use an RTOS, your best design is often the one that uses it least.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System19 The Most Perverse Thing The disadvantages of having more tasks are visited upon you almost automatically. You reap the advantages only if you divide your system into tasks carefully. The moral –Other things being equal, use as few tasks as you can get away with; add more tasks to your design only for clear reasons.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System20 The Time for Adding More Tasks - 1 One obvious reason for having multiple tasks is to be able to assign higher priorities to parts of the work with tighter response time requirements. If some part of the code need better response, this part should be separated into another task.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System21 The Time for Adding More Tasks - 2 It often makes sense to have a separate task to deal with hardware shared by different parts of the system. Task1 Task2 ErrorsTask

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System22 A Laser Printer Example The task graph

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System23 Another Example - Flash Memory The task vHandleFalshTask

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System24 Some Suggestions Have many small tasks, so that each is simple. –Trade-off: simple but a lot of shared data –Also, your system will have a lot of intertask communications. Have separate tasks for work that needs to be done in response to separate stimuli.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System25 Some Suggestions The sample code

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System26 Recommended Task Structure The pseudo code

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System27 Advantages of This Task Architecture The task blocks in only one place. –When another task puts a request on the task’s queue, this task is not off waiting for some other event that may or may not happen in a timely fashion. When there is nothing for this task to do, its input queue will be empty and the task will block and use up no microprocessor time. This task does not have public data that other tasks can share.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System28 Avoid Creating and Destroying Tasks Every RTOS allows you to create tasks as the system is starting. Two reasons –The functions that create an destroy tasks are typically the most time-consuming functions in the RTOS. –Whereas creating a tasks is relatively reliable operation, it can be difficult to destroy task without leaving little pieces lying around to cause bugs.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System29 Time-Slicing RTOSs also allow you to turn this option off. Time-slicing is not helpful when –The tasks are not all equally urgent and therefore get different priorities. –They are of equal importance, and you don’t care which of them finishes first. Time-slicing causes more task switches and therefore cuts throughput.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System30 Restricting Your Use Most RTOSs, even fairly small ones, offer more services than you are likely to need on any given project. You can save memory by figuring out a subset of the RTOS features that is sufficient for your system and using only that.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System31 An Example - the Underground Tank Monitoring System

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System32 Tank Monitoring System The figure

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System33 Some Initial Questions When the float in one tank is rising rapidly, how often do we need to read it? How quickly must the system respond when the user pushes a button? How fast does the printer print?

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System34 Resolving a Timing Problem The system must check each tank in which the float is rising several times a second, but it takes 4 or 5 seconds to calculate the quantity of gasoline n a tank after the float is read. –Using a faster CPU? –No calculations? Just using raw float readings?

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System35 Deciding to Use an RTOS We must first decide whether an RTOS architecture is suitable. Can you build a system that does all this work in ISRs? Will it be easy to build a system tat does all this work in ISRs?

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System36 Dividing the Work into Tasks A level calculation task An overflow detection task A float hardware task A button handling task A display task An alarm bell task A print formatting task

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System37 Moving the System Forward Sending necessary signals! –Whenever the user presses a button, the button hardware interrupts the microprocessors. –When the user wishes to print a report, the print formatting task can send the first line of the report to the printer.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System38 Dealing with the Shared Data The level data is shared by several tasks –The level calculation task –The display task –The print formatting task A semaphore or another task? –What is the longest that any one task will hold on to the semaphore? –Can every other task wait that long?

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System39 Conclusion Tasks

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System40 Conclusion The message flow

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System41 Encapsulating Semaphores and Queues

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System42 Encapsulating Semaphores The construction forces any code that wants to know the value of a shared variable to call a function to get it.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System43 A Buggy One The wretched code

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System44 Another Example The tank system

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System45 Encapsulating Queues Some potential bugs in the code for handling a shared flash memory. –Any programmer can blow it and send a message that does not contain a FLASH_MSG structure. –Somebody may assign a value to eFlashOp other than one of the two legal values. –Anybody might accidentally write a message intended for the flash task to the wrong queue. –Any task might destroy the flash task input by mistake.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System46 Encapsulating Queues The queue has been encapsulated inside of the flash.c module.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System47 Hard Real-Time Scheduling Considerations

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System48 Hard Deadlines The ability to meet hard deadlines comes from writing fast code. In some cases, it might make sense to write some frequently called subroutines in assembly language.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System49 Saving Memory Space

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System50 Limited Memory Embedded systems often have limited memory. Tradeoff between the code space and the data space Saving stack space

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System51 Saving Code Space Make sure that you aren’t using two functions to do the same thing. Check that your development tools aren’t sabotaging you. Configure your RTOS to contain only those functions that you need. Look at the assembly listings created by your cross-compiler to see if certain of your C statement translate into huge numbers of instruction.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System52 An Example Initialization

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System53 Saving Code Space Consider using static variables instead of variables on the stack.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System54 Saving Code Space If you are using an 8-bit processor, consider using char variables instead of int variables.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System55 Saving Code Space If all else fails, you can usually save a lot of space by writing your code in assembly language.

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System56 Saving Power

元智大學資訊工程系 Systems - Basic Design Using a Real-Time Operating System57 Power Issue The primary method for preserving battery power is to turn off parts or all of the system whenever possible. Two common modes –The CPU stops executing instructions, stops any built-in peripherals and stops its clock circuit. –The CPU stops executing instructions but the on-board peripherals continue to operate.