1 / 11

Safe Queue?

Safe Queue?. … while (next(head) == tail); // block if full queue[head] = data; // write data ET0 = 0; // disable T-0 interrupts head = next(head); // update pointer ET1 = 1; // enable T-1 interrupts … unsigned char next(unsigned char ptr) { if (ptr == QMX) ptr = 0; else ptr++

val
Download Presentation

Safe Queue?

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. Safe Queue? • … • while (next(head) == tail); // block if full • queue[head] = data; // write data • ET0 = 0; // disable T-0 interrupts • head = next(head); // update pointer • ET1 = 1; // enable T-1 interrupts • … • unsigned char next(unsigned char ptr) { • if (ptr == QMX) ptr = 0; • else ptr++ • return(ptr); • }

  2. Consider the compiler Compiler output? MOV R0,TAIL MOV R1,HEAD LOOP: ACALL NEXT SUBB A,R0 JZ LOOP MOV R3,#QUEUE ADD R3,R1 MOV @R3,R4 CLR ET0 ACALL NEXT MOV HEAD,A SETB ET0 C code for blocking queue … while (next(head) == tail); queue[head] = data; ET0 = 0; head = next(head); ET1 = 1; … unsigned char next(unsigned char ptr) { if (ptr == 9) ptr = 0; else ptr++ return(ptr); } Assume next() returns value in accumulator, leaves R1 as is

  3. I think we’re safe now MOV R1,HEAD LOOP: ACALL NEXT MOV R0,TAIL ;refresh SUBB A,R0 JZ LOOP MOV R3,#QUEUE ADD R3,R1 MOV @R3,R4 CLR ET0 ACALL NEXT MOV HEAD,A SETB ET0 volatile data unsigned char tail; … while (next(head) == tail); queue[head] = data; ET0 = 0; head = next(head); ET1 = 1; … unsigned char next(unsigned char ptr) { if (ptr == 9) ptr = 0; else ptr++ return(ptr); } *compiler knows that sfr’s are volatile (ports, flags)

  4. Embedded Software Architectures • No Operating System • Round robin: sequential polling for events • Round robin w/ interrupts • Function Queue Scheduling • Real Time Operating System

  5. Maestro w/ Round Robin Only void main (void) { if (TF0) music_task(); // process timer overflow if (R1) serial_input_task(); // process serial input } Would this work for maestro (lab4)? How do we know?

  6. Task Diagram Worst case: character comes one cycle before TF0 Worst Case Latency = max run time of all other tasks main serial task serial music main w.c. latency deadline What is the worst case serial processing time? Depends on response message length--could be bad! How much latency can we tolerate? Practically none timer0 overflow occurs (TF0) char arrives

  7. Round Robin w/ Interrupts volatile bit fEvent; void isr(void) { time_critical_processing(); fEvent = TRUE; } void main (void) { if (R1) serial_input_task(); if (fEvent) { housekeeping(); fEvent = FALSE; } } Why not put housekeeping into the ISR too? Then our worst case latency to a separate time critical event would be poor Would this work for maestro? See next slide

  8. What are the time critical functions?Flipping channels, change tones at end of timeslice What are the housekeeping functions? TNE count down and stream processing (TNE, Tones) Do these have hard time constraints too? Yes, one time slice (18ms)…good enough? Not necessarily…serial is undefined! Maestro in RR+INT volatile bit fEndOfSlice; void isr(void) { process_tones(); if (!--sliceCount) { changeTones(); sliceCount = SliceSize fEndOfSlice = TRUE; } } main () { if (R1) serial_input_task(); if (fEndOfSlice) { if (--TNE==0) process_next_event(); fEndOfSlice = FALSE; } }

  9. Task Diagram Worst case analysis: character comes one cycle before TF0 Problem: housekeeping can still miss its deadline, depends on serial task execution time time slice start time slice end isr serial housekeeping main deadline timer0 overflow occurs (TF0) Can we do better? char arrives

  10. Benefits • Modularization of the Application • Some Virtual Machine Features • Device Drivers (Virtual Devices)

  11. Embedded Software • Software States v. Finite State Machines • Hierarchical State • Thread/Process Communication • Critical Sections • Synchronization • Messaging and Signaling

More Related