Standardize AFBR irq lock calls

This commit is contained in:
alexklimaj 2022-09-12 11:24:33 -06:00 committed by Daniel Agar
parent 3398380262
commit ba1b6f4d2c
1 changed files with 16 additions and 13 deletions

View File

@ -138,22 +138,23 @@ status_t S2PI_SetBaudRate(uint32_t baudRate_Bps)
status_t S2PI_CaptureGpioControl(void) status_t S2PI_CaptureGpioControl(void)
{ {
/* Check if something is ongoing. */ /* Check if something is ongoing. */
irqstate_t irqstate_flags = px4_enter_critical_section(); IRQ_LOCK();
status_t status = s2pi_.Status; status_t status = s2pi_.Status;
if (status != STATUS_IDLE) { if (status != STATUS_IDLE) {
px4_leave_critical_section(irqstate_flags); IRQ_UNLOCK();
return status; return status;
} }
s2pi_.Status = STATUS_S2PI_GPIO_MODE; s2pi_.Status = STATUS_S2PI_GPIO_MODE;
px4_leave_critical_section(irqstate_flags);
// GPIO mode (output push pull) // GPIO mode (output push pull)
px4_arch_configgpio(PX4_MAKE_GPIO_OUTPUT_SET(s2pi_.GPIOs[S2PI_CLK])); px4_arch_configgpio(PX4_MAKE_GPIO_OUTPUT_SET(s2pi_.GPIOs[S2PI_CLK]));
px4_arch_configgpio(PX4_MAKE_GPIO_OUTPUT_SET(s2pi_.GPIOs[S2PI_MISO])); px4_arch_configgpio(PX4_MAKE_GPIO_INPUT(s2pi_.GPIOs[S2PI_MISO]));
px4_arch_configgpio(PX4_MAKE_GPIO_OUTPUT_SET(s2pi_.GPIOs[S2PI_MOSI])); px4_arch_configgpio(PX4_MAKE_GPIO_OUTPUT_SET(s2pi_.GPIOs[S2PI_MOSI]));
IRQ_UNLOCK();
return STATUS_OK; return STATUS_OK;
} }
@ -167,16 +168,15 @@ status_t S2PI_CaptureGpioControl(void)
status_t S2PI_ReleaseGpioControl(void) status_t S2PI_ReleaseGpioControl(void)
{ {
/* Check if something is ongoing. */ /* Check if something is ongoing. */
irqstate_t irqstate_flags = px4_enter_critical_section(); IRQ_LOCK();
status_t status = s2pi_.Status; status_t status = s2pi_.Status;
if (status != STATUS_S2PI_GPIO_MODE) { if (status != STATUS_S2PI_GPIO_MODE) {
px4_leave_critical_section(irqstate_flags); IRQ_UNLOCK();
return status; return status;
} }
s2pi_.Status = STATUS_IDLE; s2pi_.Status = STATUS_IDLE;
px4_leave_critical_section(irqstate_flags);
// SPI alternate // SPI alternate
stm32_configgpio(s2pi_.GPIOs[S2PI_CLK]); stm32_configgpio(s2pi_.GPIOs[S2PI_CLK]);
@ -186,6 +186,8 @@ status_t S2PI_ReleaseGpioControl(void)
// probably not necessary // probably not necessary
stm32_spibus_initialize(BROADCOM_AFBR_S50_S2PI_SPI_BUS); stm32_spibus_initialize(BROADCOM_AFBR_S50_S2PI_SPI_BUS);
IRQ_UNLOCK();
return STATUS_OK; return STATUS_OK;
} }
@ -254,22 +256,23 @@ status_t S2PI_ReadGpioPin(s2pi_slave_t slave, s2pi_pin_t pin, uint32_t *value)
status_t S2PI_CycleCsPin(s2pi_slave_t slave) status_t S2PI_CycleCsPin(s2pi_slave_t slave)
{ {
/* Check the driver status. */ /* Check the driver status. */
irqstate_t irqstate_flags = px4_enter_critical_section(); IRQ_LOCK();
status_t status = s2pi_.Status; status_t status = s2pi_.Status;
if (status != STATUS_IDLE) { if (status != STATUS_IDLE) {
px4_leave_critical_section(irqstate_flags); IRQ_UNLOCK();
return status; return status;
} }
s2pi_.Status = STATUS_BUSY; s2pi_.Status = STATUS_BUSY;
px4_leave_critical_section(irqstate_flags);
px4_arch_gpiowrite(s2pi_.GPIOs[S2PI_CS], 0); px4_arch_gpiowrite(s2pi_.GPIOs[S2PI_CS], 0);
px4_arch_gpiowrite(s2pi_.GPIOs[S2PI_CS], 1); px4_arch_gpiowrite(s2pi_.GPIOs[S2PI_CS], 1);
s2pi_.Status = STATUS_IDLE; s2pi_.Status = STATUS_IDLE;
IRQ_UNLOCK();
return STATUS_OK; return STATUS_OK;
} }
@ -339,11 +342,11 @@ status_t S2PI_TransferFrame(s2pi_slave_t spi_slave, uint8_t const *txData, uint8
} }
/* Check the driver status, lock if idle. */ /* Check the driver status, lock if idle. */
irqstate_t irqstate_flags = px4_enter_critical_section(); IRQ_LOCK();
status_t status = s2pi_.Status; status_t status = s2pi_.Status;
if (status != STATUS_IDLE) { if (status != STATUS_IDLE) {
px4_leave_critical_section(irqstate_flags); IRQ_UNLOCK();
return status; return status;
} }
@ -358,7 +361,7 @@ status_t S2PI_TransferFrame(s2pi_slave_t spi_slave, uint8_t const *txData, uint8
s2pi_.spi_frame_size = frameSize; s2pi_.spi_frame_size = frameSize;
work_queue(HPWORK, &broadcom_s2pi_transfer_work, broadcom_s2pi_transfer_callout, NULL, 0); work_queue(HPWORK, &broadcom_s2pi_transfer_work, broadcom_s2pi_transfer_callout, NULL, 0);
px4_leave_critical_section(irqstate_flags); IRQ_UNLOCK();
return STATUS_OK; return STATUS_OK;
} }