Download presentation
Presentation is loading. Please wait.
Published byBrent Paul Modified over 8 years ago
1
Chapter 5: Time Management 1
2
Time Management OSTimeDly() OSTimeDlyHMSM() OSTimeDlyResume() OSTimeGet() OSTimeSet() 2
3
Properties of μC/OS-IITime Management The system overhead is proportioned to the frequency of ticks – Compared to the uTime package of linux Delay a task until tx t=OSTimeGet(); if (tx-t>0) OSTimeDly(tx-t); – What’s wrong 3 void InterruptServiceRoutine{. } void HeighPriorityTask {. } OSTime= 5 OSTime= 6
4
Time Management Services OSTimeDly(), OSTimeDlyHMSM() – Allow a task to delay itself for a number of ticks – If your application must delay for at least one tick, you must call OSTimeDly(2) OSTimeDlyResume() Resume a delayed task OSTimeSet(), OSTimeGet() Set/obtain the system timer 4
5
OSTimeDly() 5 Because the task is no longer ready, the scheduler should be called to active the next highest priority task. Store the number of ticks in the TCB of the current task.
6
OSTimeDlyHMSM() 6
7
OSTimeTick() 7 OSTickISR() { OSTimeTick() } OSTimeTick() { foreach(…) }
8
Timer (1) 8 TCB...... OSTCBDly...... TCB...... OSTCBDly...... TCB...... OSTCBDly...... TCB...... OSTCBDly...... TCB...... OSTCBDly...... OSTickISR() { OSTimeTick() } OSTimeTick() { foreach(…) } OSTCBList
9
Timer (2) 9 TCB...... OSTCBDly...... TCB...... OSTCBDly...... TCB...... OSTCBDly...... TCB...... OSTCBDly...... TCB...... OSTCBDly...... OSTickISR() { OSMBoxPost() } TickTask() { OSMBoxPend() OSTimeTick() OS_Sched() } OSTimeTick() { foreach(…) } OSTCBList
10
OSTimeDlyResume() 10 See if the task is ready to run. A delayed task might also have been suspended. Make the task ready to run Clear the time delay
11
OSTimeDlyResume() 11 OSChangePrio() may change this value
12
OSTimeGet() & OSTimeSet() 12 The tick interrupt may read/write the variable “OSTime” while we call OSTimeGet/Set.
13
OSTimeDlyUntil() 13 void function1() { OS_ENTER_CRITICAL(); t=OSTimeGet(); if (tx-t>0) OSTimeDly(tx-t); OS_EXIT_CRITICAL(); } void function2() { OSSchedLock(); t=OSTimeGet(); if (tx-t>0) OSTimeDly(tx-t); OSSchedUnlock() }
14
OSTimeDlyUntil() 14 void function2() { OSTimeLockUntil(tx); } /* OSTimeDlyUntil() is a new system call.*/ void OSTimeDlyUntil(INT16U tx) { int ticks; OS_ENTER_CRITICAL(); ticks = tx- OSTime if (ticks > 0) { if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) { OSRdyGrp &= ~OSTCBCur->OSTCBBitY; } OSTCBCur->OSTCBDly = ticks; OS_EXIT_CRITICAL(); OS_Sched(); }
15
A Lightweight Implementation of Time Service (BSD) 15 Idea: using a linked list to describe waiting events – The list is sorted in time order – The time for each event is kept as a difference from the time of the previous event in the linked list 3ticks (3) 2ticks (5) 4ticks (9) 1ticks (10) NIL
16
Example 16 INT32U TestNewTimer (void) { OSTimeDly(16);/*at time 16*/ } 12 ticks (12) 2 ticks (14) 4 ticks (18) 1 ticks (19) NILbefore 12 ticks (12) 2 ticks (14) 2 ticks (16) 2 ticks (18) 1 ticks (19) NIL after
17
Enhancement The hardware timer can trigger the software timer until the time of the next time event. 17 3ticks (3) 2ticks (5) 4ticks (9) 1ticks (10) NIL Set H/W timer = 3 Set H/W timer = 2 Set H/W timer = 4 Set H/W timer = 1
18
Enhancement The relation between time granularity and system overhead can be broken if we modify the tick service. We should maintain the semantics of the time-related services 18
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.