Attribute VB_Name = "Module1"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Port.inc"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\ParameterClass.cls
Option Explicit
'*****************************************************************************
' Module:
'        SCU
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the
'        SCU dialog script and in the SCU codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0  ste            10.03.00    final version for TC1775A
'        2.0  ste            19.07.00    on page "Software Reset" Boot options
'                                        changed (TC1775B)
'        ---------------------------------------------------------------------
'        5.0  ste            23.07.02    final version for TC1796
'        ---------------------------------------------------------------------
'             ste            14.07.03    IN00-IN33 of REQLINE changed
'             ste            14.07.03    on page "Software Reset" Boot options
'                                        changed (TC1766)
'
'*****************************************************************************


'*****************************************************************************
' @Constants
'*****************************************************************************


'*****************************************************************************
' @Function descriptions
'*****************************************************************************

'*****************************************************************************
'Description:
'        For each function which should be used for this module a line
'        "If (Not func.AddFunction .." must be insert in this function.
'        For each parameter that should be used for this function a
'        line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added function a project variable with the name
'        "DUMMY_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  RefreshFunctionDescriptions = False

  Dim sDescription As String
  Dim sReturnValue As String
  Dim sIndex As String
  Dim sPrefix As String

  sIndex = "SCU" ' & vIndex
  sPrefix = sIndex & "_"


  ' for each function of this module the property AddFunction must be called
  '
  ' AddFunction(sFuncName As String, sFuncType As String, sFuncDescription As String,
  '             sReturnvalue As String, lSort As Long) As Boolean
  '
  ' sFuncName          | String | function name as key (use the name of the variable
  '                               for the function name e.g. SCU_NAME_Init)
  ' sFuncType          | String | type of the function
  ' sFuncDescription   | String | description of the function
  ' sReturnvalue       | String | description of the return value
  ' lSort              | Long   | ' sort of the function (0 => macro, 1 => function, 2 => ISR, 3 => TRAP)


    ' for each parameter of a function the property AddParameter must be called
    '
    'AddParameter(sParName As String, sPar As String, sParType As String, sParDescription As String) As Boolean
    '
    ' sParName         | String | parameter name (key)
    ' sPar             | String | parameter name
    ' sParType         | String | type of the parameter
    ' sParDescription  | String | description of the parameter


  '------------------------------------------------------------------------------------------------
  ' Description for SCU_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sIndex)
  sReturnValue = "None"
  If (Not func.AddFunction(sIndex & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

'''''  '------------------------------------------------------------------------------------------------
'''''  ' Description for SCU_NAME_SetIdle
'''''  '------------------------------------------------------------------------------------------------
'''''  sDescription = "This function sets the CPU in IDLE mode. The CPU core clock " & _
'''''                        "is disabled. All peripherals remain powered and clocked. " & _
'''''                        "Processor memory is accessible to peripherals. A reset, watchdog timer event, " & _
'''''                        "a falling edge on the #NMI pin, or any enabled interrupt event will wake the CPU. "
'''''  sReturnValue = "None"
'''''  If (Not func.AddFunction(sIndex & "_NAME_SetIdle", "void", sDescription, sReturnValue, 1)) Then Exit Function
'''''
'''''  '------------------------------------------------------------------------------------------------
'''''  ' Description for SCU_NAME_SetSleep
'''''  '------------------------------------------------------------------------------------------------
'''''  sDescription = "This function sets the CPU in SLEEP mode. The system clock " & _
'''''                        "continues to be distributed only to those peripherals programmed " & _
'''''                        "to operate in Sleep Mode. A reset, watchdog timer event, " & _
'''''                        "a falling edge on the #NMI pin, or interrupts from operating peripherals will wake the CPU. "
'''''  sReturnValue = "None"
'''''  If (Not func.AddFunction(sIndex & "_NAME_SetSleep", "void", sDescription, sReturnValue, 1)) Then Exit Function
'''''
'''''  '------------------------------------------------------------------------------------------------
'''''  ' Description for SCU_NAME_SetDeepSleep
'''''  '------------------------------------------------------------------------------------------------
''''''  sDescription = "This function sets the CPU in DEEP SLEEP mode. All clocks, the PLL, " & _
''''''                               "and the oscillator are shuts off. Therefor, Deep Sleep mode consumes the least power of all states. " & _
''''''                               "Only a power-on reset or a falling edge on the #NMI pin will restart the system."
''''''  sReturnValue = "None"
''''''  If (Not func.AddFunction(sIndex & "_NAME_SetDeepSleep", "void", sDescription, sReturnValue, 1)) Then Exit Function
'''''
'''''
'''''  '------------------------------------------------------------------------------------------------
'''''  ' Description for SCU_NAME_SoftReset
'''''  '------------------------------------------------------------------------------------------------
'''''  sDescription = "This function generates a soft reset. Unlike the other reset " & _
'''''                        "causes the soft reset offers the option to exclude two " & _
'''''                        "functions from the reset. These are the system timer " & _
'''''                        "and the external reset output #HRST. In addition, " & _
'''''                        "it has the option to change the boot configuration. " & vbCrLf & _
'''''                        "Example: " & vbCrLf & _
'''''                        "To reset the controller with the configured soft reset option, " & _
'''''                        "this function must be called as follow: " & vbCrLf & _
'''''                        r.v(sIndex & "_NAME_SoftReset") & "(" & r.v(sIndex & "_PARA_RESET_OPTIONS") & ");"
'''''  sReturnValue = "None"
'''''  If (Not func.AddFunction(sIndex & "_NAME_SoftReset", "void", sDescription, sReturnValue, 1)) Then Exit Function
'''''    sDescription = "Required options for the soft reset (value for the RST_REQ register)"
'''''    If (Not func.AddParameter(sIndex & "_NAME_SoftReset_Par1", "uwOptions", "uword", sDescription)) Then Exit Function
'''''
'''''  '------------------------------------------------------------------------------------------------
'''''  ' Description for SCU_NAME_ResetStatus
'''''  '------------------------------------------------------------------------------------------------
'''''  sDescription = "This macro returns the status of the reset cause register " & _
'''''                        "RST_SR. This register indicates after a reset which type " & _
'''''                        "of reset had occurred and which part of the chip have been " & _
'''''                        "affected by that reset. " & vbCrLf & _
'''''                        "The possible values for the returned status are: " & vbCrLf & _
'''''                        "Bit 0 = 1    ->  system timer was reset " & vbCrLf & _
'''''                        "Bit 2 = 1    ->  external reset pin (#HRST) was activated " & vbCrLf & _
'''''                        "Bits [19:16] ->  latched boot configuration" & vbCrLf & _
'''''                        "Bit 21 = 1   ->  value of the break input pin (#BRKIN)" & vbCrLf & _
'''''                        "Bit 27 = 1   ->  the last reset was a power-on reset " & vbCrLf & _
'''''                        "Bit 28 = 1   ->  the last reset was a hard reset " & vbCrLf & _
'''''                        "Bit 29 = 1   ->  the last reset was a soft reset " & vbCrLf & _
'''''                        "Bit 30 = 1   ->  the last reset was a watchdog reset "
'''''  sReturnValue = "Value of the reset status register RST_SR"
'''''  If (Not func.AddFunction(sIndex & "_NAME_ResetStatus", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for SCU_NAME_ERUSetFL
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro sets the FLx bit of the choosen input channel. " & _
                 "This bit can trigger an interrupt and can taken into consideration for the pattern detection. " & _
                 "Since this macro uses protected registers hence  MAIN_vUnlockProtecReg(void) should be called " & _
                 "before calling this macro and then MAIN_vLockProtecReg(void) should be called ."
  sReturnValue = "None"
  If (Not func.AddFunction(sIndex & "_NAME_ERUSetFL", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the ERU input channel (0-3)"
    If (Not func.AddParameter(sIndex & "_NAME_ERUSetFL_Par1", "CHANNEL_NUMBER", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for SCU_NAME_ERUResetINTF
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro resets the FLx bit of the choosen input channel. " & _
                 "This bit can taken into consideration for the pattern detection. " & _
                 "Since this macro uses protected registers hence  MAIN_vUnlockProtecReg(void) should be called " & _
                 "before calling this macro and then MAIN_vLockProtecReg(void) should be called ."
  sReturnValue = "None"
  If (Not func.AddFunction(sIndex & "_NAME_ERUResetFL", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the ERU input channel (0-3)"
    If (Not func.AddParameter(sIndex & "_NAME_ERUResetFL_Par1", "CHANNEL_NUMBER", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for SCU_NAME_ERUGetINTF
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro returns the FLx bit of the choosen input channel. " & _
                  "Since this macro uses protected registers hence  MAIN_vUnlockProtecReg(void) should be called " & _
                 "before calling this macro and then MAIN_vLockProtecReg(void) should be called ."
  sReturnValue = "State of the FLx bit"
  If (Not func.AddFunction(sIndex & "_NAME_ERUGetFL", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the ERU input channel (0-3)"
    If (Not func.AddParameter(sIndex & "_NAME_ERUGetFL_Par1", "CHANNEL_NUMBER", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for SCU_NAME_ERUGetPDR
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro returns the PDRx bit (pattern detection result) of the choosen input channel. " & _
                 "Since this macro uses protected registers hence  MAIN_vUnlockProtecReg(void) should be called " & _
                 "before calling this macro and then MAIN_vLockProtecReg(void) should be called ."
  sReturnValue = "State of the PDRx bit"
  If (Not func.AddFunction(sIndex & "_NAME_ERUGetPDR", "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the ERU input channel (0-3)"
    If (Not func.AddParameter(sIndex & "_NAME_ERUGetPDR_Par1", "CHANNEL_NUMBER", "", sDescription)) Then Exit Function

        If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
End Function


'*****************************************************************************
'Description:
'        For each parameter that should be used as a constant (on page "Parameters")
'        a line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added parameter a project variable with the name
'        "DUMMY_PARA_Parametername" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex           parameter of the module which was added with AddModule
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshParameterDescriptions(vIndex As Variant, para As ParameterClass, r As ProjectData) As Boolean
  On Error Resume Next

  RefreshParameterDescriptions = False

  Dim sDescription As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "SCU" & vIndex
  sRegPre = sVarPre & "_"


  ' for each parameter of this module the property AddParameter must be called
  '
  ' AddParameter(sParameterName As String, sParameterDescription As String) As Boolean
  '
  ' sParameterName         | String | parameter name as key (use the name of the variable
  '                                   for the parameter name e.g. SSC_PARA_MODE)
  ' sParameterDescription  | String | description of the parameter

  '------------------------------------------------------------------------------------------------
  ' Description for SCU_PARA_WDT_RELOAD
  '------------------------------------------------------------------------------------------------
''''  sDescription = "Specifies the configured options for a watchdog trigger"
''''  If (Not para.AddParameter(sVarPre & "_PARA_WDT_RELOAD", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for SCU_PARA_RESET_OPTIONS
  '------------------------------------------------------------------------------------------------
''''  sDescription = "Specifies the configured options for a software reset"
''''  If (Not para.AddParameter(sVarPre & "_PARA_RESET_OPTIONS", sDescription)) Then Exit Function

        If (Not para.Sort) Then Exit Function

  RefreshParameterDescriptions = True
End Function


'*****************************************************************************
' @Functions
'*****************************************************************************


'*****************************************************************************
'Description:
'        This function returns the module clock (in MHz) of the
'        SCU module depending on the configured modes
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        module clock (in MHz)
'*****************************************************************************
Function GetSCUModuleClock(r As ProjectData, vIndex As Variant) As Double
  On Error GoTo GetSCUModuleClockError
  Dim sIndex As String
  Dim v As String
  Dim sPrefix As String

  sIndex = "SCU" ' & vIndex
  sPrefix = sIndex & "_"

  GetSCUModuleClock = 1
  GetSCUModuleClock = GetSystemClock(r)
  Exit Function

GetSCUModuleClockError:
  GetSCUModuleClock = 1
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function returns the WDT timer period (in s).
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        WDT timer period (in s)
'*****************************************************************************
Function GetWDTTimerPeriod(r As ProjectData, vIndex As Variant) As Double
  On Error GoTo GetWDTTimerPeriodError
  Dim sIndex As String
  Dim v As String
  sIndex = "SCU" & vIndex

  GetWDTTimerPeriod = 1
  If (r.v("WDT_CON1_WDTIR") = 1) Then
    GetWDTTimerPeriod = (2 ^ 16 - r.v("WDT_CON0_WDTREL")) * 256 / GetSCUModuleClock(r, vIndex)
  Else
    GetWDTTimerPeriod = (2 ^ 16 - r.v("WDT_CON0_WDTREL")) * 16384 / GetSCUModuleClock(r, vIndex)
  End If

  Exit Function

GetWDTTimerPeriodError:
  GetWDTTimerPeriod = 1
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function returns the WDT timeout period (in s).
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        WDT timeout period (in s)
'*****************************************************************************
Function GetWDTTimeoutPeriod(r As ProjectData, vIndex As Variant) As Double
  On Error GoTo GetWDTTimeoutPeriodError
  Dim sIndex As String
  Dim v As String
  sIndex = "SCU" & vIndex

  GetWDTTimeoutPeriod = 1
  If (r.v("WDT_CON1_WDTIR") = 1) Then
    GetWDTTimeoutPeriod = (2 ^ 16 - &HFFFC) * 256 / GetSCUModuleClock(r, vIndex)
  Else
    GetWDTTimeoutPeriod = (2 ^ 16 - &HFFFC) * 16384 / GetSCUModuleClock(r, vIndex)
  End If

  Exit Function

GetWDTTimeoutPeriodError:
  GetWDTTimeoutPeriod = 1
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function returns the text for the combobox cboCFG.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        iType           current value of the boot type
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Function GetCboCFGText(r As ProjectData, iType As Integer) As String
  On Error Resume Next
  Dim s As String
  Dim sPrefix As String

  sPrefix = "RST_"

  s = ""
  ' Normal boot mode
  If (r.v(sPrefix & "REQ_SWBRKIN") = 1) Then
    Select Case iType
        Case 0
            s = "Serial boot from ASC to PMI scratchpad, run loaded program (CFG[3:0] = 0000)"
        Case 1
            s = "Serial boot from CAN to PMI scratchpad, run loaded program (CFG[3:0] = 0001)"
        Case 2
            s = "Normal Internal Start. Jump to internal flash (CFG[3:0] = 0010)"
        Case 3
            s = "Alternate Boot Mode. Jump to internal flash after CRC check if check fails (CFG[3:0] = 0011)"
        Case 4
            s = "Internal Start in EEC SRAM, if ED. Jump to emulation chip SRAM. (CFG[3:0] = 0100)"
        Case 15
            s = "Optional Bootstrap Loader. Serial boot, selected via SW configuration inputs (CFG[3:0] = 1111)"
    End Select
  End If

  ' Debug boot mode
  If (r.v(sPrefix & "REQ_SWBRKIN") = 0) Then
    Select Case iType
        Case 0
            s = "tristate chip (CFG[3:0] = 0000)"
        Case 7
            s = "run pin shortcut test, go to reset state (CFG[3:0] = 0111)"
    End Select
  End If

  GetCboCFGText = s
End Function

'*****************************************************************************
'Description:
'        This function returns the alternate pin name or other input signal
'        of a REQLINEx input line.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        group           Group A or group B input
'        iINPUTCHANNELNumber  number of the REQLINE (0-3)
'        INPUTCHANNELInput   number of the input of a REQLINE (0-3)
'-----------------------------------------------------------------------------
'Returns:
'        Alternate pin name (e.g "REQ3") or input signal
'*****************************************************************************
Function GetINPUTCHANNELxInputName(r As ProjectData, vIndex As Variant, group As String, iINPUTCHANNELNumber As Integer, iINPUTCHANNELInput As Integer) As Variant
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sInput As String

  GetINPUTCHANNELxInputName = ""

  sVarPre = "SCU" & vIndex
  sRegPre = "" ' sVarPre & "_"
  sInput = "ERU_" & iINPUTCHANNELNumber & group & iINPUTCHANNELInput
  Select Case sInput
  'ERS0
    Case "ERU_0A0"
         GetINPUTCHANNELxInputName = "Pin P2.1 (ERU_0A0)"
    Case "ERU_0A1"
         GetINPUTCHANNELxInputName = "Pin ESR1 (ERU_0A1) "
    Case "ERU_0A2"
         GetINPUTCHANNELxInputName = "U0C0_DX0INS (ERU_0A2)"
    Case "ERU_0A3"
         GetINPUTCHANNELxInputName = "U0C0_DX2INS (ERU_0A3)"
         
    Case "ERU_0B0"
         GetINPUTCHANNELxInputName = "Pin P1.0 (ERU_0B0)"
    Case "ERU_0B1"
         GetINPUTCHANNELxInputName = "Pin P5.13 (ERU_0B1)"
    Case "ERU_0B2"
         GetINPUTCHANNELxInputName = "U0C1_DX0INS (ERU_0B2)"
    Case "ERU_0B3"
         GetINPUTCHANNELxInputName = "U0C1_DX2INS (ERU_0B3)"
         
    'ERS1
    Case "ERU_1A0"
         GetINPUTCHANNELxInputName = "Pin P2.2 (ERU_1A0)"
    Case "ERU_1A1"
         GetINPUTCHANNELxInputName = "Pin ESR2 (ERU_1A1)"
    Case "ERU_1A2"
         GetINPUTCHANNELxInputName = "U1C0_DX0INS (ERU_1A2)"
    Case "ERU_1A3"
         GetINPUTCHANNELxInputName = "U1C0_DX2INS (ERU_1A3)"
         
    Case "ERU_1B0"
         GetINPUTCHANNELxInputName = "Pin P1.1 (ERU_1B0)"
    Case "ERU_1B1"
         GetINPUTCHANNELxInputName = "MultiCAN_CAN4INS (ERU_1B1) "
    Case "ERU_1B2"
         GetINPUTCHANNELxInputName = "U1C1_DX0INS (ERU_1B2)"
    Case "ERU_1B3"
         GetINPUTCHANNELxInputName = "U1C1_DX2INS (ERU_1B3)"
         
     'ERS2
    Case "ERU_2A0"
         GetINPUTCHANNELxInputName = "Pin P1.2 (ERU_2A0)"
    Case "ERU_2A1"
         GetINPUTCHANNELxInputName = "MultiCAN_CAN3INS (ERU_2A1)"
    Case "ERU_2A2"
         GetINPUTCHANNELxInputName = "U2C0_DX0INS (ERU_2A2)"
    Case "ERU_2A3"
         GetINPUTCHANNELxInputName = "U2C0_DX2INS (ERU_2A3)"
         
    Case "ERU_2B0"
         GetINPUTCHANNELxInputName = "U2C0_DX1INS (ERU_2B0)"
    Case "ERU_2B1"
         GetINPUTCHANNELxInputName = "MultiCAN_CAN2INS (ERU_2B1)"
    Case "ERU_2B2"
         GetINPUTCHANNELxInputName = "U2C1_DX0INS (ERU_2B2)"
    Case "ERU_2B3"
         GetINPUTCHANNELxInputName = "U2C1_DX2INS (ERU_2B3)"
         
      'ERS3
         
    Case "ERU_3A0"
         GetINPUTCHANNELxInputName = "Pin P1.3 (ERU_3A0)"
    Case "ERU_3A1"
         GetINPUTCHANNELxInputName = "MultiCAN_CAN1INS (ERU_3A1)"
''    Case "ERU_3A2"
''         GetINPUTCHANNELxInputName = "GPTA0_OUT0"
''    Case "ERU_3A3"
''         GetINPUTCHANNELxInputName = "MSC0_FCLP"
         
    Case "ERU_3B0"
         GetINPUTCHANNELxInputName = "U1C0_DX1INS (ERU_3B0)"
    Case "ERU_3B1"
         GetINPUTCHANNELxInputName = "MultiCAN_CAN0INS (ERU_3B1)"
''    Case "ERU_3B2"
''         GetINPUTCHANNELxInputName = "GPTA0_OUT0"
''    Case "ERU_3B3"
''         GetINPUTCHANNELxInputName = "MSC0_FCLP"
    
  End Select

End Function


'*****************************************************************************
'Description:
'        This function returns the pin name or other input signal
'        of a INPUTCHANNELx input line.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iINPUTCHANNELNumber  number of the INPUTCHANNEL (0-3)
'        iINPUTCHANNELInput   number of the input of a INPUTCHANNEL (0-3)
'-----------------------------------------------------------------------------
'Returns:
'        Pin name (e.g "P1.2") or input signal
'*****************************************************************************
Function GetINPUTCHANNELxInput(r As ProjectData, vIndex As Variant, iINPUTCHANNELNumber As Integer, iINPUTCHANNELInput As Integer) As Variant
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sInput As String

  GetINPUTCHANNELxInput = "none"

  sVarPre = "SCU" & vIndex
  sRegPre = "" ' sVarPre & "_"
  sInput = "IN" & iINPUTCHANNELNumber & iINPUTCHANNELInput

  Select Case sInput
    ' INPUTCHANNEL0
''''    Case "IN00"
''''         GetINPUTCHANNELxInput = GetCurrentPinFromAlternatePin(r, sVarPre & "_REQ0")
''''    Case "IN01"
''''         GetINPUTCHANNELxInput = GetCurrentPinFromAlternatePin(r, sVarPre & "_REQ4")
''''    Case "IN02"
''''         If (r.Exist("GPTA_OUT0") = True) Then
''''           If Not (r.v("GPTA_OUT0") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT0")
''''           End If
''''         End If
''''    Case "IN03"
''''         If (r.Exist("MSC0_FCLP") = True) Then
''''           If Not (r.v("MSC0_FCLP") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("MSC0_FCLP")
''''           End If
''''         End If
''''
''''    ' INPUTCHANNEL1
''''    Case "IN10"
''''         GetINPUTCHANNELxInput = GetCurrentPinFromAlternatePin(r, sVarPre & "_REQ1")
''''    Case "IN11"
''''         GetINPUTCHANNELxInput = GetCurrentPinFromAlternatePin(r, sVarPre & "_REQ5")
''''    Case "IN12"
''''         If (r.Exist("GPTA_OUT8") = True) Then
''''           If Not (r.v("GPTA_OUT8") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT8")
''''           End If
''''         End If
''''    Case "IN13"
''''         If (r.Exist("GPTA_OUT4") = True) Then
''''           If Not (r.v("GPTA_OUT4") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT4")
''''           End If
''''         End If
''''
''''    ' INPUTCHANNEL2
''''    Case "IN20"
''''         GetINPUTCHANNELxInput = GetCurrentPinFromAlternatePin(r, sVarPre & "_REQ2")
''''    Case "IN21"
''''         If (r.Exist("GPTA_OUT7") = True) Then
''''           If Not (r.v("GPTA_OUT7") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT7")
''''           End If
''''         End If
''''    Case "IN22"
''''         If (r.Exist("GPTA_OUT16") = True) Then
''''           If Not (r.v("GPTA_OUT16") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT16")
''''           End If
''''         End If
''''    Case "IN23"
''''         If (r.Exist("GPTA_OUT17") = True) Then
''''           If Not (r.v("GPTA_OUT17") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT17")
''''           End If
''''         End If
''''
''''    ' INPUTCHANNEL3
''''    Case "IN30"
''''         GetINPUTCHANNELxInput = GetCurrentPinFromAlternatePin(r, sVarPre & "_REQ3")
''''    Case "IN31"
''''         If (r.Exist("GPTA_OUT22") = True) Then
''''           If Not (r.v("GPTA_OUT22") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT22")
''''           End If
''''         End If
''''    Case "IN32"
''''         If (r.Exist("GPTA_OUT24") = True) Then
''''           If Not (r.v("GPTA_OUT24") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT24")
''''           End If
''''         End If
''''    Case "IN33"
''''         If (r.Exist("GPTA_OUT25") = True) Then
''''           If Not (r.v("GPTA_OUT25") = "0") Then
''''             GetINPUTCHANNELxInput = r.v("GPTA_OUT25")
''''           End If
''''         End If
         Case Else
         
  End Select

End Function


'*****************************************************************************
'Description:
'             This functoin returns a minimal module clock in MHz.
'-----------------------------------------------------------------------------
'Parameters:
'       r         As Projectdata
'       sRegPre   Register Prefix
'       sVarPre   Module Prefix
'
'-----------------------------------------------------------------------------
'Returns:
'        minimal module clock [MHz]
'*****************************************************************************
Function GetMinModuleClock(r As ProjectData, sRegPre As String, sVarPre As String) As Double
    On Error Resume Next
    GetMinModuleClock = 1
    
    GetMinModuleClock = 1 / 1024 * GetSystemClock(r)
    GetMinModuleClock = GetMinModuleClock / 2

End Function

'*****************************************************************************
'Description:
'             This functoin returns a maximal module clock in MHz.
'-----------------------------------------------------------------------------
'Parameters:
'       r   As Projectdata
'       sRegPre   Register Prefix
'       sVarPre   Module Prefix
'
'-----------------------------------------------------------------------------
'Returns:
'        maximal module clock [MHz]
'*****************************************************************************
Function GetMaxModuleClock(r As ProjectData, sRegPre As String, sVarPre As String) As Double
    On Error Resume Next
    GetMaxModuleClock = 1
    
    If (r.v(sRegPre & "FDR_DM") < 2) Then
        'if normal mode
        GetMaxModuleClock = GetSystemClock(r)
    Else
        'if fractional mode
        GetMaxModuleClock = 1023 / 1024 * GetSystemClock(r)
    End If
    GetMaxModuleClock = GetMaxModuleClock / 2

End Function

'*****************************************************************************
'Description:
'             This functoin returns a module clock in MHz.
'-----------------------------------------------------------------------------
'Parameters:
'       r   As Projectdata
'       sRegPre   Register Prefix
'       sVarPre   Module Prefix
'
'-----------------------------------------------------------------------------
'Returns:
'        module clock [MHz]
'*****************************************************************************
Function GetModuleClock(r As ProjectData, sRegPre As String, sVarPre As String) As Double
    On Error Resume Next
    GetModuleClock = 1
    
    If (r.v(sRegPre & "FDR_DM") < 2) Then
        'if normal mode
        GetModuleClock = GetSystemClock(r) * 1 / (1024 - r.l(sRegPre & "FDR_STEP")) / 2
    Else
        'if fractional mode
        GetModuleClock = GetSystemClock(r) * r.l(sRegPre & "FDR_STEP") / 1024 / 2
    End If
    GetModuleClock = GetModuleClock
End Function

'*****************************************************************************
'Description:
'             This function updates a module clock.
'-----------------------------------------------------------------------------
'Parameters:
'       r   As Projectdata
'       sRegPre   Register Prefix
'       sVarPre   Module Prefix
'
'-----------------------------------------------------------------------------
'Returns:
'        none
'*****************************************************************************
Sub UpdateModuleClock(r As ProjectData, sRegPre As String, sVarPre As String)
    On Error Resume Next
    Dim d As Double
    Dim l As Long
    ''''l = CONVERT2HZ
    
''''    If (r.d(sVarPre & "_RequiredClock") * l > GetMaxModuleClock(r, sRegPre, sVarPre) * l) Then
''''        r.d(sVarPre & "_RequiredClock") = GetMaxModuleClock(r, sRegPre, sVarPre)
''''    ElseIf (r.d(sVarPre & "_RequiredClock") * l < GetMinModuleClock(r, sRegPre, sVarPre) * l) Then
''''        r.d(sVarPre & "_RequiredClock") = GetMinModuleClock(r, sRegPre, sVarPre)
''''    End If
    
''''    If (r.v(sRegPre & "FDR_DM") < 2) Then
''''        'if normal mode
''''        d = 1024 - GetSystemClock(r) / (r.d(sVarPre & "_RequiredClock") * 2)
''''        If (d > 1023) Then
''''            d = 1023
''''        End If
''''    Else
''''        'if fractional mode
''''        d = r.d(sVarPre & "_RequiredClock") / GetSystemClock(r) * 1024 * 2
''''        If (d > 1023) Then
''''            d = 1023
''''        ElseIf (d = 0) Then
''''            d = 0
''''        End If
''''    End If

''''    r.l(sRegPre & "FDR_STEP") = d
End Sub

'*****************************************************************************
'Description:
'        This function checks if the module clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            the module clock is disabled
'        False           else
'*****************************************************************************
Function IsModuleClockDisabled(r As ProjectData, sRegPre As String, sVarPre As String) As Boolean
  On Error Resume Next

  IsModuleClockDisabled = False
  IsModuleClockDisabled = (r.v(sRegPre & "FDR_DM") = 0 Or IsPinSYSCLKDeselected(r, ""))

End Function

'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if the module
'        clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************
Function GetTooltipModuleClockDisabled(r As ProjectData, sRegPre As String, sVarPre As String) As String
  On Error Resume Next

  GetTooltipModuleClockDisabled = ""

  If (IsPinSYSCLKDeselected(r, "")) Then
    GetTooltipModuleClockDisabled = GetTooltipModuleClockDisabled & FormatDisabledToolTip("no pin as SYSCLK selected")
  End If
  If (r.v(sRegPre & "FDR_DM") = 0) Then
    GetTooltipModuleClockDisabled = GetTooltipModuleClockDisabled & FormatDisabledToolTip("the SYSCLK output is disabled")
  End If

End Function

'*****************************************************************************
'Description:
'        This function checks if the SYSCLK pin is deselected.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            pin deselected
'        False           else
'*****************************************************************************
Function IsPinSYSCLKDeselected(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  Dim sIndex As String
  Dim sPrefix As String

  sIndex = "SCU" & vIndex
  sPrefix = sIndex & "_"
  
  IsPinSYSCLKDeselected = False

  ''''If (GetCurrentPinFromAlternatePin(r, sIndex & "_SYSCLK") = NO_PIN_SELECTED) Then
   '''' IsPinSYSCLKDeselected = True
  ''''End If

End Function


'*****************************************************************************
'Description:
'        This function checks if the emergency stop pin is deselected.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            pin deselected
'        False           else
'*****************************************************************************
Function IsPinEMSDeselected(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  Dim sIndex As String
  Dim sPrefix As String

  sIndex = "SCU" & vIndex
  sPrefix = sIndex & "_"
  
  IsPinEMSDeselected = False

''''  If (GetCurrentPinFromAlternatePin(r, sIndex & "_EMS") = NO_PIN_SELECTED) Then
''''    IsPinEMSDeselected = True
''''  End If

End Function

'*****************************************************************************
'Description:
'        This function returns the alternate pin name or other input signal
'        of a REQLINEx input line.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        group           Group A or group B input
'        iINPUTCHANNELNumber  number of the REQLINE (0-3)
'        INPUTCHANNELInput   number of the input of a REQLINE (0-3)
'-----------------------------------------------------------------------------
'Returns:
'        Alternate pin name (e.g "REQ3") or input signal
'*****************************************************************************
Function IsERUOptAvailable(r As ProjectData, vIndex As Variant, sInput As String, iNr As Integer) As Variant
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  IsERUOptAvailable = False

  sVarPre = "SCU" & vIndex
  sRegPre = "" ' sVarPre & "_"
  
  Select Case sInput
  'ERS0
    Case "ERU_0A0"
         IsERUOptAvailable = (IsAlternateInputPinFree(r, "SCU_EX0AINA_I") And (Not r.v("INT_USE_ERS0")))
    Case "ERU_0A1"
         IsERUOptAvailable = False
    Case "ERU_0A2"
         IsERUOptAvailable = False
''''         If (r.v("U0C0_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX0 signal
''''            If (r.v("U0C0_ASC_cboRxD") = "None") And (r.v("U0C0_SSC_cboRxD") = "None") And (r.v("U0C0_IIC_cboSDA") = "None") Then
''''               IsERUOptAvailable = False
''''            Else
''''               IsERUOptAvailable = True
''''            End If
''''        End If
    Case "ERU_0A3"
             IsERUOptAvailable = False
''''         If (r.v("U0C0_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX2 signal
''''            'Chk if SSC is in Slave mode
'''''            If (r.v("U0C0_SSC_OptOperMode") = 1) Then
''''                If (r.v("U0C0_SSC_cboSlS") = "None") Then
''''                   IsERUOptAvailable = False
''''                Else
''''                   IsERUOptAvailable = True
''''                End If
'''''             Else
'''''               IsERUOptAvailable = False
'''''            End If
''''        End If
''''
    Case "ERU_0B0"
         IsERUOptAvailable = IsAlternateInputPinFree(r, "SCU_EX0BINA_I")
    Case "ERU_0B1"
         IsERUOptAvailable = IsAlternateInputPinFree(r, "SCU_EX0BINB")
    Case "ERU_0B2"
         IsERUOptAvailable = False
''''          If (r.v("U0C1_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX0 signal
''''            If (r.v("U0C1_ASC_cboRxD") = "None") And (r.v("U0C1_SSC_cboRxD") = "None") And (r.v("U0C1_IIC_cboSDA") = "None") Then
''''               IsERUOptAvailable = False
''''            Else
''''               IsERUOptAvailable = True
''''            End If
''''        End If
    Case "ERU_0B3"
        IsERUOptAvailable = False
''''         If (r.v("U0C1_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX2 signal
''''            'Chk if SSC is in Slave mode
'''''            If (r.v("U0C0_SSC_OptOperMode") = 1) Then
''''                If (r.v("U0C1_SSC_cboSlS") = "None") Then
''''                   IsERUOptAvailable = False
''''                Else
''''                   IsERUOptAvailable = True
''''                End If
'''''             Else
'''''               IsERUOptAvailable = False
'''''            End If
''''        End If
    'ERS1
    Case "ERU_1A0"
         IsERUOptAvailable = (IsAlternateInputPinFree(r, "SCU_EX1AINA_I") And (Not r.v("INT_USE_ERS1")))
    Case "ERU_1A1"
         IsERUOptAvailable = False
    Case "ERU_1A2"
         IsERUOptAvailable = False
''''          If (r.v("U1C0_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX0 signal
''''            If (r.v("U1C0_ASC_cboRxD") = "None") And (r.v("U1C0_SSC_cboRxD") = "None") And (r.v("U1C0_IIC_cboSDA") = "None") Then
''''               IsERUOptAvailable = False
''''            Else
''''               IsERUOptAvailable = True
''''            End If
''''        End If
    Case "ERU_1A3"
    
         IsERUOptAvailable = False
''''         If (r.v("U1C0_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX2 signal
''''            'Chk if SSC is in Slave mode
'''''            If (r.v("U0C0_SSC_OptOperMode") = 1) Then
''''                If (r.v("U1C0_SSC_cboSlS") = "None") Then
''''                   IsERUOptAvailable = False
''''                Else
''''                   IsERUOptAvailable = True
''''                End If
'''''             Else
'''''               IsERUOptAvailable = False
'''''            End If
''''        End If
''''
    Case "ERU_1B0"
         IsERUOptAvailable = IsAlternateInputPinFree(r, "SCU_EX1BINA_I")
    Case "ERU_1B1"

         If (r.v("CAN_USE_NODE4_RXD_PIN") = "Pin RXDC4 is not Used" Or r.v("MAIN_CPU_TYPE") = "XC2267-96F66") Then
         IsERUOptAvailable = False
           If r.v(sVarPre & "_USE_ERU" & iNr & "B") = 2 Then
            r.v(sVarPre & "_USE_ERU" & iNr & "B") = 0
           End If
         Else
         IsERUOptAvailable = True
         End If

    Case "ERU_1B2"
        IsERUOptAvailable = False
''''         If (r.v("U1C1_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX0 signal
''''            If (r.v("U1C1_ASC_cboRxD") = "None") And (r.v("U1C1_SSC_cboRxD") = "None") And (r.v("U1C1_IIC_cboSDA") = "None") Then
''''               IsERUOptAvailable = False
''''            Else
''''               IsERUOptAvailable = True
''''            End If
''''        End If
    Case "ERU_1B3"
    
        IsERUOptAvailable = False
''''         If (r.v("U1C1_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX2 signal
''''            'Chk if SSC is in Slave mode
'''''            If (r.v("U0C0_SSC_OptOperMode") = 1) Then
''''                If (r.v("U1C1_SSC_cboSlS") = "None") Then
''''                   IsERUOptAvailable = False
''''                Else
''''                   IsERUOptAvailable = True
''''                End If
'''''             Else
'''''               IsERUOptAvailable = False
'''''            End If
''''        End If
         
     'ERS2
    Case "ERU_2A0"
         IsERUOptAvailable = (IsAlternateInputPinFree(r, "SCU_EX2AINA_I") And (Not r.v("INT_USE_ERS2")))
    Case "ERU_2A1"
         If r.v("CAN_USE_NODE3_RXD_PIN") = "Pin RXDC3 is not Used" Then
         IsERUOptAvailable = False
         Else
         IsERUOptAvailable = True
         End If
    Case "ERU_2A2"
    
        IsERUOptAvailable = False
''''         If (r.v("U2C0_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX0 signal
''''            If (r.v("U2C0_ASC_cboRxD") = "None") And (r.v("U2C0_SSC_cboRxD") = "None") And (r.v("U2C0_IIC_cboSDA") = "None") Then
''''               IsERUOptAvailable = False
''''            Else
''''               IsERUOptAvailable = True
''''            End If
''''        End If
    Case "ERU_2A3"
    
    IsERUOptAvailable = False
''''         If (r.v("U2C0_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX2 signal
''''            'Chk if SSC is in Slave mode
'''''            If (r.v("U0C0_SSC_OptOperMode") = 1) Then
''''                If (r.v("U2C0_SSC_cboSlS") = "None") Then
''''                   IsERUOptAvailable = False
''''                Else
''''                   IsERUOptAvailable = True
''''                End If
'''''             Else
'''''               IsERUOptAvailable = False
'''''            End If
''''        End If
''''
    Case "ERU_2B0"
    
        IsERUOptAvailable = False
''''            'Condn for DX1 signal
''''            If (r.v("U2C0_Proto") = "SSC") Then
''''                'Chk if SSC is in Slave mode
'''''                If (r.v("U2C0_SSC_OptOperMode") = 1) Then
''''                    If (r.v("U2C0_SSC_cboClk") = "None") Then
''''                       IsERUOptAvailable = False
''''                    Else
''''                       IsERUOptAvailable = True
''''                    End If
'''''                Else
'''''                    IsERUOptAvailable = False
'''''                End If
''''
''''            ElseIf (r.v("U2C0_Proto") = "IIC") Then
''''                'Chk if IIC is in Slave or Multi Master mode
'''''                If (r.v("U2C0_IIC_OMOD") <> 0) Then
''''                    If (r.v("U2C0_IIC_cboSCL") = "None") Then
''''                       IsERUOptAvailable = False
''''                    Else
''''                       IsERUOptAvailable = True
''''                    End If
'''''                Else
'''''                    IsERUOptAvailable = False
'''''                End If
''''            End If
            
    Case "ERU_2B1"
         If r.v("CAN_USE_NODE2_RXD_PIN") = "Pin RXDC2 is not Used" Then
         IsERUOptAvailable = False
         Else
         IsERUOptAvailable = True
         End If
    Case "ERU_2B2"
    
        IsERUOptAvailable = False
''''         If (r.v("U2C1_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX0 signal
''''            If (r.v("U2C1_ASC_cboRxD") = "None") And (r.v("U2C1_SSC_cboRxD") = "None") And (r.v("U2C1_IIC_cboSDA") = "None") Then
''''               IsERUOptAvailable = False
''''            Else
''''               IsERUOptAvailable = True
''''            End If
''''        End If
    Case "ERU_2B3"
    
        IsERUOptAvailable = False
''''         If (r.v("U2C1_Proto") = "") Then
''''            IsERUOptAvailable = False
''''         Else
''''            'Condn for DX2 signal
''''            'Chk if SSC is in Slave mode
'''''            If (r.v("U0C0_SSC_OptOperMode") = 1) Then
''''                If (r.v("U2C1_SSC_cboSlS") = "None") Then
''''                   IsERUOptAvailable = False
''''                Else
''''                   IsERUOptAvailable = True
''''                End If
'''''             Else
'''''               IsERUOptAvailable = False
'''''            End If
''''        End If
''''
      'ERS3
         
    Case "ERU_3A0"
         IsERUOptAvailable = (IsAlternateInputPinFree(r, "SCU_EX3AINA_I") And (Not r.v("INT_USE_ERS3")))
    Case "ERU_3A1"
          If r.v("CAN_USE_NODE1_RXD_PIN") = "Pin RXDC1 is not Used" Then
         IsERUOptAvailable = False
         Else
         IsERUOptAvailable = True
         End If

    Case "ERU_3B0"
         IsERUOptAvailable = False
    Case "ERU_3B1"
         If r.v("CAN_USE_NODE0_RXD_PIN") = "Pin RXDC0 is not Used" Then
         IsERUOptAvailable = False
         Else
         IsERUOptAvailable = True
         End If

  End Select

End Function

'*****************************************************************************
'Description:
'        This function do the default settings when no pin in Group A/B is selected.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             ERS number
'-----------------------------------------------------------------------------
'Returns:
'        True            pin deselected
'        False           else
'*****************************************************************************
Function DefaultSettingsForSourceSel(r As ProjectData, vIndex As Variant, iNr As Integer)
  On Error Resume Next
  Dim sIndex As String
  Dim sPrefix As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "SCU" & vIndex
  sRegPre = sVarPre & "_"

  
  If r.v(sVarPre & "_USE_ERU" & iNr & "B") = 0 And r.v(sVarPre & "_USE_ERU" & iNr & "A") = 0 Then 'No input is selected
    r.v(sRegPre & "EXICON" & iNr & "_SS") = 0
  End If
  If r.v(sVarPre & "_USE_ERU" & iNr & "B") <> 0 And r.v(sVarPre & "_USE_ERU" & iNr & "A") = 0 Then 'B is selected
    r.v(sRegPre & "EXICON" & iNr & "_SS") = 1
  End If
  If r.v(sVarPre & "_USE_ERU" & iNr & "A") <> 0 And r.v(sVarPre & "_USE_ERU" & iNr & "B") = 0 Then 'No input is selected
    r.v(sRegPre & "EXICON" & iNr & "_SS") = 0
  End If

  sIndex = "SCU" & vIndex
  sPrefix = sIndex & "_"
  

End Function

'*****************************************************************************
'Description:
'        This function do the default settings when trigger is disabled in ETLx
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             ERS number
'-----------------------------------------------------------------------------
'Returns:
'        True            pin deselected
'        False           else
'*****************************************************************************
''''Function DefaultSettingsForOutputChannelx(r As ProjectData, vIndex As Variant, iNr As Integer)
''''  On Error Resume Next
''''  Dim sIndex As String
''''  Dim sPrefix As String
''''  Dim sVarPre As String
''''  Dim sRegPre As String
''''  Dim i As Integer
''''
''''  sVarPre = "SCU" & vIndex
''''  sRegPre = sVarPre & "_"
''''
'''' For i = 0 To 3
'''' r.v(sRegPre & "EXOCON" & iNr & "_IPEN" & i) = 0
'''' Next i
'''' r.v(sRegPre & "EXOCON" & iNr & "_GEEN") = 0
'''' r.v(sRegPre & "EXOCON" & iNr & "_GP") = 0
'''' r.v(sRegPre & "EXOCON" & iNr & "_ISS") = 0
''''  sIndex = "SCU" & vIndex
''''  sPrefix = sIndex & "_"
''''
''''
''''End Function

'*****************************************************************************
'Description:
'        This function returns the tool tip for the corresponding ERU source option.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        group           Group A or group B input
'        iINPUTCHANNELNumber  number of the REQLINE (0-3)
'        INPUTCHANNELInput   number of the input of a REQLINE (0-3)
'-----------------------------------------------------------------------------
'Returns:
'        Tool tip for the corresponding ERU source option.
'*****************************************************************************
Function GetERUDisableToolTip(r As ProjectData, vIndex As Variant, sInput As String, iNr As Integer) As Variant
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  

  sVarPre = "SCU" & vIndex
  sRegPre = "" ' sVarPre & "_"
  GetERUDisableToolTip = " "
  
  Select Case sInput
  
    'Pins used in INT page
    Case "ERU_0A0", "ERU_1A0", "ERU_2A0", "ERU_3A0"
    
         If (Not (IsAlternateInputPinFree(r, "SCU_EX" & iNr & "AINA_I"))) Then
            GetERUDisableToolTip = GetDisabledAlternatePinTooltip(r, "SCU_EX" & iNr & "AINA_I")
         End If
         
         If (r.v("INT_USE_ERS" & iNr) = 1) Then
            GetERUDisableToolTip = vbCrLf & "-pin is used in INT page to generate ERU_IOUT" & iNr & " signal " 'GetDisabledAlternatePinTooltip(r, "SCU_EX" & iNr & "AINA_I")
         End If
         
    Case "ERU_0A1"
         GetERUDisableToolTip = vbCrLf & "-This option is currently not supported "
         
   'Pins not used in INT page
    Case "ERU_0B0", "ERU_1B0"
         If (Not (IsAlternateInputPinFree(r, "SCU_EX" & iNr & "BINA_I"))) Then
            GetERUDisableToolTip = GetDisabledAlternatePinTooltip(r, "SCU_EX" & iNr & "AINA_I")
         End If
         
    Case "ERU_0B1"
         If (Not (IsAlternateInputPinFree(r, "SCU_EX" & iNr & "BINB"))) Then
            GetERUDisableToolTip = GetDisabledAlternatePinTooltip(r, "SCU_EX" & iNr & "BINB")
         End If
    
    'ESR2
    Case "ERU_1A1"
         GetERUDisableToolTip = vbCrLf & "-This option is currently not supported"
    
         
    'MultiCAN pins
    Case "ERU_2A1", "ERU_3A1", "ERU_2B1", "ERU_3B1"
         GetERUDisableToolTip = vbCrLf & "-CAN receive input pin is not selected"
         
    Case "ERU_1B1"
        If r.v("MAIN_CPU_TYPE") = "XC2267-96F66" Then
        GetERUDisableToolTip = vbCrLf & "-Node 4 is not available in this controller package"
        Else
        GetERUDisableToolTip = vbCrLf & "-CAN receive input pin is not selected"
        End If
        
      
    
    
         
     'USIC DX0INS pins
    Case "ERU_0A2", "ERU_1A2", "ERU_2A2", "ERU_0B2", "ERU_1B2", "ERU_2B2"
    GetERUDisableToolTip = vbCrLf & "-This option is currently not supported"
''''         GetERUDisableToolTip = vbCrLf & "-USIC data input pin is not selected"
         
     'USIC DX2INS pins
    Case "ERU_0A3", "ERU_1A3", "ERU_2A3", "ERU_0B3", "ERU_1B3", "ERU_2B3"
    GetERUDisableToolTip = vbCrLf & "-This option is currently not supported"
''''         GetERUDisableToolTip = vbCrLf & "-USIC control input pin is not selected"
         
     'USIC DX1INS pins
    Case "ERU_2B0", "ERU_3B0"
    GetERUDisableToolTip = vbCrLf & "-This option is currently not supported"
''''           GetERUDisableToolTip = vbCrLf & "-USIC clock input pin is not selected"
               
     
  End Select

End Function






