summaryrefslogtreecommitdiff
path: root/src/timer.c
diff options
context:
space:
mode:
authorSherman <[email protected]>2022-01-26 17:48:46 +0800
committerSherman <[email protected]>2022-01-26 17:48:46 +0800
commit544c721d89ee7c6e7d3f88dd5bd555a221d8222e (patch)
treeaafdd34b49eca60159844a6712883cd01fd478b7 /src/timer.c
parentfc3c29df709798bcbf0c40e4146e628975c40b9e (diff)
parent032ce63ed39c1bbb9f68068c0cf8b876771f27c8 (diff)
Merge branch 'master' of github.com:RT-Thread/rt-thread
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/timer.c b/src/timer.c
index da113298da..5d54f85dbd 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,
@@ -257,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);
@@ -278,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));
@@ -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 is the timeout function
*
- * @param timeout the timeout function
+ * @param parameter is the parameter of timeout function
*
- * @param parameter the parameter of timeout function
+ * @param time is timeout ticks of the timer
*
- * @param time the tick of timer
+ * NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
*
- * @param flag the flag of timer
+ * @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(time < RT_TICK_MAX / 2);
+
/* allocate a object */
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
if (timer == RT_NULL)
@@ -347,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);
@@ -386,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);
@@ -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
@@ -511,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);
@@ -547,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);
@@ -581,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: