Chapter 05
Chapter 05
Chapter 05
Time Management
1
Time Management
• OSTimeDly()
• OSTimeDlyHMSM()
• OSTimeDlyResume()
• OSTimeGet()
• OSTimeSet()
2
Properties of μC/OS-IITime Management
4
OSTimeDly()
6
OSTimeTick()
OSTickISR() {
OSTimeTick() {
OSTimeTick()
foreach(…)
}
}
7
OSTCBList
Timer (1)
TCB TCB TCB TCB TCB
. . . . .
. . . . .
. . . . .
OSTCBDly OSTCBDly OSTCBDly OSTCBDly OSTCBDly
. . . . .
. . . . .
. . . . .
OSTickISR() {
OSTimeTick() {
OSTimeTick()
foreach(…)
}
}
8
OSTCBList
Timer (2)
TCB TCB TCB TCB TCB
. . . . .
. . . . .
. . . . .
OSTCBDly OSTCBDly OSTCBDly OSTCBDly OSTCBDly
. . . . .
. . . . .
. . . . .
9
Clear the
time delay
OSTimeDlyResume()
Make the
task ready
to run See if the task is ready to run.
A delayed task might also
have been suspended.
10
OSTimeDlyResume()
11
OSTimeGet() & OSTimeSet()
12
OSTimeDlyUntil()
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()
}
13
OSTimeDlyUntil()
void function2() {
OSTimeLockUntil(tx);
}
15
Example
12 ticks 2 ticks 4 ticks 1 ticks
before NIL
(12) (14) (18) (19)
16
Enhancement
• The hardware timer can trigger the software
timer until the time of the next time event.
17
Enhancement
• The relation between time granularity
and system overhead can be broken if
we modify the tick service.
18