timer.c 18 KB

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