Software APIs
dt_pwm.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 pwm and top earlgrey.
10 */
11
12#include "hw/top/dt/dt_pwm.h"
13
14
15
16
17
18/**
19 * Description of instances.
20 */
21typedef struct dt_desc_pwm {
22 dt_instance_id_t inst_id; /**< Instance ID */
23 uint32_t reg_addr[kDtPwmRegBlockCount]; /**< Base address of each register block */
24 uint32_t mem_addr[kDtPwmMemoryCount]; /**< Base address of each memory */
25 uint32_t mem_size[kDtPwmMemoryCount]; /**< Size in bytes of each memory */
26 /**
27 * Alert ID of the first Alert of this instance.
28 *
29 * This value is undefined if the block is not connected to the Alert Handler.
30 */
32 dt_clock_t clock[kDtPwmClockCount]; /**< Clock signal connected to each clock port */
33 dt_reset_t reset[kDtPwmResetCount]; /**< Reset signal connected to each reset port */
34 dt_periph_io_t periph_io[kDtPwmPeriphIoCount]; /**< Description of each peripheral I/O */
35 struct {
36 uint8_t output_channel_count; /**< Number of output channels */
37 } ipgen_ext; /**< Extension */
39
40
41
42
43static const dt_desc_pwm_t pwm_desc[kDtPwmCount] = {
44 [kDtPwmAon] = {
45 .inst_id = kDtInstanceIdPwmAon,
46 .reg_addr = {
47 [kDtPwmRegBlockCore] = 0x40450000,
48 },
49 .mem_addr = {
50 },
51 .mem_size = {
52 },
54 .clock = {
57 },
58 .reset = {
61 },
62 .periph_io = {
63 [kDtPwmPeriphIoPwm0] = {
64 .__internal = {
65 .type = kDtPeriphIoTypeMio,
66 .dir = kDtPeriphIoDirOut,
67 .periph_input_or_direct_pad = 0,
68 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm0,
69 },
70 },
71 [kDtPwmPeriphIoPwm1] = {
72 .__internal = {
73 .type = kDtPeriphIoTypeMio,
74 .dir = kDtPeriphIoDirOut,
75 .periph_input_or_direct_pad = 0,
76 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm1,
77 },
78 },
79 [kDtPwmPeriphIoPwm2] = {
80 .__internal = {
81 .type = kDtPeriphIoTypeMio,
82 .dir = kDtPeriphIoDirOut,
83 .periph_input_or_direct_pad = 0,
84 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm2,
85 },
86 },
87 [kDtPwmPeriphIoPwm3] = {
88 .__internal = {
89 .type = kDtPeriphIoTypeMio,
90 .dir = kDtPeriphIoDirOut,
91 .periph_input_or_direct_pad = 0,
92 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm3,
93 },
94 },
95 [kDtPwmPeriphIoPwm4] = {
96 .__internal = {
97 .type = kDtPeriphIoTypeMio,
98 .dir = kDtPeriphIoDirOut,
99 .periph_input_or_direct_pad = 0,
100 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm4,
101 },
102 },
103 [kDtPwmPeriphIoPwm5] = {
104 .__internal = {
105 .type = kDtPeriphIoTypeMio,
106 .dir = kDtPeriphIoDirOut,
107 .periph_input_or_direct_pad = 0,
108 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm5,
109 },
110 },
111 },
112 .ipgen_ext = {
113 .output_channel_count = 6,
114 },
115 },
116};
117
118/**
119 * Return a pointer to the `dt_pwm_desc_t` structure of the requested
120 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
121 * the function) with the provided default value.
122 */
123#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwm_t)0 || (dt) >= kDtPwmCount) return (default); &pwm_desc[dt]; })
124
126 if (inst_id >= kDtInstanceIdPwmAon && inst_id <= kDtInstanceIdPwmAon) {
127 return (dt_pwm_t)(inst_id - kDtInstanceIdPwmAon);
128 }
129 return (dt_pwm_t)0;
130}
131
136
138 dt_pwm_t dt,
139 dt_pwm_reg_block_t reg_block) {
140 // Return a recognizable address in case of wrong argument.
141 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
142}
143
145 dt_pwm_t dt,
146 dt_pwm_memory_t mem) {
147 // Return a recognizable address in case of wrong argument.
148 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
149}
150
152 dt_pwm_t dt,
153 dt_pwm_memory_t mem) {
154 // Return an empty size in case of wrong argument.
155 return TRY_GET_DT(dt, 0)->mem_size[mem];
156}
157
158
160 dt_pwm_t dt,
161 dt_pwm_alert_t alert) {
162 return (dt_alert_id_t)((uint32_t)pwm_desc[dt].first_alert + (uint32_t)alert);
163}
164
166 dt_pwm_t dt,
167 dt_alert_id_t alert) {
168 dt_pwm_alert_t count = kDtPwmAlertCount;
169 if (alert < pwm_desc[dt].first_alert || alert >= pwm_desc[dt].first_alert + (dt_alert_id_t)count) {
170 return count;
171 }
172 return (dt_pwm_alert_t)(alert - pwm_desc[dt].first_alert);
173}
174
175
177 dt_pwm_t dt,
178 dt_pwm_periph_io_t sig) {
179 // Return a harmless value in case of wrong argument.
180 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
181}
182
184 dt_pwm_t dt,
185 dt_pwm_clock_t clk) {
186 // Return the first clock in case of invalid argument.
187 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
188}
189
191 dt_pwm_t dt,
192 dt_pwm_reset_t rst) {
193 const dt_pwm_reset_t count = kDtPwmResetCount;
194 if (rst >= count) {
195 return kDtResetUnknown;
196 }
197 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
198}
199
200
201
203 return TRY_GET_DT(dt, 0)->ipgen_ext.output_channel_count;
204}
205
206