给软件定时器增加定时器工作状态查询的功能
This commit is contained in:
parent
bad4f92451
commit
720d8479a5
|
@ -431,6 +431,7 @@ struct rt_object_information
|
||||||
#define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
|
#define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
|
||||||
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
|
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
|
||||||
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
|
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
|
||||||
|
#define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
|
||||||
|
|
||||||
#ifndef RT_TIMER_SKIP_LIST_LEVEL
|
#ifndef RT_TIMER_SKIP_LIST_LEVEL
|
||||||
#define RT_TIMER_SKIP_LIST_LEVEL 1
|
#define RT_TIMER_SKIP_LIST_LEVEL 1
|
||||||
|
|
13
src/timer.c
13
src/timer.c
|
@ -488,6 +488,19 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
|
||||||
case RT_TIMER_CTRL_SET_PERIODIC:
|
case RT_TIMER_CTRL_SET_PERIODIC:
|
||||||
timer->parent.flag |= RT_TIMER_FLAG_PERIODIC;
|
timer->parent.flag |= RT_TIMER_FLAG_PERIODIC;
|
||||||
break;
|
break;
|
||||||
|
/* zhaoshimin 20191204 add query the timer state */
|
||||||
|
case RT_TIMER_CTRL_GET_STATE:
|
||||||
|
if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
||||||
|
{
|
||||||
|
/*timer is start and run*/
|
||||||
|
*(rt_tick_t *)arg = RT_TIMER_FLAG_ACTIVATED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*timer is stop*/
|
||||||
|
*(rt_tick_t *)arg = RT_TIMER_FLAG_DEACTIVATED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
|
Loading…
Reference in New Issue