/**
*   @file     Wdg_Cfg.h
*   @implements Wdg_Cfg.h_Artifact
*   @version  1.0.0
*
*   @brief    AUTOSAR Wdg - Contains the implementation of the Watchdog API
*   @details  It contains the layer requested by autosar. The functions are independent of
*             hardware settings.
*
*   @addtogroup  Wdg  
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : Swt
*   Dependencies         : none
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef WDG_CFG_H
#define WDG_CFG_H

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct.
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and namespace shall be distinct.
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct.
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
* The used compilers use more than 31 chars for identifiers.
*
* @section Wdg_Cfg_h_REF_1
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if its identifier only appears in a single function.
* This violation is due to exporting the externally configured initialization structure used by the "Wdg_Init" function.
*
* @section Wdg_Cfg_h_REF_2
* Violates MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once.
* This violation is not fixed since the inclusion of <MA>_MemMap.h is as per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section Wdg_Cfg_h_REF_3
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* Macros that are used only in some configuration.
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/

#include "WdgIf_Types.h"

#include "Mcal.h"
[!NOCODE!][!//
[!VAR "WdgDisableDemReport" = "0"!]
[!IF "node:exists(WdgDemEventParameterRefs)"!]
      [!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'true'"!]
        [!VAR "WdgDisableDemReport" = "1"!]
      [!ENDIF!]
[!ELSE!]
  [!VAR "WdgDisableDemReport" = "1"!]
[!ENDIF!]
[!ENDNOCODE!][!//
[!IF "$WdgDisableDemReport = 0"!]
#include "Dem.h"
[!ENDIF!]

[!INCLUDE "Wdg_VersionCheck_Inc.m"!][!//
[!INCLUDE "Wdg_PluginMacros.m"!][!//
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
* @file           Wdg_Cfg.h
*/
#define WDG_VENDOR_ID_CFG                    43
#define WDG_AR_RELEASE_MAJOR_VERSION_CFG     4
#define WDG_AR_RELEASE_MINOR_VERSION_CFG     3
#define WDG_AR_RELEASE_REVISION_VERSION_CFG  1
#define WDG_SW_MAJOR_VERSION_CFG             1
#define WDG_SW_MINOR_VERSION_CFG             0
#define WDG_SW_PATCH_VERSION_CFG             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/

/* Check if source file and WdgIf_Types header file are of the same Autosar version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if (( WDG_AR_RELEASE_MAJOR_VERSION_CFG != WDGIF_TYPES_AR_RELEASE_MAJOR_VERSION) || \
         ( WDG_AR_RELEASE_MINOR_VERSION_CFG != WDGIF_TYPES_AR_RELEASE_MINOR_VERSION) \
        )
        #error "AutoSar Version Numbers of Wdg_Cfg.h and WdgIf_Types.h are different"
    #endif
#endif

[!IF "$WdgDisableDemReport = 0"!]
 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
     /* Check if source file and Dem header file are of the same Autosar version */
     #if (( WDG_AR_RELEASE_MAJOR_VERSION_CFG != DEM_AR_RELEASE_MAJOR_VERSION) || \
          ( WDG_AR_RELEASE_MINOR_VERSION_CFG != DEM_AR_RELEASE_MINOR_VERSION))
         #error "AutoSar Version Numbers of Wdg_Channel.c and Dem.h are different"
     #endif
 #endif
[!ENDIF!]
/*==================================================================================================
*                                       GLOBAL CONSTANTS
==================================================================================================*/
#define WDG_START_SEC_CONST_UNSPECIFIED
/**
* @brief Include Memory mapping specification
*
* @violates @ref Wdg_Cfg_h_REF_2 MISRA 2012 Required 4.10
*/
#include "Wdg_MemMap.h"
 /**
 * @brief Dem error codes
 */
 /* @violates @ref Wdg_Cfg_h_REF_1 MISRA 2012 Advisory 8.9*/
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)Wdg_E_Disable_Rejected;
[!ENDIF!][!//
[!ENDIF!][!//
 /* @violates @ref Wdg_Cfg_h_REF_1 MISRA 2012 Advisory 8.9*/
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)Wdg_E_Mode_Failed;
[!ENDIF!][!//
[!ENDIF!][!//
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)Wdg_E_Corrupt_Config;
[!ENDIF!][!//
[!ENDIF!][!//
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)Wdg_E_Invalid_Call;
[!ENDIF!][!//
[!ENDIF!][!//
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)Wdg_E_Forbidden_Invocation;
[!ENDIF!][!//
[!ENDIF!][!//
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)WDG_E_Unlocked;
[!ENDIF!][!//
[!ENDIF!][!//
[!IF "node:exists(WdgDemEventParameterRefs)"!][!//
[!IF "WdgGeneral/AutosarExt/WdgDisableDemReportErrorStatus = 'false'"!][!//

extern CONST(Mcal_DemErrorType, WDG_CONST)Wdg_E_Invalid_Parameter;
[!ENDIF!][!//
[!ENDIF!][!//

#define WDG_STOP_SEC_CONST_UNSPECIFIED
/**
* @brief Include Memory mapping specification
*
* @violates @ref Wdg_Cfg_h_REF_2 MISRA 2012 Required 4.10
*/
#include "Wdg_MemMap.h"
 /**
 * @brief Dem error codes
 */

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/
[!LOOP "WdgSettingsConfig/*"!]
[!CALL "WdgCheckCbkNotification","SwtInstance" = "node:value(./WdgInstance)"!]
[!ENDLOOP!]

[!LOOP "WdgSettingsConfig/*"!]
[!CALL "WdgInstanceMacro","SwtInstance" = "node:value(./WdgInstance)"!]
[!ENDLOOP!]

/**
* @brief  This define indicate that the watchdog is internal
*/
#define WDG_INTERNAL_MODULE         (0U)

/**
* @brief  This define indicate that the watchdog is external connected on SPI
*/
#define WDG_EXTERNAL_MODULE_SPI     (1U)

/**
* @brief  This define indicate that the watchdog is external connected on DIO
*/
#define WDG_EXTERNAL_MODULE_DIO     (2U)

 /**
 * @brief  This define indicate the number of HW IPs available on the Platform
 */
[!VAR "MaxIndex"="num:i(count(ecu:list('Wdg.WdgInstance')))"!]
[!VAR "MaxInstance"="num:i(substring-after(ecu:list('Wdg.WdgInstance')[num:i($MaxIndex)],'SWT')+1)"!]
#define WDG_NO_OF_INSTANCES            ([!"num:i(substring-after(ecu:list('Wdg.WdgInstance')[num:i($MaxIndex)],'SWT')+1)"!]U)
/**
* @brief  This variable will indicate which type of driver is in use
*/
#define WDG_TYPE ([!//
[!IF "text:match('',string(WdgExternalConfiguration/WdgExternalContainerRef))"!][!//
          WDG_INTERNAL_MODULE[!//
[!ELSEIF "text:match('Spi',substring-before(substring-after([!//
          WdgExternalConfiguration/WdgExternalContainerRef,'/'),'/'))"!][!//
          WDG_EXTERNAL_MODULE_SPI[!//
[!ELSE!][!//
          WDG_EXTERNAL_MODULE_DIO[!//
[!ENDIF!])

/**
* @brief  Compile switch to enable/disable development error detection for this module
*/
#define WDG_DEV_ERROR_DETECT   ([!IF "WdgGeneral/WdgDevErrorDetect"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/** 
* @brief  Switch to globaly enable/disable the production error reporting.
*/
#define WDG_DISABLE_DEM_REPORT_ERROR_STATUS           [!IF "$WdgDisableDemReport = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!]

/**
* @brief  Compile switch to allow/forbid disabling the watchdog driver during runtime
*/
#define WDG_DISABLE_ALLOWED    ([!IF "WdgGeneral/WdgDisableAllowed"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief  Compile switch to enable/disable the version information
*/
#define WDG_VERSION_INFO_API   ([!IF "WdgGeneral/WdgVersionInfoApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

[!VAR "x" = "0"!]
[!FOR "x" = "0" TO "$MaxInstance - num:i(1)"!]
    [!IF "0 = $x"!]
/**
* @brief  This variable will indicate the index of instance 0
*/
#define WdgConf_WdgGeneral_[!"node:name(WdgGeneral/WdgIndex)"!]_U8 ((uint8)[!"num:i(WdgGeneral/WdgIndex)"!])
    [!ELSE!]
[!"'/**'"!]
* @brief  This variable will indicate the index of instance [!"$x"!]
[!"'*/'"!]
#define WdgConf_WdgGeneral_[!"node:name(concat('WdgGeneral/WdgIndex',$x))"!]_U8 ((uint8)[!"node:value(concat('WdgGeneral/WdgIndex',$x))"!])
    [!ENDIF!]
[!ENDFOR!]

/**
* @brief  This variable will indicate the Wdg Initial Timeout parameter in miliseconds
*/
#define WDG_INITIAL_TIMEOUT_U16 ((uint16)[!"num:i(WdgGeneral/WdgInitialTimeout * 1000)"!])

/**
* @brief  This variable will indicate the Wdg Max Timeout parameter in miliseconds
*/
/* @violates @ref Wdg_Cfg_h_REF_3 MISRA 2012 Advisory 2.5*/
#define WDG_MAX_TIMEOUT_U16     ((uint16)[!"num:i(WdgGeneral/WdgMaxTimeout * 1000)"!])

/**
* @brief  This macro indicate Wdg Max Timeout to fix compiler warning comparision always true
*/
#define WDG_MAX_TIMEOUT_VALUE ([!"num:i(WdgGeneral/WdgMaxTimeout * 1000)"!]U)
/**
* @brief  This macro will indicate max value of 16bits integer type
*/
#define WDG_MAX_VALUE_TYPE16      (65535U)

/**
* @brief  This define indicate that the watchdog is Enable or Disable User mode support
*/
#define WDG_ENABLE_USER_MODE_SUPPORT    ([!IF "WdgGeneral/WdgEnableUserModeSupport"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief This constant specifies the minimum value that will be set in the SWT timeout register
*/
#define SWT_MIN_VALUE_TIMEOUT_U32               ((uint32)[!"num:inttohex(ecu:get('Swt.MinVal.TimeOut'))"!])

#ifdef WDG_ENABLE_USER_MODE_SUPPORT
    #if(STD_ON == WDG_ENABLE_USER_MODE_SUPPORT)
        /**
        * @brief  This define indicate that the ipv SWT is protected by register protection 
        */
        #define WDG_SWT_REG_PROT_AVAILABLE
    #endif /* (STD_ON == WDG_ENABLE_USER_MODE_SUPPORT) */
#endif /* ifdef WDG_ENABLE_USER_MODE_SUPPORT */

/**
* @brief  perform checking marco MCAL_ENABLE_USER_MODE_SUPPORT available or not.
*/
#ifndef MCAL_ENABLE_USER_MODE_SUPPORT
    #if (STD_ON == WDG_ENABLE_USER_MODE_SUPPORT)
        #error MCAL_ENABLE_USER_MODE_SUPPORT is not enabled. For running Wdg in user mode, the MCAL_ENABLE_USER_MODE_SUPPORT needs to be defined
    #endif /* (STD_ON == WDG_ENABLE_USER_MODE_SUPPORT) */
#endif /* ifndef MCAL_ENABLE_USER_MODE_SUPPORT */

[!LOOP "WdgSettingsConfig/*"!]
[!CALL "WdgIsr","WdgSwtInstance" = "node:value(./WdgInstance)"!]
[!ENDLOOP!]

[!LOOP "WdgSettingsConfig/*"!][!//
[!IF "./WdgSettingsSlow/WdgKeyedService = 'true'[!//"
   or ./WdgSettingsFast/WdgKeyedService = 'true'"!][!//
/**
* @brief  This variable will indicate if that the WdgKeyedService is used
*/
#define  WDG_KEYED_SERVICE_USED
[!BREAK!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//

/** 
* @brief  This variable will indicate RAM/ROM execution
*/
[!IF "WdgGeneral/WdgRunArea = 'ROM'"!][!//
#define WDG_ROM (1U)
[!ELSEIF "WdgGeneral/WdgRunArea = 'RAM'"!][!//
#define WDG_RAM (0U)
[!ENDIF!][!//

[!IF "((IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!]
    [!CALL "WdgExportDriverConfiguration"!]
[!ENDIF!]
              
[!INDENT "0"!][!//
[!IF "IMPLEMENTATION_CONFIG_VARIANT='VariantPreCompile' or IMPLEMENTATION_CONFIG_VARIANT='VariantLinkTime' "!][!// 
  [!IF "variant:size()<=1"!][!// 
    #define WDG_PRECOMPILE_SUPPORT  (STD_ON)
  [!ELSE!][!//
    #define WDG_PRECOMPILE_SUPPORT  (STD_OFF)  
  [!ENDIF!][!// 
[!ELSE!][!//
  #define WDG_PRECOMPILE_SUPPORT  (STD_OFF)  
[!ENDIF!][!// 
[!ENDINDENT!][!//

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/

/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                   FUNCTION PROTOTYPES
==================================================================================================*/


#ifdef __cplusplus
}
#endif

#endif /* WDG_CFG_H */
/** @} */
