samd/mphalport: Use CYCCNT for SAMD51's mp_hal_ticks_cpu().
And use mp_hal_ticks_us() for SAM21's mp_hal_ticks_cpu(). The SAMD21 has no CYCCNT register, and the SysTick register has only a 1 ms span (== 48000 count range).
This commit is contained in:
parent
a9304af8fa
commit
fd7b57dd22
|
@ -71,12 +71,22 @@ static inline mp_uint_t mp_hal_ticks_us(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ticks_cpu is limited to a 1 ms period, since the CPU SysTick counter
|
#if defined (MCU_SAMD21)
|
||||||
// is used for the 1 ms SysTick_Handler interrupt.
|
|
||||||
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
#define mp_hal_ticks_cpu mp_hal_ticks_us
|
||||||
return (system_time_t)SysTick->VAL;
|
|
||||||
|
#elif defined (MCU_SAMD51)
|
||||||
|
static inline void mp_hal_ticks_cpu_enable(void) {
|
||||||
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||||
|
DWT->CYCCNT = 0;
|
||||||
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
||||||
|
return (system_time_t)DWT->CYCCNT;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline uint64_t mp_hal_time_ns(void) {
|
static inline uint64_t mp_hal_time_ns(void) {
|
||||||
return mp_hal_ticks_ms_64() * 1000000;
|
return mp_hal_ticks_ms_64() * 1000000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "samd_soc.h"
|
#include "samd_soc.h"
|
||||||
#include "sam.h"
|
#include "sam.h"
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
|
#include "mphalport.h"
|
||||||
|
|
||||||
static void usb_init(void) {
|
static void usb_init(void) {
|
||||||
// Init USB clock
|
// Init USB clock
|
||||||
|
@ -110,4 +111,7 @@ void samd_init(void) {
|
||||||
SysTick_Config(get_cpu_freq() / 1000);
|
SysTick_Config(get_cpu_freq() / 1000);
|
||||||
init_us_counter();
|
init_us_counter();
|
||||||
usb_init();
|
usb_init();
|
||||||
|
#if defined (MCU_SAMD51)
|
||||||
|
mp_hal_ticks_cpu_enable();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue