From d2fc54fab9ffbd407d09704d4e4b5a144899f99c Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Apr 2017 15:23:13 +0700 Subject: [PATCH] Change FreeRTOS tick source from systick to RTC for low-power mode --- changelog.md | 15 ++++++++------- cores/nRF5/freertos/config/FreeRTOSConfig.h | 2 +- .../portable/CMSIS/nrf52/port_cmsis_systick.c | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/changelog.md b/changelog.md index 96eeebfb..617fe5f5 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ - Add waitForEvent() as alias to __WFE() instruction - Enable FreeRTOS's Idle hook, add rtos_idle_callback() as optional callback for user - Add mutex to prevent uart conflict +- Change FreeRTOS tick source from systick to RTC for low-power mode #### New Example @@ -20,13 +21,13 @@ - Add BLEDiscovery - Add BLEGap and BLEGatt to manage peripheral & central with Gatt client and server support - BLE API changes - - connPaired(), requestPairing() - - rename BLEBas .update() to .write() - - change Bluefruit setConnInterval()/setConnIntervalMS() return type from `err_t` to `bool` - - change BLECentral startScanning()/stopScanning()/connect() return type from `err_t` to `bool` - - change BLECharacteristic notify() return type from `err_t` to `bool` - - change BLEHid report function return type from `err_t` to `bool` - - change BLEMid send/sendSplit return type from `err_t` to `bool` + - Add connPaired(), requestPairing() + - Rename BLEBas .update() to .write() + - Change Bluefruit setConnInterval()/setConnIntervalMS() return type from `err_t` to `bool` + - Change BLECentral startScanning()/stopScanning()/connect() return type from `err_t` to `bool` + - Change BLECharacteristic notify() return type from `err_t` to `bool` + - Change BLEHid report function return type from `err_t` to `bool` + - Change BLEMid send/sendSplit return type from `err_t` to `bool` - New BLE Serivce - Apple Notification Center Service (ANCS) - Central BLE UART diff --git a/cores/nRF5/freertos/config/FreeRTOSConfig.h b/cores/nRF5/freertos/config/FreeRTOSConfig.h index f886b3df..3e90e090 100644 --- a/cores/nRF5/freertos/config/FreeRTOSConfig.h +++ b/cores/nRF5/freertos/config/FreeRTOSConfig.h @@ -89,7 +89,7 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -#define configTICK_SOURCE FREERTOS_USE_SYSTICK +#define configTICK_SOURCE FREERTOS_USE_RTC #define configUSE_PREEMPTION 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 diff --git a/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c b/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c index a073b929..ad8dbe10 100644 --- a/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c +++ b/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c @@ -153,9 +153,16 @@ void vPortSetupTimerInterrupt( void ) void xPortSysTickHandler( void ) { - nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_TICK); +// nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_TICK); + portNRF_RTC_REG->EVENTS_TICK = 0; + uint32_t dummy = portNRF_RTC_REG->EVENTS_TICK; + (void) dummy; + #if configUSE_TICKLESS_IDLE == 1 - nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0); +// nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_COMPARE_0); + portNRF_RTC_REG->EVENTS_COMPARE[0] = 0; + uint32_t dummy2 = portNRF_RTC_REG->EVENTS_COMPARE[0]; + (void) dummy2; #endif /* The SysTick runs at the lowest interrupt priority, so when this interrupt @@ -198,6 +205,7 @@ void xPortSysTickHandler( void ) */ void vPortSetupTimerInterrupt( void ) { +#if 0 /* Request LF clock */ nrf_drv_clock_lfclk_request(NULL); @@ -206,6 +214,12 @@ void vPortSetupTimerInterrupt( void ) nrf_rtc_int_enable (portNRF_RTC_REG, RTC_INTENSET_TICK_Msk); nrf_rtc_task_trigger (portNRF_RTC_REG, NRF_RTC_TASK_CLEAR); nrf_rtc_task_trigger (portNRF_RTC_REG, NRF_RTC_TASK_START); +#else + portNRF_RTC_REG->PRESCALER = portNRF_RTC_PRESCALER; + portNRF_RTC_REG->INTENSET = RTC_INTENSET_TICK_Msk; + portNRF_RTC_REG->TASKS_CLEAR = 1; + portNRF_RTC_REG->TASKS_START = 1; +#endif NVIC_SetPriority(portNRF_RTC_IRQn, configKERNEL_INTERRUPT_PRIORITY); NVIC_EnableIRQ(portNRF_RTC_IRQn);