EECE 276 – Embedded SystemsEmbedded Software Architectures 1EECE 276Embedded SystemsEmbedded SW ArchitecturesRound-robinFunction-queue schedulingEECE 276 – Embedded SystemsEmbedded Software Architectures 2Software ArchitectureO How to “do” things – how to arrange code for an embedded system application.O Four variants:1. Round-robin2. Round-robin with interrupts3. Function-queue-scheduling4. Real-time Operating SystemEECE 276 – Embedded SystemsEmbedded Software Architectures 3Round-robin: Poll and Servevoid main() {while(TRUE) {if(// I/O Device #1 needs service) {// Service I/O #1}if(// I/O Device #2 needs service) {// Service I/O #2}…if(// I/O Device #n needs service) {// Service I/O #n}}}EECE 276 – Embedded SystemsEmbedded Software Architectures 4Round-robin: Poll and ServePro: Very simple, straightforward, no interruptsCons: 1. If a device needs faster service than the “cycle-time”, it may not work.2. If there is a lengthy processing, the system may not react fast enough.3. Very fragile – hard to extend, reprogram, change. 4. No interrupts!EECE 276 – Embedded SystemsEmbedded Software Architectures 5Round-robin with interrupts (1)bool fDev1 = FALSE, fDev2 = FALSE, … fDevn = FALSE;void interrupt vHandleDev1() {// Handle Dev 1fDev1 = TRUE;}…void interrupt vHandleDevn() {// Handle Dev nfDevn = TRUE;}For every device: ISR handles I/O termination and sets flag.EECE 276 – Embedded SystemsEmbedded Software Architectures 6Round-robin with interrupts (2)void main() {while (TRUE) {if(fDev1) {fDev1 = FALSE;// Handle data from Dev 1}…if(fDevn) {fDevn = FALSE;// Handle data from Dev n}}}For every device: if device needs attention, main handles data and clears flag.EECE 276 – Embedded SystemsEmbedded Software Architectures 7Round-robin with interruptsO ISRs: handlers for I/O, main(): “task code”O ISR-s ensure fast initial reactions to devicesO Priorities: vHandleDev1 > vHandleDev2 > … vHandleDevn (per IT priority)Problem: All “tasks” (non-ISR codes) are handled with the same priority Solution:Move “task code” into ISR May slow down system (longer ISR!)Change the order of flag-polling in main()Priority through polling orderWCRT: total exec time for all task codes + all ISR-sEECE 276 – Embedded SystemsEmbedded Software Architectures 8Function-Queue-SchedulingQueue data structure:First-in-first-out (FIFO) orderVariant: Priority QueueList of queues ordered according to priorityQueue of elementsElem dequeue(Queue);Queue enqueue(Queue,Elem);EECE 276 – Embedded SystemsEmbedded Software Architectures 9Function-Queue-Scheduling (1)void interrupt vHandleDev1() {// Handle Dev 1enqueue(q,fP1);}…void interrupt vHandleDevn() {// Handle Dev nenqueue(q,fPn);}ISR: Take care of device and enqueuecorresponding function pointer.EECE 276 – Embedded SystemsEmbedded Software Architectures 10Function-Queue-Scheduling (2)void fP1() {// Task code for Dev 1}…void fP2() {// Task code for Dev }void main() {while(TRUE) {while(//Queue of function pointers is not empty) {fP = dequeue(q);// call fP}}}Task functions for each task. Dequeue next function pointer and call function. Q: A shared QueueEECE 276 – Embedded SystemsEmbedded Software Architectures 11Function-Queue-SchedulingWCRT – if priority queue is used: Longest task code + exec time of ISRsTradeoff: Response time for low-priority task code may get worse! – “Starvation” because of higher-priority interruptsEECE 276 – Embedded SystemsEmbedded Software Architectures 12Real-Time OS (1)void interrupt vHandleDev1() {// Handle Dev 1// Send signal #1}…void interrupt vHandleDevn() {// Handle Dev n// Send signal #n}ISR: Take care of device and send a unique signal.EECE 276 – Embedded SystemsEmbedded Software Architectures 13Real-time OS (2)void task1() {// Wait for signal #1// Task code for Dev 1}…void taskn() {// Wait for signal #n// Task code for Dev }void main() {// Start task1…// Start taskn}Task: A concurrent activity, with its own thread of control/stack (“context”)EECE 276 – Embedded SystemsEmbedded Software Architectures 14Real-Time OS ArchitectureO RTOS provides:» Task creation and processor scheduling services» Processor is time-sliced across tasks» Signaling services (send() and wait())Arrows indicate context (task) switching pointsTASK1TASK2TASK3TimeISR1EECE 276 – Embedded SystemsEmbedded Software Architectures 15ComparisonHigh (needs kernel)Very good0 + ISR execution timesISRs and task code in priority orderRTOSShared data problem and function queue codeQueue mgmt is criticalExecution time for the longest task code + ISRsISRs and task code in priority orderFunction Queue SchedulingShared data problem (ISRsand task code)Poor if task code is changedTotal of all task code + all ISRsISR in priority order, tasks same priorityRound-robin with interruptsVery simplePoorSum of all task codeNoneRound-robinComplexityStability at code
View Full Document