From 11baedc4cd4aba871020accb37c36601c1d276a3 Mon Sep 17 00:00:00 2001 From: EricB-ADI <122300463+EricB-ADI@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:36:29 -0500 Subject: [PATCH] modified mxc_lock.c to be portable --- .../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, 14 insertions(+), 33 deletions(-) diff --git a/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk b/Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk index cde4ab47d1..224beac9ff 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-307-gf557dbf1716 +MSDK_VERSION_STRING := v2023_10-309-g1d05e78b5aa 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 1c1034c6df..04bf100823 100644 --- a/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c +++ b/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c @@ -22,21 +22,15 @@ #include "mxc_device.h" #include "mxc_lock.h" -#ifndef __riscv + /* ************************************************************************** */ int MXC_GetLock(uint32_t *lock, uint32_t value) { - 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); + while(*lock != 0) {} - // Do not start any other memory access until memory barrier is complete - __DMB(); + __disable_irq(); + *lock = 1; + __enable_irq(); return E_NO_ERROR; } @@ -45,20 +39,5 @@ 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 5376d62a91..38573bf637 100644 --- a/Libraries/PeriphDrivers/libPeriphDriver.mk +++ b/Libraries/PeriphDrivers/libPeriphDriver.mk @@ -65,12 +65,10 @@ 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 "$(RISCV_CORE)" "1" -ifneq "$(RISCV_CORE)" "RV32" -# ^ NOTE(JC): Some legacy Makefiles use "RV32". We recommend using "1" in the UG +ifneq "$(TARGET)" "MAX780002" 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 7add3b5bef..95d7b39749 100644 --- a/Libraries/PeriphDrivers/max78002_files.mk +++ b/Libraries/PeriphDrivers/max78002_files.mk @@ -49,8 +49,12 @@ 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