| 1 |
/* timer.h — ARM Generic Timer for Raspberry Pi 5 */ |
| 2 |
|
| 3 |
#ifndef TIMER_H |
| 4 |
#define TIMER_H |
| 5 |
|
| 6 |
#include <stdint.h> |
| 7 |
|
| 8 |
/* Timer frequency (read from CNTFRQ_EL0, typically 54MHz on Pi 5) */ |
| 9 |
static inline uint64_t timer_get_freq(void) { |
| 10 |
uint64_t freq; |
| 11 |
__asm__ volatile("mrs %0, cntfrq_el0" : "=r"(freq)); |
| 12 |
return freq; |
| 13 |
} |
| 14 |
|
| 15 |
/* Current counter value */ |
| 16 |
static inline uint64_t timer_get_count(void) { |
| 17 |
uint64_t count; |
| 18 |
__asm__ volatile("mrs %0, cntpct_el0" : "=r"(count)); |
| 19 |
return count; |
| 20 |
} |
| 21 |
|
| 22 |
/* Initialize timer for periodic tick (100 Hz) */ |
| 23 |
void timer_init(void); |
| 24 |
|
| 25 |
/* Timer IRQ handler — called from vectors.S */ |
| 26 |
void timer_irq(void); |
| 27 |
|
| 28 |
/* Get tick count */ |
| 29 |
uint64_t timer_ticks(void); |
| 30 |
|
| 31 |
#endif /* TIMER_H */ |
| 32 |
|