I am using the PIT as a timer with the following code (timer_ticks increments every time the PIT handler is called):
Code: Select all
void timer_wait(int ticks) { // Time offset in ticks as argument
unsigned long w_ticks; // Ticks to wait for
w_ticks = timer_ticks + ticks; // The current tick count plus the time offset
while(timer_ticks < w_ticks) {
} // Loop until timer_ticks > ticks count to wait for
}
However, nothing else fixes the issue - I have tried adding in an internal counter that ticks up and sending STI before the while loop to ensure interrupts are received and neither cause the loop to exit to allow the rest of the kernel to load.
To clarify, this code does work - the timer exits as expected:
Code: Select all
void timer_wait(int ticks) { // Time offset in ticks as argument
unsigned long w_ticks; // Ticks to wait for
w_ticks = timer_ticks + ticks; // The sum of the initial tick count and the time offset
while(timer_ticks < w_ticks) {
terminal_writestring(" \b"); // Write a space and delete it to produce no net output
} // Loop until timer_ticks > ticks count to wait for
Edit: Global variable 'int timer_ticks' changed to 'volatile int timer_ticks' - fixed my problem with an explanation below