/**
*   @file    IoDal.c
*   @version 1.0.0
*
*   @brief   Integration Framework - IO Driver Abstraction Layer component configuration file
*   @details This file implements the IODAL configuration interface to application layer.
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2018 NXP
*   All Rights Reserved.
*   This file contains sample code only. It is not part of the production code deliverables.
*
*/
/*=========================================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   
*   SW Version           : 1.0.0
*   Build Version        : MPC5777CXG_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190318
*
============================================================================================================================*/
/*============================================================================================================================
==============================================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif


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

/*===================================================================================================================
*                              SOURCE FILE VERSION INFORMATION
====================================================================================================================*/
#define IODAL_PBCFG_VENDOR_ID_C                       43

#define IODAL_PBCFG_AR_RELEASE_MAJOR_VERSION_C        4
#define IODAL_PBCFG_AR_RELEASE_MINOR_VERSION_C        3
#define IODAL_PBCFG_AR_RELEASE_REVISION_VERSION_C     1

#define IODAL_PBCFG_SW_MAJOR_VERSION_C                1
#define IODAL_PBCFG_SW_MINOR_VERSION_C                0
#define IODAL_PBCFG_SW_PATCH_VERSION_C                0

/*===================================================================================================================
*                                     FILE VERSION CHECKS
====================================================================================================================*/
/* Check if source file and IoDal_Cfg.h header file are of the same vendor */
#if (IODAL_PBCFG_VENDOR_ID_C != IODAL_CFG_VENDOR_ID)
    #error "IoDal.c and IoDal_Cfg.h have different vendor ids"
#endif

/* Check if source file and IoDal_Cfg.h header file are of the same Autosar version */
#if ((IODAL_PBCFG_AR_RELEASE_MAJOR_VERSION_C != IODAL_CFG_AR_RELEASE_MAJOR_VERSION) || \
     (IODAL_PBCFG_AR_RELEASE_MINOR_VERSION_C != IODAL_CFG_AR_RELEASE_MINOR_VERSION) || \
     (IODAL_PBCFG_AR_RELEASE_REVISION_VERSION_C != IODAL_CFG_AR_RELEASE_REVISION_VERSION) \
    )
    #error "AutoSar Version Numbers of IoDal.c and IoDal_Cfg.h are different"
#endif

/* Check if source file and IoDal_Cfg.h header file are of the same Software version */
#if ((IODAL_PBCFG_SW_MAJOR_VERSION_C != IODAL_CFG_SW_MAJOR_VERSION) || \
     (IODAL_PBCFG_SW_MINOR_VERSION_C != IODAL_CFG_SW_MINOR_VERSION) || \
     (IODAL_PBCFG_SW_PATCH_VERSION_C != IODAL_CFG_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of IoDal.c and IoDal_Cfg.h are different"
#endif


/* Check if source file and IoDal_Drv_Cfg.h header file are of the same vendor */
#if (IODAL_PBCFG_VENDOR_ID_C != IODAL_DRV_CFG_VENDOR_ID)
    #error "IoDal.c and IoDal_Drv_Cfg.h have different vendor ids"
#endif

/* Check if source file and IoDal_Drv_Cfg.h header file are of the same Autosar version */
#if ((IODAL_PBCFG_AR_RELEASE_MAJOR_VERSION_C != IODAL_DRV_CFG_AR_RELEASE_MAJOR_VERSION) || \
     (IODAL_PBCFG_AR_RELEASE_MINOR_VERSION_C != IODAL_DRV_CFG_AR_RELEASE_MINOR_VERSION) || \
     (IODAL_PBCFG_AR_RELEASE_REVISION_VERSION_C != IODAL_DRV_CFG_AR_RELEASE_REVISION_VERSION) \
    )
    #error "AutoSar Version Numbers of IoDal.c and IoDal_Drv_Cfg.h are different"
#endif

/* Check if source file and IoDal_Drv_Cfg.h header file are of the same Software version */
#if ((IODAL_PBCFG_SW_MAJOR_VERSION_C != IODAL_DRV_CFG_SW_MAJOR_VERSION) || \
     (IODAL_PBCFG_SW_MINOR_VERSION_C != IODAL_DRV_CFG_SW_MINOR_VERSION) || \
     (IODAL_PBCFG_SW_PATCH_VERSION_C != IODAL_DRV_CFG_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of IoDal.c and IoDal_Drv_Cfg.h are different"
#endif



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

#define    IODAL_MAX_CHANNELS_HW_VAR_0                7U

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


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


/*==================================================================================================
                                       LOCAL VARIABLES
==================================================================================================*/
static Adc_ValueGroupType IoDal_AniDescriptor_AdcGroup_0_HW_VAR_0[1]    =    {0};

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


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

/*Critical Note: A BSW analog input using SW trigger can only reference TT elements FROM ONE TABLE... 
               if analog inputs use different OCU channels/TT Table than the generation tool should report an Error.
            
                The  Time-Triggered Table used by Analog input has the exact size determined by the number of inputs that have as referees
                entries in the TT Tab
                Basically if a user defines 10 entries and only uses 5 inputs than the size of the OcuTimeTable will be 5 and only the entries referenced will be printed in the Table; all other will be ignored.
 */
           

/*Entries for TimeTriggerTable_0 scheduling points NOT used as SW trigger by ADC*/
static CONST(uint32, IODAL_CONST) IoDal_OcuTimeTable_TimeTriggerTable_0_HW_VAR_0[1] = {100};

/*SYNC PWM HW CONFIGURATIONS*/


#if(IODAL_DIO_EXT_DEV == STD_ON)
#endif

#if IODAL_MAX_DIO_CHANNELS_HW_VAR_0 > 0U
/*DIO Channel descriptor*/
static CONST(IoDal_DigitalDescriptorType, IODAL_CONST) IoDal_DioChannelDescriptor_HW_VAR_0[IODAL_MAX_DIO_CHANNELS_HW_VAR_0] =
{ 
    {
        DioConf_DioChannel_Dio_DigKey1,        /*DIO Channel ID*/
        STD_LOW,
        NULL_PTR        /*External Device*/    
    },
 
    {
        DioConf_DioChannel_Dio_out1,        /*DIO Channel ID*/
        STD_LOW,
        NULL_PTR        /*External Device*/    
    },
 
    {
        DioConf_DioChannel_Dio_PwmKey2,        /*DIO Channel ID*/
        STD_LOW,
        NULL_PTR        /*External Device*/    
    }
};
#endif

#if IODAL_MAX_PWM_CHANNELS_HW_VAR_0 > 0U
/*PWM Channel descriptor*/
static CONST(IoDal_PwmDescriptorType, IODAL_CONST) IoDal_PwmChannelDescriptor_HW_VAR_0[IODAL_MAX_PWM_CHANNELS_HW_VAR_0] =
{ 
    {
        PwmChannel_0,        /*PWM Channel ID*/ 
        NULL_PTR,                /*Sync FTM not used. No additional configuration required*/
        NULL_PTR        /*External Device*/
    },
 
    {
        PwmChannel_1,        /*PWM Channel ID*/ 
        NULL_PTR,                /*Sync FTM not used. No additional configuration required*/
        NULL_PTR        /*External Device*/
    }
};
#endif

#if IODAL_MAX_MOTOR_BRIDGE_OUTPUT_DESCRIPTORS > 0U
/*PWM Channel descriptor*/
static CONST(IoDal_MotorBridgeDescriptorType, IODAL_CONST) IoDal_BridgeDescriptor_HW_VAR_0[IODAL_MAX_MOTOR_BRIDGES_HW_VAR_0] =
{
};
#endif

#if IODAL_MAX_ANALOG_CHANNELS_HW_VAR_0 > 0U
/*Analog Channel descriptor*/
static CONST(IoDal_AnalogDescriptorType, IODAL_CONST) IoDal_AdcChannelDescriptor_HW_VAR_0[IODAL_MAX_ANALOG_CHANNELS_HW_VAR_0] =
{ 
    {
        AdcGroup_0,        /*ADC Group ID*/     
        0,         /*ADC Channel Position in the ADC AdcGroup_0 Group definition*/
        250,        /*ADC Conversion Time(in ticks)*/
        IoDal_AniDescriptor_AdcGroup_0_HW_VAR_0,    /**ADC result data array */
        0    /*Time trigger entry index within IoDal_OcuTimeTable_*_HW_VAR_0*/            
    }

};
#endif

#if  IODAL_MAX_ICU_CHANNELS_HW_VAR_0 > 0U
/*ICU Channel descriptor*/
static CONST(IoDal_IcuDescriptorType, IODAL_CONST) IoDal_IcuChannelDescriptor_HW_VAR_0[IODAL_MAX_ICU_CHANNELS_HW_VAR_0] =
{};
#endif

#if  IODAL_MAX_OCU_CHANNELS_HW_VAR_0 > 0U
/*OCU Channel descriptor*/
static CONST(IoDal_OcuDescriptorType, IODAL_CONST) IoDal_OcuChannelDescriptor_HW_VAR_0[IODAL_MAX_OCU_CHANNELS_HW_VAR_0] =
{ 
    {
        OcuChannel_0,        /*OCU Channel ID*/
        1,        /*Size of the timetable*/
        IoDal_OcuTimeTable_TimeTriggerTable_0_HW_VAR_0
    }
};
#endif

/*Mapping of BSW Channels to Specific Channel Descriptors*/
static CONST(IoDal_BswChannelMapType, IODAL_CONST) IoDal_BswChannelMap_HW_VAR_0[IODAL_MAX_CHANNELS_HW_VAR_0] = 
{    /*IoDal_Dio_Key1*/
    {
        IODAL_DIO_INPUT,        /*Datatype of current channel*/
        0        /*Index of current channel in own Datatype Channel Descriptor*/
    },    
    /*IoDal_Dio_Out1*/
    {
        IODAL_DIO_OUTPUT,        /*Datatype of current channel*/
        1        /*Index of current channel in own Datatype Channel Descriptor*/
    },    
    /*IoDal_Ocu_Trigger*/
    {
        IODAL_TIMER_OUTPUT,        /*Datatype of current channel*/
        0        /*Index of current channel in own Datatype Channel Descriptor*/
    },    
    /*IoDal_Adc_Pot*/
    {
        IODAL_ANALOG_SW_TRIG,        /*Datatype of current channel*/
        0        /*Index of current channel in own Datatype Channel Descriptor*/
    },    
    /*IoDal_Pwm_Out1*/
    {
        IODAL_PWM_FIXED_PERIOD_OUTPUT,        /*Datatype of current channel*/
        0        /*Index of current channel in own Datatype Channel Descriptor*/
    },    
    /*IoDal_Pwm_Key2*/
    {
        IODAL_DIO_INPUT,        /*Datatype of current channel*/
        2        /*Index of current channel in own Datatype Channel Descriptor*/
    },    
    /*IoDal_Pwm_Out2*/
    {
        IODAL_PWM_FIXED_PERIOD_OUTPUT,        /*Datatype of current channel*/
        1        /*Index of current channel in own Datatype Channel Descriptor*/
    }    
};

/*=====================================================================================================================*/
/**
@brief      IoDal_AdcBufferSetup - callout to initialize ADC buffers
@details    This function is used to setup external buffers for ADC results for each configured ADC group

@return     void

@pre None
@post None
*/
/*=====================================================================================================================*/
FUNC(void, IODAL_APP_CODE) IoDal_AdcBufferSetup(void)
{
    (void)Adc_SetupResultBuffer(AdcGroup_0, &IoDal_AniDescriptor_AdcGroup_0_HW_VAR_0[0]);
}

CONST(IoDal_BswIoConfigType, IODAL_CONST) IoDal_Config[IODAL_MAX_HW_VARIANTS] = 
{    
    {
        1, /*Number of Analog channels*/
        0, /*Index of Analog SW Trigger descriptor*/
        2, /*Number of Pwm channels*/
        3, /*Number of Digital channels*/
        1, /*Number of Output Compare  channels*/
        0, /*Number of input Capture channels*/
        0, /*Number of HW Bridges connected to uC*/        
#ifdef IFWK_USE_ADC
        IoDal_AdcChannelDescriptor_HW_VAR_0,
        &IoDal_AdcBufferSetup,
#endif
#ifdef IFWK_USE_PWM
        IoDal_PwmChannelDescriptor_HW_VAR_0,
#endif
#ifdef IFWK_USE_DIO        
        IoDal_DioChannelDescriptor_HW_VAR_0,
#endif
#ifdef IFWK_USE_OCU        
        IoDal_OcuChannelDescriptor_HW_VAR_0,
#endif
#ifdef IFWK_USE_ICU        
        IoDal_IcuChannelDescriptor_HW_VAR_0,
#endif
#ifdef IFWK_USE_BRIDGE_DEV
       IoDal_BridgeDescriptor_HW_VAR_0,
#endif     
        IoDal_BswChannelMap_HW_VAR_0
    }    
};

