Skip to content

Commit ff0f1b9

Browse files
ArcaneNibbledlech
authored andcommitted
pbio/drv/clock/clock_ev3: Implement finer-resolution timer values
1 parent 566813f commit ff0f1b9

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
static const uint32_t auxclk_freq_hz = SOC_ASYNC_2_FREQ;
3232
static const uint32_t timer_ms_period = (auxclk_freq_hz / 1000) - 1;
33+
static const uint32_t timer_us_division = auxclk_freq_hz / 1000000;
3334

3435
/**
3536
* The current tick in milliseconds
@@ -81,17 +82,19 @@ void pbdrv_clock_init(void) {
8182
}
8283

8384
uint32_t pbdrv_clock_get_us(void) {
84-
// TODO: TIAM1808 implementation.
85-
return 0;
85+
uint32_t tim_val = TimerCounterGet(SOC_TMR_0_REGS, TMR_TIMER12);
86+
uint32_t t_us = tim_val / timer_us_division;
87+
return pbdrv_clock_get_ms() * 1000 + t_us;
8688
}
8789

8890
uint32_t pbdrv_clock_get_ms(void) {
8991
return systick_ms;
9092
}
9193

9294
uint32_t pbdrv_clock_get_100us(void) {
93-
// REVISIT: Use actual time since this isn't providing better resolution.
94-
return pbdrv_clock_get_ms() * 10;
95+
uint32_t tim_val = TimerCounterGet(SOC_TMR_0_REGS, TMR_TIMER12);
96+
uint32_t t_100_us = tim_val / timer_us_division / 100;
97+
return pbdrv_clock_get_ms() * 10 + t_100_us;
9598
}
9699

97100
#endif // PBDRV_CONFIG_CLOCK_TIAM1808

0 commit comments

Comments
 (0)