Attribute VB_Name = "Module1"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Port.inc"

Option Explicit

'*****************************************************************************
' Module:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the
'        CAPCOM6x dialog script and in the CAPCOM6x codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   Neelakanta   03.05.07     version 1.0 for XC22xx
'
'*****************************************************************************


'*****************************************************************************
' Constants
'*****************************************************************************
Global Const CH_HIGH = 8

'*****************************************************************************
'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
'        "CAPCOMx_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 sVarPre As String
  Dim sFctName As String
  Dim i As Integer
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer

  sVarPre = "CCU" & vIndex

  iCh_low = 0
  iCh_high = 3
  iTmr_12 = 12
  iTmr_13 = 13

  ' 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. SSC_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 CAPCOMx_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sVarPre)
  
  sReturnValue = "None"
  
  If (Not func.AddFunction(sVarPre & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "StartTmr"
  sDescription = "This macro starts the selected " & sVarPre & " timer. " & _
                 "The timer continues counting from where it stopped. " & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be started"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "StopTmr"
  sDescription = "This macro stops the selected " & sVarPre & " timer. " & _
                 "The content of the timer register remains unchanged. " & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be stopped"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "ResetTmr"
  sDescription = "This macro sets the selected " & sVarPre & " timer " & _
                 "counter register to zero. Timer is not stopped." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be cleared"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "SetTmrPeriod"
  sDescription = "This macro loads the period register of the selected " & sVarPre & _
                 " timer." & vbCrLf & vbCrLf & _
                 "Note: Call the macro " & r.v(sVarPre & "_NAME_EnableShadowTransfer") & "() to " & _
                 "enable the shadow transfer." & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be used"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function
    sDescription = "16-bit Value with which the " & sVarPre & " timer reload register is to be loaded"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "Value", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "SetDeadTimePeriod"
  sDescription = "This macro loads the counter of the deat time register."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "counter value (ubValue = 0x01 .. 0x3F)"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubValue", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "EnableShadowTransfer"
  sDescription = "This macro enables the transfer from the shadow registers to " & _
                 "the actual " & sVarPre & " registers." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be used"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "LoadChannelShadowRegister"
  sDescription = "This macro loads the selected " & sVarPre & " channel shadow register " & _
                 "with the parameter Value. " & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions are available for RegName: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_low) & " .. " & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_high) & _
                 " (see @Defines in header file)"

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " channel to be loaded"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ChName", "", sDescription)) Then Exit Function
    sDescription = "16-bit Value with which the " & sVarPre & " shadow register is to be loaded"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "Value", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "GetChannelShadowRegister"
  sDescription = "This macro returns the content of the " & sVarPre & _
                 " capture/compare shadow register of the selected channel." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions are available for RegName: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_low) & " .. " & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_high) & _
                 " (see @Defines in header file)"

  sReturnValue = "Current 16-bit value of the " & sVarPre & " shadow register"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " channel to be readed"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ChName", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "GetChannelRegister"
  sDescription = "This macro returns the content of the " & sVarPre & _
                 " capture/compare register of the selected channel." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions are available for RegName: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_low) & " .. " & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_high) & _
                 " (see @Defines in header file)"

  sReturnValue = "Current 16-bit value of the " & sVarPre & " register"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " channel to be readed"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ChName", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "GetTmrCounter"
  sDescription = "This macro returns the contens of the selected " & sVarPre & _
                 " timer counter register." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "16-bit counter value"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be used"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "SetTmrCounter"
  sDescription = "This macro loads the selected " & sVarPre & _
                 " timer counter register with the parameter Value . " & _
                 "It is possible to use this macro " & _
                 "only if the selected timer is stopped." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions for TimerNr are available: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & vbCrLf & _
                 r.v(sVarPre & "_PARA_TIMER_" & iTmr_13)

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " timer to be used"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "TimerNr", "", sDescription)) Then Exit Function
    sDescription = "16-bit value with which the " & sVarPre & " counter register is to be loaded"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "Value", "", sDescription)) Then Exit Function


  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "SetStatusBit"
  sDescription = "This macro sets the capture / compare modifikation status bit of the selected " & _
                 sVarPre & " channel. " & _
                 "" & vbCrLf & _
                 "The following definitions are available for ChName: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_low) & " .. " & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_high) & _
                 " (see @Defines in header file)"

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " channel to be used"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ChName", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_...
  '------------------------------------------------------------------------------------------------
  sFctName = "ResetStatusBit"
  sDescription = "This macro resets the capture / compare modifikation status bit of the selected " & _
                 sVarPre & " channel. " & _
                 "" & vbCrLf & _
                 "The following definitions are available for ChName: " & vbCrLf & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_low) & " .. " & _
                 r.v(sVarPre & "_PARA_CHANNEL_" & iCh_high) & _
                 " (see @Defines in header file)"

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Name of the " & sVarPre & " channel to be used"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ChName", "", sDescription)) Then Exit Function


  For i = 0 To 3

      '------------------------------------------------------------------------------------------------
      ' Description for CAPCOMx_NAME_...
      '------------------------------------------------------------------------------------------------
      sFctName = "NodeI" & i
      sDescription = "This is the interrupt service routine for the " & sVarPre & _
                     " node I" & Format(i) & ". If the content of the corresponding " & _
                     "compare timer (configurable) equals the content of the " & _
                     "capture/compare register or if a capture event " & _
                     "occurs at the associated port pin, the interrupt request " & _
                     "flag is set and an interrupt is triggered " & _
                     "(only if enabled)."

                     sDescription = sDescription & vbCrLf & TOOLTIP_ISR_USERCODE

      sReturnValue = "None"
      If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 2)) Then Exit Function

  Next i

  '------------------------------------------------------------------------------------------------
  ' Description for CAPCOMx_NAME_... vSyncStartTmr
  '------------------------------------------------------------------------------------------------
  sFctName = "vSyncStartTmr"
  sDescription = "This macro is used to configure synchronous feature of CCx (CCU6x & CC2) " _
               & "timers. By using this macro following timers CCU6x - T12, T13 and " _
               & "CC2 - T7, T8 will be starting Synchronously depending on the " _
               & "configuration of the modules. " _
              & vbCrLf & vbCrLf & _
                 "NOTE : This function code will be generated in Main.h, and it " _
                      & "has to be called in the Main_vInit() function. "
                      
  sReturnValue = "None"
  If (Not func.AddFunction("CCU60_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) 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
  Dim sParaName As String
  Dim i As Integer
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

  iCh_low = 0
  iCh_high = 3
  iTmr_12 = 12
  iTmr_13 = 13


  ' 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 DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies " & sVarPre & " timer " & iTmr_12
  sParaName = "TIMER_" & iTmr_12
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies " & sVarPre & " timer " & iTmr_13
  sParaName = "TIMER_" & iTmr_13
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  For i = iCh_low To iCh_high
      '------------------------------------------------------------------------------------------------
      ' Description for DUMMY_PARA_xx
      '------------------------------------------------------------------------------------------------
      sDescription = "This parameter identifies " & sVarPre & " channel " & i
      sParaName = "CHANNEL_" & i
      If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function
  Next i
        
        If (Not para.Sort) Then Exit Function

  RefreshParameterDescriptions = True
End Function

'*****************************************************************************
'Description:
'          This function returns the module clock [MHz] of the
'          CAPCOM module depending on the configured modes
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           ParameterValue
'-----------------------------------------------------------------------------
'Returns:
'      GetCAPCOMSystemClock [MHz]
'
'*****************************************************************************
Function GetCAPCOMModuleClock(r As projectdata, vIndex As Variant) As Double
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim v As String
  
  sVarPre = "CAP" & vIndex
  sRegPre = sVarPre

  GetCAPCOMModuleClock = 1
  GetCAPCOMModuleClock = GetPeripheralClock(r)

End Function


'*****************************************************************************
'Description:
'        This function is called from the CAPCOM module
'        and calculate overflow time fot DTM.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        iTmr            Timer Nr (12)
'-----------------------------------------------------------------------------
'Returns:
'        overflow time [s]
'
'*****************************************************************************
Function GetOverflowDTM(r As projectdata, vIndex As Variant, iTmr As Integer) As Double
  On Error Resume Next
  Dim i As Integer
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If

'  i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")

  GetOverflowDTM = r.l(sRegPre & "T12DTC_DTM") * 2 ^ (i) / GetCAPCOMModuleClock(r, vIndex)


End Function

'*****************************************************************************
'Description:
'        This function is called from the CAPCOMx module
'        and calculate the maximum resolution for dead time.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        iTmr            Timer Nr. (12)
'-----------------------------------------------------------------------------
'Returns:
'        Value of the max. resolution [s]
'
'*****************************************************************************
Function GetMaxResolutionDTM(r As projectdata, vIndex As Variant, iTmr As Integer) As Double
  On Error Resume Next
  Dim sRegPre As String
  Dim sVarPre As String

    Dim i As Integer
    
  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If


  GetMaxResolutionDTM = 255 * 2 ^ (i) / _
                        GetCAPCOMModuleClock(r, vIndex)

End Function

'*****************************************************************************
'Description:
'        This function is called from the CAPCOMx module
'        and calculate the maximum resolution for dead time.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        iTmr            Timer Nr. (12)
'-----------------------------------------------------------------------------
'Returns:
'        Value of the max. resolution [s]
'
'*****************************************************************************
Function GetMinResolutionDTM(r As projectdata, vIndex As Variant, iTmr As Integer) As Double
  On Error Resume Next
  Dim sRegPre As String
  Dim sVarPre As String

Dim i As Integer

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If

  GetMinResolutionDTM = 2 ^ (i) / _
                        GetCAPCOMModuleClock(r, vIndex)

End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShowPage function
'        and calculate the value of the DTM.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        t               entered time [s]
'        rIndex
'             True       for overflow time
'             False      for underflow time
'        TimerNr         timer number (12)
'-----------------------------------------------------------------------------
'Returns:
'        Value of DTM
'
'*****************************************************************************
Function GetTimerNrValueDTM(r As projectdata, vIndex As Variant, t As Variant, rIndex As Boolean, iTmr As Integer) As Long
  On Error Resume Next
  Dim i As Integer
  Dim s As String
  Dim sRegPre As String
  Dim sVarPre As String

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

  If (t > GetMaxResolutionDTM(r, vIndex, iTmr)) Then
    t = GetMaxResolutionDTM(r, vIndex, iTmr)
  End If
  If (t < GetMinResolutionDTM(r, vIndex, iTmr)) Then
    t = GetMinResolutionDTM(r, vIndex, iTmr)
  End If

  
  i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")

  GetTimerNrValueDTM = t / 2 ^ i * GetCAPCOMModuleClock(r, vIndex)

End Function

'*****************************************************************************
'Description:
'        This function is called from the CAPCOM module
'        and calculate overflow time.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        iTmr            Timer Nr (e.g. 12 or 13)
'-----------------------------------------------------------------------------
'Returns:
'        overflow time [s]
'
'*****************************************************************************
Function GetOverflow(r As projectdata, vIndex As Variant, iTmr As Integer) As Double
  On Error Resume Next
  Dim i As Integer
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If

'  i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")

  If (iTmr = 12) Then
      If (r.v(sRegPre & "TCTR0_CTM") = 0) Then
          GetOverflow = (1 + r.sfr(sRegPre & "T" & iTmr & "PR")) * _
                        2 ^ (i) / GetCAPCOMModuleClock(r, vIndex)
      Else
          GetOverflow = (2 * (r.sfr(sRegPre & "T" & iTmr & "PR") + 1)) * _
                        2 ^ (i) / GetCAPCOMModuleClock(r, vIndex)
      End If
  Else
      GetOverflow = (1 + r.sfr(sRegPre & "T" & iTmr & "PR")) * _
                    2 ^ (i) / GetCAPCOMModuleClock(r, vIndex)
  End If

    
End Function

'*****************************************************************************
'Description:
'        This function is called from the CAPCOMx module
'        and calculate the maximum resolution for timer clock.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        iTmr            Timer Nr. (12 or 13)
'-----------------------------------------------------------------------------
'Returns:
'        Value of the max. resolution [s]
'
'*****************************************************************************
Function GetMaxResolution(r As projectdata, vIndex As Variant, iTmr As Integer) As Double
  On Error Resume Next
  Dim sRegPre As String
  Dim sVarPre As String

Dim i As Integer

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If

  If (iTmr = 12) Then
      If (r.v(sRegPre & "TCTR0_CTM") = 0) Then
          GetMaxResolution = 65536 * 2 ^ (i) / _
                             GetCAPCOMModuleClock(r, vIndex)
      Else
          GetMaxResolution = 2 * 65535 * 2 ^ (i) / _
                             GetCAPCOMModuleClock(r, vIndex)
      End If
  Else
      GetMaxResolution = 65536 * 2 ^ (i) / _
                         GetCAPCOMModuleClock(r, vIndex)
  End If

End Function

'*****************************************************************************
'Description:
'        This function is called from the CAPCOMx module
'        and calculate the maximum resolution for timer clock.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        iTmr            Timer Nr. (12 or 13)
'-----------------------------------------------------------------------------
'Returns:
'        Value of the max. resolution [s]
'
'*****************************************************************************
Function GetMinResolution(r As projectdata, vIndex As Variant, iTmr As Integer) As Double
  On Error Resume Next
  Dim sRegPre As String
  Dim sVarPre As String

Dim i As Integer

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If

  GetMinResolution = 2 ^ (i) / _
                     GetCAPCOMModuleClock(r, vIndex) * 2

End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShowPage function
'        and calculate the value of the timer register TxREL.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        vIndex          ParameterValue
'        t               entered time [s]
'        rIndex
'             True       for overflow time
'             False      for underflow time
'        TimerNr         timer number (12 or 13)
'-----------------------------------------------------------------------------
'Returns:
'        Value of the period register
'
'*****************************************************************************
Function GetTimerNrValue(r As projectdata, vIndex As Variant, t As Variant, rIndex As Boolean, iTmr As Integer) As Long
  On Error Resume Next
  Dim i As Integer
  Dim s As String
  Dim sRegPre As String
  Dim sVarPre As String

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

  If (t > GetMaxResolution(r, vIndex, iTmr)) Then
    t = GetMaxResolution(r, vIndex, iTmr)
  End If
  If (t < GetMinResolution(r, vIndex, iTmr)) Then
    t = GetMinResolution(r, vIndex, iTmr)
  End If

        If r.v(sRegPre & "TCTR0_T" & iTmr & "PRE") = 0 Then
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
        Else
            i = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") + 8
        End If
 
  If (iTmr = 12) Then
      If (r.v(sRegPre & "TCTR0_CTM") = 0) Then
          GetTimerNrValue = t / 2 ^ i * GetCAPCOMModuleClock(r, vIndex) - 1
      Else
          GetTimerNrValue = t / 2 ^ i * GetCAPCOMModuleClock(r, vIndex) / 2 - 1
      End If
  Else
      GetTimerNrValue = t / 2 ^ i * GetCAPCOMModuleClock(r, vIndex) - 1
  End If

End Function


'*****************************************************************************
'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, vIndex As Variant) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"
  
  IsModuleClockDisabled = False
  IsModuleClockDisabled = r.v(sRegPre & "KSCFG_MODEN") = 0
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, vIndex As Variant) As String
  On Error Resume Next
  Dim sIndex As String
  Dim sPrefix As String
  Dim sRegPre As String
  sIndex = "CC" & vIndex
  sPrefix = sIndex & ""
  sRegPre = "CCU" & vIndex & "_"
  
  GetTooltipModuleClockDisabled = ""
  If (r.v(sRegPre & "KSCFG_MODEN") = 0) Then
    GetTooltipModuleClockDisabled = GetTooltipModuleClockDisabled & _
      FormatDisabledTooltip("the module is disabled")
  End If

End Function


'*****************************************************************************
'Description:
'        This function returns the text item for the cbo TxCLK.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        iTmr           timer (12 or 13)
'        i              prescaler
'-----------------------------------------------------------------------------
'Returns:
'       string for cbo
'*****************************************************************************
Function GetTextForCLKcbo(r As projectdata, vIndex As Variant, iTmr As Integer, i As Integer) As String
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    s = ""
    s = "fcpu / " & 2 ^ i & " (Resolution: " & _
        Format$(2 ^ i / GetCAPCOMModuleClock(r, vIndex), "0.000") & " s)"
        
    GetTextForCLKcbo = s

End Function


'*****************************************************************************
'Description:
'        This function returns the text item for the cbo ExRunSel.
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex         parameter
'        iTmr           timer (12 or 13)
'        i              prescaler
'-----------------------------------------------------------------------------
'Returns:
'       string for cbo
'*****************************************************************************
Function GetTextForExRunSelCbo(vIndex As Variant, iTmr As Integer, i As Integer) As String
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
        
    If (i = 0) Then
        s = "Disable external setting of T" & iTmr & "R"
    ElseIf (i = 1) Then
        s = "Rising edge of signal T" & iTmr & "HR"
    ElseIf (i = 2) Then
        s = "Falling edge of signal T" & iTmr & "HR"
    ElseIf (i = 3) Then
        s = "Any edge of signal T" & iTmr & "HR"
    End If
    GetTextForExRunSelCbo = s
    
End Function


'*****************************************************************************
'Description:
'        This function returns the test for the cbo ExRunSel.
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex         parameter
'        iTmr           timer (12 or 13)
'        i              prescaler
'-----------------------------------------------------------------------------
'Returns:
'       string for cbo
'*****************************************************************************
Function GetTextForCntModeSelCbo(vIndex As Variant, iTmr As Integer, i As Integer) As String
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
    
        If (i = 0) Then
            s = "Disable Counting Mode of T" & iTmr & "R"
        ElseIf (i = 1) Then
            s = "TCTR4.T" & iTmr & "CNT written with 1 event"
        ElseIf (i = 2) Then
            s = "Counts rising edge detected at T" & iTmr & "HR"
        ElseIf (i = 3) Then
            s = "Counts falling edge detected at T" & iTmr & "HR"
        End If
    
    GetTextForCntModeSelCbo = s
    
End Function

'*****************************************************************************
'Description:
'        This function sets the register value for MCMPS.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub LoadMCMPSValue(r As projectdata, vIndex As Variant)
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
  
    r.v(sRegPre & "MCMOUTS_MCMPS") = _
      1 * r.v(sRegPre & "MCMPS_CC60") + _
      2 * r.v(sRegPre & "MCMPS_COUT60") + _
      4 * r.v(sRegPre & "MCMPS_CC61") + _
      8 * r.v(sRegPre & "MCMPS_COUT61") + _
      16 * r.v(sRegPre & "MCMPS_CC62") + _
      32 * r.v(sRegPre & "MCMPS_COUT62")

End Sub

'*****************************************************************************
'Description:
'        This function sets the register value for PSL.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub LoadPSLValue(r As projectdata, vIndex As Variant)
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
  
    r.v(sRegPre & "PSLR_PSL") = _
      1 * r.v(sRegPre & "PSL_CC60") + _
      2 * r.v(sRegPre & "PSL_COUT60") + _
      4 * r.v(sRegPre & "PSL_CC61") + _
      8 * r.v(sRegPre & "PSL_COUT61") + _
      16 * r.v(sRegPre & "PSL_CC62") + _
      32 * r.v(sRegPre & "PSL_COUT62")

End Sub

'*****************************************************************************
'Description:
'        This function sets the register value for TRPEN.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub LoadTRPENValue(r As projectdata, vIndex As Variant)
    On Error Resume Next
   
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
  
    r.v(sRegPre & "TRPCTR_TRPEN") = _
      1 * r.v(sRegPre & "TRPEN_CC60") + _
      2 * r.v(sRegPre & "TRPEN_COUT60") + _
      4 * r.v(sRegPre & "TRPEN_CC61") + _
      8 * r.v(sRegPre & "TRPEN_COUT61") + _
      16 * r.v(sRegPre & "TRPEN_CC62") + _
      32 * r.v(sRegPre & "TRPEN_COUT62")

End Sub

'*****************************************************************************
'Description:
'        This function sets the register value for T12MODEN.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub LoadT12MODENValue(r As projectdata, vIndex As Variant)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
  
    r.v(sRegPre & "MODCTR_T12MODEN") = _
      1 * r.v(sRegPre & "T12MODEN_CC60") + _
      2 * r.v(sRegPre & "T12MODEN_COUT60") + _
      4 * r.v(sRegPre & "T12MODEN_CC61") + _
      8 * r.v(sRegPre & "T12MODEN_COUT61") + _
      16 * r.v(sRegPre & "T12MODEN_CC62") + _
      32 * r.v(sRegPre & "T12MODEN_COUT62")

End Sub

'*****************************************************************************
'Description:
'        This function sets the register value for T13MODEN.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub LoadT13MODENValue(r As projectdata, vIndex As Variant)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
  
    r.v(sRegPre & "MODCTR_T13MODEN") = _
      1 * r.v(sRegPre & "T13MODEN_CC60") + _
      2 * r.v(sRegPre & "T13MODEN_COUT60") + _
      4 * r.v(sRegPre & "T13MODEN_CC61") + _
      8 * r.v(sRegPre & "T13MODEN_COUT61") + _
      16 * r.v(sRegPre & "T13MODEN_CC62") + _
      32 * r.v(sRegPre & "T13MODEN_COUT62")

End Sub

'*****************************************************************************
'Description:
'        This function sets the register value for PISELL.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Public Sub LoadPISELLValue(r As projectdata, vIndex As Variant)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
  
    r.sfr(sRegPre & "PISELL") = _
      1 * r.v(sRegPre & "PISELL_ISCC60") + _
      4 * r.v(sRegPre & "PISELL_ISCC61") + _
      16 * r.v(sRegPre & "PISELL_ISCC62") + _
      64 * r.v(sRegPre & "PISELL_ISTRP") + _
      256 * r.v(sRegPre & "PISELL_ISPOS0") + _
      1024 * r.v(sRegPre & "PISELL_ISPOS1") + _
      4096 * r.v(sRegPre & "PISELL_ISPOS2") + _
      16384 * r.v(sRegPre & "PISELL_IST12HR")

End Sub

'*****************************************************************************
'Description:
'        This function sets the selected capture/compare mode for selected
'        CCU6 channel.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        iChannel       channel nuber (0, 1, 2 or 3)
'        i              mode
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub SelectModeForCC6Channelx(r As projectdata, vIndex As Variant, iChannel As Integer, i As Integer)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim iActualMode As Integer

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"


        If (iChannel < 3) Then

        iActualMode = r.v(sRegPre & "T12MSEL_MSEL6" & iChannel)

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 0
        If (i = 0) Then
            r.v(sRegPre & "T12DTC_DTE" & iChannel) = 0
            r.v(sRegPre & "T12MODEN_CC6" & iChannel) = 0
            r.v(sRegPre & "T12MODEN_COUT6" & iChannel) = 0
            Call LoadT12MODENValue(r, vIndex)

            r.v(sRegPre & "CMPSTAT_CC6" & iChannel & "PS") = 0
            r.v(sRegPre & "CMPSTAT_COUT6" & iChannel & "PS") = 0

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 1
        ElseIf (i = 1) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 2
        ElseIf (i = 2) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 3
        ElseIf (i = 3) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 4
        ElseIf (i = 4) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 5
        ElseIf (i = 5) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 6
        ElseIf (i = 6) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 7
        ElseIf (i = 7) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 8
        ElseIf (i = 8) Then
            r.v(sRegPre & "T12MODEN_CC6" & iChannel) = 0
            r.v(sRegPre & "T12MODEN_COUT6" & iChannel) = 0
            Call LoadT12MODENValue(r, vIndex)

            r.v(sRegPre & "CMPSTAT_CC6" & iChannel & "PS") = 0
            r.v(sRegPre & "CMPSTAT_COUT6" & iChannel & "PS") = 0

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 9
        ElseIf (i = 9) Then
            r.v(sRegPre & "T12DTC_DTE" & iChannel) = 1

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 10
        ElseIf (i = 10) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 11
        ElseIf (i = 11) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 12
        ElseIf (i = 12) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 13
        ElseIf (i = 13) Then

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'soll mode = 14
        ElseIf (i = 14) Then

        End If

        r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i

    'if iChannel = 3
    Else

        r.v(sRegPre & "PSLR_PSL63") = 0
        r.v(sRegPre & "CMPSTAT_COUT63PS") = 0
        r.v(sRegPre & "TRPCTR_TRPEN13") = 0
        r.v(sRegPre & "MODCTR_ECT13O") = 0

    End If

End Sub


'*****************************************************************************
'Description:
'        This function returns a real duty cycle for selected channel.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        iChannel       channel nuber (0, 1 or 2)
'-----------------------------------------------------------------------------
'Returns:
'       real duty cycle
'*****************************************************************************
Function GetRealDutyCecle(r As projectdata, vIndex As Variant, iChannel As Integer) As Double
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim d As Double

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    If (iChannel < 3) Then
        d = (r.sfr(sRegPre & "T12PR") + 1 - _
          r.sfr(sRegPre & "CC6" & iChannel & "SR")) / _
          (r.sfr(sRegPre & "T12PR") + 1) * 100
    Else
        d = (r.sfr(sRegPre & "T13PR") + 1 - _
          r.sfr(sRegPre & "CC6" & iChannel & "SR")) / _
          (r.sfr(sRegPre & "T13PR") + 1) * 100
    End If
    
    If (d < 0) Then
      d = 0
    End If

   GetRealDutyCecle = d
    

End Function

'*****************************************************************************
'Description:
'        This function updates the register CC6xSR.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        iChannel       channel nuber (0, 1 or 2)
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub UpdateDutyCycle(r As projectdata, vIndex As Variant, iChannel As Integer)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim l As Long

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    If (iChannel < 3) Then
        l = (r.sfr(sRegPre & "T12PR") + 1) * _
          (1 - r.v(sVarPre & "_REQ_DUTY_CYCLE_" & iChannel) / 100)
    Else
        l = (r.sfr(sRegPre & "T13PR") + 1) * _
          (1 - r.v(sVarPre & "_REQ_DUTY_CYCLE_" & iChannel) / 100)
    End If

    If (l > 65535) Then
        l = 65535
    End If

    r.sfr(sRegPre & "CC6" & iChannel & "SR") = l

End Sub


'*****************************************************************************
'Description:
'        This function checks the selected channel. If the channel is disabled
'        its returns true, else false
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        iChannel       channel nuber (0, 1 or 2)
'-----------------------------------------------------------------------------
'Returns:
'       true if channel is disabled, else false
'*****************************************************************************
Function IsChannelDisabled(r As projectdata, vIndex As Variant, iChannel As Integer) As Boolean
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    IsChannelDisabled = False

    If (r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = 0) Then
        IsChannelDisabled = True
    Else
        IsChannelDisabled = False
    End If
    

End Function


'*****************************************************************************
'Description:
'        This function returns disabled tooltip if selected channel is disabled
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        iChannel       channel nuber (0, 1 or 2)
'-----------------------------------------------------------------------------
'Returns:
'       formated tooltip if channel is disabled
'*****************************************************************************
Function GetDisabledTooltipIfChaneelDisabled(r As projectdata, vIndex As Variant, iChannel As Integer) As String
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim s As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    s = ""
    s = FormatDisabledTooltip("capture/compare channel " & iChannel & " is disabled")

    GetDisabledTooltipIfChaneelDisabled = s

End Function


'*****************************************************************************
'Description:
'        This function sets the pages ModulationControl of Pin CC6x Or COUT6x
'        to the default.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'        sPin           name of the Pin (CC or COUT)
'        iChannel       channel nuber (0, 1 or 2)
'-----------------------------------------------------------------------------
'Returns:
'       formated tooltip if channel is disabled
'*****************************************************************************
Sub SetModulationControlPagesToDefault(r As projectdata, vIndex As Variant, sPin As String, iChannel As Integer)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    r.v(sRegPre & "TRPEN_" & sPin & "6" & iChannel) = 0
    Call LoadTRPENValue(r, vIndex)
    r.v(sRegPre & "PSL_" & sPin & "6" & iChannel) = 0
    Call LoadPSLValue(r, vIndex)
    r.v(sRegPre & "MCMPS_" & sPin & "6" & iChannel) = 0
    Call LoadMCMPSValue(r, vIndex)
    r.v(sRegPre & "T13MODEN_" & sPin & "6" & iChannel) = 0
    Call LoadT13MODENValue(r, vIndex)
    r.v(sRegPre & "T12MODEN_" & sPin & "6" & iChannel) = 0
    Call LoadT12MODENValue(r, vIndex)
    
End Sub

'*****************************************************************************
'Description:
'        This function disables the hall sensor mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub DisableHallSensorMode(r As projectdata, vIndex As Variant)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    Call SelectModeForCC6Channelx(r, vIndex, 0, 0)
    Call SelectModeForCC6Channelx(r, vIndex, 1, 0)
    Call SelectModeForCC6Channelx(r, vIndex, 2, 0)

End Sub

'*****************************************************************************
'Description:
'        This function enables the hall sensor mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub EnableHallSensorMode(r As projectdata, vIndex As Variant)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    Call SelectModeForCC6Channelx(r, vIndex, 0, 8)
    Call SelectModeForCC6Channelx(r, vIndex, 1, 8)
    Call SelectModeForCC6Channelx(r, vIndex, 2, 8)

    'disable dead time generation
    r.v(sRegPre & "T12DTC_DTE0") = 0
    r.v(sRegPre & "T12DTC_DTE1") = 0
    r.v(sRegPre & "T12DTC_DTE2") = 0

End Sub


'*****************************************************************************
'Description:
'        This function checks if the hall sensor mode is selected.
'-----------------------------------------------------------------------------
'Parameters:
'        r              reference to the ProjectData object
'        vIndex         parameter
'-----------------------------------------------------------------------------
'Returns:
'       true if hall sensor mode is selected, else false
'*****************************************************************************
Function IsHallSensorModeEnable(r As projectdata, vIndex As Variant) As Boolean
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    IsHallSensorModeEnable = False
    
    If ((r.sfr(sRegPre & "T12MSEL") And 4095) = 2184) Then
        IsHallSensorModeEnable = True
    End If

End Function


'*****************************************************************************
'Description:
'        This function returnd the text for the interrupt node cbo.
'-----------------------------------------------------------------------------
'Parameters:
'        iNode              node poninter
'-----------------------------------------------------------------------------
'Returns:
'       string for the cbo
'*****************************************************************************
Function GetCboIsrNodeText(iNode As Integer) As String
    On Error Resume Next
    
    GetCboIsrNodeText = "Interrupt node I" & iNode & " is selected"

End Function

'*****************************************************************************
'Description:
'        This function sets the selected node pointer
'-----------------------------------------------------------------------------
'Parameters:
'        r
'        vIndex             module index
'        sBitName           name of bit in interrupt node pointer register
'        iNode              node poninter
'-----------------------------------------------------------------------------
'Returns:
'       string for the cbo
'*****************************************************************************
Sub SetIsrNode(r As projectdata, vIndex As Variant, sBitName, iNode As Integer)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    r.v(sRegPre & "INP_" & sBitName) = iNode

End Sub

'*****************************************************************************
'Description:
'        This function checks if all interrupts are disabled
'-----------------------------------------------------------------------------
'Parameters:
'        r
'        vIndex             module index
'-----------------------------------------------------------------------------
'Returns:
'       true if all isr are disabled, else false
'*****************************************************************************
Function AllIsrDisabled(r As projectdata, vIndex As Variant) As Boolean
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
    
    AllIsrDisabled = False

    If (r.v(sRegPre & "2IC_IE") = 0 And _
        r.v(sRegPre & "3IC_IE") = 0 And _
        r.v(sRegPre & "1IC_IE") = 0 And _
        r.v(sRegPre & "0IC_IE") = 0) Then

        AllIsrDisabled = True

    End If

End Function

'*****************************************************************************
'Description:
'        This function checks if all interrupts are disabled and sets the
'        node isr to the enabled interrupt.
'-----------------------------------------------------------------------------
'Parameters:
'        r
'        vIndex             module index
'        sRegName           name of the disabled ISR
'-----------------------------------------------------------------------------
'Returns:
'       true if all isr are disabled, else false
'*****************************************************************************
Sub DeselectNodeIsr(r As projectdata, vIndex As Variant, sRegName As String)
    On Error Resume Next
      
    Dim sVarPre As String
    Dim sRegPre As String
    Dim saBit(7) As String
    Dim i As Integer
    Dim iHelp As Integer

    saBit(0) = "INPCC60"
    saBit(1) = "INPCC61"
    saBit(2) = "INPCC62"
    saBit(3) = "INPCHE"
    saBit(4) = "INPERR"
    saBit(5) = "INPT12"
    saBit(6) = "INPT13"

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
   
    If (r.v(sRegPre & "0IC_IE") = 1) Then
        iHelp = 0
    ElseIf (r.v(sRegPre & "1IC_IE") = 1) Then
        iHelp = 1
    ElseIf (r.v(sRegPre & "2IC_IE") = 1) Then
        iHelp = 2
    ElseIf (r.v(sRegPre & "3IC_IE") = 1) Then
        iHelp = 3
    Else
        For i = 0 To 6
            r.v(sRegPre & "INP_" & saBit(i)) = 0
        Next i
        Exit Sub
    End If

    
    If (sRegName = "0IC") Then
        For i = 0 To 6
            If (r.v(sRegPre & "INP_" & saBit(i)) = 0) Then
                r.v(sRegPre & "INP_" & saBit(i)) = iHelp
            End If
        Next i

    ElseIf (sRegName = "1IC") Then
        For i = 0 To 6
            If (r.v(sRegPre & "INP_" & saBit(i)) = 1) Then
                r.v(sRegPre & "INP_" & saBit(i)) = iHelp
            End If
        Next i

    ElseIf (sRegName = "2IC") Then
        For i = 0 To 6
            If (r.v(sRegPre & "INP_" & saBit(i)) = 2) Then
                r.v(sRegPre & "INP_" & saBit(i)) = iHelp
            End If
        Next i

    ElseIf (sRegName = "3IC") Then
        For i = 0 To 6
            If (r.v(sRegPre & "INP_" & saBit(i)) = 3) Then
                r.v(sRegPre & "INP_" & saBit(i)) = iHelp
            End If
        Next i
    End If

End Sub

'*****************************************************************************
'Description:
'        This function checks sets the node ISR to the first enabled interrupt.
'-----------------------------------------------------------------------------
'Parameters:
'        r
'        vIndex             module index
'        sRegName           name of the disabled ISR
'-----------------------------------------------------------------------------
'Returns:
'       true if all isr are disabled, else false
'*****************************************************************************
Sub SelectNodeIsr(r As projectdata, vIndex As Variant, sRegName As String)
    Dim sVarPre As String
    Dim sRegPre As String
    Dim saBit(7) As String
    Dim i As Integer
    Dim iHelp As Integer

    saBit(0) = "INPCC60"
    saBit(1) = "INPCC61"
    saBit(2) = "INPCC62"
    saBit(3) = "INPCHE"
    saBit(4) = "INPERR"
    saBit(5) = "INPT12"
    saBit(6) = "INPT13"

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
    
    If (r.v(sRegPre & "2IC_IE") = 0 And _
        r.v(sRegPre & "3IC_IE") = 0 And _
        r.v(sRegPre & "1IC_IE") = 0 And _
        r.v(sRegPre & "0IC_IE") = 0) Then

        If (sRegName = "0IC") Then
            For i = 0 To 6
                r.v(sRegPre & "INP_" & saBit(i)) = 0
            Next i

        ElseIf (sRegName = "1IC") Then
            For i = 0 To 6
                r.v(sRegPre & "INP_" & saBit(i)) = 1
            Next i

        ElseIf (sRegName = "2IC") Then
            For i = 0 To 6
                r.v(sRegPre & "INP_" & saBit(i)) = 2
            Next i

        ElseIf (sRegName = "3IC") Then
            For i = 0 To 6
                r.v(sRegPre & "INP_" & saBit(i)) = 3
            Next i

        End If

    End If

End Sub


'*****************************************************************************
'Description:
'        This function sets the CC6 module to the default.
'-----------------------------------------------------------------------------
'Parameters:
'        r
'        vIndex             module index
'        sRegName           name of the disabled ISR
'-----------------------------------------------------------------------------
'Returns:
'       true if all isr are disabled, else false
'*****************************************************************************
Sub DisableCC6Module(r As projectdata, vIndex As Variant)
    On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String
    Dim i As Integer
    Dim iChannel As Integer
    
    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"

    r.v(sVarPre & "_USE_Init") = 0

    Call DisableSRN(r, sVarPre, sRegPre & "2IC", "NodeI0")
    Call DisableSRN(r, sVarPre, sRegPre & "3IC", "NodeI1")
    Call DisableSRN(r, sVarPre, sRegPre & "1IC", "NodeI2")
    Call DisableSRN(r, sVarPre, sRegPre & "0IC", "NodeI3")

    r.sfr(sRegPre & "TRPCTR") = 0
    
    If (vIndex = 60) Then
        Call ReleaseAlternateInputPin(r, sVarPre & "_#CTRAPA(P10.6)")
        Call ReleaseAlternateInputPin(r, sVarPre & "_#CTRAPB(P8.6)")
    ElseIf (vIndex = 61) Then
        Call ReleaseAlternateInputPin(r, sVarPre & "_#CTRAPA(P0.6)")
        Call ReleaseAlternateInputPin(r, sVarPre & "_#CTRAPB(P0.7)")
    End If
    
    r.sfr(sRegPre & "CMPSTAT") = 0
    r.v(sRegPre & "PSLR_PSL63") = 0

    r.v(sRegPre & "MODCTR_ECT13O") = 0

    r.v(sRegPre & "T12DTC_DTE0") = 0
    r.v(sRegPre & "T12DTC_DTE1") = 0
    r.v(sRegPre & "T12DTC_DTE2") = 0

    r.sfr(sRegPre & "IEN") = 0
    
    r.v(sRegPre & "PSL_CC60") = 0
    r.v(sRegPre & "PSL_CC61") = 0
    r.v(sRegPre & "PSL_CC62") = 0
    r.v(sRegPre & "PSL_COUT60") = 0
    r.v(sRegPre & "PSL_COUT61") = 0
    r.v(sRegPre & "PSL_COUT62") = 0
    Call LoadPSLValue(r, vIndex)

    r.v(sRegPre & "TRPEN_CC60") = 0
    r.v(sRegPre & "TRPEN_CC61") = 0
    r.v(sRegPre & "TRPEN_CC62") = 0
    r.v(sRegPre & "TRPEN_COUT60") = 0
    r.v(sRegPre & "TRPEN_COUT61") = 0
    r.v(sRegPre & "TRPEN_COUT62") = 0
    Call LoadTRPENValue(r, vIndex)

    r.v(sRegPre & "MCMPS_CC60") = 0
    r.v(sRegPre & "MCMPS_CC61") = 0
    r.v(sRegPre & "MCMPS_CC62") = 0
    r.v(sRegPre & "MCMPS_COUT60") = 0
    r.v(sRegPre & "MCMPS_COUT61") = 0
    r.v(sRegPre & "MCMPS_COUT62") = 0
    Call LoadMCMPSValue(r, vIndex)

    r.v(sRegPre & "T12MODEN_CC60") = 0
    r.v(sRegPre & "T12MODEN_CC61") = 0
    r.v(sRegPre & "T12MODEN_CC62") = 0
    r.v(sRegPre & "T12MODEN_COUT60") = 0
    r.v(sRegPre & "T12MODEN_COUT61") = 0
    r.v(sRegPre & "T12MODEN_COUT62") = 0
    Call LoadT12MODENValue(r, vIndex)

    r.v(sRegPre & "T13MODEN_CC60") = 0
    r.v(sRegPre & "T13MODEN_CC61") = 0
    r.v(sRegPre & "T13MODEN_CC62") = 0
    r.v(sRegPre & "T13MODEN_COUT60") = 0
    r.v(sRegPre & "T13MODEN_COUT61") = 0
    r.v(sRegPre & "T13MODEN_COUT62") = 0
    Call LoadT13MODENValue(r, vIndex)

    Call SelectModeForCC6Channelx(r, vIndex, 0, 0)
    Call SelectModeForCC6Channelx(r, vIndex, 1, 0)
    Call SelectModeForCC6Channelx(r, vIndex, 2, 0)
    Call SelectModeForCC6Channelx(r, vIndex, 3, 0)

    r.v(sRegPre & "MODCTR_MCMEN") = 0
    r.v(sRegPre & "MCMCTR_SWSEL") = 0
    r.v(sRegPre & "MCMCTR_SWSYN") = 0
    r.v(sRegPre & "IEN_ENIDLE") = 0
    r.v(sRegPre & "IEN_ENCHE") = 0
    r.v(sRegPre & "IEN_ENWHE") = 0

    r.sfr(sRegPre & "TCTR2") = 0
    r.v(sRegPre & "TCTR2_T13TED") = 1

    r.v(sRegPre & "TCTR4_T12RS") = 0
    r.v(sRegPre & "TCTR4_T13RS") = 0
    r.sfr(sRegPre & "TCTR0") = 0
    r.sfr(sRegPre & "T12PR") = 1
    r.sfr(sRegPre & "T13PR") = 1
    r.sfr(sRegPre & "T12DTC") = 1
    
    For iChannel = 0 To 3
        r.sfr(sRegPre & "CC6" & iChannel & "SR") = 0
        r.v(sVarPre & "_REQ_DUTY_CYCLE_" & iChannel) = 100
        Call UpdateDutyCycle(r, vIndex, iChannel)
    Next iChannel
        
    If (vIndex = 60) Then
        For i = 0 To 2
            If (GetPinFunction(r, sVarPre & "_CC6" & i & "INA(P10." & i & ")") = 1) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CC6" & i & "INA(P10." & i & ")")
            ElseIf (GetPinFunction(r, sVarPre & "_CC6" & i & "INA(P8." & i & ")") = 1) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CC6" & i & "INB(P8." & i & ")")

            ElseIf (GetPinFunction(r, sVarPre & "_CC6" & i & "(P10." & i & ")") = 2) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_CC6" & i & "(P10." & i & ")")
            ElseIf (GetPinFunction(r, sVarPre & "_CC6" & i & "(P8." & i & ")") = 2) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_CC6" & i & "(P8." & i & ")")
            End If
            
            Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P10." & i + 3 & ")")
            Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P8." & i + 3 & ")")

            Call ReleaseAlternateInputPin(r, sVarPre & "_CCPOS" & i & "A(P10." & i + 7 & ")")
            Call ReleaseAlternateInputPin(r, sVarPre & "_CCPOS" & i & "B(P9." & 7 - i & ")")
        Next i

        i = 3
        Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P10.7)")
        Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P10.10)")
        Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P8.6)")
    ElseIf (vIndex = 61) Then
        For i = 0 To 2
            If (GetPinFunction(r, sVarPre & "_CC6" & i & "INA(P0." & i & ")") = 1) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CC6" & i & "INA(P0." & i & ")")
            End If
            If (GetPinFunction(r, sVarPre & "_CC6" & i & "(P0." & i & ")") = 2) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_CC6" & i & "(P0." & i & ")")
            End If
            
            Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P0." & i + 3 & ")")
        Next i

        Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "(P0.6)")
    End If
    
    r.v("CCU60_USE_BLDCConfig") = 0
    r.v("CCU60_USE_Normal") = 1
    
    r.v(sVarPre & "_CC60_LSTINDX0") = 0
    r.v(sVarPre & "_CC60_LSTINDX1") = 0
    r.v(sVarPre & "_CC60_LSTINDX2") = 0
    r.v(sVarPre & "_CC61_LSTINDX0") = 0
    r.v(sVarPre & "_CC61_LSTINDX1") = 0
    r.v(sVarPre & "_CC61_LSTINDX2") = 0
    r.v(sVarPre & "_CC62_LSTINDX0") = 0
    r.v(sVarPre & "_CC62_LSTINDX1") = 0
    r.v(sVarPre & "_CC62_LSTINDX2") = 0
    
    r.v(sVarPre & "_COUT60_LSTINDX1") = 0
    r.v(sVarPre & "_COUT60_LSTINDX2") = 0
    r.v(sVarPre & "_COUT61_LSTINDX1") = 0
    r.v(sVarPre & "_COUT61_LSTINDX2") = 0
    r.v(sVarPre & "_COUT62_LSTINDX1") = 0
    r.v(sVarPre & "_COUT62_LSTINDX2") = 0
    r.v(sVarPre & "_COUT63_LSTINDX1") = 0
    r.v(sVarPre & "_COUT63_LSTINDX2") = 0
    r.v(sVarPre & "_COUT63_LSTINDX3") = 0
    
    r.v(sVarPre & "_CC60IN_LSTINDX0") = 0
    r.v(sVarPre & "_CC60IN_LSTINDX1") = 0
    r.v(sVarPre & "_CC60IN_LSTINDX2") = 0
    r.v("CCU60_CC60IN_LSTINDX3") = 0
    r.v(sVarPre & "_CC61IN_LSTINDX0") = 0
    r.v(sVarPre & "_CC61IN_LSTINDX1") = 0
    r.v(sVarPre & "_CC61IN_LSTINDX2") = 0
    r.v(sVarPre & "_CC62IN_LSTINDX0") = 0
    r.v(sVarPre & "_CC62IN_LSTINDX1") = 0
    r.v(sVarPre & "_CC62IN_LSTINDX2") = 0
    
    r.v(sVarPre & "_CCPOS0_LSTINDX1") = 0
    r.v(sVarPre & "_CCPOS0_LSTINDX2") = 0
    r.v(sVarPre & "_CCPOS1_LSTINDX1") = 0
    r.v(sVarPre & "_CCPOS1_LSTINDX2") = 0
    r.v(sVarPre & "_CCPOS2_LSTINDX1") = 0
    r.v(sVarPre & "_CCPOS2_LSTINDX2") = 0
    r.v(sVarPre & "_T12HR_LSTINDX0") = 0
    r.v(sVarPre & "_T12HR_LSTINDX1") = 0
    r.v(sVarPre & "_T12HR_LSTINDX2") = 0
    r.v(sVarPre & "_T12HR_LSTINDX3") = 0
    r.v(sVarPre & "_T13HR_LSTINDX0") = 0
    r.v(sVarPre & "_T13HR_LSTINDX1") = 0
    r.v(sVarPre & "_T13HR_LSTINDX2") = 0
    r.v(sVarPre & "_T13HR_LSTINDX3") = 0
    
    r.v(sVarPre & "_CTRAP_LSTINDX0") = 0
    r.v(sVarPre & "_CTRAP_LSTINDX1") = 0
    r.v(sVarPre & "_CTRAP_LSTINDX2") = 0
    r.v(sVarPre & "_CTRAP_LSTINDX3") = 0
    
 'FOR CCU60
 If (vIndex = 60) Then
    r.v("MuxFor_CCU60_CC60(P10.0)") = 0
    r.v("MuxFor_CCU60_CC61(P10.1)") = 0
    r.v("MuxFor_CCU60_CC62(P10.2)") = 0
    r.v("MuxFor_CCU60_COUT60(P10.3)") = 0
    r.v("MuxFor_CCU60_COUT61(P10.4)") = 0
    r.v("MuxFor_CCU60_COUT62(P10.5)") = 0
    r.v("MuxFor_CCU60_CC60(P8.0)") = 0
    r.v("MuxFor_CCU60_CC61(P8.1)") = 0
    r.v("MuxFor_CCU60_CC62(P8.2)") = 0
    r.v("MuxFor_CCU60_COUT60(P8.3)") = 0
    r.v("MuxFor_CCU60_COUT61(P8.4)") = 0
    r.v("MuxFor_CCU60_COUT62(P8.5)") = 0
    r.v("MuxFor_CCU60_COUT63(P8.6)") = 0
    r.v("MuxFor_CCU60_COUT63(P10.7)") = 0
    r.v("MuxFor_CCU60_COUT63(P10.10)") = 0
    
    r.v("MuxFor_CCU60_CC60INA(P10.0)") = 0
    r.v("MuxFor_CCU60_CC61INA(P10.1)") = 0
    r.v("MuxFor_CCU60_CC62INA(P10.2)") = 0
    r.v("MuxFor_CCU60_CC60INB(P8.0)") = 0
    r.v("MuxFor_CCU60_CC61INB(P8.1)") = 0
    r.v("MuxFor_CCU60_CC62INB(P8.2)") = 0
    
    r.v("MuxFor_CCU60_#CTRAPA(P10.6)") = 0
    r.v("MuxFor_CCU60_#CTRAPB(P8.6)") = 0
    r.v("MuxFor_CCU60_T12HRB(P5.5)") = 0
    r.v("MuxFor_CCU60_T12HRC(P5.8)") = 0
    r.v("MuxFor_CCU60_T13HRC(P5.8)") = 0
    r.v("MuxFor_CCU60_CCPOS0A(P10.7)") = 0
    r.v("MuxFor_CCU60_CCPOS1A(P10.8)") = 0
    r.v("MuxFor_CCU60_CCPOS2A(P10.9)") = 0
    r.v("MuxFor_CCU60_CCPOS0B(P9.7)") = 0
    r.v("MuxFor_CCU60_CCPOS1B(P9.6)") = 0
    r.v("MuxFor_CCU60_CCPOS2B(P9.5)") = 0
    
    If (r.v("MAIN_CPU_Type") = "XC2287-96F66" Or r.v("MAIN_CPU_Type") = "XC2287-96F80" Or _
         r.v("MAIN_CPU_Type") = "XE167F-96F66" Or r.v("MAIN_CPU_Type") = "XE167F-96F80" Or _
         r.v("MAIN_CPU_Type") = "XE167G-96F66" Or r.v("MAIN_CPU_Type") = "XE167G-96F80" Or _
         r.v("MAIN_CPU_Type") = "XE167H-96F66" Or r.v("MAIN_CPU_Type") = "XE167H-96F80" Or _
         r.v("MAIN_CPU_Type") = "XE167K-96F66" Or r.v("MAIN_CPU_Type") = "XE167K-96F80") Then
      r.sfr("P8_IOCR00") = 0
      r.sfr("P8_IOCR01") = 0
      r.sfr("P8_IOCR02") = 0
      r.sfr("P8_IOCR03") = 0
      r.sfr("P8_IOCR04") = 0
      r.sfr("P8_IOCR05") = 0
      r.sfr("P8_IOCR06") = 0
    End If
      r.sfr("P10_IOCR00") = 0
      r.sfr("P10_IOCR01") = 0
      r.sfr("P10_IOCR02") = 0
      r.sfr("P10_IOCR03") = 0
      r.sfr("P10_IOCR04") = 0
      r.sfr("P10_IOCR05") = 0
      r.sfr("P10_IOCR07") = 0
      r.sfr("P10_IOCR10") = 0
    
 'FOR CCU61
 ElseIf (vIndex = 61) Then
    r.v("MuxFor_CCU61_CC60(P0.0)") = 0
    r.v("MuxFor_CCU61_CC61(P0.1)") = 0
    r.v("MuxFor_CCU61_CC62(P0.2)") = 0
    r.v("MuxFor_CCU61_COUT60(P0.3)") = 0
    r.v("MuxFor_CCU61_COUT61(P0.4)") = 0
    r.v("MuxFor_CCU61_COUT62(P0.5)") = 0
    r.v("MuxFor_CCU61_COUT63(P0.6)") = 0
    r.v("MuxFor_CCU61_CC60INA(P0.0)") = 0
    r.v("MuxFor_CCU61_CC61INA(P0.1)") = 0
    r.v("MuxFor_CCU61_CC62INA(P0.2)") = 0
    r.v("MuxFor_CCU61_#CTRAPA(P0.6)") = 0
    r.v("MuxFor_CCU61_#CTRAPB(P0.7)") = 0
    r.v("MuxFor_CCU61_T12HRB(P1.2)") = 0
    r.v("MuxFor_CCU61_T12HRC(P5.8)") = 0
    r.v("MuxFor_CCU61_T13HRC(P5.8)") = 0
     
     r.sfr("P0_IOCR00") = 0
     r.sfr("P0_IOCR01") = 0
     r.sfr("P0_IOCR02") = 0
     r.sfr("P0_IOCR03") = 0
     r.sfr("P0_IOCR04") = 0
     r.sfr("P0_IOCR05") = 0
     r.sfr("P0_IOCR06") = 0


'FOR CCU62
ElseIf (vIndex = 62) Then
    r.v("MuxFor_CCU62_CC60(P1.7)") = 0
    r.v("MuxFor_CCU62_CC61(P1.6)") = 0
    r.v("MuxFor_CCU62_CC62(P1.2)") = 0
    r.v("MuxFor_CCU62_COUT60(P1.5)") = 0
    r.v("MuxFor_CCU62_COUT61(P1.4)") = 0
    r.v("MuxFor_CCU62_COUT62(P1.1)") = 0
    r.v("MuxFor_CCU62_COUT63(P1.3)") = 0
    r.v("MuxFor_CCU62_CC60INA(P1.7)") = 0
    r.v("MuxFor_CCU62_CC61INA(P1.6)") = 0
    r.v("MuxFor_CCU62_CC62INA(P1.2)") = 0
    r.v("MuxFor_CCU62_#CTRAPA(P7.1)") = 0
    r.v("MuxFor_CCU62_#CTRAPB(P1.0)") = 0
    r.v("MuxFor_CCU62_T12HRB(P1.3)") = 0
    r.v("MuxFor_CCU62_T12HRC(P5.8)") = 0
    r.v("MuxFor_CCU62_T13HRC(P5.8)") = 0
    r.v("MuxFor_CCU62_CCPOS0A(P7.2)") = 0
    r.v("MuxFor_CCU62_CCPOS1A(P7.3)") = 0
    r.v("MuxFor_CCU62_CCPOS2A(P7.4)") = 0
    
    r.sfr("P1_IOCR07") = 0
    r.sfr("P1_IOCR01") = 0
    r.sfr("P1_IOCR02") = 0
    r.sfr("P1_IOCR03") = 0
    r.sfr("P1_IOCR04") = 0
    r.sfr("P1_IOCR05") = 0
    r.sfr("P1_IOCR06") = 0
    
'FOR CCU63
ElseIf (vIndex = 63) Then
    r.v("MuxFor_CCU63_CC60(P9.0)") = 0
    r.v("MuxFor_CCU63_CC61(P9.1)") = 0
    r.v("MuxFor_CCU63_CC62(P9.2)") = 0
    r.v("MuxFor_CCU63_COUT60(P9.3)") = 0
    r.v("MuxFor_CCU63_COUT61(P9.4)") = 0
    r.v("MuxFor_CCU63_COUT62(P9.5)") = 0
    r.v("MuxFor_CCU63_COUT62(P9.6)") = 0
    r.v("MuxFor_CCU63_COUT63(P9.6)") = 0
    r.v("MuxFor_CCU63_#CTRAPA(P9.6)") = 0
    r.v("MuxFor_CCU63_#CTRAPB(P9.7)") = 0
    r.v("MuxFor_CCU63_CC60INA(P9.0)") = 0
    r.v("MuxFor_CCU63_CC61INA(P9.1)") = 0
    r.v("MuxFor_CCU63_CC62INA(P9.2)") = 0
    r.v("MuxFor_CCU63_CC60(P2.0)") = 0
    r.v("MuxFor_CCU63_CC61(P2.1)") = 0
    r.v("MuxFor_CCU63_CC62(P2.2)") = 0
    r.v("MuxFor_CCU63_CC60INB(P2.0)") = 0
    r.v("MuxFor_CCU63_CC61INB(P2.1)") = 0
    r.v("MuxFor_CCU63_CC62INB(P2.2)") = 0
    r.v("MuxFor_CCU63_COUT63(P2.3)") = 0
    r.v("MuxFor_CCU63_CCPOS0A(P11.0)") = 0
    r.v("MuxFor_CCU63_CCPOS1A(P11.1)") = 0
    r.v("MuxFor_CCU63_CCPOS2A(P11.2)") = 0
    r.v("MuxFor_CCU63_T12HRB(P5.4)") = 0
    r.v("MuxFor_CCU63_T12HRC(P5.8)") = 0
    r.v("MuxFor_CCU63_T13HRC(P5.8)") = 0
    
    If (r.v("MAIN_CPU_Type") = "XC2287-96F66" Or r.v("MAIN_CPU_Type") = "XC2287-96F80" Or _
       r.v("MAIN_CPU_Type") = "XE167F-96F66" Or r.v("MAIN_CPU_Type") = "XE167F-96F80" Or _
       r.v("MAIN_CPU_Type") = "XE167G-96F66" Or r.v("MAIN_CPU_Type") = "XE167G-96F80" Or _
       r.v("MAIN_CPU_Type") = "XE167H-96F66" Or r.v("MAIN_CPU_Type") = "XE167H-96F80" Or _
       r.v("MAIN_CPU_Type") = "XE167K-96F66" Or r.v("MAIN_CPU_Type") = "XE167K-96F80") Then
      
        r.sfr("P9_IOCR00") = 0
        r.sfr("P9_IOCR01") = 0
        r.sfr("P9_IOCR02") = 0
        r.sfr("P9_IOCR03") = 0
        r.sfr("P9_IOCR04") = 0
        r.sfr("P9_IOCR05") = 0
        r.sfr("P9_IOCR06") = 0
    End If
    
     r.sfr("P2_IOCR00") = 0
     r.sfr("P2_IOCR01") = 0
     r.sfr("P2_IOCR02") = 0
     r.sfr("P2_IOCR03") = 0

End If

End Sub

'*****************************************************************************
'Description:
'        This function returns the Data Item for selecting a pin in CC6x module.
'-----------------------------------------------------------------------------
'Parameters:
'        cboname            Combo name
'        index              Data Item serial no from 0..1,2,3
'        vIndex             Module name 60 or 61 or 62 or 63
'-----------------------------------------------------------------------------
'Returns:
'       true if all isr are disabled, else false
'*****************************************************************************

Public Function GetTextcbo(cboname As String, index As Integer, vIndex As Variant) As String
    On Error Resume Next
    
    If (vIndex = 60) Then
        If (cboname = "CC60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC60/CC60IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC60 as Output(P10.0)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC60INA as Input(P10.0)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CC60 as Output(P8.0)"
            ElseIf (index = 4) Then
                GetTextcbo = "Use Pin CC60INB as Input(P8.0)"
            ElseIf (index = 5) Then
                GetTextcbo = "Use Pin CC60IND as Input(RTC_Interrupt)"
            End If
        End If
        
        If (cboname = "CC61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC61/CC61IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC61 as Output(P10.1)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC61INA as Input(P10.1)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CC61 as Output(P8.1)"
            ElseIf (index = 4) Then
                GetTextcbo = "Use Pin CC61INB as Input(P8.1)"
            End If
        End If
        
        If (cboname = "CC62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC62/CC62IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC62 as Output(P10.2)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC62INA as Input(P10.2)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CC62 as Output(P8.2)"
            ElseIf (index = 4) Then
                GetTextcbo = "Use Pin CC62INB as Input(P8.2)"
            End If
        End If
        
        If (cboname = "COUT60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT60 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT60 as Output(P10.3)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin COUT60 as Output(P8.3)"
            End If
        End If
        
        If (cboname = "COUT61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT61 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT61 as Output(P10.4)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin COUT61 as Output(P8.4)"
            End If
        End If
        
        If (cboname = "COUT62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT62 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT62 as Output(P10.5)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin COUT62 as Output(P8.5)"
            End If
        End If
        
        If (cboname = "COUT63cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT63 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT63 as Output(P10.7)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin COUT63 as Output(P10.10)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin COUT63 as Output(P8.6)"
            End If
        End If
        
        If (cboname = "CCPOS0cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS0 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS0A as Input(P10.7)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CCPOS0B as Input(P9.7)"
            End If
        End If
        
        If (cboname = "CCPOS1cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS1 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS1A as Input(P10.8)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CCPOS1B as Input(P9.6)"
            End If
        End If
        
        If (cboname = "CCPOS2cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS2 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS2A as Input(P10.9)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CCPOS2B as Input(P9.5)"
            End If
        End If
        
        If (cboname = "T12HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use T12HRA as Input(CCU63_MCM_ST)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin T12HRB as Input(P5.5)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T12HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T12HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "T13HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use T13HRA as Input(EXTCLK(SCU))"
            ElseIf (index = 1) Then
                GetTextcbo = "Use T13HRB as Input(CCU60_T12_ZM)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T13HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T13HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "CTRAPcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use CTRAPD as Input(1)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CTRAPA as Input(P10.6)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CTRAPB as Input(P8.6)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CTRAPC as Input(ESR2)"
            End If
            
        End If
    End If
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' FOR CCU61 MODULE
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    If (vIndex = 61) Then
        
        If (cboname = "CC60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC60/CC60IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC60 as Output(P0.0)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC60INA as Input(P0.0)"
            End If
        End If
        
        If (cboname = "CC61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC61/CC61IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC61 as Output(P0.1)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC61INA as Input(P0.1)"
            End If
        End If
        
        If (cboname = "CC62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC62/CC62IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC62 as Output(P0.2)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC62INA as Input(P0.2)"
            End If
        End If
        
        If (cboname = "COUT60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT60 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT60 as Output(P0.3)"
            End If
        End If
        
        If (cboname = "COUT61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT61 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT61 as Output(P0.4)"
            End If
        End If
        
        If (cboname = "COUT62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT62 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT62 as Output(P0.5)"
            End If
        End If
        
        If (cboname = "COUT63cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT63 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT63 as Output(P0.6)"
            End If
        End If
       
        If (cboname = "T12HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use T12HRA as Input(CCU60_MCM_ST)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin T12HRB as Input(P1.2)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T12HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T12HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "T13HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin T13HR is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use T13HRB as Input(CCU61_T12_ZM)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T13HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T13HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "CTRAPcbo") Then
            
            If (index = 0) Then
                GetTextcbo = "Use CTRAPD as Input(1)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CTRAPA as Input(P0.6)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CTRAPB as Input(P0.7)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CTRAPC as Input(ESR2)"
            End If
            
        End If
    End If
    
    
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' Pins for the CCU62 Module
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        If (vIndex = 62) Then
        
        If (cboname = "CC60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC60/CC60IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC60 as Output(P1.7)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC60INA as Input(P1.7)"
            End If
        End If
        
        If (cboname = "CC61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC61/CC61IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC61 as Output(P1.6)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC61INA as Input(P1.6)"
            End If
        End If
        
        If (cboname = "CC62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC62/CC62IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC62 as Output(P1.2)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC62INA as Input(P1.2)"
            End If
        End If
        
        If (cboname = "COUT60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT60 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT60 as Output(P1.5)"
            End If
        End If
        
        If (cboname = "COUT61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT61 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT61 as Output(P1.4)"
            End If
        End If
        
        If (cboname = "COUT62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT62 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT62 as Output(P1.1)"
            End If
        End If
        
        If (cboname = "COUT63cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT63 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT63 as Output(P1.3)"
            End If
        End If
       
       If (cboname = "CCPOS0cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS0 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS0A as Input(P7.2)"
            End If
        End If
        
        If (cboname = "CCPOS1cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS1 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS1A as Input(P7.3)"
            End If
        End If
        
        If (cboname = "CCPOS2cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS2 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS2A as Input(P7.4)"
            End If
        End If
        
        If (cboname = "T12HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use T12HRA as Input(CCU61_MCM_ST)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin T12HRB as Input(P1.3)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T12HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T12HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "T13HRcbo") Then
           If (index = 0) Then
                GetTextcbo = "Use T13HRA as Input(CAN_INT_O15)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use T13HRB as Input(CCU62_T12_ZM)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T13HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T13HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "CTRAPcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use CTRAPD as Input(1)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CTRAPA as Input(P7.1)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CTRAPB as Input(P1.0)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CTRAPC as Input(ESR2)"
            End If
        End If
    End If
    
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' Pins for the CCU63 Module
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        If (vIndex = 63) Then
       
        If (cboname = "CC60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC60/CC60IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC60 as Output(P9.0)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC60INA as Input(P9.0)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CC60 as Output(P2.0)"
            ElseIf (index = 4) Then
                GetTextcbo = "Use Pin CC60INB as Input(P2.0)"
            End If
        End If
        
        If (cboname = "CC61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC61/CC61IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC61 as Output(P9.1)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC61INA as Input(P9.1)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CC61 as Output(P2.1)"
            ElseIf (index = 4) Then
                GetTextcbo = "Use Pin CC61INB as Input(P2.1)"
            End If
        End If
        
        If (cboname = "CC62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CC62/CC62IN is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CC62 as Output(P9.2)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CC62INA as Input(P9.2)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CC62 as Output(P2.2)"
            ElseIf (index = 4) Then
                GetTextcbo = "Use Pin CC62INB as Input(P2.2)"
            End If
        End If
        
        If (cboname = "COUT60cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT60 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT60 as Output(P9.3)"
            End If
        End If
        
        If (cboname = "COUT61cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT61 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT61 as Output(P9.4)"
            End If
        End If
        
        If (cboname = "COUT62cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT62 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT62 as Output(P9.5)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin COUT62 as Output(P9.6)"
            End If
        End If
        
        If (cboname = "COUT63cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin COUT63 is Not Selected"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin COUT63 as Output(P9.6)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin COUT63 as Output(P2.3)"
            End If
        End If
        
        If (cboname = "CCPOS0cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS0 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS0A as Input(P11.0)"
            End If
        End If
        
        If (cboname = "CCPOS1cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS1 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS1A as Input(P11.1)"
            End If
        End If
        
        If (cboname = "CCPOS2cbo") Then
            If (index = 0) Then
                GetTextcbo = "Pin CCPOS2 is Not Selected (=0)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CCPOS2A as Input(P11.2)"
            End If
        End If
        
        If (cboname = "T12HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use T12HRA as Input(CCU62_MCM_ST)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin T12HRB as Input(P5.4)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T12HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T12HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "T13HRcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use T13HRA as Input(CAN_INT_O15)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use T13HRB as Input(CCU63_T12_ZM)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin T13HRC as Input(P5.8)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use T13HRD as Input(SYSCON1.GLCCST)"
            End If
        End If
        
        If (cboname = "CTRAPcbo") Then
            If (index = 0) Then
                GetTextcbo = "Use CTRAPD as Input(1)"
            ElseIf (index = 1) Then
                GetTextcbo = "Use Pin CTRAPA as Input(P9.6)"
            ElseIf (index = 2) Then
                GetTextcbo = "Use Pin CTRAPB as Input(P9.7)"
            ElseIf (index = 3) Then
                GetTextcbo = "Use Pin CTRAPC as Input(ESR2)"
            End If
        End If
    End If

    
End Function

