From d684c21619905153eff68c43927207248925f6c2 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 12 Aug 2014 12:35:28 +0200 Subject: New U-Boot like AVR main program. Uses U-Boot source code taken from: git://git.denx.de/u-boot.git --- avr/timer.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 avr/timer.c (limited to 'avr/timer.c') diff --git a/avr/timer.c b/avr/timer.c new file mode 100644 index 0000000..84a9737 --- /dev/null +++ b/avr/timer.c @@ -0,0 +1,87 @@ +/* + */ + + +#include "common.h" + +//#include +//#include +#include +#include + +//#include + + +#include "timer.h" + +/* timer interrupt/overflow counter */ +static volatile uint32_t timestamp; + + +/*---------------------------------------------------------*/ +/* 1000Hz timer interrupt generated by OC1A */ +/*---------------------------------------------------------*/ + +ISR(TIMER1_COMPA_vect) +{ + static int_fast8_t tick_10ms; + int_fast8_t i; + + + timestamp++; + + i = tick_10ms + 1; + if (i == 10) { + i = 0; + Stat |= S_10MS_TO; + + /* Drive timer procedure of low level disk I/O module */ + //disk_timerproc(); + } + tick_10ms = i; + +} + + + +/*--------------------------------------------------------------------------*/ + +#if 0 + +void do_10ms(void) +{ + if (to_counter) + to_counter--; +} + +#endif + +/*--------------------------------------------------------------------------*/ + + +void timer_setup(void) +{ + + /* Clock */ + CLKPR = _BV(CLKPCE); + CLKPR = 0; + + /* Timer */ + + OCR1A = F_CPU / 1000 - 1; // Timer1: 1000Hz interval (OC1A) + TCCR1B = 0b00001001; + TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt +} + + +uint32_t get_timer(uint32_t base) +{ + uint32_t ret; + + ATOMIC_BLOCK(ATOMIC_FORCEON) + { + ret = timestamp; + } + return ret - base; +} + -- cgit v1.2.3