rp2/mphalport: Implement mp_hal_ticks_cpu for RISCV using mcycle.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
957cea23d5
commit
ea2eed1b23
|
@ -125,6 +125,17 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
|||
return did_write ? ret : 0;
|
||||
}
|
||||
|
||||
#if PICO_RISCV
|
||||
__attribute__((naked)) mp_uint_t mp_hal_ticks_cpu(void) {
|
||||
__asm volatile (
|
||||
"li a0, 4\n" // mask value to uninhibit mcycle counter
|
||||
"csrw mcountinhibit, a0\n" // uninhibit mcycle counter
|
||||
"csrr a0, mcycle\n" // get mcycle counter
|
||||
"ret\n"
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
void mp_hal_delay_us(mp_uint_t us) {
|
||||
// Avoid calling sleep_us() and invoking the alarm pool by splitting long
|
||||
// sleeps into an optional longer sleep and a shorter busy-wait
|
||||
|
|
|
@ -96,11 +96,15 @@ static inline mp_uint_t mp_hal_ticks_ms(void) {
|
|||
return to_ms_since_boot(get_absolute_time());
|
||||
}
|
||||
|
||||
#if PICO_ARM
|
||||
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
||||
// ticks_cpu() is defined as using the highest-resolution timing source
|
||||
// in the system. This is usually a CPU clock, but doesn't have to be.
|
||||
return time_us_32();
|
||||
}
|
||||
#elif PICO_RISCV
|
||||
mp_uint_t mp_hal_ticks_cpu(void);
|
||||
#endif
|
||||
|
||||
static inline mp_uint_t mp_hal_get_cpu_freq(void) {
|
||||
return clock_get_hz(clk_sys);
|
||||
|
|
Loading…
Reference in New Issue