MCUSW
PWM Driver API

Introduction

This component provides services for initialization and control of the PWM unit (pulse width modulation). The PWM module generates pulses with variable pulse width. It allows the selection of the duty cycle and the signal period time.

See also
PWM Configuration
Pwm Driver Interrupt Handlers

Sub Modules

 PWM Configuration
 
 Pwm Driver Interrupt Handlers
 

Functions

void Pwm_Init (const Pwm_ConfigType *CfgPtr)
 Service for PWM initialization. More...
 
void Pwm_DeInit (void)
 Service for PWM de-initialization. More...
 
void Pwm_SetDutyCycle (Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
 Service for setting Duty Cycle. More...
 
void Pwm_SetPeriodAndDuty (Pwm_ChannelType ChannelNumber, Pwm_PeriodType Period, uint16 DutyCycle)
 Service for setting Period and Duty Cycle. More...
 
void Pwm_SetOutputToIdle (Pwm_ChannelType ChannelNumber)
 Service to set the output of a channel immediately to idle. More...
 
Pwm_OutputStateType Pwm_GetOutputState (Pwm_ChannelType ChannelNumber)
 
void Pwm_DisableNotification (Pwm_ChannelType ChannelNumber)
 Service to disable the Edge Notification. More...
 
void Pwm_EnableNotification (Pwm_ChannelType ChannelNumber, Pwm_EdgeNotificationType Notification)
 Service to enable the Edge Notification. More...
 
void Pwm_GetVersionInfo (Std_VersionInfoType *versioninfo)
 This service returns the version information of this module. More...
 
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 structure. More...
 

Macros

#define PWM_DUTY_0_PERCENT   (0x0U)
 16bit value representing 0% of a period value More...
 
#define PWM_DUTY_100_PERCENT   (0x8000U)
 16 bit value representing 100% of a period value More...
 
#define PWM_DUTY_50_PERCENT   (0x4000U)
 16 bit value representing 50% of a period value More...
 

PWM Driver Module SW Version Info

Defines for PWM Driver version used for compatibility checks

#define PWM_SW_MAJOR_VERSION   (9U)
 Driver Implementation Major Version. More...
 
#define PWM_SW_MINOR_VERSION   (0U)
 Driver Implementation Minor Version. More...
 
#define PWM_SW_PATCH_VERSION   (1U)
 Driver Implementation Patch Version. More...
 

PWM Driver Module AUTOSAR Version Info

Defines for PWM Driver AUTOSAR version used for compatibility checks

#define PWM_AR_RELEASE_MAJOR_VERSION   (4U)
 AUTOSAR Major version specification implemented by PWM Driver. More...
 
#define PWM_AR_RELEASE_MINOR_VERSION   (3U)
 AUTOSAR Minor version specification implemented by PWM Driver. More...
 
#define PWM_AR_RELEASE_REVISION_VERSION   (1U)
 AUTOSAR Patch version specification implemented by PWM Driver. More...
 

PWM Driver ID Info

#define PWM_VENDOR_ID   ((uint16) 44U)
 Texas Instruments Vendor ID. More...
 
#define PWM_MODULE_ID   ((uint16) 121U)
 PWM Driver Module ID. More...
 

PWM Error Codes

PWM Driver Instance ID

Error codes returned by PWM functions

#define PWM_E_INIT_FAILED   ((uint8)(0x10U))
 PWM driver configuration parameter error. More...
 
#define PWM_E_UNINIT   ((uint8)(0x11U))
 PWM driver Not initialized error. More...
 
#define PWM_E_PARAM_CHANNEL   ((uint8)(0x12U))
 PWM driver Invalid param. More...
 
#define PWM_E_PERIOD_UNCHANGEABLE   ((uint8)(0x13U))
 PWM driver Fixed period channel. More...
 
#define PWM_E_ALREADY_INITIALIZED   ((uint8)(0x14U))
 PWM driver Already initialized. More...
 
#define PWM_E_PARAM_POINTER   ((uint8)(0x15U))
 PWM driver pointer paramter error. More...
 
#define PWM_E_NOT_DISENGAGED   ((uint8)(0x16U))
 RunTime Error: API Pwm_SetPowerState is called while the PWM module is still in use. More...
 

PWM Service Ids

The Service Id is one of the argument to Det_ReportError function and is used to identify the source of the error

#define PWM_SID_INIT   ((uint8)(0x0U))
 PWM driver service ID for Initialization API. More...
 
#define PWM_SID_DEINIT   ((uint8)(0x1U))
 PWM driver service ID for De-Initialization API. More...
 
#define PWM_SID_SET_DUTY_CYCLE   ((uint8)(0x2U))
 PWM driver service ID for set duty cycle API. More...
 
#define PWM_SID_SET_PERIOD_AND_DUTY   ((uint8)(0x3U))
 PWM driver service ID for set duty cycle and period API. More...
 
#define PWM_SID_SET_OUTPUT_TO_IDLE   ((uint8)(0x4U))
 PWM driver service ID for set output state to idle API. More...
 
#define PWM_SID_GET_OUTPUT_STATE   ((uint8)(0x5U))
 PWM driver service ID for get output state API. More...
 
#define PWM_SID_DISABLE_NOTIFICATION   ((uint8)(0x6U))
 PWM driver service ID for disable notification API. More...
 
#define PWM_SID_ENABLE_NOTIFICATION   ((uint8)(0x7U))
 PWM driver service ID for Enable notification API. More...
 
#define PWM_SID_GET_VERSION_INFO   ((uint8)(0x8U))
 PWM driver service ID for Get version info API. More...
 
#define PWM_SID_REGISTER_READBACK   ((uint8)(0xDU))
 PWM driver service ID for Critical register read back API. More...
 

PWM Driver State Values

The PWM Driver State Values

#define PWM_STATUS_UNINIT   ((uint8)(0U))
 PWM driver Status uninitialized. More...
 
#define PWM_STATUS_INIT   ((uint8)(1U))
 PWM driver Status Initialized. More...
 

Macro Definition Documentation

◆ PWM_SW_MAJOR_VERSION

#define PWM_SW_MAJOR_VERSION   (9U)

Driver Implementation Major Version.

◆ PWM_SW_MINOR_VERSION

#define PWM_SW_MINOR_VERSION   (0U)

Driver Implementation Minor Version.

◆ PWM_SW_PATCH_VERSION

#define PWM_SW_PATCH_VERSION   (1U)

Driver Implementation Patch Version.

◆ PWM_AR_RELEASE_MAJOR_VERSION

#define PWM_AR_RELEASE_MAJOR_VERSION   (4U)

AUTOSAR Major version specification implemented by PWM Driver.

◆ PWM_AR_RELEASE_MINOR_VERSION

#define PWM_AR_RELEASE_MINOR_VERSION   (3U)

AUTOSAR Minor version specification implemented by PWM Driver.

◆ PWM_AR_RELEASE_REVISION_VERSION

#define PWM_AR_RELEASE_REVISION_VERSION   (1U)

AUTOSAR Patch version specification implemented by PWM Driver.

◆ PWM_VENDOR_ID

#define PWM_VENDOR_ID   ((uint16) 44U)

Texas Instruments Vendor ID.

◆ PWM_MODULE_ID

#define PWM_MODULE_ID   ((uint16) 121U)

PWM Driver Module ID.

◆ PWM_E_INIT_FAILED

#define PWM_E_INIT_FAILED   ((uint8)(0x10U))

PWM driver configuration parameter error.

◆ PWM_E_UNINIT

#define PWM_E_UNINIT   ((uint8)(0x11U))

PWM driver Not initialized error.

◆ PWM_E_PARAM_CHANNEL

#define PWM_E_PARAM_CHANNEL   ((uint8)(0x12U))

PWM driver Invalid param.

◆ PWM_E_PERIOD_UNCHANGEABLE

#define PWM_E_PERIOD_UNCHANGEABLE   ((uint8)(0x13U))

PWM driver Fixed period channel.

◆ PWM_E_ALREADY_INITIALIZED

#define PWM_E_ALREADY_INITIALIZED   ((uint8)(0x14U))

PWM driver Already initialized.

◆ PWM_E_PARAM_POINTER

#define PWM_E_PARAM_POINTER   ((uint8)(0x15U))

PWM driver pointer paramter error.

◆ PWM_E_NOT_DISENGAGED

#define PWM_E_NOT_DISENGAGED   ((uint8)(0x16U))

RunTime Error: API Pwm_SetPowerState is called while the PWM module is still in use.

◆ PWM_SID_INIT

#define PWM_SID_INIT   ((uint8)(0x0U))

PWM driver service ID for Initialization API.

◆ PWM_SID_DEINIT

#define PWM_SID_DEINIT   ((uint8)(0x1U))

PWM driver service ID for De-Initialization API.

◆ PWM_SID_SET_DUTY_CYCLE

#define PWM_SID_SET_DUTY_CYCLE   ((uint8)(0x2U))

PWM driver service ID for set duty cycle API.

◆ PWM_SID_SET_PERIOD_AND_DUTY

#define PWM_SID_SET_PERIOD_AND_DUTY   ((uint8)(0x3U))

PWM driver service ID for set duty cycle and period API.

◆ PWM_SID_SET_OUTPUT_TO_IDLE

#define PWM_SID_SET_OUTPUT_TO_IDLE   ((uint8)(0x4U))

PWM driver service ID for set output state to idle API.

◆ PWM_SID_GET_OUTPUT_STATE

#define PWM_SID_GET_OUTPUT_STATE   ((uint8)(0x5U))

PWM driver service ID for get output state API.

◆ PWM_SID_DISABLE_NOTIFICATION

#define PWM_SID_DISABLE_NOTIFICATION   ((uint8)(0x6U))

PWM driver service ID for disable notification API.

◆ PWM_SID_ENABLE_NOTIFICATION

#define PWM_SID_ENABLE_NOTIFICATION   ((uint8)(0x7U))

PWM driver service ID for Enable notification API.

◆ PWM_SID_GET_VERSION_INFO

#define PWM_SID_GET_VERSION_INFO   ((uint8)(0x8U))

PWM driver service ID for Get version info API.

◆ PWM_SID_REGISTER_READBACK

#define PWM_SID_REGISTER_READBACK   ((uint8)(0xDU))

PWM driver service ID for Critical register read back API.

◆ PWM_STATUS_UNINIT

#define PWM_STATUS_UNINIT   ((uint8)(0U))

PWM driver Status uninitialized.

◆ PWM_STATUS_INIT

#define PWM_STATUS_INIT   ((uint8)(1U))

PWM driver Status Initialized.

◆ PWM_DUTY_0_PERCENT

#define PWM_DUTY_0_PERCENT   (0x0U)

16bit value representing 0% of a period value

◆ PWM_DUTY_100_PERCENT

#define PWM_DUTY_100_PERCENT   (0x8000U)

16 bit value representing 100% of a period value

◆ PWM_DUTY_50_PERCENT

#define PWM_DUTY_50_PERCENT   (0x4000U)

16 bit value representing 50% of a period value

Function Documentation

◆ Pwm_Init()

void Pwm_Init ( const Pwm_ConfigType CfgPtr)

Service for PWM initialization.

*  Service name        : Pwm_Init
*  Syntax              : Pwm_Init(P2CONST(Pwm_ConfigType,
*                                  AUTOMATIC, PWM_PBCFG) ConfigPtr)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x00
*  Sync/Async          : Synchronous
*  Reentrancy          : Non Reentrant
*  Parameters (in)     : Pointer to the configuration
*  Parameters (out)    : None
*  Return value        : void
*  Description         : Initializes internal variables
*                        and the PWM unit of the micro controller.
*                        The function can be called on task level.
*  

◆ Pwm_DeInit()

void Pwm_DeInit ( void  )

Service for PWM de-initialization.

*  Service name        : Pwm_DeInit
*  Syntax              : Pwm_DeInit(void)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x01
*  Sync/Async          : Synchronous
*  Reentrancy          : Non Reentrant
*  Parameters (in)     : None
*  Parameters (out)    : None
*  Return value        : void
*  Description         : After DeInit output states should be in idle level
*                       (it is configurable whether reset state is restored or
*                        if channel output states are really set to idle).
*                        The function can be called on task level.
*  

◆ Pwm_SetDutyCycle()

void Pwm_SetDutyCycle ( Pwm_ChannelType  ChannelNumber,
uint16  DutyCycle 
)

Service for setting Duty Cycle.

*  Service name        : Pwm_SetDutyCycle
*  Syntax              : Pwm_SetDutyCycle(Pwm_ChannelType Channel,
*                                         uint16 DutyCycle)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x02
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Parameters (in)     : Pwm_ChannelType Channel
*  Parameters (in)     : uint16 DutyCycle
*  Parameters (out)    : None
*  Return value        : void
*  Description         : This service sets the duty cycle for a channel
*                        if DutyCycle is 0%, set output to inverse of polarity
*                        if DutyCycle is >= 100%, set output to polarity
*                        if 0% < DutyCycle < 100%, set output accordingly
*                        The function can be called on task level.
*  

◆ Pwm_SetPeriodAndDuty()

void Pwm_SetPeriodAndDuty ( Pwm_ChannelType  ChannelNumber,
Pwm_PeriodType  Period,
uint16  DutyCycle 
)

Service for setting Period and Duty Cycle.

*  Service name        : Pwm_SetPeriodAndDuty
*  Syntax              : Pwm_SetPeriodAndDuty(Pwm_ChannelType Channel,
*                                  Pwm_PeriodType Period, uint16 DutyCycle)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x03
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Parameters (in)     : Pwm_ChannelType Channel
*  Parameters (in)     : Pwm_PeriodType Period
*  Parameters (in)     : uint16 DutyCycle
*  Parameters (out)    : None
*  Return value        : void
*  Description         : This service sets period and duty cycle for a channel
*                        if DutyCycle is 0%, set output to inverse of polarity
*                        if DutyCycle is >= 100%, set output to polarity
*                        if 0% < DutyCycle < 100%, set output accordingly
*                        The function can be called on task level.
*  

◆ Pwm_SetOutputToIdle()

void Pwm_SetOutputToIdle ( Pwm_ChannelType  ChannelNumber)

Service to set the output of a channel immediately to idle.

*  Service name        : Pwm_SetOutputToIdle
*  Syntax              : Pwm_SetOutputToIdle(Pwm_ChannelType Channel)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x04
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Parameters (in)     : Pwm_ChannelType Channel
*  Parameters (out)    : None
*  Return value        : void
*  Description         : This service sets the output of a channel
*                        immediately to idle. The idle output level
*                        is configured in driver configuration.
*                        The function can be called on task level.
*  

◆ Pwm_GetOutputState()

Pwm_OutputStateType Pwm_GetOutputState ( Pwm_ChannelType  ChannelNumber)

◆ Pwm_DisableNotification()

void Pwm_DisableNotification ( Pwm_ChannelType  ChannelNumber)

Service to disable the Edge Notification.

*  Service name        : Pwm_DisableNotification
*  Syntax              : Pwm_DisableNotification(Pwm_ChannelType ChannelNumber)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x06
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Parameters (in)     : Pwm_ChannelType ChannelNumber
*  Parameters (out)    : None
*  Return value        : None
*  Description         : Disables the Edge Notification
*                        This service deactivates the Edge Notification for the
*                        pwm channel specified by the ChannelNumber Parameter.
*                        The function can be called on task level.
*  

◆ Pwm_EnableNotification()

void Pwm_EnableNotification ( Pwm_ChannelType  ChannelNumber,
Pwm_EdgeNotificationType  Notification 
)

Service to enable the Edge Notification.

*  Service name        : Pwm_EnableNotification
*  Syntax              : Pwm_EnableNotification (Pwm_ChannelType Channel,
*                        Pwm_EdgeNotificationType Notification)
*  Mode                : Supervisor Mode (Privileged Mode)
*  Service ID[hex]     : 0x07
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Parameters (in)     : Pwm_ChannelType ChannelNumber
*  Parameters (in)     : Pwm_EdgeNotificationType  Notification
*  Parameters (out)    : None
*  Return value        : None
*  Description         : Enables the Edge Notification
*                        This service enables the notification of the chosen
*                        edges for the Pwm channel specified by the
*                        ChannelNumber.The function can be called on task level
*  

◆ Pwm_GetVersionInfo()

void Pwm_GetVersionInfo ( Std_VersionInfoType *  versioninfo)

This service returns the version information of this module.

*  Service name        : Pwm_GetVersionInfo
*  Syntax              : Pwm_GetVersionInfo(P2VAR(Std_VersionInfoType,
*                           AUTOMATIC, PWM_APPL_DATA) versioninfo)
*  Mode                : User Mode (Non-Privileged Mode)
*  Service ID[hex]     : 0x08
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Parameters (in)     : Std_VersionInfoType - Version info.
*  Parameters (out)    : None
*  Return value        : void
*  Description         : Returns the version information of this module.
*                        The function can be called on task level.
*  

◆ 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 structure.

*  Service name        : Pwm_RegisterReadback(Pwm_ChannelType ChannelNumber,
*                                          Pwm_RegisterReadbackType *RegRbPtr)
*  Sync/Async          : Synchronous
*  Reentrancy          : Reentrant
*  Service ID[hex]     : 0x0D
*  Parameters (in)     : Pwm_ChannelType ChannelNumber
*  Parameters (inout)  : RegRbPtr - Pointer to where to store the readback
*                        values. If this pointer is NULL, then the API
*                        will return E_NOT_OK.
*  Description         : This API is used to check the status of critical
                         registers which donot change during program execution.
*  Return value        : Std_ReturnType
*                        E_OK: Register read back has been done successfully
*                        E_NOT_OK: Register read back failed
*