Skip to content

Commit

Permalink
Merge pull request #2865 from particle-iot/fix/spi_concurrent
Browse files Browse the repository at this point in the history
[hal] SPI: fixes threading safty issue
  • Loading branch information
XuGuohui authored Feb 19, 2025
2 parents 0e48bfe + f1e8c59 commit fd2baf7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions hal/src/rtl872x/spi_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,12 @@ class Spi {
return SYSTEM_ERROR_NONE;
}

int lock(system_tick_t timeout = 0) {
int lock(system_tick_t timeout = 1) {
CHECK_TRUE(hal_interrupt_is_isr() == false, SYSTEM_ERROR_INVALID_STATE);
// FIXME: os_mutex_recursive_lock doesn't take any arguments, using trylock for now
if (timeout) {
if (timeout != 0) {
return os_mutex_recursive_lock(mutex_);
}

return os_mutex_recursive_trylock(mutex_);
}

Expand Down Expand Up @@ -1219,6 +1218,9 @@ int hal_spi_sleep(hal_spi_interface_t spi, bool sleep, void* reserved) {

int32_t hal_spi_acquire(hal_spi_interface_t spi, const hal_spi_acquire_config_t* conf) {
auto spiInstance = CHECK_TRUE_RETURN(getInstance(spi), SYSTEM_ERROR_NOT_FOUND);
if (conf && conf->timeout == 0) {
return spiInstance->lock(0);
}
return spiInstance->lock();
}

Expand Down

0 comments on commit fd2baf7

Please sign in to comment.