From 781f3ddb81f4991983d977dbfab0711a963736c8 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Aug 2021 11:46:56 +0700 Subject: [PATCH] clean up malloc/free --- cores/nRF5/freertos/config/FreeRTOSConfig.h | 18 +++++++++--------- cores/nRF5/new.cpp | 12 ------------ cores/nRF5/rtos.h | 20 ++++++-------------- keywords.txt | 4 ---- 4 files changed, 15 insertions(+), 39 deletions(-) diff --git a/cores/nRF5/freertos/config/FreeRTOSConfig.h b/cores/nRF5/freertos/config/FreeRTOSConfig.h index bff583b4..4158726d 100644 --- a/cores/nRF5/freertos/config/FreeRTOSConfig.h +++ b/cores/nRF5/freertos/config/FreeRTOSConfig.h @@ -184,15 +184,15 @@ standard names - or at least those used in the unmodified vector table. */ /** Implementation note: Use this with caution and set this to 1 ONLY for debugging * ---------------------------------------------------------- - * Set the value of configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to below for enabling or disabling RTOS tick auto correction: - * 0. This is default. If the RTC tick interrupt is masked for more than 1 tick by higher priority interrupts, then most likely - * one or more RTC ticks are lost. The tick interrupt inside RTOS will detect this and make a correction needed. This is needed - * for the RTOS internal timers to be more accurate. - * 1. The auto correction for RTOS tick is disabled even though few RTC tick interrupts were lost. This feature is desirable when debugging - * the RTOS application and stepping though the code. After stepping when the application is continued in debug mode, the auto-corrections of - * RTOS tick might cause asserts. Setting configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to 1 will make RTC and RTOS go out of sync but could be - * convenient for debugging. - */ + * Set the value of configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to below for enabling or disabling RTOS tick auto correction: + * 0. This is default. If the RTC tick interrupt is masked for more than 1 tick by higher priority interrupts, then most likely + * one or more RTC ticks are lost. The tick interrupt inside RTOS will detect this and make a correction needed. This is needed + * for the RTOS internal timers to be more accurate. + * 1. The auto correction for RTOS tick is disabled even though few RTC tick interrupts were lost. This feature is desirable when debugging + * the RTOS application and stepping though the code. After stepping when the application is continued in debug mode, the auto-corrections of + * RTOS tick might cause asserts. Setting configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to 1 will make RTC and RTOS go out of sync but could be + * convenient for debugging. + */ #define configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG 0 // Sysview is enabled by default at debug level 3 diff --git a/cores/nRF5/new.cpp b/cores/nRF5/new.cpp index c646576a..541097d0 100644 --- a/cores/nRF5/new.cpp +++ b/cores/nRF5/new.cpp @@ -76,16 +76,4 @@ caddr_t _sbrk( int incr ) return (caddr_t) prev_heap; } -void __malloc_lock(struct _reent *ptr) -{ - (void) ptr; - vTaskSuspendAll(); -} - -void __malloc_unlock(struct _reent *ptr) -{ - (void) ptr; - xTaskResumeAll(); -} - } diff --git a/cores/nRF5/rtos.h b/cores/nRF5/rtos.h index 5715cbdf..90f64770 100644 --- a/cores/nRF5/rtos.h +++ b/cores/nRF5/rtos.h @@ -50,8 +50,6 @@ #include "queue.h" #include "semphr.h" -#define DEBUG_MALLOC 1 - #define DELAY_FOREVER portMAX_DELAY enum @@ -63,19 +61,13 @@ enum TASK_PRIO_HIGHEST = 4, }; -#define ms2tick pdMS_TO_TICKS +#define ms2tick pdMS_TO_TICKS +#define tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / configTICK_RATE_HZ ) +#define tick2us(tck) ( ( ((uint64_t)(tck)) * 1000000) / configTICK_RATE_HZ ) -#define tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / configTICK_RATE_HZ ) -#define tick2us(tck) ( ( ((uint64_t)(tck)) * 1000000) / configTICK_RATE_HZ ) - -#if DEBUG_MALLOC - #define rtos_malloc_type(_type) ({ LOG_LV2("MALLOC", #_type " = %d bytes", sizeof(_type)); ((_type*) rtos_malloc(sizeof(_type))); }) -#else - #define rtos_malloc_type(_type) ((_type*) rtos_malloc(sizeof(_type))) -#endif - -#define rtos_malloc malloc -#define rtos_free free +// legacy thread-safe malloc/free +#define rtos_malloc malloc +#define rtos_free free // Visible only with C++ #ifdef __cplusplus diff --git a/keywords.txt b/keywords.txt index 873d1cfb..5caec07f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -36,10 +36,6 @@ delay_ns KEYWORD2 analogOversampling KEYWORD2 analogReadVDD KEYWORD2 -# RTOS -rtos_malloc KEYWORD2 -rtos_free KEYWORD2 - nrf52_flash_init KEYWORD2 nrf52_flash_erase_sector KEYWORD2 nrf52_flash_write KEYWORD2