/*!
* @file     Wdg.h
*
* @version  1.0.0
*
* @brief    AUTOSAR WDG Driver header file
*
* @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 WDG_H
#define WDG_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Wdg_Cfg.h"
#include "Wdg_Types.h"

#if (STD_ON == WDG_USE_GPT)
#include "Gpt.h"
#endif

#if (STD_ON == WDG_INSTANCE0)

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup WDG_Driver
  * @brief WDG driver modules
  @{
*/

/** @defgroup WDG_Macros
  @{
*/
/**************************************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
**************************************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define WDG_H_VENDOR_ID                     0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define WDG_H_MODULE_ID                     0x0066U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define WDG_H_AR_RELEASE_MAJOR_VERSION      0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define WDG_H_AR_RELEASE_MINOR_VERSION      0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define WDG_H_AR_RELEASE_REVISION_VERSION   0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define WDG_H_SW_MAJOR_VERSION              0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define WDG_H_SW_MINOR_VERSION              0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define WDG_H_SW_PATCH_VERSION              0x00U

/**@} end of group WDG_Macros */

/**************************************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************************************/
/* Make sure the vendor id is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_VENDOR_ID != WDG_CFG_H_VENDOR_ID)
    #error "Vendor id mismatch between Wdg.h and Wdg_Cfg.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_AR_RELEASE_MAJOR_VERSION != WDG_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Wdg.h and Wdg_Cfg.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_AR_RELEASE_MINOR_VERSION != WDG_CFG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Wdg.h and Wdg_Cfg.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_AR_RELEASE_REVISION_VERSION != WDG_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Wdg.h and Wdg_Cfg.h"
#endif
/* Make sure the software major version number is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_SW_MAJOR_VERSION != WDG_CFG_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Wdg.h and Wdg_Cfg.h"
#endif
/* Make sure the software minor version number is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_SW_MINOR_VERSION != WDG_CFG_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Wdg.h and Wdg_Cfg.h"
#endif
/* Make sure the software patch version number is the same between Wdg.h and Wdg_Cfg.h */
#if (WDG_H_SW_PATCH_VERSION != WDG_CFG_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Wdg.h and Wdg_Cfg.h"
#endif

/* Make sure the vendor id is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_VENDOR_ID != WDG_TYPES_H_VENDOR_ID)
    #error "Vendor id mismatch between Wdg.h and Wdg_Types.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_AR_RELEASE_MAJOR_VERSION != WDG_TYPES_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Wdg.h and Wdg_Types.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_AR_RELEASE_MINOR_VERSION != WDG_TYPES_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Wdg.h and Wdg_Types.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_AR_RELEASE_REVISION_VERSION != WDG_TYPES_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Wdg.h and Wdg_Types.h"
#endif
/* Make sure the software major version number is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_SW_MAJOR_VERSION != WDG_TYPES_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Wdg.h and Wdg_Types.h"
#endif
/* Make sure the software minor version number is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_SW_MINOR_VERSION != WDG_TYPES_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Wdg.h and Wdg_Types.h"
#endif
/* Make sure the software patch version number is the same between Wdg.h and Wdg_Types.h */
#if (WDG_H_SW_PATCH_VERSION != WDG_TYPES_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Wdg.h and Wdg_Types.h"
#endif

#if (STD_ON == WDG_USE_GPT)
    /* Make sure the vendor id is the same between Wdg.h and Gpt.h */
    #if (WDG_H_VENDOR_ID != GPT_H_VENDOR_ID)
        #error "Vendor id mismatch between Wdg.h and Gpt.h"
    #endif
    /* Make sure the AUTOSAR major version number is the same between Wdg.h and Gpt.h */
    #if (WDG_H_AR_RELEASE_MAJOR_VERSION != GPT_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR Major Version Number mismatch between Wdg.h and Gpt.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Wdg.h and Gpt.h */
    #if (WDG_H_AR_RELEASE_MINOR_VERSION != GPT_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Wdg.h and Gpt.h"
    #endif
    /* Make sure the AUTOSAR revision version number is the same between Wdg.h and Gpt.h */
    #if (WDG_H_AR_RELEASE_REVISION_VERSION != GPT_H_AR_RELEASE_REVISION_VERSION)
        #error "AUTOSAR Revision Version Number mismatch between Wdg.h and Gpt.h"
    #endif
    /* Make sure the software major version number is the same between Wdg.h and Gpt.h */
    #if (WDG_H_SW_MAJOR_VERSION != GPT_H_SW_MAJOR_VERSION)
        #error "Software Major Version Number mismatch between Wdg.h and Gpt.h"
    #endif
    /* Make sure the software minor version number is the same between Wdg.h and Gpt.h */
    #if (WDG_H_SW_MINOR_VERSION != GPT_H_SW_MINOR_VERSION)
        #error "Software Minor Version Number mismatch between Wdg.h and Gpt.h"
    #endif
    /* Make sure the software patch version number is the same between Wdg.h and Gpt.h */
    #if (WDG_H_SW_PATCH_VERSION != GPT_H_SW_PATCH_VERSION)
        #error "Software Patch Version Number mismatch between Wdg.h and Gpt.h"
    #endif
#endif

/**************************************************************************************************
                    ENUMERATION DEFINITION
**************************************************************************************************/
/** @defgroup WDG_Enumerations
  @{
*/

/**
 * @brief   Defines wdg module development errors.
 */
typedef enum
{
    WDG_E_DRIVER_STATE     = 0x10,  //!< API is called on incorrect place

    WDG_E_PARAM_MODE       = 0x11,  //!< API is called when parameter is not
                                    //!< WDGIF_SLOW_MODE, WDGIF_FAST_MODE or mode parameters is wrong.

    WDG_E_PARAM_CONFIG     = 0x12,  //!< API is called when parameter is not
                                    //!< WDGIF_SLOW_MODE, WDGIF_FAST_MODE or mode parameters is wrong.

    WDG_E_PARAM_TIMEOUT    = 0x13,  //!< timeout value is higher than the maximum timeout value which is set by
                                    //!< user on configuration tool.

    WDG_E_PARAM_POINTER    = 0x14,  //!< API is called with point parameter is wrong

    WDG_E_INIT_FAILED      = 0x15   //!< Wdg_Init() is called with NULL_PTR when Config Variant is VariantPostBuild.

} Wdg_ErrorIdType;

/**
 * @brief   Defines wdg Service Id.
 */
typedef enum
{
    SID_WDG_INIT                 = 0x00,     //!< corresponding with Wdg_Init() API

    SID_WDG_SETMODE              = 0x01,     //!< corresponding with Wdg_SetMode() API

    SID_WDG_SETTRIGGERCONDITION  = 0x02,     //!< corresponding with Wdg_SetTriggerCondition() API

    SID_WDG_TRIGGER              = 0x03      //!< corresponding with Wdg_GptCallbackFunctionX() function

#if (STD_ON == WDG_VERSION_INFO_API)
    ,
    SID_WDG_GETVERSION           = 0x04      //!< corresponding with Wdg_GetVersionInfo() API
#endif

} Wdg_ServiceIdType;

/**
 * @brief   enumerate wdg module status
 */
typedef enum
{
    WDG_UNINIT          = 0x00,  //!< wdg module has not been initialized

    WDG_IDLE            = 0x01,  //!< wdg counter is not work

    WDG_BUSY            = 0x02,  //!< wdg counter is working

    WDG_IS_INITIALIZING = 0x03   //!< wdg module is initializing

} Wdg_ModuleStatusType;

/**@} end of group WDG_Enumerations */

/**************************************************************************************************
                    STRUCT DEFINITION
**************************************************************************************************/
/** @defgroup WDG_Structure
  @{
*/

/**
 * @brief   Used for pointers to structures holding configuration data provided to the Wdg module
 *          initialization routine for configuration of the module and watchdog hardware.
 */
typedef struct
{
    CONST(WdgIf_ModeType, WDG_CONST) wdgInitMode;      //!< wdg hardware module

    CONST(Wdg_InstanceType, WDG_CONST) wdgInstanceId;   //!< wdg hardware instance id

#if (STD_ON == WDG_USE_GPT)
    CONST(Gpt_ChannelType, WDG_CONST) wdgGptChannelId;    //!< Gpt hardware channel

    CONST(uint32, WDG_CONST) wdgGptSourceClock;    //!< trigger source clock
#endif

    P2CONST(Wdg_ModeParamterType, WDG_VAR, WDG_APPL_CONST) wdgModeParameter[2];   //!< point to specific mode parameter

} Wdg_ConfigType;

/**@} end of group WDG_Structure */

/**************************************************************************************************
                    GLOBAL VARIABLE
**************************************************************************************************/
#define WDG_START_SEC_CONST_8
#include "Wdg_MemMap.h"

/** @defgroup WDG_Variable
  @{
*/

extern CONST(uint8, WDG_CONST) g_wdgIndex[WDG_INSTANCES_SUPPORT_NUMBER];

/**@} end of group WDG_Variable */

#define WDG_STOP_SEC_CONST_8
#include "Wdg_MemMap.h"

#define WDG_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Wdg_MemMap.h"

/** @defgroup WDG_Variable
  @{
*/

extern CONST(Wdg_ConfigType, WDG_CONST) g_wdgConfig;

/**@} end of group WDG_Variable */

#define WDG_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Wdg_MemMap.h"

/**************************************************************************************************
                    FUNCTION DECLARATION
**************************************************************************************************/
#ifdef WDG_RUN_AREA_ROM
#define WDG_START_SEC_CODE
#else
#define WDG_START_SEC_RAMCODE
#endif
#include "Wdg_MemMap.h"

/** @defgroup WDG_Fuctions
  @{
*/

#if (STD_ON == WDG_VERSION_INFO_API)
FUNC(void, WDG_CODE) Wdg_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, WDG_APPL_DATA) versioninfo);
#endif

#if (STD_ON == WDG_USE_GPT)
FUNC(void, WDG_CODE) Wdg_SetTriggerCondition(CONST(uint16, WDG_CONST) timeout);
#else
FUNC(void, WDG_CODE) Wdg_SetTriggerCondition(void);
#endif

FUNC(Std_ReturnType, WDG_CODE) Wdg_SetMode(CONST(WdgIf_ModeType, WDG_CONST) Mode);

FUNC(void, WDG_CODE) Wdg_Init(P2CONST(Wdg_ConfigType, AUTOMATIC, WDG_APPL_CONST) ConfigPtr);

/**@} end of group WDG_Fuctions */

#ifdef WDG_RUN_AREA_ROM
#define WDG_STOP_SEC_CODE
#else
#define WDG_STOP_SEC_RAMCODE
#endif
#include "Wdg_MemMap.h"

#endif

#ifdef __cplusplus
}
#endif

#endif

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