/**
*   @file    Mcu_Dem_Wrapper.c
*   @version 1.0.0
*
*   @brief   AUTOSAR Mcu - Convenience functions implementations for DEM.
*   @details Contains implementations of convenience functions for DEM calls to reduce code clutter in IPs.
*
*   @addtogroup MCU
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : MC
*   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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section Mcu_Dem_Wrapper_h_REF_1
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor
* directives or comments. AUTOSAR imposes the specification of the sections in which certain parts
* of the driver must be placed.
*
* @section Mcu_Dem_Wrapper_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 comes from the order of includes in the .c file
* and from include dependencies. As a safe approach, any file must include all its dependencies.
* Header files are already protected against double inclusions. The inclusion of Mcu_MemMap.h is as
* per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section Mcu_Dem_Wrapper_h_REF_3
* Violates MISRA 2012 Advisory Directive 4.9, A function should be used in preference to a function-like macro
* where they are interchangeable. This violation is done to reduce code complexity by not having to clutter
* every function which can throw a timeout error with DEM preprocessor directives.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct.
* This violation is due to the AUTOSAR requirement [SWS_BSW_00036] (perform inter module checks).
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct.
* This rule does not apply if either identifier is a macro identifier, because this case is covered
* by Rule 5.4 and Rule 5.5.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and name space shall be distinct.
* This rule does not apply if either identifier is a macro identifier, because this case is covered
* by Rule 5.4 and Rule 5.5.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
* The identifier clash is between macro identifiers. Therefore, this rule is incorrectly reported by the tool.
*
*/


/*==================================================================================================
                                         INCLUDE FILES
 1) system and project includes
 2) needed interfaces from external units
 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Mcu_Dem_Wrapper.h"

/*==================================================================================================
                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define MCU_DEM_WRAPPER_VENDOR_ID_C                       43
#define MCU_DEM_WRAPPER_AR_RELEASE_MAJOR_VERSION_C        4
#define MCU_DEM_WRAPPER_AR_RELEASE_MINOR_VERSION_C        3
#define MCU_DEM_WRAPPER_AR_RELEASE_REVISION_VERSION_C     1
#define MCU_DEM_WRAPPER_SW_MAJOR_VERSION_C                1
#define MCU_DEM_WRAPPER_SW_MINOR_VERSION_C                0
#define MCU_DEM_WRAPPER_SW_PATCH_VERSION_C                0

/*==================================================================================================
                                      FILE VERSION CHECKS
==================================================================================================*/
/**
* @brief            The MCU module's implementer shall avoid the integration of incompatible files.
*
*/
/* Check if current file and Mcu_Dem_Wrapper header file are of the same vendor */
#if (MCU_DEM_WRAPPER_VENDOR_ID_C != MCU_DEM_WRAPPER_VENDOR_ID)
    #error "Mcu_Dem_Wrapper.c and Mcu_Dem_Wrapper.h have different vendor ids"
#endif

/* Check if current file and Mcu_Dem_Wrapper header file are of the same Autosar version */
#if ((MCU_DEM_WRAPPER_AR_RELEASE_MAJOR_VERSION_C    != MCU_DEM_WRAPPER_AR_RELEASE_MAJOR_VERSION) || \
     (MCU_DEM_WRAPPER_AR_RELEASE_MINOR_VERSION_C    != MCU_DEM_WRAPPER_AR_RELEASE_MINOR_VERSION) || \
     (MCU_DEM_WRAPPER_AR_RELEASE_REVISION_VERSION_C != MCU_DEM_WRAPPER_AR_RELEASE_REVISION_VERSION) \
    )
    #error "AutoSar Version Numbers of Mcu_Dem_Wrapper.c and Mcu_Dem_Wrapper.h are different"
#endif

/* Check if current file and Mcu_Dem_Wrapper header file are of the same software version */
#if ((MCU_DEM_WRAPPER_SW_MAJOR_VERSION_C != MCU_DEM_WRAPPER_SW_MAJOR_VERSION) || \
     (MCU_DEM_WRAPPER_SW_MINOR_VERSION_C != MCU_DEM_WRAPPER_SW_MINOR_VERSION) || \
     (MCU_DEM_WRAPPER_SW_PATCH_VERSION_C != MCU_DEM_WRAPPER_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of Mcu_Dem_Wrapper.c and Mcu_Dem_Wrapper.h are different"
#endif



/*==================================================================================================
                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/

/*==================================================================================================
                                       LOCAL CONSTANTS
==================================================================================================*/

/*==================================================================================================
                                       LOCAL VARIABLES
==================================================================================================*/

/*==================================================================================================
                                       GLOBAL CONSTANTS
==================================================================================================*/

/*==================================================================================================
                                       GLOBAL VARIABLES
==================================================================================================*/

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

/*==================================================================================================
                                       LOCAL FUNCTIONS
==================================================================================================*/

/*==================================================================================================
                                       GLOBAL FUNCTIONS
==================================================================================================*/
#define MCU_START_SEC_CODE
/**
* @violates @ref Mcu_Dem_Wrapper_h_REF_2 Precautions shall be taken in order to prevent the contents
* of a header file being included more than once.
*/
#include "Mcu_MemMap.h"


#if (MCU_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
/**
* @brief    Reports timeout error to DEM.
* @details  Checks if the timeout expired and reports the timeout error to DEM if that is the case.
*
* @param[in]  u32Timeout  Maximum timeout to be waited.
*
* @return     void.
*/
FUNC (void, MCU_CODE) Mcu_ReportDemTimeoutError(CONST(uint32, AUTOMATIC) u32Timeout)
{
    if ((uint32)0x0U == u32Timeout)
    {
        if ((uint32)STD_ON == Mcu_pDemCfgPtr->Mcu_E_TimeoutFailureCfg.state)
        {
            /* According to requirement [SWS_Dem_00183] from the ASR 4.3.1 "AUTOSAR_SWS_DiagnosticEventManager" document,
             * "BSW modules calling Dem_SetEventStatus can safely ignore the return value." */
            (void)Dem_SetEventStatus((Dem_EventIdType)Mcu_pDemCfgPtr->Mcu_E_TimeoutFailureCfg.id, DEM_EVENT_STATUS_FAILED);
        }
    }
 }
#endif


#define MCU_STOP_SEC_CODE
/**
* @violates @ref Mcu_Dem_Wrapper_h_REF_1 #include directives should only be preceded by preprocessor
* directives or comments.
*
* @violates @ref Mcu_Dem_Wrapper_h_REF_2 Precautions shall be taken in order to prevent the contents
* of a header file being included more than once.
*/
#include "Mcu_MemMap.h"


#ifdef __cplusplus
}
#endif

/** @} */
