From 30fd28a89a1a73428f9cd8086add95c4066d2857 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sun, 15 Aug 2021 23:04:35 +0800 Subject: add the comment of timer.c --- src/timer.c | 98 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 30 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 1c8e70fccc..18b7ac4d58 100644 --- a/src/timer.c +++ b/src/timer.c @@ -16,6 +16,7 @@ * 2012-12-15 Bernard fix the next timeout issue in soft timer * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer * timeout function. + * 2021-08-15 supperthomas add the comment */ #include @@ -59,10 +60,10 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); /**@{*/ /** - * This function will set a hook function, which will be invoked when enter - * timer timeout callback function. - * - * @param hook the hook function + * @brief This function will set a hook function on timer, + * which will be invoked when enter timer timeout callback function. + * + * @param hook the function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { @@ -70,10 +71,10 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) } /** - * This function will set a hook function, which will be invoked when exit - * timer timeout callback function. - * - * @param hook the hook function + * @brief This function will set a hook function, which will be + * invoked when exit * timer timeout callback function. + * + * @param hook the function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) { @@ -83,6 +84,20 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) /**@}*/ #endif /* RT_USING_HOOK */ + +/** + * @brief [internal] the init funtion of timer + * + * the internal called function of rt_timer_init + * + * @see rt_timer_init + * + * @param timer the static timer object + * @param timeout the timeout function + * @param parameter the parameter of timeout function + * @param time the tick of timer + * @param flag the flag of timer + */ static void _rt_timer_init(rt_timer_t timer, void (*timeout)(void *parameter), void *parameter, @@ -110,7 +125,13 @@ static void _rt_timer_init(rt_timer_t timer, } } -/* the fist timer always in the last row */ +/** + * @brief find the next emtpy timer + * + * @param timer_list the timer of the next timeout + * + * @return rt_tick_t the point of timer + */ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) { struct rt_timer *timer; @@ -133,6 +154,11 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) return timeout_tick; } +/** + * @brief remove the timer + * + * @param timer the point of timer + */ rt_inline void _rt_timer_remove(rt_timer_t timer) { int i; @@ -144,6 +170,12 @@ rt_inline void _rt_timer_remove(rt_timer_t timer) } #if RT_DEBUG_TIMER +/** + * @brief the number of timer + * + * @param timer + * @return int the count + */ static int rt_timer_count_height(struct rt_timer *timer) { int i, cnt = 0; @@ -155,7 +187,11 @@ static int rt_timer_count_height(struct rt_timer *timer) } return cnt; } - +/** + * @brief dump the all timer information + * + * @param timer_heads the head of timer + */ void rt_timer_dump(rt_list_t timer_heads[]) { rt_list_t *list; @@ -180,9 +216,8 @@ void rt_timer_dump(rt_list_t timer_heads[]) /**@{*/ /** - * This function will initialize a timer, normally this function is used to - * initialize a static timer object. - * + * @brief This function will initialize a timer + * normally this function is used to initialize a static timer object. * @param timer the static timer object * @param name the name of timer * @param timeout the timeout function @@ -208,11 +243,10 @@ void rt_timer_init(rt_timer_t timer, RTM_EXPORT(rt_timer_init); /** - * This function will detach a timer from timer management. - * - * @param timer the static timer object - * - * @return the operation status, RT_EOK on OK; RT_ERROR on error + * @brief This function will detach a timer from timer management. + * + * @param timer the timer to be detached + * @return rt_err_t RT_EOK */ rt_err_t rt_timer_detach(rt_timer_t timer) { @@ -241,7 +275,7 @@ RTM_EXPORT(rt_timer_detach); #ifdef RT_USING_HEAP /** - * This function will create a timer + * @brief This function will create a timer * * @param name the name of timer * @param timeout the timeout function @@ -273,7 +307,7 @@ rt_timer_t rt_timer_create(const char *name, RTM_EXPORT(rt_timer_create); /** - * This function will delete a timer and release timer memory + * @brief This function will delete a timer and release timer memory * * @param timer the timer to be deleted * @@ -306,7 +340,7 @@ RTM_EXPORT(rt_timer_delete); #endif /* RT_USING_HEAP */ /** - * This function will start the timer + * @brief This function will start the timer * * @param timer the timer to be started * @@ -429,7 +463,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) RTM_EXPORT(rt_timer_start); /** - * This function will stop the timer + * @brief This function will stop the timer * * @param timer the timer to be stopped * @@ -463,7 +497,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer) RTM_EXPORT(rt_timer_stop); /** - * This function will get or set some options of the timer + * @brief This function will get or set some options of the timer * * @param timer the timer to be get or set * @param cmd the control command @@ -521,8 +555,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) RTM_EXPORT(rt_timer_control); /** - * This function will check timer list, if a timeout event happens, the - * corresponding timeout function will be invoked. + * @brief This function will check timer list, if a timeout event happens, + * the corresponding timeout function will be invoked. * * @note this function shall be invoked in operating system timer interrupt. */ @@ -596,7 +630,7 @@ void rt_timer_check(void) } /** - * This function will return the next timeout tick in the system. + * @brief This function will return the next timeout tick in the system. * * @return the next timeout tick in the system */ @@ -607,7 +641,7 @@ rt_tick_t rt_timer_next_timeout_tick(void) #ifdef RT_USING_TIMER_SOFT /** - * This function will check software-timer list, if a timeout event happens, the + * @brief This function will check software-timer list, if a timeout event happens, the * corresponding timeout function will be invoked. */ void rt_soft_timer_check(void) @@ -684,7 +718,11 @@ void rt_soft_timer_check(void) RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n")); } -/* system timer thread entry */ +/** + * @brief system timer thread entry + * + * @param parameter + */ static void rt_thread_timer_entry(void *parameter) { rt_tick_t next_timeout; @@ -723,7 +761,7 @@ static void rt_thread_timer_entry(void *parameter) /** * @ingroup SystemInit * - * This function will initialize system timer + * @brief This function will initialize system timer */ void rt_system_timer_init(void) { @@ -738,7 +776,7 @@ void rt_system_timer_init(void) /** * @ingroup SystemInit * - * This function will initialize system timer thread + * @brief This function will initialize system timer thread */ void rt_system_timer_thread_init(void) { -- cgit v1.3.1 From 19bcf9ae32682697dc2beac7cc605f7338d44c2f Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Mon, 16 Aug 2021 22:07:46 +0800 Subject: add the formatted file --- src/irq.c | 24 ++++++++++++------------ src/timer.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/timer.c') diff --git a/src/irq.c b/src/irq.c index ac43c45573..40c2aa5305 100644 --- a/src/irq.c +++ b/src/irq.c @@ -22,11 +22,11 @@ static void (*rt_interrupt_leave_hook)(void); /** * @ingroup Hook - * + * * @brief This function set a hook function when the system enter a interrupt - * + * * @note the hook function must be simple and never be blocked or suspend. - * + * * @param hook The function point to be called */ void rt_interrupt_enter_sethook(void (*hook)(void)) @@ -36,11 +36,11 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) /** * @ingroup Hook - * + * * @brief This function set a hook function when the system exit a interrupt. - * + * * @note the hook function must be simple and never be blocked or suspend. - * + * * @param hook The function point to be called */ void rt_interrupt_leave_sethook(void (*hook)(void)) @@ -64,9 +64,9 @@ volatile rt_uint8_t rt_interrupt_nest = 0; /** * @brief This function will be invoked by BSP, when enter interrupt service routine - * + * * @note please don't invoke this routine in application - * + * * @see rt_interrupt_leave */ void rt_interrupt_enter(void) @@ -86,9 +86,9 @@ RTM_EXPORT(rt_interrupt_enter); /** * @brief This function will be invoked by BSP, when leave interrupt service routine - * + * * @note please don't invoke this routine in application - * + * * @see rt_interrupt_enter */ void rt_interrupt_leave(void) @@ -108,10 +108,10 @@ RTM_EXPORT(rt_interrupt_leave); /** * @brief This function will return the nest of interrupt. - * + * * User application can invoke this function to get whether current * context is interrupt context. - * + * * @return rt_uint8_t the number of nested interrupts. */ RT_WEAK rt_uint8_t rt_interrupt_get_nest(void) diff --git a/src/timer.c b/src/timer.c index 18b7ac4d58..44d0d4a7cc 100644 --- a/src/timer.c +++ b/src/timer.c @@ -16,7 +16,7 @@ * 2012-12-15 Bernard fix the next timeout issue in soft timer * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer * timeout function. - * 2021-08-15 supperthomas add the comment + * 2021-08-15 supperthomas add the comment */ #include @@ -60,9 +60,9 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); /**@{*/ /** - * @brief This function will set a hook function on timer, + * @brief This function will set a hook function on timer, * which will be invoked when enter timer timeout callback function. - * + * * @param hook the function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) @@ -71,9 +71,9 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) } /** - * @brief This function will set a hook function, which will be + * @brief This function will set a hook function, which will be * invoked when exit * timer timeout callback function. - * + * * @param hook the function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) @@ -87,11 +87,11 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) /** * @brief [internal] the init funtion of timer - * + * * the internal called function of rt_timer_init - * + * * @see rt_timer_init - * + * * @param timer the static timer object * @param timeout the timeout function * @param parameter the parameter of timeout function @@ -127,9 +127,9 @@ static void _rt_timer_init(rt_timer_t timer, /** * @brief find the next emtpy timer - * + * * @param timer_list the timer of the next timeout - * + * * @return rt_tick_t the point of timer */ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) @@ -155,8 +155,8 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) } /** - * @brief remove the timer - * + * @brief remove the timer + * * @param timer the point of timer */ rt_inline void _rt_timer_remove(rt_timer_t timer) @@ -172,8 +172,8 @@ rt_inline void _rt_timer_remove(rt_timer_t timer) #if RT_DEBUG_TIMER /** * @brief the number of timer - * - * @param timer + * + * @param timer * @return int the count */ static int rt_timer_count_height(struct rt_timer *timer) @@ -189,7 +189,7 @@ static int rt_timer_count_height(struct rt_timer *timer) } /** * @brief dump the all timer information - * + * * @param timer_heads the head of timer */ void rt_timer_dump(rt_list_t timer_heads[]) @@ -244,7 +244,7 @@ RTM_EXPORT(rt_timer_init); /** * @brief This function will detach a timer from timer management. - * + * * @param timer the timer to be detached * @return rt_err_t RT_EOK */ @@ -555,7 +555,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) RTM_EXPORT(rt_timer_control); /** - * @brief This function will check timer list, if a timeout event happens, + * @brief This function will check timer list, if a timeout event happens, * the corresponding timeout function will be invoked. * * @note this function shall be invoked in operating system timer interrupt. @@ -719,9 +719,9 @@ void rt_soft_timer_check(void) } /** - * @brief system timer thread entry - * - * @param parameter + * @brief system timer thread entry + * + * @param parameter */ static void rt_thread_timer_entry(void *parameter) { -- cgit v1.3.1 From 247f21f998ccb61f3bdebfa3239c1714c81905f3 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 17 Aug 2021 05:56:39 -0400 Subject: [kernel][timer] 规范内部函数和变量命名 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 82 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 44d0d4a7cc..07647a55f9 100644 --- a/src/timer.c +++ b/src/timer.c @@ -23,7 +23,7 @@ #include /* hard timer list */ -static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; +static rt_list_t _timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #ifdef RT_USING_TIMER_SOFT @@ -39,12 +39,12 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #endif /* RT_TIMER_THREAD_PRIO */ /* soft timer status */ -static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE; +static rt_uint8_t _soft_timer_status = RT_SOFT_TIMER_IDLE; /* soft timer list */ -static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; -static struct rt_thread timer_thread; +static rt_list_t _soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; +static struct rt_thread _timer_thread; ALIGN(RT_ALIGN_SIZE) -static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; +static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #endif /* RT_USING_TIMER_SOFT */ #ifdef RT_USING_HOOK @@ -98,7 +98,7 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) * @param time the tick of timer * @param flag the flag of timer */ -static void _rt_timer_init(rt_timer_t timer, +static void _timer_init(rt_timer_t timer, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, @@ -132,7 +132,7 @@ static void _rt_timer_init(rt_timer_t timer, * * @return rt_tick_t the point of timer */ -static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) +static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) { struct rt_timer *timer; register rt_base_t level; @@ -159,7 +159,7 @@ static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) * * @param timer the point of timer */ -rt_inline void _rt_timer_remove(rt_timer_t timer) +rt_inline void _timer_remove(rt_timer_t timer) { int i; @@ -176,7 +176,7 @@ rt_inline void _rt_timer_remove(rt_timer_t timer) * @param timer * @return int the count */ -static int rt_timer_count_height(struct rt_timer *timer) +static int _timer_count_height(struct rt_timer *timer) { int i, cnt = 0; @@ -203,7 +203,7 @@ void rt_timer_dump(rt_list_t timer_heads[]) struct rt_timer *timer = rt_list_entry(list, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); - rt_kprintf("%d", rt_timer_count_height(timer)); + rt_kprintf("%d", _timer_count_height(timer)); } rt_kprintf("\n"); } @@ -238,7 +238,7 @@ void rt_timer_init(rt_timer_t timer, /* timer object initialization */ rt_object_init(&(timer->parent), RT_Object_Class_Timer, name); - _rt_timer_init(timer, timeout, parameter, time, flag); + _timer_init(timer, timeout, parameter, time, flag); } RTM_EXPORT(rt_timer_init); @@ -260,7 +260,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _rt_timer_remove(timer); + _timer_remove(timer); /* stop timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -300,7 +300,7 @@ rt_timer_t rt_timer_create(const char *name, return RT_NULL; } - _rt_timer_init(timer, timeout, parameter, time, flag); + _timer_init(timer, timeout, parameter, time, flag); return timer; } @@ -325,7 +325,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _rt_timer_remove(timer); + _timer_remove(timer); /* stop timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -362,7 +362,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) /* stop timer firstly */ level = rt_hw_interrupt_disable(); /* remove timer from list */ - _rt_timer_remove(timer); + _timer_remove(timer); /* change status of timer */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -379,13 +379,13 @@ rt_err_t rt_timer_start(rt_timer_t timer) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { /* insert timer to soft timer list */ - timer_list = rt_soft_timer_list; + timer_list = _soft_timer_list; } else #endif /* RT_USING_TIMER_SOFT */ { /* insert timer to system timer list */ - timer_list = rt_timer_list; + timer_list = _timer_list; } row_head[0] = &timer_list[0]; @@ -448,11 +448,11 @@ rt_err_t rt_timer_start(rt_timer_t timer) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { /* check whether timer thread is ready */ - if ((soft_timer_status == RT_SOFT_TIMER_IDLE) && - ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) + if ((_soft_timer_status == RT_SOFT_TIMER_IDLE) && + ((_timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume timer thread to check soft timer */ - rt_thread_resume(&timer_thread); + rt_thread_resume(&_timer_thread); rt_schedule(); } } @@ -485,7 +485,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer) /* disable interrupt */ level = rt_hw_interrupt_disable(); - _rt_timer_remove(timer); + _timer_remove(timer); /* change status */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -576,9 +576,9 @@ void rt_timer_check(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - while (!rt_list_isempty(&rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) + while (!rt_list_isempty(&_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { - t = rt_list_entry(rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + t = rt_list_entry(_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); /* @@ -590,7 +590,7 @@ void rt_timer_check(void) RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ - _rt_timer_remove(t); + _timer_remove(t); if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) { t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -636,7 +636,7 @@ void rt_timer_check(void) */ rt_tick_t rt_timer_next_timeout_tick(void) { - return rt_timer_list_next_timeout(rt_timer_list); + return _timer_list_next_timeout(_timer_list); } #ifdef RT_USING_TIMER_SOFT @@ -658,9 +658,9 @@ void rt_soft_timer_check(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) + while (!rt_list_isempty(&_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { - t = rt_list_entry(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + t = rt_list_entry(_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); current_tick = rt_tick_get(); @@ -674,7 +674,7 @@ void rt_soft_timer_check(void) RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ - _rt_timer_remove(t); + _timer_remove(t); if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) { t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; @@ -682,7 +682,7 @@ void rt_soft_timer_check(void) /* add timer to temporary list */ rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); - soft_timer_status = RT_SOFT_TIMER_BUSY; + _soft_timer_status = RT_SOFT_TIMER_BUSY; /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -695,7 +695,7 @@ void rt_soft_timer_check(void) /* disable interrupt */ level = rt_hw_interrupt_disable(); - soft_timer_status = RT_SOFT_TIMER_IDLE; + _soft_timer_status = RT_SOFT_TIMER_IDLE; /* Check whether the timer object is detached or started again */ if (rt_list_isempty(&list)) { @@ -723,14 +723,14 @@ void rt_soft_timer_check(void) * * @param parameter */ -static void rt_thread_timer_entry(void *parameter) +static void _timer_thread_entry(void *parameter) { rt_tick_t next_timeout; while (1) { /* get the next timeout tick */ - next_timeout = rt_timer_list_next_timeout(rt_soft_timer_list); + next_timeout = _timer_list_next_timeout(_soft_timer_list); if (next_timeout == RT_TICK_MAX) { /* no software timer exist, suspend self. */ @@ -767,9 +767,9 @@ void rt_system_timer_init(void) { int i; - for (i = 0; i < sizeof(rt_timer_list) / sizeof(rt_timer_list[0]); i++) + for (i = 0; i < sizeof(_timer_list) / sizeof(_timer_list[0]); i++) { - rt_list_init(rt_timer_list + i); + rt_list_init(_timer_list + i); } } @@ -784,24 +784,24 @@ void rt_system_timer_thread_init(void) int i; for (i = 0; - i < sizeof(rt_soft_timer_list) / sizeof(rt_soft_timer_list[0]); + i < sizeof(_soft_timer_list) / sizeof(_soft_timer_list[0]); i++) { - rt_list_init(rt_soft_timer_list + i); + rt_list_init(_soft_timer_list + i); } /* start software timer thread */ - rt_thread_init(&timer_thread, + rt_thread_init(&_timer_thread, "timer", - rt_thread_timer_entry, + _timer_thread_entry, RT_NULL, - &timer_thread_stack[0], - sizeof(timer_thread_stack), + &_timer_thread_stack[0], + sizeof(_timer_thread_stack), RT_TIMER_THREAD_PRIO, 10); /* startup */ - rt_thread_startup(&timer_thread); + rt_thread_startup(&_timer_thread); #endif /* RT_USING_TIMER_SOFT */ } -- cgit v1.3.1 From 320c44adf81c7405a6b791fc890d7c21a7dbd756 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Sat, 28 Aug 2021 23:31:35 +0800 Subject: add the fixed comment --- src/irq.c | 8 ++--- src/timer.c | 112 ++++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 68 insertions(+), 52 deletions(-) (limited to 'src/timer.c') diff --git a/src/irq.c b/src/irq.c index 40c2aa5305..81c972c955 100644 --- a/src/irq.c +++ b/src/irq.c @@ -25,7 +25,7 @@ static void (*rt_interrupt_leave_hook)(void); * * @brief This function set a hook function when the system enter a interrupt * - * @note the hook function must be simple and never be blocked or suspend. + * @note The hook function must be simple and never be blocked or suspend. * * @param hook The function point to be called */ @@ -39,7 +39,7 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) * * @brief This function set a hook function when the system exit a interrupt. * - * @note the hook function must be simple and never be blocked or suspend. + * @note The hook function must be simple and never be blocked or suspend. * * @param hook The function point to be called */ @@ -65,7 +65,7 @@ volatile rt_uint8_t rt_interrupt_nest = 0; /** * @brief This function will be invoked by BSP, when enter interrupt service routine * - * @note please don't invoke this routine in application + * @note Please don't invoke this routine in application * * @see rt_interrupt_leave */ @@ -87,7 +87,7 @@ RTM_EXPORT(rt_interrupt_enter); /** * @brief This function will be invoked by BSP, when leave interrupt service routine * - * @note please don't invoke this routine in application + * @note Please don't invoke this routine in application * * @see rt_interrupt_enter */ diff --git a/src/timer.c b/src/timer.c index 07647a55f9..5c90d34675 100644 --- a/src/timer.c +++ b/src/timer.c @@ -61,9 +61,9 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); /** * @brief This function will set a hook function on timer, - * which will be invoked when enter timer timeout callback function. + * which will be invoked when enter timer timeout callback function. * - * @param hook the function point of timer + * @param hook The function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { @@ -72,9 +72,9 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) /** * @brief This function will set a hook function, which will be - * invoked when exit * timer timeout callback function. + * invoked when exit timer timeout callback function. * - * @param hook the function point of timer + * @param hook The function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) { @@ -86,17 +86,21 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) /** - * @brief [internal] the init funtion of timer + * @brief [internal] The init funtion of timer * - * the internal called function of rt_timer_init + * The internal called function of rt_timer_init * * @see rt_timer_init * - * @param timer the static timer object - * @param timeout the timeout function - * @param parameter the parameter of timeout function - * @param time the tick of timer - * @param flag the flag of timer + * @param timer The static timer object + * + * @param timeout The timeout function + * + * @param parameter The parameter of timeout function + * + * @param time The tick of timer + * + * @param flag The flag of timer */ static void _timer_init(rt_timer_t timer, void (*timeout)(void *parameter), @@ -126,11 +130,11 @@ static void _timer_init(rt_timer_t timer, } /** - * @brief find the next emtpy timer + * @brief Find the next emtpy timer ticks * - * @param timer_list the timer of the next timeout + * @param timer_list The timer of the next timeout * - * @return rt_tick_t the point of timer + * @return rt_tick_t The next timer's ticks */ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) { @@ -155,9 +159,9 @@ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) } /** - * @brief remove the timer + * @brief Remove the timer * - * @param timer the point of timer + * @param timer The point of the timer */ rt_inline void _timer_remove(rt_timer_t timer) { @@ -171,10 +175,11 @@ rt_inline void _timer_remove(rt_timer_t timer) #if RT_DEBUG_TIMER /** - * @brief the number of timer + * @brief The number of timer * - * @param timer - * @return int the count + * @param timer the head of timer + * + * @return int the count of timer */ static int _timer_count_height(struct rt_timer *timer) { @@ -218,12 +223,18 @@ void rt_timer_dump(rt_list_t timer_heads[]) /** * @brief This function will initialize a timer * normally this function is used to initialize a static timer object. - * @param timer the static timer object - * @param name the name of timer - * @param timeout the timeout function - * @param parameter the parameter of timeout function - * @param time the tick of timer - * @param flag the flag of timer + * + * @param timer The static timer object + * + * @param name The name of timer + * + * @param timeout The timeout function + * + * @param parameter The parameter of timeout function + * + * @param time The tick of timer + * + * @param flag The flag of timer */ void rt_timer_init(rt_timer_t timer, const char *name, @@ -245,8 +256,9 @@ RTM_EXPORT(rt_timer_init); /** * @brief This function will detach a timer from timer management. * - * @param timer the timer to be detached - * @return rt_err_t RT_EOK + * @param timer The timer to be detached + * + * @return rt_err_t The status of detach */ rt_err_t rt_timer_detach(rt_timer_t timer) { @@ -277,13 +289,17 @@ RTM_EXPORT(rt_timer_detach); /** * @brief This function will create a timer * - * @param name the name of timer - * @param timeout the timeout function - * @param parameter the parameter of timeout function - * @param time the tick of timer - * @param flag the flag of timer + * @param name The name of timer + * + * @param timeout The timeout function + * + * @param parameter The parameter of timeout function + * + * @param time The tick of timer + * + * @param flag The flag of timer * - * @return the created timer object + * @return The created timer object */ rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), @@ -309,9 +325,9 @@ RTM_EXPORT(rt_timer_create); /** * @brief This function will delete a timer and release timer memory * - * @param timer the timer to be deleted + * @param timer The timer to be deleted * - * @return the operation status, RT_EOK on OK; RT_ERROR on error + * @return rt_err_t The operation status, RT_EOK on OK; RT_ERROR on error */ rt_err_t rt_timer_delete(rt_timer_t timer) { @@ -342,9 +358,9 @@ RTM_EXPORT(rt_timer_delete); /** * @brief This function will start the timer * - * @param timer the timer to be started + * @param timer The timer to be started * - * @return the operation status, RT_EOK on OK, -RT_ERROR on error + * @return The operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_start(rt_timer_t timer) { @@ -465,9 +481,9 @@ RTM_EXPORT(rt_timer_start); /** * @brief This function will stop the timer * - * @param timer the timer to be stopped + * @param timer The timer to be stopped * - * @return the operation status, RT_EOK on OK, -RT_ERROR on error + * @return The operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_stop(rt_timer_t timer) { @@ -499,11 +515,11 @@ RTM_EXPORT(rt_timer_stop); /** * @brief This function will get or set some options of the timer * - * @param timer the timer to be get or set - * @param cmd the control command - * @param arg the argument + * @param timer The timer to be get or set + * @param cmd The control command + * @param arg The argument * - * @return RT_EOK + * @return rt_err_t the statu of control */ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { @@ -558,7 +574,7 @@ RTM_EXPORT(rt_timer_control); * @brief This function will check timer list, if a timeout event happens, * the corresponding timeout function will be invoked. * - * @note this function shall be invoked in operating system timer interrupt. + * @note This function shall be invoked in operating system timer interrupt. */ void rt_timer_check(void) { @@ -632,7 +648,7 @@ void rt_timer_check(void) /** * @brief This function will return the next timeout tick in the system. * - * @return the next timeout tick in the system + * @return The next timeout tick in the system */ rt_tick_t rt_timer_next_timeout_tick(void) { @@ -642,7 +658,7 @@ rt_tick_t rt_timer_next_timeout_tick(void) #ifdef RT_USING_TIMER_SOFT /** * @brief This function will check software-timer list, if a timeout event happens, the - * corresponding timeout function will be invoked. + * corresponding timeout function will be invoked. */ void rt_soft_timer_check(void) { @@ -719,9 +735,9 @@ void rt_soft_timer_check(void) } /** - * @brief system timer thread entry + * @brief System timer thread entry * - * @param parameter + * @param parameter The arg of the thread */ static void _timer_thread_entry(void *parameter) { -- cgit v1.3.1 From a35520f841ebb7fb2152e7f9a7893d3a95f8615f Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Mon, 30 Aug 2021 07:28:36 +0800 Subject: fix the return --- src/irq.c | 6 ++--- src/timer.c | 74 ++++++++++++++++++++++++++++++------------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src/timer.c') diff --git a/src/irq.c b/src/irq.c index 81c972c955..3889a2a2c8 100644 --- a/src/irq.c +++ b/src/irq.c @@ -27,7 +27,7 @@ static void (*rt_interrupt_leave_hook)(void); * * @note The hook function must be simple and never be blocked or suspend. * - * @param hook The function point to be called + * @param hook the function point to be called */ void rt_interrupt_enter_sethook(void (*hook)(void)) { @@ -41,7 +41,7 @@ void rt_interrupt_enter_sethook(void (*hook)(void)) * * @note The hook function must be simple and never be blocked or suspend. * - * @param hook The function point to be called + * @param hook the function point to be called */ void rt_interrupt_leave_sethook(void (*hook)(void)) { @@ -112,7 +112,7 @@ RTM_EXPORT(rt_interrupt_leave); * User application can invoke this function to get whether current * context is interrupt context. * - * @return rt_uint8_t the number of nested interrupts. + * @return the number of nested interrupts. */ RT_WEAK rt_uint8_t rt_interrupt_get_nest(void) { diff --git a/src/timer.c b/src/timer.c index 5c90d34675..da52a02fc8 100644 --- a/src/timer.c +++ b/src/timer.c @@ -63,7 +63,7 @@ static void (*rt_timer_exit_hook)(struct rt_timer *timer); * @brief This function will set a hook function on timer, * which will be invoked when enter timer timeout callback function. * - * @param hook The function point of timer + * @param hook is the function point of timer */ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { @@ -74,7 +74,7 @@ void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) * @brief This function will set a hook function, which will be * invoked when exit timer timeout callback function. * - * @param hook The function point of timer + * @param hook is the function point of timer */ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) { @@ -92,15 +92,15 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) * * @see rt_timer_init * - * @param timer The static timer object + * @param timer is timer object * - * @param timeout The timeout function + * @param timeout is the timeout function * - * @param parameter The parameter of timeout function + * @param parameter is the parameter of timeout function * - * @param time The tick of timer + * @param time is the tick of timer * - * @param flag The flag of timer + * @param flag the flag of timer */ static void _timer_init(rt_timer_t timer, void (*timeout)(void *parameter), @@ -132,9 +132,9 @@ static void _timer_init(rt_timer_t timer, /** * @brief Find the next emtpy timer ticks * - * @param timer_list The timer of the next timeout + * @param timer_list is the array of time list * - * @return rt_tick_t The next timer's ticks + * @return the next timer's ticks */ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) { @@ -161,7 +161,7 @@ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[]) /** * @brief Remove the timer * - * @param timer The point of the timer + * @param timer the point of the timer */ rt_inline void _timer_remove(rt_timer_t timer) { @@ -179,7 +179,7 @@ rt_inline void _timer_remove(rt_timer_t timer) * * @param timer the head of timer * - * @return int the count of timer + * @return count of timer */ static int _timer_count_height(struct rt_timer *timer) { @@ -224,17 +224,17 @@ void rt_timer_dump(rt_list_t timer_heads[]) * @brief This function will initialize a timer * normally this function is used to initialize a static timer object. * - * @param timer The static timer object + * @param timer is the point of timer * - * @param name The name of timer + * @param name is a pointer to the name of the timer * - * @param timeout The timeout function + * @param timeout is the callback of timer * - * @param parameter The parameter of timeout function + * @param parameter is the param of the callback * - * @param time The tick of timer + * @param time is the ticks of timer * - * @param flag The flag of timer + * @param flag is the flag of timer */ void rt_timer_init(rt_timer_t timer, const char *name, @@ -256,9 +256,9 @@ RTM_EXPORT(rt_timer_init); /** * @brief This function will detach a timer from timer management. * - * @param timer The timer to be detached + * @param timer is the timer to be detached * - * @return rt_err_t The status of detach + * @return the status of detach */ rt_err_t rt_timer_detach(rt_timer_t timer) { @@ -289,17 +289,17 @@ RTM_EXPORT(rt_timer_detach); /** * @brief This function will create a timer * - * @param name The name of timer + * @param name the name of timer * - * @param timeout The timeout function + * @param timeout the timeout function * - * @param parameter The parameter of timeout function + * @param parameter the parameter of timeout function * - * @param time The tick of timer + * @param time the tick of timer * - * @param flag The flag of timer + * @param flag the flag of timer * - * @return The created timer object + * @return the created timer object */ rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), @@ -325,9 +325,9 @@ RTM_EXPORT(rt_timer_create); /** * @brief This function will delete a timer and release timer memory * - * @param timer The timer to be deleted + * @param timer the timer to be deleted * - * @return rt_err_t The operation status, RT_EOK on OK; RT_ERROR on error + * @return the operation status, RT_EOK on OK; RT_ERROR on error */ rt_err_t rt_timer_delete(rt_timer_t timer) { @@ -358,9 +358,9 @@ RTM_EXPORT(rt_timer_delete); /** * @brief This function will start the timer * - * @param timer The timer to be started + * @param timer the timer to be started * - * @return The operation status, RT_EOK on OK, -RT_ERROR on error + * @return the operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_start(rt_timer_t timer) { @@ -481,9 +481,9 @@ RTM_EXPORT(rt_timer_start); /** * @brief This function will stop the timer * - * @param timer The timer to be stopped + * @param timer the timer to be stopped * - * @return The operation status, RT_EOK on OK, -RT_ERROR on error + * @return the operation status, RT_EOK on OK, -RT_ERROR on error */ rt_err_t rt_timer_stop(rt_timer_t timer) { @@ -515,11 +515,11 @@ RTM_EXPORT(rt_timer_stop); /** * @brief This function will get or set some options of the timer * - * @param timer The timer to be get or set - * @param cmd The control command - * @param arg The argument + * @param timer the timer to be get or set + * @param cmd the control command + * @param arg the argument * - * @return rt_err_t the statu of control + * @return the statu of control */ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { @@ -648,7 +648,7 @@ void rt_timer_check(void) /** * @brief This function will return the next timeout tick in the system. * - * @return The next timeout tick in the system + * @return the next timeout tick in the system */ rt_tick_t rt_timer_next_timeout_tick(void) { @@ -737,7 +737,7 @@ void rt_soft_timer_check(void) /** * @brief System timer thread entry * - * @param parameter The arg of the thread + * @param parameter is the arg of the thread */ static void _timer_thread_entry(void *parameter) { -- cgit v1.3.1 From 75b65ebcf2d2261bcd5cf762cc8aa8452e78b8d1 Mon Sep 17 00:00:00 2001 From: WillianChan Date: Tue, 31 Aug 2021 10:39:44 +0800 Subject: [fix][kernel][timer]fixed timer ASSERT exception due to multithreaded scheduling Signed-off-by: WillianChan --- src/timer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index da52a02fc8..25ba175306 100644 --- a/src/timer.c +++ b/src/timer.c @@ -367,6 +367,7 @@ rt_err_t rt_timer_start(rt_timer_t timer) unsigned int row_lvl; rt_list_t *timer_list; register rt_base_t level; + register rt_bool_t need_schedule; rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL]; unsigned int tst_nr; static unsigned int random_nr; @@ -375,6 +376,8 @@ rt_err_t rt_timer_start(rt_timer_t timer) RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); + need_schedule = RT_FALSE; + /* stop timer firstly */ level = rt_hw_interrupt_disable(); /* remove timer from list */ @@ -457,9 +460,6 @@ rt_err_t rt_timer_start(rt_timer_t timer) timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED; - /* enable interrupt */ - rt_hw_interrupt_enable(level); - #ifdef RT_USING_TIMER_SOFT if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { @@ -469,11 +469,19 @@ rt_err_t rt_timer_start(rt_timer_t timer) { /* resume timer thread to check soft timer */ rt_thread_resume(&_timer_thread); - rt_schedule(); + need_schedule = RT_TRUE; } } #endif /* RT_USING_TIMER_SOFT */ + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + if (need_schedule) + { + rt_schedule(); + } + return RT_EOK; } RTM_EXPORT(rt_timer_start); -- cgit v1.3.1