real time system 03 philip a lapalante 2nd edition

Upload: anshuljain77

Post on 30-May-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Real Time System 03 Philip A Lapalante 2nd Edition

    1/27

    Real-Timeernels

    KEY POINTS OF THE CHAPTER1. Real-timemultitaskingcan be achievedwithout intemrpts,and when

    feasible, t is preferredbecauset leads to systems hat ale easier oanalyze.2. Foreground/backgroundarchitectures are the most widely used inembedded PPlications.

    The task-control lock model s used n commercial eal-timeexecutivesand in full-featured operating systemswhere the number of tasks isdynamic or indeterminate.The more featuresa real-timekernelprovides, themore complex t is, themore its performancedegrades,and the more difficult it is to analyze.A nonintemrpt driven cyclic executive s basedon one or severalmajorcycles that describe he order in which minor cycles are executed.

    In Chapter 1 we noted that a specializedcollection of systemprograms s calledan operating system.Anyone who has used a computer has intdractedwith thecomputer'sopelatingsystemdirectly or indirectly.Although there aremany well-known commercial operating systems, they are often too bulky and too all-purpose to be useful in real-time applications that are embedded and hqvestringentresponse-time equirements.Frequently, the real-time systems designer must design a bare-bonesoperatingsystem,or useone of the specializedeal-timeoperatingsystems tiatare commerciallyavailable. For customcomputers uchas thoseused n many

    l4l

    5 .

  • 8/9/2019 Real Time System 03 Philip A Lapalante 2nd Edition

    2/27

    Chap.6l Real-TimeKem

    embeddedapplications,there are no commercial operating systems availablThis chapterwill help you build your own real-time operating system,or at leidentify desirable eatures f you choose o purchasea real-time operatingsystor use an existing one.All operatingsystemsmustprovidethree specificfunctions: task schedulitask dispatching, and intertask communication.A scheduler determineswhitask will run next in a multitasking system, while a dispatcher performs ttnecessary qokkeeping o start that task. These unctions can be provided eithby hardwareor by software.aswe shall demonstrate.Note also hat the termsraandprocessare interchangeable.A kernel, executive,or nucleus is the smallest portion of the operatisystem hat provides for task scheduling,dispatching, and intertask cornmunition. In embeddedsystems, his essentially epresents he entire real-time systewhereas n commercial real-time operating systems this might be all but ttdevicedrivers.An onion skin diagram suchas hatgiven in Figure 6.1 can beusto depict the role of the kemel in an operating system.

    Since the publication of the first edition of this text, new variants of ttdefinition of "kmel" have evolved. They are given here in increasing ordercomplexity. Of course, as the complexity decreases, o do the code size aresponse imes. The hierarchy is also shown in Figure 6.2.

    Figure6.1 The role of the kemel n operating ystems.

    . \

  • 8/9/2019 Real Time System 03 Philip A Lapalante 2nd Edition

    3/27

    Chao.6 I Real-Time Kemels

    User nterfaceShell

    Fileanddisksupportlnterorocessorommunicationandsvnchronization

    Task chedulingThreadfask ontrolBlockmanagement

    HardwareFigure 6.2 Kemel hierarchy.

    t Nano-kernel-Simple thread-of-executionsameas''flow-of-control")management. t essentiallyprovides only one of the three servrcesprovidedby a kemel; that is, it provides or task dispatching.Micro-kernel-A nano-kemel hat provides or task scheduling.Kernel-A micro-kemel that provides for intertask synchronizationandcommunicationvia semaphores,mailboxes, and other methods.Executive-A kemel that includes privatized memory blocks, I/Oservices,and other complex features.Most commercial real-time kemelsare really executives.

    t Operating system-An executive that provides for a generalizeduserinterface or commandprocessor, ecurity,and a file management ystem.By this definition, the Unix kernel is indeed an operating system.

    UNIX*, a registered rademark of AT&T's UNIX System Laboratories, sthe common name for a family of interactive, multiuser operating systems. t isavailable in one version or another for virtually any computer, ranging fromdegktop personal computers and workstations to the rnost powerful supr-computers.This capablemultitasking system s ideally suited or both stand-aloneand distributed processing configurations. It has powerful, yet easy-to-use,hardware nterface mechanisms, nd t providesan excellent rneansof organizingand storing files on a variety of media, ncluding magnetic disks, magnetic apes,and optical disks. Unix systemsare available to support ndividual users, smallgroups,or entire departmenKon a wide range of processingplatforms.

    In this chapterwe exam_inetrategiesemployed in the desigrr of real-timekemels.*IINIX is not an acronym, and therefore need not be capitalized unless referring to the

    registered rademark. Generally, the term 'Unix' is used throughout this text-

    r43

    Operatingystem

    ExecutiveKemelMicro-kemelNanekemel

    II

  • 8/9/2019 Real Time System 03 Philip A Lapalante 2nd Edition

    4/27

    1446.1 POLLED OOPSYSTEMS

    Chap. 6 I Real-Time Kerrnl.

    Polled loop systemsare the simplest real-time kernel. Polled loops allow for t'asresponseo singledevices ut can'tdo muchelse. n apolled oop system, singland epetitive est n'structions used o testa lag that ndicateswhether r not someventhas occurred. f the eventhas not occulred, hen thepolling continues.Nointertask ommunication r schedulings needed ecause nly a sinqle askexistsI EXAMPLE 6.1A software system s needed o handle packetsof data that arrive at a rate of no more than I persecond.A flag called "Packet_here" s set by the network, which writes the data into the CPL-*memory via DMA. The data are availablewhen Packet_here= 1. Using a Pascalcode fragment,uecan describea polled loop to handlesuch a system:

    II ' r l l l

    p','{iu,,

    ! l L l l

    wnt re L j

  • 8/9/2019 Real Time System 03 Philip A Lapalante 2nd Edition

    5/27

    6. 1 I PolledLoop SystemsSrn\\chposition

    Figure 6.3 Switch bounce.

    period can be realizedwith a programmable imer that issuesan interrupt afler acountdownperiod. n theabsence f suchhardware, software outinecanbe writtento implement he delay.To illustratesucha technique onsider he foilowing.I EXAMPLE.3A polled loop system s used to handle an event that occurs randomly but no more than once persecond.The event s known to exhibit a switch-bounceeffect that disappearsafter20 milliseconds.A 10-millisegond ixed-rate interrupt is available for synchronization.The event is signaled by anextemal device that sets a memory location FLAG to TRUE.

    In Pascala synchronizedpolled loop would look like:

    lJ5

    Onoff

    While TF.UEdobeg in

    if FLAG = TRUE thenbeg in

    c o u n te r : = 0 ;wh i fe counter