/*!
* @file     Pwm_TmrTypes.h
*
* @version  1.0.0
*
* @brief    Header file of pwm type struct with TMR driver
*
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifndef PWM_TMR_TYPES_H
#define PWM_TMR_TYPES_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Pwm_Cfg.h"
#include "Port.h"

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup PWM_Driver
  * @brief PWM driver modules
  @{
*/

/** @defgroup PWM_Macros
  @{
*/
/**************************************************************************
                  VENDOR ID & AUTOSAR VERSION INFO
**************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define PWM_TMR_TYPES_H_VENDOR_ID                       0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define PWM_TMR_TYPES_H_MODULE_ID                       0x0079U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define PWM_TMR_TYPES_H_AR_RELEASE_MAJOR_VERSION        0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define PWM_TMR_TYPES_H_AR_RELEASE_MINOR_VERSION        0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define PWM_TMR_TYPES_H_AR_RELEASE_REVISION_VERSION     0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define PWM_TMR_TYPES_H_SW_MAJOR_VERSION                0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define PWM_TMR_TYPES_H_SW_MINOR_VERSION                0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define PWM_TMR_TYPES_H_SW_PATCH_VERSION                0x00U

/**@} end of group PWM_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_VENDOR_ID != PWM_CFG_H_VENDOR_ID)
    #error "Vendor id mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h " 
#endif
/* Make sure the AUTOSAR major version number is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_AR_RELEASE_MAJOR_VERSION != PWM_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_AR_RELEASE_MINOR_VERSION != PWM_CFG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_AR_RELEASE_REVISION_VERSION != PWM_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h "
#endif
/* Make sure the software major version number is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_SW_MAJOR_VERSION != PWM_CFG_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h "
#endif
/* Make sure the software minor version number is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_SW_MINOR_VERSION != PWM_CFG_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h "
#endif
/* Make sure the software patch version number is the same between Pwm_TmrTypes.h and Pwm_Cfg.h */
#if (PWM_TMR_TYPES_H_SW_PATCH_VERSION != PWM_CFG_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Pwm_TmrTypes.h and Pwm_Cfg.h "
#endif

/* Make sure the vendor id is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_VENDOR_ID != PORT_H_VENDOR_ID)
    #error "Vendor id mismatch between Pwm_TmrTypes.h and Port.h " 
#endif
/* Make sure the AUTOSAR major version number is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_AR_RELEASE_MAJOR_VERSION != PORT_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Pwm_TmrTypes.h and Port.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_AR_RELEASE_MINOR_VERSION != PORT_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Pwm_TmrTypes.h and Port.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_AR_RELEASE_REVISION_VERSION != PORT_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Pwm_TmrTypes.h and Port.h "
#endif
/* Make sure the software major version number is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_SW_MAJOR_VERSION != PORT_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Pwm_TmrTypes.h and Port.h "
#endif
/* Make sure the software minor version number is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_SW_MINOR_VERSION != PORT_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Pwm_TmrTypes.h and Port.h "
#endif
/* Make sure the software patch version number is the same between Pwm_TmrTypes.h and Port.h */
#if (PWM_TMR_TYPES_H_SW_PATCH_VERSION != PORT_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Pwm_TmrTypes.h and Port.h "
#endif

/**************************************************************************
                    OTHER TYPE DEFINITION
**************************************************************************/
/** @defgroup PWM_Structure
  @{
*/

/** Pwm_ChannelType adapt to tmr method */
typedef uint8 Pwm_TmrChIdType;
/** pwm tmr channel fault/overflow notification function point type */
typedef void (*Pwm_TmrFaultOverflowNotifyType)(uint8 ModuleId);
/** pwm tmr notification condition */
typedef uint8 Pwm_TmrNotifyConditionType;
/** pwm tmr channel name type */
typedef uint8 Pwm_ChNameType;
/** pwm tmr instance Id type */
typedef uint8 Pwm_TmrInstanceType;

/**@} end of group PWM_Structure */

/**************************************************************************
                    MACRO DEFINITION
**************************************************************************/
/** @defgroup PWM_Macros
  @{
*/

/** pwm tmr channel name */
#define PWM_TMR1_CH1    ((Pwm_ChNameType)0)
#define PWM_TMR1_CH2    ((Pwm_ChNameType)1)
#define PWM_TMR1_CH3    ((Pwm_ChNameType)2)
#define PWM_TMR1_CH4    ((Pwm_ChNameType)3)
#define PWM_TMR2_CH1    ((Pwm_ChNameType)4)
#define PWM_TMR2_CH2    ((Pwm_ChNameType)5)
#define PWM_TMR2_CH3    ((Pwm_ChNameType)6)
#define PWM_TMR2_CH4    ((Pwm_ChNameType)7)
#define PWM_TMR3_CH1    ((Pwm_ChNameType)8)
#define PWM_TMR3_CH2    ((Pwm_ChNameType)9)
#define PWM_TMR3_CH3    ((Pwm_ChNameType)10)
#define PWM_TMR3_CH4    ((Pwm_ChNameType)11)
#define PWM_TMR4_CH1    ((Pwm_ChNameType)12)
#define PWM_TMR4_CH2    ((Pwm_ChNameType)13)
#define PWM_TMR4_CH3    ((Pwm_ChNameType)14)
#define PWM_TMR4_CH4    ((Pwm_ChNameType)15)

#define PWM_TMR_CH1     ((Pwm_TmrChIdType)0)
#define PWM_TMR_CH2     ((Pwm_TmrChIdType)1)
#define PWM_TMR_CH3     ((Pwm_TmrChIdType)2)
#define PWM_TMR_CH4     ((Pwm_TmrChIdType)3)

/** pwm tmr instance macro */
#define PWM_TMR1    ((Pwm_TmrInstanceType)0)
#define PWM_TMR2    ((Pwm_TmrInstanceType)1)
#define PWM_TMR3    ((Pwm_TmrInstanceType)2)
#define PWM_TMR4    ((Pwm_TmrInstanceType)3)

/** pwm tmr notification condition */
#define PWM_TMR_INT_CONDITION_NO_EDGE     ((Pwm_TmrNotifyConditionType)0U)
#define PWM_TMR_CCXIFLG_EDGE              ((Pwm_TmrNotifyConditionType)1U)
#define PWM_TMR_UIFLG_EDGE                ((Pwm_TmrNotifyConditionType)2U)
#define PWM_TMR_UIFLG_NO_EDGE_NOTIF       ((Pwm_TmrNotifyConditionType)4U)
#define PWM_TMR_UIFLG_FAULT_IDLE_STATE    ((Pwm_TmrNotifyConditionType)8U)
#define PWM_TMR_CHANNEL_NOT_USED          ((Pwm_TmrNotifyConditionType)255U)

/**@} end of group PWM_Macros */

/**************************************************************************
                    ENUMERATION DEFINITION
**************************************************************************/
/** @defgroup PWM_Enumerations
  @{
*/

/**
 * @brief    pwm channel alignment enumeration
 */
typedef enum
{
    PWM_EDGE_ALIGN = 0x0U,    //!< a channel signal generated at the starting edge of the pwm period

    PWM_CENTER_ALIGN = 0x1U,  //!< a channel signal generated around the middle of the pwm period

    PWM_EDGE_SYNCHRONOUS_ALIGN = 0x2U, //!< two channel signal generated with the same polarity
                                       //!< can be phase shift by deadtime

    PWM_EDGE_COMPLEMENTARY_ALIGN = 0x3U, //!< two channel signal generated with the complementary polarity
                                         //!< can be phase shift by deadtime

    PWM_CENTER_SYNCHRONOUS_ALIGN = 0x4U, //!< two channel signal generated with the same polarity
                                         //!< can be phase shift by deadtime

    PWM_CENTER_COMPLEMENTARY_ALIGN = 0x5U //!< two channel signal generated with the complementary polarity
                                           //!< can be phase shift by deadtime
}Pwm_ChAlignType;

/**
 * @brief    pwm center aligned mode enumeration
 */
typedef enum
{
    PWM_TMR_EDGE_ALIGN           = 0x0U,  //!< TMR edge align

    PWM_TMR_CENTER_ALIGN_MODE1   = 0x1U,  //!< A match interruption occurs only during decrement counting

    PWM_TMR_CENTER_ALIGN_MODE2   = 0x2U,  //!< A match interruption occurs only during increment counting

    PWM_TMR_CENTER_ALIGN_MODE3   = 0x3U   //!< A match interruption occurs whether counting down or up

}Pwm_TmrAlignType;

/**
 * @brief    pwm output mode enumeration
 */
typedef enum
{
    PWM_OUTPUT_LOW_LEVEL   = 0x4U,  //!< OC1REF output low level

    PWM_OUTPUT_HIGH_LEVEL  = 0x5U,  //!< OC1REF output high level

    PWM_OUTPUT_MODE1       = 0x6U,  //!< pwm mode 1: TMR_CNT < TMR_CCx, output active level

    PWM_OUTPUT_MODE2       = 0x7U   //!< pwm mode 1: TMR_CNT < TMR_CCx, output idle level

}Pwm_OutputModeType;

/**@} end of group PWM_Enumerations */

/**************************************************************************
                    STRUCT DEFINITION
**************************************************************************/
/** @defgroup PWM_Structure
  @{
*/

/**
 * @brief    PWM tmr configuration register struct
 */
typedef struct
{
    CONST(Pwm_TmrInstanceType, PWM_CONST)   tmrName;     //!< pwm tmr instance id
    CONST(uint16, PWM_CONST)  periodTick;  //!< pwm tmr period Tick
    CONST(uint32, PWM_CONST)  tmrCtrl1;    //!< tmr control register 1
    CONST(uint32, PWM_CONST)  tmrPsc;      //!< tmr prescaler register
#if (STD_ON == PWM_DUAL_CLOCK_MODE_SUPPORTED)
    CONST(uint32, PWM_CONST)  pscAlt;      //!< tmr alterna prescaler register
#endif
    CONST(uint32, PWM_CONST)  tmrBdt;      //!< tmr break and dead time register
#if (STD_ON == PWM_FAULT_CHECK_SUPPORTED)
    CONST(Pwm_TmrFaultOverflowNotifyType, PWM_CONST)  pwmTmrFaultNotifyPtr;   //!< tmr fault function ptr
#endif
#if (STD_ON == PWM_OVERFLOW_CHECK_SUPPORTED)
    CONST(Pwm_TmrFaultOverflowNotifyType, PWM_CONST)  pwmTmrOverflowNotifyPtr;   //!< tmr overflow function ptr
#endif
} Pwm_TmrRegValType;

/**
 * @brief    PWM tmr channel configuration struct
 */
typedef struct
{
    CONST(Pwm_OutputStateType, PWM_CONST) pwmChPolarity;  //!< pwm tmr channel signal polarity

    CONST(Pwm_OutputStateType, PWM_CONST) pwmChIdleState; //!< pwm tmr channel signal idle state

    CONST(uint16, PWM_CONST) pwmChDutyCycle;              //!< pwm tmr channel duty cycle, from 0 to 0x8000

    CONST(Pwm_TmrChIdType, PWM_CONST) pwmChName;          //!< pwm tmr channel id

    CONST(Pwm_ChAlignType, PWM_CONST) pwmChAlign;         //!< pwm tmr channel align class

    CONST(Pwm_OutputModeType, PWM_CONST) mode1or2;        //!< Does the valid level occur before or after the match

    CONST(Port_PinType, PWM_CONST) pwmpin;                //!< pin used to output

#if (STD_ON == PWM_FAULT_CHECK_SUPPORTED)
    CONST(Pwm_OutputStateType, PWM_CONST) ocLevle;        //!< OC output level when fault occure

    CONST(Pwm_OutputStateType, PWM_CONST) ocnLevle;       //!< OCN output level when fault occure
#endif

} Pwm_TmrChCfgType;

/**
 * @brief    indicate PWM tmr channel number and channel configuration
 */
typedef struct
{
    CONST(Pwm_TmrChIdType, PWM_CONST) cfgChNumber;        //!< indicate PWM tmr channel number on a instance

    CONST(Pwm_TmrInstanceType, PWM_CONST) cfgTmrNumber;   //!< indicate PWM tmr instance number

    CONST(Pwm_TmrChCfgType, PWM_CONST) (*pCfgChPtr)[];    //!< point to tmr channel configuration

    CONST(Pwm_TmrRegValType, PWM_CONST) (*pCfgTmrPtr)[];  //!< point to tmr instance configuration

} Pwm_TmrIpCfgType;

/**
 * @brief    pwm channel reality type
 */
typedef struct 
{

    CONSTP2CONST(Pwm_TmrIpCfgType, PWM_CONST, PWM_APPL_CONST)  pTmrIpCfgPtr;   //!< pwm channel adopt tmr

} Pwm_IpCfgType;

/**@} end of group PWM_Structure */

#ifdef __cplusplus
}
#endif

#endif

/**@} end of group PWM_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
