summaryrefslogtreecommitdiff
path: root/src/timer.c
diff options
context:
space:
mode:
authorWayne Lin <[email protected]>2022-01-25 18:53:52 +0800
committerWayne Lin <[email protected]>2022-01-25 18:53:52 +0800
commitc95c296e9915a38a666ae1a2575c2a4d0ba1d376 (patch)
treec6e5a1ffe4ceb997e853ba0c3daffc9dc60c8b79 /src/timer.c
parentf7ba146a01fcf23a2b06a141d1b1a56cb27b878c (diff)
parent32a5668593c578b85560338c29d76f3a252c8dbc (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
# Conflicts: # bsp/gd32/gd32107c-eval/rtconfig.h
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/src/timer.c b/src/timer.c
index 846c33263b..5d54f85dbd 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -17,6 +17,7 @@
* 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
* timeout function.
* 2021-08-15 supperthomas add the comment
+ * 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to timer.c
*/
#include <rtthread.h>
@@ -47,7 +48,20 @@ ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
#endif /* RT_USING_TIMER_SOFT */
-#ifdef RT_USING_HOOK
+#ifndef __on_rt_object_take_hook
+ #define __on_rt_object_take_hook(parent) __ON_HOOK_ARGS(rt_object_take_hook, (parent))
+#endif
+#ifndef __on_rt_object_put_hook
+ #define __on_rt_object_put_hook(parent) __ON_HOOK_ARGS(rt_object_put_hook, (parent))
+#endif
+#ifndef __on_rt_timer_enter_hook
+ #define __on_rt_timer_enter_hook(t) __ON_HOOK_ARGS(rt_timer_enter_hook, (t))
+#endif
+#ifndef __on_rt_timer_exit_hook
+ #define __on_rt_timer_exit_hook(t) __ON_HOOK_ARGS(rt_timer_exit_hook, (t))
+#endif
+
+#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
extern void (*rt_object_take_hook)(struct rt_object *object);
extern void (*rt_object_put_hook)(struct rt_object *object);
static void (*rt_timer_enter_hook)(struct rt_timer *timer);
@@ -232,9 +246,12 @@ void rt_timer_dump(rt_list_t timer_heads[])
*
* @param parameter is the param of the callback
*
- * @param time is the ticks of timer
+ * @param time is timeout ticks of timer
+ *
+ * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
*
* @param flag is the flag of timer
+ *
*/
void rt_timer_init(rt_timer_t timer,
const char *name,
@@ -243,8 +260,10 @@ void rt_timer_init(rt_timer_t timer,
rt_tick_t time,
rt_uint8_t flag)
{
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
+ RT_ASSERT(timeout != RT_NULL);
+ RT_ASSERT(time < RT_TICK_MAX / 2);
/* timer object initialization */
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
@@ -264,7 +283,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
RT_ASSERT(rt_object_is_systemobject(&timer->parent));
@@ -289,15 +308,17 @@ RTM_EXPORT(rt_timer_detach);
/**
* @brief This function will create a timer
*
- * @param name the name of timer
+ * @param name is the name of timer
*
- * @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 timeout ticks of the timer
*
- * @param flag the flag of timer
+ * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
+ *
+ * @param flag is the flag of timer
*
* @return the created timer object
*/
@@ -309,6 +330,10 @@ rt_timer_t rt_timer_create(const char *name,
{
struct rt_timer *timer;
+ /* parameter check */
+ RT_ASSERT(timeout != RT_NULL);
+ RT_ASSERT(time < RT_TICK_MAX / 2);
+
/* allocate a object */
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
if (timer == RT_NULL)
@@ -333,7 +358,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
RT_ASSERT(rt_object_is_systemobject(&timer->parent) == RT_FALSE);
@@ -372,7 +397,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
unsigned int tst_nr;
static unsigned int random_nr;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
@@ -387,11 +412,6 @@ rt_err_t rt_timer_start(rt_timer_t timer)
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
- /*
- * get timeout tick,
- * the max timeout tick shall not great than RT_TICK_MAX/2
- */
- RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
timer->timeout_tick = rt_tick_get() + timer->init_tick;
#ifdef RT_USING_TIMER_SOFT
@@ -497,7 +517,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
@@ -533,7 +553,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
{
register rt_base_t level;
- /* timer check */
+ /* parameter check */
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
@@ -567,6 +587,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
/*timer is stop*/
*(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED;
}
+ case RT_TIMER_CTRL_GET_REMAIN_TIME:
+ *(rt_tick_t *)arg = timer->timeout_tick;
break;
default: