forked from Archive/PX4-Autopilot
Standardize AFBR irq lock calls
This commit is contained in:
parent
3398380262
commit
ba1b6f4d2c
|
@ -138,22 +138,23 @@ status_t S2PI_SetBaudRate(uint32_t baudRate_Bps)
|
|||
status_t S2PI_CaptureGpioControl(void)
|
||||
{
|
||||
/* Check if something is ongoing. */
|
||||
irqstate_t irqstate_flags = px4_enter_critical_section();
|
||||
IRQ_LOCK();
|
||||
status_t status = s2pi_.Status;
|
||||
|
||||
if (status != STATUS_IDLE) {
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
IRQ_UNLOCK();
|
||||
return status;
|
||||
}
|
||||
|
||||
s2pi_.Status = STATUS_S2PI_GPIO_MODE;
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
|
||||
// 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_MISO]));
|
||||
px4_arch_configgpio(PX4_MAKE_GPIO_INPUT(s2pi_.GPIOs[S2PI_MISO]));
|
||||
px4_arch_configgpio(PX4_MAKE_GPIO_OUTPUT_SET(s2pi_.GPIOs[S2PI_MOSI]));
|
||||
|
||||
IRQ_UNLOCK();
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
|
@ -167,16 +168,15 @@ status_t S2PI_CaptureGpioControl(void)
|
|||
status_t S2PI_ReleaseGpioControl(void)
|
||||
{
|
||||
/* Check if something is ongoing. */
|
||||
irqstate_t irqstate_flags = px4_enter_critical_section();
|
||||
IRQ_LOCK();
|
||||
status_t status = s2pi_.Status;
|
||||
|
||||
if (status != STATUS_S2PI_GPIO_MODE) {
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
IRQ_UNLOCK();
|
||||
return status;
|
||||
}
|
||||
|
||||
s2pi_.Status = STATUS_IDLE;
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
|
||||
// SPI alternate
|
||||
stm32_configgpio(s2pi_.GPIOs[S2PI_CLK]);
|
||||
|
@ -186,6 +186,8 @@ status_t S2PI_ReleaseGpioControl(void)
|
|||
// probably not necessary
|
||||
stm32_spibus_initialize(BROADCOM_AFBR_S50_S2PI_SPI_BUS);
|
||||
|
||||
IRQ_UNLOCK();
|
||||
|
||||
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)
|
||||
{
|
||||
/* Check the driver status. */
|
||||
irqstate_t irqstate_flags = px4_enter_critical_section();
|
||||
IRQ_LOCK();
|
||||
status_t status = s2pi_.Status;
|
||||
|
||||
if (status != STATUS_IDLE) {
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
IRQ_UNLOCK();
|
||||
return status;
|
||||
}
|
||||
|
||||
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], 1);
|
||||
|
||||
s2pi_.Status = STATUS_IDLE;
|
||||
|
||||
IRQ_UNLOCK();
|
||||
|
||||
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. */
|
||||
irqstate_t irqstate_flags = px4_enter_critical_section();
|
||||
IRQ_LOCK();
|
||||
status_t status = s2pi_.Status;
|
||||
|
||||
if (status != STATUS_IDLE) {
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
IRQ_UNLOCK();
|
||||
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;
|
||||
work_queue(HPWORK, &broadcom_s2pi_transfer_work, broadcom_s2pi_transfer_callout, NULL, 0);
|
||||
|
||||
px4_leave_critical_section(irqstate_flags);
|
||||
IRQ_UNLOCK();
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue