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 "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 base_addr[kDtPwmRegBlockCount]; /**< Base address of each register block */
24 /**
25 * Alert ID of the first Alert of this instance.
26 *
27 * This value is undefined if the block is not connected to the Alert Handler.
28 */
30 dt_clock_t clock[kDtPwmClockCount]; /**< Clock signal connected to each clock port */
31 dt_reset_t reset[kDtPwmResetCount]; /**< Reset signal connected to each reset port */
32 dt_periph_io_t periph_io[kDtPwmPeriphIoCount]; /**< Description of each peripheral I/O */
33 struct {
34 uint8_t output_channel_count; /**< Number of output channels */
35 } ipgen_ext; /**< Extension */
37
38
39
40
41static const dt_desc_pwm_t pwm_desc[kDtPwmCount] = {
42 [kDtPwmAon] = {
43 .inst_id = kDtInstanceIdPwmAon,
44 .base_addr = {
45 [kDtPwmRegBlockCore] = 0x40450000,
46 },
48 .clock = {
51 },
52 .reset = {
55 },
56 .periph_io = {
57 [kDtPwmPeriphIoPwm0] = {
58 .__internal = {
59 .type = kDtPeriphIoTypeMio,
60 .dir = kDtPeriphIoDirOut,
61 .periph_input_or_direct_pad = 0,
62 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm0,
63 },
64 },
65 [kDtPwmPeriphIoPwm1] = {
66 .__internal = {
67 .type = kDtPeriphIoTypeMio,
68 .dir = kDtPeriphIoDirOut,
69 .periph_input_or_direct_pad = 0,
70 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm1,
71 },
72 },
73 [kDtPwmPeriphIoPwm2] = {
74 .__internal = {
75 .type = kDtPeriphIoTypeMio,
76 .dir = kDtPeriphIoDirOut,
77 .periph_input_or_direct_pad = 0,
78 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm2,
79 },
80 },
81 [kDtPwmPeriphIoPwm3] = {
82 .__internal = {
83 .type = kDtPeriphIoTypeMio,
84 .dir = kDtPeriphIoDirOut,
85 .periph_input_or_direct_pad = 0,
86 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm3,
87 },
88 },
89 [kDtPwmPeriphIoPwm4] = {
90 .__internal = {
91 .type = kDtPeriphIoTypeMio,
92 .dir = kDtPeriphIoDirOut,
93 .periph_input_or_direct_pad = 0,
94 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm4,
95 },
96 },
97 [kDtPwmPeriphIoPwm5] = {
98 .__internal = {
99 .type = kDtPeriphIoTypeMio,
100 .dir = kDtPeriphIoDirOut,
101 .periph_input_or_direct_pad = 0,
102 .outsel_or_dt_pad = kTopEarlgreyPinmuxOutselPwmAonPwm5,
103 },
104 },
105 },
106 .ipgen_ext = {
107 .output_channel_count = 6,
108 },
109 },
110};
111
112/**
113 * Return a pointer to the `dt_pwm_desc_t` structure of the requested
114 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
115 * the function) with the provided default value.
116 */
117#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_pwm_t)0 || (dt) >= kDtPwmCount) return (default); &pwm_desc[dt]; })
118
120 if (inst_id >= kDtInstanceIdPwmAon && inst_id <= kDtInstanceIdPwmAon) {
121 return (dt_pwm_t)(inst_id - kDtInstanceIdPwmAon);
122 }
123 return (dt_pwm_t)0;
124}
125
130
132 dt_pwm_t dt,
133 dt_pwm_reg_block_t reg_block) {
134 // Return a recognizable address in case of wrong argument.
135 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
136}
137
138
140 dt_pwm_t dt,
141 dt_pwm_alert_t alert) {
142 return (dt_alert_id_t)((uint32_t)pwm_desc[dt].first_alert + (uint32_t)alert);
143}
144
146 dt_pwm_t dt,
147 dt_alert_id_t alert) {
148 dt_pwm_alert_t count = kDtPwmAlertCount;
149 if (alert < pwm_desc[dt].first_alert || alert >= pwm_desc[dt].first_alert + (dt_alert_id_t)count) {
150 return count;
151 }
152 return (dt_pwm_alert_t)(alert - pwm_desc[dt].first_alert);
153}
154
155
157 dt_pwm_t dt,
158 dt_pwm_periph_io_t sig) {
159 // Return a harmless value in case of wrong argument.
160 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
161}
162
164 dt_pwm_t dt,
165 dt_pwm_clock_t clk) {
166 // Return the first clock in case of invalid argument.
167 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
168}
169
171 dt_pwm_t dt,
172 dt_pwm_reset_t rst) {
173 const dt_pwm_reset_t count = kDtPwmResetCount;
174 if (rst >= count) {
175 return kDtResetUnknown;
176 }
177 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
178}
179
180
181
183 return TRY_GET_DT(dt, 0)->ipgen_ext.output_channel_count;
184}
185
186