Presentation is loading. Please wait.

Presentation is loading. Please wait.

Safe Queue? … while (next(head) == tail); // block if full

Similar presentations


Presentation on theme: "Safe Queue? … while (next(head) == tail); // block if full"— 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 C code for blocking queue Compiler output?
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 output? MOV R0,TAIL MOV R1,HEAD LOOP: ACALL NEXT SUBB A,R0 JZ LOOP MOV R3,#QUEUE ADD R3,R1 CLR ET0 ACALL NEXT MOV HEAD,A SETB ET0 Assume next() returns value in accumulator, leaves R1 as is

3 I think we’re safe now 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); } MOV R1,HEAD LOOP: ACALL NEXT MOV R0,TAIL ;refresh SUBB A,R0 JZ LOOP MOV R3,#QUEUE ADD R3,R1 CLR ET0 ACALL NEXT MOV HEAD,A SETB ET0 *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 serial task main 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 Maestro in RR+INT 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! 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) char arrives Can we do better?

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


Download ppt "Safe Queue? … while (next(head) == tail); // block if full"

Similar presentations


Ads by Google