mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-25 21:05:01 +02:00
fw/accel.c: keep track of uptime and return it with uptime() (untested)
This commit is contained in:
parent
3b7c3017fc
commit
7045109090
26
fw/sweep.c
26
fw/sweep.c
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user