mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 23:25:54 +02:00
atusb/fw/: make timer code use interrupts instead of polling
- board_app.c (timer_poll): replaced with interrupt handler - board_app.c (__timer_read): merged polling of timer_poll into the read loop (so it works as before, provided that interrupts are disabled) - board_app.c (timer_read): run __timer_read with interrupts disabled - board_app.c (timer_init): enable timer 1 overflow interrupt - atusb.c (main): enabled global interrupts - atusb.c (main): don't call poll_timer anymore - board.h (timer_poll): removed
This commit is contained in:
parent
2acdaca218
commit
a69916da52
@ -14,6 +14,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
@ -36,8 +37,8 @@ int main(void)
|
|||||||
ep0_init();
|
ep0_init();
|
||||||
timer_init();
|
timer_init();
|
||||||
|
|
||||||
while (1) {
|
sei();
|
||||||
|
|
||||||
|
while (1)
|
||||||
usb_poll();
|
usb_poll();
|
||||||
timer_poll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ void slp_tr(void);
|
|||||||
void led(int on);
|
void led(int on);
|
||||||
void panic(void);
|
void panic(void);
|
||||||
|
|
||||||
void timer_poll(void);
|
|
||||||
uint64_t timer_read(void);
|
uint64_t timer_read(void);
|
||||||
void timer_init(void);
|
void timer_init(void);
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
#define F_CPU 8000000UL
|
#define F_CPU 8000000UL
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
@ -22,7 +23,7 @@
|
|||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
|
|
||||||
static uint32_t timer_h = 0; /* 2^(16+32) / 8 MHz = ~1.1 years */
|
static volatile uint32_t timer_h = 0; /* 2^(16+32) / 8 MHz = ~1.1 years */
|
||||||
|
|
||||||
|
|
||||||
void reset_cpu(void)
|
void reset_cpu(void)
|
||||||
@ -44,22 +45,22 @@ void slp_tr(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void timer_poll(void)
|
ISR(TIMER1_OVF_vect)
|
||||||
{
|
{
|
||||||
if (!(TIFR1 & (1 << TOV1)))
|
|
||||||
return;
|
|
||||||
TIFR1 = 1 << TOV1;
|
|
||||||
timer_h++;
|
timer_h++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t timer_read(void)
|
static uint64_t __timer_read(void)
|
||||||
{
|
{
|
||||||
uint32_t high;
|
uint32_t high;
|
||||||
uint8_t low, mid;
|
uint8_t low, mid;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
timer_poll();
|
if (TIFR1 & (1 << TOV1)) {
|
||||||
|
TIFR1 = 1 << TOV1;
|
||||||
|
timer_h++;
|
||||||
|
}
|
||||||
high = timer_h;
|
high = timer_h;
|
||||||
low = TCNT1L;
|
low = TCNT1L;
|
||||||
mid = TCNT1H;
|
mid = TCNT1H;
|
||||||
@ -74,12 +75,27 @@ uint64_t timer_read(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t timer_read(void)
|
||||||
|
{
|
||||||
|
uint64_t res;
|
||||||
|
|
||||||
|
cli();
|
||||||
|
res = __timer_read();
|
||||||
|
sei();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void timer_init(void)
|
void timer_init(void)
|
||||||
{
|
{
|
||||||
/* configure timer 1 as a free-running CLK counter */
|
/* configure timer 1 as a free-running CLK counter */
|
||||||
|
|
||||||
TCCR1A = 0;
|
TCCR1A = 0;
|
||||||
TCCR1B = 1 << CS10;
|
TCCR1B = 1 << CS10;
|
||||||
|
|
||||||
|
/* enable timer overflow interrupt */
|
||||||
|
|
||||||
|
TIMSK1 = 1 << TOIE1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user