Software APIs
dt_usbdev.h File Reference

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

#include "dt_api.h"
#include <stdint.h>

Go to the source code of this file.

Macros

#define OPENTITAN_USBDEV_HAS_CONN_VBUS   1
 List of supported hardware features.
 
#define OPENTITAN_USBDEV_HAS_CONN_PULLUP   1
 
#define OPENTITAN_USBDEV_HAS_CONN_REF_PULSE   1
 
#define OPENTITAN_USBDEV_HAS_CONN_PIN_CONFIG   1
 
#define OPENTITAN_USBDEV_HAS_CONN_RESET   1
 
#define OPENTITAN_USBDEV_HAS_BUFFER_MEMORY   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_RX   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_TX   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_ENDPOINTS   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_BULK   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_ISOCHRONOUS   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL   1
 
#define OPENTITAN_USBDEV_HAS_TRANSFER_INTERRUPT   1
 
#define OPENTITAN_USBDEV_HAS_POWER_SUSPEND   1
 
#define OPENTITAN_USBDEV_HAS_POWER_RESUME   1
 
#define OPENTITAN_USBDEV_HAS_POWER_AON   1
 
#define OPENTITAN_USBDEV_HAS_POWER_WAKE_DISCONNECT   1
 
#define OPENTITAN_USBDEV_HAS_POWER_WAKE_RESUME   1
 
#define OPENTITAN_USBDEV_HAS_POWER_WAKE_BUS_RESET   1
 
#define OPENTITAN_USBDEV_HAS_POWER_TOGGLE_RESTORE   1
 

Typedefs

typedef enum dt_usbdev dt_usbdev_t
 List of instances.
 
typedef enum dt_usbdev_reg_block dt_usbdev_reg_block_t
 List of register blocks.
 
typedef enum dt_usbdev_irq dt_usbdev_irq_t
 List of IRQs.
 
typedef enum dt_usbdev_alert dt_usbdev_alert_t
 List of Alerts.
 
typedef enum dt_usbdev_clock dt_usbdev_clock_t
 List of clock ports.
 
typedef enum dt_usbdev_reset dt_usbdev_reset_t
 List of reset ports.
 
typedef enum dt_usbdev_periph_io dt_usbdev_periph_io_t
 List of peripheral I/O.
 

Enumerations

enum  dt_usbdev {
  kDtUsbdev = 0 ,
  kDtUsbdevFirst = 0 ,
  kDtUsbdevCount = 1
}
 List of instances. More...
 
enum  dt_usbdev_reg_block {
  kDtUsbdevRegBlockCore = 0 ,
  kDtUsbdevRegBlockCount = 1
}
 List of register blocks. More...
 
enum  dt_usbdev_irq {
  kDtUsbdevIrqPktReceived = 0 ,
  kDtUsbdevIrqPktSent = 1 ,
  kDtUsbdevIrqDisconnected = 2 ,
  kDtUsbdevIrqHostLost = 3 ,
  kDtUsbdevIrqLinkReset = 4 ,
  kDtUsbdevIrqLinkSuspend = 5 ,
  kDtUsbdevIrqLinkResume = 6 ,
  kDtUsbdevIrqAvOutEmpty = 7 ,
  kDtUsbdevIrqRxFull = 8 ,
  kDtUsbdevIrqAvOverflow = 9 ,
  kDtUsbdevIrqLinkInErr = 10 ,
  kDtUsbdevIrqRxCrcErr = 11 ,
  kDtUsbdevIrqRxPidErr = 12 ,
  kDtUsbdevIrqRxBitstuffErr = 13 ,
  kDtUsbdevIrqFrame = 14 ,
  kDtUsbdevIrqPowered = 15 ,
  kDtUsbdevIrqLinkOutErr = 16 ,
  kDtUsbdevIrqAvSetupEmpty = 17 ,
  kDtUsbdevIrqCount = 18
}
 List of IRQs. More...
 
enum  dt_usbdev_alert {
  kDtUsbdevAlertFatalFault = 0 ,
  kDtUsbdevAlertCount = 1
}
 List of Alerts. More...
 
enum  dt_usbdev_clock {
  kDtUsbdevClockClk = 0 ,
  kDtUsbdevClockAon = 1 ,
  kDtUsbdevClockCount = 2
}
 List of clock ports. More...
 
enum  dt_usbdev_reset {
  kDtUsbdevResetRst = 0 ,
  kDtUsbdevResetAon = 1 ,
  kDtUsbdevResetCount = 2
}
 List of reset ports. More...
 
enum  dt_usbdev_periph_io {
  kDtUsbdevPeriphIoSense = 0 ,
  kDtUsbdevPeriphIoUsbDp = 1 ,
  kDtUsbdevPeriphIoUsbDn = 2 ,
  kDtUsbdevPeriphIoCount = 3
}
 List of peripheral I/O. More...
 

Functions

dt_usbdev_t dt_usbdev_from_instance_id (dt_instance_id_t inst_id)
 Get the usbdev instance from an instance ID.
 
dt_instance_id_t dt_usbdev_instance_id (dt_usbdev_t dt)
 Get the instance ID of an instance.
 
uint32_t dt_usbdev_reg_block (dt_usbdev_t dt, dt_usbdev_reg_block_t reg_block)
 Get the register base address of an instance.
 
dt_plic_irq_id_t dt_usbdev_irq_to_plic_id (dt_usbdev_t dt, dt_usbdev_irq_t irq)
 Get the PLIC ID of a usbdev IRQ for a given instance.
 
dt_usbdev_irq_t dt_usbdev_irq_from_plic_id (dt_usbdev_t dt, dt_plic_irq_id_t irq)
 Convert a global IRQ ID to a local usbdev IRQ type.
 
dt_alert_id_t dt_usbdev_alert_to_alert_id (dt_usbdev_t dt, dt_usbdev_alert_t alert)
 Get the alert ID of a usbdev alert for a given instance.
 
dt_usbdev_alert_t dt_usbdev_alert_from_alert_id (dt_usbdev_t dt, dt_alert_id_t alert)
 Convert a global alert ID to a local usbdev alert type.
 
dt_periph_io_t dt_usbdev_periph_io (dt_usbdev_t dt, dt_usbdev_periph_io_t sig)
 Get the peripheral I/O description of an instance.
 
dt_clock_t dt_usbdev_clock (dt_usbdev_t dt, dt_usbdev_clock_t clk)
 Get the clock signal connected to a clock port of an instance.
 
dt_reset_t dt_usbdev_reset (dt_usbdev_t dt, dt_usbdev_reset_t rst)
 Get the reset signal connected to a reset port of an instance.
 

Detailed Description

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

This file contains the type definitions and global functions of the usbdev.

Definition in file dt_usbdev.h.

Macro Definition Documentation

◆ OPENTITAN_USBDEV_HAS_BUFFER_MEMORY

#define OPENTITAN_USBDEV_HAS_BUFFER_MEMORY   1

Definition at line 133 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_CONN_PIN_CONFIG

#define OPENTITAN_USBDEV_HAS_CONN_PIN_CONFIG   1

Definition at line 131 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_CONN_PULLUP

#define OPENTITAN_USBDEV_HAS_CONN_PULLUP   1

Definition at line 129 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_CONN_REF_PULSE

#define OPENTITAN_USBDEV_HAS_CONN_REF_PULSE   1

Definition at line 130 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_CONN_RESET

#define OPENTITAN_USBDEV_HAS_CONN_RESET   1

Definition at line 132 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_CONN_VBUS

#define OPENTITAN_USBDEV_HAS_CONN_VBUS   1

List of supported hardware features.

Definition at line 128 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_AON

#define OPENTITAN_USBDEV_HAS_POWER_AON   1

Definition at line 143 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_RESUME

#define OPENTITAN_USBDEV_HAS_POWER_RESUME   1

Definition at line 142 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_SUSPEND

#define OPENTITAN_USBDEV_HAS_POWER_SUSPEND   1

Definition at line 141 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_TOGGLE_RESTORE

#define OPENTITAN_USBDEV_HAS_POWER_TOGGLE_RESTORE   1

Definition at line 147 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_WAKE_BUS_RESET

#define OPENTITAN_USBDEV_HAS_POWER_WAKE_BUS_RESET   1

Definition at line 146 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_WAKE_DISCONNECT

#define OPENTITAN_USBDEV_HAS_POWER_WAKE_DISCONNECT   1

Definition at line 144 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_POWER_WAKE_RESUME

#define OPENTITAN_USBDEV_HAS_POWER_WAKE_RESUME   1

Definition at line 145 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_BULK

#define OPENTITAN_USBDEV_HAS_TRANSFER_BULK   1

Definition at line 137 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL

#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL   1

Definition at line 139 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_RX

#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_RX   1

Definition at line 134 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_TX

#define OPENTITAN_USBDEV_HAS_TRANSFER_CONTROL_TX   1

Definition at line 135 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_ENDPOINTS

#define OPENTITAN_USBDEV_HAS_TRANSFER_ENDPOINTS   1

Definition at line 136 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_INTERRUPT

#define OPENTITAN_USBDEV_HAS_TRANSFER_INTERRUPT   1

Definition at line 140 of file dt_usbdev.h.

◆ OPENTITAN_USBDEV_HAS_TRANSFER_ISOCHRONOUS

#define OPENTITAN_USBDEV_HAS_TRANSFER_ISOCHRONOUS   1

Definition at line 138 of file dt_usbdev.h.

Typedef Documentation

◆ dt_usbdev_alert_t

List of Alerts.

Alerts are guaranteed to be numbered consecutively from 0.

◆ dt_usbdev_clock_t

List of clock ports.

Clock ports are guaranteed to be numbered consecutively from 0.

◆ dt_usbdev_irq_t

List of IRQs.

IRQs are guaranteed to be numbered consecutively from 0.

◆ dt_usbdev_periph_io_t

List of peripheral I/O.

Peripheral I/O are guaranteed to be numbered consecutively from 0.

◆ dt_usbdev_reg_block_t

List of register blocks.

Register blocks are guaranteed to start at 0 and to be consecutively numbered.

◆ dt_usbdev_reset_t

List of reset ports.

Reset ports are guaranteed to be numbered consecutively from 0.

Enumeration Type Documentation

◆ dt_usbdev

enum dt_usbdev

List of instances.

Enumerator
kDtUsbdev 

usbdev

Definition at line 23 of file dt_usbdev.h.

◆ dt_usbdev_alert

List of Alerts.

Alerts are guaranteed to be numbered consecutively from 0.

Enumerator
kDtUsbdevAlertFatalFault 

This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected.

Definition at line 86 of file dt_usbdev.h.

◆ dt_usbdev_clock

List of clock ports.

Clock ports are guaranteed to be numbered consecutively from 0.

Enumerator
kDtUsbdevClockClk 

Clock port clk_i.

kDtUsbdevClockAon 

Clock port clk_aon_i.

Definition at line 96 of file dt_usbdev.h.

◆ dt_usbdev_irq

List of IRQs.

IRQs are guaranteed to be numbered consecutively from 0.

Enumerator
kDtUsbdevIrqPktReceived 

Raised if a packet was received using an OUT or SETUP transaction.

This interrupt is directly tied to whether the RX FIFO is empty, so it should be cleared only after handling the FIFO entry.

kDtUsbdevIrqPktSent 

Raised if a packet was sent as part of an IN transaction.

This interrupt is directly tied to whether a sent packet has not been acknowledged in the !!in_sent register. It should be cleared only after clearing all bits in the !!in_sent register.

kDtUsbdevIrqDisconnected 

Raised if VBUS is lost, thus the link is disconnected.

kDtUsbdevIrqHostLost 

Raised if link is active but SOF was not received from host for 4.096 ms.

The SOF should be every 1 ms.

kDtUsbdevIrqLinkReset 

Raised if the link is at SE0 longer than 3 us indicating a link reset (host asserts for min 10 ms, device can react after 2.5 us).

kDtUsbdevIrqLinkSuspend 

Raised if the line has signaled J for longer than 3ms and is therefore in suspend state.

kDtUsbdevIrqLinkResume 

Raised when the link becomes active again after being suspended.

kDtUsbdevIrqAvOutEmpty 

Raised when the Available OUT Buffer FIFO is empty and the device interface is enabled.

This interrupt is directly tied to the FIFO status, so the Available OUT Buffer FIFO must be provided with a free buffer before the interrupt can be cleared.

kDtUsbdevIrqRxFull 

Raised when the RX FIFO is full and the device interface is enabled.

This interrupt is directly tied to the FIFO status, so the RX FIFO must have an entry removed before the interrupt is cleared. If the condition is not cleared, the interrupt can re-assert.

kDtUsbdevIrqAvOverflow 

Raised if a write was done to either the Available OUT Buffer FIFO or the Available SETUP Buffer FIFO when the FIFO was full.

kDtUsbdevIrqLinkInErr 

Raised if a packet to an IN endpoint started to be received but was then dropped due to an error.

After transmitting the IN payload, the USB device expects a valid ACK handshake packet. This error is raised if either the packet or CRC is invalid, leading to a NAK instead, or if a different token was received.

kDtUsbdevIrqRxCrcErr 

Raised if a CRC error occurred on a received packet.

kDtUsbdevIrqRxPidErr 

Raised if an invalid Packet IDentifier (PID) was received.

kDtUsbdevIrqRxBitstuffErr 

Raised if an invalid bitstuffing was received.

kDtUsbdevIrqFrame 

Raised when the USB frame number is updated with a valid SOF.

kDtUsbdevIrqPowered 

Raised if VBUS is applied.

kDtUsbdevIrqLinkOutErr 

Raised if a packet to an OUT endpoint started to be received but was then dropped due to an error.

This error is raised if the data toggle, token, packet and/or CRC are invalid, or if the appropriate Available OUT Buffer FIFO is empty and/or the Received Buffer FIFO is full when a packet should have been received.

kDtUsbdevIrqAvSetupEmpty 

Raised when the Available SETUP Buffer FIFO is empty and the device interface is enabled.

This interrupt is directly tied to the FIFO status, so the Available SETUP Buffer FIFO must be provided with a free buffer before the interrupt can be cleared.

Definition at line 47 of file dt_usbdev.h.

◆ dt_usbdev_periph_io

List of peripheral I/O.

Peripheral I/O are guaranteed to be numbered consecutively from 0.

Definition at line 118 of file dt_usbdev.h.

◆ dt_usbdev_reg_block

List of register blocks.

Register blocks are guaranteed to start at 0 and to be consecutively numbered.

Definition at line 34 of file dt_usbdev.h.

◆ dt_usbdev_reset

List of reset ports.

Reset ports are guaranteed to be numbered consecutively from 0.

Enumerator
kDtUsbdevResetRst 

Reset port rst_ni.

kDtUsbdevResetAon 

Reset port rst_aon_ni.

Definition at line 107 of file dt_usbdev.h.

Function Documentation

◆ dt_usbdev_alert_from_alert_id()

dt_usbdev_alert_t dt_usbdev_alert_from_alert_id ( dt_usbdev_t dt,
dt_alert_id_t alert )

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

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

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

Definition at line 144 of file dt_usbdev.c.

◆ dt_usbdev_alert_to_alert_id()

dt_alert_id_t dt_usbdev_alert_to_alert_id ( dt_usbdev_t dt,
dt_usbdev_alert_t alert )

Get the alert ID of a usbdev 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 usbdev.
alertA usbdev alert.
Returns
The Alert Handler alert ID of the alert of this instance.

Definition at line 138 of file dt_usbdev.c.

◆ dt_usbdev_clock()

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

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

Definition at line 162 of file dt_usbdev.c.

◆ dt_usbdev_from_instance_id()

dt_usbdev_t dt_usbdev_from_instance_id ( dt_instance_id_t inst_id)

Get the usbdev instance from an instance ID.

For example, dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3.

Parameters
inst_idInstance ID.
Returns
A usbdev instance.

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

Definition at line 94 of file dt_usbdev.c.

◆ dt_usbdev_instance_id()

dt_instance_id_t dt_usbdev_instance_id ( dt_usbdev_t dt)

Get the instance ID of an instance.

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

Definition at line 101 of file dt_usbdev.c.

◆ dt_usbdev_irq_from_plic_id()

dt_usbdev_irq_t dt_usbdev_irq_from_plic_id ( dt_usbdev_t dt,
dt_plic_irq_id_t irq )

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

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

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

Definition at line 123 of file dt_usbdev.c.

◆ dt_usbdev_irq_to_plic_id()

dt_plic_irq_id_t dt_usbdev_irq_to_plic_id ( dt_usbdev_t dt,
dt_usbdev_irq_t irq )

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

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

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

Definition at line 113 of file dt_usbdev.c.

◆ dt_usbdev_periph_io()

Get the peripheral I/O description of an instance.

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

Definition at line 155 of file dt_usbdev.c.

◆ dt_usbdev_reg_block()

Get the register base address of an instance.

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

Definition at line 106 of file dt_usbdev.c.

◆ dt_usbdev_reset()

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

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

Definition at line 169 of file dt_usbdev.c.