From 4a2dcaa2fa18ad16207d496dbfcdbf85ec70c2e8 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Thu, 8 Aug 2024 11:17:48 -0400 Subject: [PATCH] https://github.com/rusefi/rusefi/issues/6781 macro hook allowing consumers to limit loops --- os/hal/include/hal.h | 1 + os/hal/include/limited_wait.h | 6 ++++++ os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c | 6 ++---- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 os/hal/include/limited_wait.h diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index 913da1104..6e825471e 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -28,6 +28,7 @@ #include "osal.h" #include "board.h" #include "halconf.h" +#include "limited_wait.h" /* Error checks on the configuration header file.*/ #if !defined(HAL_USE_PAL) diff --git a/os/hal/include/limited_wait.h b/os/hal/include/limited_wait.h new file mode 100644 index 000000000..e66210ab2 --- /dev/null +++ b/os/hal/include/limited_wait.h @@ -0,0 +1,6 @@ +#pragma once + +// this hook allows rusEFI to fail gracefully instead of on hanging +#ifndef LIMITED_WHILE_LOOP +#define LIMITED_WHILE_LOOP(msg, condition) { (void)msg ; while (condition) ; } +#endif diff --git a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c index 02bc9a07b..686403b31 100644 --- a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c @@ -703,14 +703,12 @@ uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) { SPI_CR2_DS_0)) { volatile uint8_t *spidr = (volatile uint8_t *)&spip->spi->DR; *spidr = (uint8_t)frame; - while ((spip->spi->SR & SPI_SR_RXNE) == 0) - ; + LIMITED_WHILE_LOOP("SPI_SR_RXNE", (spip->spi->SR & SPI_SR_RXNE) == 0); return (uint16_t)*spidr; } else { spip->spi->DR = frame; - while ((spip->spi->SR & SPI_SR_RXNE) == 0) - ; + LIMITED_WHILE_LOOP("SPI_SR_RXNE", (spip->spi->SR & SPI_SR_RXNE) == 0); return spip->spi->DR; } }