/**
*   @file           Mcem_DemErrors.h
*
*   @version 1.0.0
*
*   @brief   AUTOSAR Mcem - MCEM extended DEM reporting mechanism header file
*   @details Declaration of the variables and functions part of MCEM extended DEM reporting mechanism.
*
*   @addtogroup MCEM_MODULE
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : Fccu
*   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-2018 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef MCEM_DEM_ERRORS_H
#define MCEM_DEM_ERRORS_H

#ifdef __cplusplus
extern "C"{
#endif

/**
 *
 * @page misra_violations MISRA-C:2004 violations
 *
 * @section Mcem_DemErrors_h_REF_1
 * Violates MISRA 2004 Required Rule 19.15, Precautions shall be taken in order to prevent the
 * contents of a header file being included twice
 * This is not a violation since all header files are protected against multiple inclusions
 *
 * @section Mcem_DemErrors_h_REF_2
 * Violates MISRA 2004 Advisory Rule 19.7, A function should be used in preference to a function-like
 * macro. Compiler abstraction need to implement function-like macros to hide compiler specifics from
 * the implementation.
 *
 * @section Mcem_DemErrors_h_REF_3
 * Violates MISRA 2004 Required Rule 19.4, C macros shall only expand to a braced initialiser, a constant, a
 * parenthesised expression, a type qualifier, a storage class specifier, or a do-while-zero construct
 * This is used to abstract compiler specific encapsulation of definitions and declarations
 *
 * @section Mcem_DemErrors_h_REF_4
 * Violates MISRA 2004 Required Rule 19.10, In the definition of a function-like macro each instance of a
 * parameter shall be enclosed in parentheses unless it is used as * the operand of # or ##.
 * This is used to abstract compiler specific encapsulation of definitions and declarations
 *
 * @section Mcem_DemErrors_h_REF_5
 * Violates MISRA 2004 Advisory Rule 19.13, The # and ## preprocessor operators should not be used.
 * This is used to abstract the fault injection mechanism which inserts labels in the asm code.
 *
 * @section Mcem_DemErrors_h_REF_6
 * Violates MISRA 2004 Required Rule 1.4, The compiler/linker shall be checked to ensure
 * that 31 character significance and case sensitivity are supported for external identifiers.
 * The used compilers/linkers allow more than 31 characters significance for external identifiers.
 *
 * @section Mcem_DemErrors_h_REF_7
 * Violates MISRA 2004 Required Rule 8.8, An external object or function shall be declared 
 * in one and only one file.
 * These objects are used in several files in the code.
 *
 * @section [global]
 * Violates MISRA 2004 Required Rule 5.1, Exceeds 31 characters due to AUTOSAR compatibility
 */

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

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define MCEM_DEM_ERRORS_VENDOR_ID                    43
#define MCEM_DEM_ERRORS_MODULE_ID                    0
#define MCEM_DEM_ERRORS_AR_RELEASE_MAJOR_VERSION     4
#define MCEM_DEM_ERRORS_AR_RELEASE_MINOR_VERSION     3
#define MCEM_DEM_ERRORS_AR_RELEASE_REVISION_VERSION  1
#define MCEM_DEM_ERRORS_SW_MAJOR_VERSION             1
#define MCEM_DEM_ERRORS_SW_MINOR_VERSION             0
#define MCEM_DEM_ERRORS_SW_PATCH_VERSION             0

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

/* Check if current file and CDD_.h header file are of the same vendor */
#if (MCEM_DEM_ERRORS_VENDOR_ID != CDD_MCEM_VENDOR_ID_CFG)
#error "Mcem_DemErrors.h and CDD_.h have different vendor ids"
#endif
/* Check if current file and CDD_.h header file are of the same Autosar version */
#if ((MCEM_DEM_ERRORS_AR_RELEASE_MAJOR_VERSION    != CDD_MCEM_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (MCEM_DEM_ERRORS_AR_RELEASE_MINOR_VERSION    != CDD_MCEM_AR_RELEASE_MINOR_VERSION_CFG) || \
     (MCEM_DEM_ERRORS_AR_RELEASE_REVISION_VERSION != CDD_MCEM_AR_RELEASE_REVISION_VERSION_CFG))
#error "AutoSar Version Numbers of Mcem_DemErrors.h and CDD_.h are different"
#endif
/* Check if current file and CDD_.h header file are of the same Software version */
#if ((MCEM_DEM_ERRORS_SW_MAJOR_VERSION != CDD_MCEM_SW_MAJOR_VERSION_CFG) || \
     (MCEM_DEM_ERRORS_SW_MINOR_VERSION != CDD_MCEM_SW_MINOR_VERSION_CFG) || \
     (MCEM_DEM_ERRORS_SW_PATCH_VERSION != CDD_MCEM_SW_PATCH_VERSION_CFG))
#error "Software Version Numbers of Mcem_DemErrors.h and CDD_.h are different"
#endif

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


/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/
/* Macro for updating the nReturnValue variable in the called function with a DEM identifier derived
from a current return value base */
/** @violates @ref Mcem_DemErrors_h_REF_2 A function should be used in preference to a function-like macro. */
/** @violates @ref Mcem_DemErrors_h_REF_3 C macros shall only expand to a braced initialiser, a constant, a parenthesised expression */
#define Mcem_ExtendRetValForDem(retVal, demIdBase) \
       ((uint8)(((retVal) == 0x0U) ? (0x0U) : ((((demIdBase) - 0x1U)) + (retVal))))

/* Defines for the the IDs of the FPs (Failure Points) in a function - correspond to the returned value when 
   MCEM_DEM_EXTENDED_DATA is STD_ON */
/* --- HLD layer functions ---------------------------------------- */
/* FP IDs for Mcem_Init() */
#define ID_MCEM_INIT_FP1_U8                             ((uint8)1U)
#define ID_MCEM_INIT_FP2_U8                             ((uint8)17U)
/* FP IDs for Mcem_PeriodicChecks() */
#define ID_MCEM_PERIODIC_CHECKS_FP1_U8                  ((uint8)1U)
/* FP IDs for Mcem_GetErrors */
#define ID_MCEM_GET_ERRORS_FP1_U8                       ((uint8)1U)
/* FP IDs for Mcem_ClearFaults */
#define ID_MCEM_CLEAR_FAULTS_FP1_U8                     ((uint8)3U)

/* --- IPW layer functions --------------------------------------- */
#define ID_MCEM_IPW_INIT_FP1_U8                         ((uint8)1U)
#define ID_MCEM_IPW_GET_ERRORS_FP1_U8                   ((uint8)1U)
#define ID_MCEM_IPW_CLEAR_FAULT_FP1_U8                  ((uint8)1U)
#define ID_MCEM_IPW_CLEAR_FAULT_FP2_U8                  ((uint8)6U)

/* --- IP layer functions - FCCU --------------------------------- */
/* FP IDs for Mcem_Fccu_Init() */
#define ID_MCEM_FCCU_INIT_FP1_U8                        ((uint8)1U)
#define ID_MCEM_FCCU_INIT_FP3_LOOPx_U8                  ((uint8)3U)
#define ID_MCEM_FCCU_INIT_FP4_LOOPx_U8                  ((uint8)4U)
#define ID_MCEM_FCCU_INIT_FP5_U8                        ((uint8)5U)
#define ID_MCEM_FCCU_INIT_FP7_U8                        ((uint8)7U)
#define ID_MCEM_FCCU_INIT_FP9_U8                        ((uint8)9U)
#define ID_MCEM_FCCU_INIT_FP11_U8                       ((uint8)11U)

/* FP IDs for Mcem_Fccu_PeriodicCheck */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP1_U8              ((uint8)1U)
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP2_U8              ((uint8)2U)
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP3_U8              ((uint8)3U)
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP4_U8              ((uint8)4U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP5_LOOPx_U8        ((uint8)5U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP6_LOOPx_U8        ((uint8)6U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP7_LOOPx_U8        ((uint8)7U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP8_LOOPx_U8        ((uint8)8U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP9_LOOPx_U8        ((uint8)9U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP10_LOOPx_U8       ((uint8)10U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_PERIODIC_CHECK_FP11_LOOPx_U8       ((uint8)11U)
/* FP IDs for Mcem_Fccu_ExecuteOperation */
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_EXECUTE_OPERATION_FP1_U8           ((uint8)1U)
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_EXECUTE_OPERATION_FP2_U8           ((uint8)2U)
/* FP IDs for Fccu_TestAndLockFCCUAccess */
/** @violates @ref Mcem_DemErrors_h_REF_6 The used compilers use more than 31 chars for identifiers. */
#define ID_MCEM_FCCU_TEST_AND_LOCK_ACCESS_FP1_U8        ((uint8)1U)
/* FP IDs for Mcem_Fccu_WaitToComplete */
#define ID_MCEM_FCCU_WAIT_TO_COMPLETE_FP1_U8            ((uint8)1U)
/* FP IDs for Mcem_Fccu_GetErrors */
#define ID_MCEM_FCCU_GET_ERRORS_FP1_U8                  ((uint8)1U)
/* FP IDs for Mcem_Fccu_ClearFault */
#define ID_MCEM_FCCU_CLEAR_FAULT_FP1_U8                 ((uint8)1U)
#define ID_MCEM_FCCU_CLEAR_FAULT_FP2_U8                 ((uint8)3U)
#define ID_MCEM_FCCU_CLEAR_FAULT_FP3_U8                 ((uint8)4U)
#define ID_MCEM_FCCU_CLEAR_FAULT_FP4_U8                 ((uint8)5U)

/* --- IP layer functions - MEMU --------------------------------- */
#define ID_MCEM_MEMU_CLEAR_FAULT_FP1_U8                 ((uint8)1U)

/* Defines for the valid length of the information in the Dem extended data structure */
#define MCEM_DEM_EXT_DATA_LENGTH_2BYTES_U8              ((uint8)2U)
#define MCEM_DEM_EXT_DATA_LENGTH_3BYTES_U8              ((uint8)3U)
#define MCEM_DEM_EXT_DATA_LENGTH_8BYTES_U8              ((uint8)8U)

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


/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
#if (STD_ON == MCEM_DEM_EXTENDED_DATA)
    /* Structure defining the DEM extended data kept internally by the Mcem driver and reported to
    upper layer through call of Dem_ReportErrorStatusPreExtData() API, when a runtime error occurs */
    typedef struct
    {
        VAR(uint8,  AUTOMATIC) u8FpId;
        VAR(uint8,  AUTOMATIC) u8Loop;
        VAR(uint8,  AUTOMATIC) au8ExtendedData[2];
        VAR(uint32, AUTOMATIC) u32ExtendedData;
    }Mcem_DemExtDataType;
    
    /* Define the data type of the value returned by the Mcem functions containing value of the FPs */
    typedef uint8           Mcem_ReturnType;
#else
    /* Define the data type of the value returned by the Mcem functions when DEM extended reporting
    mechanism is not enabled */
    typedef Std_ReturnType  Mcem_ReturnType;
#endif /* STD_ON == MCEM_DEM_EXTENDED_DATA */

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/
#if (STD_ON == MCEM_DEM_EXTENDED_DATA)

#define MCEM_START_SEC_VAR_NO_INIT_UNSPECIFIED
/* @violates @ref Mcem_DemErrors_h_REF_1 precautions to prevent the contents of a header file being included twice. */
#include "Mcem_MemMap.h"

    /* DEM extended data kept internally by the Mcem driver and reported to upper layer through call
    of Dem_ReportErrorStatusPreExtData() API, when a runtime error occurs */
    /** @violates @ref Mcem_DemErrors_h_REF_7  External object declared more than once*/
    extern VAR(Mcem_DemExtDataType, MCEM_VAR) Mcem_DemExtData;

#define MCEM_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
/* @violates @ref Mcem_DemErrors_h_REF_1 precautions to prevent the contents of a header file being included twice. */
#include "Mcem_MemMap.h"
        
#define MCEM_START_SEC_VAR_NO_INIT_8
/* @violates @ref Mcem_DemErrors_h_REF_1 precautions to prevent the contents of a header file being included twice. */
#include "Mcem_MemMap.h"

    /* Variable storing the lenght of the valid information inside DEM extended data structure above */
    /** @violates @ref Mcem_DemErrors_h_REF_7  External object declared more than once*/
    extern VAR(uint8, MCEM_VAR) u8DemExtDataLength;

#define MCEM_STOP_SEC_VAR_NO_INIT_8
/* @violates @ref Mcem_DemErrors_h_REF_1 precautions to prevent the contents of a header file being included twice. */
#include "Mcem_MemMap.h"

#endif /* STD_ON == MCEM_DEM_EXTENDED_DATA */

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

#ifdef __cplusplus
}
#endif

#endif /*MCEM_DEM_ERRORS_H*/

/** @} */
