Software APIs
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 /**
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] = {
43 [kDtSensorCtrl] = {
44 .inst_id = kDtInstanceIdSensorCtrl,
45 .reg_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 },
124 },
125};
126
127/**
128 * Return a pointer to the `dt_sensor_ctrl_desc_t` structure of the requested
129 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
130 * the function) with the provided default value.
131 */
132#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sensor_ctrl_t)0 || (int)(dt) >= kDtSensorCtrlCount) return (default); &sensor_ctrl_desc[dt]; })
133
140
145
148 dt_sensor_ctrl_reg_block_t reg_block) {
149 // Return a recognizable address in case of wrong argument.
150 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
151}
152
156 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
157 if (first_irq == kDtPlicIrqIdNone) {
158 return kDtPlicIrqIdNone;
159 }
160 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
161}
162
165 dt_plic_irq_id_t irq) {
167 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
168 if (first_irq == kDtPlicIrqIdNone) {
169 return count;
170 }
171 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
172 return count;
173 }
174 return (dt_sensor_ctrl_irq_t)(irq - first_irq);
175}
176
177
181 return (dt_alert_id_t)((uint32_t)sensor_ctrl_desc[dt].first_alert + (uint32_t)alert);
182}
183
186 dt_alert_id_t alert) {
188 if (alert < sensor_ctrl_desc[dt].first_alert || alert >= sensor_ctrl_desc[dt].first_alert + (dt_alert_id_t)count) {
189 return count;
190 }
191 return (dt_sensor_ctrl_alert_t)(alert - sensor_ctrl_desc[dt].first_alert);
192}
193
194
198 // Return a harmless value in case of wrong argument.
199 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
200}
201
205 // Return the first clock in case of invalid argument.
206 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
207}
208
213 if (rst >= count) {
214 return kDtResetUnknown;
215 }
216 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
217}
218
219