Sie sind auf Seite 1von 32

Lab 4 Learning the Development Environment The Next Step Lab Objectives:

This project is the third phase in the formal development life cycle of a portable data measurement and collection system. In the previous two phases, we developed the full specification and design documentation for the initial portions of the system. The development process included the high-level system architecture, the ability to perform a subset of the necessary control functions, and portions of the display and annunciation components. We also built and worked a simple kernel, a hardware timebase, and utilized a non-preemptive schedule to manage the selection and e ecution of the series of tasks comprising the system. !"#y d$ng kernel %&n gi'n,timebase hardware,l(p l)ch non-preemptive %* +u'n l, l$a ch-n v. th$c hi/n li0n ti1p c2a c3c tasks4 In the current phase, we will move those tasks from the simple kernel to a full real-time operating system! #y d$ng c3c tasks t5 simple kernel sang h/ %i6u h.nh real-time4 !7T894 called :ree7T89 !because of what we are paying for it, of course - we;re really clever with coming up with names4. FreeRTOS utilizes a preemptive, priority-based scheduler to manage the system ! preemptive" #h$%ng ph&p n'y kh(c ph)c nh$*c +i,m c-a l.p l/ch nonpreemptive khi th0i gian th1c thi c&c t&c v) l2u 3&c t&c v) s4 +$*c th1c hi5n v' c6 th, b/ ng(t gi7a ch8ng +, ph)c v) th1c thi c&c t&c v) kh&c 3% ch9 l.p l/ch n'y cho ph:p +;m b;o th0i gian +&p <ng cho c&c s1 ki5n v' t&c v) ng(n v' nhanh h%n= !FreeRTOS s> d)ng preemptive,l.p l/ch priority ?based +, t@ ch<c h5 thAng= <ost processors designed for embedded applications utilize just such a computing core!s= d>ng ? core4. The OS provides a number of built-in library functions as well as drivers for a wide variety of peripheral devices such as timers, digital input and output channels, telecommunications links, and analog to digital converters that can then be utilized in the application!OS cung cBp sA h'm th$ vi5n cCng nh$ +iDu khi,n c&c thi9t b/ ngoEi vi nh$ timers, input sA v' kFnh output,link truyDn thGng, HI3 +, dJng trong <ng d)ng= Kn an earlier phase of our proLect, we have worked with one such built-in device and its driver, the timer. We have also designed several others, one for the display, and other for a serial interface, and a third for the keypad, into our system. The goal of this phase of the project is to continue and to e tend our development of the environmental monitoring system. To that end, we;ll work with some of the other built-in capabilities on the 9tellaris @AIB<C9DEFG H Iorte -<C system and we will learn to design, develop, and debug drivers for such devices under :ree7T89

- ? of GD -

The final subsystem must be capable collecting data from several different types of sensors, performing some local processing of the data from those sensors, displaying it locally, and transmitting to a remote station Kn addition, low power consumption will be an important aspect of the final product. !3uAi cJng h5 thAng ph;i thu th.p +$*c d7 li5u t8 M v'i c;m bi9n kh&c nhau,th1c hi5n N> lO d7 li5u t8 sensors,hi,n th/ chPng,v' truyDn +9n trEm remote station=

- G of GD -

QRKST UV TRW3 RKSQ


Kn the third phase of the design life cycle of such a system, we will, M Kntroduce a real real time operating system X Hdd features and capabilities to an eNisting product Y Kncorporate several additional simple tasks to our system Z Kntroduce additional peripheral devices and develop drivers for them [ Hmend the formal specifications to reflect the new features \ Hmend eNisting ]T^ diagrams to reflect the new features _ ]tilize other ]T^ diagrams to model new, dynamic capabilities of the system ` 3ontinue to improve skills with pointers, the passing of pointers to subroutines, and manipulating them in subroutines
Prerequisites:

:amiliarity with I programming, the Te as Instruments 9tellaris @AI-B<C9DEFG implementation of the J7< Iorte -<C vK< microcomputer, and the IJ7 9ystems @mbedded Workbench integrated I H Jssembler development environment. J wee bit of patience.
Background Information:

Lid incredibly well on Mroject CN tired and an ious to rela . Oetting ready to go party in a few weeksP.but don;t want to go outside with the current temps and the rain. Real-time Operating S stem We are now moving our design to an 7T89 Q a real-time operating system called :ree7T89. This is an operating system with an attitudePa pirate operating system Pr..yeah, it;s got rr;sPand at least one nasty patchPrrPthis ain;t freetos, mateyPrrr. Mlease check out the :ree7T89 web site. Rou can find this and related documentation atP. httpSHHwww.freertos.orgH Iheck out the getting started and advanced information here or directly at httpSHHwww.freertos.orgH:ree7T89-+uick-start-guide.html httpSHHwww.freertos.orgH7T89Tports.html httpSHHwww.freertos.orgHaUUUEU.htmlVTI In this project, we;re going to continue to improve on the capabilities in our previous designsPthis is the real world and we;ll add more features to our system as well. We have to make money selling people things that we first convince them that they needPyes, we;ll make modifications to Wersion G.U of our earlier systemP.and raise the price, of course. We have to support the continually flagging economy.

- C of GD -

7elevant chapters from the te tS Ihapters X, D, E, ??, ?G, and ?F.

!autions and "arnings:

Yever ask a guide in the Zffizi in :irenze who is carrying rare porcelain vases directions to the Monte Wechio. Yever light up if you just purchased and donned paper pants and jacket from a street vendor to meet the Watican;s dress code. Thoughts on traveling this summer. In the Z.9., always look to the left, make sure all traffic is stopped for C miles in each direction, and erect protective barricades before crossing the street then walk out without even looking to see if there is any traffic coming and register with the nearest lawyer on the other side of the street. In the Z.A., always look rightPit;s generally safe e cept for the ta is in Bondon. In :rance, look both ways, because they really are aiming for youP.then look again, take a phasor disrupter, and run really fast, firing in all directions. This will stop les voitures aiming for you as well as the rampaging strikers protesting somethingP+ua[Pje ne sais +ua. In ItalyPwellP.forget it, you;ll never get across the street Q don;t even try. In Wietnam, hmmm, there;s a challenge. <oses parting the 7ed 9ea was an amateur compared to anyone crossing a major boulevard in 9aigon with XUU million motorcycle drivers !even more than in Italy4 who think a 7ed light is an amusing diversion. Why are the night markets open during the day in Taiwan[ \e certain to check out the wiring in your hotel room where ever you goPand take along some black tape just in case. Jfter the climate change is over, will we still be able to get ice in Iceland[ Jlways practice safe software engineeringPdon;t leave unused bits laying around the lab or as 9cott Jdams writes in the Lilbert strip.

^Lilbert by 9cott Jdams Q GF _anuary GU?C

Laborator :

We will use this project to continue working with the formal development life cycle of an embedded system. 9pecifically, we will continue to move inside the system to implement the software modules !the how Q the system internal view4 that was reflected in the use cases !the what Q the system e ternal view4 of the environmental monitoring and analysis system. To this end, we will continue the development of a simple kernel and scheduler that will handle a number of new and legacy tasks and support dynamic task creation and - ] of GD -

deletion.!I`ng van ph3t tri*n simple kernel v. l(p l)ch,tasks %bng ,th0m ca4 ae will now introduce and design a dynamic task bueue cach task will continue to share data using pointers and data structs !Thi9t k9 h'ng +*i task +dng,mei task s4 share d7 li5u s> d)ng pointers and data structs = In the initial phase, we modeled many of the subsystems as we focused on the flow of control through the system. In the second phase, we started to implement the detailed drivers for the various subsystems. Qow, in the third phase, our main focus will be on porting the system to a real-time operating system !RTOS=!Trfng t2m chgnh"""" N2y d1ng h5 thAng trFn h5 +iDu h'nh th0i gian th1c= . We will continue to work with the IJ7 IL@ development tool to edit and build the software then download and debug the code in the target environment. Js we continue the development of the system, we willP. Introduce a real time operating system, Todify the startup task to work under the RTOS, ]tilize a priority based preemptive schedule, ]pgrade the hardware based system time base, Iontinue work with the 9tellaris Iorte -<C OMI8 subsystem, Incorporate several additional tasks and peripheral devices, 3ontinue work with interrupts, interrupt service routines, and hardware timing functions, Implement and test the new features and capabilities of the system, Ztilize Z<B diagrams to model some of the dynamic aspects of the system.

This lab, lab report, and program are to be done as a team Q play nice, share the e+uipment, and no fighting.
Soft#are Project $ %eveloping Basic &asks

Rou have just been given a once in a lifetime opportunity to participate in the formation an e citing new start up. \ecause of the growing concerns over rising temperatures and the associated glacial melt, you and several colleagues have decided to set your own direction and to start a company to develop a multipurpose environmental monitoring and reporting system. \ased upon initial discussions with your colleagues, you decide to call the company MonitoringStuffRUs-UnLtd, and have put together a set of preliminary re+uirements for a small, portable, low power, product based on IMod and smart phone ideas and technologies. The product, CheckItOut, will have the ability to perform many of the basic environmental measurements that people studying and researching factors potentially affecting climate change need to make.

- X of GD -

Rour team decides that the system must be portable, lightweight, low power, ine pensive, and Internet enabled. :urther, that the prototype unit must have the ability to make such basic measurements as temperature, flow rate, concentration of various pollutants or mi tures, etc., perform simple computations such as trending, and log historical data. The initial deliverables for the system will include the display and alarm portion of the monitoring system as well demonstrated ability to handle temperature, flow rate, and perform carbon and salinity measurements. 8ther measurements and capabilities will follow in subse+uent phases. Jll of the sensors that will provide input to the system and any of the peripheral devices with which the system will be able to interact will not be available at present, so, we will model those signals to test the system architecture, flow of control, infrastructure, and internal data sharing. The first and second phases of the environmental monitoring system have been successfully completed. Rour company has just been awarded the development contract for the third stage of the project. 9imilar to the second phase, the tasks during the current phase include modifications to the design to improve performance as well as to incorporate additional features and capabilities. The Mhase III features are given in the re+uirements and design specifications that follow. 7e+uirements for the first two phases have been removed for clarity. Mhase III re+uirements supersede Mhase I and II specifications where ever there may be a conflict. The re+uirements for the third phase of the project development life cycle are specified below. System Requirements Specification
1. !eneral Description

J state of the art environmental monitoring and analysis system is to be designed and developed. The following specification elaborates the re+uirements for the display and alarm portion of the system. The display and alarm management subsystem must accept inputs from a number of sensors that can be used to collect data from various points in a localized geographic area which may be either on land or in the ocean or a river then signal a warning if the data falls outside of pre-specified bounds. Letailed analysis of the data will be performed by other parts of the system to be added at a future time. The outputs of the sensors are measuring a variety of natural phenomenon the values of which comprise a number of different data types such as integers, strings or high precision numbers. The system must be designed to accommodate each of these different types.
"hase ### $o%ification

:or clarity, the identification of most of the Mhase I and Mhase II modifications has been removed from this document. If specific information about these modifications is re+uired, refer the appropriate earlier version.

- F of GD -

P'ase III (dditions

M X Y

The system will incorporate a real-time operating system #lease see HppendiN H The overall system safety must be improved Hmend the rebuirements and design specifications to reflect the new features

3h3 y9u tA cin thFm" M R5 +iDu h'nh th0i gian th1c X s1 an to'n c-a h5 thAng ph;i +$*c c;i thi5n YjthFm c&c tgnh nkng mli
&. Display an% 'larm $anagement System

The display and measurement component of the system in the first prototype must track and support the measurement and display of the following signalsS
$easurements

Temperature :low 7ate Ioncentration of several different pollutants or other chemical elements The status, alarm, and warning management portion of the system must monitor and annunciate the following signalsS
Status

\attery state
'larms

Temperature, flow rate or pollutant concentration too high


(arning

Temperature, flow rate, or pollutant concentration out of range Iisplayed messages comprise three maLor categories" annunciation, status, and warning / alarm. 9uch information is to be presented on an 8B@L display and on a series of lights on the front panel. 9ensor signals are to be continuously monitored against predetermined limits. If such limits are e ceeded, a visible and aural indication is to be given and shall continue until acknowledged. Jcknowledgement shall terminate the aural indication but the visible indication shall continue until the aberrant value has returned to its proper range. If the signal value remains out of range for a specified time, the aural annunciation shall recommence.
"hase ### '%%itions

The system will incorporate a real-time operating system. Mlease see Jppendi J.

- K of GD -

The system will support the measurement analog signals from temperature, carbon, and salinity sensors. #lease see the documentation for the analog to digital convertor in the HRT 3orteN-TY v_T microcomputer data sheet and on the class web site

- D of GD -

&.1 )se *ases

The following use cases e press the e ternal view of the system !see Ihapter X in the te t4, !To be added Q by engineering P this would be you4
"hase ###

!To be updated as necessary4

Soft+are Design Specification


1. !eneral Description

J prototype for a state of the art environmental monitoring and analysis system is to be designed and developed. The high-level architecture is to be modular, comprising a set of tasks that are e ecuted, in turn, forever. The third phase of the development cycle will focus on enhancing the system flow of control, developing KjO drivers for several of the sensors, and enhancing the display and alarm management subsystem !miai +oEn th< ba c-a chu kn ph&t tri,n s4 t.p trung v'o tkng c$0ng dong ch;y h5 thAng ki,m so&t, ph&t tri,n trpnh +iDu khi,n K j O cho mdt sA c&c bd c;m bi9n, v' tkng c$0ng m'n hpnh hi,n th/ v' h5 thAng con bu;n lO b&o +dng = The display and alarm management subsystem which must accept inputs from a number of sensors that are used to collect data from various points in a localized geographic area which may be either on land or in the ocean or a river then signal a warning H alarm if the data falls outside of pre-specified bounds. Letailed analysis of the data will be performed by other parts of the system to be incorporated later. The outputs of the sensors are measuring a variety of natural phenomenon the values of which comprise a number of different data types such as integers, strings or high precision numbers. The system must be designed to accommodate each of these different types. The prototype will be implemented using the J7< Iorte -<C vK< microcomputer development board. The prototype software will schedule task e ecution, control the 8B@L on the board, and manage the peripheral B@Ls through the processor;s output ports.
In addition, each team member must determine the execution time of one of the tasks analytically - you examine the comprising instructions and add up their times. Each team member must do one task. "hase ### '%%itions an% $o%ifications

To implement the re+uired additions to the product, the following Mhase C capabilities must be incorporated. a. A Real Time Operating System - Implemented using the :ree7T89 !7T894 system. b. Startup ProcessS <odify the task creation and initialization process when the system starts as re+uired by the operating system. a Tdt h5 +iDu h'nh th0i gian th1c - th1c hi5n bqng c&ch s> d)ng h5 thAng FreeRTOS !RTOS=

- E of GD -

b rhsi +dng bu& trpnh" S>a +@i c&c bu& trpnh tEo cGng vi5c v' khsi tEo khi h5 thAng b(t +iu theo yFu ciu c-a h5 +iDu h'nh The following elaborates the updated specifications for the display and alarm portion of the system.!ph3t tri*n hi*n th) v. c'nh b3o4
&. ,unctional Decomposition Tas- Diagrams

The system is to be decomposed into the maLor functional blocks" Measure, Compute, Display, Data Entry, Annunciation, Status, and Schedule. These blocks decompose into the following taskHclass diagrams !see Ihapter X in the te t4, !To be supplied by engineering4

&.1 System Soft+are 'rchitecture

The environmental monitoring and collection system is to be architected as a set of tasks based upon the functional decomposition given above and are specified in the following taskHclass diagrams !see Ihapter X in the te t4. !To be supplied by engineering and updated as necessary4
"hase ### $o%ification

The set of tasks will e ecute continuously following power 8Y. They will all have designer assigned priority and will be pre-emptable. Information within the system will be e changed utilizing a number of shared variables.
&.1.1 Tas-s an% Tas- *ontrol .loc-s

The design and implementation of the system software will comprise a number of tasks. @ach task will be e pressed as a TI\ !Task Iontrol \lock4 structure.
"hase ### mo%ification

The following TCB description replaces the previous version T3t creation will be done under the FreeRTOS OS utilizing a task create wrapper function !T3t s4 +$*c tEo ra d$li h5 +iDu h'nh FreeRTOS= Ietails of the function are given in HppendiN H. The following function prototypes given for the tasks are defined for the application
"hase ###

! To be updated to reflect additions and modifications 4

- ?U of GD -

- ?? of GD -

&.1.& #ntertas- Data Exchange an% *ontrol Data

Jll of the system;s shared variables will have global scopeN the remainder will have local scope. \ased upon the 7e+uirements 9pecification, the following variables are defined to hold the status and alarm information and command and control information. The initial state of each of the variables is specified as followsS
$easurements

Type unsigned int temperature7aw\ufdDe


Display

flow7ate7aw\ufdDe carbonBevel7aw\ufdDe salinityBevel7aw\ufdDe

Leclare as a D measurement temperature buffer Leclare as a D measurement flow rate buffer Leclare as a D measurement carbon level buffer Leclare as a D measurement salinity level buffer

Type unsigned int tempIorrected flow7ateIorrected carbonBevelIorrected salinityBevelIorrected initial value U initial value U initial value U initial value U

Type !To be supplied by engineering4


'larms

Aeypad status and data Bocal Iomms status and data

initial values initial values

Type unsigned char temp8ut8f7ange flrt8ut8f7ange carbonBevel8utof7ange salinityBevel8utof7ange initial value U initial value U initial value U initial value U

- ?G of GD -

(arning

Type \ool?
Status

tempfigh flrtfigh carbonBevelfigh salinityBevelfigh

initial value :JB9@ initial value :JB9@ initial value :JB9@ initial value :JB9@

Type unsigned short battery9tate initial value GUU

?. Jlthough an e plicit boolean datatype was added to the JY9I standard in <arch GUUU, the compiler weire using doesnit recognize it as an intrinsic or native type. !9ee httpSHHen.wikipedia.orgHwikiHITprogrammingTlanguageVIEE if interested4 We can emulate the \oolean datatype as followsS enum _myBool { FALSE = 0, TRUE = 1 }; typedef enum _myBool Bool; Mut the code snippet in an include file and include it as necessary.

&.1./ Data Structures

The TI\ member, taskLataMtr, will reference a struct containing references to all data utilized by task. @ach data struct will contain pointers to data re+uiredHmodified by the target task as given in the following representative e ample,

where gdatah would be an integer re+uired by myTask. $easureData folds pointers to the shared variablesS temperature\uf flow7ate\uf carbonBevel\uf salinityBevel\uf *omputeData folds pointers to the shared variablesS - ?C of GD -

temperature\uf flow7ate\uf carbonBevel\uf salinityBevel\uf tempIorrected flow7ateIorrected carbonBevelIorrected salinityBevelIorrected DisplayData folds pointers to the shared variablesS tempIorrected flow7ateIorrected carbonBevelIorrected salinityBevelIorrected battery9tate !To be supplied by engineering4 Aeypad status and data Bocal Iomms status and data (arning'larmData folds pointers to the shared variablesS temperature\uf flow7ate\uf carbonBevel\uf salinityBevel\uf battery9tate Status folds pointers to the shared variablesS battery9tate
"hase ### Sche%uleData %eprecate%

Sche%uleData folds pointer to YZBB

- ?] of GD -

"hase ### mo%ification

0eypa%*onsoleData folds pointers to the variablesS Aeypad status and data !To be supplied by engineering4 !To be updated as necessary4 Local*omsData folds pointers to the variablesS Bocal Iomms status and data !To be supplied by engineering4 !To be updated as necessary4
&.1.1 Tas- 2ueue "hase ### $o%ification

The tasks comprising the application will be held in a task +ueue and will be pre-emptable. The initial task +ueue will be created under the startup task in the :ree7T89 89. Thereafter, it will managed by the 7T89 scheduler. Letails of the 89, the startup task, and TI\s are given in Jppendi J. 9even of the TI\ elements in the +ueue correspond to tasks, Measure Co!pute "ispla# $e#padConsole LocalCo!s %arning-&lar! and Status and one to the dynamically scheduled Startup' The tasks are identified and elaborated in 9ection G.G. The Schedule task is not in the +ueue. The task function pointer in each TI\ should be initialized to point to the proper task. :or e ample, TI\ element zero should have its function pointer initialized to point to the taskU function. The data pointer of each TI\ should be initialized to point to the proper data structure used by that task. :or e ample, if Measure"ata is the data structure for the task Measure, then the data pointer of the TI\ should point to Measure"ata. (ote) %hen a conte*t switch is !ade +ecause a running task +locks or ter!inates or on return fro! interrupt the highest priorit# task that is read# to run will +e selected fro! the ,ueue started or resu!ed and !oved to the run state' -or the case of an interrupt the resu!ed task !a# or !a# not +e the interrupted task'
&.& Tas- Definitions an% .ehaviour

The dynamic behaviour of each task is given, as appropriate, in the following activity diagrams !see Ihapter X in the te t4. !To be supplied Q by engineering4
"hase ###

!To be updated as necessary4

- ?X of GD -

Startup Phase III Modification

The startup task shall run one time at startup and is to be the first task to run. It shall not be part of the task +ueue. The task shall, Ionfigure and activate the system time base that is to be the reference for timing all warning and alarm durations. Ionfigure and initialize all hardware subsystems. Ireate and initialize all statically scheduled tasks. @nable all necessary interrupts. 9tart the system. @ it.

The static tasks are to be assigned the following prioritiesS !To be supplied by engineering4

Schedule Phase III Modification

The schedule task is deprecated and replaced +# the -reeRTOS scheduler The schedule task manages the e ecution order and period of the tasks in the system. fowever, the task is not in the task +ueue. The round robyn task schedule comprises a major cycle and a series of minor cycles. The period of the major cycle is X seconds. The duration of the minor cycle is specified by the designer. :ollowing each cycle major cycle through the task +ueue, the scheduler will cause the suspension of all task activity, e cept for the operation of the warning and error annunciation, for five seconds. In between major cycles, there shall be a number of minor cycles to support functionality that must e ecute on a shorter period. The following block diagram illustrates the design. The Olobal Iounter is incremented every time the Bocal Lelay e pires. If the Bocal Lelay is ?UU ms, for e ample, then ?U counts on the Olobal Iounter represent ? sec. Jll tasks have access to the 9ystem Time \ase and, thus, can utilize it as a reference upon which to base their timing. The 9oftware Lelay must be replaced by a fardware Timer.

- ?F of GD -

Yote, all timing in the system must be derived from the 9ystem Time \ase. The individual tasks cannot implement their own delay functions. :urther, the system cannot block for five seconds. The following se+uence diagram gives the flow of control algorithm for the system !To be supplied Q by engineering4
Phase III

!To be updated as necessary4

Measure

The <easure function shall accept a pointer of type voidj with a return type of void. The pointer in the task argument will be re-cast as a pointer to the Measure task;s data structure type before it can be dereferenced.
Phase III modification

The following task descriptions for the !easure!ent of te!perature car+on level and salinit# level replace the previous versions' The flow rate !easure!ent re!ains unchanged' :or the prototype, the temperature and the carbon and salinity levels must be measured. These data are to be read as analog signals on input Ihannels U, ?, and G. The JHL convertor will return the value of the voltage on the corresponding input channel e pressed as a ?U bit binary number. The input voltage range supported by the JHL is U.U to C.C W. The system shall store the D most recent samples for each measurement, as ?F bit binary numbers, into each of the corresponding buffers. The stored values shall be e pressed in millivolts.
temperatureRa+

Temperature is measured by a temperature transducer. The output of the transducer is an analog signal with a range of U to k GUU mW LI.
car3onLevelRa+

Iarbon level is measured by a carbon level transducer. The output of the transducer is an analog signal with a range of U to k ?UU mW LI.
salinityLevelRa+

9alinity level is measured by a carbon level transducer. The output of the transducer is an analog signal with a range of U to k ?UU mW LI.

- ?K of GD -

flo+RateRa+

The flow7ate is measured by a flow rate transducer. The output of the transducer is a digital signal that appears as a series of successive negative transitions. 9uch transitions can be detected using an e ternal event interrupt. The fre+uency of the signal is thence proportional to the flow rate. The fre+uency of the signal is determined by first measuring the time interval between successive transitions. The measured values are then stored in a circular D reading buffer as binary values. The values are only to be stored if the current reading differs by more than ?Xl from the previously stored reading Q note this is above or below the previously stored reading. The flow7ate transducers are currently under development. 8ne of the objectives of the present phase is to obtain some field data on a beta version of the transducers. To this end, the upper fre+uency limit !shortest interval between transitions4 of the incoming signal must be empirically determined. The upper limit will correspond to GUU liters per second and the lower to G liters per second.
Compute

$easure% #nterval

The Co!pute function shall accept a pointer of type voidj with a return type of void. The pointer in the task argument will be re-cast as a pointer to the Co!pute task;s data structure type before it can be dereferenced. When available, the Co!pute task will take the data ac+uired by the Measure task and perform any necessary transformations or corrections. The following relationships are defined between the raw data and the converted values. a. Temperature in IelsiusS tempIorrected m X k U.Dtemp7aw b. IarbonBevel in ppmS carbonBevelIorrected m K k ?.G carbonBevel7aw c. 9alinityBevel in pptS salinityBevelIorrectedm F k U.K salinityBevel7aw d. :low 7ate in lpsS flow7ateIorrected m E kG.Uflow7ate7aw

Keypad Console Task

The ke#padConsole function shall accept a pointer of type voidj with a return type of void. The pointer in the task argument will be re-cast as a pointer to the ke#padConsole task;s data structure type before it can be dereferenced. The keypad shall enable the user to program the environmental monitoring system and shall be scanned for new key presses on a two-second cycle or as needed.

- ?D of GD -

Aeypad input will override localIomms input. The ke#padConsole task will support the following functionality in Mhase II.
a. 0eypa% 4 Local*omms Select 0ey '

Aeypad H BocalIomms 9elect shall permit the user to choose the keypad or the serial communication !localIomms4 channel to configure the system. The ' key on the keypad shall be used to select between the two choices.
b. 5LED 4 Local*omms Select 0ey .

8B@L H BocalIomms 9elect shall permit the user to choose between the 8B@L display or the serial communication !localIomms4 channel to display system configuration or measurement information.
c. ,unction Select

The *.., keys on the keypad shall be used to select the function to be programmed. The following functions will be supportedS
Scan *onfigure 4 Display 0ey *

9can Ionfigure H Lisplay 9elect shall permit the user to choose between configuring a scan or displaying measurement data when the system is scanning. The display device will be specified by the 8B@L H BocalIomms 9elect function. J scan comprises a se+uence of measurements that are to be made. :or Mhase II, four measurement types are supported. Temperature U Iarbon ? 9alinity G :low 7ate C J measurement type can be repeated in a scan.

LocalComms

The localCo!!s task shall accept a pointer of type voidj with a return type of void. In the implementation of the function, this pointer will be re-cast as a pointer to the localCo!!s task;s data structure type. The localCo!!s task will manage a bidirectional local serial communication channel between the monitoring e+uipment and a local mobile device. The e change shall comprise specified commands from a mobile device as well as returned status, warning, and alarm information. Information returned from the monitoring device will be sent to the mobile device where it can be stored and also displayed using fypertermn or on the 9erial Mort <onitor. The localCo!!s driver shall enable the user to issue commands program the environmental monitoring system or display measurement data. Aeypad input will override localCo!!s input. The localCo!!s task will support the following functionality in Mhase II. - ?E of GD -

a. 0eypa% 4 Local*omms Select 0ey '

Aeypad H BocalIomms 9elect shall permit the user to choose the keypad or the serial communication !localIomms4 channel to configure the system. The two letter command ' shall select keypad input. The two letter command '1 shall select localIomms input.
3. 5LED 4 Local*omms Select 0ey .

8B@L H BocalIomms 9elect shall permit the user to choose between the 8B@L display or the serial communication !localIomms4 channel to display system configuration or measurement information. The two letter command . shall select 8B@L. The two letter command .1 shall select localIomms.
c. ,unction Select

The *.., keys on the keypad shall be used to select the function to be programmed. The following functions will be supported
Scan *onfigure 4 Display 0ey *

9can Ionfigure H Lisplay 9elect shall permit the user to choose between configuring a scan or displaying measurement data when the system is scanning. The display device will be specified by the 8B@L H BocalIomms 9elect function. The two letter command * shall select scan configuration. The two letter command *1 shall select display measurement data. J scan comprises a se+uence of measurements that are to be made. :or Mhase II, four measurement types are supported. Temperature U Iarbon ? 9alinity G :low 7ate C J measurement type can be repeated in a scan. In the display mode, the corrected measurement data presented on the local console must be e pressed as four strings as followsS Temperature o JHL Ihannel V readingp I Iarbon Bevel o JHL Ihannel V readingp ppm 9alinity Bevel o JHL Ihannel V readingp ppt :low 7ate o :low rate reading p BM9 \attery 9tatus oTime remainingp fours

OL !display The oled"ispla# function shall accept a pointer of type voidj with a return type of void. - GU of GD -

In the implementation of the function this pointer will be re-cast as a pointer to oled"ispla# task;s data structure type before it can be dereferenced. The oled"ispla# task provides a driver for the local 8B@L display. The driver supports two major modesS *onfigure and Run.
*onfigure $o%e

In the *onfigure $o%e, the oled"ispla# task presents the current configuration of the instrument by default and provides the display portion of the user interface when the user is programming the instrument.
Run $o%e

In the Run $o%e, the oled"ispla# task retrieves the measurement results of the Co!pute task. The task must convert the data into J9III, format it so that it may be displayed on the instrument front panel 8B@L display, and finally present the data. Temperature, flow rate, battery status, and carbon and salinity levels shall be presented as illustrated in the following front panel diagram, Temperature Iarbon Bevel 9alinity Bevel :low 7ate \attery 9tatus o JHL Ihannel V readingp I o JHL Ihannel V readingp ppm o JHL Ihannel V readingp ppt o :low rate reading p BM9 oTime remainingp fours

!To be supplied Q by engineering4

"arning# Alarm

The %arning-&lar! function shall accept a pointer of type voidj with a return type of void. The pointer in the task argument will be re-cast as a pointer to the %arning-&lar! task;s data structure type before it can be dereferenced.

- G? of GD -

The normal range for the measurements is specified as followsS ?. TemperatureS -?X I to XU I G. :low 7ateS ?GU liters per second C. IarbonBevelS CDU ppm ]. 9alinityBevelS CU ppt X. \atteryS Oreater than GUl charge remaining The normal state shall e ist under the following conditionsS ?. If all measurements and the state of the battery are within their specified range, all B@Ls on the front panel shall be 8::. J warning shall be issued under the following conditionsS ?. If any measurement is out of range, the 7@L B@L on the front panel shall be illuminated and flashing with a one second period. G. If the flow rate measurement is out of range, B@LU on the front panel shall be illuminated and flashing with a G second period. C. If either the carbon or salinity level is out of range, B@L? on the front panel shall be illuminated Jn alarm shall be issued under the following conditions ?. If either pollutant level measurement is more than GU percent above the specified limit, B@LG on the front panel shall be illuminated and solid. The aural alarm shall sound with a series of one second tones. G. If &cknowledge key on the front panel is depressed, the aural alarm shall cease and B@LC on the front panel shall flash with a one second period until the levels return to within EUl of normal. The state of the battery display shall flash with a one second period when the state of the battery drops below GUl remaining.
Status

The Status function shall accept a pointer of type voidj with a return type of void. The pointer in the task argument will be re-cast as a pointer to the Status task;s data structure type before it can be dereferenced. The battery state shall be decremented by ? each time the Status task is entered.

- GG of GD -

Phase III &.6 Data an% *ontrol ,lo+

The system inputs and outputs and the data and control flow through the system are specified as shown in the following data flow diagram. !To be supplied by engineering4
&.7 "erformance

The following re,uire!ent has +een !odified The e ecution time of each task is to be determined analytically Q you must e amine the comprising instructions and add up their times. @ach person in the group is to select one task on which to perform the analysis.

&.8 !eneral

8nce each cycle through the task +ueue, one of the OMI8 lines must be toggled. Jll the structures and variables are declared as globals although they must be accessed as locals. (ote) %e declare the varia+les as glo+als to per!it their access at run ti!e' The flow of control for the system will be implemented using a construct of the form
+hile91: ; myStuff< =

The program should walk through the +ueue you defined above and call each of the functions in turn. \e sure to implement your +ueue so that when it gets to the last element, it wraps back around to the head of the +ueue. In addition, you will add a timing delay to your loop so that you can associate real time with your annunciation counters. :or e ample, if the loop were to delay Xms after each task was e ecuted, you would know that it takes GXms for all tasks to be e ecuted once. We can use this fact to create task counters that implement the proper flashing rate for each of the annunciation indicators. :or e ample, imagine a task that counted to XU and then started over. If each count lasted GUms, !due to the previous e ample4 then the task would wait ? second !XU j GUms4 between events. To accomplish this, we create the functionS gdelayTms!int timeTinTms4h. Thereafter, simply call this function with the delay in milliseconds as its argument. 7emember Bab ?.

- GC of GD -

)*+ Recommended %esign (pproac'

This project involves designing, developing, and integrating a number of software components. 8n any such project, the approach one takes can greatly affect the ease at which the project comes together and the +uality of the final product. To this end, we strongly encourage you to follow these guidelinesS ?. Levelop all of your Z<B diagrams first. This will give you both the static and dynamic structure of the system. G. \lock out the functionality of each module. This analysis should be based upon your use cases. This will give you a chance think through how you want each module to work and what you want it to do. C. Lo a preliminary design of the tasks and associated data structures. This will give you a chance to look at the big picture and to think about how you want your design to work before writing any code. This analysis should be based upon your Z<B classHtask diagrams. ]. Write the pseudo code for the system and for each of the constituent modules. X. Levelop the high-level flow of control in your system. This analysis should be based upon your activity and se+uence diagrams. Then code the top-level structure of your system with the bodies of each module stubbed out. This will enable you to verify the flow of control within your system works and that you are able to invoke each of your procedures and have them return the e pected results in the e pected place. F. When you are ready to create the project in the IJ7 IL@. It is strongly recommended that you follow these stepsS a. \uild your project. b. Znderstand, and correct if necessary, any compiler warnings. c. Iorrect any compile errors and warnings. d. Test your code. e. 7epeat steps a-d as necessary. f. Write your report g. Lemo your project. h. Oo have a beer. Caution" Knterchanging step h with any other step can significantly affect the successful completion of your design j proLect
,*+ Lab Report

Rou are welcomed and encouraged to use any of the e ample code on the system either directly or as a guide. :or any such code you use, you must cite the source uyou will be

- G] of GD -

given a failing mark on the lab if you do not cite your sources in your listing - this is not something to be hand written in after the fact, it must be included in your source codeu This is an easy step that you should get in the habit of doing. !o not $orget to use proper coding style% including proper comments& Please see the coding standard on the class 'eb page under documentation& Mlease include in your lab report an estimate of the number of hours you spent working on each of the followingS Lesign Ioding Test H Lebug Locumentation Mlease include the items listed below in your project reportS ?. fard copy of your pseudo code G. fard copy of your source code. C. @mpirically measured individual task e ecution time. ]. Include a high-level block diagram with your report. X. \e sure to include all of the items identified as qto be provided by engineering.; F. If you were not able to get your design to work, include a contingency section describing the problem you are having, an e planation of possible causes, a discussion of what you did to try to solve the problem, and why such attempts failed. K. The final report must be signed by team members attesting to the fact that the work contained therein is their own and each must identify which portion!s4 of the project she or he worked on. D. If a stealth submersible sinks, how do they find it[ E. Loes a helium filled balloon fall or rise south of the e+uator[ ?U. If you fly faster than the speed of sound, do you have to slow down every now and then to let the sound catch up[ ??. If you fly really really fast around the world, can you catch up to the sound before it catches up to you and answer a +uestion before you hear it[ ?G. If you don;t answer a cell phone call, where does it go[ Is it just sitting there waiting for you[
NO E! If any of the abo"e re#uirements is not clear, or you ha"e any concerns or #uestions about you$re re#uired to do, please do not hesitate to ask us.

- GX of GD -

(ppendi- (: "orking #it' an R&OS

We are now moving the design to an 7T89 Q real-time operating system called, simply enough, :ree7T89 because of what it is and the price we pay for it. This operating system is an open source version of another 89 called <icro I H 8perating 9ystem or IH89. Js we move to the 89, we will bring forward all of the tools and techni+ues that we have studied thus far. Rou are encouraged to look at the information and tutorials on the :ree7T89 websitesS httpSHHwww.freertos.orgH httpSHHwww.freertos.orgHportlmCs EFX.htmlV9ourceIode8rg for a lot of very good information. Jlso, the class webpage for a working e ampleS httpSHHwww.ee.washington.eduHclassH]KGHpeckolHcodeH9tellaris@ amplesH Bet;s see how this works. In our work so far, we have created Task Iontrol \locks !TI\s4 of increasing comple ity to contain our task;s function and data. Znder :ree7T89, we;ll do the same thingN however, now, we will use a wrapper function as a tool to build those for us. Znder :ree7T89, we write, Tas-s We create a task using the system call,
voi% > Tas-*reate 9 voi%9tas-*o%e:9voi% >:? 44 44 44 char >name? int stac-Depth? voi% >parameters? int priority? tas-Can%le >create%tas-"tr 44 44 44 44 44 pointer to the tas- function the tas- prototype is of the form "oid task %"oid &pd'( name of the tassi@e of the stac- allocate% for the taspointer to the %ata passe% in to the tastas- priority ..A? lo+est B highest han%le 3y +hich the create% tas- can 3e reference%

9ee all this stuffPsee we weren;t lying to youP.this is really how you do itP.

- GF of GD -

Tas- Execution The system e ecutes in an infinite loop as we have been doing. We force a conte t switch using a vTask"ela#./ statement to give up the IMZ to another task. $ain Rour main!4 with one additional simple task might look like the following,

- GK of GD -

44 tas- prototypes voi% vTas-19voi% >v"arameters:< voi% main9 voi% : 44 this tas- gets calle% as soon as +e 3oot up. ; 44 this is the startup tas44 set up the har%+are prvSetupCar%+are9:< 44 har%+are setup 44 create the tas-s xTas-*reate9vTas-1? DTas- 1D? 1 44 other tas-s to 3e create% 44 remaining co%e 44 start the sche%uler vTas-StartSche%uler9:< 44 shoul% never get here return< = voi% vTas-19voi% >v"arameters: ; 44 test message to %isplay x5LED$essage x$essage< x$essage.pc$essage E DCello from? Tas- 1D< 44 all tas-s run in an infinite loop +hile91: ; 44 Sen% the message to the 5LED gate-eeper for %isplay. x2ueueSen%9 x5LED2ueue? Fx$essage? :< 44 %elay to force a context s+itch vTas-Delay91 :< = = 44 other tas-s an% co%e ? N)LL? 1? N)LL:<

- GD of GD -

(ppendi- B: .eneral Purpose I/O $ .PIO Overvie#

The Oeneral Murpose IH8 module enables the Iorte processor to bring !digital4 signals in from e ternal world devices or to send !digital4 signals to out to e ternal world devices. :rom the processor;s data sheet, the OMI8 module is composed of seven physical blocks, each corresponding to an individual OMI8 ports !Mort J, Mort \, Mort I, Mort L, Mort @, Mort :, Mort O4. The module supports from X to ]G programmable inputHoutput pins, depending on the peripherals being used. Letails of the OMI8 subsystem, specific capabilities, and how the blocks are configured are given in section D of the B<C9DEFG datasheet. httpSHHwww.ee.washington.eduHclassH]KGHpeckolHdocH9tellarisLocumentationHLeviceHLatashee t-B<C9DEFG.pdf 7ead through this section carefully. It is important to note that all OMI8 pins are tri-stated by default and that asserting a Mower-8n-7eset !M874 or 79T puts the pins back to their default state. Jlso look through the blinky, adTest, and gpioTjtag e amples in the IJ7 Workbench and the e amples in section D of the datasheet. 9ee also httpSHHwww.ee.washington.eduHclassH]KGHpeckolHdocH9tellarisLocumentationH\oardHDEFGT@va l\oard.pdf for the 9tellaris \oard IH8 pinout.
!"#5 "a%

The OMI8 function interfaces to the e ternal world through what is called a digital I0O pad. The pad associated with each port can be independently configured, by the user, based on the particular application re+uirements. Zsing the pad control registers, it is possible to set the drive strength, specify an open-drain configuration, choose pull-up and pull-down resistors, control the signal slew-rate, and digital input enable.
.asic *onfiguration an% *ontrol Registers

The specific configuration or operational mode for a OMI8 port !and thus set of pins4 is established through a user programmable set of control registers. The direction of each individual pin, as either an input or an output, is determined by the value of the corresponding bit in a data direction register' \ased upon the values in the data direction register, the associated data register either captures incoming data or drives it out to the pads. When the corresponding data direction bit is set to U, the pin is configured as an input and the corresponding data register bit will capture and store the value on the OMI8 port pin. When the data direction +it is set to ?, the OMI8 is configured as an output and the corresponding data register bit will be driven out on the OMI8 port.

- GE of GD -

(ppendi- !: Background on Interrupts

7ecall back to the last lab, in order to determine when a time delay had passed, we used a function of the form dela#MS./ function. This is a very inefficient use of valuable resources. The dela#MS./ function is a software loopN while we are in the loop, we can do nothing else. We will now use a timer and timer interrupt to do the same function. Jn interrupt is notification that an event has occurred. What event[ Well, the event is truly arbitrary !i.e. the user pushed a button, the timer has reached its ma count, a byte has just arrived on the serial port, etc.4 and the interrupt simply indicates that the event occurred. The important point keep in mind is that interrupts allow for as#nchronous program operation. That is, interrupts allow a program to e ecute without having to continuously check Q poll - for when an event occurs. 7ather, a program can dedicate most of the IMZ time to other tasks and only when an interrupt occurs will the code to handle this event be triggered. <ost often, the phrase servicing the interrupt is used to describe the process of e ecuting a piece of code in response to a generated interrupt. To help clarify how interrupts are used, let us now give an e ample. 9uppose that we have an embedded system used in an automobile that is responsible for a variety of tasksS changing the speed of the automobile, monitoring the status of the engine, responding to user input, managing the fuel injector, etc. :rom this list of tasks, we know that some are more demanding than othersS managing the fuel injector is more IMZ intensive than responding to the button that turns the headlights on. 9ince users are likely to turn the headlights onHoff infre+uently !i.e. once or twice a day4 it makes sense to have this event generate an interrupt. If we setup the headlight-switch to generate an interrupt, we can dedicate most of the running time to handling more important tasks and we don;t have to waste value IMZ cycles polling for this event. In this e ample, we can dedicate our attention to managing the fuel injector and not waste time polling for when the user pushes the headlight-switch. fence, it is easy to see how using an interrupt vs. polling is a much more efficient way for handling the headlight-switch. When an interrupt occurs, how does the program service this event[ \y using an interrupt service routine .ISR/, a program can define code that should be run when an interrupt occurs. Zsing the e ample above, we can create an I97 !let us call it LightS%1ISR. /4 to handle the case when the light-switch interrupt occurs. :urthermore, the LightS%1ISR. / function will only be e ecuted when the light-switch interrupt occurs. To manage any hardware or software interrupt properly, we must do the following steps are re+uiredS ?. Lefine the interrupt service routine !I974 G. 9etup the interrupt vector ta+le with the address of the I97

- CU of GD -

(ppendi- %: "orking #it' Interrupts

When working with interrupts, it is important that one keep in mind the following information. ?. Interrupts are asynchronous events that can originate in the software or in the hardwareN inside or outside of the processor. G. The interrupt level !essentially the priority4 of each interrupt is usually predetermined by the design of the processor or the supporting underware. C. 8ne must write an interrupt service routine .ISR/. Bike the body of a function, this routine provides the body of the interrupt. That is, the task that is to be e ecuted when the interrupt occurs. The I97 should be short and concise. It should only contain sufficient code to get a job done or to apprise the system that something needs to be done. The following are definite no;s when writing an I97 The I97 should not block waiting on some other event. The I97 should not work with semaphores or monitors. The I97 should not contain a number !judgment call here4 of calls to functions or perform recursive operations. It;s easy to blow the stack. The I97 should not disable interrupts for an e tended time. The I97 should not contain dozens of lines of code.

]. 8ne must store the address of the ISR in the interrupt vector table. The table is essentially an array of function pointers, inde ed according to the interrupt number. Mroviding the I97 and getting itis address !pointer to that function4 into the interrupt vector table varies with different environments. :or our environment, follow what was done in the gpio-2tag project e ample in the 9tellaris environment. Book over the file gpio-2tag'c and the file startup1ewar!'c. fereis what you have to doP.. ?. Write the I97 for your interrupt G. Mut that above your !ain./ routine. C. 8pen the file startup1ewar!'c for your project. Rou had to bring this in when you created the project. ]. 9ave a backup of that file in case you make a mistake X. :ind the interrupt vector table in the startup1ewar!'c file.... HHjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj HH The vector table. Yote that the proper constructs must be placed on this to HH ensure that it ends up at physical address U UUUU.UUUU. HHjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj TTroot const uWector@ntry TTvectorTtablede r s.intvecs :ind the interrupt that you are intending to use in the vector table and replace

- C? of GD -

the name Int"efault3andle with the name of your I97 and also declare the function prototype as e*tern near the top of the file so that the compiler does not complain.. Book at how this was done in the startup1ewar!'c file for the gpio-2tag project e ample. Jlso, then read the material in section D of the Iorte <C data sheet on interrupts. X. 8ne must ena+le the interrupt. This can be done globally Q all interrupts are enabled Q or locally Q interrupt is enabled. Znless the interrupt is enabled, even if it occurs physically, it will not be recognized by the system. YoteS one enables the full port, not an individual pin for an interrupt. F. 8ne must acknowledge .or recogni4e or clear/ the interrupt when it occurs. Znless otherwise taken care of by the system !generally not the case4. This has the effect of resetting the interrupt and allowing further interrupts of the same kind to recur. If it is not acknowledged, it may occur once then never again. The acknowledgement is usually done in the I97. K. 8ne must e*it the interrupt properl#' Znlike a simple function call, the return from an interrupt is a bit more involved. Oenerally there is a specific statement !not a simple return4 that is used for e it and cleanup. @ ternal interrupts, or e ceptions as they are referred to on the B<C9DEFG Iorte processor, are configured and brought in through the OMI8 ports. 9pecifically, one can specify the source of the interrupt, its polarity, and the edge properties !rising or falling edge interrupt4. J detailed discussion of the management and use of Iorte e ceptions is given in section G.X of the datasheet. Jlso look through the interrupt e ample in the IJ7 Workbench.

- CG of GD -

Das könnte Ihnen auch gefallen