Software APIs
dt_i2c.c File Reference

Device Tables (DT) for IP i2c and top earlgrey. More...

#include "hw/top/dt/dt_i2c.h"

Go to the source code of this file.

Data Structures

struct  dt_desc_i2c
 Description of instances. More...
 

Macros

#define TRY_GET_DT(dt, default)
 Return a pointer to the dt_i2c_desc_t structure of the requested dt if it's a valid index.
 

Typedefs

typedef struct dt_desc_i2c dt_desc_i2c_t
 Description of instances.
 

Functions

dt_i2c_t dt_i2c_from_instance_id (dt_instance_id_t inst_id)
 Get the i2c instance from an instance ID.
 
dt_instance_id_t dt_i2c_instance_id (dt_i2c_t dt)
 Get the instance ID of an instance.
 
uint32_t dt_i2c_reg_block (dt_i2c_t dt, dt_i2c_reg_block_t reg_block)
 Get the register base address of an instance.
 
uint32_t dt_i2c_memory_base (dt_i2c_t dt, dt_i2c_memory_t mem)
 Get the base address of a memory.
 
uint32_t dt_i2c_memory_size (dt_i2c_t dt, dt_i2c_memory_t mem)
 Get the size of a memory.
 
dt_plic_irq_id_t dt_i2c_irq_to_plic_id (dt_i2c_t dt, dt_i2c_irq_t irq)
 Get the PLIC ID of a i2c IRQ for a given instance.
 
dt_i2c_irq_t dt_i2c_irq_from_plic_id (dt_i2c_t dt, dt_plic_irq_id_t irq)
 Convert a global IRQ ID to a local i2c IRQ type.
 
dt_alert_id_t dt_i2c_alert_to_alert_id (dt_i2c_t dt, dt_i2c_alert_t alert)
 Get the alert ID of a i2c alert for a given instance.
 
dt_i2c_alert_t dt_i2c_alert_from_alert_id (dt_i2c_t dt, dt_alert_id_t alert)
 Convert a global alert ID to a local i2c alert type.
 
dt_periph_io_t dt_i2c_periph_io (dt_i2c_t dt, dt_i2c_periph_io_t sig)
 Get the peripheral I/O description of an instance.
 
dt_clock_t dt_i2c_clock (dt_i2c_t dt, dt_i2c_clock_t clk)
 Get the clock signal connected to a clock port of an instance.
 
dt_reset_t dt_i2c_reset (dt_i2c_t dt, dt_i2c_reset_t rst)
 Get the reset signal connected to a reset port of an instance.
 

Detailed Description

Device Tables (DT) for IP i2c and top earlgrey.

Definition in file dt_i2c.c.


Data Structure Documentation

◆ dt_desc_i2c

struct dt_desc_i2c

Description of instances.

Definition at line 19 of file dt_i2c.c.

Data Fields
dt_clock_t clock[kDtI2cClockCount] Clock signal connected to each clock port.
top_darjeeling_alert_id_t first_alert Alert ID of the first Alert of this instance.

This value is undefined if the block is not connected to the Alert Handler.

top_earlgrey_alert_id_t first_alert Alert ID of the first Alert of this instance.

This value is undefined if the block is not connected to the Alert Handler.

top_darjeeling_plic_irq_id_t first_irq PLIC ID of the first IRQ of this instance.

This can be kDtPlicIrqIdNone if the block is not connected to the PLIC.

top_earlgrey_plic_irq_id_t first_irq PLIC ID of the first IRQ of this instance.

This can be kDtPlicIrqIdNone if the block is not connected to the PLIC.

dt_instance_id_t inst_id Instance ID.
uint32_t mem_addr[kDtI2cMemoryCount] Base address of each memory.
uint32_t mem_size[kDtI2cMemoryCount] Size in bytes of each memory.
dt_periph_io_t periph_io[kDtI2cPeriphIoCount] Description of each peripheral I/O.
uint32_t reg_addr[kDtI2cRegBlockCount] Base address of each register block.
dt_reset_t reset[kDtI2cResetCount] Reset signal connected to each reset port.

Macro Definition Documentation

◆ TRY_GET_DT

#define TRY_GET_DT ( dt,
default )
Value:
({ if ((dt) < (dt_i2c_t)0 || (dt) >= kDtI2cCount) return (default); &i2c_desc[dt]; })

Return a pointer to the dt_i2c_desc_t structure of the requested dt if it's a valid index.

Otherwise, this macro will return (i.e. exit the function) with the provided default value.

Definition at line 160 of file dt_i2c.c.

Function Documentation

◆ dt_i2c_alert_from_alert_id()

dt_i2c_alert_t dt_i2c_alert_from_alert_id ( dt_i2c_t dt,
dt_alert_id_t alert )

Convert a global alert ID to a local i2c alert type.

Parameters
dtInstance of i2c.
alertA global alert ID that belongs to this instance.
Returns
The i2c alert, or kDtI2cAlertCount.

Note: This function assumes that the global alert ID belongs to the instance of i2c passed in parameter. In other words, it must be the case that dt_i2c_instance_id(dt) == dt_alert_id_to_instance_id(alert). Otherwise, this function will return kDtI2cAlertCount.

Definition at line 226 of file dt_i2c.c.

◆ dt_i2c_alert_to_alert_id()

dt_alert_id_t dt_i2c_alert_to_alert_id ( dt_i2c_t dt,
dt_i2c_alert_t alert )

Get the alert ID of a i2c alert for a given instance.

Note: This function only makes sense if the instance is connected to the Alert Handler. For any instances where the instance is not connected, the return value is unspecified.

Parameters
dtInstance of i2c.
alertA i2c alert.
Returns
The Alert Handler alert ID of the alert of this instance.

Definition at line 220 of file dt_i2c.c.

◆ dt_i2c_clock()

Get the clock signal connected to a clock port of an instance.

Parameters
dtInstance of i2c.
clkClock port.
Returns
Clock signal.

Definition at line 244 of file dt_i2c.c.

◆ dt_i2c_from_instance_id()

dt_i2c_t dt_i2c_from_instance_id ( dt_instance_id_t inst_id)

Get the i2c instance from an instance ID.

For example, dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3.

Parameters
inst_idInstance ID.
Returns
A i2c instance.

Note: This function only makes sense if the instance ID has device type i2c, otherwise the returned value is unspecified.

Definition at line 162 of file dt_i2c.c.

◆ dt_i2c_instance_id()

dt_instance_id_t dt_i2c_instance_id ( dt_i2c_t dt)

Get the instance ID of an instance.

Parameters
dtInstance of i2c.
Returns
The instance ID of that instance.

Definition at line 169 of file dt_i2c.c.

◆ dt_i2c_irq_from_plic_id()

dt_i2c_irq_t dt_i2c_irq_from_plic_id ( dt_i2c_t dt,
dt_plic_irq_id_t irq )

Convert a global IRQ ID to a local i2c IRQ type.

Parameters
dtInstance of i2c.
irqA PLIC ID that belongs to this instance.
Returns
The i2c IRQ, or kDtI2cIrqCount.

Note: This function assumes that the PLIC ID belongs to the instance of i2c passed in parameter. In other words, it must be the case that dt_i2c_instance_id(dt) == dt_plic_id_to_instance_id(irq). Otherwise, this function will return kDtI2cIrqCount.

Definition at line 205 of file dt_i2c.c.

◆ dt_i2c_irq_to_plic_id()

dt_plic_irq_id_t dt_i2c_irq_to_plic_id ( dt_i2c_t dt,
dt_i2c_irq_t irq )

Get the PLIC ID of a i2c IRQ for a given instance.

If the instance is not connected to the PLIC, this function will return kDtPlicIrqIdNone.

Parameters
dtInstance of i2c.
irqA i2c IRQ.
Returns
The PLIC ID of the IRQ of this instance.

Definition at line 195 of file dt_i2c.c.

◆ dt_i2c_memory_base()

uint32_t dt_i2c_memory_base ( dt_i2c_t dt,
dt_i2c_memory_t mem )

Get the base address of a memory.

Parameters
dtInstance of i2c.
memThe memory requested.
Returns
The base address of the requested memory.

Definition at line 181 of file dt_i2c.c.

◆ dt_i2c_memory_size()

uint32_t dt_i2c_memory_size ( dt_i2c_t dt,
dt_i2c_memory_t mem )

Get the size of a memory.

Parameters
dtInstance of i2c.
memThe memory requested.
Returns
The size of the requested memory.

Definition at line 188 of file dt_i2c.c.

◆ dt_i2c_periph_io()

Get the peripheral I/O description of an instance.

Parameters
dtInstance of i2c.
sigRequested peripheral I/O.
Returns
Description of the requested peripheral I/O for this instance.

Definition at line 237 of file dt_i2c.c.

◆ dt_i2c_reg_block()

uint32_t dt_i2c_reg_block ( dt_i2c_t dt,
dt_i2c_reg_block_t reg_block )

Get the register base address of an instance.

Parameters
dtInstance of i2c.
reg_blockThe register block requested.
Returns
The register base address of the requested block.

Definition at line 174 of file dt_i2c.c.

◆ dt_i2c_reset()

Get the reset signal connected to a reset port of an instance.

Parameters
dtInstance of i2c.
rstReset port.
Returns
Reset signal.

Definition at line 251 of file dt_i2c.c.