Software APIs
dt_rom_ctrl.c
Go to the documentation of this file.
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4//
5// Device table API auto-generated by `dtgen`
6
7/**
8 * @file
9 * @brief Device Tables (DT) for IP rom_ctrl and top englishbreakfast.
10 */
11
12#include "dt/dt_rom_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_rom_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtRomCtrlRegBlockCount]; /**< Base address of each register block */
22 dt_clock_t clock[kDtRomCtrlClockCount]; /**< Clock signal connected to each clock port */
23 dt_reset_t reset[kDtRomCtrlResetCount]; /**< Reset signal connected to each reset port */
25
26
27
28
29static const dt_desc_rom_ctrl_t rom_ctrl_desc[kDtRomCtrlCount] = {
30 [kDtRomCtrl] = {
31 .inst_id = kDtInstanceIdRomCtrl,
32 .base_addr = {
33 [kDtRomCtrlRegBlockRom] = 0x00008000,
34 [kDtRomCtrlRegBlockRegs] = 0x411e0000,
35 },
36 .clock = {
38 },
39 .reset = {
41 },
42 },
43};
44
45/**
46 * Return a pointer to the `dt_rom_ctrl_desc_t` structure of the requested
47 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
48 * the function) with the provided default value.
49 */
50#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rom_ctrl_t)0 || (dt) >= kDtRomCtrlCount) return (default); &rom_ctrl_desc[dt]; })
51
53 if (inst_id >= kDtInstanceIdRomCtrl && inst_id <= kDtInstanceIdRomCtrl) {
54 return (dt_rom_ctrl_t)(inst_id - kDtInstanceIdRomCtrl);
55 }
56 return (dt_rom_ctrl_t)0;
57}
58
63
66 dt_rom_ctrl_reg_block_t reg_block) {
67 // Return a recognizable address in case of wrong argument.
68 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
69}
70
71
72
73
77 // Return the first clock in case of invalid argument.
78 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
79}
80
84 const dt_rom_ctrl_reset_t count = kDtRomCtrlResetCount;
85 if (rst >= count) {
86 return kDtResetUnknown;
87 }
88 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
89}
90
91