man.bsd.lv manual page server

Manual Page Search Parameters

SPI(9) Kernel Developer's Manual SPI(9)

spi_configure, spi_transfer, spi_transfer_init, spi_chunk_init, spi_transfer_add, spi_wait, spi_done, spi_send, spi_recv, spi_send_recvSerial Peripheral Interface (SPI) kernel interface

#include <dev/spi/spivar.h>

int
spi_configure(struct spi_handle *sh, int mode, int speed);

int
spi_transfer(struct spi_handle *sh, struct spi_transfer *st);

void
spi_transfer_init(struct spi_transfer *st);

void
spi_chunk_init(struct spi_chunk *chunk, int cnt, const uint8_t *wptr, uint8_t *rptr);

void
spi_transfer_add(struct spi_transfer *st, struct spi_chunk *chunk);

void
spi_wait(struct spi_transfer *st);

void
spi_done(struct spi_transfer *st, int err);

int
spi_recv(struct spi_handle *sh, int cnt, uint8_t *data);

int
spi_send(struct spi_handle *sh, int cnt, const uint8_t *data);

int
spi_send_recv(struct spi_handle *sh, int scnt, const uint8_t *snd, int rcnt, const uint8_t *rcv);

SPI is a 4-wire synchronous full-duplex serial bus. It is commonly used for connecting devices such as EEPROMs, displays, and other types of integrated circuits. The spi interface provides a means of communicating with SPI-connected devices.

The following functions comprise the API provided to drivers of SPI-connected devices.

The struct spi_handle corresponding to the device is passed in the driver attachment.

(sh, mode, speed)
Sets mode and speed for subsequent communication with a SPI slave.
(sh, st)
Queue transfer to SPI controller. spi_transfer() returns an errno value when the transfer couldn't be queued.
(st)
Initialize a transfer structure.
(chunk, cnt, wptr, rptr")
Initialize a chunk structure, each chunk corresponds to a possibly bi-directional transfer where the same amount of bytes is shifted in and out.
(st, chunk)
Append a chunk to transfer structure.
(st)
Wait for a transfer to complete. When the transfer has failed for some reason, the field st->st_errno is set to a non-zero value.
(st, err)
Called back machine-dependent backend to signal completion of a transfer.

For simplicity there are convenience functions that combine common operations. These functions return an errno value when the transfer failed.

(sh, cnt, data)
Prepares a chunk for receiving data, queues a transfer and waits for it to complete.
(sh, cnt, data)
Prepares a chunk for sending data, queues a transfer and waits for it to complete.
(sh, scnt, snd, rcnt, rcv)
Prepares two chunks for sending data first and then receiving an answer, queues a transfer and waits for it to complete. This is not a full-duplex operation.

spi(4)

The spi API first appeared in NetBSD 4.0.

February 23, 2019 NetBSD-9.2