[timer] improve parameter checking
This commit is contained in:
parent
65ecca80ee
commit
1874bd25aa
|
@ -98,7 +98,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
|
|||
/* remove list */
|
||||
rt_list_remove(&(work->list));
|
||||
work->flags &= ~RT_WORK_STATE_PENDING;
|
||||
/* */
|
||||
|
||||
if (ticks == 0)
|
||||
{
|
||||
if (queue->work_current != work)
|
||||
|
@ -288,6 +288,7 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work)
|
|||
* @param queue A pointer to the workqueue object.
|
||||
* @param work A pointer to the work item object.
|
||||
* @param time The delay time (unit: OS ticks) for the work item to be submitted to the work queue.
|
||||
* The max timeout tick should be no more than (RT_TICK_MAX/2 - 1)
|
||||
*
|
||||
* @return RT_EOK Success.
|
||||
* @return -RT_EBUSY This work item is executing.
|
||||
|
|
28
src/timer.c
28
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
|
||||
|
|
Loading…
Reference in New Issue