Software APIs
Macros | Typedefs | Enumerations | Functions | Variables
device.h File Reference

(c534d13)

This header contains declarations of device-specific information. More...

#include <stdbool.h>
#include <stdint.h>
#include "sw/device/lib/base/macros.h"

Go to the source code of this file.

Macros

#define CALCULATE_UART_NCO_(baudrate, peripheral_clock)
 A helper macro to calculate NCO values. More...
 
#define CALCULATE_UART_NCO(baudrate, peripheral_clock)
 
#define CALCULATE_UART_TX_FIFO_CPU_CYCLES(baud_rate_, cpu_freq_, fifo_depth_)   ((cpu_freq_)*10 * (fifo_depth_) / (baud_rate_))
 Helper macro to calculate the time it takes to transmit the entire UART TX FIFO in CPU cycles. More...
 
#define CALCULATE_AST_CHECK_POLL_CPU_CYCLES(cpu_freq_)   ((cpu_freq_)*100 / 1000000)
 Helper macro to calculate the maximum duration of the AST initialization check poll in CPU cycles. More...
 

Typedefs

typedef enum device_type device_type_t
 A device_type_t represents a particular device type for which device-specific symbols are available.
 

Enumerations

enum  device_type {
  kDeviceSimDV = 0,
  kDeviceSimVerilator = 1,
  kDeviceFpgaCw310 = 2,
  kDeviceFpgaCw305 = 3,
  kDeviceFpgaCw340 = 4,
  kDeviceSilicon = 5
}
 A device_type_t represents a particular device type for which device-specific symbols are available. More...
 

Functions

OT_WARN_UNUSED_RESULT uint64_t to_cpu_cycles (uint64_t usec)
 A platform-specific function to convert microseconds to cpu cycles. More...
 
void device_fpga_version_print (void)
 Prints the FPGA version. More...
 

Variables

const device_type_t kDeviceType
 Indicates the device that this program has been linked for. More...
 
const uint64_t kClockFreqCpuHz
 The CPU clock frequency of the device, in hertz. More...
 
const uint64_t kClockFreqPeripheralHz
 The peripheral clock frequency of the device, in hertz. More...
 
const uint64_t kClockFreqHiSpeedPeripheralHz
 The high-speed peripheral clock frequency of the device, in hertz. More...
 
const uint64_t kClockFreqUsbHz
 The USB clock frequency of the device, in hertz. More...
 
const uint64_t kClockFreqAonHz
 The always on clock frequency of the device, in hertz. More...
 
const uint64_t kUartBaudrate
 The baudrate of the UART peripheral (if such a thing is present).
 
const uint32_t kUartNCOValue
 The pre-calculated UART NCO value based on the Baudrate and Peripheral clock.
 
const uint32_t kUartBaud115K
 Additional pre-calculated UART NCO values. More...
 
const uint32_t kUartBaud230K
 
const uint32_t kUartBaud460K
 
const uint32_t kUartBaud921K
 
const uint32_t kUartBaud1M33
 
const uint32_t kUartBaud1M50
 
const uint32_t kUartTxFifoCpuCycles
 The time it takes to transmit the entire UART TX fifo in CPU cycles.
 
const uint32_t kAstCheckPollCpuCycles
 Maximum duration of the AST initialization check poll in CPU cycles. More...
 
const uintptr_t kDeviceTestStatusAddress
 An address to write to report test status. More...
 
const uintptr_t kDeviceLogBypassUartAddress
 An address to write use for UART logging bypass. More...
 

Detailed Description

This header contains declarations of device-specific information.

This header contains "device-specific" declarations, i.e., information that all devices are known to provide, but which is specific to the particular choice of platform, which can range from a software simulation, like Verilator or a DV testbench, to real harware, like an FPGA or ASIC.

Definitions for these symbols can be found in other files in this directory, which should be linked in depending on which platform an executable is intended for.

Definition in file device.h.

Macro Definition Documentation

◆ CALCULATE_AST_CHECK_POLL_CPU_CYCLES

#define CALCULATE_AST_CHECK_POLL_CPU_CYCLES (   cpu_freq_)    ((cpu_freq_)*100 / 1000000)

Helper macro to calculate the maximum duration of the AST initialization check poll in CPU cycles.

This macro assumes that the desired duration is 100us.

Definition at line 173 of file device.h.

◆ CALCULATE_UART_NCO

#define CALCULATE_UART_NCO (   baudrate,
  peripheral_clock 
)
Value:
CALCULATE_UART_NCO_(baudrate, peripheral_clock) < 0x10000 \
? CALCULATE_UART_NCO_(baudrate, peripheral_clock) \
: 0;

Definition at line 131 of file device.h.

◆ CALCULATE_UART_NCO_

#define CALCULATE_UART_NCO_ (   baudrate,
  peripheral_clock 
)
Value:
(baudrate == 1500000 && peripheral_clock == 24000000) \
? 0xffff \
: (uint32_t)(((uint64_t)(baudrate) << (16 + 4)) / (peripheral_clock))

A helper macro to calculate NCO values.

NOTE: the left shift value is dependent on the UART hardware. The NCO width is 16 bits and the NCO calculates a 16x oversampling clock. If uart baud rate is 1.5Mbps and IO is 24Mhz, NCO is 0x10000, which is over the NCO width, use NCO = 0xffff for this case since the error is tolerable. Refer to #4263

Definition at line 126 of file device.h.

◆ CALCULATE_UART_TX_FIFO_CPU_CYCLES

#define CALCULATE_UART_TX_FIFO_CPU_CYCLES (   baud_rate_,
  cpu_freq_,
  fifo_depth_ 
)    ((cpu_freq_)*10 * (fifo_depth_) / (baud_rate_))

Helper macro to calculate the time it takes to transmit the entire UART TX FIFO in CPU cycles.

This macro assumes 10 bits per byte (no parity bits) and a 128 byte deep TX FIFO.

Definition at line 159 of file device.h.

Enumeration Type Documentation

◆ device_type

A device_type_t represents a particular device type for which device-specific symbols are available.

Enumerator
kDeviceSimDV 

Represents "DV", i.e.

running the test in a DV simulation testbench.

DISCLAIMER: it is important this value remains assigned to 0, as it is implicitly checked in the test_rom_start.S assembly code to determine whether or not to initialize SRAM.

kDeviceSimVerilator 

Represents the "Verilator" device, i.e., a synthesis of the OpenTitan design by Verilator into C++.

kDeviceFpgaCw310 

Represents the "ChipWhisperer CW310 FPGA" device, i.e., the particular FPGA board blessed for OpenTitan development, containing a Xilinx FPGA.

kDeviceFpgaCw305 

Represents the "ChipWhisperer CW305 FPGA" device, i.e., the smaller FPGA development board with SCA capability, containing a Xilinx FPGA.

kDeviceFpgaCw340 

Represents the "ChipWhisperer CW340 FPGA" device, i.e., the particular FPGA board blessed for OpenTitan development, containing a Xilinx FPGA.

kDeviceSilicon 

Represents the "Silicon" device, i.e., an instantiation of OpenTitan in Silicon.

Definition at line 35 of file device.h.

Function Documentation

◆ device_fpga_version_print()

void device_fpga_version_print ( void  )

Prints the FPGA version.

This function is a NOP unless we are building for an FPGA.

Definition at line 61 of file device_fpga_cw305.c.

◆ to_cpu_cycles()

OT_WARN_UNUSED_RESULT uint64_t to_cpu_cycles ( uint64_t  usec)

A platform-specific function to convert microseconds to cpu cycles.

This is primarily used for spin waits that use the cpu cycle counters. For platforms with clock periods slower than 1 us this will round up.

Definition at line 25 of file device_fpga_cw305.c.

Variable Documentation

◆ kAstCheckPollCpuCycles

const uint32_t kAstCheckPollCpuCycles

Maximum duration of the AST initialization check poll in CPU cycles.

This number depends on kClockFreqCpuHz and the resulting duration must be 100us.

Definition at line 54 of file device_fpga_cw305.c.

◆ kClockFreqAonHz

const uint64_t kClockFreqAonHz

The always on clock frequency of the device, in hertz.

This is the operating clock used by the always on timer, power manager and other peripherals that continue to operate after the device is in sleep state.

Definition at line 31 of file device_fpga_cw305.c.

◆ kClockFreqCpuHz

const uint64_t kClockFreqCpuHz

The CPU clock frequency of the device, in hertz.

This is the operating clock for the main processing host.

Definition at line 23 of file device_fpga_cw305.c.

◆ kClockFreqHiSpeedPeripheralHz

const uint64_t kClockFreqHiSpeedPeripheralHz

The high-speed peripheral clock frequency of the device, in hertz.

This is the operating clock used by the spi host

Definition at line 27 of file device_fpga_cw310.c.

◆ kClockFreqPeripheralHz

const uint64_t kClockFreqPeripheralHz

The peripheral clock frequency of the device, in hertz.

This is the operating clock used by timers, uarts, other peripheral interfaces.

Definition at line 27 of file device_fpga_cw305.c.

◆ kClockFreqUsbHz

const uint64_t kClockFreqUsbHz

The USB clock frequency of the device, in hertz.

This is the operating clock used by the USB phy interface and USB's software interface.

Definition at line 29 of file device_fpga_cw305.c.

◆ kDeviceLogBypassUartAddress

const uintptr_t kDeviceLogBypassUartAddress

An address to write use for UART logging bypass.

If this is zero, there is no address to write to bypass UART logging.

See also
LOG

Definition at line 59 of file device_fpga_cw305.c.

◆ kDeviceTestStatusAddress

const uintptr_t kDeviceTestStatusAddress

An address to write to report test status.

If this is zero, there is no address to write to report test status.

Depending on the simulation environment and the value written to this address, the simulation may stop.

See also
#test_status_set

Definition at line 57 of file device_fpga_cw305.c.

◆ kDeviceType

const device_type_t kDeviceType

Indicates the device that this program has been linked for.

This can be used, for example, for conditioning an operation on the precise device type.

Indicates the device that this program has been linked for.

Definition at line 19 of file device_fpga_cw305.c.

◆ kUartBaud115K

const uint32_t kUartBaud115K

Additional pre-calculated UART NCO values.

If the pre-calculated value is zero, then the corresponding baudrate is not supported.

Definition at line 38 of file device_fpga_cw305.c.