MCUSW
Pwm.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) 2019 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 /* DesignId : DES_PWM_001*/
89 /* Requirements : MCAL-3502, MCAL-3503, MCAL-3509, MCAL-3511,
90  * MCAL-3535, MCAL-3631, MCAL-3505, MCAL-3507,
91  * MCAL-981, MCAL-4475
92  */
93 
94 /*
95  * Below are the PWM module's environment requirements which can't be mapped
96  * to this driver
97  */
98 /* DesignId : DES_PWM_001, DES_PWM_014*/
99  /*
100  * Requirements : MCAL-3554, MCAL-3552, MCAL-3510
101  */
102 #ifndef PWM_H
103 #define PWM_H
104 
105 /* ========================================================================== */
106 /* Include Files */
107 /* ========================================================================== */
108 /* DesignId : DES_PWM_006 */
109 /* Requirements :MCAL-3504 , MCAL-3506*/
110 #include "Pwm_Cfg.h"
111 #include "Std_Types.h"
112 
113 #ifdef __cplusplus
114 extern "C"
115 {
116 #endif
117 
118 /* ========================================================================== */
119 /* Macros & Typedefs */
120 /* ========================================================================== */
128 #define PWM_SW_MAJOR_VERSION (1U)
129 
130 #define PWM_SW_MINOR_VERSION (2U)
131 
132 #define PWM_SW_PATCH_VERSION (1U)
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 
158 #define PWM_INSTANCE_ID ((uint8) 0U)
159 /* @} */
160 
161 
168 /* DesignId : DES_PWM_010 */
169 /* Requirements : MCAL-4480 */
170 
172 #ifndef PWM_E_INIT_FAILED
173 #define PWM_E_INIT_FAILED ((uint8)(0x10U))
174 #endif
175 
176 /* DesignId : DES_PWM_010 */
177 /* Requirements : MCAL-3524 */
178 
180 #ifndef PWM_E_UNINIT
181 #define PWM_E_UNINIT ((uint8)(0x11U))
182 #endif
183 
184 /* DesignId : DES_PWM_010 */
185 /* Requirements : MCAL-3525 */
186 
188 #ifndef PWM_E_PARAM_CHANNEL
189 #define PWM_E_PARAM_CHANNEL ((uint8)(0x12U))
190 #endif
191 
192 /* DesignId : DES_PWM_010 */
193 /* Requirements : MCAL-3526 */
194 
196 #ifndef PWM_E_PERIOD_UNCHANGEABLE
197 #define PWM_E_PERIOD_UNCHANGEABLE ((uint8)(0x13U))
198 #endif
199 
200 /* DesignId : DES_PWM_010 */
201 /* Requirements : MCAL-3527 */
203 #ifndef PWM_E_ALREADY_INITIALIZED
204 #define PWM_E_ALREADY_INITIALIZED ((uint8)(0x14U))
205 #endif
206 
207 /* DesignId : DES_PWM_010 */
208 /* Requirements : MCAL-4480 */
210 #ifndef PWM_E_PARAM_POINTER
211 #define PWM_E_PARAM_POINTER ((uint8)(0x15U))
212 #endif
213 
214 /* DesignId : DES_PWM_010 */
215 /* Requirements : MCAL-4481 */
218 #ifndef PWM_E_NOT_DISENGAGED
219 #define PWM_E_NOT_DISENGAGED ((uint8)(0x16U))
220 #endif
221 /* @} */
222 
231 #define PWM_SID_INIT ((uint8)(0x0U))
232 
233 #define PWM_SID_DEINIT ((uint8)(0x1U))
234 
235 #define PWM_SID_SET_DUTY_CYCLE ((uint8)(0x2U))
236 
237 #define PWM_SID_SET_PERIOD_AND_DUTY ((uint8)(0x3U))
238 
239 #define PWM_SID_SET_OUTPUT_TO_IDLE ((uint8)(0x4U))
240 
241 #define PWM_SID_GET_OUTPUT_STATE ((uint8)(0x5U))
242 
243 #define PWM_SID_DISABLE_NOTIFICATION ((uint8)(0x6U))
244 
245 #define PWM_SID_ENABLE_NOTIFICATION ((uint8)(0x7U))
246 
247 #define PWM_SID_GET_VERSION_INFO ((uint8)(0x8U))
248 
249 #define PWM_SID_REGISTER_READBACK ((uint8)(0xDU))
250 /* @} */
251 
259 #define PWM_STATUS_UNINIT ((uint8)(0U))
260 
261 #define PWM_STATUS_INIT ((uint8)(1U))
262 
263 /* @} */
264 
265 /* DesignId : DES_PWM_016 */
266 /* Requirements : MCAL-3533, MCAL-3534
267  */
268 /* Req MCAL-3534 states that PWM module shall comply below duty cycle scheme
269  * - 0x0000 means 0%.
270  * - 0x8000 means 100%.
271  * 0x8000 gives the highest resolution while allowing 100% duty cycle
272  * to be represented with a 16 bit value
273  */
275 #define PWM_DUTY_0_PERCENT (0x0U)
276 
277 #define PWM_DUTY_100_PERCENT (0x8000U)
278 
279 #define PWM_DUTY_50_PERCENT (0x4000U)
280 
281 #if defined (SOC_AM65XX)
282 
283 #define PWM_MAX_NUM_CHANNELS (16U)
284 #endif /* AM65XX */
285 
286 #if defined (SOC_J721E)
287 #define PWM_MAX_NUM_CHANNELS (30U)
288 #endif /* SOC_J721E */
289 /*
290  * PWM channels available for user
291  */
293 #define PWM_CHANNEL1 (0U)
294 
295 #define PWM_CHANNEL2 (1U)
296 
297 #define PWM_CHANNEL3 (2U)
298 
299 #define PWM_CHANNEL4 (3U)
300 
301 #define PWM_CHANNEL5 (4U)
302 
303 #define PWM_CHANNEL6 (5U)
304 
305 #define PWM_CHANNEL7 (6U)
306 
307 #define PWM_CHANNEL8 (7U)
308 
309 #define PWM_CHANNEL9 (8U)
310 
311 #define PWM_CHANNEL10 (9U)
312 
313 #define PWM_CHANNEL11 (10U)
314 
315 #define PWM_CHANNEL12 (11U)
316 
317 #define PWM_CHANNEL13 (12U)
318 
319 #define PWM_CHANNEL14 (13U)
320 
321 #define PWM_CHANNEL15 (14U)
322 
323 #define PWM_CHANNEL16 (15U)
324 
325 #if defined (SOC_J721E)
326 
327 #define PWM_CHANNEL17 (16U)
328 
329 #define PWM_CHANNEL18 (17U)
330 
331 #define PWM_CHANNEL19 (18U)
332 
333 #define PWM_CHANNEL20 (19U)
334 
335 #define PWM_CHANNEL21 (20U)
336 
337 #define PWM_CHANNEL22 (21U)
338 
339 #define PWM_CHANNEL23 (22U)
340 
341 #define PWM_CHANNEL24 (23U)
342 
343 #define PWM_CHANNEL25 (24U)
344 
345 #define PWM_CHANNEL26 (25U)
346 
347 #define PWM_CHANNEL27 (26U)
348 
349 #define PWM_CHANNEL28 (27U)
350 
351 #define PWM_CHANNEL29 (28U)
352 
353 #define PWM_CHANNEL30 (29U)
354 
355 #endif /* SOC_J721E */
356 
357 /* ========================================================================== */
358 /* Structures and Enums */
359 /* ========================================================================== */
360 
365 /* DesignId : DES_PWM_001 */
366 /* Requirements : MCAL-3538 */
368 typedef enum
369 {
370  PWM_LOW = 0U,
375 
376 /* DesignId : DES_PWM_001 */
377 /*
378  * Requirements :MCAL-3539
379  */
381 typedef enum
382 {
390 
391 /* DesignId : DES_PWM_001 */
392 /* Requirements :MCAL-3537 */
394 typedef uint32 Pwm_PeriodType;
395 
396 /* DesignId : DES_PWM_001 */
397 /* Requirements : MCAL-3536 */
399 typedef uint32 Pwm_ChannelType;
400 /* DesignId : DES_PWM_013 */
401 /* Requirements : MCAL-3540 */
407 typedef enum
408 {
416 
417 
418 
420 typedef void (*Pwm_NotifyFuncType)(void);
422 typedef struct
423 {
424  Pwm_ChannelType channelId;
426 
428 typedef struct Pwm_ConfigType_PC_s
429 {
433 
434 
436 typedef struct
437 {
440  uint16 dutyCycle;
442  uint32 hwPeriod;
444  Pwm_OutputStateType polarity;
446  Pwm_OutputStateType idleState;
448  Pwm_ChannelClassType channelClass;
450  uint32 prescale;
462 #if (PWM_NOTIFICATION_SUPPORTED == STD_ON)
465 #endif
467 
468 /* DesignId : DES_PWM_012 */
469 /* Requirements : MCAL-3542, MCAL-3541 */
471 typedef struct Pwm_ConfigType_s
472 {
476 
477 #if (STD_ON == PWM_REGISTER_READBACK_API)
478 
481 typedef struct
482 {
483  /*
484  * GPT related registers
485  */
486  uint32 pwmRev;
488  uint32 pwmTtgr;
493 
494 #endif /* #if (STD_ON == PWM_REGISTER_READBACK_API) */
495 
496 /* @} */
497 
498 /* ========================================================================== */
499 /* Function Declarations */
500 /* ========================================================================== */
501 
520 FUNC(void, PWM_CODE) Pwm_Init(P2CONST
521  (Pwm_ConfigType, AUTOMATIC, PWM_PBCFG) ConfigPtr);
522 
523 #if (STD_ON == PWM_DEINIT_API)
524 
542 FUNC(void, PWM_CODE) Pwm_DeInit(void);
543 #endif
544 
545 #if (STD_ON == PWM_SET_DUTY_CYCLE_API)
546 
567 FUNC(void, PWM_CODE) Pwm_SetDutyCycle(
568  Pwm_ChannelType ChannelNumber, uint16 DutyCycle);
569 #endif
570 
571 #if (STD_ON == PWM_SET_PERIOD_AND_DUTY_API)
572 
594 FUNC(void, PWM_CODE) Pwm_SetPeriodAndDuty(
595  Pwm_ChannelType ChannelNumber, Pwm_PeriodType Period, uint16 DutyCycle);
596 #endif
597 
598 #if (STD_ON == PWM_SET_OUTPUT_TO_IDLE_API)
599 
617 FUNC(void, PWM_CODE) Pwm_SetOutputToIdle(Pwm_ChannelType ChannelNumber);
618 #endif
619 
620 #if (STD_ON == PWM_NOTIFICATION_SUPPORTED)
621 
639 FUNC(void, PWM_CODE) Pwm_DisableNotification(Pwm_ChannelType ChannelNumber);
640 #endif
641 
642 #if (STD_ON == PWM_NOTIFICATION_SUPPORTED)
643 
663 FUNC(void, PWM_CODE) Pwm_EnableNotification(
664  Pwm_ChannelType ChannelNumber, Pwm_EdgeNotificationType Notification);
665 #endif
666 
685 FUNC(void, PWM_CODE) Pwm_GetVersionInfo(
686  P2VAR(Std_VersionInfoType, AUTOMATIC, PWM_APPL_DATA) versioninfo);
687 
688 #if(STD_ON == PWM_REGISTER_READBACK_API)
689 
711 Std_ReturnType Pwm_RegisterReadback(
712  Pwm_ChannelType ChannelNumber, Pwm_RegisterReadbackType *RegRbPtr);
713 #endif
714 
715 #ifdef __cplusplus
716 }
717 #endif
718 
719 #endif /* #ifndef PWM_H_ */
720 
721 /* @} */
Definition: Pwm.h:370
Definition: Pwm.h:387
Pwm_OutputStateType idleState
Definition: Pwm.h:446
uint32 pwmRev
Definition: Pwm.h:486
Pwm configuration structure.
Definition: Pwm.h:471
PWM register readback structure.
Definition: Pwm.h:481
Definition: Pwm.h:413
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...
void Pwm_Init(const Pwm_ConfigType *ConfigPtr)
Service for PWM initialization.
Definition: Pwm.h:385
Definition: Pwm.h:372
Pwm_ChannelClassType
Period type for pwm channels. Fixed periods prohibit changes to the period length with Pwm_SetPeriod(...
Definition: Pwm.h:407
Pwm_EdgeNotificationType
Possible edge notification.
Definition: Pwm.h:381
Pwm_ChannelClassType channelClass
Definition: Pwm.h:448
void Pwm_EnableNotification(Pwm_ChannelType ChannelNumber, Pwm_EdgeNotificationType Notification)
Service to enable the Edge Notification.
uint32 hwPeriod
Definition: Pwm.h:442
Pwm_OutputStateType
Possible output states of a PWM channel.
Definition: Pwm.h:368
void Pwm_DeInit(void)
Service for PWM de-initialization.
uint32 Pwm_PeriodType
typedef of period value
Definition: Pwm.h:394
void Pwm_SetPeriodAndDuty(Pwm_ChannelType ChannelNumber, Pwm_PeriodType Period, uint16 DutyCycle)
Service for setting Period and Duty Cycle.
uint32 pwmTimerSynCtrl
Definition: Pwm.h:490
uint32 Pwm_ChannelType
PWM Channel type.
Definition: Pwm.h:399
Pwm_ChannelType channelId
Definition: Pwm.h:424
uint32 pwmTtgr
Definition: Pwm.h:488
Definition: Pwm.h:411
void Pwm_SetOutputToIdle(Pwm_ChannelType ChannelNumber)
Service to set the output of a channel immediately to idle.
This file contains generated pre compile configuration file for PWM MCAL driver.
Pwm channel configuration.
Definition: Pwm.h:436
#define PWM_NUM_CHANNELS
Number of configured channels.
Definition: Pwm_Cfg.h:128
Pwm_OutputStateType polarity
Definition: Pwm.h:444
Definition: Pwm.h:409
Definition: Pwm.h:383
void Pwm_DisableNotification(Pwm_ChannelType ChannelNumber)
Service to disable the Edge Notification.
uint32 prescale
Definition: Pwm.h:450
void(* Pwm_NotifyFuncType)(void)
Notification callback function pointer.
Definition: Pwm.h:420
Pwm channel configuration.
Definition: Pwm.h:422
uint16 dutyCycle
Definition: Pwm.h:440
void Pwm_SetDutyCycle(Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
Service for setting Duty Cycle.
uint32 instanceClkHz
Definition: Pwm.h:438
void Pwm_GetVersionInfo(Std_VersionInfoType *versioninfo)
This service returns the version information of this module.
Pwm configuration structure.
Definition: Pwm.h:428
Pwm_NotifyFuncType notificationHandler
Definition: Pwm.h:463