/**
*   @file    Adc_Siu.c
*   @version 1.0.0
*
*   @brief   AUTOSAR Adc SIU source file support for ADC driver.
*   @details This file is the SIU ADC low level driver code.
*
*   @addtogroup ADC_SIU
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : EQADC
*   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 Adc_Siu_c_REF_1
*          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
*          Adc_MemMap.h is as per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section Adc_Siu_c_REF_2
*          Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor
*          directives or comments. Adc_MemMap.h is included after each section define in order to set the current
*          memory section as defined by AUTOSAR
*
* @section Adc_Siu_c_REF_3
*          Violates MISRA 2012 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type.
*          The cast is used to access memory mapped registers.
*
* @section Adc_Siu_c_REF_4
*          Violates MISRA 2012 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type.
*          This macro computes the address of any register by using the hardware offset of the controller.
*          The address calculated as an unsigned int is passed to a macro for initializing the pointer with that address.
*
* @section Adc_Siu_c_REF_5
*          Violates MISRA 2012 Required Rule 10.8, The value of a composite expression shall not be cast to a different essential type category or a wider essential type.
*          This rule is only violated where the base address of the instance has to be selected according to the instance number.
*
* @section Adc_Siu_c_REF_6
*          Violates MISRA 2012 Advisory Rule 8.7,Functions and objects should not be defined with external linkage if they are referenced in only one translation unit.
*          This function needs external linkage if interrupts are enabled in the configuration.
*
* @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 name space 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.
*
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Adc_Siu.h"
#define USER_MODE_REG_PROT_ENABLED      (ADC_USER_MODE_REG_PROT_ENABLED)
#include "SilRegMacros.h"
#include "Adc_Reg_eSys_Siu.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define ADC_SIU_VENDOR_ID_C                    43
#define ADC_SIU_AR_RELEASE_MAJOR_VERSION_C     4
#define ADC_SIU_AR_RELEASE_MINOR_VERSION_C     3
#define ADC_SIU_AR_RELEASE_REVISION_VERSION_C  1
#define ADC_SIU_SW_MAJOR_VERSION_C             1
#define ADC_SIU_SW_MINOR_VERSION_C             0
#define ADC_SIU_SW_PATCH_VERSION_C             0

/*==================================================================================================
                                      FILE VERSION CHECKS
==================================================================================================*/
/* Adc_Siu.h version check start */
#if ((ADC_SIU_AR_RELEASE_MAJOR_VERSION_C != ADC_SIU_AR_RELEASE_MAJOR_VERSION) || \
     (ADC_SIU_AR_RELEASE_MINOR_VERSION_C != ADC_SIU_AR_RELEASE_MINOR_VERSION) || \
     (ADC_SIU_AR_RELEASE_REVISION_VERSION_C != ADC_SIU_AR_RELEASE_REVISION_VERSION) \
    )
    #error "AUTOSAR Version Numbers of Adc_Siu.c and Adc_Siu.h are different"
#endif

#if ((ADC_SIU_SW_MAJOR_VERSION_C != ADC_SIU_SW_MAJOR_VERSION) || \
     (ADC_SIU_SW_MINOR_VERSION_C != ADC_SIU_SW_MINOR_VERSION) || \
     (ADC_SIU_SW_PATCH_VERSION_C != ADC_SIU_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of Adc_Siu.c and Adc_Siu.h are different"
#endif

#if (ADC_SIU_VENDOR_ID_C != ADC_SIU_VENDOR_ID)
    #error "VENDOR ID for Adc_Siu.c and Adc_Siu.h is different"
#endif
/* Adc_Siu.h version check end */

/* SilRegMacros.h version check start */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  #if ((ADC_SIU_AR_RELEASE_MAJOR_VERSION_C != SILREGMACROS_AR_RELEASE_MAJOR_VERSION) || \
       (ADC_SIU_AR_RELEASE_MINOR_VERSION_C != SILREGMACROS_AR_RELEASE_MINOR_VERSION) \
      )
      #error "AUTOSAR Version Numbers of Adc_Siu.c and SilRegMacros.h are different"
  #endif
#endif
/* SilRegMacros.h version check end */

/* Adc_Reg_eSys_Siu.h version check start */
#if ((ADC_SIU_AR_RELEASE_MAJOR_VERSION_C != ADC_REGESYS_SIU_AR_RELEASE_MAJOR_VERSION_REG) || \
     (ADC_SIU_AR_RELEASE_MINOR_VERSION_C != ADC_REGESYS_SIU_AR_RELEASE_MINOR_VERSION_REG) || \
     (ADC_SIU_AR_RELEASE_REVISION_VERSION_C != ADC_REGESYS_SIU_AR_RELEASE_REVISION_VERSION_REG) \
    )
    #error "AUTOSAR Version Numbers of Adc_Siu.c and Adc_Reg_eSys_Siu.h are different"
#endif

#if ((ADC_SIU_SW_MAJOR_VERSION_C != ADC_REGESYS_SIU_SW_MAJOR_VERSION_REG) || \
     (ADC_SIU_SW_MINOR_VERSION_C != ADC_REGESYS_SIU_SW_MINOR_VERSION_REG) ||\
     (ADC_SIU_SW_PATCH_VERSION_C != ADC_REGESYS_SIU_SW_PATCH_VERSION_REG) \
    )
    #error "Software Version Numbers of Adc_Siu.c and Adc_Reg_eSys_Siu.h are different"
#endif

#if (ADC_SIU_VENDOR_ID_C != ADC_REGESYS_SIU_VENDOR_ID_REG)
    #error "VENDOR ID for Adc_Siu.c and Adc_Reg_eSys_Siu.h is different"
#endif
/* Adc_Reg_eSys_Siu.h version check end */

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

/*==================================================================================================
*                                       LOCAL MACROS
==================================================================================================*/

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

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

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

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

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

/*==================================================================================================
*                                       LOCAL FUNCTIONS
==================================================================================================*/
#if (STD_ON == ADC_HW_TRIGGER_API)
#define ADC_START_SEC_CODE
/** @violates @ref Adc_Siu_c_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
#include "Adc_MemMap.h"

/*==================================================================================================
                                       GLOBAL FUNCTIONS
==================================================================================================*/
/**
* @brief          This function reset all HW triggers.
* @details        This function reset all HW triggers.
*
* @return         void
*/
/** @violates @ref Adc_Siu_c_REF_6 Functions and objects should not be defined with external linkage if they are
*referenced in only one translation unit.*/
FUNC(void, ADC_CODE) Adc_Siu_ResetAllHwTrigger(void)
{
    /* set SIU_ISEL(4-7) default reset value */
    /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
    /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
    REG_WRITE32(SIU_ISEL4_REG_ADDR32, EQADC_REG32_RESET_VALUE_U32);
    /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
    /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
    REG_WRITE32(SIU_ISEL5_REG_ADDR32, EQADC_REG32_RESET_VALUE_U32);
    /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
    /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
    REG_WRITE32(SIU_ISEL6_REG_ADDR32, EQADC_REG32_RESET_VALUE_U32);
    /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
    /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
    REG_WRITE32(SIU_ISEL7_REG_ADDR32, EQADC_REG32_RESET_VALUE_U32);
}

/**
* @brief          This function enable an HW trigger.
* @details        This function enable an HW trigger.
*
* @param[in]      u16HwResource - Pointer to group configuration
* @param[in]      u8EqadcIdx - eQADCA or eQADCB
* @param[in]      u8Fifo - Fifo number
*
* @return         void
*
*/
FUNC(void, ADC_CODE) Adc_Siu_EnableHwTrigger
(
    VAR(uint16, AUTOMATIC) u16HwResource,
    VAR(uint8, AUTOMATIC) u8EqadcIdx,
    VAR(uint8, AUTOMATIC) u8Fifo
)
{
    if (u8EqadcIdx == (uint8)ADC_EQADC_A)
    {
        /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
        /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
        /** @violates @ref Adc_Siu_c_REF_5 The value of a composite expression shall not be cast to a different essential type category*/
        REG_WRITE8((SIU_ISEL4_REG_ADDR32 + (uint32)(5UL - (uint32)u8Fifo)), (uint8)u16HwResource);
    }
    else
    {
        /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
        /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
        /** @violates @ref Adc_Siu_c_REF_5 The value of a composite expression shall not be cast to a different essential type category*/
        REG_WRITE8((SIU_ISEL6_REG_ADDR32 + (uint32)(5UL - (uint32)u8Fifo)), (uint8)u16HwResource);
    }
}

/**
* @brief          This function disable an HW trigger.
* @details        This function disable an HW trigger.
*
* @param[in]      u8EqadcIdx - eQADCA or eQADCB
* @param[in]      u8Fifo - Fifo number
*
* @return         void
*
*/
FUNC(void, ADC_CODE) Adc_Siu_DisableHwTrigger
(
    VAR(uint8, AUTOMATIC) u8EqadcIdx,
    VAR(uint8, AUTOMATIC) u8Fifo
)
{
    /* Reset the trigger source */
    if (u8EqadcIdx == (uint8)ADC_EQADC_A)
    {
        /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
        /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
        /** @violates @ref Adc_Siu_c_REF_5 The value of a composite expression shall not be cast to a different essential type category*/        
        REG_WRITE8((SIU_ISEL4_REG_ADDR32 + (uint32)(5UL - (uint32)u8Fifo)), SIU_REG8_RESET_VALUE_U8);
    }
    else
    {
        /** @violates @ref Adc_Siu_c_REF_3 A conversion should not be performed between a pointer to object and an integer type.*/
        /** @violates @ref Adc_Siu_c_REF_4 A cast shall not be performed between pointer to void and an arithmetic type.*/
        /** @violates @ref Adc_Siu_c_REF_5 The value of a composite expression shall not be cast to a different essential type category*/
        REG_WRITE8((SIU_ISEL6_REG_ADDR32 + (uint32)(5UL - (uint32)u8Fifo)), SIU_REG8_RESET_VALUE_U8);
    }
}

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

#endif /* (STD_ON == ADC_HW_TRIGGER_API) */

#ifdef __cplusplus
}
#endif

/** @} */
