NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
Data Structures
neorv32_spi.h File Reference

Serial peripheral interface controller (SPI) HW driver header file. More...

Go to the source code of this file.

Data Structures

struct  neorv32_spi_t
 

Functions

Prototypes
int neorv32_spi_available (void)
 
void neorv32_spi_setup (int prsc, int cdiv, int clk_phase, int clk_polarity, uint32_t irq_mask)
 
void neorv32_spi_highspeed_enable (void)
 
void neorv32_spi_highspeed_disable (void)
 
uint32_t neorv32_spi_get_clock_speed (void)
 
void neorv32_spi_disable (void)
 
void neorv32_spi_enable (void)
 
int neorv32_spi_get_fifo_depth (void)
 
void neorv32_spi_cs_en (int cs)
 
void neorv32_spi_cs_dis (void)
 
uint8_t neorv32_spi_trans (uint8_t tx_data)
 
void neorv32_spi_put_nonblocking (uint8_t tx_data)
 
uint8_t neorv32_spi_get_nonblocking (void)
 
int neorv32_spi_busy (void)
 

IO Device: Serial Peripheral Interface Controller (SPI)

#define NEORV32_SPI   ((neorv32_spi_t*) (NEORV32_SPI_BASE))
 
enum  NEORV32_SPI_CTRL_enum {
  SPI_CTRL_EN = 0 , SPI_CTRL_CPHA = 1 , SPI_CTRL_CPOL = 2 , SPI_CTRL_CS_SEL0 = 3 ,
  SPI_CTRL_CS_SEL1 = 4 , SPI_CTRL_CS_SEL2 = 5 , SPI_CTRL_CS_EN = 6 , SPI_CTRL_PRSC0 = 7 ,
  SPI_CTRL_PRSC1 = 8 , SPI_CTRL_PRSC2 = 9 , SPI_CTRL_CDIV0 = 10 , SPI_CTRL_CDIV1 = 11 ,
  SPI_CTRL_CDIV2 = 12 , SPI_CTRL_CDIV3 = 13 , SPI_CTRL_HIGHSPEED = 14 , SPI_CTRL_RX_AVAIL = 16 ,
  SPI_CTRL_TX_EMPTY = 17 , SPI_CTRL_TX_NHALF = 18 , SPI_CTRL_TX_FULL = 19 , SPI_CTRL_IRQ_RX_AVAIL = 20 ,
  SPI_CTRL_IRQ_TX_EMPTY = 21 , SPI_CTRL_IRQ_TX_HALF = 22 , SPI_CTRL_IRQ_IDLE = 23 , SPI_CTRL_FIFO_LSB = 24 ,
  SPI_CTRL_FIFO_MSB = 27 , SPI_CTRL_BUSY = 31
}
 

Detailed Description

Serial peripheral interface controller (SPI) HW driver header file.

Note
These functions should only be used if the SPI unit was synthesized (IO_SPI_EN = true).

Macro Definition Documentation

◆ NEORV32_SPI

#define NEORV32_SPI   ((neorv32_spi_t*) (NEORV32_SPI_BASE))

SPI module hardware access (neorv32_spi_t)

Enumeration Type Documentation

◆ NEORV32_SPI_CTRL_enum

SPI control register bits

Enumerator
SPI_CTRL_EN 

SPI control register(0) (r/w): SPI unit enable

SPI_CTRL_CPHA 

SPI control register(1) (r/w): Clock phase

SPI_CTRL_CPOL 

SPI control register(2) (r/w): Clock polarity

SPI_CTRL_CS_SEL0 

SPI control register(3) (r/w): Direct chip select bit 1

SPI_CTRL_CS_SEL1 

SPI control register(4) (r/w): Direct chip select bit 2

SPI_CTRL_CS_SEL2 

SPI control register(5) (r/w): Direct chip select bit 2

SPI_CTRL_CS_EN 

SPI control register(6) (r/w): Chip select enable (selected CS line output is low when set)

SPI_CTRL_PRSC0 

SPI control register(7) (r/w): Clock prescaler select bit 0

SPI_CTRL_PRSC1 

SPI control register(8) (r/w): Clock prescaler select bit 1

SPI_CTRL_PRSC2 

SPI control register(9) (r/w): Clock prescaler select bit 2

SPI_CTRL_CDIV0 

SPI control register(10) (r/w): Clock divider bit 0

SPI_CTRL_CDIV1 

SPI control register(11) (r/w): Clock divider bit 1

SPI_CTRL_CDIV2 

SPI control register(12) (r/w): Clock divider bit 2

SPI_CTRL_CDIV3 

SPI control register(13) (r/w): Clock divider bit 3

SPI_CTRL_HIGHSPEED 

SPI control register(14) (r/w): High-speed mode

SPI_CTRL_RX_AVAIL 

SPI control register(16) (r/-): RX FIFO data available (RX FIFO not empty)

SPI_CTRL_TX_EMPTY 

SPI control register(17) (r/-): TX FIFO empty

SPI_CTRL_TX_NHALF 

SPI control register(18) (r/-): TX FIFO not at least half full

SPI_CTRL_TX_FULL 

SPI control register(19) (r/-): TX FIFO full

SPI_CTRL_IRQ_RX_AVAIL 

SPI control register(20) (r/w): Fire IRQ if RX FIFO data available (RX FIFO not empty)

SPI_CTRL_IRQ_TX_EMPTY 

SPI control register(21) (r/w): Fire IRQ if TX FIFO empty

SPI_CTRL_IRQ_TX_HALF 

SPI control register(22) (r/w): Fire IRQ if TX FIFO not at least half full

SPI_CTRL_IRQ_IDLE 

SPI control register(23) (r/w): Fire IRQ if TX FIFO is empty and SPI bus engine is idle

SPI_CTRL_FIFO_LSB 

SPI control register(24) (r/-): log2(FIFO size), lsb

SPI_CTRL_FIFO_MSB 

SPI control register(27) (r/-): log2(FIFO size), msb

SPI_CTRL_BUSY 

SPI control register(31) (r/-): SPI busy flag

Function Documentation

◆ neorv32_spi_available()

int neorv32_spi_available ( void )

Check if SPI unit was synthesized.

Returns
0 if SPI was not synthesized, 1 if SPI is available.

◆ neorv32_spi_busy()

int neorv32_spi_busy ( void )

Check if SPI transceiver is busy or TX FIFO not empty.

Returns
0 if idle, 1 if busy

◆ neorv32_spi_cs_dis()

void neorv32_spi_cs_dis ( void )

Deactivate currently active SPI chip select signal.

Note
The SPI chip select output lines are HIGH when deactivated.

◆ neorv32_spi_cs_en()

void neorv32_spi_cs_en ( int cs)

Activate single SPI chip select signal.

Note
The SPI chip select output lines are LOW when activated.
Parameters
csChip select line to activate (0..7).

◆ neorv32_spi_disable()

void neorv32_spi_disable ( void )

Disable SPI controller.

◆ neorv32_spi_enable()

void neorv32_spi_enable ( void )

Enable SPI controller.

◆ neorv32_spi_get_clock_speed()

uint32_t neorv32_spi_get_clock_speed ( void )

Get configured clock speed in Hz.

Returns
Actual configured SPI clock speed in Hz.

◆ neorv32_spi_get_fifo_depth()

int neorv32_spi_get_fifo_depth ( void )

Get SPI FIFO depth.

Returns
FIFO depth (number of entries), zero if no FIFO implemented

◆ neorv32_spi_get_nonblocking()

uint8_t neorv32_spi_get_nonblocking ( void )

Get SPI RX data (non-blocking).

Returns
Receive data (8-bit, LSB-aligned).

◆ neorv32_spi_highspeed_disable()

void neorv32_spi_highspeed_disable ( void )

Disable high-speed mode.

◆ neorv32_spi_highspeed_enable()

void neorv32_spi_highspeed_enable ( void )

Enable high-speed mode.

◆ neorv32_spi_put_nonblocking()

void neorv32_spi_put_nonblocking ( uint8_t tx_data)

Initiate SPI TX transfer (non-blocking).

Parameters
tx_dataTransmit data (8-bit, LSB-aligned).

◆ neorv32_spi_setup()

void neorv32_spi_setup ( int prsc,
int cdiv,
int clk_phase,
int clk_polarity,
uint32_t irq_mask )

Enable and configure SPI controller. The SPI control register bits are listed in NEORV32_SPI_CTRL_enum.

Parameters
[in]prscClock prescaler select (0..7). See NEORV32_CLOCK_PRSC_enum. @prama[in] cdiv Clock divider (0..15).
[in]clk_phaseClock phase (0=sample on rising edge, 1=sample on falling edge).
[in]clk_polarityClock polarity (when idle).
[in]irq_maskInterrupt configuration mask (CTRL's irq_* bits).

◆ neorv32_spi_trans()

uint8_t neorv32_spi_trans ( uint8_t tx_data)

Initiate SPI transfer.

Note
This function is blocking.
Parameters
tx_dataTransmit data (8-bit, LSB-aligned).
Returns
Receive data (8-bit, LSB-aligned).