1 / 12

Advanced Embedded Systems Design

Advanced Embedded Systems Design. Lecture 4 Preemptive multi-tasking – inter-task communications BAE 5030 - 003 Fall 2004 Instructor: Marvin Stone Biosystems and Agricultural Engineering Oklahoma State University. Goals for Class Today. Questions over reading Preemptive multi-tasking

conor
Download Presentation

Advanced Embedded Systems Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Embedded Systems Design Lecture 4 Preemptive multi-tasking – inter-task communications BAE 5030 - 003 Fall 2004 Instructor: Marvin Stone Biosystems and Agricultural Engineering Oklahoma State University

  2. Goals for Class Today • Questions over reading • Preemptive multi-tasking • Time triggered scheduler • Keil Compiler • interrupts / profiling • Set assignment

  3. inter- task communications • Required to allow data to be passed between producing and consuming tasks • Queueing is needed when inflow and outflow rates are not matched. (average inflow <= average outflow) • Types • message queues (ping-pong, circular) • Pipes - FIFO buffer between tasks • Sockets - bidirectional, sequenced flow between tasks • Other • Task synchronization and mutual exclusion mechanisms • binary / mutual-exclusion semaphores • counting semaphores – where multiple of a resource must be metered

  4. Nature of inter-task communications • Generally done with shared memory • Tasks mutually understand a named memory as a communications pathway • Preemptive multi-tasking systems • Require inter-task coordination of access to shared memory • Non-atomic access to memory corrupts communication • Named shared memory is a limited shared resource • Time triggered systems • Time division multiplexing assures no two tasks run at the same time therefore do not require coordination to shared memory • Assumes shared memory is completely updated during each tasks access

  5. Inter-task communications - Example • Task 1 writes integer buffer for consumption during its execution • Task 2 reads integer buffer during its execution • If Task 1 is interrupted during the writing of the integer by task 2, communications will be corrupted. (Race condition) • Example: See 8051 MOV instruction and storage of int.

  6. Task 1 Tests Semaphore to assure not busy otherwise waits Sets Semaphore to “Busy” Writes integer Sets Semaphore to “Free” Task 2 Tests Semaphore to assure not busy otherwise waits Sets Semaphore to busy Reads integer Sets Semaphore to “Free” Inter-task communications – Binary Semaphore

  7. Inter-task communications – Binary Semaphore – Issues • Note that in both task 1 and task 2, both test then set the semaphore to “Busy” • Consider the potential problem that might occur if task 1 interrupts task 2 between the test of semaphore and set to busy • Task 1 concludes semaphore is free, sets the semaphore to “Busy”, Begins writing to Integer Flag. • Task 2 also sets flag to “Busy” and reads while Task 1 writes • Corrupted communications could result. Generally Task 2 completes before task 1 may continue and the process works successfully – not as intended • An assumption in the above system is that the semaphore can be written in a single un-interruptable (atomic) process. If the writing of the semaphore is a multi-instruction process, an interrupt could occur during writing of the semaphore and a corrupted result would occur as in the original example.

  8. Task 1 Increments Semaphore to indicate an integer has been added to the queue Writes integer Task 2 Tests semaphore to assure it is > 0 Reads integer Decrements Semaphore to indicate an integer has been removed from the queue Inter-task communications – Counting Semaphore

  9. Inter-task communications – Counting Semaphore – Issues • As in the original problem, Synchronized access to shared data must be provided. • Here a binary semaphore could be used to control access to the resource and counting semaphore • An “All-in-one” counting semaphore can be used assuming atomic access

  10. Strategies to test and set semaphore in an atom ;Subroutine to set semaphore to Free SETB Semaphore RTS ;Subroutine to set semaphore to Busy CLRB Semaphore RTS ;Subroutine to check and wait on semaphore ;Set indicates Free, Clear indicates Busy testset JBC Semaphore, busy ; Jump if semaphore set and clear semaphore JMP testset busy RTS

  11. Message Queues / Pipes / Sockets • Memory buffer • Character • Normally organized as FIFO • Bi-directional flow (sockets) and flow control handshaking between processes may be supported • Function • Head maintained at the “read” end by consumer. • Tail maintained at “write” end by producer • Tail advanced to the end of buffer and then to beginning • Tail may not advance past head (Buffer full) • Head may not be consumed beyond tail (Buffer empty)

  12. Assignment • Code a program to receive characters from the serial port and to accumulate a string of them and print the string after receiving a carriage return. Use the hybrid scheduler given in Pont. Use a serial port ISR to receive characters and a time triggered task to accumulate characters and print after a carriage return. • Read Pont, Chapter 17 • Tutorial – 30 min • Explain Rate Monotonic Analysis

More Related