1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-26 05:03:09 +02:00

fw/: base sweep start time on absolute time

This way, we can define the next sweep while the previous one is still
in progress.
This commit is contained in:
Werner Almesberger 2012-06-24 11:59:52 -03:00
parent 646f54d25c
commit 023c2aa1e9
3 changed files with 14 additions and 5 deletions

View File

@ -25,7 +25,6 @@
static struct sweep sweep = { static struct sweep sweep = {
.wait_ticks = 60000, /* 60 ms */
.pixel_ticks = 1000, /* 1 ms */ .pixel_ticks = 1000, /* 1 ms */
.left = 0, .left = 0,
.right = MAX_LINES-1, .right = MAX_LINES-1,
@ -128,6 +127,7 @@ sei();
#if 1 #if 1
if (state == FWD_START_SWEEP && !sweeping) { if (state == FWD_START_SWEEP && !sweeping) {
state = FWD_SWEEP; state = FWD_SWEEP;
sweep.start_ticks = uptime()+60000; /* 60 ms */
sweep_image(&sweep); sweep_image(&sweep);
} }
#endif #endif

View File

@ -118,6 +118,15 @@ uint32_t uptime(void)
void sweep_image(const struct sweep *sweep) void sweep_image(const struct sweep *sweep)
{ {
uint32_t t;
/* calculate start time */
t = uptime();
if (sweep->start_ticks <= t)
return;
t = sweep->start_ticks-t;
TCCR1B = 0; /* stop the timer */ TCCR1B = 0; /* stop the timer */
cli(); cli();
@ -142,9 +151,9 @@ void sweep_image(const struct sweep *sweep)
/* timing parameters */ /* timing parameters */
pixel_ticks = sweep->pixel_ticks; pixel_ticks = sweep->pixel_ticks;
wait_periods = sweep->wait_ticks >> 16; wait_periods = t >> 16;
if (wait_periods) { if (wait_periods) {
wait_short = sweep->wait_ticks; wait_short = t;
wait_period = 0xffff; wait_period = 0xffff;
/* /*
@ -157,7 +166,7 @@ void sweep_image(const struct sweep *sweep)
} }
ICR1 = wait_period; ICR1 = wait_period;
} else { } else {
ICR1 = sweep->wait_ticks; ICR1 = t;
} }
/* prepare the hardware timer */ /* prepare the hardware timer */

View File

@ -19,7 +19,7 @@
struct sweep { struct sweep {
uint32_t wait_ticks; /* number of ticks to wait before image */ uint32_t start_ticks; /* absolute start time */
uint16_t pixel_ticks; /* number of ticks per pixel */ uint16_t pixel_ticks; /* number of ticks per pixel */
uint8_t left; /* leftmost line of image */ uint8_t left; /* leftmost line of image */
uint8_t right; /* rightmost line of image */ uint8_t right; /* rightmost line of image */