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 "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 base_addr[kDtOtpMacroRegBlockCount]; /**< Base address of each register block */
22 dt_clock_t clock[kDtOtpMacroClockCount]; /**< Clock signal connected to each clock port */
23 dt_reset_t reset[kDtOtpMacroResetCount]; /**< Reset signal connected to each reset port */
24 dt_periph_io_t periph_io[kDtOtpMacroPeriphIoCount]; /**< Description of each peripheral I/O */
26
27
28
29
30static const dt_desc_otp_macro_t otp_macro_desc[kDtOtpMacroCount] = {
31 [kDtOtpMacro] = {
32 .inst_id = kDtInstanceIdOtpMacro,
33 .base_addr = {
34 [kDtOtpMacroRegBlockCore] = 0x40138000,
35 },
36 .clock = {
38 },
39 .reset = {
41 },
42 .periph_io = {
43 [kDtOtpMacroPeriphIoTest0] = {
44 .__internal = {
45 .type = kDtPeriphIoTypeMio,
46 .dir = kDtPeriphIoDirOut,
47 .periph_input_or_direct_pad = 0,
48 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselOtpMacroTest0,
49 },
50 },
51 [kDtOtpMacroPeriphIoTest1] = {
52 .__internal = {
55 .periph_input_or_direct_pad = 0,
56 .outsel_or_dt_pad = 0,
57 },
58 },
59 [kDtOtpMacroPeriphIoTest2] = {
60 .__internal = {
63 .periph_input_or_direct_pad = 0,
64 .outsel_or_dt_pad = 0,
65 },
66 },
67 [kDtOtpMacroPeriphIoTest3] = {
68 .__internal = {
71 .periph_input_or_direct_pad = 0,
72 .outsel_or_dt_pad = 0,
73 },
74 },
75 [kDtOtpMacroPeriphIoTest4] = {
76 .__internal = {
79 .periph_input_or_direct_pad = 0,
80 .outsel_or_dt_pad = 0,
81 },
82 },
83 [kDtOtpMacroPeriphIoTest5] = {
84 .__internal = {
87 .periph_input_or_direct_pad = 0,
88 .outsel_or_dt_pad = 0,
89 },
90 },
91 [kDtOtpMacroPeriphIoTest6] = {
92 .__internal = {
95 .periph_input_or_direct_pad = 0,
96 .outsel_or_dt_pad = 0,
97 },
98 },
99 [kDtOtpMacroPeriphIoTest7] = {
100 .__internal = {
102 .dir = kDtPeriphIoDirInout,
103 .periph_input_or_direct_pad = 0,
104 .outsel_or_dt_pad = 0,
105 },
106 },
107 },
108 },
109};
110
111/**
112 * Return a pointer to the `dt_otp_macro_desc_t` structure of the requested
113 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
114 * the function) with the provided default value.
115 */
116#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_otp_macro_t)0 || (dt) >= kDtOtpMacroCount) return (default); &otp_macro_desc[dt]; })
117
119 if (inst_id >= kDtInstanceIdOtpMacro && inst_id <= kDtInstanceIdOtpMacro) {
120 return (dt_otp_macro_t)(inst_id - kDtInstanceIdOtpMacro);
121 }
122 return (dt_otp_macro_t)0;
123}
124
129
132 dt_otp_macro_reg_block_t reg_block) {
133 // Return a recognizable address in case of wrong argument.
134 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
135}
136
137
138
142 // Return a harmless value in case of wrong argument.
143 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
144}
145
149 // Return the first clock in case of invalid argument.
150 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
151}
152
156 const dt_otp_macro_reset_t count = kDtOtpMacroResetCount;
157 if (rst >= count) {
158 return kDtResetUnknown;
159 }
160 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
161}
162
163