* @brief This function will stop the timer * * @param timer the timer to be stopped * * @return the operation status, RT_EOK on OK, -RT_ERROR on error */
| 624 | * @return the operation status, RT_EOK on OK, -RT_ERROR on error |
| 625 | */ |
| 626 | rt_err_t rt_timer_stop(rt_timer_t timer) |
| 627 | { |
| 628 | rt_base_t level; |
| 629 | struct rt_spinlock *spinlock; |
| 630 | |
| 631 | /* timer check */ |
| 632 | RT_ASSERT(timer != RT_NULL); |
| 633 | RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); |
| 634 | |
| 635 | spinlock = _timerlock_idx(timer); |
| 636 | |
| 637 | level = rt_spin_lock_irqsave(spinlock); |
| 638 | |
| 639 | if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) |
| 640 | { |
| 641 | rt_spin_unlock_irqrestore(spinlock, level); |
| 642 | return -RT_ERROR; |
| 643 | } |
| 644 | RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent))); |
| 645 | |
| 646 | _timer_remove(timer); |
| 647 | /* change status */ |
| 648 | timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; |
| 649 | |
| 650 | rt_spin_unlock_irqrestore(spinlock, level); |
| 651 | |
| 652 | return RT_EOK; |
| 653 | } |
| 654 | RTM_EXPORT(rt_timer_stop); |
| 655 | |
| 656 | /** |