?? timer.c
字號(hào):
//-----------------------------------------------------------------------------
// Net TIMER.C
//
// This module sets up the timer and handles the timer interrupt
//-----------------------------------------------------------------------------
#include "net.h"
#include "timer.h"
#include "general.h"
#include <avr/signal.h>
extern unsigned char CONTROL_L;
extern unsigned int event_word;
extern unsigned long initial_sequence_nr;
#define Timer0V (unsigned char)(256-F_CPU/32/1000)
static unsigned char Count1ms = 0;
void Timer0_Init (void)
{
TCNT0 = Timer0V;//148;/* reset TCNT0 for 1ms */
TCCR0 = 3; /* count with clk of F_CPU/32 */
TIMSK = 1<<TOIE0; /* enable TCNT0 overflow interrupt*/
}
//1ms timer
SIGNAL(SIG_OVERFLOW0)
{
static unsigned char Count25ms = 25;
static unsigned char Count1s = 40;
static unsigned int count1 = 0;
static unsigned int count2 = 0;
TCNT0 = Timer0V; /* reset counter to get this interrupt again */
if(Count1ms)Count1ms--;
if (Count25ms) Count25ms--;
else
{
Count25ms=25; //25ms
RunOff;
if (Count1s) Count1s--;
else
{
Count1s=40; //1s, run led invert
if(CONTROL_L)RunOn;
}
// Advance the initial sequence number
initial_sequence_nr += 6250;
// Keep it some distance from rolling over
if (initial_sequence_nr & 0x10000000L) initial_sequence_nr = 1;
count1++;
// These events happens every 0.50 seconds, not simultaneously
if (count1 == 5) event_word |= EVENT_ARP_RETRANSMIT;
if (count1 == 10) event_word |= EVENT_TCP_INACTIVITY;
if (count1 == 15) event_word |= EVENT_READ_ANALOG;
if (count1 == 20)
{
count1 = 0;
event_word |= EVENT_TCP_RETRANSMIT;
}
count2++;
if (count2 == 2401)
{
// This happens every 60.025 seconds, not simultaneous
// with above tasks
count2 = 0;
event_word |= EVENT_AGE_ARP_CACHE;
}
}
}
void Delay1ms(unsigned char T)
{
Count1ms=T;
while (Count1ms);
}
int swapint(int k)
{
return (((k>>8)&0x00ff)+((k<<8)&0xff00));
}
long swaplong(long k)
{
return ((swapint(k>>16)&0x0000ffff)+(((ULONG)swapint(k)<<16)&0xffff0000));
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -