4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-31 02:50:26 +08:00

remove soft timer tick increase

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2108 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2012-05-05 01:45:17 +00:00
parent e01d425bf3
commit b14044212b
3 changed files with 350 additions and 335 deletions

View File

@ -59,10 +59,9 @@ rt_tick_t rt_tick_get(void)
void rt_tick_set(rt_tick_t tick) void rt_tick_set(rt_tick_t tick)
{ {
rt_base_t level; rt_base_t level;
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
rt_tick = tick; rt_tick = tick;
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
} }

View File

@ -28,6 +28,9 @@ static rt_list_t rt_timer_list = RT_LIST_OBJECT_INIT(rt_timer_list);
#ifdef RT_USING_TIMER_SOFT #ifdef RT_USING_TIMER_SOFT
/* soft timer list */ /* soft timer list */
static rt_list_t rt_soft_timer_list; static rt_list_t rt_soft_timer_list;
static struct rt_thread timer_thread;
ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
#endif #endif
#ifdef RT_USING_HOOK #ifdef RT_USING_HOOK
@ -75,6 +78,15 @@ static void _rt_timer_init(rt_timer_t timer,
rt_list_init(&(timer->list)); rt_list_init(&(timer->list));
} }
static rt_tick_t rt_timer_list_next_timeout(rt_list_t* timer_list)
{
struct rt_timer* timer;
if (rt_list_isempty(timer_list)) return RT_TICK_MAX;
timer = rt_list_entry(timer_list->next, struct rt_timer, list);
return timer->timeout_tick;
}
/** /**
* @addtogroup Clock * @addtogroup Clock
*/ */
@ -211,13 +223,13 @@ 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)));
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* get timeout tick, the max timeout tick shall not great than RT_TICK_MAX/2 */ /* get timeout tick, the max timeout tick shall not great than RT_TICK_MAX/2 */
RT_ASSERT(timer->init_tick < 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;
/* disable interrupt */
level = rt_hw_interrupt_disable();
#ifdef RT_USING_TIMER_SOFT #ifdef RT_USING_TIMER_SOFT
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
{ {
@ -255,6 +267,19 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
#ifdef RT_USING_TIMER_SOFT
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
{
/* check whether timer thread is ready */
if (timer_thread.stat != RT_THREAD_READY)
{
/* resume timer thread to check soft timer */
rt_thread_resume(&timer_thread);
rt_schedule();
}
}
#endif
return -RT_EOK; return -RT_EOK;
} }
@ -279,15 +304,15 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
/* disable interrupt */ /* disable interrupt */
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
/* change stat */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
/* remove it from timer list */ /* remove it from timer list */
rt_list_remove(&(timer->list)); rt_list_remove(&(timer->list));
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
/* change stat */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
return RT_EOK; return RT_EOK;
} }
@ -333,9 +358,6 @@ rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void *arg)
* *
* @note this function shall be invoked in operating system timer interrupt. * @note this function shall be invoked in operating system timer interrupt.
*/ */
#ifdef RT_USING_TIMER_SOFT
void rt_soft_timer_tick_increase(void);
#endif
void rt_timer_check(void) void rt_timer_check(void)
{ {
struct rt_timer *t; struct rt_timer *t;
@ -391,32 +413,20 @@ void rt_timer_check(void)
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
/* increase soft timer tick */
#ifdef RT_USING_TIMER_SOFT
rt_soft_timer_tick_increase();
#endif
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n")); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n"));
} }
#ifdef RT_USING_TIMER_SOFT /**
static struct rt_thread timer_thread; * This function will return the next timeout tick in the system.
ALIGN(RT_ALIGN_SIZE) *
static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; * @return the next timeout tick in the system
static struct rt_semaphore timer_sem; */
rt_tick_t rt_timer_next_timeout_tick(void)
static rt_uint16_t timer_ex_cnt;
void rt_soft_timer_tick_increase(void)
{ {
timer_ex_cnt ++; return rt_timer_list_next_timeout(&rt_timer_list);
if (timer_ex_cnt >= (RT_TICK_PER_SECOND / RT_TIMER_TICK_PER_SECOND))
{
timer_ex_cnt = 0;
rt_sem_release(&timer_sem);
}
} }
#ifdef RT_USING_TIMER_SOFT
/** /**
* This function will check timer list, if a timeout event happens, the * This function will check timer list, if a timeout event happens, the
* corresponding timeout function will be invoked. * corresponding timeout function will be invoked.
@ -469,8 +479,7 @@ void rt_soft_timer_check(void)
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
} }
} }
else else break; /* not check anymore */
break; /* not check anymore */
} }
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n")); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
@ -479,17 +488,25 @@ void rt_soft_timer_check(void)
/* system timer thread entry */ /* system timer thread entry */
static void rt_thread_timer_entry(void *parameter) static void rt_thread_timer_entry(void *parameter)
{ {
rt_tick_t next_timeout;
while (1) while (1)
{ {
/* take software timer semaphore */ next_timeout = rt_timer_list_next_timeout(&rt_soft_timer_list);
rt_sem_take(&timer_sem, RT_WAITING_FOREVER); if (next_timeout == RT_TICK_MAX)
{
rt_thread_suspend(rt_thread_self());
rt_schedule();
}
else
{
rt_thread_delay(next_timeout);
}
/* lock scheduler */ /* lock scheduler */
rt_enter_critical(); rt_enter_critical();
/* check software timer */ /* check software timer */
rt_soft_timer_check(); rt_soft_timer_check();
/* unlock scheduler */ /* unlock scheduler */
rt_exit_critical(); rt_exit_critical();
} }
@ -517,7 +534,6 @@ void rt_system_timer_thread_init(void)
{ {
#ifdef RT_USING_TIMER_SOFT #ifdef RT_USING_TIMER_SOFT
rt_list_init(&rt_soft_timer_list); rt_list_init(&rt_soft_timer_list);
rt_sem_init(&timer_sem, "timer", 0, RT_IPC_FLAG_FIFO);
/* start software timer thread */ /* start software timer thread */
rt_thread_init(&timer_thread, rt_thread_init(&timer_thread,