1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-12-25 22:34:35 +02:00

ubb-vga.c (delay): try to compensate for APB jitter (experimental)

First, we extend all deadlines a litte to make sure we never have to
wait negative time. Second, we get the timer value at the end of the
wait and CPU-loop for the difference between the actual value and the
ideal (extended) value.
This commit is contained in:
Werner Almesberger 2011-05-03 12:09:24 -03:00
parent 72235b9212
commit 01d33e28a7

View File

@ -244,11 +244,17 @@ static void cleanup(void)
static void delay(uint16_t cycles)
{
static uint16_t next = 0;
uint16_t t;
next += cycles;
TDHR(TIMER) = next;
TFCR = 1 << (TIMER+16);
while (!(TFR & (1 << (TIMER+16))));
t = next+24-TCNT(TIMER);
t >>= 1;
while (t--)
asm("");
}