mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08:24:11 +01:00
PIOS SPI: Add a second claim bus method for use in ISR. This has no timeout
and uses an ISR safe queue claiming method. This avoids deadlocks when ISR blocks other tasks from freeing the bus.
This commit is contained in:
parent
ec903449cd
commit
ff0bd87f4e
@ -247,6 +247,27 @@ int32_t PIOS_SPI_ClaimBus(uint32_t spi_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim the SPI bus semaphore from an ISR. Has no timeout.
|
||||
* \param[in] spi SPI number (0 or 1)
|
||||
* \return 0 if no error
|
||||
* \return -1 if timeout before claiming semaphore
|
||||
*/
|
||||
int32_t PIOS_SPI_ClaimBusISR(uint32_t spi_id)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
struct pios_spi_dev * spi_dev = (struct pios_spi_dev *)spi_id;
|
||||
|
||||
bool valid = PIOS_SPI_validate(spi_dev);
|
||||
PIOS_Assert(valid)
|
||||
|
||||
if (xQueueGenericReceive(( xQueueHandle ) spi_dev->busy, NULL, 0x0000 , pdFALSE ) != pdTRUE)
|
||||
return -1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Release the SPI bus semaphore. Calling the SPI functions does not require this
|
||||
* \param[in] spi SPI number (0 or 1)
|
||||
|
@ -54,6 +54,7 @@ extern int32_t PIOS_SPI_TransferByte(uint32_t spi_id, uint8_t b);
|
||||
extern int32_t PIOS_SPI_TransferBlock(uint32_t spi_id, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len, void *callback);
|
||||
extern int32_t PIOS_SPI_Busy(uint32_t spi_id);
|
||||
extern int32_t PIOS_SPI_ClaimBus(uint32_t spi_id);
|
||||
extern int32_t PIOS_SPI_ClaimBusISR(uint32_t spi_id);
|
||||
extern int32_t PIOS_SPI_ReleaseBus(uint32_t spi_id);
|
||||
extern void PIOS_SPI_IRQ_Handler(uint32_t spi_id);
|
||||
extern void PIOS_SPI_SetPrescalar(uint32_t spi_id, uint32_t prescalar);
|
||||
|
Loading…
Reference in New Issue
Block a user