Software APIs
dt_otp_macro.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 otp_macro and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_otp_macro.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_otp_macro {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtOtpMacroRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtOtpMacroMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtOtpMacroMemoryCount]; /**< Size in bytes of each memory */
24 dt_clock_t clock[kDtOtpMacroClockCount]; /**< Clock signal connected to each clock port */
25 dt_reset_t reset[kDtOtpMacroResetCount]; /**< Reset signal connected to each reset port */
26 dt_periph_io_t periph_io[kDtOtpMacroPeriphIoCount]; /**< Description of each peripheral I/O */
28
29
30
31
32static const dt_desc_otp_macro_t otp_macro_desc[kDtOtpMacroCount] = {
33 [kDtOtpMacro] = {
34 .inst_id = kDtInstanceIdOtpMacro,
35 .reg_addr = {
36 [kDtOtpMacroRegBlockPrim] = 0x40138000,
37 },
38 .mem_addr = {
39 },
40 .mem_size = {
41 },
42 .clock = {
44 },
45 .reset = {
47 },
48 .periph_io = {
49 [kDtOtpMacroPeriphIoTest0] = {
50 .__internal = {
51 .type = kDtPeriphIoTypeMio,
52 .dir = kDtPeriphIoDirOut,
53 .periph_input_or_direct_pad = 0,
54 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselOtpMacroTest0,
55 },
56 },
57 [kDtOtpMacroPeriphIoTest1] = {
58 .__internal = {
61 .periph_input_or_direct_pad = 0,
62 .outsel_or_dt_pad = 0,
63 },
64 },
65 [kDtOtpMacroPeriphIoTest2] = {
66 .__internal = {
69 .periph_input_or_direct_pad = 0,
70 .outsel_or_dt_pad = 0,
71 },
72 },
73 [kDtOtpMacroPeriphIoTest3] = {
74 .__internal = {
77 .periph_input_or_direct_pad = 0,
78 .outsel_or_dt_pad = 0,
79 },
80 },
81 [kDtOtpMacroPeriphIoTest4] = {
82 .__internal = {
85 .periph_input_or_direct_pad = 0,
86 .outsel_or_dt_pad = 0,
87 },
88 },
89 [kDtOtpMacroPeriphIoTest5] = {
90 .__internal = {
93 .periph_input_or_direct_pad = 0,
94 .outsel_or_dt_pad = 0,
95 },
96 },
97 [kDtOtpMacroPeriphIoTest6] = {
98 .__internal = {
100 .dir = kDtPeriphIoDirInout,
101 .periph_input_or_direct_pad = 0,
102 .outsel_or_dt_pad = 0,
103 },
104 },
105 [kDtOtpMacroPeriphIoTest7] = {
106 .__internal = {
108 .dir = kDtPeriphIoDirInout,
109 .periph_input_or_direct_pad = 0,
110 .outsel_or_dt_pad = 0,
111 },
112 },
113 },
114 },
115};
116
117/**
118 * Return a pointer to the `dt_otp_macro_desc_t` structure of the requested
119 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
120 * the function) with the provided default value.
121 */
122#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otp_macro_t)0 || (dt) >= kDtOtpMacroCount) return (default); &otp_macro_desc[dt]; })
123
125 if (inst_id >= kDtInstanceIdOtpMacro && inst_id <= kDtInstanceIdOtpMacro) {
126 return (dt_otp_macro_t)(inst_id - kDtInstanceIdOtpMacro);
127 }
128 return (dt_otp_macro_t)0;
129}
130
135
138 dt_otp_macro_reg_block_t reg_block) {
139 // Return a recognizable address in case of wrong argument.
140 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
141}
142
146 // Return a recognizable address in case of wrong argument.
147 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
148}
149
153 // Return an empty size in case of wrong argument.
154 return TRY_GET_DT(dt, 0)->mem_size[mem];
155}
156
157
158
162 // Return a harmless value in case of wrong argument.
163 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
164}
165
169 // Return the first clock in case of invalid argument.
170 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
171}
172
176 const dt_otp_macro_reset_t count = kDtOtpMacroResetCount;
177 if (rst >= count) {
178 return kDtResetUnknown;
179 }
180 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
181}
182
183