From 291a28b5076d8ea376416e6fd0296574b6ab5683 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 8 Apr 2017 16:59:45 +0700 Subject: [PATCH] add waitForEvent() as macro for __WFE(). Enable Idle Hook and call wfe instruction --- cores/nRF5/freertos/config/FreeRTOSConfig.h | 2 +- cores/nRF5/rtos.cpp | 10 ++++++++++ cores/nRF5/wiring.h | 5 +---- .../examples/Peripheral/bleuart/bleuart.ino | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cores/nRF5/freertos/config/FreeRTOSConfig.h b/cores/nRF5/freertos/config/FreeRTOSConfig.h index 73818bf4..f886b3df 100644 --- a/cores/nRF5/freertos/config/FreeRTOSConfig.h +++ b/cores/nRF5/freertos/config/FreeRTOSConfig.h @@ -113,7 +113,7 @@ #define configENABLE_BACKWARD_COMPATIBILITY 1 /* Hook function related definitions. */ -#define configUSE_IDLE_HOOK 0 +#define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 #define configCHECK_FOR_STACK_OVERFLOW 1 #define configUSE_MALLOC_FAILED_HOOK 1 diff --git a/cores/nRF5/rtos.cpp b/cores/nRF5/rtos.cpp index 46070117..d33569af 100644 --- a/cores/nRF5/rtos.cpp +++ b/cores/nRF5/rtos.cpp @@ -82,3 +82,13 @@ bool SchedulerRTOS::startLoop(taskfunc_t task, const char* name, uint32_t stack_ return pdPASS == xTaskCreate( _redirect_task, name, stack_size, (void*) task, TASK_PRIO_NORMAL, &handle); } + +extern "C" +{ + +void vApplicationIdleHook( void ) +{ + waitForEvent(); +} + +} diff --git a/cores/nRF5/wiring.h b/cores/nRF5/wiring.h index bf802e4c..fc67de65 100644 --- a/cores/nRF5/wiring.h +++ b/cores/nRF5/wiring.h @@ -24,10 +24,7 @@ extern "C" { extern void init(void); -static inline void sleep(void) -{ - __WFE(); -} +#define waitForEvent() __WFE() extern void enterSerialDfu(void); extern void enterOTADfu(void); diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino index 8055e098..0a035e18 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino @@ -107,7 +107,7 @@ void loop() // Equavilent to __WFE (Wait For Event) instruction. // It is a hint to allow CPU to enter low-power state until an event occured - sleep(); + waitForEvent(); } void connect_callback(void)