[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 */
|
/* remove list */
|
||||||
rt_list_remove(&(work->list));
|
rt_list_remove(&(work->list));
|
||||||
work->flags &= ~RT_WORK_STATE_PENDING;
|
work->flags &= ~RT_WORK_STATE_PENDING;
|
||||||
/* */
|
|
||||||
if (ticks == 0)
|
if (ticks == 0)
|
||||||
{
|
{
|
||||||
if (queue->work_current != work)
|
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 queue A pointer to the workqueue object.
|
||||||
* @param work A pointer to the work item 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.
|
* @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_EOK Success.
|
||||||
* @return -RT_EBUSY This work item is executing.
|
* @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 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
|
* @param flag is the flag of timer
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
void rt_timer_init(rt_timer_t timer,
|
void rt_timer_init(rt_timer_t timer,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
@ -259,6 +262,8 @@ void rt_timer_init(rt_timer_t timer,
|
||||||
{
|
{
|
||||||
/* parameter check */
|
/* parameter check */
|
||||||
RT_ASSERT(timer != RT_NULL);
|
RT_ASSERT(timer != RT_NULL);
|
||||||
|
RT_ASSERT(timeout != RT_NULL);
|
||||||
|
RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
|
||||||
|
|
||||||
/* timer object initialization */
|
/* timer object initialization */
|
||||||
rt_object_init(&(timer->parent), RT_Object_Class_Timer, name);
|
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
|
* @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
|
* @return the created timer object
|
||||||
*/
|
*/
|
||||||
|
@ -323,6 +330,10 @@ rt_timer_t rt_timer_create(const char *name,
|
||||||
{
|
{
|
||||||
struct rt_timer *timer;
|
struct rt_timer *timer;
|
||||||
|
|
||||||
|
/* parameter check */
|
||||||
|
RT_ASSERT(timeout != RT_NULL);
|
||||||
|
RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2);
|
||||||
|
|
||||||
/* allocate a object */
|
/* allocate a object */
|
||||||
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
|
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
|
||||||
if (timer == RT_NULL)
|
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)));
|
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;
|
timer->timeout_tick = rt_tick_get() + timer->init_tick;
|
||||||
|
|
||||||
#ifdef RT_USING_TIMER_SOFT
|
#ifdef RT_USING_TIMER_SOFT
|
||||||
|
|
Loading…
Reference in New Issue