Skip to content

Commit 7ba2c75

Browse files
committed
pbio/drv/clock/clock_ev3: Implement finer-resolution timer values
1 parent 2aa0259 commit 7ba2c75

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/pbio/drv/clock/clock_ev3.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// The system tick uses the "12" half of the timer, and the PRU1 (TODO) uses the "34" half.
3131
const uint32_t auxclk_freq_hz = 24000000;
3232
const uint32_t timer_ms_period = (auxclk_freq_hz / 1000) - 1;
33+
const uint32_t timer_us_division = auxclk_freq_hz / 1000000;
3334

3435
/**
3536
* The current tick in milliseconds
@@ -105,17 +106,19 @@ void pbdrv_clock_init(void) {
105106
}
106107

107108
uint32_t pbdrv_clock_get_us(void) {
108-
// TODO: TIAM1808 implementation.
109-
return 0;
109+
uint32_t tim_val = TimerCounterGet(SOC_TMR_0_REGS, TMR_TIMER12);
110+
uint32_t t_us = tim_val / timer_us_division;
111+
return pbdrv_clock_get_ms() * 1000 + t_us;
110112
}
111113

112114
uint32_t pbdrv_clock_get_ms(void) {
113115
return systick_ms;
114116
}
115117

116118
uint32_t pbdrv_clock_get_100us(void) {
117-
// REVISIT: Use actual time since this isn't providing better resolution.
118-
return pbdrv_clock_get_ms() * 10;
119+
uint32_t tim_val = TimerCounterGet(SOC_TMR_0_REGS, TMR_TIMER12);
120+
uint32_t t_100_us = tim_val / timer_us_division / 100;
121+
return pbdrv_clock_get_ms() * 10 + t_100_us;
119122
}
120123

121124
void pbdrv_clock_busy_delay_ms(uint32_t ms) {

0 commit comments

Comments
 (0)