Skip to content

Commit

Permalink
modified mxc_lock.c to be portable
Browse files Browse the repository at this point in the history
  • Loading branch information
EricB-ADI committed Oct 24, 2024
1 parent 1d05e78 commit 11baedc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 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-307-gf557dbf1716
MSDK_VERSION_STRING := v2023_10-309-g1d05e78b5aa
MSDK_VERSION_YEAR := 2023
MSDK_VERSION_MONTH := 10

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

0 comments on commit 11baedc

Please sign in to comment.