* @brief This function will start the timer * * @param timer the timer to be started * * @return the operation status, RT_EOK on OK, -RT_ERROR on error */
| 560 | * @return the operation status, RT_EOK on OK, -RT_ERROR on error |
| 561 | */ |
| 562 | rt_err_t rt_timer_start(rt_timer_t timer) |
| 563 | { |
| 564 | rt_sched_lock_level_t slvl; |
| 565 | int is_thread_timer = 0; |
| 566 | struct rt_spinlock *spinlock; |
| 567 | rt_list_t *timer_list; |
| 568 | rt_base_t level; |
| 569 | rt_err_t err; |
| 570 | |
| 571 | /* parameter check */ |
| 572 | RT_ASSERT(timer != RT_NULL); |
| 573 | RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); |
| 574 | |
| 575 | #ifdef RT_USING_TIMER_ALL_SOFT |
| 576 | timer_list = _soft_timer_list; |
| 577 | spinlock = &_stimer_lock; |
| 578 | #else |
| 579 | #ifdef RT_USING_TIMER_SOFT |
| 580 | if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) |
| 581 | { |
| 582 | timer_list = _soft_timer_list; |
| 583 | spinlock = &_stimer_lock; |
| 584 | } |
| 585 | else |
| 586 | #endif /* RT_USING_TIMER_SOFT */ |
| 587 | { |
| 588 | timer_list = _timer_list; |
| 589 | spinlock = &_htimer_lock; |
| 590 | } |
| 591 | #endif |
| 592 | |
| 593 | if (timer->parent.flag & RT_TIMER_FLAG_THREAD_TIMER) |
| 594 | { |
| 595 | rt_thread_t thread; |
| 596 | is_thread_timer = 1; |
| 597 | rt_sched_lock(&slvl); |
| 598 | |
| 599 | thread = rt_container_of(timer, struct rt_thread, thread_timer); |
| 600 | RT_ASSERT(rt_object_get_type(&thread->parent) == RT_Object_Class_Thread); |
| 601 | rt_sched_thread_timer_start(thread); |
| 602 | } |
| 603 | |
| 604 | level = rt_spin_lock_irqsave(spinlock); |
| 605 | |
| 606 | err = _timer_start(timer_list, timer); |
| 607 | |
| 608 | rt_spin_unlock_irqrestore(spinlock, level); |
| 609 | |
| 610 | if (is_thread_timer) |
| 611 | { |
| 612 | rt_sched_unlock(slvl); |
| 613 | } |
| 614 | |
| 615 | return err; |
| 616 | } |
| 617 | RTM_EXPORT(rt_timer_start); |
| 618 | |
| 619 | /** |