#include "timer.h"
#include "watchdog.h"
#include "task.h"
static uint64_t reload;
static inline uint64_t cntfrq(void){ uint64_t v; asm("mrs %0,CNTFRQ_EL0":"=r"(v)); return v; }
void timer_init(unsigned hz){
    reload = cntfrq()/hz;
    asm volatile("msr CNTP_TVAL_EL0,%0"::"r"(reload));
    asm volatile("msr CNTP_CTL_EL0,%0"::"r"(1));
}
void timer_handler(void){
    asm volatile("msr CNTP_TVAL_EL0,%0"::"r"(reload));
    watchdog_kick(); scheduler_yield();
}