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:
parent
bcb37f6d17
commit
1133895d2c
|
@ -64,6 +64,8 @@ void rt_tick_increase(void);
|
|||
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms);
|
||||
|
||||
void rt_system_timer_init(void);
|
||||
void rt_system_timer_thread_init(void);
|
||||
|
||||
void rt_timer_init(rt_timer_t timer,
|
||||
const char* name,
|
||||
void (*timeout)(void* parameter), void* parameter,
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#endif
|
||||
|
||||
#define NO_SYS 0
|
||||
#define LWIP_SOCKET (NO_SYS==0)
|
||||
#define LWIP_NETCONN (NO_SYS==0)
|
||||
#define LWIP_SOCKET 1
|
||||
#define LWIP_NETCONN 1
|
||||
|
||||
#ifdef RT_LWIP_IGMP
|
||||
#define LWIP_IGMP 1
|
||||
|
@ -40,15 +40,15 @@
|
|||
#define LWIP_PLATFORM_BYTESWAP 0
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
|
||||
/* Enable SO_RCVTIMEO processing. */
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
|
||||
/* #define RT_LWIP_DEBUG */
|
||||
|
||||
#ifdef RT_LWIP_DEBUG
|
||||
#define LWIP_DEBUG
|
||||
#endif
|
||||
|
||||
/* Enable SO_RCVTIMEO processing. */
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
|
||||
/* ---------- Debug options ---------- */
|
||||
#ifdef LWIP_DEBUG
|
||||
#define SYS_DEBUG LWIP_DBG_OFF
|
||||
|
|
122
src/timer.c
122
src/timer.c
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* 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:
|
||||
* Date Author Notes
|
||||
|
@ -22,13 +22,15 @@
|
|||
|
||||
#include "kservice.h"
|
||||
|
||||
/* #define TIMER_DEBUG */
|
||||
/* #define RT_TIMER_DEBUG */
|
||||
|
||||
/* hard timer list */
|
||||
static rt_list_t rt_timer_list;
|
||||
|
||||
#ifdef RT_USING_TIMER_SOFT
|
||||
/* soft timer list */
|
||||
static rt_list_t rt_soft_timer_list;
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_HOOK
|
||||
extern void (*rt_object_take_hook)(struct rt_object* object);
|
||||
|
@ -54,18 +56,6 @@ void rt_timer_timeout_sethook(void (*hook)(struct rt_timer* timer))
|
|||
/*@}*/
|
||||
#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,
|
||||
void (*timeout)(void* parameter), void* parameter,
|
||||
rt_tick_t time, rt_uint8_t flag)
|
||||
|
@ -228,8 +218,10 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
|||
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
#ifdef RT_USING_TIMER_SOFT
|
||||
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)
|
||||
{
|
||||
t = rt_list_entry(n, struct rt_timer, list);
|
||||
|
@ -246,7 +238,8 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
|||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
@ -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.
|
||||
*
|
||||
*/
|
||||
void rt_soft_timer_tick_hook (void);
|
||||
void rt_timer_check()
|
||||
{
|
||||
rt_tick_t current_tick;
|
||||
|
@ -358,7 +350,7 @@ void rt_timer_check()
|
|||
struct rt_timer *t;
|
||||
register rt_base_t level;
|
||||
|
||||
#ifdef TIMER_DEBUG
|
||||
#ifdef RT_TIMER_DEBUG
|
||||
rt_kprintf("timer check enter\n");
|
||||
#endif
|
||||
|
||||
|
@ -387,7 +379,7 @@ void rt_timer_check()
|
|||
/* reget tick */
|
||||
current_tick = rt_tick_get();
|
||||
|
||||
#ifdef TIMER_DEBUG
|
||||
#ifdef RT_TIMER_DEBUG
|
||||
rt_kprintf("current tick: %d\n", current_tick);
|
||||
#endif
|
||||
|
||||
|
@ -410,50 +402,26 @@ void rt_timer_check()
|
|||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
/**/
|
||||
rt_soft_timer_tick_hook ( );
|
||||
|
||||
#ifdef TIMER_DEBUG
|
||||
#ifdef RT_TIMER_DEBUG
|
||||
rt_kprintf("timer check leave\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static struct rt_thread soft_timer_thread;
|
||||
static rt_uint8_t rt_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
|
||||
#ifdef RT_USING_TIMER_SOFT
|
||||
static struct rt_thread timer_thread;
|
||||
static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
|
||||
static struct rt_semaphore timer_sem;
|
||||
|
||||
static rt_uint16_t timer_ex_cnt;
|
||||
|
||||
|
||||
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()
|
||||
/* check software timer list. if a timeout event happens, the corresponding
|
||||
timeout function will be invoked. */
|
||||
static void rt_soft_timer_check()
|
||||
{
|
||||
rt_tick_t current_tick;
|
||||
rt_list_t *n;
|
||||
struct rt_timer *t;
|
||||
|
||||
#ifdef TIMER_DEBUG
|
||||
rt_kprintf("timer check enter\n");
|
||||
#ifdef RT_TIMER_DEBUG
|
||||
rt_kprintf("software timer check enter\n");
|
||||
#endif
|
||||
|
||||
current_tick = rt_tick_get();
|
||||
|
@ -478,7 +446,7 @@ void rt_soft_timer_check()
|
|||
/* reget tick */
|
||||
current_tick = rt_tick_get();
|
||||
|
||||
#ifdef TIMER_DEBUG
|
||||
#ifdef RT_TIMER_DEBUG
|
||||
rt_kprintf("current tick: %d\n", current_tick);
|
||||
#endif
|
||||
|
||||
|
@ -497,26 +465,49 @@ void rt_soft_timer_check()
|
|||
}
|
||||
else break;
|
||||
}
|
||||
#ifdef TIMER_DEBUG
|
||||
rt_kprintf("timer check leave\n");
|
||||
|
||||
#ifdef RT_TIMER_DEBUG
|
||||
rt_kprintf("software timer check leave\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* system timer thread entry */
|
||||
static void rt_thread_timer_entry(void* parameter)
|
||||
{
|
||||
(void)parameter;
|
||||
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_soft_timer_check( );
|
||||
/* check software timer */
|
||||
rt_soft_timer_check();
|
||||
|
||||
/* unlock scheduler */
|
||||
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
|
||||
|
@ -524,18 +515,19 @@ static void rt_thread_timer_entry(void* parameter)
|
|||
* 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);
|
||||
timer_ex_cnt = 0;
|
||||
/*init timer_ex thread*/
|
||||
rt_thread_init(&soft_timer_thread,
|
||||
#ifdef RT_USING_TIMER_SOFT
|
||||
/* start software timer thread */
|
||||
rt_thread_init(&timer_thread,
|
||||
"timer",
|
||||
rt_thread_timer_entry, RT_NULL,
|
||||
&rt_thread_stack[0], sizeof(rt_thread_stack),
|
||||
&timer_thread_stack[0], sizeof(timer_thread_stack),
|
||||
RT_TIMER_THREAD_PRIO, 10);
|
||||
|
||||
/* startup */
|
||||
rt_thread_startup(&soft_timer_thread);
|
||||
rt_thread_startup(&timer_thread);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
|
Loading…
Reference in New Issue