NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_spi.c File Reference

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

#include <neorv32.h>

Functions

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)
 
void neorv32_spi_cs_en_nonblocking (int cs)
 
void neorv32_spi_cs_dis_nonblocking (void)
 
int neorv32_spi_check_cs (void)
 
int neorv32_spi_busy (void)
 

Detailed Description

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

Note
These functions should only be used if the SPI unit was synthesized (IO_SPI_EN = true).
See also
https://stnolting.github.io/neorv32/sw/files.html

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_check_cs()

int neorv32_spi_check_cs ( void )

Check if any chip-select line is active.

Returns
0 if no CS lines are active, 1 if at least one CS line is active.

◆ 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.
This function is blocking.

◆ neorv32_spi_cs_dis_nonblocking()

void neorv32_spi_cs_dis_nonblocking ( void )

Deactivate currently active SPI chip select signal (non-blocking).

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.
This function is blocking.
Parameters
csChip select line to activate (0..7).

◆ neorv32_spi_cs_en_nonblocking()

void neorv32_spi_cs_en_nonblocking ( int cs)

Activate single SPI chip select signal (non-blocking).

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)

Put SPI TX data (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)

Perform a single SPI data transfer.

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