fix(radio): race condition on pulse buffer (#6634)

This commit is contained in:
Raphael Coeffic
2025-10-14 20:42:41 +10:00
committed by GitHub
parent 2cbd995f35
commit dd029bc591
22 changed files with 73 additions and 6 deletions
@@ -274,6 +274,13 @@ static void set_oc_mode(const stm32_pulse_timer_t* tim, uint32_t ocmode)
LL_TIM_OC_SetMode(tim->TIMx, channel, ocmode);
}
bool stm32_pulse_is_completed(const stm32_pulse_timer_t* tim)
{
uint32_t channel = _get_base_channel(tim->TIM_Channel);
return !LL_TIM_IsEnabledCounter(tim->TIMx) ||
LL_TIM_OC_GetMode(tim->TIMx, channel) == LL_TIM_OCMODE_FORCED_INACTIVE;
}
void stm32_pulse_wait_for_completed(const stm32_pulse_timer_t* tim)
{
uint32_t channel = _get_base_channel(tim->TIM_Channel);
@@ -69,6 +69,7 @@ void stm32_pulse_set_cmp_val(const stm32_pulse_timer_t* tim, uint32_t cmp_val);
void stm32_pulse_start(const stm32_pulse_timer_t* tim);
void stm32_pulse_stop(const stm32_pulse_timer_t* tim);
bool stm32_pulse_is_completed(const stm32_pulse_timer_t* tim);
void stm32_pulse_wait_for_completed(const stm32_pulse_timer_t* tim);
// return true if it could be disabled without interrupting a pulse train, false otherwise
@@ -383,7 +383,7 @@ static void stm32_serial_send_buffer(void* ctx, const uint8_t* data, uint32_t si
}
}
static uint8_t stm32_serial_tx_completed(void* ctx)
static bool stm32_serial_tx_completed(void* ctx)
{
auto st = (stm32_serial_state*)ctx;
if (!st) return 1;
@@ -494,6 +494,13 @@ static void stm32_softserial_tx_send_buffer(void* ctx, const uint8_t* data, uint
stm32_pulse_start_dma_req(timer, pulses, length, ocmode, cmp_val);
}
static bool stm32_softserial_tx_completed(void* ctx)
{
auto port = (const stm32_softserial_tx_port*)ctx;
auto timer = port->tim;
return stm32_pulse_is_completed(timer);
}
void stm32_softserial_set_polarity(void* ctx, uint8_t polarity)
{
auto port = (const stm32_softserial_tx_port*)ctx;
@@ -507,7 +514,7 @@ const etx_serial_driver_t STM32SoftSerialTxDriver = {
.deinit = stm32_softserial_tx_deinit,
.sendByte = stm32_softserial_tx_send_byte,
.sendBuffer = stm32_softserial_tx_send_buffer,
.txCompleted = nullptr,
.txCompleted = stm32_softserial_tx_completed,
.waitForTxCompleted = stm32_softserial_tx_wait,
.enableRx = nullptr, // TODO: combine with EXTI / Timer implementation? (S.PORT INV RX)
.getByte = nullptr,
+2 -1
View File
@@ -86,6 +86,7 @@ static void deinit(void* ctx)
static void sendByte(void*, uint8_t) {}
static void sendBuffer(void*, const uint8_t*, uint32_t) {}
static bool txCompleted(void*) { return true; }
static void waitForTxCompleted(void*) {}
static int getByte(void*,uint8_t*) { return -1; }
@@ -94,7 +95,7 @@ const etx_serial_driver_t _fakeSerialDriver = {
.deinit = deinit,
.sendByte = sendByte,
.sendBuffer = sendBuffer,
.txCompleted = nullptr,
.txCompleted = txCompleted,
.waitForTxCompleted = waitForTxCompleted,
.enableRx = nullptr,
.getByte = getByte,
+2 -1
View File
@@ -381,6 +381,7 @@ static void* null_drv_init(void* hw_def, const etx_serial_init* dev) { return nu
static void null_drv_deinit(void* ctx) { }
static void null_drv_send_byte(void* ctx, uint8_t b) { }
static void null_drv_send_buffer(void* ctx, const uint8_t* b, uint32_t l) { }
static bool null_drv_tx_completed(void* ctx) { return true; }
static int null_drv_get_byte(void* ctx, uint8_t* b) { return 0; }
static void null_drv_set_baudrate(void* ctx, uint32_t baudrate) { }
@@ -389,7 +390,7 @@ const etx_serial_driver_t null_drv = {
.deinit = null_drv_deinit,
.sendByte = null_drv_send_byte,
.sendBuffer = null_drv_send_buffer,
.txCompleted = nullptr,
.txCompleted = null_drv_tx_completed,
.waitForTxCompleted = nullptr,
.enableRx = nullptr,
.getByte = null_drv_get_byte,