Skip to content

Commit

Permalink
Revert "modified mxc_lock.c to be portable"
Browse files Browse the repository at this point in the history
This reverts commit 11baedc.
  • Loading branch information
EricB-ADI committed Oct 24, 2024
1 parent 11baedc commit 5dab6a1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Libraries/CMSIS/Device/Maxim/GCC/mxc_version.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 26 additions & 5 deletions Libraries/PeriphDrivers/Source/SYS/mxc_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
6 changes: 4 additions & 2 deletions Libraries/PeriphDrivers/libPeriphDriver.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions Libraries/PeriphDrivers/max78002_files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5dab6a1

Please sign in to comment.