1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-12-22 23:23:21 +02:00

fw/accel.c: keep track of uptime and return it with uptime() (untested)

This commit is contained in:
Werner Almesberger 2012-06-21 08:55:43 -03:00
parent 3b7c3017fc
commit 7045109090
2 changed files with 25 additions and 3 deletions

View File

@ -24,6 +24,7 @@
volatile bool sweeping = 0;
static volatile uint32_t t_up; /* uptime, in timer ticks (wraps in 4295 s) */
static volatile uint32_t t_sw; /* cumulative number of timer ticks in sweep */
static uint16_t wait_periods; /* number of periods to wait before image */
@ -38,9 +39,13 @@ static bool forward;
ISR(TIMER1_OVF_vect)
{
/* update the sweep time */
uint16_t t;
t_sw += ICR1;
/* update the time counters */
t = ICR1;
t_sw += t;
t_up += t;
/* if at the end of the image, only update the time */
@ -79,6 +84,23 @@ ISR(TIMER1_OVF_vect)
}
uint32_t uptime(void)
{
uint32_t a, b;
uint16_t d;
do {
cli();
a = t_up;
d = ICR1;
b = t_up;
sei();
}
while (a != b);
return a+d;
}
void sweep_image(const struct sweep *sweep)
{
TCCR1B = 0; /* stop the timer */

View File

@ -29,7 +29,7 @@ struct sweep {
extern volatile bool sweeping;
uint32_t uptime(void);
void sweep_image(const struct sweep *sweep);
void sweep_init(void);