From 3f83bb06ac2adade11c38884836dd6694d0c6cf0 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Apr 2017 23:52:59 +0700 Subject: [PATCH] move waitForEvent() to wiring, increase configMINIMAL_STACK_SIZE from 60 to 100 --- cores/nRF5/Arduino.h | 3 --- cores/nRF5/freertos/config/FreeRTOSConfig.h | 2 +- cores/nRF5/wiring.h | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cores/nRF5/Arduino.h b/cores/nRF5/Arduino.h index 7652ba23..ab0810b5 100644 --- a/cores/nRF5/Arduino.h +++ b/cores/nRF5/Arduino.h @@ -111,9 +111,6 @@ uint32_t setLoopStacksize(void); #define portModeRegister(port) ( &(NRF_GPIO->DIRSET) ) #define digitalPinHasPWM(P) ( true ) -// Hint instruction to tell CPU go to low power mode -#define waitForEvent() __WFE() // sd_app_evt_wait() - /* * digitalPinToTimer(..) is AVR-specific and is not defined for nRF52 * architecture. If you need to check if a pin supports PWM you must diff --git a/cores/nRF5/freertos/config/FreeRTOSConfig.h b/cores/nRF5/freertos/config/FreeRTOSConfig.h index 3e90e090..98fe8956 100644 --- a/cores/nRF5/freertos/config/FreeRTOSConfig.h +++ b/cores/nRF5/freertos/config/FreeRTOSConfig.h @@ -97,7 +97,7 @@ #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ 10000 #define configMAX_PRIORITIES ( 5 ) -#define configMINIMAL_STACK_SIZE ( 60 ) +#define configMINIMAL_STACK_SIZE ( 100 ) #define configTOTAL_HEAP_SIZE ( 4096 ) /* not used since we use malloc */ #define configMAX_TASK_NAME_LEN ( 8 ) #define configUSE_16_BIT_TICKS 0 diff --git a/cores/nRF5/wiring.h b/cores/nRF5/wiring.h index ac87c7b3..afb65c6c 100644 --- a/cores/nRF5/wiring.h +++ b/cores/nRF5/wiring.h @@ -27,6 +27,25 @@ extern void init(void); extern void enterSerialDfu(void); extern void enterOTADfu(void); +// Hint instruction to tell CPU go to low power mode +#if 1 +#define waitForEvent() __WFE() +#else +ATTR_ALWAYS_INLINE static inline void waitForEvent(void) +{ + // Set bit 7 and bits 4..0 in the mask to one (0x ...00 1001 1111) + enum { FPU_EXCEPTION_MASK = 0x0000009F }; + + /* Clear exceptions and PendingIRQ from the FPU unit */ + __set_FPSCR(__get_FPSCR() & ~(FPU_EXCEPTION_MASK)); + (void) __get_FPSCR(); + NVIC_ClearPendingIRQ(FPU_IRQn); + + /* Call SoftDevice Wait For event */ + (void) sd_app_evt_wait(); +} +#endif + #ifdef __cplusplus } #endif