Embedded Systems More Operating System Services C.-Z. Yang Sept.-Dec. 2001.

Slides:



Advertisements
Similar presentations
Lectures on File Management
Advertisements

Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Real-Time Library: RTX
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
 A quantum is the amount of time a thread gets to run before Windows checks.  Length: Windows 2000 / XP: 2 clock intervals Windows Server systems: 12.
IN2305-II Embedded Programming Lecture 7: More OS Services.
Embedded Systems Introduction to Real-Time Operating Systems C.-Z. Yang Sept.-Dec
CS510 Advanced OS Seminar Class 10 A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
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)
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Embedded Systems Software Architectures C.-Z. Yang Sept.-Dec
Chapter 11 Operating Systems
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.
Computer Organization and Architecture
Embedded Systems Basic Design Using a Real- Time Operating System C.-Z. Yang Sept.-Dec
Embedded Systems Interrupts C.-Z. Yang Sept.-Dec
FreeRTOS.
Real-Time Operating Systems Suzanne Rivoire November 20, 2002
SOC Consortium Course Material SoC Design Laboratory Lab 8 Real-time OS - 2 Speaker: Yung-Chih Chen Advisor: Prof. Chun-Yao Wang November 17, 2003 Department.
國立台灣大學 資訊工程學系 Introduction to uC/OS-II
1 I-Logix Professional Services Specialist Rhapsody IDF (Interrupt Driven Framework) CPU External Code RTOS OXF Framework Rhapsody Generated.
Nachos Phase 1 Code -Hints and Comments
I/O Systems I/O Hardware Application I/O Interface
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Operating system Structure and Operation by Dr. Amin Danial Asham.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
ECE291 Computer Engineering II Lecture 15 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
MicroC/OS-II S O T R.  MicroC/OS-II (commonly termed as µC/OS- II or uC/OS-II), is the acronym for Micro-Controller Operating Systems Version 2.  It.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
6.0 INTRODUCTION TO REAL-TIME OPERATING SYSTEMS (RTOS) 6.0 Introduction A more complex software architecture is needed to handle multiple tasks, coordination,
Lab 4 : Real-Time OS Team #7 P 李彥勳 P 謝嵩淮 R 侯凱文.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
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.
I/O Software CS 537 – Introduction to Operating Systems.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Copyright © Curt Hill More on Operating Systems Continuation of Introduction.
1 8. Basic Design Using a Real-Time Operating System Kim jung kil.
Chapter 7. More Operating System Services
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Chapter 7: Semaphore Management Seulki Lee 1. Semaphore?  A protocol mechanism offered by most multitasking kernels  Control access to a shared resource.
Module 12: I/O Systems I/O hardware Application I/O Interface
Topics Covered What is Real Time Operating System (RTOS)
Mechanism: Limited Direct Execution
An Embedded Software Primer
An Embedded Software Primer
Operating Systems Chapter 5: Input/Output Management
Operating System Concepts
Last Week Introduced operating systems Discussed the Kernel
CSCI1600: Embedded and Real Time Software
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CSCI1600: Embedded and Real Time Software
Embedded System Development Lecture 10 3/21/2007
Embedded System Development Lecture 12 4/4/2007
Chapter 6: Event Control Block (ECB)
Module 12: I/O Systems I/O hardwared Application I/O Interface
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Embedded Systems More Operating System Services C.-Z. Yang Sept.-Dec. 2001

元智大學資訊工程系 Systems - More Operating Systems Services2 Common Communication Services Data sharing –Tasks must be able to communicate with one another to coordinate their activities or to share data. Some mechanisms are provided in most RTOSs. –Queues –Mailboxes –Pipes

元智大學資訊工程系 Systems - More Operating Systems Services3 A Simple Example Three tasks –Task1 –Task2 –ErrorsTask Task1 Task2 ErrorsTask

元智大學資訊工程系 Systems - More Operating Systems Services4 The Code Task1 and Task2

元智大學資訊工程系 Systems - More Operating Systems Services5 The Code ErrorsTask If the queue is empty, this function will block the calling task.

元智大學資訊工程系 Systems - More Operating Systems Services6 Some Working Details Most RTOSs require that you initialize your queues before you use them. –You should guarantee that queue initialization should be carried out before any task tries to use the queue. Most RTOSs allow you to has as many queues as you want. –So you should pass an additional parameter to every queue function.

元智大學資訊工程系 Systems - More Operating Systems Services7 Some Working Details If your code tries to write to a queue when the queue is full, the RTOS must either –return an error to let you know that the write operation failed –or it must block the task until some other task reads data from the queue and thereby creates some space. Many RTOSs include an additional function that will read from a queue if there is any data and will return an error code if not.

元智大學資訊工程系 Systems - More Operating Systems Services8 Some Working Details The amount of data that the RTOS lets you write to the queue in one call may not be exactly the amount that want to write. –Many RTOSs are inflexible about this. –One common characteristic is to allow you to write onto a queue in one call the number of byte taken up by a void pointer.

元智大學資訊工程系 Systems - More Operating Systems Services9 More Realistic Code Queue data structures and operations

元智大學資訊工程系 Systems - More Operating Systems Services10 More Realistic Code main, Task1 and Task2

元智大學資訊工程系 Systems - More Operating Systems Services11 More Realistic Code vLogError

元智大學資訊工程系 Systems - More Operating Systems Services12 More Realistic Code ErrorsTasks

元智大學資訊工程系 Systems - More Operating Systems Services13 Remarks on the Previous Code A fairly common RTOS interface –Write one void pointer to the queue with each call. A fairly common coding technique –Cast the data as a void pointers.

元智大學資訊工程系 Systems - More Operating Systems Services14 Another Example Reading temperatures

元智大學資訊工程系 Systems - More Operating Systems Services15 A Closer Look at OSQPost() OSQPost UBYTE OSQPost(OS_EVENT *pevent, void *msg) { OS_Q *pq; OS_TCB *ptcb; UBYTE x; UBYTE y; UBYTE bitx; UBYTE bity; UBYTE p; OS_ENTER_CRITICAL(); if (pevent->OSEventGrp) { /* See if any task pending on queue */ … } else { … }

元智大學資訊工程系 Systems - More Operating Systems Services16 A Closer Look at OSQPost() OSQPost - if part y = OSUnMapTbl[pevent->OSEventGrp]; /* Find highest prio. task waiting for message */ bity = OSMapTbl[y]; x = OSUnMapTbl[pevent->OSEventTbl[y]]; bitx = OSMapTbl[x]; p = (y << 3) + x; /* Find priority of task getting the msg */ if ((pevent->OSEventTbl[y] &= ~bitx) == 0) { /* Remove this task from the waiting list */ pevent->OSEventGrp &= ~bity; } ptcb = OSTCBPrioTbl[p]; /* Point to this task's OS_TCB */ ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from readying task */ ptcb->OSTCBEventPtr = (OS_EVENT *)0; /* Unlink ECB from this task */ ptcb->OSTCBMsg = msg; /* Send message directly to waiting task */ ptcb->OSTCBStat &= ~OS_STAT_Q; /* Clear bit associated with event type */ if (ptcb->OSTCBStat == OS_STAT_RDY) { /* See if task is ready (could be susp'd) */ OSRdyGrp |= bity; /* Put task in the ready to run list */ OSRdyTbl[y] |= bitx; } OS_EXIT_CRITICAL(); OSSched(); /* Find highest priority task ready to run */ return (OS_NO_ERR);

元智大學資訊工程系 Systems - More Operating Systems Services17 A Closer Look at OSQPost() OSQPost - else part pq = pevent->OSEventPtr; /* Point to queue control block */ if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */ OS_EXIT_CRITICAL(); return (OS_Q_FULL); } else { *pq->OSQIn++ = msg; /* Insert message into queue */ pq->OSQEntries++; /* Update the nbr of entries in the queue */ if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of queue */ pq->OSQIn = pq->OSQStart; } OS_EXIT_CRITICAL(); } return (OS_NO_ERR);

元智大學資訊工程系 Systems - More Operating Systems Services18 Mailboxes

元智大學資訊工程系 Systems - More Operating Systems Services19 Mailboxes In general, mailboxes are much like queues. The typical RTOS has functions to create, to write to, and to read from mailboxes. Perhaps there are functions to check whether the mailbox contains any messages and to destroy the mailbox if it is no longer needed.

元智大學資訊工程系 Systems - More Operating Systems Services20 Some Variations in RTOSs The number of messages in a mailbox –Some RTOSs allow a certain number. –Others allow only one. Some RTOSs do not have such limitation for each mailbox, but they have a limit to the total number. In some RTOSs, you can prioritize mailbox messages.

元智大學資訊工程系 Systems - More Operating Systems Services21 An Example - MultiTask! Each message is a void pointer –uMbId: the mailbox on which to operate. –sndmsg: the function adding p_vMsg into the message queue with the priority indicated by uPriority –rcvmsg: returning the highest-priority message –chkmsg: returning the first message in the mailbox

元智大學資訊工程系 Systems - More Operating Systems Services22 Pipes

元智大學資訊工程系 Systems - More Operating Systems Services23 Pipes Pipes are also much like queues. Variations –Some RTOSs allow you to write message of varying lengths onto pipes. –Pipes in some RTOSs are entirely bye-oriented. –Some RTOSs use the standard C library functions fread and fwrite to read from and write to pipes.

元智大學資訊工程系 Systems - More Operating Systems Services24 Which Should I Use? This depends on –flexibility –speed –memory space –length of time that interrupts must be disabled within the RTOS functions

元智大學資訊工程系 Systems - More Operating Systems Services25 Some Pitfalls Most RTOSs do not restrict which tasks can read from or write to any given queue, mailbox, or pipe. –You must ensure that tasks use the correct one each time. The RTOS cannot ensure that data written onto a queue, mailbox, or pipe will be properly interpreted by the task that reads it. –You must declare your programming interface very clearly.

元智大學資訊工程系 Systems - More Operating Systems Services26 An Example A bug easy to be found by compilers

元智大學資訊工程系 Systems - More Operating Systems Services27 An Example A concealed bug

元智大學資訊工程系 Systems - More Operating Systems Services28 More Pitfalls Running out of space in queues, mailboxes, or pipes is usually a disaster for embedded software. Passing pointers from one task to another through a queue, mailbox, or pipe is one of several ways to create shared data inadvertently.

元智大學資訊工程系 Systems - More Operating Systems Services29 An Example No malloc and free BeforeAfter

元智大學資訊工程系 Systems - More Operating Systems Services30 An Example No malloc and free BeforeAfter

元智大學資訊工程系 Systems - More Operating Systems Services31 An Example However, there is a bug. –When the main task gets a value for pTemperatures from the queue, pTemperatures will point to the iTemperatures array in vReadTemperaturesTask. –If the RTOS switches from vMainTask to vReadTemperaturesTask while vMainTask was comparing iTemperatures[0] to iTemperatures[1], and if vReadTemperaturesTask then changes the values in iTemperatures, the shared-data bug occurs.

元智大學資訊工程系 Systems - More Operating Systems Services32 Timer Functions

元智大學資訊工程系 Systems - More Operating Systems Services33 Timing Is a Very Important Issue Most embedded systems must keep track of the passage of time. One simple service that most RTOSs offer is a function that delays a task for a period of time.

元智大學資訊工程系 Systems - More Operating Systems Services34 An Example for Making a TEL Call The code

元智大學資訊工程系 Systems - More Operating Systems Services35 Several Questions How do I know that the taskDelay function takes a number of milliseconds as its parameters? –Check your programming manuals. –Usually the delay function in most RTOSs takes the number of system ticks as its parameters. How accurate are the delays produced by the taskDelay function? –The nearest system tick. –A heartbeat timer.

元智大學資訊工程系 Systems - More Operating Systems Services36 Timer Accuracy vTaskDelay(3)

元智大學資訊工程系 Systems - More Operating Systems Services37 More Questions How does the RTOS know how to setup the timer hardware on ly particular hardware? –This is the job of the developer who is responsible for OS porting. –If you are the person, you may have to write your own timer setup software and timer interrupt routine. What is a “normal” length for the system tick? –There really isn’t one. –A trade-off: more accurate, more timer interrupts.

元智大學資訊工程系 Systems - More Operating Systems Services38 More Questions What if my system needs extremely accurate timing? –Two choices: –(1) to make the system tick short enough that RTOS timing fit your definition of “extremely accurate”. –(2) to use a separate hardware timer for those timings that must be extremely accurate.

元智大學資訊工程系 Systems - More Operating Systems Services39 Other Timing Services Most RTOSs offer an array of other timing services. All of them are based on the system tick. Some cautions are needed. –Timeout for getting a semaphore Code for recovering must be provided. We should try to find other good solutions.

元智大學資訊工程系 Systems - More Operating Systems Services40 A Useful Service To call the function of your choice after a given number of system ticks. An example –Radio on/off –Turning-on procedure power on 12ms, setting the frequency 3ms, turning on the transmitter

元智大學資訊工程系 Systems - More Operating Systems Services41 The Code

元智大學資訊工程系 Systems - More Operating Systems Services42 Events

元智大學資訊工程系 Systems - More Operating Systems Services43 Events An event is essentially a Boolean flag that tasks can set or reset and that other tasks can wait for. Task1Task2

元智大學資訊工程系 Systems - More Operating Systems Services44 Some Standard Features More than one task can block waiting for the same event, and the RTOS will unblock all of them when the event occurs. RTOSs typically form groups of events, and tasks can wait for any subset of events within the group. Different RTOSs deal in different ways with the issue of resetting an event after it has occurred and tasks that were waiting for it have been blocked.

元智大學資訊工程系 Systems - More Operating Systems Services45 An Example AMX code

元智大學資訊工程系 Systems - More Operating Systems Services46 A Brief Comparison of the Methods for Intertask Communication

元智大學資訊工程系 Systems - More Operating Systems Services47 Semaphores are usually the fastest and simplest methods. –However, not much information can pass through a semaphore. Events are a little more complicated than semaphores and take up just a hair more microprocessor time than semaphores. –ADV: A task can wait for any one of several events at the same time, whereas it can only wait for one semaphore. –ADV: Some RTOSs make it convenient to use events and make it inconvenient to use semaphores.

元智大學資訊工程系 Systems - More Operating Systems Services48 Queues allow you to send a lot of information from one task to another. –The drawbacks putting messages into and taking messages out of queues is more microprocessor-intensive that queues offer you many more opportunities to insert bugs into your code.

元智大學資訊工程系 Systems - More Operating Systems Services49 Memory Management

元智大學資訊工程系 Systems - More Operating Systems Services50 Memory Management Most RTOSs have some kind of memory management subsystem. Real-time engineers often avoid using malloc() and free() because –they are typically slow and –their execution times are unpredictable. They favor instead functions that allocate and free fixed-size buffers.

元智大學資訊工程系 Systems - More Operating Systems Services51 An Example in MultiTask! Pools –Each of which consists of some number of memory buffers. –In any give pool, all of the buffers are the same size. Two functions to allocate a buffer –getbuf() –reqbuf()

元智大學資訊工程系 Systems - More Operating Systems Services52 An Example in MultiTask! You have to tell MultiTask! where the free memory is. A function to initialize the pool –init_mem_pool

元智大學資訊工程系 Systems - More Operating Systems Services53 A Simple Example Code The printing subsystem

元智大學資訊工程系 Systems - More Operating Systems Services54 Some Important Notes The code always allocates a full 40-char buffer. –This waste of memory is the price you pay for the improved speed that fixed-size buffers allow. A common compromise that retains the high-speed memory routines but uses memory reasonably efficiently is to allocate three of four memory buffer pools, each with a different size of buffer.

元智大學資訊工程系 Systems - More Operating Systems Services55 Interrupt Routines in an RTOS Environment

元智大學資訊工程系 Systems - More Operating Systems Services56 Interrupt Routines Two rules must be followed. Rule 1 –An interrupt routine must not call any RTOS function that might block the caller. Rule 2 –An interrupt routine may not call any RTOS function that might cause the RTOS to switch tasks unless the RTOS knows that an interrupt routine, and not a task, is executing.

元智大學資訊工程系 Systems - More Operating Systems Services57 Rule 1: No Blocking The nuclear reactor

元智大學資訊工程系 Systems - More Operating Systems Services58 An Example of Nonblocking

元智大學資訊工程系 Systems - More Operating Systems Services59 Rule 2: No RTOS Calls without Fair Warning A naïve view

元智大學資訊工程系 Systems - More Operating Systems Services60 Rule 2: No RTOS Calls without Fair Warning What really happen

元智大學資訊工程系 Systems - More Operating Systems Services61 The First Solution Requiring your cooperation to intercept all the interrupts.

元智大學資訊工程系 Systems - More Operating Systems Services62 The Second Solution The RTOS provides a function that the interrupt routines call to let the RTOS know that an interrupt routine is running.

元智大學資訊工程系 Systems - More Operating Systems Services63 The Third Mechanism Some RTOSs provide a separate set of functions especially for interrupt routines. So there might be OSISRSemPost in addition to OSSemPost.

元智大學資訊工程系 Systems - More Operating Systems Services64 Rule 2 and Nested Interrupts If your system allows interrupt routines to nest, then another consideration comes into play. If the high-priority interrupt routine makes any calls to RTOS functions, then the lower- priority interrupt routine must let the RTOS know when the lower-priority interrupt occurs.

元智大學資訊工程系 Systems - More Operating Systems Services65 Rule 2 and Nested Interrupts The RTOS scheduler should not run until all interrupt routines are complete.