Unformatted text preview:

1January 21, 2014 Jonathan Valvano EE445M/EE380L.6Real-Time Operating SystemsTerminologyReference McDermott EE382N-4uC/OS-III, The Real-Time Kernel, or a High Performance, Scalable, ROMable, Preemptive, Multitasking Kernel for Microprocessors, Microcontrollers & DSPs, there are a bunch of versions, with and without a board, Hardcover, by Jean J LabrosseMicroC OS II: The Real Time Kernel, by Jean J. Labrosse , 2002, ISBN 1-5782-0103-9, $72.76 The Definitive Guide to the ARM Cortex-M3 TI, Second Edition, Paperback, Joseph Yiu, $53.95 Chapters 5 8 13, Embedded Microcomputer Systems: Real Time Operating Systems for Arm Cortex M Microcontrollers, , Jonathan W. Valvano, January 21, 2014 Jonathan Valvano EE445M/EE380L.6Single thread vs multithreadStatus1Input data1BusyReadyStatus2Output data2BusyReadyOtherfunction1Busy waitStatus1Input data1BusyReadyTask1Status2Output data2BusyReadyTask2Task3Otherfunction3Thread schedulerOtherfunction2Task4Otherfunction4January 21, 2014 Jonathan Valvano EE445M/EE380L.6What is a thread?R0R1R2...SPPCThread1StackProgramR0R1R2...SPPCThread2StackProgramR0R1R2...SPPCThread3StackProgramR0R1R2...SPPCThread4StackProgramJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Thread or Taskvoid Display(void){ unsigned long data,voltage;for(;;){ data = OS_MailBox_Recv();voltage = 31*data/64; LCD_Message(0,"v(mV) =",voltage); } }void Producer(void){ unsigned short data; data = ADC_In(1);if(OS_Fifo_Put(data) == 0){ DataLost++;} }void Consumer(void){ unsigned short data,average;unsigned long sum;unsigned short n;for(;;){sum = 0;for(n = 0; n < LENGTH; n++){data = OS_Fifo_Get(); sum = sum + data;}average = sum/LENGTH;OS_MailBox_Send(average);}}Show main, threads in Lab72January 21, 2014 Jonathan Valvano EE445M/EE380L.6Real-time tasks• Hard real-time– Bounded latency• Soft real-time– Execute ASAP• Not real-timeJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Thread Classification• Periodic, execution at regular intervals– E.g., ADC, DAC, motor control– E.g., Check CO levels• Aperiodic, execution can not be anticipated– Execution is frequent– E.g., New position detected as wheel turns• Sporadic, execution can not be anticipated– Execution is infrequent– E.g., Faults, errors, catastrophes January 21, 2014 Jonathan Valvano EE445M/EE380L.6Thread Scheduler• List possible thread states• List possible scheduling algorithms– What?–How?–Why?• Performance measures– Utilization– Latency– BandwidthRound robinWeighted round robinPriorityStaticDynamicDeterministicWhen to run scheduler??January 21, 2014 Jonathan Valvano EE445M/EE380L.6Priority• Execute highest priority first– Can you have two tasks at same priority?• Minimize latency on real-time tasks• Assign a dollar cost for delays– Minimize cost3January 21, 2014 Jonathan Valvano EE445M/EE380L.6Priority Schedulers• Earliest deadline first, dynamic• Earliest slack-time first , dynamic– Slack = (time to deadline)-(work left to do)• Rate monotonic scheduling, static– Assign priority based on how often Ti is runs– Lower Ti (more frequent) are higher priorityJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Rate Monotonic Scheduling Theorem• All n tasks are periodic – Priority based on period of Ti– Maximum execution time Ei• No synchronization between tasks• Execute highest priority task firstln(2)11/n2niTiEJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Time Management• System time• Time stamps– When did it occur?– Performance measures• Thread sleeping• Measurements– Input capture period -> wheel RPM– Input capture PW -> ultrasonic distanceJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Communication• Types– Data sharing– Pipes=FIFO (one to one, buffered, ordered)– Mailbox (one to one, unbuffered)– Messages (many to many)• Deadlock – prevention, avoidance, detection, recovery• Performance measures– Latency– Bandwidth– Error rate4January 21, 2014 Jonathan Valvano EE445M/EE380L.6Race condition• Two or more threads access the same global• At least one access is a writeModule 7GPIOBModule 3 GPIOBChannel 3Channel 7January 21, 2014 Jonathan Valvano EE445M/EE380L.6Race, Critical Sections• Permanently allocated object– Shared variables– I/O ports• Write access changes official copy• Read access creates two copies– Original copy in memory– Temporary copy in register• Nonatomic access, load/store architectureJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Reentrant• Variables in registers, stack• No nonatomic write sequence– Permanently allocated object– WR, RMW, WW sequenceLook at programming manualLDREX STREXCortexM3Programmer.pdf pg33,71CortexM3InstructionSet.pdf pg 39January 21, 2014 Jonathan Valvano EE445M/EE380L.6Making the access atomic• Disable all interrupts• Lock the scheduler – No other foreground threads can run– Background ISR will occur• Mutex semaphore– Blocks other threads trying to access info– All nonrelated operations not delayedShow code with NestCnt++If NestCnt-- == 0 then run or don’t run scheduler??Measure time with I=1- Maximum time- Total time5January 21, 2014 Jonathan Valvano EE445M/EE380L.6Synchronization• Sequential• Fork, spawn, join• Rendezvous• Trigger, event flags– or, and– I/O event (e.g., I/O edge, RX, TX) – periodic time (e.g., TATOMIS)• Sleep ADC ADC Producer ConsumerFifoDisplayMailBoxLCDSwitch TamperInterpreterRxFifoUSART1serialTxFifoJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6SemaphoreOther calculations10MainprogramISRFlag = 0Do important stuffFlagFlag = 1Other calculations10MainprogramISRFlag = 0Do important stuffFlagFlag = 1January 21, 2014 Jonathan Valvano EE445M/EE380L.6MailboxOther calculationsRead datafrom inputFullEmptyMainprogramISRProcess MailStatus = EmptyStatusMail = dataStatus = FullabcdJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Portability• Small kernel • Common structure• Hardware abstraction layerMicrium-ARM-uCOS-II-Cortex-M3.exeShow Micrium directory6January 21, 2014 Jonathan Valvano EE445M/EE380L.6Hooks• Run user supplied code at strategic places• Allows you to– Extend the OS– Implement debugging– Implement performance testing– Implement black box recording• Collect run-time performance dataJanuary 21, 2014 Jonathan Valvano EE445M/EE380L.6Additional OS terms• Run-time configurable – Priority, stack size, fifo size, time slice• Certification– Medical,


View Full Document

UT EE 345 - Real-Time Operating Systems

Download Real-Time Operating Systems
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Real-Time Operating Systems and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Real-Time Operating Systems 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?