- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.c
More file actions
Latest commit
22 lines (19 loc) · 557 Bytes
/
Copy pathtimer.c
File metadata and controls
22 lines (19 loc) · 557 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include"types.h"
volatileuint32_ttimer_ticks=0;
/**
* @brief Called whenever the hardware PIT timer fires (IRQ0)
*/
voidtimer_handler(void) {
timer_ticks++;
}
/**
* @brief Sleeps execution for a specified number of milliseconds
*/
voidsleep(uint32_tms) {
uint32_tstart_ticks=timer_ticks;
// Assuming PIT is configured to 100 Hz (1 tick = 10 ms)
uint32_tticks_to_wait=ms / 10;
while ((timer_ticks-start_ticks) <ticks_to_wait) {
__asm__ __volatile__("hlt"); // Sleep CPU until next timer interrupt
}
}