Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hal] SPI: fixes threading safty issue #2865

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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