STM32G0 MCAL 0.0.1
Tiny MCAL for educational purpose.
Loading...
Searching...
No Matches
Pwm.c File Reference

Pwm Driver More...

#include "Std_Types.h"
#include "Pwm.h"
#include "Pwm_Arch.h"

Macros

#define PWM_CHANNEL_MIN   1
 
#define PWM_CHANNEL_MAX   2
 
#define Det_ReportError(ModuleId, InstanceId, ApiId, ErrorId)
 

Functions

void Pwm_Init (const Pwm_ConfigType *ConfigPtr)
 Pwm Initialization
 
void Pwm_DeInit (void)
 Pwm Deinitialization
 
void Pwm_SetDutyCycle (Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
 Pwm Set Duty Cycle
 
void Pwm_SetPeriodAndDuty (Pwm_ChannelType ChannelNumber, Pwm_PeriodType Period, uint16 DutyCycle)
 Pwm Set Period and Duty
 
void Pwm_SetOutputToIdle (Pwm_ChannelType ChannelNumber)
 Pwm Set Output To Idle
 
Pwm_OutputStateType Pwm_GetOutputState (Pwm_ChannelType ChannelNumber)
 Pwm Get Output State
 
void Pwm_DisableNotification (Pwm_ChannelType ChannelNumber)
 Pwm Disable Notification
 
void Pwm_EnableNotification (Pwm_ChannelType ChannelNumber, Pwm_EdgeNotificationType Notification)
 Pwm Enable Notification
 
Std_ReturnType Pwm_SetPowerState (Pwm_PowerStateRequestResultType *Result)
 Pwm Set Power State
 
Std_ReturnType Pwm_GetCurrentPowerState (Pwm_PowerStateType *CurrentPowerState, Pwm_PowerStateRequestResultType *Result)
 Pwm Get Current Power State
 
Std_ReturnType Pwm_GetTargetPowerState (Pwm_PowerStateType *TargetPowerState, Pwm_PowerStateRequestResultType *Result)
 Pwm Get Target Power State
 
Std_ReturnType Pwm_PreparePowerState (Pwm_PowerStateType PowerState, Pwm_PowerStateRequestResultType *Result)
 Pwm Prepare Power State
 
void Pwm_GetVersionInfo (Std_VersionInfoType *versioninfo)
 Pwm Get Version Info
 

Variables

static Pwm_HwUnit HwUnit_Pwm
 Variable for the initial value of the pwm configuration array.
 

Detailed Description

Pwm Driver

Author
Jazmín Melendrez

The driver provides functions for initialization and control of the microcontroller internal PWM stage (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.

Macro Definition Documentation

◆ Det_ReportError

#define Det_ReportError ( ModuleId,
InstanceId,
ApiId,
ErrorId )
Value:
(void)0
Parameters
ModuleIdmodule id number
InstanceIdInstance Id
ApiIdPai id
ErrorIdError code

Function Documentation

◆ Pwm_DeInit()

void Pwm_DeInit ( void )

Pwm Deinitialization

This function de-initializes the Pwm module.

Requirement
SWS_Pwm_00096, SWS_Pwm_00117, SWS_Pwm_10051, SWS_Pwm_20051

◆ Pwm_DisableNotification()

void Pwm_DisableNotification ( Pwm_ChannelType ChannelNumber)

Pwm Disable Notification

Function to disable the PWM signal edge notification.

Parameters
ChannelNumberNumeric identifier of the PWM
Requirement
SWS_Pwm_91003, SWS_Pwm_00117 SWS_Pwm_00047, SWS_Pwm_10051, SWS_Pwm_20051

< Minimum valid PWM channel number.

◆ Pwm_EnableNotification()

void Pwm_EnableNotification ( Pwm_ChannelType ChannelNumber,
Pwm_EdgeNotificationType Notification )

Pwm Enable Notification

Function to enable the PWM signal edge notification according to notification parameter.

Parameters
ChannelNumberNumeric identifier of the PWM
NotificationType of notification PWM_RISING_EDGE or PWM_FALLING_EDGE or PWM_BOTH_EDGES.
Requirement
SWS_Pwm_91004, SWS_Pwm_00117 SWS_Pwm_00047, SWS_Pwm_10051, SWS_Pwm_20051

< Minimum valid PWM channel number.

◆ Pwm_GetCurrentPowerState()

Std_ReturnType Pwm_GetCurrentPowerState ( Pwm_PowerStateType * CurrentPowerState,
Pwm_PowerStateRequestResultType * Result )

Pwm Get Current Power State

This API returns the current power state of the PWM HW unit.

Parameters
CurrentPowerStateThe current power mode of the PWM HW Unit is returned in this parameter
ResultIf the API returns E_OK: PWM_SERVICE_ACCEPTED: Current power mode was returned. If the API returns E_NOT_OK: PWM_NOT_INIT: PWM Module not initialized.
Return values
E_OKMode could be read E_NOT_OK: Service is rejected
Requirement
SWS_Pwm_00177, SWS_Pwm_00117

◆ Pwm_GetOutputState()

Pwm_OutputStateType Pwm_GetOutputState ( Pwm_ChannelType ChannelNumber)

Pwm Get Output State

Function to read the internal state of the PWM output signal.

Parameters
ChannelNumberNumeric identifier of the PWM
Return values
PWM_HIGHThe PWM output state is high PWM_LOW: The PWM output state is low
Requirement
SWS_Pwm_00100, SWS_Pwm_00117 SWS_Pwm_00047, SWS_Pwm_10051, SWS_Pwm_20051

< Minimum valid PWM channel number.

◆ Pwm_GetTargetPowerState()

Std_ReturnType Pwm_GetTargetPowerState ( Pwm_PowerStateType * TargetPowerState,
Pwm_PowerStateRequestResultType * Result )

Pwm Get Target Power State

This API returns the Target power state of the PWM HW unit.

Parameters
TargetPowerStateThe Target power mode of the PWM HW Unit is returned in this parameter.
ResultIf the API returns E_OK: PWM_SERVICE_ACCEPTED:Target power mode was returned. If the API returns E_NOT_OK: PWM_NOT_INIT: PWM Module not initialized.
Return values
E_OKMode could be read E_NOT_OK: Service is rejected
Requirement
SWS_Pwm_00180, SWS_Pwm_00117

◆ Pwm_GetVersionInfo()

void Pwm_GetVersionInfo ( Std_VersionInfoType * versioninfo)

Pwm Get Version Info

This function returns the version information of this module.

Parameters
versioninfoPointer to where to store the version information of this module.
Requirement
SWS_Pwm_00103, SWS_Pwm_00117

◆ Pwm_Init()

void Pwm_Init ( const Pwm_ConfigType * ConfigPtr)

Pwm Initialization

Service for PWM initialization.

Parameters
ConfigPtrPointer to driver configuration
Requirement
SWS_Pwm_00095, SWS_Pwm_00018, SWS_Pwm_10051, SWS_Pwm_20051

◆ Pwm_PreparePowerState()

Std_ReturnType Pwm_PreparePowerState ( Pwm_PowerStateType PowerState,
Pwm_PowerStateRequestResultType * Result )

Pwm Prepare Power State

This API starts the needed process to allow the PWM HW module to enter the requested power state.

Parameters
PowerStateThe Target power mode of the PWM HW Unit is returned in this parameter.
ResultIf the API returns E_OK: PWM_SERVICE_ACCEPTED: PWM Module power state preparation was started. If the API returns E_NOT_OK: PWM_NOT_INIT: PWM Module not initialized. PWM_SEQUENCE_ERROR: wrong API call sequence (Current Power State = Target Power State). PWM_POWER_STATE_NOT_SUPP: PWM Module does not support the requested power state. PWM_TRANS_NOT_POSSIBLE: PWM Module cannot transition directly from the current power state to the requested power state or the HW peripheral is still busy
Return values
E_OKPreparation process started E_NOT_OK: Service is rejected
Requirement
SWS_Pwm_00183, SWS_Pwm_00117

◆ Pwm_SetDutyCycle()

void Pwm_SetDutyCycle ( Pwm_ChannelType ChannelNumber,
uint16 DutyCycle )

Pwm Set Duty Cycle

This function sets the duty cycle of the PWM channel.

Parameters
ChannelNumberNumeric identifier of the PWM
DutyCycleMin=0x0000 Max=0x8000
Requirement
SWS_Pwm_91000, SWS_Pwm_00117, SWS_Pwm_00047, SWS_Pwm_10051, SWS_Pwm_20051

< Minimum valid PWM channel number.

◆ Pwm_SetOutputToIdle()

void Pwm_SetOutputToIdle ( Pwm_ChannelType ChannelNumber)

Pwm Set Output To Idle

This function sets the PWM output to the configured Idle state.

Parameters
ChannelNumberNumeric identifier of the PWM
Requirement
SWS_Pwm_91002, SWS_Pwm_00117 SWS_Pwm_00047, SWS_Pwm_10051, SWS_Pwm_20051

< Minimum valid PWM channel number.

◆ Pwm_SetPeriodAndDuty()

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

Pwm Set Period and Duty

This function sets the period and the duty cycle of a PWM channel.

Parameters
ChannelNumberNumeric identifier of the PWM
PeriodPeriod of the PWM signal
DutyCycleMin=0x0000 Max=0x8000
Requirement
SWS_Pwm_91001, SWS_Pwm_00117, SWS_Pwm_00045, SWS_Pwm_00047, SWS_Pwm_10051, SWS_Pwm_20051

< Minimum valid PWM channel number.

◆ Pwm_SetPowerState()

Std_ReturnType Pwm_SetPowerState ( Pwm_PowerStateRequestResultType * Result)

Pwm Set Power State

This function configures the Pwm module so that it enters the already prepared power state, chosen between a predefined set of configured ones.

Parameters
ResultIf the API returns E_OK: PWM_SERVICE_ACCEPTED:Power state change executed. If the API returns E_NOT_OK: PWM_NOT_INIT: PWM Module not initialized. PWM_SEQUENCE_ERROR: wrong API call sequence. PWM_HW_FAILURE: the HW module has a failure which prevents it to enter the required power state
Return values
E_OKPower Mode changed E_NOT_OK: request rejected
Requirement
SWS_Pwm_00166, SWS_Pwm_00117

Variable Documentation

◆ HwUnit_Pwm

Pwm_HwUnit HwUnit_Pwm
static
Initial value:
=
{
.HwUnitState = PWM_STATE_UNINIT,
.Config = NULL_PTR,
.Pwm_ChannelClass = PWM_VARIABLE_PERIOD,
.Pwm_channelNumber = 2 ,
}
@ PWM_STATE_UNINIT
Definition Pwm_Types.h:160
@ PWM_VARIABLE_PERIOD
Definition Pwm_Types.h:109
#define NULL_PTR
null pointer definition
Definition Std_Types.h:165

Variable for the initial value of the pwm configuration array.

< Add static when no testing