/**********************************************************************************************************************
 *  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.  All rights reserved.
 *
 *  \endverbatim
 *  -------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  -------------------------------------------------------------------------------------------------------------------
 *         File:  Icu_PBcfg.c
 *      Project:  Tms570_AutosarIcuDriver
 *       Module:  ICU
 *    Generator:  EB Tresos
 *
 *  Description:  The ICU driver is a module using the input capture unit (ICU) for demodulation of a PWM signal,
 *                counting pulses, measuring of frequency and duty cycle, generating simple interrupts and wake-up
 *                interrupts.
 *
 *                The ICU driver provides services for
 *                -    Signal edge notification
 *                -    Controlling wake-up interrupts
 *                -    Periodic signal time measurement
 *                -    Edge timestamping, usable for the acquisition of non-periodic signals
 *                -    Edge counting
 *
 *                This module works on pins and ports which are configured by the PORT driver for this purpose. For
 *                this reason there is no configuration and initialization of this port structure in the ICU Driver.
 *********************************************************************************************************************/

/**********************************************************************************************************************
 *---------------------------------------------------------------------------------------------------------------------
 * Author:  Vineeth Thomas Alex
 *---------------------------------------------------------------------------------------------------------------------
 * Revision History
 *---------------------------------------------------------------------------------------------------------------------
 * Version     Date           Author                   Change ID          Description
 *---------------------------------------------------------------------------------------------------------------------
 * 02.21.00    30Sept2014     Vineeth Thomas Alex      SDOCM00113121      Initial version adapted from TMS570LS3137
 * 02.21.01    16Mar2016      Enrique Lizarraga        SDOCM00121723      Update version number
 * 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.
***********************************************************************************************************************
**********************************************************************************************************************/
#define ICU_PBCFG_SOURCE
/**********************************************************************************************************************
 *  INCLUDES
 *********************************************************************************************************************/

#include "Std_Types.h"
#include "Icu_Cfg.h"
#include "Icu.h"
#include "Icu_Cbk.h"
/**********************************************************************************************************************
 *  VERSION CHECK
 *********************************************************************************************************************/

#define ICU_CFG_C_MAJOR_VERSION               (5U)
#define ICU_CFG_C_MINOR_VERSION               (30U)
#define ICU_CFG_C_PATCH_VERSION               (0U)

/* ---- Perform version checking  ----------------------------------------- */
#if (   (ICU_SW_MAJOR_VERSION != ICU_CFG_C_MAJOR_VERSION) \
     || (ICU_SW_MINOR_VERSION != ICU_CFG_C_MINOR_VERSION))
  #error "Version numbers of Icu_PBcfg.c and Icu.h are inconsistent!"
#endif

#if (   (ICU_CFG_MAJOR_VERSION != ICU_CFG_C_MAJOR_VERSION) \
     || (ICU_CFG_MINOR_VERSION != ICU_CFG_C_MINOR_VERSION))
  #error "Version numbers of Icu_PBcfg.c and Icu_Cfg.h are inconsistent!"
#endif

/*SAFETYMCUSW 580 S MR:1.1 <APPROVED> "Reason - Memory mapping requires this syntax" */
#define ICU_START_SEC_CONST_PBCFG
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format for specifying memory sections" */
#include "MemMap.h"

/* Icu Channel Configuration parameters */
[!VAR "Index" = "0"!]
[!LOOP "as:modconf('Icu')[1]/IcuConfigSet/*"!]
static CONST(Icu_ChannelConfigType, ICU_PBCFG) IcuConfigSet[!"num:i($Index)"!]_ChannelConfig_at[] =
{
	[!LOOP "IcuChannel/*"!][!/*Channel Loop */!]
	{
		[!IF "IcuMeasurementMode = 'ICU_MODE_EDGE_COUNTER'"!]NULL_PTR[!ELSEIF "IcuMeasurementMode = 'ICU_MODE_SIGNAL_EDGE_DETECT'"!][!IF "string(IcuSignalEdgeDetection/IcuSignalNotification) != ''"!][!"string(IcuSignalEdgeDetection/IcuSignalNotification)"!][!ELSE!]NULL_PTR[!ENDIF!][!ELSEIF "IcuMeasurementMode = 'ICU_MODE_SIGNAL_MEASUREMENT'"!]NULL_PTR[!ELSE!][!IF "string(IcuTimestampMeasurement/IcuTimestampNotification) != ''"!][!"string(IcuTimestampMeasurement/IcuTimestampNotification)"!][!ELSE!]NULL_PTR[!ENDIF!][!ENDIF!],/*Notification function*/
		[!"IcuMeasurementMode"!],/*Measurement mode*/
		[!"IcuDefaultStartEdge"!],/*Default Start Edge*/
		0U,/*Hardware Identifier*/
		[!IF "IcuMeasurementMode = 'ICU_MODE_TIMESTAMP'"!][!"string(IcuTimestampMeasurement/IcuTimestampMeasurementProperty)"!][!ELSEIF "string(IcuMeasurementMode = 'ICU_MODE_SIGNAL_MEASUREMENT')"!][!"string(IcuSignalMeasurement/IcuSignalMeasurementProperty)"!][!ELSE!]255U[!ENDIF!],/*Common Variable for property info*/
		[!IF "IcuWakeupCapability"!][!IF "node:refexists(IcuWakeup/IcuChannelWakeupInfo)"!][!"num:i(node:ref(IcuWakeup/IcuChannelWakeupInfo)/EcuMWakeupSourceId)"!]U[!ELSE!]ICU_UNDEFINED[!ENDIF!][!ELSE!]ICU_UNDEFINED[!ENDIF!]/*Wakeup Identifier*/
	}[!IF "not(node:islast())"!],[!ENDIF!][!CR!][!ENDLOOP!]
};
[!VAR "Index" = "$Index+1"!][!ENDLOOP!]


/*<Het_Icu_PROGRAM>*/
[!VAR "Index" = "0"!]
[!LOOP "as:modconf('Icu')[1]/IcuConfigSet/*"!][!AUTOSPACING!]
[!VAR "Count"="0"!][!VAR "Block2Flag" = "0"!][!VAR "PrgField"="0"!][!VAR "CntField"="0"!][!VAR "PrgField_Init_Ecnt"="5184"!][!VAR "CntField_Init_Ecnt"="7"!][!VAR "PrgField_Init_Pcnt" = "3840"!][!VAR "PrgField_Init_Wcap" = "5632"!][!VAR "CntField_Init_Wcap"="3"!][!VAR "NextAddr"="2"!][!VAR "Event"="0"!][!VAR "Pin" = "0"!]
[!VAR "NoofChs"="0"!][!LOOP "IcuChannel/*"!][!VAR "NoofChs"="$NoofChs+1"!][!ENDLOOP!]
static CONST(Het_Icu_InstructionType, ICU_PBCFG) IcuConfigSet[!"num:i($Index)"!]_HetBlock1_at[] =
{
	[!LOOP "IcuChannel/*"!]
	[!VAR "Pin" = "num:dectoint(string(num:i(substring-after(IcuInputPin,'NHET'))))"!][!IF "$Count < $NoofChs - 1"!][!VAR "NextAddr"="$Count + 2"!][!ELSE!][!VAR "NextAddr"="47"!][!ENDIF!]
	[!IF "IcuMeasurementMode = 'ICU_MODE_EDGE_COUNTER'"!][!/*ECNT Instruction*/!][!VAR "PrgField" = "num:inttohex(num:add($PrgField_Init_Ecnt,bit:shl($NextAddr,13)),8)"!][!IF "IcuDefaultStartEdge = 'ICU_RISING_EDGE'"!][!VAR "Event"="2"!][!ELSEIF "IcuDefaultStartEdge = 'ICU_FALLING_EDGE'"!][!VAR "Event"="1"!][!ELSE!][!VAR "Event"="3"!][!ENDIF!][!VAR "CntField" = "num:inttohex(num:add(num:add(num:add($CntField_Init_Ecnt,bit:shl($NextAddr,13)),bit:shl($Event,4)),bit:shl($Pin,8)),8)"!][!ELSEIF "IcuMeasurementMode = 'ICU_MODE_SIGNAL_EDGE_DETECT'"!][!/*ECNT Instruction*/!][!VAR "PrgField" = "num:inttohex(num:add($PrgField_Init_Ecnt,bit:shl($NextAddr,13)),8)"!][!IF "IcuDefaultStartEdge = 'ICU_RISING_EDGE'"!][!VAR "Event"="2"!][!ELSEIF "IcuDefaultStartEdge = 'ICU_FALLING_EDGE'"!][!VAR "Event"="1"!][!ELSE!][!VAR "Event"="3"!][!ENDIF!][!VAR "CntField" = "num:inttohex(num:add(num:add(num:add($CntField_Init_Ecnt,bit:shl($NextAddr,13)),bit:shl($Event,4)),bit:shl($Pin,8)),8)"!][!ELSEIF "IcuMeasurementMode = 'ICU_MODE_SIGNAL_MEASUREMENT'"!][!/*PCNT Instruction*/!][!IF "IcuSignalMeasurementProperty = 'ICU_HIGH_TIME'"!][!VAR "Event"="1"!][!ELSEIF "IcuSignalMeasurementProperty = 'ICU_ACTIVE_TIME'"!][!VAR "Event"="1"!][!ELSEIF "IcuSignalMeasurementProperty = 'ICU_LOW_TIME'"!][!VAR "Event"="0"!][!ELSEIF "IcuSignalMeasurementProperty = 'ICU_PERIOD_TIME'"!][!VAR "Event" = "2"!][!ELSE!][!VAR "Event"="1"!][!VAR "NextAddr"="$NextAddr + 31"!][!VAR "Block2Flag" = "$Block2Flag + 1"!][!ENDIF!][!VAR "PrgField" = "num:inttohex(num:add(num:add(num:add($PrgField_Init_Pcnt,bit:shl($Event,6)),$Pin),bit:shl($NextAddr,13)),8)"!][!VAR "CntField"= "num:inttohex(0,8)"!][!ELSE!][!IF "IcuDefaultStartEdge = 'ICU_RISING_EDGE'"!][!VAR "Event"="2"!][!ELSEIF "IcuDefaultStartEdge = 'ICU_FALLING_EDGE'"!][!VAR "Event"="1"!][!ELSE!][!VAR "Event"="3"!][!ENDIF!][!VAR "PrgField" = "num:inttohex(num:add($PrgField_Init_Wcap,bit:shl($NextAddr,13)),8)"!][!VAR "CntField" = "num:inttohex(num:add(num:add(num:add($CntField_Init_Wcap,bit:shl($Event,5)),bit:shl($Pin,8)),bit:shl($NextAddr,13)),8)"!][!ENDIF!]
	{ [!"$PrgField"!]U, [!"$CntField"!]U, [!"num:inttohex(0,8)"!]U, [!"num:inttohex(0,1)"!]U}[!IF "$Count < $NoofChs - 1"!],[!ENDIF!][!CR!]
	[!VAR "Count"="$Count+1"!][!VAR "Block2Flag" = "bit:shl($Block2Flag,1)"!][!ENDLOOP!]

	[!IF "$Count=0"!]
	{[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,2)"!]U}[!CR!]
	[!ENDIF!]
};
[!VAR "MaxCount"="$Count"!][!VAR "Count"="0"!]
static CONST(Het_Icu_InstructionType, ICU_PBCFG) IcuConfigSet[!"num:i($Index)"!]_HetBlock2_at[] =
{
	[!LOOP "IcuChannel/*"!]
	[!IF "bit:and(bit:shr($Block2Flag,num:sub($MaxCount,$Count)),1) = 0"!]{[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,2)"!]U}[!ELSE!][!VAR "Pin" = "num:dectoint(string(num:i(substring-after(IcuInputPin,'NHET'))))"!]{[!"num:inttohex(num:add(num:add(num:add($PrgField_Init_Pcnt,bit:shl(2,6)),$Pin),bit:shl($Count+2,13)),8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,2)"!]U}[!ENDIF!][!IF "$Count < $NoofChs - 1"!],[!ENDIF!][!CR!]
	[!VAR "Count"="$Count+1"!][!ENDLOOP!]
	
	[!IF "$Count=0"!]
	{[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,8)"!]U,[!"num:inttohex(0,2)"!]U}[!CR!]
	[!ENDIF!]
	
};
[!VAR "Index"="$Index+1"!][!ENDLOOP!]
/*</Het_Icu_PROGRAM>*/


/*<Het_Icu_RAM_BLOCK_ARRAY>*/
/* --- HET block array for IcuConfigSet --- */
[!VAR "Index" = "0"!]
[!LOOP "as:modconf('Icu')[1]/IcuConfigSet/*"!]
[!VAR "Count" = "0"!]
[!LOOP "IcuChannel/*"!][!VAR "Count"="$Count+1"!][!ENDLOOP!]
static CONST(Het_Icu_BlockType, ICU_PBCFG) IcuConfigSet[!"num:i($Index)"!]_HetRamBlocks_at[] =
{
    {IcuConfigSet[!"num:i($Index)"!]_HetBlock1_at, [!"num:i($Count)"!]U},
    {IcuConfigSet[!"num:i($Index)"!]_HetBlock2_at, [!"num:i($Count)"!]U}
};
[!VAR "Index" = "$Index+1"!][!ENDLOOP!]
/*</Het_Icu_RAM_BLOCK_ARRAY>*/


/* global Icu runtime configuration Het1,Het2*/
/*<ICU_CONFIGURATION>*/
[!VAR "Index" = "0"!][!VAR "CountEC"="0"!][!VAR "CountTS"="0"!][!VAR "CountED"="0"!][!VAR "CountSM"="0"!]
[!LOOP "as:modconf('Icu')[1]/IcuConfigSet/*"!]
[!LOOP "IcuChannel/*"!][!IF "IcuMeasurementMode = 'ICU_MODE_EDGE_COUNTER'"!][!VAR "CountEC" = "$CountEC+1"!][!ELSEIF "IcuMeasurementMode = 'ICU_MODE_SIGNAL_EDGE_DETECT'"!][!VAR "CountED" = "$CountED+1"!][!ELSEIF "IcuMeasurementMode = 'ICU_MODE_SIGNAL_MEASUREMENT'"!][!VAR "CountSM" = "$CountSM+1"!][!ELSE!][!VAR "CountTS" = "$CountTS+1"!][!ENDIF!][!ENDLOOP!]
CONST(Icu_ConfigType, ICU_PBCFG) [!"@name"!] =
{
	IcuConfigSet[!"num:i($Index)"!]_ChannelConfig_at,/*Channel Config*/
	IcuConfigSet[!"num:i($Index)"!]_HetRamBlocks_at,/*Instruction Set*/
	[!"num:i($CountEC)"!]U,/* Number of edge counter channels*/
	[!"num:i($CountTS)"!]U,/* Number of timestamping channels*/
	[!"num:i($CountED)"!]U,/* Number of signal edge detection channels*/
	[!"num:i($CountSM)"!]U,/* Number of signal measurement channels*/
	[!"concat('ICU_',concat(IcuHetSelect,'_REG_ADDR'))"!],/*NHET Register Base Address*/
	[!"concat('ICU_',concat(IcuHetSelect,'_RAM_ADDR'))"!]/*NHET RAM Base Address*/
};
[!VAR "Index" = "$Index+1"!][!ENDLOOP!]
/*</ICU_CONFIGURATION>*/
/*SAFETYMCUSW 580 S MR:1.1 <APPROVED> "Reason - Memory mapping requires this syntax" */
#define ICU_STOP_SEC_CONST_PBCFG
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format for specifying memory sections" */
#include "MemMap.h"

/**********************************************************************************************************************
 *  END OF FILE: Icu_PBcfg.c                                                                                          *
 *********************************************************************************************************************/


