|
atmega16做的,里面很多链表,看不懂,以前从来没有见过,大神们指点指点
随便贴个函数:
-----------------------------------------------timer.h----------------------------------------------------------
#define TIMER_COUNT_INIT (256-(((unsigned long long)SYSTEM_OSC)/1000/256))
struct timer_list{
struct list_head list;
void (*timer_cb)(void *);
void *param_cb;
u16 status;
u16 expires;
};
enum{
TIMER_STATUS_IDLE,
TIMER_STATUS_ACTIVE,
TIMER_STATUS_UNKNOW
};
extern void timer_init(void);
extern u32 jiffies;
extern int timer_register(struct timer_list *timer);
extern int timer_unregister(struct timer_list *timer);
extern int timer_mod(struct timer_list *timer,unsigned int expires);
#endif
---------------------------------timer.c-----------------------------------------------------------------------
#pragma interrupt_handler timer0_overflow_interrupt:iv_TIMER0_OVF
static LIST_HEAD(g_timer_head);
u32 jiffies=0;
void timer0_overflow_interrupt(void)
{
struct timer_list *t;
struct list_head *pos;
jiffies++;
list_for_each(pos, &g_timer_head)
{
t=list_entry(pos,struct timer_list,list);
/*
if(t->status!=TIMER_STATUS_ACTIVE)
continue;
if(t->expires<jiffies)
continue;
t->status=TIMER_STATUS_IDLE;
*/
if(!t->timer_cb)
continue;
t->timer_cb(t->param_cb);
}
TCNT0=TIMER_COUNT_INIT;
}
int timer_register(struct timer_list *timer)
{
system_interrupt_disable();
list_add_tail(&timer->list,&g_timer_head);
system_interrupt_enable();
return 0;
}
int timer_unregister(struct timer_list *timer)
{
system_interrupt_disable();
list_del(&timer->list);
system_interrupt_enable();
return 0;
}
/*
int timer_mod(struct timer_list *timer,unsigned int expires)
{
timer->expires=expires;
timer->status=TIMER_STATUS_ACTIVE;
return 0;
}
*/
void timer_init(void)
{
TCNT0=TIMER_COUNT_INIT;
TCCR0=(1<<CS02)/*|(1<<CS00)*/;
TIMSK=(1<<TOIE0);
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!
|