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

Two-Wire Device Controller (TWD) HW driver header file. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  neorv32_twd_t
 

Functions

Prototypes
int neorv32_twd_available (void)
 
void neorv32_twd_setup (int device_addr, int fsel, int irq_rx_avail, int irq_rx_full, int irq_tx_empty)
 
int neorv32_twd_get_fifo_depth (void)
 
void neorv32_twd_disable (void)
 
void neorv32_twd_enable (void)
 
void neorv32_twd_clear_rx (void)
 
void neorv32_twd_clear_tx (void)
 
int neorv32_twd_sense_scl (void)
 
int neorv32_twd_sense_sda (void)
 
int neorv32_twd_busy (void)
 
int neorv32_twd_rx_available (void)
 
int neorv32_twd_rx_full (void)
 
int neorv32_twd_tx_empty (void)
 
int neorv32_twd_tx_full (void)
 
void neorv32_twd_put (uint8_t data)
 
uint8_t neorv32_twd_get (void)
 

IO Device: Two-Wire Device Controller (TWD)

#define NEORV32_TWD   ((neorv32_twd_t*) (NEORV32_TWD_BASE))
 
enum  NEORV32_TWD_CTRL_enum {
  TWD_CTRL_EN = 0 , TWD_CTRL_CLR_RX = 1 , TWD_CTRL_CLR_TX = 2 , TWD_CTRL_FSEL = 3 ,
  TWD_CTRL_DEV_ADDR0 = 4 , TWD_CTRL_DEV_ADDR6 = 10 , TWD_CTRL_IRQ_RX_AVAIL = 11 , TWD_CTRL_IRQ_RX_FULL = 12 ,
  TWD_CTRL_IRQ_TX_EMPTY = 13 , TWD_CTRL_FIFO_LSB = 15 , TWD_CTRL_FIFO_MSB = 18 , TWD_CTRL_RX_AVAIL = 25 ,
  TWD_CTRL_RX_FULL = 26 , TWD_CTRL_TX_EMPTY = 27 , TWD_CTRL_TX_FULL = 28 , TWD_CTRL_SENSE_SCL = 29 ,
  TWD_CTRL_SENSE_SDA = 30 , TWD_CTRL_BUSY = 31
}
 
enum  NEORV32_TWD_DATA_enum { TWD_DATA_LSB = 0 , TWD_DATA_MSB = 7 }
 

Detailed Description

Two-Wire Device Controller (TWD) HW driver header file.

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

Macro Definition Documentation

◆ NEORV32_TWD

#define NEORV32_TWD   ((neorv32_twd_t*) (NEORV32_TWD_BASE))

TWD module hardware access (neorv32_twd_t)

Enumeration Type Documentation

◆ NEORV32_TWD_CTRL_enum

TWD control register bits

Enumerator
TWD_CTRL_EN 

TWD control register(0) (r/w): TWD enable

TWD_CTRL_CLR_RX 

TWD control register(1) (-/w): Clear RX FIFO, flag auto-clears

TWD_CTRL_CLR_TX 

TWD control register(2) (-/w): Clear TX FIFO, flag auto-clears

TWD_CTRL_FSEL 

TWD control register(3) (r/w): Bus sample clock / filter select

TWD_CTRL_DEV_ADDR0 

TWD control register(4) (r/w): Device address (7-bit), LSB

TWD_CTRL_DEV_ADDR6 

TWD control register(10) (r/w): Device address (7-bit), MSB

TWD_CTRL_IRQ_RX_AVAIL 

TWD control register(11) (r/w): IRQ if RX FIFO data available

TWD_CTRL_IRQ_RX_FULL 

TWD control register(12) (r/w): IRQ if RX FIFO full

TWD_CTRL_IRQ_TX_EMPTY 

TWD control register(13) (r/w): IRQ if TX FIFO empty

TWD_CTRL_FIFO_LSB 

TWD control register(15) (r/-): log2(FIFO size), LSB

TWD_CTRL_FIFO_MSB 

TWD control register(18) (r/-): log2(FIFO size), MSB

TWD_CTRL_RX_AVAIL 

TWD control register(25) (r/-): RX FIFO data available

TWD_CTRL_RX_FULL 

TWD control register(26) (r/-): RX FIFO full

TWD_CTRL_TX_EMPTY 

TWD control register(27) (r/-): TX FIFO empty

TWD_CTRL_TX_FULL 

TWD control register(28) (r/-): TX FIFO full

TWD_CTRL_SENSE_SCL 

TWD control register(29) (r/-): current state of the SCL bus line

TWD_CTRL_SENSE_SDA 

TWD control register(30) (r/-): current state of the SDA bus line

TWD_CTRL_BUSY 

TWD control register(31) (r/-): bus engine is busy (transaction in progress)

◆ NEORV32_TWD_DATA_enum

TWD data register bits

Enumerator
TWD_DATA_LSB 

TWD data register(0) (r/w): Receive/transmit data (8-bit) LSB

TWD_DATA_MSB 

TWD data register(7) (r/w): Receive/transmit data (8-bit) MSB

Function Documentation

◆ neorv32_twd_available()

int neorv32_twd_available ( void )

Check if TWD unit was synthesized.

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

◆ neorv32_twd_busy()

int neorv32_twd_busy ( void )

Check if there is a TWD bus operation in progress.

Returns
0 if idle, 1 if busy.

◆ neorv32_twd_clear_rx()

void neorv32_twd_clear_rx ( void )

Clear TWD RX FIFO.

◆ neorv32_twd_clear_tx()

void neorv32_twd_clear_tx ( void )

Clear TWD TX FIFO.

◆ neorv32_twd_disable()

void neorv32_twd_disable ( void )

Disable TWD controller.

◆ neorv32_twd_enable()

void neorv32_twd_enable ( void )

Enable TWD controller.

◆ neorv32_twd_get()

uint8_t neorv32_twd_get ( void )

Get data byte from RX FIFO.

Warning
This function is non-blocking. Check FIFO status before.
Returns
Data byte read from RX FIFO.

◆ neorv32_twd_get_fifo_depth()

int neorv32_twd_get_fifo_depth ( void )

Get TWD FIFO depth.

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

◆ neorv32_twd_put()

void neorv32_twd_put ( uint8_t data)

Put data byte into TX FIFO.

Warning
This function is non-blocking. Check FIFO status before.
Parameters
[in]dataData byte to be stored in TX FIFO.

◆ neorv32_twd_rx_available()

int neorv32_twd_rx_available ( void )

Check if RX data available.

Returns
0 if no data available, 1 if data is available.

◆ neorv32_twd_rx_full()

int neorv32_twd_rx_full ( void )

Check if RX FIFO is full.

Returns
0 if no RX FIFO is not full, 1 if RX FIFO is full.

◆ neorv32_twd_sense_scl()

int neorv32_twd_sense_scl ( void )

Get current state of SCL bus line.

Returns
1 if SCL is high, 0 if SCL is low.

◆ neorv32_twd_sense_sda()

int neorv32_twd_sense_sda ( void )

Get current state of SDA bus line.

Returns
1 if SDA is high, 0 if SDA is low.

◆ neorv32_twd_setup()

void neorv32_twd_setup ( int device_addr,
int fsel,
int irq_rx_avail,
int irq_rx_full,
int irq_tx_empty )

Enable and configure TWD controller. The TWD control register bits are listed in NEORV32_TWD_CTRL_enum.

Parameters
[in]device_addr7-bit device address.
[in]fselBus sample clock / filter select.
[in]irq_rx_availIRQ if RX FIFO data available.
[in]irq_rx_fullIRQ if RX FIFO full.
[in]irq_tx_emptyIRQ if TX FIFO empty.

◆ neorv32_twd_tx_empty()

int neorv32_twd_tx_empty ( void )

Check if TX FIFO is empty.

Returns
0 if no TX FIFO is not empty, 1 if TX FIFO is empty.

◆ neorv32_twd_tx_full()

int neorv32_twd_tx_full ( void )

Check if TX FIFO is full.

Returns
0 if no TX FIFO is not full, 1 if TX FIFO is full.