Linux User Mode SPI Driver

Implementation of SPI access from Linux User Space. More...

Detailed Description

Implementation of SPI access from Linux User Space.

This module allows to connect a RIOT application that runs on a Linux host to the physical SPI bus(ses) of that host. To do so, the application has to be compiled for the native board in a Linux environment.

SPI support is automatically included if either a module requiring the PERIPH_SPI feature is added to the application or if it is explicitly listed as FEATURES_REQUIRED in the application's Makefile.

At runtime, the process has to be connected to a specific bus on the host machine. SPI buses are exposed as /dev/spidevB.D character files, where B is the Bus ID (MISO, MOSI and SCLK lines) and D denotes the connected device or hardware chip select line. Ideally, this structure should be reflected when mapping the device files to RIOT SPI buses.

Example:

$ ./riot_native_app --spi=0:0:/dev/spidev0.0 --spi=0:1:/dev/spidev0.1

This will add /dev/spidev0.0 and /dev/spidev0.1 as SPI_DEV(0) in RIOT. The first device can be used with SPI_HWCS(0) as CS parameter, the second one with SPI_HWCS(1) as CS parameter.

Multiple SPI buses can be added by increasing SPI_NUMOF in the Makefile:

CFLAGS += -DSPI_NUMOF=n

The sames goes for the SPI_MAXCS parameter that defines the maximum number of SPI_HWCS values per bus.

Buses that aren't assigned during startup will return either SPI_NODEV or SPI_NOCS when accessed.

If the SPI API is called with SPI_CS_UNDEF as CS parameter, the driver will select the file descriptor with the lowest HWCS id for that bus, but the actual CS line will not be pulled low (if the hardware supports this). This would (in principle) allow to control CS manually.

Files

file  spidev_linux.h
 Implementation of SPI access from Linux User Space.
 

Data Structures

struct  spidev_linux_conf
 Static runtime configuration for SPI port + CS line. More...
 
struct  spidev_linux_state
 Dynamic runtime state for SPI port + CS line. More...
 

Typedefs

typedef struct spidev_linux_conf spidev_linux_conf_t
 Static runtime configuration for SPI port + CS line. More...
 
typedef struct spidev_linux_state spidev_linux_state_t
 Dynamic runtime state for SPI port + CS line. More...
 

Enumerations

enum  { SPI_SETUP_OK = 0, SPI_SETUP_INVALID = -1 }
 Status codes for SPI device setup. More...
 

Functions

int spidev_linux_setup (spi_t bus, unsigned cs_id, const char *name)
 register /dev/spidev* device to be used for SPI More...
 
void spidev_linux_teardown (void)
 Close open SPI file descriptors.
 

Typedef Documentation

◆ spidev_linux_conf_t

Static runtime configuration for SPI port + CS line.

Contains the information that is passed by command line on startup

◆ spidev_linux_state_t

Dynamic runtime state for SPI port + CS line.

Contains state of the line (whether if it's opened, in use, available, ...)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Status codes for SPI device setup.

Enumerator
SPI_SETUP_OK 

parameters are sound

SPI_SETUP_INVALID 

invalid params or duplicate definition

Definition at line 79 of file spidev_linux.h.

Function Documentation

◆ spidev_linux_setup()

int spidev_linux_setup ( spi_t  bus,
unsigned  cs_id,
const char *  name 
)

register /dev/spidev* device to be used for SPI

Parameters
[in]busSPI bus id of the device
[in]cs_idID of CS line to configure
[in]namepath name for /dev/spidev* device
Returns
SPI_SETUP_OK On success
SPI_SETUP_INVALID On invalid parameters