KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
|
This driver wraps the functions of the OpenCores SPI master. More...
#include <stdint.h>
#include <stdbool.h>
#include "cfg_soc.h"
#include "lm32soc/dev_spi.h"
#include "errorcode.h"
Go to the source code of this file.
Data Structures | |
struct | SpiInit |
SPI initialization structure. More... | |
Macros | |
#define | SPI_MAX_BYTES 16 |
The maximum bytes the SPI driver can transfer at a time. | |
#define | SPI_MAX_SLAVE 8 |
Maximum number of slaves (0 - SPI_MAX_SLAVE - 1) | |
#define | SPI_MIN_BITRATE ( WISHBONE_FREQ / ( ( SPI_DIV_MASK + 1 ) * 2 ) ) |
Minimum SPI bitrate. | |
#define | SPI_MAX_BITRATE ( WISHBONE_FREQ / 2 ) |
Maximum SPI bitrate. | |
#define | E_SPI_TIMEOUT ( E_SPI + 1 ) |
SPI transmission timeout. | |
#define | E_SPI_TIMEOUT_DESCR "SPI transmission timeout" |
#define | SPI_DEFAULT_INIT |
Default initialization structure. More... | |
Functions | |
bool | spiInit (SPI_Device *dev, SpiInit *init) |
Initializes the specified SPI device with the specified parameters. More... | |
bool | spiTxRx (SPI_Device *dev, uint8_t *dataIn, uint8_t *dataOut, int len) |
Transfers a specific number of bytes in a synchronous way. More... | |
void | spiAsyncTx (SPI_Device *dev, uint8_t *dataIn, int length) |
Start a asynchronous SPI transmission. More... | |
bool | spiASyncBusy (SPI_Device *dev) |
Returns whether or not the SPI driver is busy tranceiving data. More... | |
int | spiASyncLength (SPI_Device *dev) |
Last lenght of data transmitted. More... | |
void | spiASyncRx (SPI_Device *dev, uint8_t *dataOut) |
Reads the data received in the previous transmission. More... | |
void | spiSelect (SPI_Device *dev, uint32_t slaveNo) |
Selects a specific slave. More... | |
void | spiDeselect (SPI_Device *dev) |
Deselects all slaves. More... | |
This driver wraps the functions of the OpenCores SPI master.
The driver allows for multiple SPI devices in memory, thus the specific SPI device must be provided with every call.
The following code demonstrates how to use the SPI device, using a fictive SPI slave. So its not so much what it does, but more how it does it. This should of course be translated to your specific SPI slaves' need.
Definition in file spi.h.
#define SPI_DEFAULT_INIT |
bool spiASyncBusy | ( | SPI_Device * | dev | ) |
int spiASyncLength | ( | SPI_Device * | dev | ) |
void spiASyncRx | ( | SPI_Device * | dev, |
uint8_t * | dataOut | ||
) |
void spiAsyncTx | ( | SPI_Device * | dev, |
uint8_t * | dataIn, | ||
int | length | ||
) |
void spiDeselect | ( | SPI_Device * | dev | ) |
bool spiInit | ( | SPI_Device * | dev, |
SpiInit * | init | ||
) |
void spiSelect | ( | SPI_Device * | dev, |
uint32_t | slaveNo | ||
) |
bool spiTxRx | ( | SPI_Device * | dev, |
uint8_t * | dataIn, | ||
uint8_t * | dataOut, | ||
int | len | ||
) |
Transfers a specific number of bytes in a synchronous way.
Note that the underlying SPI device can at most send SPI_MAX_BYTES. When the length of the data to transmit exceeds this value, multiple transmits will be issued.
dev | The WB device. |
dataIn | The data to receive, may be NULL to send dummy data. |
dataOut | The data to transmit, may be NULL to not receive data. |
len | The no of bytes to transmit and receive. |
true | Operation was a success. |
false | Operation failed, check errCode() for the error code. |