MCUSW
Pwm.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (C) 2024 Texas Instruments Incorporated
4 *
5 * All rights reserved not granted herein.
6 *
7 * Limited License.
8 *
9 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10 * license under copyrights and patents it now or hereafter owns or controls to make,
11 * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12 * terms herein. With respect to the foregoing patent license, such license is granted
13 * solely to the extent that any such patent is necessary to Utilize the software alone.
14 * The patent license shall not apply to any combinations which include this software,
15 * other than combinations with devices manufactured by or for TI ("TI Devices").
16 * No hardware patent is licensed hereunder.
17 *
18 * Redistributions must preserve existing copyright notices and reproduce this license
19 * (including the above copyright notice and the disclaimer and (if applicable) source
20 * code license limitations below) in the documentation and/or other materials provided
21 * with the distribution
22 *
23 * Redistribution and use in binary form, without modification, are permitted provided
24 * that the following conditions are met:
25 *
26 * * No reverse engineering, decompilation, or disassembly of this software is
27 * permitted with respect to any software provided in binary form.
28 *
29 * * any redistribution and use are licensed by TI for use only with TI Devices.
30 *
31 * * Nothing shall obligate TI to provide you with source code for the software
32 * licensed and provided to you in object code.
33 *
34 * If software source code is provided to you, modification and redistribution of the
35 * source code are permitted provided that the following conditions are met:
36 *
37 * * any redistribution and use of the source code, including any resulting derivative
38 * works, are licensed by TI for use only with TI Devices.
39 *
40 * * any redistribution and use of any object code compiled from the source code
41 * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42 *
43 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44 *
45 * may be used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * DISCLAIMER.
49 *
50 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 */
62 
84  /*
85  * Below are the global requirements which are met by this PWM
86  * driver which can't be mapped to a particular source ID
87  */
88  /*
89  * Design: MCAL-6809,MCAL-7617,MCAL-6772,MCAL-7638,MCAL-6808,MCAL-7571,MCAL-6845,MCAL-7625,MCAL-6826,MCAl-7536,MCAL-6820,MCAL-7570,MCAL-6778,MCAL-7613
90  */
91 
92 /*
93  * Below are the PWM module's environment requirements which can't be mapped
94  * to this driver
95  */
96  /*
97  * Design: MCAL-6806,MCAL-7610,MCAL-6834,MCAL-7565,MCAL-6837,MCAL-7561
98  */
99 #ifndef PWM_H
100 #define PWM_H
101 
102 /* ========================================================================== */
103 /* Include Files */
104 /* ========================================================================== */
105 /*
106  * Design: MCAL-6888,MCAL-7551,MCAL-6824,MCAL-7572
107  */
108 #include "Std_Types.h"
109 #include "Pwm_Cfg.h"
110 
111 #ifdef __cplusplus
112 extern "C"
113 {
114 #endif
115 
116 /* ========================================================================== */
117 /* Macros & Typedefs */
118 /* ========================================================================== */
126 #define PWM_SW_MAJOR_VERSION (11U)
127 
128 #define PWM_SW_MINOR_VERSION (1U)
129 
130 #define PWM_SW_PATCH_VERSION (0U)
131 /* @} */
132 
133 
134 
142 #define PWM_AR_RELEASE_MAJOR_VERSION (4U)
143 
144 #define PWM_AR_RELEASE_MINOR_VERSION (3U)
145 
146 #define PWM_AR_RELEASE_REVISION_VERSION (1U)
147 /* @} */
148 
154 #define PWM_VENDOR_ID ((uint16) 44U)
155 
156 #define PWM_MODULE_ID ((uint16) 121U)
157 
165 /*
166  * Design: MCAL-6847,MCAL-7527
167  */
168 
170 #ifndef PWM_E_INIT_FAILED
171 #define PWM_E_INIT_FAILED ((uint8)(0x10U))
172 #endif
173 
174 /*
175  * Design: MCAL-6833,MCAL-7611
176  */
177 
179 #ifndef PWM_E_UNINIT
180 #define PWM_E_UNINIT ((uint8)(0x11U))
181 #endif
182 
183 /*
184 * Design: MCAL-6872,MCAL-7523
185 */
186 
187 
189 #ifndef PWM_E_PARAM_CHANNEL
190 #define PWM_E_PARAM_CHANNEL ((uint8)(0x12U))
191 #endif
192 
193 /*
194  * Design: MCAL-6802,MCAL-7616
195  */
196 
198 #ifndef PWM_E_PERIOD_UNCHANGEABLE
199 #define PWM_E_PERIOD_UNCHANGEABLE ((uint8)(0x13U))
200 #endif
201 
202 /*
203  * Design: MCAL-6856,MCAL-7574
204  */
206 #ifndef PWM_E_ALREADY_INITIALIZED
207 #define PWM_E_ALREADY_INITIALIZED ((uint8)(0x14U))
208 #endif
209 
210 /*
211  * Design: MCAL-6847,MCAL-7527
212  */
214 #ifndef PWM_E_PARAM_POINTER
215 #define PWM_E_PARAM_POINTER ((uint8)(0x15U))
216 #endif
217 
218 /*
219  * Design: MCAL-6879,MCAL-7529
220  */
223 #ifndef PWM_E_NOT_DISENGAGED
224 #define PWM_E_NOT_DISENGAGED ((uint8)(0x16U))
225 #endif
226 /* @} */
227 
236 #define PWM_SID_INIT ((uint8)(0x0U))
237 
238 #define PWM_SID_DEINIT ((uint8)(0x1U))
239 
240 #define PWM_SID_SET_DUTY_CYCLE ((uint8)(0x2U))
241 
242 #define PWM_SID_SET_PERIOD_AND_DUTY ((uint8)(0x3U))
243 
244 #define PWM_SID_SET_OUTPUT_TO_IDLE ((uint8)(0x4U))
245 
246 #define PWM_SID_GET_OUTPUT_STATE ((uint8)(0x5U))
247 
248 #define PWM_SID_DISABLE_NOTIFICATION ((uint8)(0x6U))
249 
250 #define PWM_SID_ENABLE_NOTIFICATION ((uint8)(0x7U))
251 
252 #define PWM_SID_GET_VERSION_INFO ((uint8)(0x8U))
253 
254 #define PWM_SID_REGISTER_READBACK ((uint8)(0xDU))
255 /* @} */
256 
264 #define PWM_STATUS_UNINIT ((uint8)(0U))
265 
266 #define PWM_STATUS_INIT ((uint8)(1U))
267 
268 /* @} */
269 
270  /*
271  * Design: MCAL-6801,MCAL-7544,MCAL-6880,MCAL-7547
272  */
273 /* Design MCAL-6880,MCAL-7547 states that PWM module shall comply below duty cycle scheme
274  * - 0x0000 means 0%.
275  * - 0x8000 means 100%.
276  * 0x8000 gives the highest resolution while allowing 100% duty cycle
277  * to be represented with a 16 bit value
278  */
280 #define PWM_DUTY_0_PERCENT (0x0U)
281 
282 #define PWM_DUTY_100_PERCENT (0x8000U)
283 
284 #define PWM_DUTY_50_PERCENT (0x4000U)
285 
286 
287 
288 
289 /* ========================================================================== */
290 /* Structures and Enums */
291 /* ========================================================================== */
292 
297 /*
298  * Design: MCAL-6775,MCAL-7543
299  */
301 typedef enum
302 {
303  PWM_LOW = 0U,
305  PWM_HIGH
308 
309 /*
310  * Design: MCAL-30321
311  */
312 #ifdef PWM_USE_EPWM
313 
314 typedef enum
315 {
316  UPDOWN_COUNTER = 0U,
318  UP_COUNTER
320 } Pwm_CounterModeType;
321 #endif
322  /*
323  * Design: MCAL-6836,MCAL-7576
324  */
326 typedef enum
327 {
328  PWM_RISING_EDGE = 1U,
330  PWM_FALLING_EDGE = 2U,
332  PWM_BOTH_EDGES = 3U
335 
336 /*
337  * Design: MCAL-6763,MCAL-7587
338  */
340 typedef uint32 Pwm_PeriodType;
341 
342 /*
343  * Design: MCAL-6883,MCAL-7505
344  */
346 typedef uint32 Pwm_ChannelType;
347 
349 typedef uint32 Pwm_FrequencyType;
350 
351 /*
352  * Design: MCAL-6796,MCAL-7589,MCAL-7597
353  */
359 typedef enum
360 {
361  PWM_FIXED_PERIOD = 0U,
368 
370 typedef enum Pwm_epwmOutputCh
371 {
372  EPWM_OUTPUT_CH_A = 0U,
374  EPWM_OUTPUT_CH_B = 1U,
379 
381 typedef void (*Pwm_NotifyFuncType)(void);
383 typedef struct
384 {
386 #ifdef PWM_USE_EPWM
387  uint32 outputCh;
389 #endif /* PWM_USE_EPWM*/
391 
393 typedef struct Pwm_ConfigType_PC_s
394 {
398 
399 
401 typedef struct
402 {
405  uint16 dutyCycle;
407  uint32 hwPeriod;
415  uint32 prescale;
417  #ifdef PWM_USE_EPWM
418  Pwm_CounterModeType CounterMode;
419  #endif
420 
431 #ifdef PWM_USE_EPWM
432  uint32 hsPrescale;
444  boolean enableHR;
446 #endif /*PWM_USE_EPWM*/
447 #if (PWM_NOTIFICATION_SUPPORTED == STD_ON)
450 #endif
452 
453 /*
454  * Design: MCAL-6885,MCAL-7533,MCAL-6799,MCAL-7535
455  */
457 typedef struct Pwm_ConfigType_s
458 {
462 
463 #if (STD_ON == PWM_REGISTER_READBACK_API)
464 
467 typedef struct
468 {
469 #ifdef PWM_USE_GPT
470  /*
471  * GPT related registers
472  */
473  uint32 pwmRev;
475  uint32 pwmTtgr;
477  uint32 pwmTimerSynCtrl;
479 #endif
480  /*
481  * EPWM related registers
482  */
483 #ifdef PWM_USE_EPWM
484  uint16 pwmTbCtl;
486  uint16 pwmTbPhs;
488  uint16 pwmTbCnt;
490  uint16 pwmAqCtlA;
492  uint16 pwmAqCtlB;
494  uint16 pwmDbCtl;
496  uint16 pwmTzSel;
498  uint16 pwmTzCtl;
500  uint16 pwmPcCtl;
502  uint16 pwmTbsts;
504  uint16 pwmTbprd;
506  uint16 pwmAqsfrc;
508  uint16 pwmAqcsfrc;
509  /* < Action Qualifier Continuous Software Force Register */
510  uint16 pwmDbred;
511  /* < Dead Band Generator Rising Edge Delay Count Register */
512  uint16 pwmDbfed;
513  /* < Dead Band Generator Falling Edge Delay Count Register */
514  uint16 pwmEtsel;
515  /* < Event Trigger Selection Registe */
516 
517 #endif
519 
520 
521 #endif /* #if (STD_ON == PWM_REGISTER_READBACK_API) */
522 
523 /* @} */
524 
525 /* ========================================================================== */
526 /* Function Declarations */
527 /* ========================================================================== */
528 
548 FUNC(void, PWM_CODE) Pwm_Init(
550 
551 #if (STD_ON == PWM_DEINIT_API)
552 
571 FUNC(void, PWM_CODE) Pwm_DeInit(void);
572 #endif
573 
574 #if (STD_ON == PWM_SET_DUTY_CYCLE_API)
575 
597 FUNC(void, PWM_CODE) Pwm_SetDutyCycle(
598  Pwm_ChannelType ChannelNumber, uint16 DutyCycle);
599 #endif
600 
601 #if (STD_ON == PWM_SET_PERIOD_AND_DUTY_API)
602 
625 FUNC(void, PWM_CODE) Pwm_SetPeriodAndDuty(
627 #endif
628 
629 #if (STD_ON == PWM_SET_OUTPUT_TO_IDLE_API)
630 
649 FUNC(void, PWM_CODE) Pwm_SetOutputToIdle(Pwm_ChannelType ChannelNumber);
650 #endif
651 
652 #if (STD_ON == PWM_GET_OUTPUT_STATE_API)
653  /* Function not implmented due to hardware limitation
654  Dummy Function*/
655 FUNC(Pwm_OutputStateType, PWM_CODE) Pwm_GetOutputState(
656  Pwm_ChannelType ChannelNumber);
657 #endif
658 
659 #if (STD_ON == PWM_NOTIFICATION_SUPPORTED)
660 
679 FUNC(void, PWM_CODE) Pwm_DisableNotification(Pwm_ChannelType ChannelNumber);
680 #endif
681 
682 #if (STD_ON == PWM_NOTIFICATION_SUPPORTED)
683 
704 FUNC(void, PWM_CODE) Pwm_EnableNotification(
706 #endif
707 
708 #if (STD_ON == PWM_VERSION_INFO_API)
709 
728 FUNC(void, PWM_CODE) Pwm_GetVersionInfo(
729  P2VAR(Std_VersionInfoType, AUTOMATIC, PWM_APPL_DATA) versioninfo);
730 #endif
731 
732 #if(STD_ON == PWM_REGISTER_READBACK_API)
733 
755 Std_ReturnType Pwm_RegisterReadback(
757 #endif
758 
759 #ifdef __cplusplus
760 }
761 #endif
762 
763 #endif /* #ifndef PWM_H_ */
764 
765 /* @} */
PWM_LOW
@ PWM_LOW
Definition: Pwm.h:303
EPWM_OUTPUT_CH_B
@ EPWM_OUTPUT_CH_B
Definition: Pwm.h:374
PWM_RISING_EDGE
@ PWM_RISING_EDGE
Definition: Pwm.h:328
versioninfo
PWM_APPL_DATA versioninfo
Definition: Pwm.h:729
PWM_HIGH
@ PWM_HIGH
Definition: Pwm.h:305
PWM_FALLING_EDGE
@ PWM_FALLING_EDGE
Definition: Pwm.h:330
Pwm_OutputStateType
Pwm_OutputStateType
Possible output states of a PWM channel.
Definition: Pwm.h:302
Pwm_ChannelConfigType::idleState
Pwm_OutputStateType idleState
Definition: Pwm.h:411
Pwm_epwmOutputCh_t
Pwm_epwmOutputCh_t
EPWM outputs in a single epwm channel.
Definition: Pwm.h:371
PWM_FIXED_PERIOD
@ PWM_FIXED_PERIOD
Definition: Pwm.h:361
Pwm_ChannelClassType
Pwm_ChannelClassType
Period type for pwm channels. Fixed periods prohibit changes to the period length with Pwm_SetPeriod(...
Definition: Pwm.h:360
Pwm_ChannelConfigType::polarity
Pwm_OutputStateType polarity
Definition: Pwm.h:409
Notification
Pwm_EdgeNotificationType Notification
Definition: Pwm.h:705
DutyCycle
uint16 DutyCycle
Definition: Pwm.h:598
Pwm_EdgeNotificationType
Pwm_EdgeNotificationType
Possible edge notification
Definition: Pwm.h:327
Pwm_RegisterReadback
Std_ReturnType Pwm_RegisterReadback(Pwm_ChannelType ChannelNumber, Pwm_RegisterReadbackType *RegRbPtr)
This function reads the important registers of the hardware unit and returns the value in the structu...
FUNC
FUNC(void, PWM_CODE) Pwm_Init(P2CONST(Pwm_ConfigType
Service for PWM initialization.
Pwm_ChannelConfigType::hwPeriod
uint32 hwPeriod
Definition: Pwm.h:407
Pwm_NotifyFuncType
void(* Pwm_NotifyFuncType)(void)
Notification callback function pointer
Definition: Pwm.h:381
Pwm_FrequencyType
uint32 Pwm_FrequencyType
typedef of frequency value (Frequency in Hz)
Definition: Pwm.h:349
Pwm_Cfg.h
This file contains generated pre compile configuration file for PWM MCAL driver.
RegRbPtr
SPI_APPL_DATA RegRbPtr
Definition: Fls.h:806
Period
Pwm_PeriodType Period
Definition: Pwm.h:626
CfgPtr
PWM_PBCFG CfgPtr
Definition: Pwm.h:549
P2CONST
P2CONST(void, AUTOMATIC, DIO_CONST) DioConfig_WKUP_GPIO0_B01_ChannelGroupRef[1]
Reference to channel group structure for WKUP_GPIO0_B01 created at config time.
PWM_NUM_CHANNELS
#define PWM_NUM_CHANNELS
Number of configured channels.
Definition: Pwm_Cfg.h:152
PWM_FIXED_PERIOD_SHIFTED
@ PWM_FIXED_PERIOD_SHIFTED
Definition: Pwm.h:363
Pwm_ChannelConfigType::notificationHandler
Pwm_NotifyFuncType notificationHandler
Definition: Pwm.h:448
Pwm_ChannelConfigType::instanceClkHz
uint32 instanceClkHz
Definition: Pwm.h:403
Pwm_ChannelConfigType::prescale
uint32 prescale
Definition: Pwm.h:415
Pwm_ChannelConfigType::channelClass
Pwm_ChannelClassType channelClass
Definition: Pwm.h:413
Pwm_PeriodType
uint32 Pwm_PeriodType
typedef of period value
Definition: Pwm.h:340
EPWM_OUTPUT_CH_A
@ EPWM_OUTPUT_CH_A
Definition: Pwm.h:372
Pwm_ChannelConfigType
Pwm channel configuration.
Definition: Pwm.h:402
PWM_VARIABLE_PERIOD
@ PWM_VARIABLE_PERIOD
Definition: Pwm.h:365
Pwm_ChannelConfigType::dutyCycle
uint16 dutyCycle
Definition: Pwm.h:405
Pwm_ConfigType_PC
Pwm configuration structure.
Definition: Pwm.h:394
Pwm_ChannelType
uint32 Pwm_ChannelType
PWM Channel type.
Definition: Pwm.h:346
PWM_BOTH_EDGES
@ PWM_BOTH_EDGES
Definition: Pwm.h:332
Pwm_ConfigType
Pwm configuration structure.
Definition: Pwm.h:458
AUTOMATIC
AUTOMATIC
Definition: Pwm.h:549
Pwm_ChannelConfigType_PC::channelId
Pwm_ChannelType channelId
Definition: Pwm.h:385
Pwm_ChannelConfigType_PC
Pwm channel configuration.
Definition: Pwm.h:384
P2VAR
P2VAR(Eth_ModeType, AUTOMATIC, ETH_APPL_DATA) CtrlModePtr)
Pwm_RegisterReadbackType
PWM register readback structure.
Definition: Pwm.h:468
EPWM_OUTPUT_CH_BOTH_A_AND_B
@ EPWM_OUTPUT_CH_BOTH_A_AND_B
Definition: Pwm.h:376