spi_dma_xfer()

Updated: May 06, 2022

The spi_dma_xfer() function uses DMA to exchange data between the SPI master and an SPI device. The prototype for this function is:

int spi_dma_xfer( int fd,
                  uint32_t device,
                  void *paddr,
                  int len);

The arguments are:

fd
The file descriptor returned by spi_open().
device
The device ID with at most one of the following flags optionally ORed in:
  • SPI_DEV_LOCK
  • SPI_DEV_UNLOCK
paddr
A pointer to the DMA buffer address, which is defined as:
typedef struct {
    uint64_t    rpaddr;
    uint64_t    wpaddr;
} spi_dma_paddr_t;
  

The rpaddr and wpaddr are physical addresses.

The spi_dma_xfer() function returns the number of bytes of data that it successfully exchanged. If an error occurred, the function returns -1 and sets errno:

EIO
The write to the device failed, or a hardware error occurred.
ENOMEM
Insufficient memory.
EPERM
The device is locked by another connection.
ENOTSUP
DMA isn't supported.

An SPI driver typically considers it to be an error if the number of bytes returned by this function isn't the same as the number of bytes it asked the function to exchange.

Note: The application is responsible for allocating and managing the DMA buffer. The application can call spi_getdrvinfo() to determine if the driver supports DMA, and whether or not the DMA buffer requires alignment.