Lines Matching full:timer
9 * 2006-04-29 Bernard implement thread timer
11 * 2006-08-10 Bernard fix the periodic timer bug
13 * 2009-11-11 LiJin add soft timer
14 * 2010-05-12 Bernard fix the timer check bug.
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
24 /* hard timer list */
36 /* soft timer list */
46 static void (*rt_timer_enter_hook)(struct rt_timer *timer);
47 static void (*rt_timer_exit_hook)(struct rt_timer *timer);
57 * timer timeout callback function.
61 void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) in rt_timer_enter_sethook() argument
68 * timer timeout callback function.
72 void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) in rt_timer_exit_sethook() argument
80 static void _rt_timer_init(rt_timer_t timer, in _rt_timer_init() argument
89 timer->parent.flag = flag; in _rt_timer_init()
92 timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; in _rt_timer_init()
94 timer->timeout_func = timeout; in _rt_timer_init()
95 timer->parameter = parameter; in _rt_timer_init()
97 timer->timeout_tick = 0; in _rt_timer_init()
98 timer->init_tick = time; in _rt_timer_init()
100 /* initialize timer list */ in _rt_timer_init()
103 rt_list_init(&(timer->row[i])); in _rt_timer_init()
107 /* the fist timer always in the last row */
110 struct rt_timer *timer; in rt_timer_list_next_timeout() local
115 timer = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, in rt_timer_list_next_timeout()
118 return timer->timeout_tick; in rt_timer_list_next_timeout()
121 rt_inline void _rt_timer_remove(rt_timer_t timer) in _rt_timer_remove() argument
127 rt_list_remove(&timer->row[i]); in _rt_timer_remove()
132 static int rt_timer_count_height(struct rt_timer *timer) in rt_timer_count_height() argument
138 if (!rt_list_isempty(&timer->row[i])) in rt_timer_count_height()
152 struct rt_timer *timer = rt_list_entry(list, in rt_timer_dump() local
155 rt_kprintf("%d", rt_timer_count_height(timer)); in rt_timer_dump()
168 * This function will initialize a timer, normally this function is used to
169 * initialize a static timer object.
171 * @param timer the static timer object
172 * @param name the name of timer
175 * @param time the tick of timer
176 * @param flag the flag of timer
178 void rt_timer_init(rt_timer_t timer, in rt_timer_init() argument
185 /* timer check */ in rt_timer_init()
186 RT_ASSERT(timer != RT_NULL); in rt_timer_init()
188 /* timer object initialization */ in rt_timer_init()
189 rt_object_init((rt_object_t)timer, RT_Object_Class_Timer, name); in rt_timer_init()
191 _rt_timer_init(timer, timeout, parameter, time, flag); in rt_timer_init()
196 * This function will detach a timer from timer management.
198 * @param timer the static timer object
202 rt_err_t rt_timer_detach(rt_timer_t timer) in rt_timer_detach() argument
206 /* timer check */ in rt_timer_detach()
207 RT_ASSERT(timer != RT_NULL); in rt_timer_detach()
208 RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); in rt_timer_detach()
209 RT_ASSERT(rt_object_is_systemobject(&timer->parent)); in rt_timer_detach()
214 _rt_timer_remove(timer); in rt_timer_detach()
219 rt_object_detach((rt_object_t)timer); in rt_timer_detach()
227 * This function will create a timer
229 * @param name the name of timer
232 * @param time the tick of timer
233 * @param flag the flag of timer
235 * @return the created timer object
243 struct rt_timer *timer; in rt_timer_create() local
246 timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name); in rt_timer_create()
247 if (timer == RT_NULL) in rt_timer_create()
252 _rt_timer_init(timer, timeout, parameter, time, flag); in rt_timer_create()
254 return timer; in rt_timer_create()
259 * This function will delete a timer and release timer memory
261 * @param timer the timer to be deleted
265 rt_err_t rt_timer_delete(rt_timer_t timer) in rt_timer_delete() argument
269 /* timer check */ in rt_timer_delete()
270 RT_ASSERT(timer != RT_NULL); in rt_timer_delete()
271 RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); in rt_timer_delete()
272 RT_ASSERT(rt_object_is_systemobject(&timer->parent) == RT_FALSE); in rt_timer_delete()
277 _rt_timer_remove(timer); in rt_timer_delete()
282 rt_object_delete((rt_object_t)timer); in rt_timer_delete()
290 * This function will start the timer
292 * @param timer the timer to be started
296 rt_err_t rt_timer_start(rt_timer_t timer) in rt_timer_start() argument
305 /* timer check */ in rt_timer_start()
306 RT_ASSERT(timer != RT_NULL); in rt_timer_start()
307 RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); in rt_timer_start()
309 /* stop timer firstly */ in rt_timer_start()
311 /* remove timer from list */ in rt_timer_start()
312 _rt_timer_remove(timer); in rt_timer_start()
313 /* change status of timer */ in rt_timer_start()
314 timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; in rt_timer_start()
317 RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent))); in rt_timer_start()
323 RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); in rt_timer_start()
324 timer->timeout_tick = rt_tick_get() + timer->init_tick; in rt_timer_start()
330 if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) in rt_timer_start()
332 /* insert timer to soft timer list */ in rt_timer_start()
338 /* insert timer to system timer list */ in rt_timer_start()
355 * preferred that the timer inserted early get called early. in rt_timer_start()
356 * So insert the new timer to the end the the some-timeout timer in rt_timer_start()
359 if ((t->timeout_tick - timer->timeout_tick) == 0) in rt_timer_start()
363 else if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX / 2) in rt_timer_start()
372 /* Interestingly, this super simple timer insert counter works very very in rt_timer_start()
374 * well", I mean it beats the randomness of timer->timeout_tick very easily in rt_timer_start()
380 &(timer->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); in rt_timer_start()
385 &(timer->row[RT_TIMER_SKIP_LIST_LEVEL - row_lvl])); in rt_timer_start()
393 timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED; in rt_timer_start()
399 if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) in rt_timer_start()
401 /* check whether timer thread is ready */ in rt_timer_start()
404 /* resume timer thread to check soft timer */ in rt_timer_start()
416 * This function will stop the timer
418 * @param timer the timer to be stopped
422 rt_err_t rt_timer_stop(rt_timer_t timer) in rt_timer_stop() argument
426 /* timer check */ in rt_timer_stop()
427 RT_ASSERT(timer != RT_NULL); in rt_timer_stop()
428 RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); in rt_timer_stop()
430 if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) in rt_timer_stop()
433 RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent))); in rt_timer_stop()
438 _rt_timer_remove(timer); in rt_timer_stop()
444 timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; in rt_timer_stop()
451 * This function will get or set some options of the timer
453 * @param timer the timer to be get or set
459 rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) in rt_timer_control() argument
461 /* timer check */ in rt_timer_control()
462 RT_ASSERT(timer != RT_NULL); in rt_timer_control()
463 RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); in rt_timer_control()
468 *(rt_tick_t *)arg = timer->init_tick; in rt_timer_control()
472 timer->init_tick = *(rt_tick_t *)arg; in rt_timer_control()
476 timer->parent.flag &= ~RT_TIMER_FLAG_PERIODIC; in rt_timer_control()
480 timer->parent.flag |= RT_TIMER_FLAG_PERIODIC; in rt_timer_control()
489 * This function will check timer list, if a timeout event happens, the
492 * @note this function shall be invoked in operating system timer interrupt.
500 RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n")); in rt_timer_check()
520 /* remove timer from timer list firstly */ in rt_timer_check()
541 /* stop timer */ in rt_timer_check()
552 RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n")); in rt_timer_check()
567 * This function will check timer list, if a timeout event happens, the
576 RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n")); in rt_soft_timer_check()
599 /* remove timer from timer list firstly */ in rt_soft_timer_check()
625 /* stop timer */ in rt_soft_timer_check()
635 RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n")); in rt_soft_timer_check()
638 /* system timer thread entry */
649 /* no software timer exist, suspend self. */ in rt_thread_timer_entry()
668 /* check software timer */ in rt_thread_timer_entry()
677 * This function will initialize system timer
692 * This function will initialize system timer thread
706 /* start software timer thread */ in rt_system_timer_thread_init()
708 "timer", in rt_system_timer_thread_init()