2 #include <ros/common.h>
8 system_timing_t system_timing = {0};
13 system_timing.tsc_freq = TSC_HZ;
14 cprintf("TSC Frequency: %llu\n", system_timing.tsc_freq);
18 set_core_timer(uint32_t usec, bool periodic)
20 // we could implement periodic timers using one-shot timers,
21 // but for now we only support one-shot
26 uint32_t clocks = (uint64_t)usec*TSC_HZ/1000000;
29 disable_irqsave(&irq_state);
32 mtpcr(PCR_COMPARE, clocks);
33 mtpcr(PCR_SR, mfpcr(PCR_SR) | (1 << (IRQ_TIMER+SR_IM_SHIFT)));
35 enable_irqsave(&irq_state);
39 mtpcr(PCR_SR, mfpcr(PCR_SR) & ~(1 << (IRQ_TIMER+SR_IM_SHIFT)));
46 if (system_timing.tsc_freq != 0)
48 uint64_t start, end, now;
51 end = start + (system_timing.tsc_freq * usec) / 1000000;
57 } while (now < end || (now > start && end < start));
59 else panic("udelay() was called before timer_init(), moron!");