Software APIs
dt_pwm.h
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#ifndef OPENTITAN_DT_PWM_H_
8#define OPENTITAN_DT_PWM_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif // __cplusplus
13
14/**
15 * @file
16 * @brief Device Tables (DT) for IP pwm and top earlgrey.
17 *
18 * This file contains the type definitions and global functions of the pwm.
19 */
20
21#include "hw/top/dt/dt_api.h"
22#include <stdint.h>
23
24
25
26
27
28/**
29 * List of instances.
30 */
31typedef enum dt_pwm {
32 kDtPwmAon = 0, /**< pwm_aon */
33 kDtPwmFirst = 0, /**< \internal First instance */
34 kDtPwmCount = 1, /**< \internal Number of instances */
36
37/**
38 * List of register blocks.
39 *
40 * Register blocks are guaranteed to start at 0 and to be consecutively numbered.
41 */
42typedef enum dt_pwm_reg_block {
43 kDtPwmRegBlockCore = 0, /**< */
44 kDtPwmRegBlockCount = 1, /**< \internal Number of register blocks */
46
47/**
48 * List of memories.
49 *
50 * Memories are guaranteed to start at 0 and to be consecutively numbered.
51 */
52typedef enum dt_pwm_memory {
53 kDtPwmMemoryCount = 0, /**< \internal Number of memories */
55
56/** Primary register block (associated with the "primary" set of registers that control the IP). */
57static const dt_pwm_reg_block_t kDtPwmRegBlockPrimary = kDtPwmRegBlockCore;
58
59/**
60 * List of Alerts.
61 *
62 * Alerts are guaranteed to be numbered consecutively from 0.
63 */
64typedef enum dt_pwm_alert {
65 kDtPwmAlertFatalFault = 0, /**< This fatal alert is triggered when a fatal TL-UL bus integrity fault is detected. */
66 kDtPwmAlertCount = 1, /**< \internal Number of Alerts */
68
69/**
70 * List of clock ports.
71 *
72 * Clock ports are guaranteed to be numbered consecutively from 0.
73 */
74typedef enum dt_pwm_clock {
75 kDtPwmClockClk = 0, /**< Clock port clk_i */
76 kDtPwmClockCore = 1, /**< Clock port clk_core_i */
77 kDtPwmClockCount = 2, /**< \internal Number of clock ports */
79
80/**
81 * List of reset ports.
82 *
83 * Reset ports are guaranteed to be numbered consecutively from 0.
84 */
85typedef enum dt_pwm_reset {
86 kDtPwmResetRst = 0, /**< Reset port rst_ni */
87 kDtPwmResetCore = 1, /**< Reset port rst_core_ni */
88 kDtPwmResetCount = 2, /**< \internal Number of reset ports */
90
91/**
92 * List of peripheral I/O.
93 *
94 * Peripheral I/O are guaranteed to be numbered consecutively from 0.
95 */
96typedef enum dt_pwm_periph_io {
97 kDtPwmPeriphIoPwm0 = 0, /**< */
98 kDtPwmPeriphIoPwm1 = 1, /**< */
99 kDtPwmPeriphIoPwm2 = 2, /**< */
100 kDtPwmPeriphIoPwm3 = 3, /**< */
101 kDtPwmPeriphIoPwm4 = 4, /**< */
102 kDtPwmPeriphIoPwm5 = 5, /**< */
103 kDtPwmPeriphIoCount = 6, /**< \internal Number of peripheral I/O */
105
106/**
107 * List of supported hardware features.
108 */
109#define OPENTITAN_PWM_HAS_DUTYCYCLE 1
110#define OPENTITAN_PWM_HAS_BLINK 1
111#define OPENTITAN_PWM_HAS_HEARTBEAT 1
112#define OPENTITAN_PWM_HAS_POLARITY 1
113#define OPENTITAN_PWM_HAS_CLOCKDIVIDER 1
114#define OPENTITAN_PWM_HAS_PHASEDELAY 1
115
116
117
118/**
119 * Get the pwm instance from an instance ID
120 *
121 * For example, `dt_uart_from_instance_id(kDtInstanceIdUart3) == kDtUart3`.
122 *
123 * @param inst_id Instance ID.
124 * @return A pwm instance.
125 *
126 * **Note:** This function only makes sense if the instance ID has device type pwm,
127 * otherwise the returned value is unspecified.
128 */
130
131/**
132 * Get the instance ID of an instance.
133 *
134 * @param dt Instance of pwm.
135 * @return The instance ID of that instance.
136 */
138
139/**
140 * Get the register base address of an instance.
141 *
142 * @param dt Instance of pwm.
143 * @param reg_block The register block requested.
144 * @return The register base address of the requested block.
145 */
146uint32_t dt_pwm_reg_block(
147 dt_pwm_t dt,
148 dt_pwm_reg_block_t reg_block);
149
150/**
151 * Get the primary register base address of an instance.
152 *
153 * This is just a convenience function, equivalent to
154 * `dt_pwm_reg_block(dt, kDtPwmRegBlockCore)`
155 *
156 * @param dt Instance of pwm.
157 * @return The register base address of the primary register block.
158 */
159static inline uint32_t dt_pwm_primary_reg_block(
160 dt_pwm_t dt) {
161 return dt_pwm_reg_block(dt, kDtPwmRegBlockCore);
162}
163
164/**
165 * Get the base address of a memory.
166 *
167 * @param dt Instance of pwm.
168 * @param mem The memory requested.
169 * @return The base address of the requested memory.
170 */
171uint32_t dt_pwm_memory_base(
172 dt_pwm_t dt,
173 dt_pwm_memory_t mem);
174
175/**
176 * Get the size of a memory.
177 *
178 * @param dt Instance of pwm.
179 * @param mem The memory requested.
180 * @return The size of the requested memory.
181 */
182uint32_t dt_pwm_memory_size(
183 dt_pwm_t dt,
184 dt_pwm_memory_t mem);
185
186
187/**
188 * Get the alert ID of a pwm alert for a given instance.
189 *
190 * **Note:** This function only makes sense if the instance is connected to the Alert Handler. For any
191 * instances where the instance is not connected, the return value is unspecified.
192 *
193 * @param dt Instance of pwm.
194 * @param alert A pwm alert.
195 * @return The Alert Handler alert ID of the alert of this instance.
196 */
198 dt_pwm_t dt,
199 dt_pwm_alert_t alert);
200
201/**
202 * Convert a global alert ID to a local pwm alert type.
203 *
204 * @param dt Instance of pwm.
205 * @param alert A global alert ID that belongs to this instance.
206 * @return The pwm alert, or `kDtPwmAlertCount`.
207 *
208 * **Note:** This function assumes that the global alert ID belongs to the
209 * instance of pwm passed in parameter. In other words, it must be the case
210 * that `dt_pwm_instance_id(dt) == dt_alert_id_to_instance_id(alert)`. Otherwise,
211 * this function will return `kDtPwmAlertCount`.
212 */
214 dt_pwm_t dt,
215 dt_alert_id_t alert);
216
217
218/**
219 * Get the peripheral I/O description of an instance.
220 *
221 * @param dt Instance of pwm.
222 * @param sig Requested peripheral I/O.
223 * @return Description of the requested peripheral I/O for this instance.
224 */
226 dt_pwm_t dt,
228
229/**
230 * Get the clock signal connected to a clock port of an instance.
231 *
232 * @param dt Instance of pwm.
233 * @param clk Clock port.
234 * @return Clock signal.
235 */
237 dt_pwm_t dt,
238 dt_pwm_clock_t clk);
239
240/**
241 * Get the reset signal connected to a reset port of an instance.
242 *
243 * @param dt Instance of pwm.
244 * @param rst Reset port.
245 * @return Reset signal.
246 */
248 dt_pwm_t dt,
249 dt_pwm_reset_t rst);
250
251
252
253/**
254 * Get the Number of output channels.
255 *
256 * @param dt Instance of pwm.
257 * @return Number of output channels.
258 */
260
261
262
263#ifdef __cplusplus
264} // extern "C"
265#endif // __cplusplus
266
267#endif // OPENTITAN_DT_PWM_H_