DOC PREVIEW
UNCC ECGR 4101 - Sharing the Processor

This preview shows page 1-2-24-25 out of 25 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Sharing the Processor: A Survey of Approaches to Supporting ConcurrencySupporting Concurrency16-1TodayTopic - How do we make the processor do things at the right times?– For more details see Chapter 5 of D.E. Simon, An Embedded Software Primer, Addison-Wesley 1999There are various methods; the best fit depends on… depends on… – system requirements – response time– software complexity – number of threads of execution– resources – RAM, interrupts, energy available16-2RTOS Cult De-ProgrammingHow do we schedule the tasks on the CPU?An infinite loop in main Real-time operating system    Real-time operating systemIs there anything else available?  16-3DefinitionsOtherprocessingSchedulerResponseTimeTask or ISR CodeTimeLatencyTtask– TRelease(i) = Time at which task i is becomes ready to run – Tresponse(i) = Delay between request for service and completion of service for task i– Ttask(i) = Time needed to perform computations for task i– TISR(i) = Time needed to perform interrupt service routine iTime16-4Round-Robin/Super-LoopExtremely simple– No interrupts– No shared data problemsPoll each device (if (device_A_ready())) Service it with task code when void main(void) {while (TRUE) {if (device_A_ready()) {service_device_A();}if (device_B_ready()) {service_device_B();}Service it with task code when needed}if (device_C_ready()) {service_device_C();}}}16-5Example Round-Robin Applicationvoid DMM_Main(void) {enum {OHMS_1, ... VOLTS_100} SwitchPos;while (TRUE) {switch (SwitchPos) {case OHMS_1:ConfigureADC(OHMS_1);EnableOhmsIndicator();x = Convert();s = FormatOhms(x);break;......case VOLTS_100:ConfigureADC(VOLTS_100);EnableVoltageIndicator();x = Convert();s = FormatVolts(x);break;}DisplayResult(s);Delay(50);}}16-6Sample Application - Network VideophoneVideo– 30 frames/s– 360 x 240 images– Compress/ Decompress with MPEG-2AudioService Direction Function WCET DeadlineVideo Send SampleFrame 1 ms 33.3 msCompressFrame 27 ms 33.3 msSendFrame 0.1 ms 33.3 msReceive ReceiveFrame 0.1 ms 33.3 msDecompressFrame 2.7 ms 33.3 msDisplayFrame1 ms33.3 msAudio– 8 kHz sampling– Compress with GSM 06.10Processor– 3000 MIPSTasks have deadlinesDisplayFrame1 ms33.3 msAudio Send ReadMicBuffer 0.001 ms 20 msCompressAudio 0.160 ms 20 msSendAudio 0.001 ms 20 msReceive ReceiveAudio 0.001 ms 20 msDecompressAudio 0.160 ms 20 msLoadAudioBuffer 0.001 ms 20 ms16-7Scheduling NV with Round-RobinRound robin works for either video or audio, but not bothNeed to split up video CompressFrame()void main() {while(TRUE) {if (TimeToSample) {SampleFrame();CompressFrame();SendFrame();}if (FrameWaiting) {if (FrameWaiting) {ReceiveFrame();DecompressFrame();DisplayFrame();}}}CompressFrame: 27 msAll audio tasks: Deadline is 20 ms from beginning of first taskRMBCASA16-8Limitations of Round-RobinArchitecture supports multi-rate systems very poorly– Voice Recorder: sample microphone at 20 kHz, sample switches at 15 Hz, update display at 4 Hz. How do we do this?Polling frequency limited by time to execute main loop– Can get more performance by testing more often (A/Z/B/Z/C/Z/...)– This makes program more complex and increases response time for other tasksother tasksPotentially Long Response Time – In worst case, need to wait for all devices to be serviced–Fragile Architecture– Adding a new device will affect timing of all other devices– Changing rates is tedious and inhumane( )∀=ttaskresponsetTjT )()(max16-9Event-Triggered using InterruptsVery basic architecture, useful for simple low-power devices, very little code or time overheadLeverages built-in task dispatching of interrupt system– Can trigger ISRs with input changes, timer expiration, UART data reception, analog input level crossing comparator thresholdFunction types–Main function configures system and then goes to sleep–Main function configures system and then goes to sleep• If interrupted, it goes right back to sleep– Only interrupts are used for normal program operationExample: bike computer– Int1: wheel rotation – Int2: mode key– Int3: clock– Output: Liquid Crystal Display 16-10Bike Computer FunctionsISR 1: Wheel rotationISR 2: Mode KeyISR 3: Time of Day TimerConfigure timer,inputs and outputscur_time = 0;rotations = 0;tenth_miles = 0;Resetrotations++;if (rotations>R_PER_MILE/10) {tenth_miles++;rotations = 0;}speed = mode++;mode = mode %NUM_MODES;return from interrupt;cur_time ++;lcd_refresh--;if (lcd_refresh==0) {convert tenth_milesand displayconvert speedand displaytenth_miles = 0;while (1) {sleep;}circumference/(cur_time – prev_time);compute avg_speed;prev_time = cur_time;return from interruptif (mode == 0)convert cur_timeand displayelse convert avg_speedand displaylcd_refresh = LCD_REF_PERIOD}16-11Limitations of Event-Triggered using InterruptsAll computing must be triggered by an event of some type– Periodic events are triggered by a timerLimited number of timers on MCUs, so may need to introduce a scheduler of some sort which – determines the next periodic event to execute, – computes the delay until it needs to run–initializes a timer to expire at that time–initializes a timer to expire at that time– goes to sleep (or idle loop)Everything (after initialization) is an ISR– All code is in ISRs, making them long– Response time depends on longest ISR. Could be too slow, unless interrupts are re-enabled in ISR– Priorities are directly tied to MCU’s interrupt priority scheme16-12Round-Robin with InterruptsAlso called foreground/backgroundInterrupt routines– Handle most urgent work– Set flags to request processing by main loopMore than one priority levelBOOL DeviceARequest, DeviceBRequest, DeviceCRequest;void interrupt HandleDeviceA(){/* do A’s urgent work */...DeviceARequest = TRUE;}void main(void) {while (TRUE) {if (DeviceARequest) {More than one priority level– Interrupts – multiple interrupt priorities possible– main codeif (DeviceARequest) {FinishDeviceA();}if (DeviceBRequest) {FinishDeviceB();}if (DeviceCRequest) {FinishDeviceC();}}}16-13Scheduling NV with Round Robin + InterruptsBOOL ReadMicBuffer_Req = FALSE,SampleFrame_Req = FALSE;interrupt void HandleMicBuffer() {copy contents of mic bufferReadMicBuffer_Done = TRUE;}interrupt void void main(void) {while (TRUE) {if (ReadMicBuffer_Done) {


View Full Document

UNCC ECGR 4101 - Sharing the Processor

Documents in this Course
Load more
Download Sharing the Processor
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 Sharing the Processor 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 Sharing the Processor 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?