dnx RTOS 2.4.0 "Goose"
|
Driver handles SPI peripheral.
Some manufactures enumerate devices starting from 1 instead of 0 (e.g. ST). In this case major number starts from 0 and is connected to the first device e.g. SPI1.
Number of peripherals determines how big major number can be. If there is only one SPI peripheral then the major number is always 0. Number of devices (minor number) can be theoretically up to 256 or to limits of memory capacity.
To initialize driver the following code can be used:
To release driver the following code can be used:
Driver configuration should be done before usage and after initialization. The best place to do this is user application. To configure particular SPI device the ioctl() function shall be used:
The Flush Byte is used by the SPI driver to flush frames from SPI device at read procedure. The SPI interface is full duplex thus it is not possible to write and read data by using fwrite() and fread() interfaces at one time. Flush Byte have not any meaning if write procedure is used.
MOSI: [ 0xFF ][ 0xFF ][ 0xFF ][ 0xFF ][ 0xFF ]
-> Flush bytes
MISO: [DATA_0][DATA_1][DATA_2][DATA_3][DATA_n]
-> Data frames read by fread()
Data to a SPI device can be wrote as regular file, but there are some restrictions because of SPI specification. Write operation by using fwrite() function sends bytes to device but incoming data is not received. Continuous write and read operation can be done by using ioctl() function. The fseek() function has no impact for SPI communication. Example assumptions:
Data from a SPI device can be read as regular file, but there are some restrictions because of SPI specification. Read operation by using fread() function sends flush bytes to a device and incoming bytes are received. Continuous write and read operation can be done by using ioctl() function. The fseek() function has no impact for SPI communication. Example assumptions:
To read and write bytes from a SPI device can be done by using ioctl() function. In this case special descriptor must be used: SPI_transceive_t. By using this object the Tx and Rx buffers must have the same sizes. Example assumptions:
Data Structures | |
struct | SPI_config_t |
struct | SPI_transceive_t |
Macros | |
#define | IOCTL_SPI__SET_CONFIGURATION _IOW(SPI, 0x00, const SPI_config_t*) |
Set SPI configuration. More... | |
#define | IOCTL_SPI__GET_CONFIGURATION _IOR(SPI, 0x01, SPI_config_t*) |
Gets SPI configuration. More... | |
#define | IOCTL_SPI__SELECT _IO(SPI, 0x02) |
Select specified slave (CS = 0) [RAW mode]. More... | |
#define | IOCTL_SPI__DESELECT _IO(SPI, 0x03) |
Deselect specified slave (CS = 1) [RAW mode]. More... | |
#define | IOCTL_SPI__TRANSCEIVE _IOWR(SPI, 0x04, SPI_transceive_t*) |
Transmit and receive specified buffer. More... | |
#define | IOCTL_SPI__TRANSMIT_NO_SELECT _IOW(SPI, 0x05, const u8_t*) |
Transmit without selection. More... | |
Enumerations | |
enum | SPI_clk_div |
enum | SPI_mode |
struct SPI_config_t |
SPI configuration type.
Data Fields | ||
---|---|---|
enum SPI_clk_div | clk_divider |
Peripheral clock divider. |
u8_t | CS_pin_idx |
Chip Select pin index. |
u8_t | CS_port_idx |
Chip Select port index. |
bool | CS_reverse | |
u8_t | flush_byte |
Flush byte in read transmission. |
enum SPI_mode | mode |
SPI mode. |
bool | msb_first |
MSb first (true). |
struct SPI_transceive_t |
#define IOCTL_SPI__DESELECT _IO(SPI, 0x03) |
#define IOCTL_SPI__GET_CONFIGURATION _IOR(SPI, 0x01, SPI_config_t*) |
[RD] | SPI_config_t * SPI peripheral configuration |
#define IOCTL_SPI__SELECT _IO(SPI, 0x02) |
#define IOCTL_SPI__SET_CONFIGURATION _IOW(SPI, 0x00, const SPI_config_t*) |
[WR] | SPI_config_t * SPI peripheral configuration |
#define IOCTL_SPI__TRANSCEIVE _IOWR(SPI, 0x04, SPI_transceive_t*) |
[WR] | SPI_transceive_t * transmit and receive frame |
#define IOCTL_SPI__TRANSMIT_NO_SELECT _IOW(SPI, 0x05, const u8_t*) |
[WR] | u8_t* byte to transfer |
enum SPI_clk_div |
Type represent peripheral divider.
enum SPI_mode |
SPI peripheral modes.