From 5dab6a1d111834a8e4bc66085303a796f90affa5 Mon Sep 17 00:00:00 2001 From: EricB-ADI <122300463+EricB-ADI@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:41:23 -0500 Subject: [PATCH] Revert "modified mxc_lock.c to be portable" This reverts commit 11baedc4cd4aba871020accb37c36601c1d276a3. --- .../CMSIS/Device/Maxim/GCC/mxc_version.mk | 2 +- Libraries/PeriphDrivers/Source/SYS/mxc_lock.c | 31 ++++++++++++++++--- Libraries/PeriphDrivers/libPeriphDriver.mk | 6 ++-- Libraries/PeriphDrivers/max78002_files.mk | 8 ++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk b/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk index 224beac9ff0..cde4ab47d13 100644 --- a/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk +++ b/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk @@ -16,7 +16,7 @@ # ############################################################################## # Autogenerated version info for build system. -MSDK_VERSION_STRING := v2023_10-309-g1d05e78b5aa +MSDK_VERSION_STRING := v2023_10-307-gf557dbf1716 MSDK_VERSION_YEAR := 2023 MSDK_VERSION_MONTH := 10 diff --git a/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c b/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c index 04bf100823a..1c1034c6df2 100644 --- a/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c +++ b/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c @@ -22,15 +22,21 @@ #include "mxc_device.h" #include "mxc_lock.h" - +#ifndef __riscv /* ************************************************************************** */ int MXC_GetLock(uint32_t *lock, uint32_t value) { - while(*lock != 0) {} + do { + // Return if the lock is taken by a different thread + if (__LDREXW((volatile uint32_t *)lock) != 0) { + return E_BUSY; + } + + // Attempt to take the lock + } while (__STREXW(value, (volatile uint32_t *)lock) != 0); - __disable_irq(); - *lock = 1; - __enable_irq(); + // Do not start any other memory access until memory barrier is complete + __DMB(); return E_NO_ERROR; } @@ -39,5 +45,20 @@ int MXC_GetLock(uint32_t *lock, uint32_t value) void MXC_FreeLock(uint32_t *lock) { // Ensure memory operations complete before releasing lock + __DMB(); *lock = 0; } +#else // __riscv +/* ************************************************************************** */ +int MXC_GetLock(uint32_t *lock, uint32_t value) +{ +#warning "Unimplemented for RISCV" + return E_NO_ERROR; +} + +/* ************************************************************************** */ +void MXC_FreeLock(uint32_t *lock) +{ +#warning "Unimplemented for RISCV" +} +#endif diff --git a/Libraries/PeriphDrivers/libPeriphDriver.mk b/Libraries/PeriphDrivers/libPeriphDriver.mk index 38573bf6378..5376d62a917 100644 --- a/Libraries/PeriphDrivers/libPeriphDriver.mk +++ b/Libraries/PeriphDrivers/libPeriphDriver.mk @@ -65,10 +65,12 @@ PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_assert.c PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_delay.c PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/nvic_table.c # TODO(JC): Implement mxc_lock for RISC-V. Skip for now. -ifneq "$(TARGET)" "MAX780002" +ifneq "$(RISCV_CORE)" "1" +ifneq "$(RISCV_CORE)" "RV32" +# ^ NOTE(JC): Some legacy Makefiles use "RV32". We recommend using "1" in the UG PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_lock.c endif - +endif # # Where to find header files for this project IPATH += $(PERIPH_DRIVER_INCLUDE_DIR) diff --git a/Libraries/PeriphDrivers/max78002_files.mk b/Libraries/PeriphDrivers/max78002_files.mk index 95d7b397499..7add3b5bef2 100644 --- a/Libraries/PeriphDrivers/max78002_files.mk +++ b/Libraries/PeriphDrivers/max78002_files.mk @@ -49,12 +49,8 @@ PERIPH_DRIVER_INCLUDE_DIR += $(INCLUDE_DIR)/$(TARGET_UC)/ PINS_FILE ?= $(SOURCE_DIR)/SYS/pins_ai87.c # Source files -ifneq "$(RISCV_CORE)" "1" -ifneq "$(RISCV_CORE)" "RV32" -# ^ NOTE(JC): Some legacy Makefiles use "RV32". We recommend using "1" in the UG -PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_lock.c -endif -endif + + PERIPH_DRIVER_C_FILES += $(PINS_FILE) PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/sys_ai87.c