1 /*
2 * Copyright (c) 2023 HPMicro
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #ifndef HPM_PWMV2_DRV_H
9 #define HPM_PWMV2_DRV_H
10
11 #include "hpm_common.h"
12 #include "hpm_pwmv2_regs.h"
13 #include "hpm_soc_feature.h"
14
15
16 /**
17 * @brief PWM driver APIs
18 * @defgroup pwmv2_interface PWMV2 driver APIs
19 * @ingroup motor_interfaces
20 * @{
21 *
22 */
23 #define PWM_UNLOCK_KEY (0xB0382607UL)
24 #define PWM_CMP_UNABLE_OUTPUT_INDEX (16)
25
26 /* IRQ enable bit mask */
27 #define PWM_IRQ_FAULT PWM_IRQEN_FAULTIRQE_MASK
28 #define PWM_IRQ_EX_RELOAD PWM_IRQEN_XRLDIRQE_MASK
29 #define PWM_IRQ_HALF_RELOAD PWM_IRQEN_HALFRLDIRQE_MASK
30 #define PWM_IRQ_RELOAD PWM_IRQEN_RLDIRQE_MASK
31 #define PWM_IRQ_CMP(x) PWM_IRQEN_CMPIRQEX_SET((1 << x))
32
33 /* PWM force output mask */
34 #define PWM_FORCE_OUTPUT(pwm_index, force_output) \
35 (force_output << (pwm_index << 1))
36
37 #define PWM_DUTY_CYCLE_FP_MAX ((1U << 24) - 1)
38
39 #ifndef PWMV2_SOC_CAL_COUNT_MAX
40 #define PWMV2_SOC_CAL_COUNT_MAX 8
41 #endif
42
43 #define PWMV2_SHADOW_INDEX(x) PWMV2_SHADOW_VAL_##x
44 #define PWMV2_CMP_INDEX(x) PWMV2_CMP_VAL_WORK_##x
45 #define PWMV2_CALCULATE_INDEX(x) PWMV2_CAL_##x
46 #define PWMV2_CAL_SHADOW_OFFSET_ZERO (31)
47
48 typedef enum {
49 pwm_counter_0 = 0,
50 pwm_counter_1 = 1,
51 pwm_counter_2 = 2,
52 pwm_counter_3 = 3,
53 } pwm_counter_t;
54
55 typedef enum {
56 pwm_channel_0 = 0,
57 pwm_channel_1 = 1,
58 pwm_channel_2 = 2,
59 pwm_channel_3 = 3,
60 pwm_channel_4 = 4,
61 pwm_channel_5 = 5,
62 pwm_channel_6 = 6,
63 pwm_channel_7 = 7,
64 } pwm_channel_t;
65
66
67 typedef enum {
68 pwm_reload_update_on_shlk = 0,
69 pwm_reload_update_on_compare_point = 1,
70 pwm_reload_update_on_reload = 2,
71 pwm_reload_update_on_trigger = 3,
72 } pwm_reload_update_time_t;
73
74
75 /**
76 * @brief pwm output type
77 *
78 */
79 typedef enum {
80 pwm_force_output_0 = 0, /**< output 0 */
81 pwm_force_output_1 = 1, /**< output 1 */
82 pwm_force_output_high_z = 2, /**< output */
83 pwm_force_output_no_force = 3,
84 } pwm_force_mode_t;
85
86 typedef enum {
87 pwm_fault_output_0 = 0, /**< output 0 */
88 pwm_fault_output_1 = 1, /**< output 1 */
89 pwm_fault_output_high_z = 2, /**< output */
90 } pwm_fault_mode_t;
91
92 typedef enum {
93 pad_fault_active_low = 1,
94 pad_fault_active_high = 0,
95 } pwm_fault_pad_polarity_t;
96
97 typedef enum {
98 pwm_shadow_register_output_polarity_on_shlk = 0,
99 pwm_shadow_register_output_polarity_on_reload = 1,
100 } pwm_shadow_register_output_polarity_t;
101
102 typedef enum {
103 pwm_force_update_shadow_immediately = 0, /**< after software set shlk bit of shlk register */
104 pwm_force_update_shadow_at_cmp_point = 1,
105 pwm_force_update_shadow_at_reload = 2, /**< immediately after the register being modified */
106 pwm_force_update_shadow_none = 3, /**< after SHSYNCI assert */
107 } pwm_force_shadow_trigger_t;
108
109 typedef enum {
110 pwm_force_immediately = 0, /**< after software set shlk bit of shlk register */
111 pwm_force_at_reload = 1,
112 pwm_force_at_trigmux = 2,
113 pwm_force_none = 3, /**< after SHSYNCI assert */
114 } pwm_force_trigger_t;
115
116
117 typedef enum {
118 pwm_logic_four_cmp_or = 0,
119 pwm_logic_four_cmp_and = 1,
120 pwm_logic_four_cmp_xor = 2,
121 pwm_logic_four_cmp_cd = 3,
122 } pwm_logic_four_cmp_cfg_t;
123
124 /**
125 * @brief select when to recover PWM output after fault
126 *
127 */
128 typedef enum {
129 pwm_fault_recovery_immediately = 0, /**< immediately*/
130 pwm_fault_recovery_on_reload = 1, /**< after pwm timer counter reload time*/
131 pwm_fault_recovery_on_hw_event = 2, /**< after hardware event assert*/
132 pwm_fault_recovery_on_fault_clear = 3, /**< after software write faultclr bit in GCR register*/
133 } pwm_fault_recovery_trigger_t;
134
135 typedef enum {
136 pwm_dac_channel_0 = 0,
137 pwm_dac_channel_1 = 1,
138 pwm_dac_channel_2 = 2,
139 pwm_dac_channel_3 = 3,
140 } pwm_dac_channel_t;
141
142 typedef enum {
143 pwm_capture_from_trigmux = 0,
144 pwm_capture_from_gpio = 1
145 } pwm_capture_input_select_t;
146
147 typedef enum {
148 pwm_dma_0 = 0,
149 pwm_dma_1 = 1,
150 pwm_dma_2 = 2,
151 pwm_dma_3 = 3,
152 } pwm_dma_chn_t;
153
154 typedef enum {
155 pwm_shadow_register_update_on_shlk = 0, /**< after software set shlk bit of shlk register*/
156 pwm_shadow_register_update_on_modify = 1, /**< immediately after the register being modified*/
157 pwm_shadow_register_update_on_reload = 2,
158 pwm_shadow_register_update_on_trigmux = 3,
159 pwm_shadow_register_update_on_rld_cmp_select0 = 4,
160 pwm_shadow_register_update_on_rld_cmp_select1 = 5,
161 pwm_shadow_register_update_on_none = 6
162 } pwm_cmp_shadow_register_update_trigger_t;
163
164 typedef enum {
165 cmp_value_from_shadow_val = 0,
166 cmp_value_from_calculate = 0x20,
167 cmp_value_from_capture_posedge = 0x30,
168 cmp_value_from_counters = 0x38,
169 cmp_value_fffff000 = 0x3e,
170 cmp_value_ffffff00 = 0x3f
171 } pwm_cmp_source_t;
172
173 /**
174 * @brief pwm compare config
175 *
176 */
177 typedef struct pwmv2_cmp_config {
178 uint32_t cmp; /**< compare value */
179 bool enable_half_cmp; /**< enable half compare value */
180 bool enable_hrcmp; /**< enable high precision pwm */
181 pwm_cmp_source_t cmp_source; /**< @ref pwm_cmp_source_t */
182 pwm_counter_t cmp_use_counter; /**< select one from 4 counters, only for CMP_N>=16 */
183 uint8_t cmp_source_index; /**< soure index */
184 uint8_t mode; /**< compare work mode: pwm_cmp_mode_output_compare or pwm_cmp_mode_input_capture */
185 pwm_cmp_shadow_register_update_trigger_t update_trigger; /**< compare configuration update trigger, need update trigger use pwm_shadow_register_update_on_trigmux */
186 uint8_t update_trigger_index; /**< select one trigger from 8, should set to pulse in trig_mux */
187 uint8_t hrcmp; /**< high precision pwm */
188 } pwmv2_cmp_config_t;
189
190 /**
191 * @brief pwm fault source config
192 *
193 */
194 typedef struct pwmv2_async_fault_source_config {
195 uint8_t async_signal_from_pad_index; /**< select from 16bit async fault from pad*/
196 pwm_fault_pad_polarity_t fault_async_pad_level; /**< fault polarity for input fault from pad, 1-active low; 0-active high */
197 } pwmv2_async_fault_source_config_t;
198
199 /**
200 * @brief pwm config data
201 *
202 */
203 typedef struct pwmv2_config {
204 bool enable_output; /**< enable pwm output */
205 bool enable_async_fault; /**< enable the input async faults from pad directly */
206 bool enable_sync_fault; /**< enable the input faults from trig_mux */
207 bool invert_output; /**< invert pwm output level */
208 bool enable_four_cmp; /**< Enable the four cmp functions */
209 pwmv2_async_fault_source_config_t async_fault_source;
210 pwm_shadow_register_output_polarity_t update_polarity_time;
211 pwm_logic_four_cmp_cfg_t logic; /**< valid only for pwm0/2/4/6 when trig_sel4 is set */
212 uint8_t update_trigger; /**< pwm config update trigger */
213 uint8_t fault_mode; /**< fault mode */
214 pwm_fault_recovery_trigger_t fault_recovery_trigger; /**< fault recoverty trigger */
215 uint8_t fault_recovery_trigmux_index; /**< select one trigger from 8, should set to pulse in trig_mux */
216 uint8_t force_shadow_trigmux_index; /**< select one trigger from 8, should set to pulse in trig_mux */
217 pwm_force_shadow_trigger_t force_shadow_trigger; /**< will load shadow register(force)mode) to force_mode_work at this time */
218 uint8_t force_trigmux_index; /**< select one trigger from 8 as force signal */
219 pwm_force_trigger_t force_trigger; /**< @ref pwm_force_trigger_t */
220 uint32_t dead_zone_in_half_cycle; /**< dead zone in half cycle*/
221 } pwmv2_config_t;
222
223 /**
224 * @brief pair pwm config
225 *
226 */
227 typedef struct pwmv2_pair_config {
228 pwmv2_config_t pwm[2]; /**< pwm config data */
229 } pwmv2_pair_config_t;
230
231 typedef struct pwmv2_cmp_calculate_cfg {
232 uint8_t counter_index; /**< select one of 4 counter reload time */
233 uint8_t in_index; /**< 0~3 to select one of the dac input value; 4~7 to select one of the current counter value */
234 uint8_t in_offset_index; /**< from one of the shadow_val */
235 int8_t t_param; /**< period parameter */
236 int8_t d_param; /**< dac/counter value parameter */
237 int8_t up_limit_param;
238 uint8_t up_limit_offset_index; /**< from one of the shadow_val */
239 int8_t low_limit_param;
240 uint8_t low_limit_offset_index; /**< from one of the shadow_val */
241 bool enable_up_limit;
242 bool enbale_low_limit;
243 } pwmv2_cmp_calculate_cfg_t;
244
245
246 #ifdef __cplusplus
247 extern "C" {
248 #endif
249
250 /**
251 * @brief pwm deinitialize function
252 *
253 * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
254 *
255 */
256 void pwmv2_deinit(PWMV2_Type *pwm_x);
257
258 /**
259 * @brief issue all shawdow register
260 *
261 * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
262 */
pwmv2_issue_shadow_register_lock_event(PWMV2_Type * pwm_x)263 static inline void pwmv2_issue_shadow_register_lock_event(PWMV2_Type *pwm_x)
264 {
265 pwm_x->WORK_CTRL1 |= PWMV2_WORK_CTRL1_SHADOW_LOCK_MASK;
266 }
267
268 /**
269 * @brief lock all shawdow register
270 *
271 * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
272 */
pwmv2_shadow_register_lock(PWMV2_Type * pwm_x)273 static inline void pwmv2_shadow_register_lock(PWMV2_Type *pwm_x)
274 {
275 pwm_x->WORK_CTRL1 |= PWMV2_WORK_CTRL1_SHADOW_LOCK_MASK;
276 }
277
278 /**
279 * @brief select one trigger from 8, set to use input signal(selected by cnt_reload_trig) to reload timer
280 *
281 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
282 * @param counter @ref pwm_counter_t
283 * @param trig_index one trigger from 8
284 */
pwmv2_set_counter_reload_trigmux_index(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t trig_index)285 static inline void pwmv2_set_counter_reload_trigmux_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
286 {
287 pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_RELOAD_TRIG_MASK) | PWMV2_CNT_CFG2_CNT_RELOAD_TRIG_SET(trig_index);
288 }
289
290 /**
291 * @brief Multiple counters are enabled at the same time
292 *
293 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
294 * @param mask bit0 - cnt0, bit1 - cnt1, bitn - cntn, n==3
295 */
pwmv2_enable_multi_counter_sync(PWMV2_Type * pwm_x,uint8_t mask)296 static inline void pwmv2_enable_multi_counter_sync(PWMV2_Type *pwm_x, uint8_t mask)
297 {
298 pwm_x->CNT_GLBCFG &= ~(PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET(mask));
299 fencerw();
300 pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET(mask);
301 }
302
303 /**
304 * @brief Multiple pwm out at the same time
305 *
306 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
307 * @param mask bit0 - cnt0, bit1 - cnt1, bitn - cntn, n==3
308 */
pwmv2_start_pwm_output_sync(PWMV2_Type * pwm_x,uint8_t mask)309 static inline void pwmv2_start_pwm_output_sync(PWMV2_Type *pwm_x, uint8_t mask)
310 {
311 pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_CNT_SW_START_SET(mask);
312 }
313
314 /**
315 * @brief unlock all shadow register
316 *
317 * @param[in] pwm_x PWM base address, HPM_PWMx(x=0..n)
318 */
pwmv2_shadow_register_unlock(PWMV2_Type * pwm_x)319 static inline void pwmv2_shadow_register_unlock(PWMV2_Type *pwm_x)
320 {
321 pwm_x->WORK_CTRL0 = PWM_UNLOCK_KEY;
322 }
323
324 /**
325 * @brief The shadow registers can be updated only when related unlock_bit is set.
326 *
327 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
328 * @param mask bit2 to bit 29 for value_shadow, bit30 for force_mode, bit31 for polarity.
329 */
pwmv2_shadow_unlock_bit_mask(PWMV2_Type * pwm_x,uint32_t mask)330 static inline void pwmv2_shadow_unlock_bit_mask(PWMV2_Type *pwm_x, uint32_t mask)
331 {
332 pwm_x->UNLOCK = mask;
333 }
334
335 /**
336 * @brief Set the value of the shadow register
337 *
338 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
339 * @param index shadow index
340 * @param value normal value (24bit)
341 * @param high_resolution_tick High precision pwm values (0 -255)
342 * @param enable_half_cycle half-cycle pwm
343 */
pwmv2_set_shadow_val(PWMV2_Type * pwm_x,uint8_t index,uint32_t value,uint8_t high_resolution_tick,bool enable_half_cycle)344 static inline void pwmv2_set_shadow_val(PWMV2_Type *pwm_x, uint8_t index, uint32_t value, uint8_t high_resolution_tick, bool enable_half_cycle)
345 {
346 pwm_x->SHADOW_VAL[index] = PWMV2_SHADOW_VAL_VALUE_SET(((value << 8) | (enable_half_cycle << 7) | (high_resolution_tick)));
347 }
348
349 /**
350 * @brief force pwm output
351 *
352 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
353 * @param chn @ref pwm_channel_t
354 * @param mode @ref pwm_force_mode_t
355 * @param invert 0 - low level, 1 - high level
356 */
pwmv2_force_output(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_force_mode_t mode,bool invert)357 static inline void pwmv2_force_output(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_force_mode_t mode, bool invert)
358 {
359 pwm_x->FORCE_MODE = (pwm_x->FORCE_MODE & ~(PWMV2_FORCE_MODE_POLARITY_SET((1 << (chn << 1))) | PWMV2_FORCE_MODE_FORCE_MODE_SET((3 << (chn << 1))))) |
360 PWMV2_FORCE_MODE_POLARITY_SET((invert << (chn << 1))) |
361 PWMV2_FORCE_MODE_FORCE_MODE_SET((mode << (chn << 1)));
362 }
363
364 /**
365 * @brief enable four pwm outputs
366 *
367 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
368 * @param chn @ref pwm_channel_t
369 */
pwmv2_enable_four_cmp(PWMV2_Type * pwm_x,pwm_channel_t chn)370 static inline void pwmv2_enable_four_cmp(PWMV2_Type *pwm_x, pwm_channel_t chn)
371 {
372 pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_TRIG_SEL4_MASK;
373 }
374
375 /**
376 * @brief disable four pwm outputs
377 *
378 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
379 * @param chn @ref pwm_channel_t
380 */
pwmv2_disable_four_cmp(PWMV2_Type * pwm_x,pwm_channel_t chn)381 static inline void pwmv2_disable_four_cmp(PWMV2_Type *pwm_x, pwm_channel_t chn)
382 {
383 pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_TRIG_SEL4_MASK;
384 }
385
386 /**
387 * @brief Direct selection of the fail signal from the pin
388 *
389 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
390 * @param chn @ref pwm_channel_t
391 * @param pad_index motor pad
392 */
pwmv2_fault_signal_select_from_pad(PWMV2_Type * pwm_x,pwm_channel_t chn,uint8_t pad_index)393 static inline void pwmv2_fault_signal_select_from_pad(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t pad_index)
394 {
395 pwm_x->PWM[chn].CFG0 = (pwm_x->PWM[chn].CFG0 & ~PWMV2_PWM_CFG0_FAULT_SEL_ASYNC_MASK) | PWMV2_PWM_CFG0_FAULT_SEL_ASYNC_SET(pad_index);
396 }
397
398 /**
399 * @brief Configure the polarity of the fail signal
400 *
401 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
402 * @param chn @ref pwm_channel_t
403 * @param polarity @ref pwm_fault_pad_polarity_t
404 */
pwmv2_fault_signal_polarity(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_fault_pad_polarity_t polarity)405 static inline void pwmv2_fault_signal_polarity(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_fault_pad_polarity_t polarity)
406 {
407 pwm_x->PWM[chn].CFG0 = (pwm_x->PWM[chn].CFG0 & ~PWMV2_PWM_CFG0_FAULT_POL_ASYNC_MASK) | PWMV2_PWM_CFG0_FAULT_POL_ASYNC_SET(polarity);
408 }
409
410 /**
411 * @brief Enable the fault signal from the pin
412 *
413 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
414 * @param chn @ref pwm_channel_t
415 */
pwmv2_enable_fault_from_pad(PWMV2_Type * pwm_x,pwm_channel_t chn)416 static inline void pwmv2_enable_fault_from_pad(PWMV2_Type *pwm_x, pwm_channel_t chn)
417 {
418 pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_FAULT_EN_ASYNC_MASK;
419 }
420
421 /**
422 * @brief Disable the fault signal from the pin
423 *
424 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
425 * @param chn @ref pwm_channel_t
426 */
pwmv2_disable_fault_from_pad(PWMV2_Type * pwm_x,pwm_channel_t chn)427 static inline void pwmv2_disable_fault_from_pad(PWMV2_Type *pwm_x, pwm_channel_t chn)
428 {
429 pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_FAULT_EN_ASYNC_MASK;
430 }
431
432 /**
433 * @brief Enable the fault signal from the trigmux
434 *
435 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
436 * @param chn @ref pwm_channel_t
437 */
pwmv2_enable_fault_from_trigmux(PWMV2_Type * pwm_x,pwm_channel_t chn)438 static inline void pwmv2_enable_fault_from_trigmux(PWMV2_Type *pwm_x, pwm_channel_t chn)
439 {
440 pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_FAULT_EN_SYNC_MASK;
441 }
442
443 /**
444 * @brief Disable the fault signal from the trigmux
445 *
446 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
447 * @param chn @ref pwm_channel_t
448 */
pwmv2_disable_fault_from_trigmux(PWMV2_Type * pwm_x,pwm_channel_t chn)449 static inline void pwmv2_disable_fault_from_trigmux(PWMV2_Type *pwm_x, pwm_channel_t chn)
450 {
451 pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_FAULT_EN_SYNC_MASK;
452 }
453
454 /**
455 * @brief Enable pwm output invert
456 *
457 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
458 * @param chn @ref pwm_channel_t
459 */
pwmv2_enable_output_invert(PWMV2_Type * pwm_x,pwm_channel_t chn)460 static inline void pwmv2_enable_output_invert(PWMV2_Type *pwm_x, pwm_channel_t chn)
461 {
462 pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_OUT_POLARITY_MASK;
463 }
464
465 /**
466 * @brief Disable pwm output invert
467 *
468 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
469 * @param chn @ref pwm_channel_t
470 */
pwmv2_disable_output_invert(PWMV2_Type * pwm_x,pwm_channel_t chn)471 static inline void pwmv2_disable_output_invert(PWMV2_Type *pwm_x, pwm_channel_t chn)
472 {
473 pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_OUT_POLARITY_MASK;
474 }
475
476 /**
477 * @brief Enable invert operations via shadow registers
478 *
479 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
480 * @param chn @ref pwm_channel_t
481 * @param update_select @ref pwm_shadow_register_output_polarity_t
482 */
pwmv2_enable_invert_by_shadow(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_shadow_register_output_polarity_t update_select)483 static inline void pwmv2_enable_invert_by_shadow(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_shadow_register_output_polarity_t update_select)
484 {
485 pwm_x->PWM[chn].CFG0 |= PWMV2_PWM_CFG0_POLARITY_OPT0_MASK;
486 pwm_x->PWM[chn].CFG0 = (pwm_x->PWM[chn].CFG0 & ~PWMV2_PWM_CFG0_POL_UPDATE_SEL_MASK) | PWMV2_PWM_CFG0_POL_UPDATE_SEL_SET(update_select);
487 }
488
489 /**
490 * @brief Disable invert operations via shadow registers
491 *
492 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
493 * @param chn @ref pwm_channel_t
494 * @param update_select @ref pwm_shadow_register_output_polarity_t
495 */
pwmv2_disable_invert_by_shadow(PWMV2_Type * pwm_x,pwm_channel_t chn)496 static inline void pwmv2_disable_invert_by_shadow(PWMV2_Type *pwm_x, pwm_channel_t chn)
497 {
498 pwm_x->PWM[chn].CFG0 &= ~PWMV2_PWM_CFG0_POLARITY_OPT0_MASK;
499 }
500
501 /**
502 * @brief Enable pwm output
503 *
504 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
505 * @param chn @ref pwm_channel_t
506 */
pwmv2_channel_enable_output(PWMV2_Type * pwm_x,pwm_channel_t chn)507 static inline void pwmv2_channel_enable_output(PWMV2_Type *pwm_x, pwm_channel_t chn)
508 {
509 pwm_x->PWM[chn].CFG1 |= PWMV2_PWM_CFG1_HIGHZ_EN_N_MASK;
510 }
511
512 /**
513 * @brief Disable pwm output
514 *
515 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
516 * @param chn @ref pwm_channel_t
517 */
pwmv2_channel_disable_output(PWMV2_Type * pwm_x,pwm_channel_t chn)518 static inline void pwmv2_channel_disable_output(PWMV2_Type *pwm_x, pwm_channel_t chn)
519 {
520 pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_HIGHZ_EN_N_MASK;
521 }
522
523 /**
524 * @brief Forces the output configuration to be updated from the time shadow hosting takes effect
525 *
526 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
527 * @param chn @ref pwm_channel_t
528 * @param update_time @ref pwm_force_shadow_trigger_t
529 */
pwmv2_force_update_time_by_shadow(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_force_shadow_trigger_t update_time)530 static inline void pwmv2_force_update_time_by_shadow(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_force_shadow_trigger_t update_time)
531 {
532 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_UPDATE_TIME_MASK) | PWMV2_PWM_CFG1_FORCE_UPDATE_TIME_SET(update_time);
533 }
534
535 /**
536 * @brief set the fault mode
537 *
538 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
539 * @param chn @ref pwm_channel_t
540 * @param mode @ref pwm_fault_mode_t
541 */
pwmv2_set_fault_mode(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_fault_mode_t mode)542 static inline void pwmv2_set_fault_mode(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_fault_mode_t mode)
543 {
544 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FAULT_MODE_MASK) | PWMV2_PWM_CFG1_FAULT_MODE_SET(mode);
545 }
546
547 /**
548 * @brief Set the fault mode recovery time
549 *
550 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
551 * @param chn @ref pwm_channel_t
552 * @param trig @ref pwm_fault_recovery_trigger_t
553 */
pwmv2_set_fault_recovery_time(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_fault_recovery_trigger_t trig)554 static inline void pwmv2_set_fault_recovery_time(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_fault_recovery_trigger_t trig)
555 {
556 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FAULT_REC_TIME_MASK) | PWMV2_PWM_CFG1_FAULT_REC_TIME_SET(trig);
557 }
558
559 /**
560 * @brief Trigger forced mode by hardware signal
561 *
562 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
563 * @param chn @ref pwm_channel_t
564 */
pwmv2_enable_force_by_hardware(PWMV2_Type * pwm_x,pwm_channel_t chn)565 static inline void pwmv2_enable_force_by_hardware(PWMV2_Type *pwm_x, pwm_channel_t chn)
566 {
567 pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_SW_FORCE_EN_MASK;
568 }
569
570 /**
571 * @brief Enable force mode triggered by software
572 *
573 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
574 * @param chn @ref pwm_channel_t
575 */
pwmv2_enable_force_by_software(PWMV2_Type * pwm_x,pwm_channel_t chn)576 static inline void pwmv2_enable_force_by_software(PWMV2_Type *pwm_x, pwm_channel_t chn)
577 {
578 pwm_x->PWM[chn].CFG1 |= PWMV2_PWM_CFG1_SW_FORCE_EN_MASK;
579 }
580
581 /**
582 * @brief Disable force mode triggered by software
583 *
584 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
585 * @param chn @ref pwm_channel_t
586 */
pwmv2_disable_force_by_software(PWMV2_Type * pwm_x,pwm_channel_t chn)587 static inline void pwmv2_disable_force_by_software(PWMV2_Type *pwm_x, pwm_channel_t chn)
588 {
589 pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_SW_FORCE_EN_MASK;
590 }
591
592 /**
593 * @brief Enable pwm complementary mode
594 *
595 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
596 * @param chn @ref pwm_channel_t
597 */
pwmv2_enable_pair_mode(PWMV2_Type * pwm_x,pwm_channel_t chn)598 static inline void pwmv2_enable_pair_mode(PWMV2_Type *pwm_x, pwm_channel_t chn)
599 {
600 pwm_x->PWM[chn].CFG1 |= PWMV2_PWM_CFG1_PAIR_MODE_MASK;
601 }
602
603 /**
604 * @brief Disable pwm complementary mode
605 *
606 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
607 * @param chn @ref pwm_channel_t
608 */
pwmv2_disable_pair_mode(PWMV2_Type * pwm_x,pwm_channel_t chn)609 static inline void pwmv2_disable_pair_mode(PWMV2_Type *pwm_x, pwm_channel_t chn)
610 {
611 pwm_x->PWM[chn].CFG1 &= ~PWMV2_PWM_CFG1_PAIR_MODE_MASK;
612 }
613
614 /**
615 * @brief Configure the logic between the 4 cmp, valid only if the 4 cmp output is enabled
616 *
617 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
618 * @param chn @ref pwm_channel_t
619 * @param logic @ref pwm_logic_four_cmp_cfg_t
620 */
pwmv2_set_four_cmp_logic(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_logic_four_cmp_cfg_t logic)621 static inline void pwmv2_set_four_cmp_logic(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_logic_four_cmp_cfg_t logic)
622 {
623 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_PWM_LOGIC_MASK) | PWMV2_PWM_CFG1_PWM_LOGIC_SET(logic);
624 }
625
626 /**
627 * @brief Setting the effective time of forced output
628 *
629 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
630 * @param chn @ref pwm_channel_t
631 * @param time @ref pwm_force_trigger_t
632 */
pwmv2_set_force_update_time(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_force_trigger_t time)633 static inline void pwmv2_set_force_update_time(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_force_trigger_t time)
634 {
635 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_TIME_MASK) | PWMV2_PWM_CFG1_FORCE_TIME_SET(time);
636 }
637
638 /**
639 * @brief Selecting trigmux's signal as a forced mode trigger source
640 *
641 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
642 * @param chn @ref pwm_channel_t
643 * @param trigmux_index trigmux index
644 */
pwmv2_trig_force_mode_select_trigmux_index(PWMV2_Type * pwm_x,pwm_channel_t chn,uint8_t trigmux_index)645 static inline void pwmv2_trig_force_mode_select_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
646 {
647 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_TRIG_SEL_MASK) | PWMV2_PWM_CFG1_FORCE_TRIG_SEL_SET(trigmux_index);
648 }
649
650 /**
651 * @brief Selection of trigger signals for software or hardware trigmux
652 *
653 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
654 * @param chn @ref pwm_channel_t
655 * @param trigmux_index select one trigger from 8
656 */
pwmv2_trig_force_hardware_or_software_select_trigmux_index(PWMV2_Type * pwm_x,pwm_channel_t chn,uint8_t trigmux_index)657 static inline void pwmv2_trig_force_hardware_or_software_select_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
658 {
659 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FORCE_ACT_SEL_MASK) | PWMV2_PWM_CFG1_FORCE_ACT_SEL_SET(trigmux_index);
660 }
661
662 /**
663 * @brief Select the trigger source that forces the output to take effect
664 *
665 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
666 * @param chn @ref pwm_channel_t
667 * @param trigmux_index select one trigger from 8
668 */
pwmv2_select_force_trigmux_index(PWMV2_Type * pwm_x,pwm_channel_t chn,uint8_t trigmux_index)669 static inline void pwmv2_select_force_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
670 {
671 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_PWM_FORCE_SEL_MASK) | PWMV2_PWM_CFG1_PWM_FORCE_SEL_SET(trigmux_index);
672 }
673
674 /**
675 * @brief Selection of trigger signal for fault recovery
676 *
677 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
678 * @param chn @ref pwm_channel_t
679 * @param trigmux_index select one trigger from 8
680 */
pwmv2_select_recovery_fault_trigmux_index(PWMV2_Type * pwm_x,pwm_channel_t chn,uint8_t trigmux_index)681 static inline void pwmv2_select_recovery_fault_trigmux_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t trigmux_index)
682 {
683 pwm_x->PWM[chn].CFG1 = (pwm_x->PWM[chn].CFG1 & ~PWMV2_PWM_CFG1_FAULT_REC_SEL_MASK) | PWMV2_PWM_CFG1_FAULT_REC_SEL_SET(trigmux_index);
684 }
685
686 /**
687 * @brief set pwm dead area
688 *
689 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
690 * @param chn @ref pwm_channel_t
691 * @param dead dead area time
692 */
pwmv2_set_dead_area(PWMV2_Type * pwm_x,pwm_channel_t chn,uint32_t dead)693 static inline void pwmv2_set_dead_area(PWMV2_Type *pwm_x, pwm_channel_t chn, uint32_t dead)
694 {
695 pwm_x->PWM[chn].DEAD_AREA = PWMV2_PWM_DEAD_AREA_DEAD_AREA_SET((dead << 8));
696 }
697
698 /**
699 * @brief Setting the comparator as an input to trigmux
700 *
701 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
702 * @param trigmux_chn @ref pwm_channel_t
703 * @param cmp_index cmp index
704 */
pwmv2_set_trigout_cmp_index(PWMV2_Type * pwm_x,pwm_channel_t trigmux_chn,uint8_t cmp_index)705 static inline void pwmv2_set_trigout_cmp_index(PWMV2_Type *pwm_x, pwm_channel_t trigmux_chn, uint8_t cmp_index)
706 {
707 pwm_x->TRIGGER_CFG[trigmux_chn] = (pwm_x->TRIGGER_CFG[trigmux_chn] & ~PWMV2_TRIGGER_CFG_TRIGGER_OUT_SEL_MASK) | PWMV2_TRIGGER_CFG_TRIGGER_OUT_SEL_SET(cmp_index);
708 }
709
710 /**
711 * @brief Enable software forced output
712 *
713 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
714 * @param chn @ref pwm_channel_t
715 */
pwmv2_enable_software_force(PWMV2_Type * pwm_x,pwm_channel_t chn)716 static inline void pwmv2_enable_software_force(PWMV2_Type *pwm_x, pwm_channel_t chn)
717 {
718 pwm_x->GLB_CTRL |= PWMV2_GLB_CTRL_SW_FORCE_SET((1 << chn));
719 }
720
721 /**
722 * @brief Disable software forced output
723 *
724 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
725 * @param chn @ref pwm_channel_t
726 */
pwmv2_disable_software_force(PWMV2_Type * pwm_x,pwm_channel_t chn)727 static inline void pwmv2_disable_software_force(PWMV2_Type *pwm_x, pwm_channel_t chn)
728 {
729 pwm_x->GLB_CTRL &= ~(PWMV2_GLB_CTRL_SW_FORCE_SET((1 << chn)));
730 }
731
732 #ifdef PWM_SOC_HRPWM_SUPPORT
733
734 /**
735 * @brief Add a delay after deadband, 0-255ths of a clock cycle
736 *
737 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
738 * @param delay_tick 0-255
739 */
pwmv2_add_delay_tick_after_dead_area(PWMV2_Type * pwm_x,uint8_t delay_tick)740 static inline void pwmv2_add_delay_tick_after_dead_area(PWMV2_Type *pwm_x, uint8_t delay_tick)
741 {
742 pwm_x->GLB_CTRL = (pwm_x->GLB_CTRL & ~PWMV2_GLB_CTRL_OUTPUT_DELAY_MASK) | PWMV2_GLB_CTRL_OUTPUT_DELAY_SET(delay_tick);
743 }
744
745 /**
746 * @brief Enable high precision pwm
747 *
748 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
749 */
pwmv2_enable_hrpwm(PWMV2_Type * pwm_x)750 static inline void pwmv2_enable_hrpwm(PWMV2_Type *pwm_x)
751 {
752 pwm_x->GLB_CTRL |= PWMV2_GLB_CTRL_HR_PWM_EN_MASK;
753 }
754
755 /**
756 * @brief Disable high precision pwm
757 *
758 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
759 */
pwmv2_disable_hrpwm(PWMV2_Type * pwm_x)760 static inline void pwmv2_disable_hrpwm(PWMV2_Type *pwm_x)
761 {
762 pwm_x->GLB_CTRL &= ~PWMV2_GLB_CTRL_HR_PWM_EN_MASK;
763 }
764
765 #endif
766
767 /**
768 * @brief Enable the software dac mode
769 *
770 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
771 * @param dac_index @ref pwm_dac_channel_t
772 */
pwmv2_enable_software_dac_mode(PWMV2_Type * pwm_x,pwm_dac_channel_t dac_index)773 static inline void pwmv2_enable_software_dac_mode(PWMV2_Type *pwm_x, pwm_dac_channel_t dac_index)
774 {
775 pwm_x->GLB_CTRL2 |= PWMV2_GLB_CTRL2_DAC_SW_MODE_SET((1 << dac_index));
776 }
777
778 /**
779 * @brief Disable the software dac mode
780 *
781 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
782 * @param dac_index @ref pwm_dac_channel_t
783 */
pwmv2_disable_software_dac_mode(PWMV2_Type * pwm_x,pwm_dac_channel_t dac_index)784 static inline void pwmv2_disable_software_dac_mode(PWMV2_Type *pwm_x, pwm_dac_channel_t dac_index)
785 {
786 pwm_x->GLB_CTRL2 &= ~PWMV2_GLB_CTRL2_DAC_SW_MODE_SET((1 << dac_index));
787 }
788
789 /**
790 * @brief Enable debug mode
791 *
792 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
793 */
pwmv2_enable_debug_mode(PWMV2_Type * pwm_x)794 static inline void pwmv2_enable_debug_mode(PWMV2_Type *pwm_x)
795 {
796 pwm_x->GLB_CTRL2 |= PWMV2_GLB_CTRL2_DEBUG_IN_EN_MASK;
797 }
798
799
800 /**
801 * @brief Disable debug mode
802 *
803 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
804 */
pwmv2_disable_debug_mode(PWMV2_Type * pwm_x)805 static inline void pwmv2_disable_debug_mode(PWMV2_Type *pwm_x)
806 {
807 pwm_x->GLB_CTRL2 &= ~PWMV2_GLB_CTRL2_DEBUG_IN_EN_MASK;
808 }
809
810 /**
811 * @brief Clear fault event
812 *
813 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
814 * @param chn @ref pwm_channel_t
815 */
pwmv2_clear_fault_event(PWMV2_Type * pwm_x,pwm_channel_t chn)816 static inline void pwmv2_clear_fault_event(PWMV2_Type *pwm_x, pwm_channel_t chn)
817 {
818 pwm_x->GLB_CTRL2 = (pwm_x->GLB_CTRL2 & ~(PWMV2_GLB_CTRL2_FAULT_CLEAR_MASK)) | PWMV2_GLB_CTRL2_FAULT_CLEAR_SET((1 << chn));
819 }
820
821 /**
822 * @brief Using the Shadow Register Function
823 *
824 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
825 */
pwmv2_enable_shadow_lock_feature(PWMV2_Type * pwm_x)826 static inline void pwmv2_enable_shadow_lock_feature(PWMV2_Type *pwm_x)
827 {
828 pwm_x->GLB_CTRL2 |= PWMV2_GLB_CTRL2_SHADOW_LOCK_EN_MASK;
829 }
830
831 /**
832 * @brief Do not use the shadow register function
833 *
834 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
835 */
pwmv2_disable_shadow_lock_feature(PWMV2_Type * pwm_x)836 static inline void pwmv2_disable_shadow_lock_feature(PWMV2_Type *pwm_x)
837 {
838 pwm_x->GLB_CTRL2 &= ~PWMV2_GLB_CTRL2_SHADOW_LOCK_EN_MASK;
839 }
840
841 /**
842 * @brief Get counter work status
843 *
844 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
845 * @param counter_index @ref pwm_counter_t
846 * @return uint32_t status mask
847 */
pwmv2_get_counter_working_status(PWMV2_Type * pwm_x,pwm_counter_t counter_index)848 static inline uint32_t pwmv2_get_counter_working_status(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
849 {
850 return PWMV2_CNT_RELOAD_WORK_VALUE_GET(pwm_x->CNT_RELOAD_WORK[counter_index]);
851 }
852
853 /**
854 * @brief Get cmp work status
855 *
856 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
857 * @param cmp_index cmp index
858 * @return uint32_t status mask
859 */
pwmv2_get_cmp_working_status(PWMV2_Type * pwm_x,uint8_t cmp_index)860 static inline uint32_t pwmv2_get_cmp_working_status(PWMV2_Type *pwm_x, uint8_t cmp_index)
861 {
862 return PWMV2_CMP_VAL_WORK_VALUE_GET(pwm_x->CMP_VAL_WORK[cmp_index]);
863 }
864
865 /**
866 * @brief Get force mode work status
867 *
868 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
869 * @return uint32_t status mask
870 */
pwmv2_get_force_working_status(PWMV2_Type * pwm_x)871 static inline uint32_t pwmv2_get_force_working_status(PWMV2_Type *pwm_x)
872 {
873 return PWMV2_FORCE_WORK_FORCE_MODE_GET(pwm_x->FORCE_WORK);
874 }
875
876 /**
877 * @brief Get the status of the output polarity
878 *
879 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
880 * @return uint32_t polarity
881 */
pwmv2_get_force_work_out_polarity_status(PWMV2_Type * pwm_x)882 static inline uint32_t pwmv2_get_force_work_out_polarity_status(PWMV2_Type *pwm_x)
883 {
884 return PWMV2_FORCE_WORK_OUT_POLARITY_GET(pwm_x->FORCE_WORK);
885 }
886
887 /**
888 * @brief Getting the value of a counter
889 *
890 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
891 * @param counter_index @ref pwm_counter_t
892 * @return uint32_t counter value
893 */
pwmv2_get_counter_value(PWMV2_Type * pwm_x,pwm_counter_t counter_index)894 static inline uint32_t pwmv2_get_counter_value(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
895 {
896 return PWMV2_CNT_VAL_VALUE_GET(pwm_x->CNT_VAL[counter_index]);
897 }
898
899 /**
900 * @brief set dac value
901 *
902 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
903 * @param dac_index @ref pwm_dac_channel_t
904 * @param value dac value
905 */
pwmv2_set_dac_value(PWMV2_Type * pwm_x,pwm_dac_channel_t dac_index,uint32_t value)906 static inline void pwmv2_set_dac_value(PWMV2_Type *pwm_x, pwm_dac_channel_t dac_index, uint32_t value)
907 {
908 pwm_x->DAC_VALUE_SV[dac_index] = PWMV2_DAC_VALUE_SV_VALUE_SET(value);
909 }
910
911 /**
912 * @brief get capture posedge value
913 *
914 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
915 * @param chn @ref pwm_channel_t
916 * @return uint32_t posedge value
917 */
pwmv2_get_capture_posedge_value(PWMV2_Type * pwm_x,pwm_channel_t chn)918 static inline uint32_t pwmv2_get_capture_posedge_value(PWMV2_Type *pwm_x, pwm_channel_t chn)
919 {
920 return PWMV2_CAPTURE_POS_CAPTURE_POS_GET(pwm_x->CAPTURE_POS[chn]);
921 }
922
923 /**
924 * @brief Select the input source for the captured signal
925 *
926 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
927 * @param chn @ref pwm_channel_t
928 * @param select @ref pwm_capture_input_select_t
929 */
pwmv2_capture_selection_input_source(PWMV2_Type * pwm_x,pwm_channel_t chn,pwm_capture_input_select_t select)930 static inline void pwmv2_capture_selection_input_source(PWMV2_Type *pwm_x, pwm_channel_t chn, pwm_capture_input_select_t select)
931 {
932 pwm_x->CAPTURE_POS[chn] = (pwm_x->CAPTURE_POS[chn] & ~PWMV2_CAPTURE_POS_CAPTURE_SELGPIO_MASK) |
933 PWMV2_CAPTURE_POS_CAPTURE_SELGPIO_SET(select);
934 }
935
936 /**
937 * @brief Set the counter to be used for the capture channel
938 *
939 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
940 * @param chn @ref pwm_channel_t
941 * @param counter_index counter index
942 */
pwmv2_set_capture_counter_index(PWMV2_Type * pwm_x,pwm_channel_t chn,uint8_t counter_index)943 static inline void pwmv2_set_capture_counter_index(PWMV2_Type *pwm_x, pwm_channel_t chn, uint8_t counter_index)
944 {
945 pwm_x->CAPTURE_POS[chn] = (pwm_x->CAPTURE_POS[chn] & ~PWMV2_CAPTURE_POS_CNT_INDEX_MASK) |
946 PWMV2_CAPTURE_POS_CNT_INDEX_SET(counter_index);
947 }
948
949 /**
950 * @brief get capture negedge value
951 *
952 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
953 * @param chn @ref pwm_channel_t
954 * @return uint32_t posedge value
955 */
pwmv2_get_capture_negedge_value(PWMV2_Type * pwm_x,pwm_channel_t chn)956 static inline uint32_t pwmv2_get_capture_negedge_value(PWMV2_Type *pwm_x, pwm_channel_t chn)
957 {
958 return PWMV2_CAPTURE_NEG_CAPTURE_NEG_GET(pwm_x->CAPTURE_NEG[chn]);
959 }
960
961 /**
962 * @brief Get all interrupt status
963 *
964 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
965 * @return uint32_t irq status mask
966 */
pwmv2_get_irq_status_all(PWMV2_Type * pwm_x)967 static inline uint32_t pwmv2_get_irq_status_all(PWMV2_Type *pwm_x)
968 {
969 return pwm_x->IRQ_STS;
970 }
971
972 /**
973 * @brief clear calculate overflow irq status
974 *
975 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
976 */
pwmv2_clear_calculate_overflow_irq_status(PWMV2_Type * pwm_x)977 static inline void pwmv2_clear_calculate_overflow_irq_status(PWMV2_Type *pwm_x)
978 {
979 pwm_x->IRQ_STS &= PWMV2_IRQ_STS_IRQ_CAL_OVERFLOW_MASK;
980 }
981
982 /**
983 * @brief enable calculate overflow irq
984 *
985 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
986 */
pwmv2_enable_calculate_overflow_irq(PWMV2_Type * pwm_x)987 static inline void pwmv2_enable_calculate_overflow_irq(PWMV2_Type *pwm_x)
988 {
989 pwm_x->IRQ_EN |= PWMV2_IRQ_EN_IRQ_EN_OVERFLOW_MASK;
990 }
991
992 /**
993 * @brief Disable calculate overflow irq
994 *
995 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
996 */
pwmv2_disable_calculate_overflow_irq(PWMV2_Type * pwm_x)997 static inline void pwmv2_disable_calculate_overflow_irq(PWMV2_Type *pwm_x)
998 {
999 pwm_x->IRQ_EN &= ~PWMV2_IRQ_EN_IRQ_EN_OVERFLOW_MASK;
1000 }
1001
1002 /**
1003 * @brief Get cmp irq status
1004 *
1005 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1006 * @return uint32_t irq status
1007 */
pwmv2_get_cmp_irq_status(PWMV2_Type * pwm_x)1008 static inline uint32_t pwmv2_get_cmp_irq_status(PWMV2_Type *pwm_x)
1009 {
1010 return PWMV2_IRQ_STS_CMP_IRQ_STS_CMP_GET(pwm_x->IRQ_STS_CMP);
1011 }
1012
1013 /**
1014 * @brief Clear cmp irq status
1015 *
1016 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1017 * @param mask uint32_t irq status
1018 */
pwmv2_clear_cmp_irq_status(PWMV2_Type * pwm_x,uint32_t mask)1019 static inline void pwmv2_clear_cmp_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
1020 {
1021 pwm_x->IRQ_STS_CMP = PWMV2_IRQ_STS_CMP_IRQ_STS_CMP_SET(mask);
1022 }
1023
1024 /**
1025 * @brief Get reload irq status
1026 *
1027 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1028 * @return uint32_t reload irq status
1029 */
pwmv2_get_reload_irq_status(PWMV2_Type * pwm_x)1030 static inline uint32_t pwmv2_get_reload_irq_status(PWMV2_Type *pwm_x)
1031 {
1032 return PWMV2_IRQ_STS_RELOAD_IRQ_STS_RELOAD_GET(pwm_x->IRQ_STS_RELOAD);
1033 }
1034
1035 /**
1036 * @brief Clear reload irq status
1037 *
1038 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1039 * @param mask irq status mask
1040 */
pwmv2_clear_reload_irq_status(PWMV2_Type * pwm_x,uint32_t mask)1041 static inline void pwmv2_clear_reload_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
1042 {
1043 pwm_x->IRQ_STS_RELOAD = PWMV2_IRQ_STS_RELOAD_IRQ_STS_RELOAD_SET(mask);
1044 }
1045
1046 /**
1047 * @brief Get capture posedge irq status
1048 *
1049 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1050 * @return uint32_t irq status
1051 */
pwmv2_get_capture_posedge_irq_status(PWMV2_Type * pwm_x)1052 static inline uint32_t pwmv2_get_capture_posedge_irq_status(PWMV2_Type *pwm_x)
1053 {
1054 return PWMV2_IRQ_STS_CAP_POS_IRQ_STS_CAP_POS_GET(pwm_x->IRQ_STS_CAP_POS);
1055 }
1056
1057 /**
1058 * @brief Clear capture posedge irq status
1059 *
1060 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1061 * @param mask capture posedge irq mask
1062 */
pwmv2_clear_capture_posedge_irq_status(PWMV2_Type * pwm_x,uint32_t mask)1063 static inline void pwmv2_clear_capture_posedge_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
1064 {
1065 pwm_x->IRQ_STS_CAP_POS = PWMV2_IRQ_STS_CAP_POS_IRQ_STS_CAP_POS_SET(mask);
1066 }
1067
1068 /**
1069 * @brief Get capture negedge irq status
1070 *
1071 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1072 * @return uint32_t irq status
1073 */
pwmv2_get_capture_negedge_irq_status(PWMV2_Type * pwm_x)1074 static inline uint32_t pwmv2_get_capture_negedge_irq_status(PWMV2_Type *pwm_x)
1075 {
1076 return PWMV2_IRQ_STS_CAP_NEG_IRQ_STS_CAP_NEG_GET(pwm_x->IRQ_STS_CAP_NEG);
1077 }
1078
1079 /**
1080 * @brief Clear capture negedge irq status
1081 *
1082 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1083 * @param mask capture posedge irq mask
1084 */
pwmv2_clear_capture_negedge_irq_status(PWMV2_Type * pwm_x,uint32_t mask)1085 static inline void pwmv2_clear_capture_negedge_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
1086 {
1087 pwm_x->IRQ_STS_CAP_NEG = PWMV2_IRQ_STS_CAP_NEG_IRQ_STS_CAP_NEG_SET(mask);
1088 }
1089
1090 /**
1091 * @brief Get fault irq status
1092 *
1093 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1094 * @return uint32_t irq status
1095 */
pwmv2_get_fault_irq_status(PWMV2_Type * pwm_x)1096 static inline uint32_t pwmv2_get_fault_irq_status(PWMV2_Type *pwm_x)
1097 {
1098 return PWMV2_IRQ_STS_FAULT_IRQ_STS_FAULT_GET(pwm_x->IRQ_STS_FAULT);
1099 }
1100
1101 /**
1102 * @brief Clear fault irq status
1103 *
1104 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1105 * @return uint32_t irq status
1106 */
pwmv2_clear_fault_irq_status(PWMV2_Type * pwm_x,uint32_t mask)1107 static inline void pwmv2_clear_fault_irq_status(PWMV2_Type *pwm_x, uint32_t mask)
1108 {
1109 pwm_x->IRQ_STS_FAULT = PWMV2_IRQ_STS_FAULT_IRQ_STS_FAULT_SET(mask);
1110 }
1111
1112 /**
1113 * @brief Get burstend irq status
1114 *
1115 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1116 * @return uint32_t irq status
1117 */
pwmv2_get_burstend_irq_status(PWMV2_Type * pwm_x)1118 static inline uint32_t pwmv2_get_burstend_irq_status(PWMV2_Type *pwm_x)
1119 {
1120 return PWMV2_IRQ_STS_BURSTEND_IRQ_STS_BURSTEND_GET(pwm_x->IRQ_STS_BURSTEND);
1121 }
1122
1123 /**
1124 * @brief Clear burstend irq status
1125 *
1126 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1127 * @param mask mask status
1128 */
pwmv2_clear_burstend__irq_status(PWMV2_Type * pwm_x,uint32_t mask)1129 static inline void pwmv2_clear_burstend__irq_status(PWMV2_Type *pwm_x, uint32_t mask)
1130 {
1131 pwm_x->IRQ_STS_BURSTEND = PWMV2_IRQ_STS_BURSTEND_IRQ_STS_BURSTEND_SET(mask);
1132 }
1133
1134 /**
1135 * @brief enable cmp irq
1136 *
1137 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1138 * @param cmp_index cmp index
1139 */
pwmv2_enable_cmp_irq(PWMV2_Type * pwm_x,uint8_t cmp_index)1140 static inline void pwmv2_enable_cmp_irq(PWMV2_Type *pwm_x, uint8_t cmp_index)
1141 {
1142 pwm_x->IRQ_EN_CMP |= PWMV2_IRQ_EN_CMP_IRQ_EN_CMP_SET(1 << cmp_index);
1143 }
1144
1145 /**
1146 * @brief disable cmp irq
1147 *
1148 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1149 * @param cmp_index cmp index
1150 */
pwmv2_disable_cmp_irq(PWMV2_Type * pwm_x,uint8_t cmp_index)1151 static inline void pwmv2_disable_cmp_irq(PWMV2_Type *pwm_x, uint8_t cmp_index)
1152 {
1153 pwm_x->IRQ_EN_CMP &= ~PWMV2_IRQ_EN_CMP_IRQ_EN_CMP_SET(1 << cmp_index);
1154 }
1155
1156 /**
1157 * @brief enable reload irq
1158 *
1159 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1160 * @param counter_index @ref pwm_counter_t
1161 */
pwmv2_enable_reload_irq(PWMV2_Type * pwm_x,pwm_counter_t counter_index)1162 static inline void pwmv2_enable_reload_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
1163 {
1164 pwm_x->IRQ_EN_RELOAD |= PWMV2_IRQ_EN_RELOAD_IRQ_EN_RELOAD_SET(1 << counter_index);
1165 }
1166
1167 /**
1168 * @brief disable reload irq
1169 *
1170 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1171 * @param counter_index @ref pwm_counter_t
1172 */
pwmv2_disable_reload_irq(PWMV2_Type * pwm_x,pwm_counter_t counter_index)1173 static inline void pwmv2_disable_reload_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
1174 {
1175 pwm_x->IRQ_EN_RELOAD &= ~PWMV2_IRQ_EN_RELOAD_IRQ_EN_RELOAD_SET(1 << counter_index);
1176 }
1177
1178 /**
1179 * @brief enable capture posedge irq
1180 *
1181 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1182 * @param channel_index @ref pwm_counter_t
1183 */
pwmv2_enable_capture_posedge_irq(PWMV2_Type * pwm_x,pwm_channel_t channel_index)1184 static inline void pwmv2_enable_capture_posedge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
1185 {
1186 pwm_x->IRQ_EN_CAP_POS |= PWMV2_IRQ_EN_CAP_POS_IRQ_EN_CAP_POS_SET(1 << channel_index);
1187 }
1188
1189 /**
1190 * @brief disable capture posedge irq
1191 *
1192 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1193 * @param channel_index @ref pwm_counter_t
1194 */
pwmv2_disable_capture_posedge_irq(PWMV2_Type * pwm_x,pwm_channel_t channel_index)1195 static inline void pwmv2_disable_capture_posedge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
1196 {
1197 pwm_x->IRQ_EN_CAP_POS &= ~PWMV2_IRQ_EN_CAP_POS_IRQ_EN_CAP_POS_SET(1 << channel_index);
1198 }
1199
1200 /**
1201 * @brief enable capture nedege irq
1202 *
1203 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1204 * @param channel_index @ref pwm_channel_t
1205 */
pwmv2_enable_capture_nededge_irq(PWMV2_Type * pwm_x,pwm_channel_t channel_index)1206 static inline void pwmv2_enable_capture_nededge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
1207 {
1208 pwm_x->IRQ_EN_CAP_NEG |= PWMV2_IRQ_EN_CAP_NEG_IRQ_EN_CAP_NEG_SET(1 << channel_index);
1209 }
1210
1211 /**
1212 * @brief disable capture nedege irq
1213 *
1214 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1215 * @param channel_index @ref pwm_channel_t
1216 */
pwmv2_disable_capture_nededge_irq(PWMV2_Type * pwm_x,pwm_channel_t channel_index)1217 static inline void pwmv2_disable_capture_nededge_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
1218 {
1219 pwm_x->IRQ_EN_CAP_NEG &= ~PWMV2_IRQ_EN_CAP_NEG_IRQ_EN_CAP_NEG_SET(1 << channel_index);
1220 }
1221
1222 /**
1223 * @brief enable fault irq
1224 *
1225 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1226 * @param channel_index @ref pwm_channel_t
1227 */
pwmv2_enable_fault_irq(PWMV2_Type * pwm_x,pwm_channel_t channel_index)1228 static inline void pwmv2_enable_fault_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
1229 {
1230 pwm_x->IRQ_EN_FAULT |= PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << channel_index);
1231 }
1232
1233 /**
1234 * @brief disable fault irq
1235 *
1236 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1237 * @param channel_index @ref pwm_channel_t
1238 */
pwmv2_disable_fault_irq(PWMV2_Type * pwm_x,pwm_channel_t channel_index)1239 static inline void pwmv2_disable_fault_irq(PWMV2_Type *pwm_x, pwm_channel_t channel_index)
1240 {
1241 pwm_x->IRQ_EN_FAULT &= ~PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << channel_index);
1242 }
1243
1244 /**
1245 * @brief enable burstend irq
1246 *
1247 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1248 * @param counter_index @ref pwm_counter_t
1249 */
pwmv2_enable_burstend_irq(PWMV2_Type * pwm_x,pwm_counter_t counter_index)1250 static inline void pwmv2_enable_burstend_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
1251 {
1252 pwm_x->IRQ_EN_BURSTEND |= PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << counter_index);
1253 }
1254
1255 /**
1256 * @brief disable burstend irq
1257 *
1258 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1259 * @param counter_index @ref pwm_counter_t
1260 */
pwmv2_disable_burstend_irq(PWMV2_Type * pwm_x,pwm_counter_t counter_index)1261 static inline void pwmv2_disable_burstend_irq(PWMV2_Type *pwm_x, pwm_counter_t counter_index)
1262 {
1263 pwm_x->IRQ_EN_BURSTEND &= ~PWMV2_IRQ_EN_FAULT_IRQ_EN_FAULT_SET(1 << counter_index);
1264 }
1265
1266 /**
1267 * @brief enable dma at compare point
1268 *
1269 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1270 * @param dma_channel @ref pwm_dma_chn_t
1271 * @param cmp_index cmp index
1272 */
pwmv2_enable_dma_at_compare_point(PWMV2_Type * pwm_x,pwm_dma_chn_t dma_channel,uint8_t cmp_index)1273 static inline void pwmv2_enable_dma_at_compare_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel, uint8_t cmp_index)
1274 {
1275 pwm_x->DMA_EN = (pwm_x->DMA_EN & ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel))) |
1276 ((PWMV2_DMA_EN_DMA0_SEL_SET(cmp_index) | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
1277 }
1278
1279 /**
1280 * @brief disable dma at compare point
1281 *
1282 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1283 * @param dma_channel @ref pwm_dma_chn_t
1284 */
pwmv2_disable_dma_at_compare_point(PWMV2_Type * pwm_x,pwm_dma_chn_t dma_channel)1285 static inline void pwmv2_disable_dma_at_compare_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel)
1286 {
1287 pwm_x->DMA_EN &= ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
1288 }
1289
1290 /**
1291 * @brief enable dma at reload point
1292 *
1293 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1294 * @param dma_channel @ref pwm_dma_chn_t
1295 * @param reload_index @ref pwm_counter_t
1296 */
pwmv2_enable_dma_at_reload_point(PWMV2_Type * pwm_x,pwm_dma_chn_t dma_channel,pwm_counter_t reload_index)1297 static inline void pwmv2_enable_dma_at_reload_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel, pwm_counter_t reload_index)
1298 {
1299 pwm_x->DMA_EN = (pwm_x->DMA_EN & ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel))) |
1300 ((PWMV2_DMA_EN_DMA0_SEL_SET(reload_index + 24) | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
1301 }
1302
1303 /**
1304 * @brief disable dma at reload point
1305 *
1306 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1307 * @param dma_channel @ref pwm_dma_chn_t
1308 */
pwmv2_disable_dma_at_reload_point(PWMV2_Type * pwm_x,pwm_dma_chn_t dma_channel)1309 static inline void pwmv2_disable_dma_at_reload_point(PWMV2_Type *pwm_x, pwm_dma_chn_t dma_channel)
1310 {
1311 pwm_x->DMA_EN &= ~((PWMV2_DMA_EN_DMA0_SEL_MASK | PWMV2_DMA_EN_DMA0_EN_MASK) << (PWMV2_DMA_EN_DMA1_SEL_SHIFT * dma_channel));
1312 }
1313
1314 /**
1315 * @brief select compare point 0 index
1316 *
1317 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1318 * @param counter @ref pwm_counter_t
1319 * @param cmp_index cmp index
1320 */
pwmv2_reload_select_compare_point0_index(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t cmp_index)1321 static inline void pwmv2_reload_select_compare_point0_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cmp_index)
1322 {
1323 pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_CMP_SEL0_MASK)) | PWMV2_CNT_CFG0_RLD_CMP_SEL0_SET(cmp_index);
1324 }
1325
1326 /**
1327 * @brief select compare point 1 index
1328 *
1329 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1330 * @param counter @ref pwm_counter_t
1331 * @param cmp_index cmp index
1332 */
pwmv2_reload_select_compare_point1_index(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t cmp_index)1333 static inline void pwmv2_reload_select_compare_point1_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cmp_index)
1334 {
1335 pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_CMP_SEL1_MASK)) | PWMV2_CNT_CFG0_RLD_CMP_SEL1_SET(cmp_index);
1336 }
1337
1338 /**
1339 * @brief Select the input trigger source for the reload point
1340 *
1341 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1342 * @param counter @ref pwm_counter_t
1343 * @param trig_index trig index
1344 */
pwmv2_reload_select_input_trigger(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t trig_index)1345 static inline void pwmv2_reload_select_input_trigger(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
1346 {
1347 pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_TRIG_SEL_MASK)) | PWMV2_CNT_CFG0_RLD_TRIG_SEL_SET(trig_index);
1348 }
1349
1350 /**
1351 * @brief Set reload update time
1352 *
1353 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1354 * @param counter @ref pwm_counter_t
1355 * @param update @ref pwm_reload_update_time_t
1356 */
pwmv2_set_reload_update_time(PWMV2_Type * pwm_x,pwm_counter_t counter,pwm_reload_update_time_t update)1357 static inline void pwmv2_set_reload_update_time(PWMV2_Type *pwm_x, pwm_counter_t counter, pwm_reload_update_time_t update)
1358 {
1359 pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~(PWMV2_CNT_CFG0_RLD_UPDATE_TIME_MASK)) | PWMV2_CNT_CFG0_RLD_UPDATE_TIME_SET(update);
1360 }
1361
1362 /**
1363 * @brief Set dac data parameter
1364 *
1365 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1366 * @param counter @ref pwm_counter_t
1367 * @param dac_parameter dac parameter
1368 */
pwmv2_counter_set_dac_data_parameter(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t dac_parameter)1369 static inline void pwmv2_counter_set_dac_data_parameter(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t dac_parameter)
1370 {
1371 pwm_x->CNT[counter].CFG0 = (pwm_x->CNT[counter].CFG0 & ~PWMV2_CNT_CFG0_CNT_D_PARAM_MASK) | PWMV2_CNT_CFG0_CNT_D_PARAM_SET(dac_parameter);
1372 }
1373
1374 /**
1375 * @brief Select dac index
1376 *
1377 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1378 * @param counter @ref pwm_counter_t
1379 * @param dac_index @ref pwm_dac_channel_t
1380 */
pwmv2_conuter_select_dac_index(PWMV2_Type * pwm_x,pwm_counter_t counter,pwm_dac_channel_t dac_index)1381 static inline void pwmv2_conuter_select_dac_index(PWMV2_Type *pwm_x, pwm_counter_t counter, pwm_dac_channel_t dac_index)
1382 {
1383 pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_DAC_INDEX_MASK) | PWMV2_CNT_CFG1_CNT_DAC_INDEX_SET(dac_index);
1384 }
1385
1386 /**
1387 * @brief Enable the upper limit of the calculation unit
1388 *
1389 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1390 * @param counter @ref pwm_counter_t
1391 */
pwmv2_counter_up_limit_enable(PWMV2_Type * pwm_x,pwm_counter_t counter)1392 static inline void pwmv2_counter_up_limit_enable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1393 {
1394 pwm_x->CNT[counter].CFG1 |= PWMV2_CNT_CFG1_CNT_LU_EN_MASK;
1395 }
1396
1397 /**
1398 * @brief Disable the upper limit of the calculation unit
1399 *
1400 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1401 * @param counter @ref pwm_counter_t
1402 */
pwmv2_counter_up_limit_disable(PWMV2_Type * pwm_x,pwm_counter_t counter)1403 static inline void pwmv2_counter_up_limit_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1404 {
1405 pwm_x->CNT[counter].CFG1 &= ~PWMV2_CNT_CFG1_CNT_LU_EN_MASK;
1406 }
1407
1408 /**
1409 * @brief Select the upper limit from the shadow register
1410 *
1411 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1412 * @param counter @ref pwm_counter_t
1413 * @param index shadow index
1414 */
pwmv2_counter_select_up_limit_from_shadow_value(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t index)1415 static inline void pwmv2_counter_select_up_limit_from_shadow_value(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t index)
1416 {
1417 pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_LIM_UP_MASK) | PWMV2_CNT_CFG1_CNT_LIM_UP_SET(index);
1418 }
1419
1420 /**
1421 * @brief Enable the lower limit of the calculation unit
1422 *
1423 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1424 * @param counter @ref pwm_counter_t
1425 */
pwmv2_counter_low_limit_enable(PWMV2_Type * pwm_x,pwm_counter_t counter)1426 static inline void pwmv2_counter_low_limit_enable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1427 {
1428 pwm_x->CNT[counter].CFG1 |= PWMV2_CNT_CFG1_CNT_LL_EN_MASK;
1429 }
1430
1431
1432 /**
1433 * @brief Disable the lower limit of the calculation unit
1434 *
1435 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1436 * @param counter @ref pwm_counter_t
1437 */
pwmv2_counter_low_limit_disable(PWMV2_Type * pwm_x,pwm_counter_t counter)1438 static inline void pwmv2_counter_low_limit_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1439 {
1440 pwm_x->CNT[counter].CFG1 &= ~PWMV2_CNT_CFG1_CNT_LL_EN_MASK;
1441 }
1442
1443 /**
1444 * @brief Select the lower limit from the shadow register
1445 *
1446 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1447 * @param counter @ref pwm_counter_t
1448 * @param index shadow index
1449 */
pwmv2_counter_select_low_limit_from_shadow_value(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t index)1450 static inline void pwmv2_counter_select_low_limit_from_shadow_value(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t index)
1451 {
1452 pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_LIM_LO_MASK) | PWMV2_CNT_CFG1_CNT_LIM_LO_SET(index);
1453 }
1454
1455 /**
1456 * @brief Select data offset from shadow register
1457 *
1458 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1459 * @param counter @ref pwm_counter_t
1460 * @param index shadow index
1461 */
pwmv2_counter_select_data_offset_from_shadow_value(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t index)1462 static inline void pwmv2_counter_select_data_offset_from_shadow_value(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t index)
1463 {
1464 pwm_x->CNT[counter].CFG1 = (pwm_x->CNT[counter].CFG1 & ~PWMV2_CNT_CFG1_CNT_IN_OFF_MASK) | PWMV2_CNT_CFG1_CNT_IN_OFF_SET(index);
1465 }
1466
1467 /**
1468 * @brief enable counter reload by trigmux
1469 *
1470 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1471 * @param counter @ref pwm_counter_t
1472 */
pwmv2_counter_enable_reload_by_trig(PWMV2_Type * pwm_x,pwm_counter_t counter)1473 static inline void pwmv2_counter_enable_reload_by_trig(PWMV2_Type *pwm_x, pwm_counter_t counter)
1474 {
1475 pwm_x->CNT[counter].CFG2 |= PWMV2_CNT_CFG2_CNT_RELOAD_EN_MASK;
1476 }
1477
1478 /**
1479 * @brief disable counter reload by trigmux
1480 *
1481 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1482 * @param counter @ref pwm_counter_t
1483 */
pwmv2_counter_disable_reload_by_trig(PWMV2_Type * pwm_x,pwm_counter_t counter)1484 static inline void pwmv2_counter_disable_reload_by_trig(PWMV2_Type *pwm_x, pwm_counter_t counter)
1485 {
1486 pwm_x->CNT[counter].CFG2 &= ~PWMV2_CNT_CFG2_CNT_RELOAD_EN_MASK;
1487 }
1488
1489 /**
1490 * @brief Select counter update by trigmux1
1491 *
1492 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1493 * @param counter @ref pwm_counter_t
1494 * @param trig_index trigmux index
1495 */
pwmv2_counter_update_trig1(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t trig_index)1496 static inline void pwmv2_counter_update_trig1(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
1497 {
1498 pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_UPDATE_TRIG1_MASK) | PWMV2_CNT_CFG2_CNT_UPDATE_TRIG1_SET(trig_index);
1499 }
1500
1501 /**
1502 * @brief Enable counter update by trigmux1
1503 *
1504 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1505 * @param counter @ref pwm_counter_t
1506 */
pwmv2_counter_enable_update_trig1(PWMV2_Type * pwm_x,pwm_counter_t counter)1507 static inline void pwmv2_counter_enable_update_trig1(PWMV2_Type *pwm_x, pwm_counter_t counter)
1508 {
1509 pwm_x->CNT[counter].CFG2 |= PWMV2_CNT_CFG2_CNT_UPDATE_EN1_MASK;
1510 }
1511
1512 /**
1513 * @brief Disable counter update by trigmux1
1514 *
1515 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1516 * @param counter @ref pwm_counter_t
1517 */
pwmv2_counter_disable_update_trig1(PWMV2_Type * pwm_x,pwm_counter_t counter)1518 static inline void pwmv2_counter_disable_update_trig1(PWMV2_Type *pwm_x, pwm_counter_t counter)
1519 {
1520 pwm_x->CNT[counter].CFG2 &= ~PWMV2_CNT_CFG2_CNT_UPDATE_EN1_MASK;
1521 }
1522
1523 /**
1524 * @brief Enable change counter value to one of the calculation cell output when cnt_update_triger1 issued
1525 *
1526 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1527 * @param counter @ref pwm_counter_t
1528 * @param cal_index cal index
1529 */
pwmv2_counter_set_trig1_calculate_cell_index(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t cal_index)1530 static inline void pwmv2_counter_set_trig1_calculate_cell_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cal_index)
1531 {
1532 pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_TRIG1_MASK) | PWMV2_CNT_CFG2_CNT_TRIG1_SET(cal_index);
1533 }
1534
1535 /**
1536 * @brief Select counter update by trigmux0
1537 *
1538 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1539 * @param counter @ref pwm_counter_t
1540 * @param trig_index trigmux index
1541 */
pwmv2_counter_update_trig0(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t trig_index)1542 static inline void pwmv2_counter_update_trig0(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
1543 {
1544 pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_UPDATE_TRIG0_MASK) | PWMV2_CNT_CFG2_CNT_UPDATE_TRIG0_SET(trig_index);
1545 }
1546
1547 /**
1548 * @brief Enable counter update by trigmux0
1549 *
1550 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1551 * @param counter @ref pwm_counter_t
1552 */
pwmv2_counter_enable_update_trig0(PWMV2_Type * pwm_x,pwm_counter_t counter)1553 static inline void pwmv2_counter_enable_update_trig0(PWMV2_Type *pwm_x, pwm_counter_t counter)
1554 {
1555 pwm_x->CNT[counter].CFG2 |= PWMV2_CNT_CFG2_CNT_UPDATE_EN0_MASK;
1556 }
1557
1558 /**
1559 * @brief Disable counter update by trigmux0
1560 *
1561 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1562 * @param counter @ref pwm_counter_t
1563 */
pwmv2_counter_disable_update_trig0(PWMV2_Type * pwm_x,pwm_counter_t counter)1564 static inline void pwmv2_counter_disable_update_trig0(PWMV2_Type *pwm_x, pwm_counter_t counter)
1565 {
1566 pwm_x->CNT[counter].CFG2 &= ~PWMV2_CNT_CFG2_CNT_UPDATE_EN0_MASK;
1567 }
1568
1569 /**
1570 * @brief Enable change counter value to one of the calculation cell output when cnt_update_triger0 issued
1571 *
1572 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1573 * @param counter @ref pwm_counter_t
1574 * @param cal_index cal index
1575 */
pwmv2_counter_set_trig0_calculate_cell_index(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t cal_index)1576 static inline void pwmv2_counter_set_trig0_calculate_cell_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t cal_index)
1577 {
1578 pwm_x->CNT[counter].CFG2 = (pwm_x->CNT[counter].CFG2 & ~PWMV2_CNT_CFG2_CNT_TRIG0_MASK) | PWMV2_CNT_CFG2_CNT_TRIG0_SET(cal_index);
1579 }
1580
1581 /**
1582 * @brief Set trigmux index to start counter
1583 *
1584 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1585 * @param counter @ref pwm_counter_t
1586 * @param trig_index trig index
1587 */
pwmv2_counter_start_select_trigger_index(PWMV2_Type * pwm_x,pwm_counter_t counter,uint8_t trig_index)1588 static inline void pwmv2_counter_start_select_trigger_index(PWMV2_Type *pwm_x, pwm_counter_t counter, uint8_t trig_index)
1589 {
1590 pwm_x->CNT[counter].CFG3 = (pwm_x->CNT[counter].CFG3 & ~PWMV2_CNT_CFG3_CNT_START_SEL_MASK) | PWMV2_CNT_CFG3_CNT_START_SEL_SET(trig_index);
1591 }
1592
1593 /**
1594 * @brief Enable trigmux to trigger counter initiation
1595 *
1596 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1597 * @param counter @ref pwm_counter_t
1598 */
pwmv2_counter_start_trigger_enable(PWMV2_Type * pwm_x,pwm_counter_t counter)1599 static inline void pwmv2_counter_start_trigger_enable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1600 {
1601 pwm_x->CNT[counter].CFG3 |= PWMV2_CNT_CFG3_CNT_HW_START_EN_MASK;
1602 }
1603
1604 /**
1605 * @brief Disable trigmux to trigger counter initiation
1606 *
1607 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1608 * @param counter @ref pwm_counter_t
1609 */
pwmv2_counter_start_trigger_disable(PWMV2_Type * pwm_x,pwm_counter_t counter)1610 static inline void pwmv2_counter_start_trigger_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1611 {
1612 pwm_x->CNT[counter].CFG3 &= ~PWMV2_CNT_CFG3_CNT_HW_START_EN_MASK;
1613 }
1614
1615 /**
1616 * @brief Set counter burst value
1617 *
1618 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1619 * @param counter @ref pwm_counter_t
1620 * @param burst burst value
1621 */
pwmv2_set_counter_burst(PWMV2_Type * pwm_x,pwm_counter_t counter,uint16_t burst)1622 static inline void pwmv2_set_counter_burst(PWMV2_Type *pwm_x, pwm_counter_t counter, uint16_t burst)
1623 {
1624 pwm_x->CNT[counter].CFG3 |= PWMV2_CNT_CFG3_CNT_BURST_SET(burst);
1625 }
1626
1627 /**
1628 * @brief Disable counter burst function
1629 *
1630 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1631 * @param counter @ref pwm_counter_t
1632 */
pwmv2_counter_burst_disable(PWMV2_Type * pwm_x,pwm_counter_t counter)1633 static inline void pwmv2_counter_burst_disable(PWMV2_Type *pwm_x, pwm_counter_t counter)
1634 {
1635 pwm_x->CNT[counter].CFG3 |= PWMV2_CNT_CFG3_CNT_BURST_MASK;
1636 }
1637
1638 /**
1639 * @brief start pwm output
1640 *
1641 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1642 * @param counter @ref pwm_counter_t
1643 */
pwmv2_start_pwm_output(PWMV2_Type * pwm_x,pwm_counter_t counter)1644 static inline void pwmv2_start_pwm_output(PWMV2_Type *pwm_x, pwm_counter_t counter)
1645 {
1646 pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_CNT_SW_START_SET((1 << counter));
1647 }
1648
1649 /**
1650 * @brief Reset pwm counter
1651 *
1652 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1653 * @param counter @ref pwm_counter_t
1654 */
pwmv2_reset_counter(PWMV2_Type * pwm_x,pwm_counter_t counter)1655 static inline void pwmv2_reset_counter(PWMV2_Type *pwm_x, pwm_counter_t counter)
1656 {
1657 pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_TIMER_RESET_SET((1 << counter));
1658 }
1659
1660 /**
1661 * @brief Enable pwm counter
1662 *
1663 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1664 * @param counter @ref pwm_counter_t
1665 */
pwmv2_enable_counter(PWMV2_Type * pwm_x,pwm_counter_t counter)1666 static inline void pwmv2_enable_counter(PWMV2_Type *pwm_x, pwm_counter_t counter)
1667 {
1668 pwm_x->CNT_GLBCFG |= PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET((1 << counter));
1669 }
1670
1671 /**
1672 * @brief Disable pwm counter
1673 *
1674 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1675 * @param counter @ref pwm_counter_t
1676 */
pwmv2_disable_counter(PWMV2_Type * pwm_x,pwm_counter_t counter)1677 static inline void pwmv2_disable_counter(PWMV2_Type *pwm_x, pwm_counter_t counter)
1678 {
1679 pwm_x->CNT_GLBCFG &= ~PWMV2_CNT_GLBCFG_TIMER_ENABLE_SET((1 << counter));
1680 }
1681
1682 /**
1683 * @brief Set calculate up limit parameter
1684 *
1685 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1686 * @param cal_index calculate index
1687 * @param value parameter
1688 */
pwmv2_calculate_set_up_limit_parameter(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t value)1689 static inline void pwmv2_calculate_set_up_limit_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
1690 {
1691 pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_LU_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_LU_PARAM_SET(value);
1692 }
1693
1694 /**
1695 * @brief Set calculate low limit parameter
1696 *
1697 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1698 * @param cal_index calculate index
1699 * @param value parameter
1700 */
pwmv2_calculate_set_low_limit_parameter(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t value)1701 static inline void pwmv2_calculate_set_low_limit_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
1702 {
1703 pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_LL_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_LL_PARAM_SET(value);
1704 }
1705
1706 /**
1707 * @brief Set calculate period parameter
1708 *
1709 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1710 * @param cal_index calculate index
1711 * @param value parameter
1712 */
pwmv2_calculate_set_period_parameter(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t value)1713 static inline void pwmv2_calculate_set_period_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
1714 {
1715 pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_T_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_T_PARAM_SET(value);
1716 }
1717
1718 /**
1719 * @brief Set calculate dac value parameter
1720 *
1721 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1722 * @param cal_index calculate index
1723 * @param value parameter
1724 */
pwmv2_calculate_set_dac_value_parameter(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t value)1725 static inline void pwmv2_calculate_set_dac_value_parameter(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t value)
1726 {
1727 pwm_x->CAL[cal_index].CFG0 = (pwm_x->CAL[cal_index].CFG0 & ~PWMV2_CAL_CFG0_CAL_D_PARAM_MASK) | PWMV2_CAL_CFG0_CAL_D_PARAM_SET(value);
1728 }
1729
1730 /**
1731 * @brief Select calculate index to counter
1732 *
1733 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1734 * @param cal_index calculate index
1735 * @param counter_calculate counter index
1736 */
pwmv2_calculate_select_counter_calculate_index(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t counter_calculate)1737 static inline void pwmv2_calculate_select_counter_calculate_index(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t counter_calculate)
1738 {
1739 pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_T_INDEX_MASK) | PWMV2_CAL_CFG1_CAL_T_INDEX_SET(counter_calculate);
1740 }
1741
1742 /**
1743 * @brief Select calculate input value
1744 *
1745 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1746 * @param cal_index calculate index
1747 * @param index shadow index
1748 */
pwmv2_calculate_select_in_value(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t index)1749 static inline void pwmv2_calculate_select_in_value(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t index)
1750 {
1751 pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_IN_INDEX_MASK) | PWMV2_CAL_CFG1_CAL_IN_INDEX_SET(index);
1752 }
1753
1754 /**
1755 * @brief enable calculate up limit
1756 *
1757 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1758 * @param cal_index calculate index
1759 */
pwmv2_calculate_enable_up_limit(PWMV2_Type * pwm_x,uint8_t cal_index)1760 static inline void pwmv2_calculate_enable_up_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
1761 {
1762 pwm_x->CAL[cal_index].CFG1 |= PWMV2_CAL_CFG1_CAL_LU_EN_MASK;
1763 }
1764
1765 /**
1766 * @brief disable calculate up limit
1767 *
1768 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1769 * @param cal_index calculate index
1770 */
pwmv2_calculate_disable_up_limit(PWMV2_Type * pwm_x,uint8_t cal_index)1771 static inline void pwmv2_calculate_disable_up_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
1772 {
1773 pwm_x->CAL[cal_index].CFG1 &= ~PWMV2_CAL_CFG1_CAL_LU_EN_MASK;
1774 }
1775
1776 /**
1777 * @brief Select up limit offset from shadow index
1778 *
1779 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1780 * @param cal_index calculate index
1781 * @param shadow_index shadow index
1782 */
pwmv2_calculate_select_up_limit_offset(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t shadow_index)1783 static inline void pwmv2_calculate_select_up_limit_offset(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t shadow_index)
1784 {
1785 pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_LIM_UP_MASK) | PWMV2_CAL_CFG1_CAL_LIM_UP_SET(shadow_index);
1786 }
1787
1788 /**
1789 * @brief Select low limit offset from shadow index
1790 *
1791 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1792 * @param cal_index calculate index
1793 * @param shadow_index shadow index
1794 */
pwmv2_calculate_select_low_limit_offset(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t shadow_index)1795 static inline void pwmv2_calculate_select_low_limit_offset(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t shadow_index)
1796 {
1797 pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_LIM_LO_MASK) | PWMV2_CAL_CFG1_CAL_LIM_LO_SET(shadow_index);
1798 }
1799
1800 /**
1801 * @brief Select offset from shadow index
1802 *
1803 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1804 * @param cal_index calculate index
1805 * @param shadow_index shadow index
1806 */
pwmv2_calculate_select_in_offset(PWMV2_Type * pwm_x,uint8_t cal_index,uint8_t shadow_index)1807 static inline void pwmv2_calculate_select_in_offset(PWMV2_Type *pwm_x, uint8_t cal_index, uint8_t shadow_index)
1808 {
1809 pwm_x->CAL[cal_index].CFG1 = (pwm_x->CAL[cal_index].CFG1 & ~PWMV2_CAL_CFG1_CAL_IN_OFF_MASK) | PWMV2_CAL_CFG1_CAL_IN_OFF_SET(shadow_index);
1810 }
1811
1812 /**
1813 * @brief enable low limit
1814 *
1815 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1816 * @param cal_index calculate index
1817 */
pwmv2_calculate_enable_low_limit(PWMV2_Type * pwm_x,uint8_t cal_index)1818 static inline void pwmv2_calculate_enable_low_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
1819 {
1820 pwm_x->CAL[cal_index].CFG1 |= PWMV2_CAL_CFG1_CAL_LL_EN_MASK;
1821 }
1822
1823 /**
1824 * @brief disable low limit
1825 *
1826 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1827 * @param cal_index calculate index
1828 */
pwmv2_calculate_disable_low_limit(PWMV2_Type * pwm_x,uint8_t cal_index)1829 static inline void pwmv2_calculate_disable_low_limit(PWMV2_Type *pwm_x, uint8_t cal_index)
1830 {
1831 pwm_x->CAL[cal_index].CFG1 &= ~PWMV2_CAL_CFG1_CAL_LL_EN_MASK;
1832 }
1833
1834 /**
1835 * @brief Select cmp trigmux index
1836 *
1837 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1838 * @param cmp_index cmp index
1839 * @param trig_index trigmux index
1840 */
pwmv2_select_cmp_trigmux(PWMV2_Type * pwm_x,uint8_t cmp_index,uint8_t trig_index)1841 static inline void pwmv2_select_cmp_trigmux(PWMV2_Type *pwm_x, uint8_t cmp_index, uint8_t trig_index)
1842 {
1843 pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_TRIG_SEL_MASK) | PWMV2_CMP_CFG_CMP_TRIG_SEL_SET(trig_index);
1844 }
1845
1846 /**
1847 * @brief Select cmp update trigmux time
1848 *
1849 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1850 * @param cmp_index cmp index
1851 * @param trig_time @ref pwm_cmp_shadow_register_update_trigger_t
1852 */
pwmv2_cmp_update_trig_time(PWMV2_Type * pwm_x,uint8_t cmp_index,pwm_cmp_shadow_register_update_trigger_t trig_time)1853 static inline void pwmv2_cmp_update_trig_time(PWMV2_Type *pwm_x, uint8_t cmp_index, pwm_cmp_shadow_register_update_trigger_t trig_time)
1854 {
1855 pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_UPDATE_TIME_MASK) | PWMV2_CMP_CFG_CMP_UPDATE_TIME_SET(trig_time);
1856 }
1857
1858 /**
1859 * @brief Select cmp source
1860 *
1861 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1862 * @param cmp_index cmp index
1863 * @param cmp_sel @ref pwm_cmp_source_t
1864 * @param index source index
1865 */
pwmv2_select_cmp_source(PWMV2_Type * pwm_x,uint8_t cmp_index,pwm_cmp_source_t cmp_sel,uint8_t index)1866 static inline void pwmv2_select_cmp_source(PWMV2_Type *pwm_x, uint8_t cmp_index, pwm_cmp_source_t cmp_sel, uint8_t index)
1867 {
1868 pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_IN_SEL_MASK) | PWMV2_CMP_CFG_CMP_IN_SEL_SET((cmp_sel + index));
1869 }
1870
1871 /**
1872 * @brief Select cmp use counter
1873 *
1874 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1875 * @param cmp_index cmp index
1876 * @param counter_index @ref pwm_counter_t
1877 */
pwmv2_cmp_select_counter(PWMV2_Type * pwm_x,uint8_t cmp_index,pwm_counter_t counter_index)1878 static inline void pwmv2_cmp_select_counter(PWMV2_Type *pwm_x, uint8_t cmp_index, pwm_counter_t counter_index)
1879 {
1880 if (cmp_index >= 16) {
1881 pwm_x->CMP[cmp_index].CFG = (pwm_x->CMP[cmp_index].CFG & ~PWMV2_CMP_CFG_CMP_CNT_MASK) | PWMV2_CMP_CFG_CMP_CNT_SET((counter_index));
1882 }
1883 }
1884
1885 /**
1886 * @brief config pwm cmp
1887 *
1888 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1889 * @param index cmp index
1890 * @param config @ref pwmv2_cmp_config_t
1891 */
1892 void pwmv2_config_cmp(PWMV2_Type *pwm_x, uint8_t index, pwmv2_cmp_config_t *config);
1893
1894 /**
1895 * @brief config async fault source
1896 *
1897 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1898 * @param index cmp index
1899 * @param config @ref pwmv2_async_fault_source_config_t
1900 */
1901 void pwmv2_config_async_fault_source(PWMV2_Type *pwm_x, pwm_channel_t index, pwmv2_async_fault_source_config_t *config);
1902
1903 /**
1904 * @brief config pwm
1905 *
1906 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1907 * @param index @ref pwm_channel_t
1908 * @param config @ref pwmv2_config_t
1909 * @param enable_pair_mode bool
1910 */
1911 void pwmv2_config_pwm(PWMV2_Type *pwm_x, pwm_channel_t index, pwmv2_config_t *config, bool enable_pair_mode);
1912
1913 /**
1914 * @brief Set pwm waveform
1915 *
1916 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1917 * @param chn @ref pwm_channel_t
1918 * @param pwm_config @ref pwmv2_config_t
1919 * @param cmp_start_index cmp start index
1920 * @param cmp @ref pwmv2_cmp_config_t
1921 * @param cmp_num cmp number
1922 * @return hpm_stat_t @ref hpm_stat_t
1923 */
1924 hpm_stat_t pwmv2_setup_waveform(PWMV2_Type *pwm_x,
1925 pwm_channel_t chn, pwmv2_config_t *pwm_config,
1926 uint8_t cmp_start_index, pwmv2_cmp_config_t *cmp, uint8_t cmp_num);
1927
1928 /**
1929 * @brief set the pwm waveform complementary mode
1930 *
1931 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1932 * @param chn @ref pwm_channel_t
1933 * @param pwm_pair_config @ref pwmv2_pair_config_t
1934 * @param cmp_start_index cmp start index
1935 * @param cmp @ref pwmv2_cmp_config_t
1936 * @param cmp_num cmp number
1937 * @return hpm_stat_t @ref hpm_stat_t
1938 */
1939 hpm_stat_t pwmv2_setup_waveform_in_pair(PWMV2_Type *pwm_x, pwm_channel_t chn,
1940 pwmv2_pair_config_t *pwm_pair_config, uint8_t cmp_start_index,
1941 pwmv2_cmp_config_t *cmp, uint8_t cmp_num);
1942
1943 /**
1944 * @brief Configure the cmp calculate unit
1945 *
1946 * @param pwm_x PWM base address, HPM_PWMx(x=0..n)
1947 * @param cal_index calculate index
1948 * @param cal @ref pwmv2_cmp_calculate_cfg_t
1949 */
1950 void pwmv2_setup_cmp_calculate(PWMV2_Type *pwm_x, uint8_t cal_index, pwmv2_cmp_calculate_cfg_t *cal);
1951
1952 #ifdef __cplusplus
1953 }
1954 #endif
1955 /**
1956 * @}
1957 */
1958 #endif /* HPM_PWMV2_DRV_H */
1959