aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/hal/inc/fsl_pwm_hal.h
blob: 37ee6859467089a63ddb7bac681f508152beb230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*
 * Copyright (c) 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FSL_PWM_HAL_H__
#define __FSL_PWM_HAL_H__

#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include "fsl_device_registers.h"

#if FSL_FEATURE_SOC_PWM_COUNT

/*!
 * @addtogroup pwm_hal
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*! @brief PWM submodules */
typedef enum _pwm_module
{
    kFlexPwmModule0 = 0U,                /*!< Sub-module 0. @internal gui name="PWM Sub-module 0" */
    kFlexPwmModule1,                     /*!< Sub-module 1. @internal gui name="PWM Sub-module 1" */
    kFlexPwmModule2,                     /*!< Sub-module 2. @internal gui name="PWM Sub-module 2" */
    kFlexPwmModule3                      /*!< Sub-module 3. @internal gui name="PWM Sub-module 3" */
} pwm_module_t;

/*! @brief PWM signals from each module */
typedef enum _pwm_module_signal
{
    kFlexPwmB = 0U,
    kFlexPwmA,
    kFlexPwmX
} pwm_module_signal_t;

/*! @brief PWM value registers */
typedef enum _pwm_val_regs
{
    kFlexPwmVAL0 = 0U,   /*!< PWM VAL0 reg. @internal gui name="PWM value register 0" */
    kFlexPwmVAL1,        /*!< PWM VAL1 reg. @internal gui name="PWM value register 1" */
    kFlexPwmVAL2,        /*!< PWM VAL2 reg. @internal gui name="PWM value register 2" */
    kFlexPwmVAL3,        /*!< PWM VAL3 reg. @internal gui name="PWM value register 3" */
    kFlexPwmVAL4,        /*!< PWM VAL4 reg. @internal gui name="PWM value register 4" */
    kFlexPwmVAL5         /*!< PWM VAL5 reg. @internal gui name="PWM value register 5" */
} pwm_val_regs_t;

/*! @brief PWM status */
typedef enum _pwm_status {
    kStatusPwmSuccess = 0U,                   /*!< PWM success status.*/
    kStatusPwmError = 1U,                     /*!< PWM error status.*/
    kStatusPwmInvalidArgument = 2U            /*!< PWM invalid argument.*/
} pwm_status_t;

/*! @brief PWM clock source selection.*/
typedef enum _pwm_clock_src
{
    kClkSrcPwmIPBusClk = 0U,  /*!< The IPBus clock is used as the clock. @internal gui name="IPBus clock" */
    kClkSrcPwmExtClk,         /*!< EXT_CLK is used as the clock. @internal gui name="External clock (EXT_CLK)" */
    kClkSrcPwm0Clk            /*!< Clock of Submodule 0 (AUX_CLK) is used as the source clock. @internal gui name="Clock of Submodule 0 clock (AUX_CLK)" */
} pwm_clock_src_t;

/*! @brief PWM prescaler factor selection for clock source*/
typedef enum _pwm_clock_ps
{
    kPwmDividedBy1 = 0U,                       /*!< PWM clock frequency = fclk/1. @internal gui name="PWM clock divided by 1" */
    kPwmDividedBy2,                            /*!< PWM clock frequency = fclk/2. @internal gui name="PWM clock divided by 2" */
    kPwmDividedBy4,                            /*!< PWM clock frequency = fclk/4. @internal gui name="PWM clock divided by 4" */
    kPwmDividedBy8,                            /*!< PWM clock frequency = fclk/8. @internal gui name="PWM clock divided by 8" */
    kPwmDividedBy16,                           /*!< PWM clock frequency = fclk/16. @internal gui name="PWM clock divided by 16" */
    kPwmDividedBy32,                           /*!< PWM clock frequency = fclk/32. @internal gui name="PWM clock divided by 32" */
    kPwmDividedBy64,                           /*!< PWM clock frequency = fclk/64. @internal gui name="PWM clock divided by 64" */
    kPwmDividedBy128                           /*!< PWM clock frequency = fclk/128. @internal gui name="PWM clock divided by 128" */
} pwm_clock_ps_t;

/*! @brief Options that can trigger a PWM FORCE_OUT */
typedef enum _pwm_force_output_trigger
{
    kForceOutputLocalForce = 0U,  /*!< The local force signal, CTRL2[FORCE], from this submodule is used to force updates. @internal gui name="The local force signal, CTRL2[FORCE], from this submodule is used to force updates" */
    kForceOutputMasterForce,      /*!< The master force signal from submodule 0 is used to force updates. @internal gui name="The master force signal from submodule 0 is used to force updates" */
    kForceOutputLocalReload,      /*!< The local reload signal from this submodule is used to force updates without regard to the state of LDOK. @internal gui name="The local reload signal from this submodule is used to force updates without regard to the state of LDOK" */
    kForceOutputMasterReload,     /*!< The master reload signal from submodule 0 is used to force updates if LDOK is set. @internal gui name="The master reload signal from submodule 0 is used to force updates if LDOK is set" */
    kForceOutputLocalSync,        /*!< The local sync signal from this submodule is used to force updates. @internal gui name="The local sync signal from this submodule is used to force updates" */
    kForceOutputMasterSync,       /*!< The master sync signal from submodule0 is used to force updates. @internal gui name="The master sync signal from submodule0 is used to force updates" */
    kForceOutputExternalForce     /*!< The external force signal, EXT_FORCE, from outside the PWM module causes updates. @internal gui name="The external force signal, EXT_FORCE, from outside the PWM module causes updates" */
} pwm_force_output_trigger_t;

/*! @brief PWM counter initialization options */
typedef enum _pwm_init_src
{
    kInitSrcLocalSync = 0U,                   /*!< Local sync (PWM_X) causes initialization. @internal gui name="Local sync (PWM_X) causes initialization"*/
    kInitSrcMasterReload,                     /*!< Master reload from submodule 0 causes initialization. @internal gui name="Master reload from submodule 0 causes initialization" */
    kInitSrcMasterSync,                       /*!< Master sync from submodule 0 causes initialization. @internal gui name="Master sync from submodule 0 causes initialization" */
    kInitSrcExtSync                           /*!< EXT_SYNC causes initialization. @internal gui name="EXT_SYNC causes initialization" */
} pwm_init_src_t;

/*! @brief PWM load frequency selection */
typedef enum _pwm_load_frequency
{
    kPwmLoadEvery1Oportunity = 0U,             /*!< Every 1 PWM opportunity. @internal gui name="Every 1 PWM opportunity" */
    kPwmLoadEvery2Oportunity,                  /*!< Every 2 PWM opportunities. @internal gui name="Every 2 PWM opportunities" */
    kPwmLoadEvery3Oportunity,                  /*!< Every 3 PWM opportunities. @internal gui name="Every 3 PWM opportunities" */
    kPwmLoadEvery4Oportunity,                  /*!< Every 4 PWM opportunities. @internal gui name="Every 4 PWM opportunities" */
    kPwmLoadEvery5Oportunity,                  /*!< Every 5 PWM opportunities. @internal gui name="Every 5 PWM opportunities" */
    kPwmLoadEvery6Oportunity,                  /*!< Every 6 PWM opportunities. @internal gui name="Every 6 PWM opportunities" */
    kPwmLoadEvery7Oportunity,                  /*!< Every 7 PWM opportunities. @internal gui name="Every 7 PWM opportunities" */
    kPwmLoadEvery8Oportunity,                  /*!< Every 8 PWM opportunities. @internal gui name="Every 8 PWM opportunities" */
    kPwmLoadEvery9Oportunity,                  /*!< Every 9 PWM opportunities. @internal gui name="Every 9 PWM opportunities" */
    kPwmLoadEvery10Oportunity,                 /*!< Every 10 PWM opportunities. @internal gui name="Every 10 PWM opportunities" */
    kPwmLoadEvery11Oportunity,                 /*!< Every 11 PWM opportunities. @internal gui name="Every 11 PWM opportunities" */
    kPwmLoadEvery12Oportunity,                 /*!< Every 12 PWM opportunities. @internal gui name="Every 12 PWM opportunities" */
    kPwmLoadEvery13Oportunity,                 /*!< Every 13 PWM opportunities. @internal gui name="Every 13 PWM opportunities" */
    kPwmLoadEvery14Oportunity,                 /*!< Every 14 PWM opportunities. @internal gui name="Every 14 PWM opportunities" */
    kPwmLoadEvery15Oportunity,                 /*!< Every 15 PWM opportunities. @internal gui name="Every 15 PWM opportunities" */
    kPwmLoadEvery16Oportunity                  /*!< Every 16 PWM opportunities. @internal gui name="Every 16 PWM opportunities" */
} pwm_load_frequency_t;

/*! @brief PWM fault select */
typedef enum _pwm_fault_input
{
    kFlexPwmFault0 = 0U,                /*!< Fault 0 input pin. @internal gui name="Fault pin 0" */
    kFlexPwmFault1,                     /*!< Fault 1 input pin. @internal gui name="Fault pin 1" */
    kFlexPwmFault2,                     /*!< Fault 2 input pin. @internal gui name="Fault pin 2" */
    kFlexPwmFault3                      /*!< Fault 3 input pin. @internal gui name="Fault pin 3" */
} pwm_fault_input_t;

/*! @brief PWM capture edge select */
typedef enum _pwm_capture_edge
{
    kCaptureDisable = 0U,                    /*!< Disabled */
    kCaptureFallingEdges,                    /*!< Capture falling edges */
    kCaptureRisingEdges,                     /*!< Capture rising edges */
    kCaptureAnyEdges                         /*!< Capture any edge */
} pwm_capture_edge_t;

/*! @brief PWM output options when a FORCE_OUT signal is asserted */
typedef enum _pwm_force_signal
{
    kFlexPwmUsePwm = 0U,        /*!< Generated PWM signal is used by the deadtime logic.*/
    kFlexPwmInvertedPwm,        /*!< Inverted PWM signal is used by the deadtime logic.*/
    kFlexPwmSoftwareControl,    /*!< Software controlled value is used by the deadtime logic. */
    kFlexPwmUseExternal         /*!< PWM_EXTA signal is used by the deadtime logic. */
} pwm_force_signal_t;

/*! @brief Optiona available for the PWM A & B pair operation */
typedef enum _pwm_chnl_pair_operation
{
    kFlexPwmIndependent = 0U,   /*!< PWM A & PWM B operation as 2 independent channels. @internal gui name="Independent" */
    kFlexPwmComplementaryPwmA,  /*!< PWM A & PWM B are compelementary channels, PWM A generates the signal. @internal gui name="Complementary, PWM A generates the signal" */
    kFlexPwmComplementaryPwmB   /*!< PWM A & PWM B are compelementary channels, PWM B generates the signal. @internal gui name="Complementary, PWM B generates the signal" */
} pwm_chnl_pair_operation_t;

/*! @brief Options available on how to load the buffered-registers with new values */
typedef enum _pwm_reg_reload
{
    kFlexPwmReloadImmediate = 0U,     /*!< Buffered-registers get loaded with new values as soon as LDOK bit is set. @internal gui name="Reload immediately upon MCTRL[LDOK] being set" */
    kFlexPwmReloadPwmHalfCycle,       /*!< Registers loaded on a PWM half cycle. @internal gui name="Reload on a PWM half cycle" */
    kFlexPwmReloadPwmFullCycle,       /*!< Registers loaded on a PWM full cycle. @internal gui name="Reload on a PWM full cycle" */
    kFlexPwmReloadPwmHalfAndFullCycle /*!< Registers loaded on a PWM half & full cycle. @internal gui name="Reload on both half and full PWM cycle" */
} pwm_reg_reload_t;

/*! @brief Options available on how to re-enable the PWM output when recovering from a fault */
typedef enum _pwm_fault_recovery_mode
{
    kFlexPwmNoRecovery = 0U,        /*!< PWM output will stay inactive. @internal gui name="No Recovery" */
    kFlexPwmRecoverHalfCycle,       /*!< PWM output re-enabled at the first half cycle. @internal gui name="Half cycle recovery" */
    kFlexPwmRecoverFullCycle,       /*!< PWM output re-enabled at the first full cycle. @internal gui name="Full cycle recovery" */
    kFlexPwmRecoverHalfAndFullCycle /*!< PWM output re-enabled at the first half or full cycle. @internal gui name="Half and Full cycle recovery" */
} pwm_fault_recovery_mode_t;

/*!
 * @brief Structure is used to hold the parameters to configure a PWM module
 *
 * @internal gui name="PWM Sub-module configuration" id="pwmModuleCfg"
 */
typedef struct PwmModuleSetup
{
    pwm_init_src_t cntrInitSel;      /*!< Option to initialize the counter. @internal gui name="PWM counter initialization" id="pwm_cntrInitSel" */
    pwm_clock_src_t clkSrc;          /*!< Clock source for the counter. @internal gui name="PWM clock source" id="pwm_clkSrc" */
    pwm_clock_ps_t prescale;         /*!< Pre-scaler to divide down the clock. @internal gui name="PWM clock prescaler" id="pwm_prescale" */
    pwm_chnl_pair_operation_t chnlPairOper; /*!< Channel pair in indepedent or complementary mode. @internal gui name="PWM channel mode" id="pwm_chnlPairOper" */
    pwm_reg_reload_t reloadLogic;    /*!< PWM Reload logic setup. @internal gui name="PWM reload logic" id="pwm_reloadLogic" */
    pwm_load_frequency_t reloadFreq; /*!< Specifies when to reload, used when user's choice is not immediate reload. @internal gui name="PWM reload frequency" id="pwm_reloadFreq" */
    pwm_force_output_trigger_t forceTrig; /*!< Specify which signal will trigger a FORCE_OUT. @internal gui name="PWM trigger settings" id="pwm_forceTrig" */
} pwm_module_setup_t;

 /*!
 * @brief Structure is used to hold the parameters to configure a PWM fault
 *
 * @internal gui name="PWM Fault configuration" id="pwmFaultCfg"
 */
typedef struct PwmFaultSetup
{
    bool automaticClearing;            /*!< true: Use automatic fault clearing; false: Manual fault clearing. @internal gui name="Automatic clearing" id="pwm_automaticClearing" */
    bool faultLevel;                   /*!< true: Logic 1 indicates fault; false: Logic 0 indicates fault. @internal gui name="Fault level" id="pwm_faultLevel" */
    bool useFaultFilter;               /*!< true: Use the filtered fault signal; false: Use the direct path from fault input. @internal gui name="Use fault filter" id="pwm_useFaultFilter" */
    pwm_fault_recovery_mode_t recMode; /*!< Specify when to re-enable the PWM output. @internal gui name="Fault recovery mode" id="pwm_recMode" */
} pwm_fault_setup_t;

/*!
 * @brief Structure is used to hold parameters to configure the capture capability of a signal pin
 */
typedef struct PwmCaptureSetup
{
    bool captureInputSel;     /*!< true: Use the edge counter signal as source
                                   false: Use the raw input signal from the pin as source */
    uint8_t edgeCompareVal;   /*!< Compare value, used only if edge counter is used as source */
    pwm_capture_edge_t edge0; /*!< Specify which edge causes a capture for input circuitry 0 */
    pwm_capture_edge_t edge1; /*!< Specify which edge causes a capture for input circuitry 1 */
    bool oneShotCapture;      /*!< true: Use one-shot capture mode;
                                   false: Use free-running capture mode */
} pwm_capture_setup_t;


/*******************************************************************************
 * API
 ******************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @brief Initialize the PWM to its reset state.
 *
 * Set the control registers to their reset state
 *
 * @param base  Base address pointer of eflexPWM module
 */
void PWM_HAL_Init(PWM_Type *base);

/*!
 * @brief Sets up a PWM sub-module.
 *
 * Flex PWM has 4 sub-modules. This function sets up key features that configure the
 * working of each sub-module. This function will setup:
 * 1. Clock source and clock prescaler
 * 2. Submodules PWM A & PWM B signals operation (independent or complementary)
 * 3. Reload logic to use and reload freqeuncy
 * 4. Force trigger to use to generate the FORCE_OUT signal.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param setupParams Parameters passed in to setup the submodule
 */
void PWM_HAL_SetupPwmSubModule(PWM_Type *base, pwm_module_t subModuleNum,
                                           pwm_module_setup_t *setupParams);

/*!
 * @brief Sets up the working of the Flex PWM fault protection.
 *
 * Flex PWM has 4 fault inputs. This function sets up the working of each fault. The function
 * will setup:
 * 1. Fault automatic clearing function
 * 2. Sets up the fault level
 * 3. Defines if the fault filter should be used for this fault input
 * 4. Recovery mode to be used to re-enable the PWM output
 *
 * @param base  Base address pointer of eflexPWM module
 * @param faultNum is a number of the PWM fault to configure.
 * @param setupParams Parameters passed in to setup the fault
 */
void PWM_HAL_SetupFaults(PWM_Type *base, pwm_fault_input_t faultNum,
                                 pwm_fault_setup_t *setupParams);

/*!
 * @brief Sets up the Flex PWM capture
 *
 * Each PWM submodule has 3 pins can be configured to use for capture. This function will
 * setup the capture for each pin as follows:
 * 1. Whether to use the edge counter or raw input
 * 2. Edge capture mode
 * 3. One-shot or continuous
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param pwmSignal Which signal in the submodule to setup
 * @param setupParams Parameters passed in to setup the input pin
 */
void PWM_HAL_SetupCapture(PWM_Type *base, pwm_module_t subModuleNum,
                                   pwm_module_signal_t pwmSignal, pwm_capture_setup_t *setupParams);

/*!
 * @brief Gets PWM capture value.
 *
 * Read one of the 6 capture value registers
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param cmpReg is a number of value compare register to get
 * @return PWM value register
 */
uint16_t PWM_HAL_GetCaptureValReg(PWM_Type *base, pwm_module_t subModuleNum,
                                            pwm_val_regs_t cmpReg);

/*!
 * @brief Sets PWM value register.
 *
 * Sets one of the 6 value registers.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param valReg is the number of the value register to be set
 * @param val is a number of value to write
 */
void PWM_HAL_SetValReg (PWM_Type *base, uint8_t subModuleNum, pwm_val_regs_t valReg,
                               uint16_t val);

/*!
 * @brief Selects the signal to output when a FORCE_OUT signal is asserted
 *
 * User specifies which pin to configure by supplying the submodule number and whether
 * he wishes to modify PWM A or PWM B within that submodule
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param pwmSignal specifies which signal to work with in the module
 * @param mode signal to output when a FORCE_OUT is triggered
 */
void PWM_HAL_SetupForceSignal(PWM_Type *base, pwm_module_t subModuleNum,
                                       pwm_module_signal_t pwmSignal, pwm_force_signal_t mode);


/*!
 * @brief Returns PWM peripheral current counter value.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @return current PWM counter value
 */
static inline uint16_t PWM_HAL_GetCounter(PWM_Type *base, pwm_module_t subModuleNum)
{
    return PWM_RD_CNT(base, subModuleNum);
}

/*!
 * @brief Sets PWM timer counter initial value.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param val initial value to be set
 */
static inline void PWM_HAL_SetCounterInitVal(PWM_Type *base, pwm_module_t subModuleNum,
                                                     uint16_t val)
{
    PWM_WR_INIT(base, subModuleNum, val);
}

/*!
 * @brief Outputs a FORCE signal.
 *
 * This function will enable/disable the force init logic and assert/de-assert the FORCE signal
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param val true to enable, false to disable.
 */
static inline void PWM_HAL_SetForceCmd(PWM_Type *base, pwm_module_t subModuleNum, bool val )
{
    PWM_BWR_CTRL2_FRCEN(base, subModuleNum, val);
    PWM_BWR_CTRL2_FORCE(base, subModuleNum, val);
}

/*!
 * @brief Sets output polarity for PWM_B.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param val true to set inverted output, false to set non inverted output.
 */
static inline void PWM_HAL_SetOutputPolarityPwmBCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                                  bool val)
{
    PWM_BWR_OCTRL_POLB(base, subModuleNum, val);
}

/*!
 * @brief Sets output polarity for PWM_A.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param val true to set inverted output, false to set non inverted output.
 */
static inline void PWM_HAL_SetOutputPolarityPwmACmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                                 bool val)
{
    PWM_BWR_OCTRL_POLA(base, subModuleNum, val);
}

/*!
 * @brief Sets output polarity for PWM_X.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param val true to set inverted output, false to set non inverted output.
 */
static inline void PWM_HAL_SetOutputPolarityPwmXCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                                 bool val)
{
    PWM_BWR_OCTRL_POLX(base, subModuleNum, val);
}

/*!
 * @brief Enables or disables if a match with a value register will cause an output trigger.
 *
 * There are 2 triggers available per PWM submodule. This function allows the user the ability
 * to activate a trigger when the counter matches one of the 6 value registers. Enabling
 * VAL0, VAL2 or VAL4 will output a trigger on a match on TRIG0. Enabling VAL1, VAL3, VAL5 will
 * output a trigger on a match on TRIG1.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param valueReg register that is the cause for the output triger.
 * @param val true to trigger enable, false to disable.
 */
static inline void PWM_HAL_SetOutputTriggerCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                          uint8_t valueReg, bool val)
{
    assert(valueReg < 6U);
    val ? PWM_SET_TCTRL(base, subModuleNum, 1U << valueReg) :
          PWM_CLR_TCTRL(base, subModuleNum, 1U << valueReg);
}

/*!
 * @brief Enables or disables fault input for PWM A.
 *
 * Enabling the specified fault will cause the PWM A signal to deactivate when the fault occurs.
 * User should configure the PWM faults by calling PWM_HAL_SetupFaults() prior to enabling them
 * in the submodules.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param fault number, options: 0,1,2,3 .
 * @param val true to enable the fault input, false to disable fault input.
 */
static inline void PWM_HAL_SetPwmAFaultInputCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                            pwm_fault_input_t fault, bool val)
{
    val ? PWM_SET_DISMAP(base, subModuleNum, 0, 1U << fault) :
          PWM_CLR_DISMAP(base, subModuleNum, 0, 1U << fault);
}

/*!
 * @brief Enables or disables fault input for PWM B.
 *
 * Enabling the specified fault will cause the PWM B signal to deactivate when the fault occurs.
 * User should configure the PWM faults by calling PWM_HAL_SetupFaults() prior to enabling them
 * in the submodules.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param fault number, options: 0,1,2,3 .
 * @param val true to enable the fault input, false to disable fault input.
 */
static inline void PWM_HAL_SetPwmBFaultInputCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                            pwm_fault_input_t fault, bool val)
{
    val ? PWM_SET_DISMAP(base, subModuleNum, 0, 1U << (fault + PWM_DISMAP_DIS0B_SHIFT)) :
          PWM_CLR_DISMAP(base, subModuleNum, 0, 1U << (fault + PWM_DISMAP_DIS0B_SHIFT));
}

/*!
 * @brief Enables or disables fault input for PWM X.
 *
 * Enabling the specified fault will cause the PWM X signal to deactivate when the fault occurs.
 * User should configure the PWM faults by calling PWM_HAL_SetupFaults() prior to enabling them
 * in the submodules.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param fault number, options: 0,1,2,3.
 * @param val true to enable the fault input; false to disable the fault input
 */
static inline void PWM_HAL_SetPwmXFaultInputCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                            pwm_fault_input_t fault, bool val)
{
    val ? PWM_SET_DISMAP(base, subModuleNum, 0, 1U << (fault + PWM_DISMAP_DIS0X_SHIFT)) :
          PWM_CLR_DISMAP(base, subModuleNum, 0, 1U << (fault + PWM_DISMAP_DIS0X_SHIFT));
}

/*!
 * @brief Sets PWM_X pin to input or output.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum Number of the PWM submodule.
 * @param val true to make the pin as output output, false to make the pin as input
 */
static inline void PWM_HAL_SetOutputPwmXCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                         bool val)
{
    val ? PWM_SET_OUTEN(base, 1U << subModuleNum) :
          PWM_CLR_OUTEN(base, 1U << subModuleNum);
}

/*!
 * @brief Sets PWM_B pin to input or output.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum Number of the PWM submodule.
 * @param val true to make the pin as output output, false to make the pin as input
 */
static inline void PWM_HAL_SetOutputPwmBCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                         bool val)
{
    val ? PWM_SET_OUTEN(base, 1U << (subModuleNum + PWM_OUTEN_PWMB_EN_SHIFT)) :
          PWM_CLR_OUTEN(base, 1U << (subModuleNum + PWM_OUTEN_PWMB_EN_SHIFT));
}

/*!
 * @brief Sets PWM_A pin to input or output.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum Number of the PWM submodule.
 * @param val true to make the pin as output output, false to make the pin as input
 */
static inline void PWM_HAL_SetOutputPwmACmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                         bool val)
{
    val ? PWM_SET_OUTEN(base, 1U << (subModuleNum + PWM_OUTEN_PWMA_EN_SHIFT)) :
          PWM_CLR_OUTEN(base, 1U << (subModuleNum + PWM_OUTEN_PWMA_EN_SHIFT));
}

/*!
 * @brief Sets software control output for a pin to high or low.
 *
 * User specifies which signal to modify by supplying the submodule number and whether
 * he wishes to modify PWM A or PWM B within that submodule
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModuleNum is a number of the PWM submodule.
 * @param output specifies which signal to work with in the module, 0 is PWM B, 1 is PWM A
 * @param val true to supply a logic 1, false to supply a logic 0.
 */
static inline void PWM_HAL_SetSwCtrlOutCmd(PWM_Type *base, pwm_module_t subModuleNum,
                                                      pwm_module_signal_t output, bool val)
{
    val ? PWM_SET_SWCOUT(base, (1U << ((subModuleNum * 2) + output))) :
          PWM_CLR_SWCOUT(base, (1U << ((subModuleNum * 2) + output)));
}

/*!
 * @brief Sets PWM generator run.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param subModules represented by corresponded bits.
 * @param val true to run selected subModuleNums, false to stop selected subModuleNums output.
 */
static inline void PWM_HAL_SetPwmRunCmd(PWM_Type *base, uint8_t subModules, bool val)
{
    assert(subModules < 16U);
    val ? PWM_SET_MCTRL(base, (unsigned)subModules << PWM_MCTRL_RUN_SHIFT) :
          PWM_CLR_MCTRL(base, (unsigned)subModules << PWM_MCTRL_RUN_SHIFT);
}

/*!
 * @brief Sets fault interrupt.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param fault represented by corresponded bits.
 * @param val true to enable the interrupt request, false to disable.
 */
static inline void PWM_HAL_SetFaultIntCmd(PWM_Type *base, pwm_fault_input_t fault,
                                                  bool val)
{
    val ? PWM_SET_FCTRL(base, (1U << fault)) : PWM_CLR_FCTRL(base, (1U << fault));
}

/*!
 * @brief Clears fault flags.
 *
 * @param base  Base address pointer of eflexPWM module
 * @param fault represented by corresponded bits.
 */
static inline void PWM_HAL_ClearFaultFlags(PWM_Type *base, pwm_fault_input_t fault)
{
    PWM_SET_FSTS(base, (1U << fault));
}

#if defined(__cplusplus)
}
#endif

/*! @}*/

#endif /* FSL_FEATURE_SOC_PWM_COUNT */

#endif /* __FSL_PWM_HAL_H__*/
/*******************************************************************************
 * EOF
 ******************************************************************************/