EECE 276 – Embedded Systems1EECE 276Embedded SystemsTimer functions and eventsEECE 276 – Embedded Systems2Timer functionsO Real-time systems often must synchronize their activities to the passage of time » “Turn power off if nothing happens for 1 mins”» Dial a digit: 100msec tone+100msec pause» “If temp and press is too high continuously for 3 minutes, then shut down reactor”O Common technique: » delay(int units) – delays task for a “units”» delay_call(int units,(void)(*func)(void*),void* arg) –call “func” with “arg” after “units”EECE 276 – Embedded Systems3Timer example codevoid phone_dial_task() {char phNum[MAX_PH_NUM]; // 0-terminated phone number str.char *phNumP;while(1) {msgq_recv(queue,&phNum,MAX_PH_NUM); // Get numbersphNumP = phNum;while(*phNumP) {delay(100); // delay for 100 mSecdialToneOn(*phNumP – ‘0’); // start tonedelay(100); // delay for 100 msecdialToneOff(); // stop tonephNumP++; // next digit}}}EECE 276 – Embedded Systems4Issues with timersO The delay(int) may not precisely delay“tick”delay ends at tickdelay(3) -> 2.9 ticksdelay(3) -> 2.3 ticksdelay(3) -> 2.9 ticksO No standard “tick” (read RTOS manual)O More accurate timing: use hardware timersEECE 276 – Embedded Systems5Events: Synchronization devicesO “event”: boolean flag O Multiple tasks can set it/wait for itO A task can wait for multiple events» AND and OR synchronizationO uCOS: Event flag groups» See App NoteEECE 276 – Embedded Systems6Comparison of task synchronization toolsO Semaphores:» Fast and simple» “Unstructured”» Limited information is carriedO Events:» Slightly more complex than semaphores» Multiple tasks for one event» One task for multiple eventsO Queues:» Pass “large” amounts of data» Enqueuing/dequeuing data is
View Full Document