call waitForEvent() in core idle hook

This commit is contained in:
hathach committed 2017-04-10 16:39:14 +07:00
1 parent f093e03c5d
commit e5d98a877f
5 files changed
+42 -14

No files matched your search

+2 -1
View File
@@ -4,7 +4,8 @@
- Add HardwarePWM class to support up to 12 channels and compatible with Neopixel library
- Add waitForEvent() as alias to __WFE() instruction
- Enable FreeRTOS's Idle hook, add rtos_idle_callback() as optional callback for user
- Enable FreeRTOS's Idle hook, and call waitForEvent() in the Idle hook.
- Add rtos_idle_callback() as optional callback for user to handle background task
- Add mutex to prevent uart conflict
- Change FreeRTOS tick source from systick to RTC for low-power mode
+1 -1
View File
@@ -111,7 +111,7 @@ uint32_t setLoopStacksize(void);
#define digitalPinHasPWM(P) ( true )
// Hint instruction to tell CPU go to low power mode
#define waitForEvent() sd_app_evt_wait() // __WFE()
#define waitForEvent() __WFE() // sd_app_evt_wait()
/*
* digitalPinToTimer(..) is AVR-specific and is not defined for nRF52
+3
View File
@@ -94,6 +94,9 @@ void vApplicationIdleHook( void )
// Weak symbol do nothing if is not implementation
rtos_idle_callback();
// All done. Instruct CPU to enter low-power state until an event/interrupt occurred
waitForEvent();
}
}
@@ -110,22 +110,24 @@ void disconnect_callback(uint8_t reason)
/**
* RTOS Idle callback is automatically invoked by FreeRTOS
* when there is no active threads. This function must not
* call any blocking FreeRTOS API such as delay(), xSemaphoreTake() etc ..
* when there is no active threads. E.g loop() call delay() and
* there is no bluetooth or hw event. This is a greate place to handle
* background data.
*
* Notes: Should be used for background work. Great place to call
* waitForEvent() (see comment below)
* NOTE: After this callback returns, MCU will enter low-power mode
* by waitForEvent() internally. THerefore user SHOULD NOT call
* waitForEvent() in this callback.
*
* WARNING: This function MUST NOT call any blocking FreeRTOS API
* such as delay(), xSemaphoreTake() etc ... for more information
* http://www.freertos.org/a00016.html
*/
void rtos_idle_callback(void)
{
// Background task here
// Instruct CPU to enter low-power state until an event/interrupt occured
// Note: This will turn off hardware PWM and maybe other peripherlas !!
// Should only call there is no active PWM devices
if ( !(PWM0.enabled() || PWM1.enabled() || PWM2.enabled() ) )
{
waitForEvent();
}
// waitForEvent() will be invoked by internal code when this callback return.
// Don't call waitForEvent() in this function nor any other blocking API()
}
@@ -109,3 +109,25 @@ void loop()
waitForEvent();
}
/**
* RTOS Idle callback is automatically invoked by FreeRTOS
* when there is no active threads. E.g loop() call delay() and
* there is no bluetooth or hw event. This is a greate place to handle
* background data.
*
* NOTE: After this callback returns, MCU will enter low-power mode
* by waitForEvent() internally. THerefore user SHOULD NOT call
* waitForEvent() in this callback.
*
* WARNING: This function MUST NOT call any blocking FreeRTOS API
* such as delay(), xSemaphoreTake() etc ... for more information
* http://www.freertos.org/a00016.html
*/
void rtos_idle_callback(void)
{
// Background task here
// waitForEvent() will be invoked by internal code when this callback return.
// Don't call waitForEvent() in this function nor any other blocking API()
}