|
|
用来控制挂起时间的。例如你主动调用delay或者阻塞于获取信号量等都会用到这个定时器。截取了一段信号量获取函数中的源码:, s3 |9 e2 k5 c$ ~& j; N0 M
`
' g3 E. C5 C6 x$ \0 G3 N/ start /9 q* d: ~+ q7 @5 D- a& t+ U
rt_ipc_list_suspend(&(sem->parent.suspend_thread),- {/ ^. F/ T: l; N9 _) g
thread,5 C& Q5 X1 ~. S3 y/ i5 E1 T
sem->parent.parent.flag);+ H; h3 o# u: Z+ q- [
) t" H) J2 p, R0 A: g
/* has waiting time, start thread timer */
5 ?# n5 v8 [* u: ?if (time > 0)- z2 F; x: e* o( O, D" e2 i
{
$ `) N2 F( W+ O9 R$ aRT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n",0 p% z! M9 F8 w$ A. M1 O2 c
thread->name));. h* I }0 }0 K" x6 ?5 ?! B h
/* reset the timeout of thread timer and start it */
( P8 \) Z; N% A2 v3 art_timer_control(&(thread->thread_timer)," O2 k' j3 x# R8 @
RT_TIMER_CTRL_SET_TIME,, f0 W( W2 g9 k! o' t
&time);0 K& q- @( R; g. J1 }1 [) F& X
rt_timer_start(&(thread->thread_timer));7 @+ s9 w: i- X; c
}
0 ?4 T% r3 _' t' v! ~) b' U( z/* enable interrupt */
7 I- W) e. x1 b1 K2 nrt_hw_interrupt_enable(temp);8 ^6 ^0 A: {* P* _. C" }
/* do schedule */5 l4 J$ ?+ D) ~4 ^0 l
rt_schedule(); rt_ipc_list_suspend(&(sem->parent.suspend_thread),
" d$ b2 {" D# w ]' M ~9 P" E* mthread,
$ A8 f3 L; _8 F6 w4 N" d; C. q Esem->parent.parent.flag);
. u8 T9 q) f9 Z2 g, K/ y/* has waiting time, start thread timer */
* g. O) G" m$ f& p( ?, ?. ~) Eif (time > 0)7 [+ ^! H. `7 Q! `; S
{5 n# X9 j4 S: B Y' R
RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n",5 E6 M4 x: ?# b$ z
thread->name));
: g+ D$ G/ z% R% r! P3 h' d/* reset the timeout of thread timer and start it */
% h! n7 u- z4 n" R3 G* f: x$ rrt_timer_control(&(thread->thread_timer),
8 B' r$ _7 ]3 {5 c! sRT_TIMER_CTRL_SET_TIME,
2 V$ A4 M2 E, p9 b& X7 ]1 ^6 M&time);. h+ a4 n/ @) {
rt_timer_start(&(thread->thread_timer));! v- Z* S+ d4 |! ^( ^. ?4 p
}' @6 q4 K* W. ~+ G9 a7 z6 Q
/* enable interrupt */2 P; i+ l0 D9 I# D! @
rt_hw_interrupt_enable(temp);
% P; V6 b# k$ I5 I% a, D' y+ x/* do schedule */+ H* b4 {, q5 d+ l1 B* f9 q
rt_schedule();`5 C1 A+ Y: X$ W% y* ^3 m
|
|