From ebee25d510b561e4884d1aad514cf2a090e9c2ff Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 1 Sep 2017 18:34:11 +0700 Subject: [PATCH] freeRTOS is configured as tickless close #40 --- changelog.md | 4 ++++ cores/nRF5/freertos/config/FreeRTOSConfig.h | 2 +- .../portable/CMSIS/nrf52/port_cmsis_systick.c | 11 +++++++---- cores/nRF5/rtos.cpp | 11 ++--------- cores/nRF5/wiring.c | 5 ----- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/changelog.md b/changelog.md index de26cc42..e0c9b140 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ ## 0.7.5 +### Core + +- Make FreeRTOS run in tickless mode + ## 0.7.0 ### Core diff --git a/cores/nRF5/freertos/config/FreeRTOSConfig.h b/cores/nRF5/freertos/config/FreeRTOSConfig.h index fefc1e5e..eb26cb83 100644 --- a/cores/nRF5/freertos/config/FreeRTOSConfig.h +++ b/cores/nRF5/freertos/config/FreeRTOSConfig.h @@ -94,7 +94,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 -#define configUSE_TICKLESS_IDLE 0 +#define configUSE_TICKLESS_IDLE 1 #define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */ #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ 1024 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 807a6fce..c6db0746 100644 --- a/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c +++ b/cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c @@ -77,6 +77,7 @@ #ifdef SOFTDEVICE_PRESENT #include "nrf_soc.h" +#include "nrf_sdm.h" #endif /*----------------------------------------------------------- @@ -244,7 +245,7 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) do{ uint8_t dummy = 0; uint32_t err_code = sd_nvic_critical_region_enter(&dummy); - APP_ERROR_CHECK(err_code); + //APP_ERROR_CHECK(err_code); }while (0); #else __disable_irq(); @@ -277,10 +278,12 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) if ( xModifiableIdleTime > 0 ) { #ifdef SOFTDEVICE_PRESENT // TODO - if (softdevice_handler_is_enabled()) + uint8_t sd_en = 0; + (void) sd_softdevice_is_enabled(&sd_en); + if (sd_en) // (softdevice_handler_is_enabled()) { uint32_t err_code = sd_app_evt_wait(); - APP_ERROR_CHECK(err_code); + //APP_ERROR_CHECK(err_code); } else #endif @@ -325,7 +328,7 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) } #ifdef SOFTDEVICE_PRESENT uint32_t err_code = sd_nvic_critical_region_exit(0); - APP_ERROR_CHECK(err_code); + //APP_ERROR_CHECK(err_code); #else __enable_irq(); #endif diff --git a/cores/nRF5/rtos.cpp b/cores/nRF5/rtos.cpp index 216d3236..aa5b2321 100644 --- a/cores/nRF5/rtos.cpp +++ b/cores/nRF5/rtos.cpp @@ -89,15 +89,8 @@ void vApplicationIdleHook( void ) { // Internal background task - // User callback is not defined. Go to low-power mode - if ( rtos_idle_callback ) - { - rtos_idle_callback(); - }else - { - // instruct CPU to enter low-power state until an event/interrupt occurred - waitForEvent(); - } + // Call user callback if defined + if ( rtos_idle_callback ) rtos_idle_callback(); } } // extern C diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index 0fa822f9..02d84afd 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -82,11 +82,7 @@ void waitForEvent(void) NVIC_ClearPendingIRQ(FPU_IRQn); #endif -#if 1 - (void) sd_app_evt_wait(); -#else uint8_t sd_en = 0; - (void) sd_softdevice_is_enabled(&sd_en); if ( sd_en ) @@ -99,7 +95,6 @@ void waitForEvent(void) __SEV(); // Clear Event Register. __WFE(); } -#endif }