remove the software timer check in tick handle.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@219 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2009-12-23 13:52:42 +00:00
parent bcb37f6d17
commit 1133895d2c
3 changed files with 110 additions and 116 deletions

View File

@ -64,6 +64,8 @@ void rt_tick_increase(void);
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms); rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms);
void rt_system_timer_init(void); void rt_system_timer_init(void);
void rt_system_timer_thread_init(void);
void rt_timer_init(rt_timer_t timer, void rt_timer_init(rt_timer_t timer,
const char* name, const char* name,
void (*timeout)(void* parameter), void* parameter, void (*timeout)(void* parameter), void* parameter,

View File

@ -8,8 +8,8 @@
#endif #endif
#define NO_SYS 0 #define NO_SYS 0
#define LWIP_SOCKET (NO_SYS==0) #define LWIP_SOCKET 1
#define LWIP_NETCONN (NO_SYS==0) #define LWIP_NETCONN 1
#ifdef RT_LWIP_IGMP #ifdef RT_LWIP_IGMP
#define LWIP_IGMP 1 #define LWIP_IGMP 1
@ -40,15 +40,15 @@
#define LWIP_PLATFORM_BYTESWAP 0 #define LWIP_PLATFORM_BYTESWAP 0
#define BYTE_ORDER LITTLE_ENDIAN #define BYTE_ORDER LITTLE_ENDIAN
/* Enable SO_RCVTIMEO processing. */
#define LWIP_SO_RCVTIMEO 1
/* #define RT_LWIP_DEBUG */ /* #define RT_LWIP_DEBUG */
#ifdef RT_LWIP_DEBUG #ifdef RT_LWIP_DEBUG
#define LWIP_DEBUG #define LWIP_DEBUG
#endif #endif
/* Enable SO_RCVTIMEO processing. */
#define LWIP_SO_RCVTIMEO 1
/* ---------- Debug options ---------- */ /* ---------- Debug options ---------- */
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
#define SYS_DEBUG LWIP_DBG_OFF #define SYS_DEBUG LWIP_DBG_OFF

View File

@ -5,7 +5,7 @@
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
* http://openlab.rt-thread.com/license/LICENSE * http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
@ -22,13 +22,15 @@
#include "kservice.h" #include "kservice.h"
/* #define TIMER_DEBUG */ /* #define RT_TIMER_DEBUG */
/* hard timer list */ /* hard timer list */
static rt_list_t rt_timer_list; static rt_list_t rt_timer_list;
#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;
#endif
#ifdef RT_USING_HOOK #ifdef RT_USING_HOOK
extern void (*rt_object_take_hook)(struct rt_object* object); extern void (*rt_object_take_hook)(struct rt_object* object);
@ -54,21 +56,9 @@ void rt_timer_timeout_sethook(void (*hook)(struct rt_timer* timer))
/*@}*/ /*@}*/
#endif #endif
/**
* @ingroup SystemInit
*
* This function will init system timer
*
*/
void rt_system_timer_init()
{
rt_list_init(&rt_timer_list);
rt_list_init(&rt_soft_timer_list);
}
static void _rt_timer_init(rt_timer_t timer, static void _rt_timer_init(rt_timer_t timer,
void (*timeout)(void* parameter), void* parameter, void (*timeout)(void* parameter), void* parameter,
rt_tick_t time, rt_uint8_t flag) rt_tick_t time, rt_uint8_t flag)
{ {
/* set flag */ /* set flag */
timer->parent.flag = flag; timer->parent.flag = flag;
@ -103,9 +93,9 @@ static void _rt_timer_init(rt_timer_t timer,
* @param flag the flag of timer * @param flag the flag of timer
*/ */
void rt_timer_init(rt_timer_t timer, void rt_timer_init(rt_timer_t timer,
const char* name, const char* name,
void (*timeout)(void* parameter), void* parameter, void (*timeout)(void* parameter), void* parameter,
rt_tick_t time, rt_uint8_t flag) rt_tick_t time, rt_uint8_t flag)
{ {
/* timer check */ /* timer check */
RT_ASSERT(timer != RT_NULL); RT_ASSERT(timer != RT_NULL);
@ -228,8 +218,10 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* disable interrupt */ /* disable interrupt */
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
#ifdef RT_USING_TIMER_SOFT
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
{/* insert timer to soft timer list */ {
/* insert timer to soft timer list */
for (n = rt_soft_timer_list.next; n != &rt_soft_timer_list; n = n->next) for (n = rt_soft_timer_list.next; n != &rt_soft_timer_list; n = n->next)
{ {
t = rt_list_entry(n, struct rt_timer, list); t = rt_list_entry(n, struct rt_timer, list);
@ -246,25 +238,26 @@ rt_err_t rt_timer_start(rt_timer_t timer)
} }
} }
else else
{/* insert timer to system timer list */ #endif
/* insert timer to system timer list */
for (n = rt_timer_list.next; n != &rt_timer_list; n = n->next)
{ {
t = rt_list_entry(n, struct rt_timer, list); /* insert timer to system timer list */
if (t->timeout_tick > timer->timeout_tick) for (n = rt_timer_list.next; n != &rt_timer_list; n = n->next)
{
t = rt_list_entry(n, struct rt_timer, list);
if (t->timeout_tick > timer->timeout_tick)
{
rt_list_insert_before(n, &(timer->list));
break;
}
}
/* no found suitable position in timer list */
if (n == &rt_timer_list)
{ {
rt_list_insert_before(n, &(timer->list)); rt_list_insert_before(n, &(timer->list));
break;
} }
} }
/* no found suitable position in timer list */
if (n == &rt_timer_list)
{
rt_list_insert_before(n, &(timer->list));
}
}
timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED; timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED;
/* enable interrupt */ /* enable interrupt */
@ -350,7 +343,6 @@ rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void* arg)
* corresponding timeout function will be invoked. * corresponding timeout function will be invoked.
* *
*/ */
void rt_soft_timer_tick_hook (void);
void rt_timer_check() void rt_timer_check()
{ {
rt_tick_t current_tick; rt_tick_t current_tick;
@ -358,7 +350,7 @@ void rt_timer_check()
struct rt_timer *t; struct rt_timer *t;
register rt_base_t level; register rt_base_t level;
#ifdef TIMER_DEBUG #ifdef RT_TIMER_DEBUG
rt_kprintf("timer check enter\n"); rt_kprintf("timer check enter\n");
#endif #endif
@ -387,12 +379,12 @@ void rt_timer_check()
/* reget tick */ /* reget tick */
current_tick = rt_tick_get(); current_tick = rt_tick_get();
#ifdef TIMER_DEBUG #ifdef RT_TIMER_DEBUG
rt_kprintf("current tick: %d\n", current_tick); rt_kprintf("current tick: %d\n", current_tick);
#endif #endif
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
{ {
/* start it */ /* start it */
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@ -410,50 +402,26 @@ void rt_timer_check()
/* enable interrupt */ /* enable interrupt */
rt_hw_interrupt_enable(level); rt_hw_interrupt_enable(level);
/**/ #ifdef RT_TIMER_DEBUG
rt_soft_timer_tick_hook ( );
#ifdef TIMER_DEBUG
rt_kprintf("timer check leave\n"); rt_kprintf("timer check leave\n");
#endif #endif
} }
#ifdef RT_USING_TIMER_SOFT
static struct rt_thread soft_timer_thread; static struct rt_thread timer_thread;
static rt_uint8_t rt_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
static struct rt_semaphore timer_sem; static struct rt_semaphore timer_sem;
static rt_uint16_t timer_ex_cnt; /* check software timer list. if a timeout event happens, the corresponding
timeout function will be invoked. */
static void rt_soft_timer_check()
rt_err_t timer_signal (void)
{
return rt_sem_release(&timer_sem);
}
void rt_soft_timer_tick_hook (void)
{
timer_ex_cnt++;
if (timer_ex_cnt >= (RT_TICK_PER_SECOND / RT_TIMER_EX_TICKS_PER_SEC))
{
timer_ex_cnt = 0;
timer_signal();
}
}
/**
* This function will check timer list, if a timeout event happens, the
* corresponding timeout function will be invoked.
*
*/
void rt_soft_timer_check()
{ {
rt_tick_t current_tick; rt_tick_t current_tick;
rt_list_t *n; rt_list_t *n;
struct rt_timer *t; struct rt_timer *t;
#ifdef TIMER_DEBUG #ifdef RT_TIMER_DEBUG
rt_kprintf("timer check enter\n"); rt_kprintf("software timer check enter\n");
#endif #endif
current_tick = rt_tick_get(); current_tick = rt_tick_get();
@ -478,12 +446,12 @@ void rt_soft_timer_check()
/* reget tick */ /* reget tick */
current_tick = rt_tick_get(); current_tick = rt_tick_get();
#ifdef TIMER_DEBUG #ifdef RT_TIMER_DEBUG
rt_kprintf("current tick: %d\n", current_tick); rt_kprintf("current tick: %d\n", current_tick);
#endif #endif
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
{ {
/* start it */ /* start it */
t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
@ -497,26 +465,49 @@ void rt_soft_timer_check()
} }
else break; else break;
} }
#ifdef TIMER_DEBUG
rt_kprintf("timer check leave\n"); #ifdef RT_TIMER_DEBUG
rt_kprintf("software timer check leave\n");
#endif #endif
} }
/* system timer thread entry */
static void rt_thread_timer_entry(void* parameter) static void rt_thread_timer_entry(void* parameter)
{ {
(void)parameter;
while (1) while (1)
{ {
rt_sem_take(&timer_sem,RT_WAITING_FOREVER); /* take the semaphore as software timer tick */
rt_sem_take(&timer_sem, RT_TICK_PER_SECOND / RT_TIMER_TICK_PER_SECOND);
/* reach here because thread takes semaphore timeout */
/* lock scheduler */
rt_enter_critical(); rt_enter_critical();
rt_soft_timer_check( ); /* check software timer */
rt_soft_timer_check();
/* unlock scheduler */
rt_exit_critical(); rt_exit_critical();
} }
} }
#endif
/**
* @ingroup SystemInit
*
* This function will init system timer
*
*/
void rt_system_timer_init()
{
rt_list_init(&rt_timer_list);
#ifdef RT_USING_TIMER_SOFT
rt_list_init(&rt_soft_timer_list);
rt_sem_init(&timer_sem, "timer", 0, RT_IPC_FLAG_FIFO);
#endif
}
/** /**
* @ingroup SystemInit * @ingroup SystemInit
@ -524,18 +515,19 @@ static void rt_thread_timer_entry(void* parameter)
* This function will init system timer thread * This function will init system timer thread
* *
*/ */
void rt_timer_thread_init(void) void rt_system_timer_thread_init()
{ {
rt_sem_init(&timer_sem, "timer", 1, RT_IPC_FLAG_FIFO); #ifdef RT_USING_TIMER_SOFT
timer_ex_cnt = 0; /* start software timer thread */
/*init timer_ex thread*/ rt_thread_init(&timer_thread,
rt_thread_init(&soft_timer_thread, "timer",
"timer", rt_thread_timer_entry, RT_NULL,
rt_thread_timer_entry, RT_NULL, &timer_thread_stack[0], sizeof(timer_thread_stack),
&rt_thread_stack[0], sizeof(rt_thread_stack), RT_TIMER_THREAD_PRIO, 10);
RT_TIMER_THREAD_PRIO, 10);
/* startup */ /* startup */
rt_thread_startup(&soft_timer_thread); rt_thread_startup(&timer_thread);
#endif
} }
/*@}*/ /*@}*/