SPI Peripheral#
SPI Peripheral Interface driver.
Flexible SPI Peripheral driver implementation for use in an NCP scenario.
This driver will support both blocking and non-blocking operation, with LDMA backing the background transfers to support nonblocking.
Functions#
Initialize the configured USART peripheral for the SPI peripheral operation.
Disable the configured USART peripheral for the SPI operation.
Write a data buffer to the controller next time the controller starts clocking SCLK.
Write one byte to the controller in a blocking fashion.
Get the amount of bytes left in the TX data buffer.
Enable/disable MISO output.
Enable/disable receiving bytes from the controller into the internal buffer.
Get the amount of bytes ready for reading.
Read from the RX buffer into a local buffer.
Get one byte from the SPI peripheral in a blocking fashion.
Flush one or both buffers.
Function Documentation#
spi_peripheral_init#
void spi_peripheral_init (void )
Initialize the configured USART peripheral for the SPI peripheral operation.
N/A |
Also sets up GPIO settings for MOSI, MISO, SCLK and SS. After initialization, the SPI peripheral will have RX enabled.
45
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_deinit#
void spi_peripheral_deinit (void )
Disable the configured USART peripheral for the SPI operation.
N/A |
50
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_sendBuffer#
int32_t spi_peripheral_sendBuffer (uint8_t * buffer, size_t length)
Write a data buffer to the controller next time the controller starts clocking SCLK.
[in] | buffer | The data buffer to send |
[in] | length | Number of bytes in the buffer to send |
This transfer will be non-blocking and its progress can be tracked through spi_peripheral_getTxBytesLeft.
Returns
BOOTLOADER_OK if successful, error code otherwise
62
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_sendByte#
int32_t spi_peripheral_sendByte (uint8_t byte)
Write one byte to the controller in a blocking fashion.
[in] | byte | The byte to send |
Warnings
If the controller goes down, this will block forever.
Returns
BOOTLOADER_OK if successful, error code otherwise
74
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_getTxBytesLeft#
size_t spi_peripheral_getTxBytesLeft (void )
Get the amount of bytes left in the TX data buffer.
N/A |
Returns
Number of bytes in the transmit buffer still needing to go out
81
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_enableTransmitter#
void spi_peripheral_enableTransmitter (bool enable)
Enable/disable MISO output.
[in] | enable | True to enable the transmitter, false to disable |
88
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_enableReceiver#
void spi_peripheral_enableReceiver (bool enable)
Enable/disable receiving bytes from the controller into the internal buffer.
[in] | enable | True to enable the receiver, false to disable |
This function makes it possible to avoid filling up the buffer with 0xFF while a controller is polling for new data.
97
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_getRxAvailableBytes#
size_t spi_peripheral_getRxAvailableBytes (void )
Get the amount of bytes ready for reading.
N/A |
Returns
Number of bytes in the receive buffer available for reading with spi_peripheral_receiveBuffer
105
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_receiveBuffer#
int32_t spi_peripheral_receiveBuffer (uint8_t * buffer, size_t requestedLength, size_t * receivedLength, bool blocking, uint32_t timeout)
Read from the RX buffer into a local buffer.
[out] | buffer | The data buffer to receive into |
[in] | requestedLength | Number of bytes we'd like to read |
[out] | receivedLength | Number of bytes read |
[in] | blocking | Indicate whether we should wait for requestedLength bytes to be available and read before returning, or we can read out whatever is currently in the buffer and return. |
[in] | timeout | Number of milliseconds to wait for data in blocking mode |
Returns
BOOTLOADER_OK if successful, error code otherwise
120
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_receiveByte#
int32_t spi_peripheral_receiveByte (uint8_t * byte)
Get one byte from the SPI peripheral in a blocking fashion.
[out] | byte | Pointer to where to put the received byte |
Warnings
If the controller never clocks in a byte, this function will block forever.
Returns
BOOTLOADER_OK if successful, error code otherwise
136
of file platform/bootloader/driver/btl_driver_spi_peripheral.h
spi_peripheral_flush#
void spi_peripheral_flush (bool flushTx, bool flushRx)
Flush one or both buffers.
[in] | flushTx | Flush the transmit buffer when true |
[in] | flushRx | Flush the receive buffer when true |
144
of file platform/bootloader/driver/btl_driver_spi_peripheral.h