summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2022-01-16 14:33:41 -0500
committerBernard Xiong <[email protected]>2022-01-20 20:58:46 +0800
commit1874bd25aae647d116dac36a17d3bc79850e200b (patch)
treeeb7eb09e8d360aeb20980412b3416a5a51736522 /src
parent65ecca80ee7b3e63998d2207f28fdc8847169eb3 (diff)
[timer] improve parameter checking
Diffstat (limited to 'src')
-rw-r--r--src/timer.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/timer.c b/src/timer.c
index 577dd5ae47..63cbcf9e07 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -246,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,
@@ -259,6 +262,8 @@ void rt_timer_init(rt_timer_t timer,
{
/* parameter check */
RT_ASSERT(timer != RT_NULL);
+ RT_ASSERT(timeout != RT_NULL);
+ RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
/* timer object initialization */
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
@@ -303,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
*/
@@ -323,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(timer->init_tick < RT_TICK_MAX / 2);
+
/* allocate a object */
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
if (timer == RT_NULL)
@@ -401,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