diff --git a/pkg/mynewt-core/contrib/core.c b/pkg/mynewt-core/contrib/core.c index a780e0636f..a1b73b3554 100644 --- a/pkg/mynewt-core/contrib/core.c +++ b/pkg/mynewt-core/contrib/core.c @@ -22,6 +22,12 @@ #include "os/os_cputime.h" #include "hal/hal_timer.h" +#ifdef CPU_FAM_NRF51 +#define TIMER_NUM 3 +#else +#define TIMER_NUM 5 +#endif + void mynewt_core_init(void) { #if (MYNEWT_VAL_OS_CPUTIME_TIMER_NUM >= 0) && (defined(CPU_NRF51) || defined(CPU_NRF52)) @@ -29,7 +35,7 @@ void mynewt_core_init(void) for nimble this must be used for the BLE stack and must go through mynewt timer initialization for it to work properly. The RTC frequency should be set to the highest possible value, so 32768Hz */ - assert(MYNEWT_VAL_OS_CPUTIME_TIMER_NUM == 5); + assert(MYNEWT_VAL_OS_CPUTIME_TIMER_NUM == TIMER_NUM); assert(MYNEWT_VAL_OS_CPUTIME_FREQ == 32768); int rc = hal_timer_init(MYNEWT_VAL_OS_CPUTIME_TIMER_NUM, NULL); assert(rc == 0); diff --git a/pkg/mynewt-core/include/syscfg/syscfg.h b/pkg/mynewt-core/include/syscfg/syscfg.h index 70885621c8..c73c60f650 100644 --- a/pkg/mynewt-core/include/syscfg/syscfg.h +++ b/pkg/mynewt-core/include/syscfg/syscfg.h @@ -60,18 +60,29 @@ /** @} */ /** - * @brief TIMER 5 (RTC_DEV0) will be mynewt-core OS_CPUTIME timer + * @brief TIMER 3 or 5 (RTC_DEV0) will be mynewt-core OS_CPUTIME timer, + * depending on used CPU family */ #ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#ifdef CPU_FAM_NRF51 +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (3) +#else #define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (5) #endif +#endif /** - * @brief Enable TIMER 5 (RTC_DEV0) + * @brief Enable TIMER 3 or TIMER 5 (RTC_DEV0) depending on used CPU family */ +#ifdef CPU_FAM_NRF51 +#ifndef MYNEWT_VAL_TIMER_3 +#define MYNEWT_VAL_TIMER_3 (1) +#endif +#else #ifndef MYNEWT_VAL_TIMER_5 #define MYNEWT_VAL_TIMER_5 (1) #endif +#endif #if IS_USED(MODULE_NIMBLE) /*** @mynewt-nimble */