timer.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * File : timer.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2006-03-12 Bernard first version
  23. * 2006-04-29 Bernard implement thread timer
  24. * 2006-06-04 Bernard implement rt_timer_control
  25. * 2006-08-10 Bernard fix the periodic timer bug
  26. * 2006-09-03 Bernard implement rt_timer_detach
  27. * 2009-11-11 LiJin add soft timer
  28. * 2010-05-12 Bernard fix the timer check bug.
  29. * 2010-11-02 Charlie re-implement tick overflow issue
  30. * 2012-12-15 Bernard fix the next timeout issue in soft timer
  31. * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
  32. * timeout function.
  33. */
  34. #include <rtthread.h>
  35. #include <rthw.h>
  36. /* hard timer list */
  37. static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
  38. #ifdef RT_USING_TIMER_SOFT
  39. #ifndef RT_TIMER_THREAD_STACK_SIZE
  40. #define RT_TIMER_THREAD_STACK_SIZE 512
  41. #endif
  42. #ifndef RT_TIMER_THREAD_PRIO
  43. #define RT_TIMER_THREAD_PRIO 0
  44. #endif
  45. /* soft timer list */
  46. static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
  47. static struct rt_thread timer_thread;
  48. ALIGN(RT_ALIGN_SIZE)
  49. static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
  50. #endif
  51. #ifdef RT_USING_HOOK
  52. extern void (*rt_object_take_hook)(struct rt_object *object);
  53. extern void (*rt_object_put_hook)(struct rt_object *object);
  54. static void (*rt_timer_timeout_hook)(struct rt_timer *timer);
  55. /**
  56. * @addtogroup Hook
  57. */
  58. /*@{*/
  59. /**
  60. * This function will set a hook function, which will be invoked when timer
  61. * is timeout.
  62. *
  63. * @param hook the hook function
  64. */
  65. void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer))
  66. {
  67. rt_timer_timeout_hook = hook;
  68. }
  69. /*@}*/
  70. #endif
  71. static void _rt_timer_init(rt_timer_t timer,
  72. void (*timeout)(void *parameter),
  73. void *parameter,
  74. rt_tick_t time,
  75. rt_uint8_t flag)
  76. {
  77. int i;
  78. /* set flag */
  79. timer->parent.flag = flag;
  80. /* set deactivated */
  81. timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  82. timer->timeout_func = timeout;
  83. timer->parameter = parameter;
  84. timer->timeout_tick = 0;
  85. timer->init_tick = time;
  86. /* initialize timer list */
  87. for (i = 0; i < RT_TIMER_SKIP_LIST_LEVEL; i++)
  88. {
  89. rt_list_init(&(timer->row[i]));
  90. }
  91. }
  92. /* the fist timer always in the last row */
  93. static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[])
  94. {
  95. struct rt_timer *timer;
  96. if (rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
  97. return RT_TICK_MAX;
  98. timer = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
  99. struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
  100. return timer->timeout_tick;
  101. }
  102. rt_inline void _rt_timer_remove(rt_timer_t timer)
  103. {
  104. int i;
  105. for (i = 0; i < RT_TIMER_SKIP_LIST_LEVEL; i++)
  106. {
  107. rt_list_remove(&timer->row[i]);
  108. }
  109. }
  110. #if RT_DEBUG_TIMER
  111. static int rt_timer_count_height(struct rt_timer *timer)
  112. {
  113. int i, cnt = 0;
  114. for (i = 0; i < RT_TIMER_SKIP_LIST_LEVEL; i++)
  115. {
  116. if (!rt_list_isempty(&timer->row[i]))
  117. cnt++;
  118. }
  119. return cnt;
  120. }
  121. void rt_timer_dump(rt_list_t timer_heads[])
  122. {
  123. rt_list_t *list;
  124. for (list = timer_heads[RT_TIMER_SKIP_LIST_LEVEL-1].next;
  125. list != &timer_heads[RT_TIMER_SKIP_LIST_LEVEL-1];
  126. list = list->next)
  127. {
  128. struct rt_timer *timer = rt_list_entry(list,
  129. struct rt_timer,
  130. row[RT_TIMER_SKIP_LIST_LEVEL-1]);
  131. rt_kprintf("%d", rt_timer_count_height(timer));
  132. }
  133. rt_kprintf("\n");
  134. }
  135. #endif
  136. /**
  137. * @addtogroup Clock
  138. */
  139. /*@{*/
  140. /**
  141. * This function will initialize a timer, normally this function is used to
  142. * initialize a static timer object.
  143. *
  144. * @param timer the static timer object
  145. * @param name the name of timer
  146. * @param timeout the timeout function
  147. * @param parameter the parameter of timeout function
  148. * @param time the tick of timer
  149. * @param flag the flag of timer
  150. */
  151. void rt_timer_init(rt_timer_t timer,
  152. const char *name,
  153. void (*timeout)(void *parameter),
  154. void *parameter,
  155. rt_tick_t time,
  156. rt_uint8_t flag)
  157. {
  158. /* timer check */
  159. RT_ASSERT(timer != RT_NULL);
  160. /* timer object initialization */
  161. rt_object_init((rt_object_t)timer, RT_Object_Class_Timer, name);
  162. _rt_timer_init(timer, timeout, parameter, time, flag);
  163. }
  164. RTM_EXPORT(rt_timer_init);
  165. /**
  166. * This function will detach a timer from timer management.
  167. *
  168. * @param timer the static timer object
  169. *
  170. * @return the operation status, RT_EOK on OK; RT_ERROR on error
  171. */
  172. rt_err_t rt_timer_detach(rt_timer_t timer)
  173. {
  174. register rt_base_t level;
  175. /* timer check */
  176. RT_ASSERT(timer != RT_NULL);
  177. /* disable interrupt */
  178. level = rt_hw_interrupt_disable();
  179. _rt_timer_remove(timer);
  180. /* enable interrupt */
  181. rt_hw_interrupt_enable(level);
  182. rt_object_detach((rt_object_t)timer);
  183. return -RT_EOK;
  184. }
  185. RTM_EXPORT(rt_timer_detach);
  186. #ifdef RT_USING_HEAP
  187. /**
  188. * This function will create a timer
  189. *
  190. * @param name the name of timer
  191. * @param timeout the timeout function
  192. * @param parameter the parameter of timeout function
  193. * @param time the tick of timer
  194. * @param flag the flag of timer
  195. *
  196. * @return the created timer object
  197. */
  198. rt_timer_t rt_timer_create(const char *name,
  199. void (*timeout)(void *parameter),
  200. void *parameter,
  201. rt_tick_t time,
  202. rt_uint8_t flag)
  203. {
  204. struct rt_timer *timer;
  205. /* allocate a object */
  206. timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
  207. if (timer == RT_NULL)
  208. {
  209. return RT_NULL;
  210. }
  211. _rt_timer_init(timer, timeout, parameter, time, flag);
  212. return timer;
  213. }
  214. RTM_EXPORT(rt_timer_create);
  215. /**
  216. * This function will delete a timer and release timer memory
  217. *
  218. * @param timer the timer to be deleted
  219. *
  220. * @return the operation status, RT_EOK on OK; RT_ERROR on error
  221. */
  222. rt_err_t rt_timer_delete(rt_timer_t timer)
  223. {
  224. register rt_base_t level;
  225. /* timer check */
  226. RT_ASSERT(timer != RT_NULL);
  227. /* disable interrupt */
  228. level = rt_hw_interrupt_disable();
  229. _rt_timer_remove(timer);
  230. /* enable interrupt */
  231. rt_hw_interrupt_enable(level);
  232. rt_object_delete((rt_object_t)timer);
  233. return -RT_EOK;
  234. }
  235. RTM_EXPORT(rt_timer_delete);
  236. #endif
  237. /**
  238. * This function will start the timer
  239. *
  240. * @param timer the timer to be started
  241. *
  242. * @return the operation status, RT_EOK on OK, -RT_ERROR on error
  243. */
  244. rt_err_t rt_timer_start(rt_timer_t timer)
  245. {
  246. unsigned int row_lvl;
  247. rt_list_t *timer_list;
  248. register rt_base_t level;
  249. rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL];
  250. unsigned int tst_nr;
  251. static unsigned int random_nr;
  252. /* timer check */
  253. RT_ASSERT(timer != RT_NULL);
  254. /* stop timer firstly */
  255. level = rt_hw_interrupt_disable();
  256. /* remove timer from list */
  257. _rt_timer_remove(timer);
  258. /* change status of timer */
  259. timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  260. rt_hw_interrupt_enable(level);
  261. RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
  262. /*
  263. * get timeout tick,
  264. * the max timeout tick shall not great than RT_TICK_MAX/2
  265. */
  266. RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
  267. timer->timeout_tick = rt_tick_get() + timer->init_tick;
  268. /* disable interrupt */
  269. level = rt_hw_interrupt_disable();
  270. #ifdef RT_USING_TIMER_SOFT
  271. if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
  272. {
  273. /* insert timer to soft timer list */
  274. timer_list = rt_soft_timer_list;
  275. }
  276. else
  277. #endif
  278. {
  279. /* insert timer to system timer list */
  280. timer_list = rt_timer_list;
  281. }
  282. row_head[0] = &timer_list[0];
  283. for (row_lvl = 0; row_lvl < RT_TIMER_SKIP_LIST_LEVEL; row_lvl++)
  284. {
  285. for (;row_head[row_lvl] != timer_list[row_lvl].prev;
  286. row_head[row_lvl] = row_head[row_lvl]->next)
  287. {
  288. struct rt_timer *t;
  289. rt_list_t *p = row_head[row_lvl]->next;
  290. /* fix up the entry pointer */
  291. t = rt_list_entry(p, struct rt_timer, row[row_lvl]);
  292. /* If we have two timers that timeout at the same time, it's
  293. * preferred that the timer inserted early get called early.
  294. * So insert the new timer to the end the the some-timeout timer
  295. * list.
  296. */
  297. if ((t->timeout_tick - timer->timeout_tick) == 0)
  298. {
  299. continue;
  300. }
  301. else if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX / 2)
  302. {
  303. break;
  304. }
  305. }
  306. if (row_lvl != RT_TIMER_SKIP_LIST_LEVEL - 1)
  307. row_head[row_lvl+1] = row_head[row_lvl]+1;
  308. }
  309. /* Interestingly, this super simple timer insert counter works very very
  310. * well on distributing the list height uniformly. By means of "very very
  311. * well", I mean it beats the randomness of timer->timeout_tick very easily
  312. * (actually, the timeout_tick is not random and easy to be attacked). */
  313. random_nr++;
  314. tst_nr = random_nr;
  315. rt_list_insert_after(row_head[RT_TIMER_SKIP_LIST_LEVEL-1],
  316. &(timer->row[RT_TIMER_SKIP_LIST_LEVEL-1]));
  317. for (row_lvl = 2; row_lvl <= RT_TIMER_SKIP_LIST_LEVEL; row_lvl++)
  318. {
  319. if (!(tst_nr & RT_TIMER_SKIP_LIST_MASK))
  320. rt_list_insert_after(row_head[RT_TIMER_SKIP_LIST_LEVEL - row_lvl],
  321. &(timer->row[RT_TIMER_SKIP_LIST_LEVEL - row_lvl]));
  322. else
  323. break;
  324. /* Shift over the bits we have tested. Works well with 1 bit and 2
  325. * bits. */
  326. tst_nr >>= (RT_TIMER_SKIP_LIST_MASK+1)>>1;
  327. }
  328. timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED;
  329. /* enable interrupt */
  330. rt_hw_interrupt_enable(level);
  331. #ifdef RT_USING_TIMER_SOFT
  332. if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
  333. {
  334. /* check whether timer thread is ready */
  335. if (timer_thread.stat != RT_THREAD_READY)
  336. {
  337. /* resume timer thread to check soft timer */
  338. rt_thread_resume(&timer_thread);
  339. rt_schedule();
  340. }
  341. }
  342. #endif
  343. return -RT_EOK;
  344. }
  345. RTM_EXPORT(rt_timer_start);
  346. /**
  347. * This function will stop the timer
  348. *
  349. * @param timer the timer to be stopped
  350. *
  351. * @return the operation status, RT_EOK on OK, -RT_ERROR on error
  352. */
  353. rt_err_t rt_timer_stop(rt_timer_t timer)
  354. {
  355. register rt_base_t level;
  356. /* timer check */
  357. RT_ASSERT(timer != RT_NULL);
  358. if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED))
  359. return -RT_ERROR;
  360. RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent)));
  361. /* disable interrupt */
  362. level = rt_hw_interrupt_disable();
  363. _rt_timer_remove(timer);
  364. /* enable interrupt */
  365. rt_hw_interrupt_enable(level);
  366. /* change stat */
  367. timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  368. return RT_EOK;
  369. }
  370. RTM_EXPORT(rt_timer_stop);
  371. /**
  372. * This function will get or set some options of the timer
  373. *
  374. * @param timer the timer to be get or set
  375. * @param cmd the control command
  376. * @param arg the argument
  377. *
  378. * @return RT_EOK
  379. */
  380. rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void *arg)
  381. {
  382. /* timer check */
  383. RT_ASSERT(timer != RT_NULL);
  384. switch (cmd)
  385. {
  386. case RT_TIMER_CTRL_GET_TIME:
  387. *(rt_tick_t *)arg = timer->init_tick;
  388. break;
  389. case RT_TIMER_CTRL_SET_TIME:
  390. timer->init_tick = *(rt_tick_t *)arg;
  391. break;
  392. case RT_TIMER_CTRL_SET_ONESHOT:
  393. timer->parent.flag &= ~RT_TIMER_FLAG_PERIODIC;
  394. break;
  395. case RT_TIMER_CTRL_SET_PERIODIC:
  396. timer->parent.flag |= RT_TIMER_FLAG_PERIODIC;
  397. break;
  398. }
  399. return RT_EOK;
  400. }
  401. RTM_EXPORT(rt_timer_control);
  402. /**
  403. * This function will check timer list, if a timeout event happens, the
  404. * corresponding timeout function will be invoked.
  405. *
  406. * @note this function shall be invoked in operating system timer interrupt.
  407. */
  408. void rt_timer_check(void)
  409. {
  410. struct rt_timer *t;
  411. rt_tick_t current_tick;
  412. register rt_base_t level;
  413. RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n"));
  414. current_tick = rt_tick_get();
  415. /* disable interrupt */
  416. level = rt_hw_interrupt_disable();
  417. while (!rt_list_isempty(&rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]))
  418. {
  419. t = rt_list_entry(rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
  420. struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
  421. /*
  422. * It supposes that the new tick shall less than the half duration of
  423. * tick max.
  424. */
  425. if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
  426. {
  427. RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));
  428. /* remove timer from timer list firstly */
  429. _rt_timer_remove(t);
  430. /* call timeout function */
  431. t->timeout_func(t->parameter);
  432. /* re-get tick */
  433. current_tick = rt_tick_get();
  434. RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
  435. if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
  436. (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
  437. {
  438. /* start it */
  439. t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  440. rt_timer_start(t);
  441. }
  442. else
  443. {
  444. /* stop timer */
  445. t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  446. }
  447. }
  448. else
  449. break;
  450. }
  451. /* enable interrupt */
  452. rt_hw_interrupt_enable(level);
  453. RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n"));
  454. }
  455. /**
  456. * This function will return the next timeout tick in the system.
  457. *
  458. * @return the next timeout tick in the system
  459. */
  460. rt_tick_t rt_timer_next_timeout_tick(void)
  461. {
  462. return rt_timer_list_next_timeout(rt_timer_list);
  463. }
  464. #ifdef RT_USING_TIMER_SOFT
  465. /**
  466. * This function will check timer list, if a timeout event happens, the
  467. * corresponding timeout function will be invoked.
  468. */
  469. void rt_soft_timer_check(void)
  470. {
  471. rt_tick_t current_tick;
  472. rt_list_t *n;
  473. struct rt_timer *t;
  474. RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n"));
  475. current_tick = rt_tick_get();
  476. /* lock scheduler */
  477. rt_enter_critical();
  478. for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1].next;
  479. n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]);)
  480. {
  481. t = rt_list_entry(n, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL-1]);
  482. /*
  483. * It supposes that the new tick shall less than the half duration of
  484. * tick max.
  485. */
  486. if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2)
  487. {
  488. RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));
  489. /* move node to the next */
  490. n = n->next;
  491. /* remove timer from timer list firstly */
  492. _rt_timer_remove(t);
  493. /* not lock scheduler when performing timeout function */
  494. rt_exit_critical();
  495. /* call timeout function */
  496. t->timeout_func(t->parameter);
  497. /* re-get tick */
  498. current_tick = rt_tick_get();
  499. RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
  500. /* lock scheduler */
  501. rt_enter_critical();
  502. if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
  503. (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
  504. {
  505. /* start it */
  506. t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  507. rt_timer_start(t);
  508. }
  509. else
  510. {
  511. /* stop timer */
  512. t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
  513. }
  514. }
  515. else break; /* not check anymore */
  516. }
  517. /* unlock scheduler */
  518. rt_exit_critical();
  519. RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
  520. }
  521. /* system timer thread entry */
  522. static void rt_thread_timer_entry(void *parameter)
  523. {
  524. rt_tick_t next_timeout;
  525. while (1)
  526. {
  527. /* get the next timeout tick */
  528. next_timeout = rt_timer_list_next_timeout(rt_soft_timer_list);
  529. if (next_timeout == RT_TICK_MAX)
  530. {
  531. /* no software timer exist, suspend self. */
  532. rt_thread_suspend(rt_thread_self());
  533. rt_schedule();
  534. }
  535. else
  536. {
  537. rt_tick_t current_tick;
  538. /* get current tick */
  539. current_tick = rt_tick_get();
  540. if ((next_timeout - current_tick) < RT_TICK_MAX/2)
  541. {
  542. /* get the delta timeout tick */
  543. next_timeout = next_timeout - current_tick;
  544. rt_thread_delay(next_timeout);
  545. }
  546. }
  547. /* check software timer */
  548. rt_soft_timer_check();
  549. }
  550. }
  551. #endif
  552. /**
  553. * @ingroup SystemInit
  554. *
  555. * This function will initialize system timer
  556. */
  557. void rt_system_timer_init(void)
  558. {
  559. int i;
  560. for (i = 0; i < sizeof(rt_timer_list)/sizeof(rt_timer_list[0]); i++)
  561. {
  562. rt_list_init(rt_timer_list+i);
  563. }
  564. }
  565. /**
  566. * @ingroup SystemInit
  567. *
  568. * This function will initialize system timer thread
  569. */
  570. void rt_system_timer_thread_init(void)
  571. {
  572. #ifdef RT_USING_TIMER_SOFT
  573. int i;
  574. for (i = 0;
  575. i < sizeof(rt_soft_timer_list)/sizeof(rt_soft_timer_list[0]);
  576. i++)
  577. {
  578. rt_list_init(rt_soft_timer_list+i);
  579. }
  580. /* start software timer thread */
  581. rt_thread_init(&timer_thread,
  582. "timer",
  583. rt_thread_timer_entry,
  584. RT_NULL,
  585. &timer_thread_stack[0],
  586. sizeof(timer_thread_stack),
  587. RT_TIMER_THREAD_PRIO,
  588. 10);
  589. /* startup */
  590. rt_thread_startup(&timer_thread);
  591. #endif
  592. }
  593. /*@}*/