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
12#include "dt/dt_sensor_ctrl.h"
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 base_addr[kDtSensorCtrlRegBlockCount]; /**< Base address of each register block */
22 /**
23 * PLIC ID of the first IRQ of this instance
24 *
25 * This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26 */
28 /**
29 * Alert ID of the first Alert of this instance.
30 *
31 * This value is undefined if the block is not connected to the Alert Handler.
32 */
34 dt_clock_t clock[kDtSensorCtrlClockCount]; /**< Clock signal connected to each clock port */
35 dt_reset_t reset[kDtSensorCtrlResetCount]; /**< Reset signal connected to each reset port */
36 dt_periph_io_t periph_io[kDtSensorCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
38
39
40
41
42static const dt_desc_sensor_ctrl_t sensor_ctrl_desc[kDtSensorCtrlCount] = {
45 .base_addr = {
46 [kDtSensorCtrlRegBlockCore] = 0x40490000,
47 },
50 .clock = {
53 },
54 .reset = {
57 },
58 .periph_io = {
59 [kDtSensorCtrlPeriphIoAstDebugOut0] = {
60 .__internal = {
61 .type = kDtPeriphIoTypeMio,
62 .dir = kDtPeriphIoDirOut,
63 .periph_input_or_direct_pad = 0,
65 },
66 },
67 [kDtSensorCtrlPeriphIoAstDebugOut1] = {
68 .__internal = {
69 .type = kDtPeriphIoTypeMio,
70 .dir = kDtPeriphIoDirOut,
71 .periph_input_or_direct_pad = 0,
73 },
74 },
75 [kDtSensorCtrlPeriphIoAstDebugOut2] = {
76 .__internal = {
77 .type = kDtPeriphIoTypeMio,
78 .dir = kDtPeriphIoDirOut,
79 .periph_input_or_direct_pad = 0,
81 },
82 },
83 [kDtSensorCtrlPeriphIoAstDebugOut3] = {
84 .__internal = {
85 .type = kDtPeriphIoTypeMio,
86 .dir = kDtPeriphIoDirOut,
87 .periph_input_or_direct_pad = 0,
89 },
90 },
91 [kDtSensorCtrlPeriphIoAstDebugOut4] = {
92 .__internal = {
93 .type = kDtPeriphIoTypeMio,
94 .dir = kDtPeriphIoDirOut,
95 .periph_input_or_direct_pad = 0,
97 },
98 },
99 [kDtSensorCtrlPeriphIoAstDebugOut5] = {
100 .__internal = {
101 .type = kDtPeriphIoTypeMio,
102 .dir = kDtPeriphIoDirOut,
103 .periph_input_or_direct_pad = 0,
105 },
106 },
107 [kDtSensorCtrlPeriphIoAstDebugOut6] = {
108 .__internal = {
109 .type = kDtPeriphIoTypeMio,
110 .dir = kDtPeriphIoDirOut,
111 .periph_input_or_direct_pad = 0,
113 },
114 },
115 [kDtSensorCtrlPeriphIoAstDebugOut7] = {
116 .__internal = {
117 .type = kDtPeriphIoTypeMio,
118 .dir = kDtPeriphIoDirOut,
119 .periph_input_or_direct_pad = 0,
121 },
122 },
123 [kDtSensorCtrlPeriphIoAstDebugOut8] = {
124 .__internal = {
125 .type = kDtPeriphIoTypeMio,
126 .dir = kDtPeriphIoDirOut,
127 .periph_input_or_direct_pad = 0,
129 },
130 },
131 },
132 },
133};
134
135/**
136 * Return a pointer to the `dt_sensor_ctrl_desc_t` structure of the requested
137 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
138 * the function) with the provided default value.
139 */
140#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sensor_ctrl_t)0 || (dt) >= kDtSensorCtrlCount) return (default); &sensor_ctrl_desc[dt]; })
141
148
153
156 dt_sensor_ctrl_reg_block_t reg_block) {
157 // Return a recognizable address in case of wrong argument.
158 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
159}
160
164 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
165 if (first_irq == kDtPlicIrqIdNone) {
166 return kDtPlicIrqIdNone;
167 }
168 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
169}
170
173 dt_plic_irq_id_t irq) {
174 dt_sensor_ctrl_irq_t count = kDtSensorCtrlIrqCount;
175 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
176 if (first_irq == kDtPlicIrqIdNone) {
177 return count;
178 }
179 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
180 return count;
181 }
182 return (dt_sensor_ctrl_irq_t)(irq - first_irq);
183}
184
185
189 return (dt_alert_id_t)((uint32_t)sensor_ctrl_desc[dt].first_alert + (uint32_t)alert);
190}
191
194 dt_alert_id_t alert) {
195 dt_sensor_ctrl_alert_t count = kDtSensorCtrlAlertCount;
196 if (alert < sensor_ctrl_desc[dt].first_alert || alert >= sensor_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
197 return count;
198 }
199 return (dt_sensor_ctrl_alert_t)(alert - sensor_ctrl_desc[dt].first_alert);
200}
201
202
206 // Return a harmless value in case of wrong argument.
207 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
208}
209
213 // Return the first clock in case of invalid argument.
214 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
215}
216
220 const dt_sensor_ctrl_reset_t count = kDtSensorCtrlResetCount;
221 if (rst >= count) {
222 return kDtResetUnknown;
223 }
224 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
225}
226
227