1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

PIOS SPI: Added a function to detect if the channel is busy

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1829 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
les 2010-10-01 16:52:20 +00:00 committed by les
parent d2c1014e29
commit 498f3d0fa6
2 changed files with 547 additions and 511 deletions

View File

@ -416,6 +416,41 @@ int32_t PIOS_SPI_TransferBlock(uint8_t spi, const uint8_t * send_buffer, uint8_t
return 0;
}
/**
* Check if a transfer is in progress
* \param[in] spi SPI number (0 or 1)
* \return >= 0 if no transfer is in progress
* \return -1 if disabled SPI port selected
* \return -2 if unsupported SPI port selected
* \return -3 if function has been called during an ongoing DMA transfer
*/
int32_t PIOS_SPI_Busy(uint8_t spi)
{
struct pios_spi_dev * spi_dev;
/* Get a handle for the device configuration */
spi_dev = find_spi_dev_by_id(spi);
if (!spi_dev) {
/* Undefined SPI port for this board (see pios_board.c) */
return -2;
}
/* DMA buffer has data or SPI transmit register not empty or SPI is busy*/
if (DMA_GetCurrDataCounter(spi_dev->cfg->dma.rx.channel) ||
!SPI_I2S_GetFlagStatus(spi_dev->cfg->regs, SPI_I2S_FLAG_TXE) ||
SPI_I2S_GetFlagStatus(spi_dev->cfg->regs, SPI_I2S_FLAG_BSY))
{
return -3;
}
return(0);
}
void PIOS_SPI_IRQ_Handler(uint8_t spi)
{
struct pios_spi_dev *spi_dev;

View File

@ -49,6 +49,7 @@ extern int32_t PIOS_SPI_SetClockSpeed(uint8_t spi, SPIPrescalerTypeDef spi_presc
extern int32_t PIOS_SPI_RC_PinSet(uint8_t spi, uint8_t pin_value);
extern int32_t PIOS_SPI_TransferByte(uint8_t spi, uint8_t b);
extern int32_t PIOS_SPI_TransferBlock(uint8_t spi, const uint8_t * send_buffer, uint8_t * receive_buffer, uint16_t len, void *callback);
extern int32_t PIOS_SPI_Busy(uint8_t spi);
extern void PIOS_SPI_IRQ_Handler(uint8_t spi);
#endif /* PIOS_SPI_H */