/***********************************************************************************************************************
 *  COPYRIGHT
 *  --------------------------------------------------------------------------------------------------------------------
 *  \verbatim
 *                 TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
 *
 *                 Property of Texas Instruments, Unauthorized reproduction and/or distribution
 *                 is strictly prohibited.  This product  is  protected  under  copyright  law
 *                 and  trade  secret law as an  unpublished work.
 *                 (C) Copyright Texas Instruments - 2014.  All rights reserved.
 *
 *  \endverbatim
 *  --------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  --------------------------------------------------------------------------------------------------------------------
 *  File:         Adc_PBcfg.c
 *  Project:      Tms570_AutosarAdcDriver
 *  Module:       AdcDriver
 *  Generator:    EB Tresos
 *
 *
 *  Description:  The Adc Driver provides the low level functions for the Adc Module.
 *---------------------------------------------------------------------------------------------------------------------
 * Author:  Vishwanath Reddy
 *---------------------------------------------------------------------------------------------------------------------
 * Templete Revision History
 *---------------------------------------------------------------------------------------------------------------------
 * Version        Date         Author               Change ID        Description
 *---------------------------------------------------------------------------------------------------------------------
 * 02.21.00       30Sep2014    Vishwanath Reddy     SDOCM00113127    Initial Version 
 * 02.21.01       23Aug2016    Vishwanath Reddy     SDOCM00121248    AdcHwUnitId is now checked against ADC_HW_UNIT0
 *                                                                   instead of zero to make it AS4.0.3 compliant.
 * 02.30.00       01Dec2016    Sudhakar Singh           None         Update version info
 * 05.30.00       15Mar2017    Sudhakar Singh       SDOCM00122834    Version supports TMS570LSxx Family of Devices.
 **********************************************************************************************************************/
 /*********************************************************************************************************************
    Project: [!"$project"!]
	Date   : [!"$datetime"!] 
	
    This file is generated by EB Tresos 
    Do not modify this file, otherwise the software may behave in unexpected way.
    
 *********************************************************************************************************************/

/**********************************************************************************************************************
 *  INCLUDES
 *********************************************************************************************************************/
#include "Std_Types.h"
#include "Adc.h"

/**********************************************************************************************************************
 *  GLOBAL CONFIG DATA
 **********************************************************************************************************************/

#define ADC_START_SEC_VAR_NOINIT_UNSPECIFIED
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"
/* Declare RAM variables. One array for each of the runtimes */
/*<ADC_GROUP_DATA_LIST>*/
[!LOOP "as:modconf('Adc')[1]/AdcConfigSet/*[1]/AdcHwUnit/*"!]static VAR(Adc_GroupDataType, ADC_VAR) Adc_GroupDataListRt0Hw[!"@index"!]_at[[!"num:i(count(AdcGroup/*))"!]];
[!ENDLOOP!]
/*</ADC_GROUP_DATA_LIST>*/ 
 
#define ADC_STOP_SEC_VAR_NOINIT_UNSPECIFIED
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

#define ADC_START_SEC_PBCFG
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

[!VAR "AdcName"="as:path(as:modconf('Adc')[1])"!][!VAR "AdcName2"="substring-after(substring-after($AdcName,'/'),'/')"!]
/* Create group configuration sets. One array for each of the runtimes */
/* SourceId : ADC_SourceId_022 */
/* DesignId : ADC_DesignId_001 */
/* Requirements : AR_ADC_SR9, AR_ADC_SR10, AR_ADC_SR13, AR_ADC_SR247, AR_ADC_SR248, AR_ADC_SR249, AR_ADC_SR253, 
                  AR_ADC_SR254, AR_ADC_SR255, AR_ADC_SR256, AR_ADC_SR257, AR_ADC_SR258, AR_ADC_SR259,*/
static CONST(Adc_GroupConfigType, ADC_PBCFG) Adc_GroupConfigList0_at[] = 
{
  [!LOOP "as:modconf('Adc')[1]/AdcConfigSet/*[1]/AdcHwUnit/*"!][!LOOP "AdcGroup/*"!][!VAR "count12"="1"!] 
  {
    ([!LOOP "AdcGroupDefinition/*"!][!VAR "adcId"="node:value(concat("/AUTOSAR/TOP-LEVEL-PACKAGES/Adc/ELEMENTS/",$AdcName2,"/AdcConfigSet/",substring-before(substring-after(substring-after(substring-after(../*[position()=$count12],'/'),'/'),'/'),'/'),"/AdcHwUnit/",substring-before(substring-after(substring-after(substring-after(substring-after(../*[position()=$count12],'/'),'/'),'/'),'/'),'/'),"/AdcChannel/",substring-after(substring-after(substring-after(substring-after(substring-after(../*[position()=$count12],'/'),'/'),'/'),'/'),'/'),"/AdcChannelId"))"!] (1<<[!"$adcId"!])[!IF "not(node:islast())"!]|[!ENDIF!][!VAR "count12"="$count12+1"!][!ENDLOOP!]),
    &Adc_GroupDataListRt0Hw[!"../../@index"!]_at[[!"@index"!]],
    (P2VAR(Adc_RegType, AUTOMATIC, MSR_REGSPACE))([!IF "../../AdcHwUnitId = 'ADC_HW_UNIT0'"!]ADC_HW_UNIT0_BASE_ADDRESS[!ELSE!]ADC_HW_UNIT1_BASE_ADDRESS[!ENDIF!]+[!IF "AdcGroupTriggSrc = 'ADC_TRIGG_SRC_SW'"!]0x08[!ELSE!]0x00[!ENDIF!] ),
    (P2VAR(uint32, AUTOMATIC, MSR_REGSPACE))([!IF "../../AdcHwUnitId = 'ADC_HW_UNIT0'"!]ADC_HW_UNIT0_BASE_ADDRESS[!ELSE!]ADC_HW_UNIT1_BASE_ADDRESS[!ENDIF!] +[!IF "AdcGroupTriggSrc = 'ADC_TRIGG_SRC_SW'"!]ADC_G2_FIFO_OFFSET[!ELSE!]ADC_EV_FIFO_OFFSET[!ENDIF!] ),
    {[!IF "node:exists(AdcNotification)= 'true'"!][!IF "AdcNotification=''"!]&Adc_AvoidNotification,&Adc_AvoidNotification[!ELSE!]&Adc_AvoidNotification,&[!"AdcNotification"!][!ENDIF!][!ELSE!]&Adc_AvoidNotification,&Adc_AvoidNotification[!ENDIF!]},
    [!IF "AdcGroupAccessMode = 'ADC_ACCESS_MODE_SINGLE'"!]  &Adc_ProcessBufferSingle,  [!CR!]  &Adc_ProcessConversionSingle,[!ELSE!]  [!IF "AdcStreamingBufferMode ='ADC_STREAM_BUFFER_LINEAR'"!]  &Adc_ProcessBufferLinear,[!CR!]  &Adc_ProcessConversionLinear,[!ELSE!]  &Adc_ProcessBufferCircular,[!CR!]    &Adc_ProcessConversionCircular,[!ENDIF!][!ENDIF!] 
    [!VAR "adcPath"="(concat("/AUTOSAR/TOP-LEVEL-PACKAGES/Adc/ELEMENTS/",$AdcName2,"/AdcConfigSet/",substring-before(substring-after(substring-after(substring-after(AdcGroupDefinition/*[1],'/'),'/'),'/'),'/'),"/AdcHwUnit/",substring-before(substring-after(substring-after(substring-after(substring-after(AdcGroupDefinition/*[1],'/'),'/'),'/'),'/'),'/'),"/AdcChannel/",substring-after(substring-after(substring-after(substring-after(substring-after(AdcGroupDefinition/*[1],'/'),'/'),'/'),'/'),'/'),"/AdcChannelSampTime"))"!] [!IF "node:exists($adcPath) = 'true'"!][!"node:value($adcPath)"!][!ELSE!]4096[!ENDIF!]U,  /*GroupSampTime_t based on the selected channel */
    [!"AdcStreamingNumSamples "!]U,
    [!"AdcGroupConversionMode"!],
    [!"AdcGroupTriggSrc"!],
    [!"AdcGroupAccessMode"!],
    [!"AdcStreamingBufferMode"!],
    [!IF "node:exists(AdcHwTrigSignal)='true'"!]  [!"AdcHwTrigSignal"!][!ELSE!]  ADC_HW_TRIG_FALLING_EDGE[!ENDIF!], /* Use rising or falling edge for event pin trigger */
    (ADC_HW_FIFO_THRESHOLD/[!"num:i(count(AdcGroupDefinition/*))"!]U),/* GroupThreshold_t */ 
    [!VAR "adcPath"="(concat("/AUTOSAR/TOP-LEVEL-PACKAGES/Adc/ELEMENTS/",$AdcName2,"/AdcConfigSet/",substring-before(substring-after(substring-after(substring-after(AdcGroupDefinition/*[1],'/'),'/'),'/'),'/'),"/AdcHwUnit/",substring-before(substring-after(substring-after(substring-after(substring-after(AdcGroupDefinition/*[1],'/'),'/'),'/'),'/'),'/'),"/AdcChannel/",substring-after(substring-after(substring-after(substring-after(substring-after(AdcGroupDefinition/*[1],'/'),'/'),'/'),'/'),'/'),"/AdcChannelResolution"))"!] [!IF "node:exists($adcPath) = 'true'"!][!"node:value($adcPath)"!][!ELSE!]12[!ENDIF!]U,/*Based on the selected channels we should select the groupResolution item */
    [!"../../AdcHwUnitId"!], /*GroupHwUnitId_t*/
    [!IF "node:exists(AdcHwTrigTimer)='true'"!][!"AdcHwTrigTimer"!][!ELSE!]0[!ENDIF!]U, /* Hardware trigger event: Zero when group is triggered
                            * by event pin; 1-7 for internal timers 
                            */
    [!IF "AdcGroupTriggSrc ='ADC_TRIGG_SRC_HW'"!]ADC_HW_GROUP_EVT[!ELSE!]  ADC_HW_GROUP_G2[!ENDIF!], /* GroupHwGroupId_u8 */
    [!"num:i(count(AdcGroupDefinition/*))"!]U,   /* The number of channels of a group */
    [!IF "AdcGroupTriggSrc  = 'ADC_TRIGG_SRC_HW'"!][!IF "AdcGroupAccessMode = 'ADC_ACCESS_MODE_STREAMING'"!][!IF "AdcStreamingBufferMode = 'ADC_STREAM_BUFFER_LINEAR'"!]ADC_GROUP_STOP_IMPLICIT[!ENDIF!][!ELSE!]ADC_GROUP_STOP_EXPLICIT[!ENDIF!][!ELSE!][!IF "AdcGroupConversionMode ='ADC_CONV_MODE_ONESHOT'"!]ADC_GROUP_STOP_IMPLICIT[!ELSE!][!IF "AdcGroupAccessMode='ADC_ACCESS_MODE_STREAMING'"!][!IF "AdcStreamingBufferMode='ADC_STREAM_BUFFER_CIRCULAR'"!]ADC_GROUP_STOP_EXPLICIT[!ELSE!]ADC_GROUP_STOP_IMPLICIT[!ENDIF!][!ELSE!]ADC_GROUP_STOP_EXPLICIT[!ENDIF!][!ENDIF!][!ENDIF!]       
  },
  [!ENDLOOP!]
  [!ENDLOOP!]
};

/*<ADC_GROUP_CONFIG_LIST>*/

/* Create hw unit configuration sets. One array for each of the runtimes */
/*<ADC_HW_UNIT_CONFIG_LIST>*/
/* SourceId : ADC_SourceId_023 */
/* DesignId : ADC_DesignId_001 */
/* Requirements : AR_ADC_SR261, AR_ADC_SR263, AR_ADC_SR264,  */
CONST(Adc_HwUnitConfigType, ADC_PBCFG) Adc_HwUnitConfigList0_at[] = 
{
[!LOOP "as:modconf('Adc')[1]/AdcConfigSet/*[1]/AdcHwUnit/*"!]  
{
  ADC_EV_FIFO_END,
  ADC_G1_FIFO_END,
  (Adc_RegisterRefType)[!IF "AdcHwUnitId = 'ADC_HW_UNIT0'"!]ADC_HW_UNIT0_BASE_ADDRESS[!ELSE!]ADC_HW_UNIT1_BASE_ADDRESS[!ENDIF!],
  [!IF "node:exists(AdcPrescale)='true'"!]  [!"num:i(AdcPrescale)"!][!ELSE!]0[!ENDIF!] 
},
[!ENDLOOP!]
};


#define ADC_STOP_SEC_PBCFG
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

#define ADC_START_SEC_PBCFG_ROOT
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

/* Create runtime configurations. */
/*<ADC_CONFIG>*/
[!LOOP "as:modconf('Adc')[1]/AdcConfigSet/*"!] CONST(Adc_ConfigType, ADC_PBCFG) [!"@name"!] =
{
    Adc_HwUnitConfigList0_at,
    Adc_GroupConfigList0_at,
    [!"num:i(count(AdcHwUnit/*))"!],
    [!"num:i(count(./AdcHwUnit/*/AdcGroup/*))"!]
};

[!ENDLOOP!]
/*</ADC_CONFIG>*/

#define ADC_STOP_SEC_PBCFG_ROOT
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

/**********************************************************************************************************************
 *  END OF FILE: Adc_PBcfg.h
 *********************************************************************************************************************/

