MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / rt_timer_control

Function rt_timer_control

src/timer.c:665–739  ·  view source on GitHub ↗

* @brief This function will get or set some options of the timer * * @param timer the timer to be get or set * @param cmd the control command * @param arg the argument * * @return the statu of control */

Source from the content-addressed store, hash-verified

663 * @return the statu of control
664 */
665rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
666{
667 struct rt_spinlock *spinlock;
668 rt_base_t level;
669
670 /* parameter check */
671 RT_ASSERT(timer != RT_NULL);
672 RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
673
674 spinlock = _timerlock_idx(timer);
675
676 level = rt_spin_lock_irqsave(spinlock);
677 switch (cmd)
678 {
679 case RT_TIMER_CTRL_GET_TIME:
680 *(rt_tick_t *)arg = timer->init_tick;
681 break;
682
683 case RT_TIMER_CTRL_SET_TIME:
684 RT_ASSERT((*(rt_tick_t *)arg) < RT_TICK_MAX / 2);
685 if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
686 {
687 _timer_remove(timer);
688 timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
689 }
690 timer->init_tick = *(rt_tick_t *)arg;
691 break;
692
693 case RT_TIMER_CTRL_SET_ONESHOT:
694 timer->parent.flag &= ~RT_TIMER_FLAG_PERIODIC;
695 break;
696
697 case RT_TIMER_CTRL_SET_PERIODIC:
698 timer->parent.flag |= RT_TIMER_FLAG_PERIODIC;
699 break;
700
701 case RT_TIMER_CTRL_GET_STATE:
702 if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
703 {
704 /*timer is start and run*/
705 *(rt_uint32_t *)arg = RT_TIMER_FLAG_ACTIVATED;
706 }
707 else
708 {
709 /*timer is stop*/
710 *(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED;
711 }
712 break;
713
714 case RT_TIMER_CTRL_GET_REMAIN_TIME:
715 *(rt_tick_t *)arg = timer->timeout_tick;
716 break;
717 case RT_TIMER_CTRL_GET_FUNC:
718 *(void **)arg = (void *)timer->timeout_func;
719 break;
720
721 case RT_TIMER_CTRL_SET_FUNC:
722 timer->timeout_func = (void (*)(void*))arg;

Callers 15

_do_send_recv_timeoutFunction · 0.85
sys_rt_timer_controlFunction · 0.85
rt_led_set_periodFunction · 0.85
sdhci_start_timerFunction · 0.85
rt_lptimer_controlFunction · 0.85
soft_rtc_alarm_updateFunction · 0.85
_waitq_inqueueFunction · 0.85
rt_completion_wait_flagsFunction · 0.85

Calls 5

rt_object_get_typeFunction · 0.85
_timerlock_idxFunction · 0.85
_timer_removeFunction · 0.85
rt_spin_lock_irqsaveFunction · 0.70

Tested by 2