1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef EMIOS_PWM_IP_H
8 #define EMIOS_PWM_IP_H
9 
10 /**
11 *   @file       Emios_Pwm_Ip.h
12 *
13 *   @addtogroup emios_pwm_ip Emios Pwm IPL
14 *   @{
15 */
16 
17 #ifdef __cplusplus
18 extern "C"{
19 #endif
20 
21 
22 /*==================================================================================================
23 *                                          INCLUDE FILES
24 * 1) system and project includes
25 * 2) needed interfaces from external units
26 * 3) internal and external interfaces from this unit
27 ==================================================================================================*/
28 #include "Std_Types.h"
29 #include "Emios_Pwm_Ip_Cfg.h"
30 #include "Emios_Pwm_Ip_Types.h"
31 
32 /*==================================================================================================
33 *                                 SOURCE FILE VERSION INFORMATION
34 ==================================================================================================*/
35 #define EMIOS_PWM_IP_VENDOR_ID                       43
36 #define EMIOS_PWM_IP_MODULE_ID                       121
37 #define EMIOS_PWM_IP_AR_RELEASE_MAJOR_VERSION        4
38 #define EMIOS_PWM_IP_AR_RELEASE_MINOR_VERSION        7
39 #define EMIOS_PWM_IP_AR_RELEASE_REVISION_VERSION     0
40 #define EMIOS_PWM_IP_SW_MAJOR_VERSION                3
41 #define EMIOS_PWM_IP_SW_MINOR_VERSION                0
42 #define EMIOS_PWM_IP_SW_PATCH_VERSION                0
43 
44 /*==================================================================================================
45 *                                       FILE VERSION CHECKS
46 ==================================================================================================*/
47 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
48     /* Check if header file and Std_Types.h are of the same AUTOSAR version */
49     #if ((EMIOS_PWM_IP_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
50          (EMIOS_PWM_IP_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION))
51         #error "AUTOSAR Version Numbers of Emios_Pwm_Ip.h and Std_Types.h are different"
52     #endif
53 #endif
54 
55 /* Check if header file and Emios_Pwm_Ip_Cfg header file are of the same vendor */
56 #if (EMIOS_PWM_IP_VENDOR_ID != EMIOS_PWM_IP_CFG_VENDOR_ID)
57     #error "Vendor IDs of Emios_Pwm_Ip.h and Emios_Pwm_Ip_Cfg.h are different."
58 #endif
59 
60 /* Check if header file and Emios_Pwm_Ip_Cfg header file are of the same AUTOSAR version */
61 #if ((EMIOS_PWM_IP_AR_RELEASE_MAJOR_VERSION    != EMIOS_PWM_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \
62      (EMIOS_PWM_IP_AR_RELEASE_MINOR_VERSION    != EMIOS_PWM_IP_CFG_AR_RELEASE_MINOR_VERSION) || \
63      (EMIOS_PWM_IP_AR_RELEASE_REVISION_VERSION != EMIOS_PWM_IP_CFG_AR_RELEASE_REVISION_VERSION))
64     #error "AUTOSAR version numbers of Emios_Pwm_Ip.h and Emios_Pwm_Ip_Cfg.h are different."
65 #endif
66 
67 /* Check if header file and Emios_Pwm_Ip_Cfg header file are of the same software version */
68 #if ((EMIOS_PWM_IP_SW_MAJOR_VERSION != EMIOS_PWM_IP_CFG_SW_MAJOR_VERSION) || \
69      (EMIOS_PWM_IP_SW_MINOR_VERSION != EMIOS_PWM_IP_CFG_SW_MINOR_VERSION) || \
70      (EMIOS_PWM_IP_SW_PATCH_VERSION != EMIOS_PWM_IP_CFG_SW_PATCH_VERSION))
71     #error "Software version numbers of Emios_Pwm_Ip.h and Emios_Pwm_Ip_Cfg.h are different."
72 #endif
73 
74 /* Check if header file and Emios_Pwm_Ip_Types header file are of the same vendor */
75 #if (EMIOS_PWM_IP_VENDOR_ID != EMIOS_PWM_IP_TYPES_VENDOR_ID)
76     #error "Vendor IDs of Emios_Pwm_Ip.h and Emios_Pwm_Ip_Types.h are different."
77 #endif
78 
79 /* Check if header file and Emios_Pwm_Ip_Types header file are of the same AUTOSAR version */
80 #if ((EMIOS_PWM_IP_AR_RELEASE_MAJOR_VERSION    != EMIOS_PWM_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
81      (EMIOS_PWM_IP_AR_RELEASE_MINOR_VERSION    != EMIOS_PWM_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
82      (EMIOS_PWM_IP_AR_RELEASE_REVISION_VERSION != EMIOS_PWM_IP_TYPES_AR_RELEASE_REVISION_VERSION))
83     #error "AUTOSAR version numbers of Emios_Pwm_Ip.h and Emios_Pwm_Ip_Types.h are different."
84 #endif
85 
86 /* Check if header file and Emios_Pwm_Ip_Types header file are of the same software version */
87 #if ((EMIOS_PWM_IP_SW_MAJOR_VERSION != EMIOS_PWM_IP_TYPES_SW_MAJOR_VERSION) || \
88      (EMIOS_PWM_IP_SW_MINOR_VERSION != EMIOS_PWM_IP_TYPES_SW_MINOR_VERSION) || \
89      (EMIOS_PWM_IP_SW_PATCH_VERSION != EMIOS_PWM_IP_TYPES_SW_PATCH_VERSION))
90     #error "Software version numbers of Emios_Pwm_Ip.h and Emios_Pwm_Ip_Types.h are different."
91 #endif
92 
93 /*==================================================================================================
94 *                                            CONSTANTS
95 ==================================================================================================*/
96 
97 /*==================================================================================================
98 *                                       DEFINES AND MACROS
99 ==================================================================================================*/
100 
101 /*==================================================================================================
102 *                                              ENUMS
103 ==================================================================================================*/
104 
105 /*==================================================================================================
106 *                                  STRUCTURES AND OTHER TYPEDEFS
107 ==================================================================================================*/
108 
109 /*==================================================================================================
110 *                                  GLOBAL VARIABLE DECLARATIONS
111 ==================================================================================================*/
112 
113 /*==================================================================================================
114 *                                       FUNCTION PROTOTYPES
115 ==================================================================================================*/
116 #define PWM_START_SEC_CODE
117 #include "Pwm_MemMap.h"
118 
119 /**
120 * @brief Initialize PWM Mode
121 *
122 * @param[in] Instance    The eMIOS group id
123 * @param[in] UserChCfg   A pointer to the PWM configuration structure
124 * @return void
125 */
126 void Emios_Pwm_Ip_InitChannel(uint8 Instance,
127                               Emios_Pwm_Ip_ChannelConfigType const *UserChCfg);
128 
129 /**
130  * @brief Reset eMIOS Channel to GPIO mode (reset default)
131  *
132  * @param[in] Instance  The eMIOS group id
133  * @param[in] Channel   The Channel in this eMIOS group
134  * @return void
135  */
136 void Emios_Pwm_Ip_DeInitChannel(uint8 Instance,
137                                 uint8 Channel);
138 
139 /**
140  * @brief Allow the software to force the output flip-flop to the level corresponding
141  * to a match on leading edge. The FLAG bit is not set.
142  *
143  * @param[in] Instance The eMIOS group id
144  * @param[in] Channel  The Channel in this eMIOS group
145  * @param[in] Enable   The Channel in Force Match Leading Edge or not
146  * @return void
147  */
148 void Emios_Pwm_Ip_ForceMatchLeadingEdge(uint8 Instance,
149                                         uint8 Channel,
150                                         boolean Enable);
151 
152 /**
153  * @brief Allow the software to force the output flip-flop to the level corresponding
154  * to a match on trailing edge. The FLAG bit is not set.
155  *
156  * @param[in] Instance The eMIOS group id
157  * @param[in] Channel  The Channel in this eMIOS group
158  * @param[in] Enable   The Channel in Force Match Leading Edge or not
159  * @return void
160  */
161 void Emios_Pwm_Ip_ForceMatchTrailingEdge(uint8 Instance,
162                                          uint8 Channel,
163                                          boolean Enable);
164 
165 /**
166  * @brief Get Period value in PWM mode
167  *
168  * @param[in] Instance  The eMIOS group id
169  * @param[in] Channel   The Channel in this eMIOS group
170  * @param[out] RetPeriod A pointer to return period value
171  * @return Emios_Pwm_Ip_PeriodType Value of period
172  */
173 Emios_Pwm_Ip_PeriodType Emios_Pwm_Ip_GetPeriod(uint8 Instance,
174                               uint8 Channel);
175 
176 /**
177  * @brief Set new Period value in PWM mode
178  *
179  * @param[in] Instance    The eMIOS group id
180  * @param[in] Channel     The Channel in this eMIOS group
181  * @param[in] NewPeriod   New Period value
182  * @return void
183  */
184 void Emios_Pwm_Ip_SetPeriod(uint8 Instance,
185                             uint8 Channel,
186                             Emios_Pwm_Ip_PeriodType NewPeriod);
187 
188 /**
189  * @brief Get Duty Cycle value in PWM mode
190  *
191  * @param[in] Instance  The eMIOS group id
192  * @param[in] Channel   The Channel in this eMIOS group
193  * @return Emios_Pwm_Ip_DutyType Value of duty cycle
194  */
195 Emios_Pwm_Ip_DutyType Emios_Pwm_Ip_GetDutyCycle(uint8 Instance,
196                                  uint8 Channel);
197 
198 /**
199  * @brief Set new Duty Cycle value in PWM mode
200  *
201  * @param[in] Instance       The eMIOS group id
202  * @param[in] Channel        The Channel in this eMIOS group
203  * @param[in] NewDutyCycle   New duty cycle value
204  * @return operation status
205  *        - EMIOS_PWM_IP_STATUS_SUCCESS      :  Operation was successful.
206  *        - EMIOS_PWM_IP_STATUS_ERROR        :  Operation failed, invalid input value.
207  */
208 Emios_Pwm_Ip_StatusType Emios_Pwm_Ip_SetDutyCycle(uint8 Instance,
209                                                   uint8 Channel,
210                                                   Emios_Pwm_Ip_DutyType NewDutyCycle);
211 
212 /**
213  * @brief Get Leading Edge Placement value in PWM mode
214  *
215  * @param[in] Instance   The eMIOS group id
216  * @param[in] Channel    The Channel in this eMIOS group
217  * @return Emios_Pwm_Ip_PeriodType Value of leading edge placement in counter bus time base
218  */
219 Emios_Pwm_Ip_PeriodType Emios_Pwm_Ip_GetPhaseShift(uint8 Instance,
220                                   uint8 Channel);
221 
222 /**
223  * @brief Set new Leading edge placement value in PWM mode
224  *
225  * @param[in] Instance     The eMIOS group id
226  * @param[in] Channel      The Channel in this eMIOS group
227  * @param[in] PhaseShift   New Phase Shift value
228  * @return void
229  */
230 Emios_Pwm_Ip_StatusType Emios_Pwm_Ip_SetPhaseShift(uint8 Instance,
231                                                    uint8 Channel,
232                                                    Emios_Pwm_Ip_DutyType PhaseShift);
233 
234 /**
235  * @brief Get dead time value in PWM mode
236  *
237  * @param[in] Instance   The eMIOS group id
238  * @param[in] Channel    The Channel in this eMIOS group
239  * @return Emios_Pwm_Ip_PeriodType Value of Dead Time
240  */
241 Emios_Pwm_Ip_PeriodType Emios_Pwm_Ip_GetDeadTime(uint8 Instance,
242                                 uint8 Channel);
243 
244 /**
245  * @brief Set new dead time value in PWM mode
246  *
247  * @param[in] Instance       The eMIOS group id
248  * @param[in] Channel        The Channel in this eMIOS group
249  * @param[in] NewDeadTime    New Dead Time value
250  * @return void
251  */
252 void Emios_Pwm_Ip_SetDeadTime(uint8 Instance,
253                               uint8 Channel,
254                               Emios_Pwm_Ip_PeriodType NewDeadTime);
255 
256 /**
257  * @brief Get Trigger Placement value in PWM mode
258  *
259  * @param[in] Instance The eMIOS group id
260  * @param[in] Channel  The Channel in this eMIOS group
261  * @return uint32 Value of Trigger Placement
262  */
263 uint32 Emios_Pwm_Ip_GetTriggerPlacement(uint8 Instance,
264                                         uint8 Channel);
265 
266 /**
267  * @brief Set new Trigger Placement value in PWM mode
268  *
269  * @param[in] Instance             The eMIOS group id
270  * @param[in] Channel              The Channel in this eMIOS group
271  * @param[in] NewTriggerPlacement  New Trigger Placement value
272  * @return void
273  */
274 void Emios_Pwm_Ip_SetTriggerPlacement(uint8  Instance,
275                                       uint8  Channel,
276                                       Emios_Pwm_Ip_PeriodType NewTriggerPlacement);
277 
278 /**
279  * @brief Set a Channel enters freeze state, should be setting
280  * EMIOS_AllowEnterDebugMode first.
281  *
282  * @param[in] Instance   The eMIOS group id
283  * @param[in] Channel    The Channel in this eMIOS group
284  * @return operation status
285  *        - EMIOS_PWM_IP_STATUS_SUCCESS                 :  Operation was successful.
286  *        - EMIOS_PWM_IP_STATUS_ERROR                   :  Operation failed, invalid input value.
287  *        - EMIOS_PWM_IP_STATUS_ENABLE_GLOBAL_FRZ       :  Need call EMIOS_AllowEnterDebugMode first.
288  */
289 Emios_Pwm_Ip_StatusType Emios_Pwm_Ip_ChannelEnterDebugMode(uint8 Instance,
290                                                            uint8 Channel);
291 
292 /**
293  * @brief Release a Channel from freeze state
294  *
295  * @param[in] Instance  The eMIOS group id
296  * @param[in] Channel   The Channel in this eMIOS group
297  * @return void
298  */
299 void Emios_Pwm_Ip_ChannelStopDebugMode(uint8 Instance,
300                                        uint8 Channel);
301 
302 /**
303  * @brief Get the Unified Channel FLAG event generated. Interrupt or DMA request.
304  *
305  * @param[in] Instance   The eMIOS group id
306  * @param[in] Channel    The Channel in this eMIOS group
307  * @return The FLAG event response type
308  */
309 Emios_Pwm_Ip_InterruptType Emios_Pwm_Ip_GetFlagRequest(uint8 Instance,
310                                                        uint8 Channel);
311 
312 /**
313  * @brief Allow the Unified Channel FLAG bit to generate an interrupt signal or
314  * a DMA request signal
315  *
316  * @param[in] Instance  The eMIOS group id
317  * @param[in] Channel   The Channel in this eMIOS group
318  * @param[in] Event     The FLAG event response type
319  * @return void
320  */
321 void Emios_Pwm_Ip_SetFlagRequest(uint8 Instance,
322                                  uint8 Channel,
323                                  Emios_Pwm_Ip_InterruptType Event);
324 
325 /**
326  * @brief Get the Unified Channel output pin logic level
327  *
328  * @param[in] Instance  The eMIOS group id
329  * @param[in] Channel   The Channel in this eMIOS group
330  * @return The Emios Channel output pin state HIGH/LOW
331  */
332 Emios_Pwm_Ip_OutputStateType Emios_Pwm_Ip_GetOutputState(uint8 Instance,
333                                                          uint8 Channel);
334 
335 /**
336  * @brief Set the state of output pin
337  *
338  * @param[in] Instance     The eMIOS group id
339  * @param[in] Channel      The Channel in this eMIOS group
340  * @param[in] OutputState  The state of output pin
341  * @return    void
342  */
343 void Emios_Pwm_Ip_SetOutputState(uint8 Instance,
344                                  uint8 Channel,
345                                  Emios_Pwm_Ip_OutputStateType OutputState);
346 
347 /**
348  * @brief Set the polarity and mode for current Channel as normal
349  *
350  * @param[in] Instance    The eMIOS group id
351  * @param[in] Channel     The Channel in this eMIOS group
352  * @param[in] DutyPercent The range of duty cycle value :0x00(0%) ->0x8000(100%)
353  * @param[in] Polarity    The polarity of Channel
354  * @param[in] Mode        Mode of Channel
355  * @return    void
356  */
357 void Emios_Pwm_Ip_SetOutputToNormal(uint8 Instance,
358                                     uint8 Channel,
359                                     uint16 DutyPercent,
360                                     Emios_Pwm_Ip_PolarityType Polarity,
361                                     Emios_Pwm_Ip_PwmModeType  Mode);
362 
363 /**
364  * @brief  Get mode of operation of the Unified Channel
365  *
366  * @param[in] Instance    The eMIOS group id
367  * @param[in] Channel     The Channel in this eMIOS group
368  * @return    Emios_Pwm_Ip_PwmModeType
369  */
370 Emios_Pwm_Ip_PwmModeType Emios_Pwm_Ip_GetChannelMode(uint8 Instance,
371                                                      uint8 Channel);
372 
373 /**
374  * @brief  Get master bus Channel
375  *
376  * @param[in] Instance    The eMIOS group id
377  * @param[in] Channel     The Channel in this eMIOS group
378  * @return    Emios_Pwm_Ip_PwmModeType
379  */
380 uint8 Emios_Pwm_Ip_GetMasterBusChannel(uint8 Instance,
381                                        uint8 Channel);
382 
383 /**
384  * @brief    Set Prescaler Enable bit.
385  *
386  * @param[in] Instance    The eMIOS group id
387  * @param[in] Channel     The Channel in this eMIOS group
388  * @param[in] Value       The value to set
389  *                        - 0     Prescaler disabled (no clock)
390  *                        - 1     Prescaler enabled
391  * @return  void
392  */
393 void Emios_Pwm_Ip_SetPreEnableClock(uint8 Instance,
394                                     uint8 Channel,
395                                     boolean Value);
396 
397 /**
398  * @brief    Set Bus Select bits.
399  *
400  * @param[in] Instance    The eMIOS group id
401  * @param[in] Channel     The Channel in this eMIOS group
402  * @param[in] Value       The value to set
403  * @return  void
404  */
405 void Emios_Pwm_Ip_SetBusSelected(uint8 Instance,
406                                  uint8 Channel,
407                                  Emios_Pwm_Ip_CounterBusSourceType Value);
408 
409 /**
410  * @brief     This function set the value of the prescaler on eMios channels
411  *
412  * @param[in] Instance    The eMIOS group id
413  * @param[in] Channel     The Channel in this eMIOS group
414  * @param[in] Value       The value to set
415  * @return    void
416  */
417 void Emios_Pwm_Ip_SetClockPs(uint8 Instance,
418                              uint8 Channel,
419                              Emios_Pwm_Ip_InternalClkPsType Value);
420 
421 /**
422  * @brief The function shall Enable the output update for the corresponding Channel.
423  *
424  * @param[in] Instance        Instance of EMIOS used.
425  * @param[in] ChannelMask     EMIOS hardware mask Channel used.
426  */
427 void Emios_Pwm_Ip_ComparatorTransferEnable(uint8 Instance, uint32 ChannelMask);
428 
429 /**
430  * @brief The function shall disable the output update for the corresponding Channel.
431  *
432  * @param[in] Instance        Instance of EMIOS used.
433  * @param[in] ChannelMask     EMIOS hardware mask Channel used.
434  */
435 void Emios_Pwm_Ip_ComparatorTransferDisable(uint8 Instance, uint32 ChannelMask);
436 
437 /**
438 * @brief        This function updates the duty cycle and-or period for the specified PWM Channel.
439 *               The value written does not take effect until calling SyncUpdate API.
440 *
441 * @param        Instance          eMIOS hardware module index
442 *
443 * @return       void
444 *
445 */
446 void Emios_Pwm_Ip_SyncUpdate(uint8 Instance);
447 
448 /**
449 * @brief        This function updates the value of UCRegA. It may be used to change duty cycle or phase shift
450 *               with minimum overhead.
451 *
452 * @param        Instance          eMIOS hardware module index
453 * @param        Channel           The Channel in this eMIOS group
454 * @param        Value             The value to set
455 *
456 * @return       void
457 *
458 */
459 void Emios_Pwm_Ip_UpdateUCRegA(uint8 Instance, uint8 Channel, Emios_Pwm_Ip_PeriodType Value);
460 
461 /**
462 * @brief        This function updates the value of UCRegB. It may be used to change duty cycle, phase shift or
463 *               inserted dead time buffer with minimum overhead.
464 *
465 * @param        Instance          eMIOS hardware module index
466 * @param        Channel           The Channel in this eMIOS group
467 * @param        Value             The value to set
468 *
469 * @return       void
470 *
471 */
472 void Emios_Pwm_Ip_UpdateUCRegB(uint8 Instance, uint8 Channel, Emios_Pwm_Ip_PeriodType Value);
473 
474 
475 #define PWM_STOP_SEC_CODE
476 #include "Pwm_MemMap.h"
477 
478 
479 #ifdef __cplusplus
480 }
481 #endif
482 
483 /** @} */
484 
485 #endif /* EMIOS_PWM_IP_H */
486