I've searched the wiki and I thought volatile was the answer, but even with volatile it's not returning.
Code: Select all
#include "timer.h"
#include <stdint.h>
#include "ports.h"
#include "../libc/function.h"
#include "isr.h"
volatile uint32_t timer_ticks = 0;
void timer_callback(registers_t *regs)
{
timer_ticks++;
UNUSED(regs);
}
void timer_wait(uint32_t ticks)
{
uint32_t eticks;
eticks = timer_ticks+ticks;
while(timer_ticks < eticks);
{
dkprint("ok \n");
}
dkprint("end");
}
void init_timer(uint32_t freq) {
register_interrupt_handler(IRQ0, timer_callback);
u32 divisor = 1193180 / freq; /* Calculate our divisor */
u8 low = (u8)(divisor & 0xFF);
u8 high = (u8)( (divisor >> 8) & 0xFF);
port_byte_out(0x43, 0x36); /* Set our command byte 0x36 */
port_byte_out(0x40, low); /* Set low byte of divisor */
port_byte_out(0x40, high); /* Set high byte of divisor */
}
I added some code to timer_wait to output timer_ticks on a loop, and when timer_wait() is called for the first time, timer_ticks is a sensible value (it's counting up over time), but whatever that starting value is, it stays at, so timer_wait() just prints, for example "608" over and over again, and never stops.
It's as if volatile is being ignored by my compiler?
I tried using a pointer to timer_ticks inside timer_wait() but that's not behaving as expected either, so now I'm rather confused. I'd appreciate any suggestions/tips.
Thanks