From 955472035d02c33aa3c7c97adfa4019d13c671ad Mon Sep 17 00:00:00 2001 From: EricB-ADI <122300463+EricB-ADI@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:00:22 -0500 Subject: [PATCH] added rv32 implementation for get lock --- Libraries/PeriphDrivers/Source/SYS/mxc_lock.c | 21 +++++++++++++++---- Libraries/PeriphDrivers/libPeriphDriver.mk | 6 ------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c b/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c index 1c1034c6df2..a5bde4832c7 100644 --- a/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c +++ b/Libraries/PeriphDrivers/Source/SYS/mxc_lock.c @@ -52,13 +52,26 @@ void MXC_FreeLock(uint32_t *lock) /* ************************************************************************** */ int MXC_GetLock(uint32_t *lock, uint32_t value) { -#warning "Unimplemented for RISCV" + + __disable_irq(); + if(*lock) + { + __enable_irq(); + return E_BUSY; + } + + *lock = value + + // Ensure memory ordering + __asm volatile("fence rw, rw"); + __enable_irq(); return E_NO_ERROR; } /* ************************************************************************** */ -void MXC_FreeLock(uint32_t *lock) -{ -#warning "Unimplemented for RISCV" +void MXC_FreeLock(uint32_t *lock) { + __asm volatile("fence" ::: "memory"); + *lock = 0; + } #endif diff --git a/Libraries/PeriphDrivers/libPeriphDriver.mk b/Libraries/PeriphDrivers/libPeriphDriver.mk index 5376d62a917..4bed4f12325 100644 --- a/Libraries/PeriphDrivers/libPeriphDriver.mk +++ b/Libraries/PeriphDrivers/libPeriphDriver.mk @@ -64,13 +64,7 @@ include ${CMSIS_ROOT}/../PeriphDrivers/$(TARGET_LC)_files.mk 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 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)