From 781d06af732b29964e3c6919dbc29208d2bb8963 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Thu, 21 Jul 2022 19:14:41 +0800 Subject: [PATCH] esp_hw_support: Remove compare_set.h API This function removes the following legacy atomic CAS functions: From compare_set.h (file removed): - compare_and_set_native() - compare_and_set_extram() From portmacro.h - uxPortCompareSet() - uxPortCompareSetExtram() Users should call esp_cpu_compare_and_set() instead as this function hides the details of atomic CAS on internal and external RAM addresses. Due to the removal of compare_set.h, some missing header includes are also fixed in this commit. --- .../general/main/test_cxx_general.cpp | 1 + components/driver/i2s/i2s_common.c | 1 + components/driver/pulse_cnt.c | 1 + components/driver/rmt/rmt_rx.c | 1 + components/driver/rmt/rmt_tx.c | 1 + components/driver/spi_slave_hd.c | 1 + .../main/test_legacy_timer.c | 1 + components/driver/twai.c | 1 + components/esp_adc/adc_continuous.c | 1 + components/esp_hw_support/CMakeLists.txt | 2 +- components/esp_hw_support/compare_set.c | 41 ---------------- .../esp_hw_support/include/compare_set.h | 29 ------------ components/esp_hw_support/intr_alloc.c | 1 + components/esp_hw_support/sleep_modes.c | 1 + components/esp_serial_slave_link/essl_spi.c | 1 + components/fatfs/test/test_fatfs_spiflash.c | 1 + .../riscv/include/freertos/portmacro.h | 37 +-------------- .../FreeRTOS-Kernel-SMP/portable/riscv/port.c | 2 +- .../xtensa/include/freertos/portmacro.h | 14 +----- .../portable/xtensa/port.c | 1 + .../riscv/include/freertos/portmacro.h | 43 ----------------- .../FreeRTOS-Kernel/portable/riscv/port.c | 1 + .../xtensa/include/freertos/portmacro.h | 47 +------------------ .../FreeRTOS-Kernel/portable/xtensa/port.c | 1 + .../lwip/port/esp32/hooks/tcp_isn_default.c | 1 + components/mbedtls/port/aes/dma/esp_aes.c | 1 + components/mbedtls/port/sha/dma/sha.c | 1 + .../mbedtls/port/sha/parallel_engine/sha.c | 8 ++-- components/mbedtls/test/test_aes.c | 1 + components/mbedtls/test/test_mbedtls_sha.c | 1 + components/pthread/pthread.c | 13 +---- components/spi_flash/cache_utils.c | 1 + components/spi_flash/flash_mmap.c | 1 + .../spi_flash/test/test_cache_disabled.c | 1 + .../main/timer_group_example_main.c | 1 + 35 files changed, 36 insertions(+), 225 deletions(-) delete mode 100644 components/esp_hw_support/compare_set.c delete mode 100644 components/esp_hw_support/include/compare_set.h diff --git a/components/cxx/test_apps/general/main/test_cxx_general.cpp b/components/cxx/test_apps/general/main/test_cxx_general.cpp index 6fb8f8fb13..eb1a544775 100644 --- a/components/cxx/test_apps/general/main/test_cxx_general.cpp +++ b/components/cxx/test_apps/general/main/test_cxx_general.cpp @@ -12,6 +12,7 @@ #include "esp_log.h" #include "unity.h" #include "unity_test_utils.h" +#include "soc/soc.h" extern "C" void setUp() { diff --git a/components/driver/i2s/i2s_common.c b/components/driver/i2s/i2s_common.c index 4c4ebbb626..4a3f8e75be 100644 --- a/components/driver/i2s/i2s_common.c +++ b/components/driver/i2s/i2s_common.c @@ -46,6 +46,7 @@ #include "esp_attr.h" #include "esp_rom_gpio.h" +#include "esp_memory_utils.h" /* The actual max size of DMA buffer is 4095 * Set 4092 here to align with 4-byte, so that the position of the slot data in the buffer will be relatively fixed */ diff --git a/components/driver/pulse_cnt.c b/components/driver/pulse_cnt.c index 2ca41f2ec6..c40d9f8a9c 100644 --- a/components/driver/pulse_cnt.c +++ b/components/driver/pulse_cnt.c @@ -30,6 +30,7 @@ #include "esp_private/periph_ctrl.h" #include "driver/gpio.h" #include "driver/pulse_cnt.h" +#include "esp_memory_utils.h" // If ISR handler is allowed to run whilst cache is disabled, // Make sure all the code and related variables used by the handler are in the SRAM diff --git a/components/driver/rmt/rmt_rx.c b/components/driver/rmt/rmt_rx.c index 380d63e30e..e38ab7231f 100644 --- a/components/driver/rmt/rmt_rx.c +++ b/components/driver/rmt/rmt_rx.c @@ -16,6 +16,7 @@ #endif #include "esp_log.h" #include "esp_check.h" +#include "esp_memory_utils.h" #include "esp_rom_gpio.h" #include "soc/rmt_periph.h" #include "soc/rtc.h" diff --git a/components/driver/rmt/rmt_tx.c b/components/driver/rmt/rmt_tx.c index 4f688618c9..3bd09da52b 100644 --- a/components/driver/rmt/rmt_tx.c +++ b/components/driver/rmt/rmt_tx.c @@ -24,6 +24,7 @@ #include "driver/gpio.h" #include "driver/rmt_tx.h" #include "rmt_private.h" +#include "esp_memory_utils.h" static const char *TAG = "rmt"; diff --git a/components/driver/spi_slave_hd.c b/components/driver/spi_slave_hd.c index 65ab728d34..643629aead 100644 --- a/components/driver/spi_slave_hd.c +++ b/components/driver/spi_slave_hd.c @@ -5,6 +5,7 @@ */ #include "esp_log.h" +#include "esp_memory_utils.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/queue.h" diff --git a/components/driver/test_apps/legacy_timer_driver/main/test_legacy_timer.c b/components/driver/test_apps/legacy_timer_driver/main/test_legacy_timer.c index fbc31a251a..2fdd3dedf7 100644 --- a/components/driver/test_apps/legacy_timer_driver/main/test_legacy_timer.c +++ b/components/driver/test_apps/legacy_timer_driver/main/test_legacy_timer.c @@ -13,6 +13,7 @@ #include "esp_private/esp_clk.h" #include "soc/soc_caps.h" #include "esp_rom_sys.h" +#include "soc/soc.h" #define TEST_TIMER_RESOLUTION_HZ 1000000 // 1MHz resolution #define TIMER_DELTA 0.001 diff --git a/components/driver/twai.c b/components/driver/twai.c index 74e6c796d2..4e96929e2e 100644 --- a/components/driver/twai.c +++ b/components/driver/twai.c @@ -20,6 +20,7 @@ #include "esp_private/periph_ctrl.h" #include "driver/twai.h" #include "soc/soc_caps.h" +#include "soc/soc.h" #include "soc/twai_periph.h" #include "soc/gpio_sig_map.h" #include "hal/twai_hal.h" diff --git a/components/esp_adc/adc_continuous.c b/components/esp_adc/adc_continuous.c index df103a99d1..6fb8759c72 100644 --- a/components/esp_adc/adc_continuous.c +++ b/components/esp_adc/adc_continuous.c @@ -26,6 +26,7 @@ #include "hal/adc_types.h" #include "hal/adc_hal.h" #include "hal/dma_types.h" +#include "esp_memory_utils.h" //For DMA #if SOC_GDMA_SUPPORTED #include "esp_private/gdma.h" diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 0ba08d14b2..6598f3f181 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -3,7 +3,7 @@ idf_build_get_property(target IDF_TARGET) set(requires soc) set(priv_requires efuse spi_flash bootloader_support) -set(srcs "compare_set.c" "cpu.c" "esp_memory_utils.c") +set(srcs "cpu.c" "esp_memory_utils.c") if(NOT BOOTLOADER_BUILD) list(APPEND srcs "esp_clk.c" "clk_ctrl_os.c" diff --git a/components/esp_hw_support/compare_set.c b/components/esp_hw_support/compare_set.c deleted file mode 100644 index e3362ed826..0000000000 --- a/components/esp_hw_support/compare_set.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "compare_set.h" -#include "spinlock.h" -#include "soc/soc_caps.h" - -#if __XTENSA__ && SOC_SPIRAM_SUPPORTED - -static spinlock_t global_extram_lock = SPINLOCK_INITIALIZER; - -void compare_and_set_extram(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - uint32_t intlevel, old_value; - __asm__ __volatile__ ("rsil %0, " XTSTR(XCHAL_EXCM_LEVEL) "\n" - : "=r"(intlevel)); - - spinlock_acquire(&global_extram_lock, SPINLOCK_WAIT_FOREVER); - - old_value = *addr; - if (old_value == compare) { - *addr = *set; - } - - spinlock_release(&global_extram_lock); - - __asm__ __volatile__ ("memw \n" - "wsr %0, ps\n" - :: "r"(intlevel)); - - *set = old_value; -} -#else // __XTENSA__ && SOC_SPIRAM_SUPPORTED - -void compare_and_set_extram(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - compare_and_set_native(addr, compare, set); -} -#endif // endif diff --git a/components/esp_hw_support/include/compare_set.h b/components/esp_hw_support/include/compare_set.h deleted file mode 100644 index c289c0ce85..0000000000 --- a/components/esp_hw_support/include/compare_set.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include -#include "esp_attr.h" -#include "esp_cpu.h" -#include "esp_memory_utils.h" -#include "hal/cpu_hal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static inline void __attribute__((always_inline)) compare_and_set_native(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - cpu_ll_compare_and_set_native(addr, compare, set); -} - -void compare_and_set_extram(volatile uint32_t *addr, uint32_t compare, uint32_t *set); - -#ifdef __cplusplus -} -#endif diff --git a/components/esp_hw_support/intr_alloc.c b/components/esp_hw_support/intr_alloc.c index 1801f483c9..c08edafedf 100644 --- a/components/esp_hw_support/intr_alloc.c +++ b/components/esp_hw_support/intr_alloc.c @@ -17,6 +17,7 @@ #include "freertos/task.h" #include "esp_err.h" #include "esp_log.h" +#include "esp_memory_utils.h" #include "esp_intr_alloc.h" #include "esp_attr.h" #include "hal/cpu_hal.h" diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 14e606f3db..b8164327e7 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -10,6 +10,7 @@ #include #include "esp_attr.h" +#include "esp_memory_utils.h" #include "esp_sleep.h" #include "esp_private/esp_timer_private.h" #include "esp_private/system_internal.h" diff --git a/components/esp_serial_slave_link/essl_spi.c b/components/esp_serial_slave_link/essl_spi.c index acf41d6048..4a6ece1a1a 100644 --- a/components/esp_serial_slave_link/essl_spi.c +++ b/components/esp_serial_slave_link/essl_spi.c @@ -8,6 +8,7 @@ #include #include "esp_log.h" #include "esp_check.h" +#include "esp_memory_utils.h" #include "driver/spi_master.h" #include "esp_private/periph_ctrl.h" #include "essl_internal.h" diff --git a/components/fatfs/test/test_fatfs_spiflash.c b/components/fatfs/test/test_fatfs_spiflash.c index 9dcd3cb208..19c33c0440 100644 --- a/components/fatfs/test/test_fatfs_spiflash.c +++ b/components/fatfs/test/test_fatfs_spiflash.c @@ -21,6 +21,7 @@ #include "test_fatfs_common.h" #include "wear_levelling.h" #include "esp_partition.h" +#include "esp_memory_utils.h" #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h index 5ef1066124..75ea18bd30 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h @@ -13,6 +13,7 @@ #include "esp_macros.h" #include "hal/cpu_hal.h" #include "esp_private/crosscore_int.h" +#include "esp_memory_utils.h" #ifdef __cplusplus extern "C" { @@ -241,42 +242,6 @@ static inline BaseType_t xPortInIsrContext(void) // Added for backward compatibility with IDF #define xPortInterruptedFromISRContext() xPortInIsrContext() -// ---------------------- Spinlocks ------------------------ - -/** - * @brief Wrapper for atomic compare-and-set instruction - * - * @note Isn't a real atomic CAS. - * @note [refactor-todo] check if we still need this - * @note [refactor-todo] Check if this function should be renamed (due to void return type) - * - * @param[inout] addr Pointer to target address - * @param[in] compare Compare value - * @param[inout] set Pointer to set value - */ -static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - compare_and_set_native(addr, compare, set); -} - -/** - * @brief Wrapper for atomic compare-and-set instruction in external RAM - * - * @note Isn't a real atomic CAS. - * @note [refactor-todo] check if we still need this - * @note [refactor-todo] Check if this function should be renamed (due to void return type) - * - * @param[inout] addr Pointer to target address - * @param[in] compare Compare value - * @param[inout] set Pointer to set value - */ -static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ -#if defined(CONFIG_SPIRAM) - compare_and_set_extram(addr, compare, set); -#endif -} - // ------------------ Critical Sections -------------------- /* diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c index f8ff4bf047..59396d055e 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c @@ -26,7 +26,7 @@ #include "FreeRTOS.h" /* This pulls in portmacro.h */ #include "task.h" #include "portmacro.h" - +#include "esp_memory_utils.h" #ifdef CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER #include "soc/periph_defs.h" #include "soc/system_reg.h" diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/portmacro.h index 87d87c99b3..eda0426af0 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/portmacro.h @@ -17,8 +17,8 @@ #include "portbenchmark.h" #include "esp_macros.h" #include "hal/cpu_hal.h" -#include "compare_set.h" /* For compare_and_set_native(). [refactor-todo] Use esp_cpu.h instead */ #include "esp_private/crosscore_int.h" +#include "esp_memory_utils.h" /* Note: We should not include any FreeRTOS headers (directly or indirectly) here as this will create a reverse dependency @@ -285,18 +285,6 @@ static inline void vPortClearInterruptMaskFromISR(UBaseType_t prev_level) // ---------------------- Spinlocks ------------------------ -static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - compare_and_set_native(addr, compare, set); -} - -static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ -#if defined(CONFIG_SPIRAM) - compare_and_set_extram(addr, compare, set); -#endif -} - static inline bool __attribute__((always_inline)) vPortCPUAcquireMutexTimeout(portMUX_TYPE *mux, int timeout) { return (spinlock_acquire(mux, timeout)); diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c index 96c232fab2..5aaf57312a 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c @@ -28,6 +28,7 @@ #include "esp_heap_caps_init.h" #include "esp_freertos_hooks.h" #include "esp_intr_alloc.h" +#include "esp_memory_utils.h" #if CONFIG_SPIRAM /* Required by esp_psram_extram_reserve_dma_pool() */ #include "esp_psram.h" diff --git a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h index 7d1a35f751..ed8f61f597 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h @@ -50,7 +50,6 @@ #include "esp_heap_caps.h" #include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */ #include "esp_newlib.h" -#include "compare_set.h" /* For compare_and_set_native(). [refactor-todo] Use esp_cpu.h instead */ /* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */ #include @@ -182,32 +181,6 @@ typedef struct { (mux)->count = 0; \ }) -/** - * @brief Wrapper for atomic compare-and-set instruction - * - * @note Isn't a real atomic CAS. - * @note [refactor-todo] check if we still need this - * @note [refactor-todo] Check if this function should be renamed (due to void return type) - * - * @param[inout] addr Pointer to target address - * @param[in] compare Compare value - * @param[inout] set Pointer to set value - */ -static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set); - -/** - * @brief Wrapper for atomic compare-and-set instruction in external RAM - * - * @note Isn't a real atomic CAS. - * @note [refactor-todo] check if we still need this - * @note [refactor-todo] Check if this function should be renamed (due to void return type) - * - * @param[inout] addr Pointer to target address - * @param[in] compare Compare value - * @param[inout] set Pointer to set value - */ -static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set); - // ------------------ Critical Sections -------------------- /** @@ -434,22 +407,6 @@ FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void) // --------------------- Interrupts ------------------------ - - -// ---------------------- Spinlocks ------------------------ - -static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - compare_and_set_native(addr, compare, set); -} - -static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ -#if defined(CONFIG_SPIRAM) - compare_and_set_extram(addr, compare, set); -#endif -} - // ---------------------- Yielding ------------------------- FORCE_INLINE_ATTR bool xPortCanYield(void) diff --git a/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c b/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c index f036e72bb6..c493ded1f2 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c +++ b/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c @@ -55,6 +55,7 @@ #include "task.h" #include "portmacro.h" #include "port_systick.h" +#include "esp_memory_utils.h" diff --git a/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h index 1232ba4902..14bdd9d98b 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h @@ -76,11 +76,12 @@ #include "esp_private/crosscore_int.h" #include "esp_macros.h" #include "esp_attr.h" +#include "esp_cpu.h" +#include "esp_memory_utils.h" #include "esp_newlib.h" /* required for esp_reent_init() in tasks.c */ #include "esp_heap_caps.h" #include "esp_rom_sys.h" #include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */ -#include "compare_set.h" /* For compare_and_set_native(). [refactor-todo] Use esp_cpu.h instead */ #include "portbenchmark.h" /* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */ @@ -405,38 +406,6 @@ void vPortSetStackWatchpoint( void *pxStackStart ); */ FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void); -/** - * @brief Wrapper for atomic compare-and-set instruction - * - * This subroutine will atomically compare *addr to 'compare'. If *addr == compare, *addr is set to *set. *set is - * updated with the previous value of *addr (either 'compare' or some other value.) - * - * @warning From the ISA docs: in some (unspecified) cases, the s32c1i instruction may return the "bitwise inverse" of - * the old mem if the mem wasn't written. This doesn't seem to happen on the ESP32 (portMUX assertions would - * fail). - * - * @note [refactor-todo] Check if this can be deprecated - * @note [refactor-todo] Check if this function should be renamed (due to void return type) - * - * @param[inout] addr Pointer to target address - * @param[in] compare Compare value - * @param[inout] set Pointer to set value - */ -static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set); - -/** - * @brief Wrapper for atomic compare-and-set instruction in external RAM - * - * Atomic compare-and-set but the target address is placed in external RAM - * - * @note [refactor-todo] Check if this can be deprecated - * - * @param[inout] addr Pointer to target address - * @param[in] compare Compare value - * @param[inout] set Pointer to set value - */ -static inline void __attribute__((always_inline)) uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set); - /* ------------------------------------------- FreeRTOS Porting Interface ---------------------------------------------- @@ -661,18 +630,6 @@ FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void) return (BaseType_t) cpu_hal_get_core_id(); } -static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ - compare_and_set_native(addr, compare, set); -} - -static inline void __attribute__((always_inline)) uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set) -{ -#ifdef CONFIG_SPIRAM - compare_and_set_extram(addr, compare, set); -#endif -} - /* ------------------------------------------------------ Misc --------------------------------------------------------- diff --git a/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c index dbe89951c7..0a631d2172 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c @@ -75,6 +75,7 @@ #include "task.h" /* Required for TaskHandle_t, tskNO_AFFINITY, and vTaskStartScheduler */ #include "port_systick.h" #include "esp_cpu.h" +#include "esp_memory_utils.h" _Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "incorrect tskNO_AFFINITY value"); diff --git a/components/lwip/port/esp32/hooks/tcp_isn_default.c b/components/lwip/port/esp32/hooks/tcp_isn_default.c index cde69ea043..14a2f5681e 100644 --- a/components/lwip/port/esp32/hooks/tcp_isn_default.c +++ b/components/lwip/port/esp32/hooks/tcp_isn_default.c @@ -75,6 +75,7 @@ #include "lwip/sys.h" #include #include "esp_rom_md5.h" +#include "esp_memory_utils.h" #ifdef CONFIG_LWIP_HOOK_TCP_ISN_DEFAULT diff --git a/components/mbedtls/port/aes/dma/esp_aes.c b/components/mbedtls/port/aes/dma/esp_aes.c index e899bee1da..4b952dbff3 100644 --- a/components/mbedtls/port/aes/dma/esp_aes.c +++ b/components/mbedtls/port/aes/dma/esp_aes.c @@ -34,6 +34,7 @@ #include "esp_attr.h" #include "soc/lldesc.h" #include "esp_heap_caps.h" +#include "esp_memory_utils.h" #include "sys/param.h" #if CONFIG_PM_ENABLE #include "esp_pm.h" diff --git a/components/mbedtls/port/sha/dma/sha.c b/components/mbedtls/port/sha/dma/sha.c index 146cf088af..cfb09603d1 100644 --- a/components/mbedtls/port/sha/dma/sha.c +++ b/components/mbedtls/port/sha/dma/sha.c @@ -30,6 +30,7 @@ #include #include "esp_log.h" +#include "esp_memory_utils.h" #include "esp_crypto_lock.h" #include "esp_attr.h" #include "soc/lldesc.h" diff --git a/components/mbedtls/port/sha/parallel_engine/sha.c b/components/mbedtls/port/sha/parallel_engine/sha.c index c2bd5c6984..8c025d707a 100644 --- a/components/mbedtls/port/sha/parallel_engine/sha.c +++ b/components/mbedtls/port/sha/parallel_engine/sha.c @@ -32,6 +32,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" +#include "esp_cpu.h" #include "hal/sha_hal.h" #include "hal/sha_types.h" @@ -106,7 +107,6 @@ static SemaphoreHandle_t sha_get_engine_state(esp_sha_type sha_type) unsigned idx = sha_engine_index(sha_type); volatile SemaphoreHandle_t *engine = &engine_states[idx]; SemaphoreHandle_t result = *engine; - uint32_t set_engine = 0; if (result == NULL) { // Create a new semaphore for 'in use' flag @@ -115,10 +115,8 @@ static SemaphoreHandle_t sha_get_engine_state(esp_sha_type sha_type) xSemaphoreGive(new_engine); // start available // try to atomically set the previously NULL *engine to new_engine - set_engine = (uint32_t)new_engine; - uxPortCompareSet((volatile uint32_t *)engine, 0, &set_engine); - - if (set_engine != 0) { // we lost a race setting *engine + if (!esp_cpu_compare_and_set((volatile uint32_t *)engine, 0, (uint32_t)new_engine)) { + // we lost a race setting *engine vSemaphoreDelete(new_engine); } result = *engine; diff --git a/components/mbedtls/test/test_aes.c b/components/mbedtls/test/test_aes.c index b0d76b4da9..4d5e4872d9 100644 --- a/components/mbedtls/test/test_aes.c +++ b/components/mbedtls/test/test_aes.c @@ -15,6 +15,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "esp_memory_utils.h" static const uint8_t key_256[] = { diff --git a/components/mbedtls/test/test_mbedtls_sha.c b/components/mbedtls/test/test_mbedtls_sha.c index aebc624c96..0682c61a9c 100644 --- a/components/mbedtls/test/test_mbedtls_sha.c +++ b/components/mbedtls/test/test_mbedtls_sha.c @@ -22,6 +22,7 @@ #include "test_apb_dport_access.h" #include "soc/soc_caps.h" #include "test_utils.h" +#include "esp_memory_utils.h" TEST_CASE("mbedtls SHA self-tests", "[mbedtls]") { diff --git a/components/pthread/pthread.c b/components/pthread/pthread.c index f93b97404c..a48f59d30d 100644 --- a/components/pthread/pthread.c +++ b/components/pthread/pthread.c @@ -10,6 +10,7 @@ #include #include "esp_err.h" #include "esp_attr.h" +#include "esp_cpu.h" #include "sys/queue.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -493,18 +494,8 @@ int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) return EINVAL; } - uint32_t res = 1; -#if defined(CONFIG_SPIRAM) - if (esp_ptr_external_ram(once_control)) { - uxPortCompareSetExtram((uint32_t *) &once_control->init_executed, 0, &res); - } else { -#endif - uxPortCompareSet((uint32_t *) &once_control->init_executed, 0, &res); -#if defined(CONFIG_SPIRAM) - } -#endif // Check if compare and set was successful - if (res == 0) { + if (esp_cpu_compare_and_set((volatile uint32_t *)&once_control->init_executed, 0, 1)) { ESP_LOGV(TAG, "%s: call init_routine %p", __FUNCTION__, once_control); init_routine(); } diff --git a/components/spi_flash/cache_utils.c b/components/spi_flash/cache_utils.c index e910979bc3..89bb53e8fc 100644 --- a/components/spi_flash/cache_utils.c +++ b/components/spi_flash/cache_utils.c @@ -43,6 +43,7 @@ #include "esp_ipc.h" #endif #include "esp_attr.h" +#include "esp_memory_utils.h" #include "esp_intr_alloc.h" #include "spi_flash_mmap.h" #include "esp_log.h" diff --git a/components/spi_flash/flash_mmap.c b/components/spi_flash/flash_mmap.c index 2a6eb3ce0d..fd4a5e17e5 100644 --- a/components/spi_flash/flash_mmap.c +++ b/components/spi_flash/flash_mmap.c @@ -15,6 +15,7 @@ #include "soc/mmu.h" #include "sdkconfig.h" #include "esp_attr.h" +#include "esp_memory_utils.h" #include "spi_flash_mmap.h" #include "esp_flash_encrypt.h" #include "esp_log.h" diff --git a/components/spi_flash/test/test_cache_disabled.c b/components/spi_flash/test/test_cache_disabled.c index afafe6461a..a8467e54df 100644 --- a/components/spi_flash/test/test_cache_disabled.c +++ b/components/spi_flash/test/test_cache_disabled.c @@ -15,6 +15,7 @@ #include #include #include +#include "esp_memory_utils.h" #include "esp_private/cache_utils.h" diff --git a/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c b/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c index 86ae68aae0..89cef45198 100644 --- a/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c +++ b/examples/peripherals/timer_group/legacy_driver/main/timer_group_example_main.c @@ -5,6 +5,7 @@ */ #include +#include "soc/soc.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h"