Software APIs
dt_sensor_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 sensor_ctrl and top earlgrey.
10 */
11
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_sensor_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtSensorCtrlRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtSensorCtrlMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtSensorCtrlMemoryCount]; /**< Size in bytes of each memory */
24 /**
25 * PLIC ID of the first IRQ of this instance
26 *
27 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
28 */
30 /**
31 * Alert ID of the first Alert of this instance.
32 *
33 * This value is undefined if the block is not connected to the Alert Handler.
34 */
36 dt_clock_t clock[kDtSensorCtrlClockCount]; /**< Clock signal connected to each clock port */
37 dt_reset_t reset[kDtSensorCtrlResetCount]; /**< Reset signal connected to each reset port */
38 dt_periph_io_t periph_io[kDtSensorCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
40
41
42
43
44static const dt_desc_sensor_ctrl_t sensor_ctrl_desc[kDtSensorCtrlCount] = {
47 .reg_addr = {
48 [kDtSensorCtrlRegBlockCore] = 0x40490000,
49 },
50 .mem_addr = {
51 },
52 .mem_size = {
53 },
56 .clock = {
59 },
60 .reset = {
63 },
64 .periph_io = {
65 [kDtSensorCtrlPeriphIoAstDebugOut0] = {
66 .__internal = {
67 .type = kDtPeriphIoTypeMio,
68 .dir = kDtPeriphIoDirOut,
69 .periph_input_or_direct_pad = 0,
71 },
72 },
73 [kDtSensorCtrlPeriphIoAstDebugOut1] = {
74 .__internal = {
75 .type = kDtPeriphIoTypeMio,
76 .dir = kDtPeriphIoDirOut,
77 .periph_input_or_direct_pad = 0,
79 },
80 },
81 [kDtSensorCtrlPeriphIoAstDebugOut2] = {
82 .__internal = {
83 .type = kDtPeriphIoTypeMio,
84 .dir = kDtPeriphIoDirOut,
85 .periph_input_or_direct_pad = 0,
87 },
88 },
89 [kDtSensorCtrlPeriphIoAstDebugOut3] = {
90 .__internal = {
91 .type = kDtPeriphIoTypeMio,
92 .dir = kDtPeriphIoDirOut,
93 .periph_input_or_direct_pad = 0,
95 },
96 },
97 [kDtSensorCtrlPeriphIoAstDebugOut4] = {
98 .__internal = {
99 .type = kDtPeriphIoTypeMio,
100 .dir = kDtPeriphIoDirOut,
101 .periph_input_or_direct_pad = 0,
103 },
104 },
105 [kDtSensorCtrlPeriphIoAstDebugOut5] = {
106 .__internal = {
107 .type = kDtPeriphIoTypeMio,
108 .dir = kDtPeriphIoDirOut,
109 .periph_input_or_direct_pad = 0,
111 },
112 },
113 [kDtSensorCtrlPeriphIoAstDebugOut6] = {
114 .__internal = {
115 .type = kDtPeriphIoTypeMio,
116 .dir = kDtPeriphIoDirOut,
117 .periph_input_or_direct_pad = 0,
119 },
120 },
121 [kDtSensorCtrlPeriphIoAstDebugOut7] = {
122 .__internal = {
123 .type = kDtPeriphIoTypeMio,
124 .dir = kDtPeriphIoDirOut,
125 .periph_input_or_direct_pad = 0,
127 },
128 },
129 [kDtSensorCtrlPeriphIoAstDebugOut8] = {
130 .__internal = {
131 .type = kDtPeriphIoTypeMio,
132 .dir = kDtPeriphIoDirOut,
133 .periph_input_or_direct_pad = 0,
135 },
136 },
137 },
138 },
139};
140
141/**
142 * Return a pointer to the `dt_sensor_ctrl_desc_t` structure of the requested
143 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
144 * the function) with the provided default value.
145 */
146#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sensor_ctrl_t)0 || (dt) >= kDtSensorCtrlCount) return (default); &sensor_ctrl_desc[dt]; })
147
154
159
162 dt_sensor_ctrl_reg_block_t reg_block) {
163 // Return a recognizable address in case of wrong argument.
164 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
165}
166
170 // Return a recognizable address in case of wrong argument.
171 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
172}
173
177 // Return an empty size in case of wrong argument.
178 return TRY_GET_DT(dt, 0)->mem_size[mem];
179}
180
184 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
185 if (first_irq == kDtPlicIrqIdNone) {
186 return kDtPlicIrqIdNone;
187 }
188 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
189}
190
193 dt_plic_irq_id_t irq) {
194 dt_sensor_ctrl_irq_t count = kDtSensorCtrlIrqCount;
195 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
196 if (first_irq == kDtPlicIrqIdNone) {
197 return count;
198 }
199 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
200 return count;
201 }
202 return (dt_sensor_ctrl_irq_t)(irq - first_irq);
203}
204
205
209 return (dt_alert_id_t)((uint32_t)sensor_ctrl_desc[dt].first_alert + (uint32_t)alert);
210}
211
214 dt_alert_id_t alert) {
215 dt_sensor_ctrl_alert_t count = kDtSensorCtrlAlertCount;
216 if (alert < sensor_ctrl_desc[dt].first_alert || alert >= sensor_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
217 return count;
218 }
219 return (dt_sensor_ctrl_alert_t)(alert - sensor_ctrl_desc[dt].first_alert);
220}
221
222
226 // Return a harmless value in case of wrong argument.
227 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
228}
229
233 // Return the first clock in case of invalid argument.
234 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
235}
236
240 const dt_sensor_ctrl_reset_t count = kDtSensorCtrlResetCount;
241 if (rst >= count) {
242 return kDtResetUnknown;
243 }
244 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
245}
246
247