Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
Option Explicit
'*****************************************************************************
' Module:
'        USIC
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'USIC'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author                    Date            Description
'        ---------------------------------------------------------------------
'          Shylashree S                20-11-2007              XC22xx v0.01
'
'
'*****************************************************************************


'*****************************************************************************
'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
'        "ASC_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 RefreshIISFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

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

  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"

  RefreshIISFunctionDescriptions = False

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

  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_WriteData
  '------------------------------------------------------------------------------------------------
  sDescription = "This function writes data to the " & sVarPre & " Transmit buffer " & _
                 "(" & sRegPre & "TBUF00)."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IISWriteData", "void", sDescription, sReturnValue, 1)) Then Exit Function
  sDescription = "valid Transmit Data "
  If (Not func.AddParameter(sVarPre & "_NAME_IISWriteData" & "_Para1", "uwData", "uword", sDescription)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_ReadData
  '------------------------------------------------------------------------------------------------
  sDescription = "This function reads out the contents of the " & sVarPre & _
                 " receive buffer (" & sRegPre & "RBUF)."

  
  
  If (r.v(sVarPre & "_IIS_OMOD") = 1) Then
    sReturnValue = "Value of the register " & sRegPre & "RBUF"
    If (Not func.AddFunction(sVarPre & "_NAME_IISReadData", "uword", sDescription, sReturnValue, 1)) Then Exit Function
    
  ElseIf (r.v(sVarPre & "_IIS_OMOD") = 0) Then
    sReturnValue = "None"
    If (Not func.AddFunction(sVarPre & "_NAME_IISReadData", "void", sDescription, sReturnValue, 1)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_IISReadData" & "_Para1", "*buffer", "uword", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_IISReadData" & "_Para2", "count", "uword", sDescription)) Then Exit Function
 
  End If
  
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_SelectChannel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to select the channel(RIGHT or LEFT)" & _
                 "in which the data has to be sent."

  sReturnValue = "None"

  If (Not func.AddFunction(sVarPre & "_NAME_IISSelectChannel", "void", sDescription, sReturnValue, 0)) Then Exit Function
  If (Not func.AddParameter(sVarPre & "_NAME_IISSelectChannel" & "_Para1", "RIGHT_CHANNEL or LEFT_CHANNEL", "", sDescription)) Then Exit Function

'------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_0IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_0IC." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIS0IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_1IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_1IC." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIS1IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_2IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_2IC." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIS2IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_3IC
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & sVarPre & "_3IC (shared with CC2)." & vbCrLf & _
                        TOOLTIP_ISR_USERCODE

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IIS3IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISFillTxFIFO
  '------------------------------------------------------------------------------------------------
  sDescription = "This function is used to fill the Transmit FIFO with user given software" & _
                 " data buffer pointer. The INxx sfrs will be assigned with the data from " & _
                 "the software data buffer."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IISFillTxFIFO", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Pointer to user data buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_IISFillTxFIFO" & "_Para1", "*uwUDTxfifo", "uword", sDescription)) Then Exit Function
    sDescription = "Amount of data to transmit"
    If (Not func.AddParameter(sVarPre & "_NAME_IISFillTxFIFO" & "_Para2", "uwUDTxfifoSize", "uword", sDescription)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISGetRxFIFOData
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the data received in " & sVarPre & "_OUTRL sfr." & _
                 "The OUTRL sfr contains the oldest data received by the Receive FIFO."

  sReturnValue = "Value of the register " & sVarPre & "_OUTRL."
  If (Not func.AddFunction(sVarPre & "_NAME_IISGetRxFIFOData", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISIsRxFIFObusy
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is currently updated by FIFO handler."

  sReturnValue = "Status of the receive FIFO, busy or not."
  If (Not func.AddFunction(sVarPre & "_NAME_IISIsRxFIFObusy", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISIsTxFIFObusy
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is currently updated by FIFO handler."

  sReturnValue = "Status of the transmit FIFO, busy or not."
  If (Not func.AddFunction(sVarPre & "_NAME_IISIsTxFIFObusy", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISIsRxFIFOfull
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is full or not."

  sReturnValue = "Status of the receive FIFO, full or not."
  If (Not func.AddFunction(sVarPre & "_NAME_IISIsRxFIFOfull", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISIsTxFIFOfull
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is full or not."

  sReturnValue = "Status of the transmit FIFO, full or not."
  If (Not func.AddFunction(sVarPre & "_NAME_IISIsTxFIFOfull", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISIsRxFIFOempty
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is empty or not."

  sReturnValue = "Status of the receive FIFO, empty or not."
  If (Not func.AddFunction(sVarPre & "_NAME_IISIsRxFIFOempty", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISIsTxFIFOempty
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is empty or not."

  sReturnValue = "Status of the transmit FIFO, empty or not."
  If (Not func.AddFunction(sVarPre & "_NAME_IISIsTxFIFOempty", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISGetRxFIFOFillingLevel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status of the receive buffer filling level."

  sReturnValue = "The filling level of receive FIFO,i:e.Value of the bitfield " & sVarPre & "_TRBSRH_RBFLVL"
  If (Not func.AddFunction(sVarPre & "_NAME_IISGetRxFIFOFillingLevel", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISGetTxFIFOFillingLevel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status of the transmit buffer filling level."

  sReturnValue = "The filling level of transmit FIFO,i:e Value of the bitfield " & sVarPre & "_TRBSRH_TBFLVL"
  If (Not func.AddFunction(sVarPre & "_NAME_IISGetTxFIFOFillingLevel", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISFlushRxFIFO
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to clear the receive FIFO. But it should only be used" & _
                 "while the FIFO buffer is not taking part in data traffic."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IISFlushRxFIFO", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for IIS UxCy_NAME_IISFlushTxFIFO
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to clear the transmit FIFO. But it should only be used" & _
                 "while the FIFO buffer is not taking part in data traffic."
                 
  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_IISFlushTxFIFO", "", sDescription, sReturnValue, 0)) Then Exit Function
  

  If (Not func.Sort) Then Exit Function

  RefreshIISFunctionDescriptions = True
End Function


'*****************************************************************************
'Description:
'        This function adds DOUT pins and returns the listindex to the cboDOUT.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         DOUT combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to DOUT Pins combobox
'*****************************************************************************
Function AddDOUTPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next
  
  Dim i As Integer
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")
    
  Select Case (ModuleName)
    
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_1") Then cboCrtl.AddItem ("P2.3")      'U0C0_DOUT_O_1
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.1")     'U0C0_DOUT_O_3
    
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_2") Then cboCrtl.AddItem ("P2.10")     'U0C1_DOUT_O_2
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_5") Then cboCrtl.AddItem ("P10.0")      'U0C1_DOUT_O_5
   
    Case ("U1C0")
      
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_1") Then cboCrtl.AddItem ("P0.0")      'U1C0_DOUT_O_1
      
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_2") Then cboCrtl.AddItem ("P0.1")      'U1C0_DOUT_O_2
      
    Case ("U1C1")
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_1") Then cboCrtl.AddItem ("P0.6")      'U1C1_DOUT_O_1
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_2") Then cboCrtl.AddItem ("P0.7")      'U1C1_DOUT_O_2
    
    Case ("U2C0")
      If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_1") Then cboCrtl.AddItem ("P1.6")      'U2C0_DOUT_O_1
      If IsControllerTypeOK(r) = 1 Then
        If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_4") Then cboCrtl.AddItem ("P9.4")      'U2C0_DOUT_O_4
      End If
    
    Case ("U2C1")
      If IsControllerTypeOK(r) = 1 Then
            If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_2") Then cboCrtl.AddItem ("P3.7")      'U2C1_DOUT_O_2
            If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_1") Then cboCrtl.AddItem ("P3.6")      'U2C1_DOUT_O_1
      Else
            If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_3") Then cboCrtl.AddItem ("P1.1")         'U2C1_DOUT_O_3
      End If
    Case Else
  
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIS_cboDOUT")) Then
        AddDOUTPINSnGetIndex = i
    End If
  Next i
  
  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False
  
End Function

'*****************************************************************************
'Description:
'        This function adds WAOUT pins and returns the listindex to the cboWAOUT.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         WAOUT combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to WAOUT Pins combobox
'*****************************************************************************

Function AddWAOUTPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
    
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModuleName)
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_SELO0_O_1") Then cboCrtl.AddItem ("P2.6")        'U0C0_SELO0_O_1
      If IsAlternateOutputPinFree(r, "U0C0_SELO2_O_1") Then cboCrtl.AddItem ("P2.11")       'U0C0_SELO2_O_1
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_SELO0_O_1") Then cboCrtl.AddItem ("P2.7")        'U0C1_SELO0_O_1
      'If IsAlternateOutputPinFree(r, "U0C1_SELO0_O_2") Then cboCrtl.AddItem ("P10.8")       'U0C1_SELO0_O_2
        If IsAlternateOutputPinFree(r, "U0C1_SELO1_O_1") Then cboCrtl.AddItem ("P2.6")       'U0C1_SELO1_O_1
    Case ("U1C0")
      If IsAlternateOutputPinFree(r, "U1C0_SELO0_O_1") Then cboCrtl.AddItem ("P0.3")        'U1C0_SELO0_O_1
      If IsAlternateOutputPinFree(r, "U1C0_SELO0_O_2") Then cboCrtl.AddItem ("P10.6")       'U1C0_SELO0_O_2
    Case ("U1C1")
      If IsAlternateOutputPinFree(r, "U1C1_SELO0_O_1") Then cboCrtl.AddItem ("P0.4")        'U1C1_SELO0_O_1
      If IsAlternateOutputPinFree(r, "U1C1_SELO1_O_1") Then cboCrtl.AddItem ("P0.3")        'U1C1_SELO1_O_1
   Case ("U2C0")
      If IsAlternateOutputPinFree(r, "U2C0_SELO4_O_1") Then cboCrtl.AddItem ("P1.3")        'U2C0_SELO4_O_1
      If IsAlternateOutputPinFree(r, "U2C0_SELO5_O_1") Then cboCrtl.AddItem ("P1.4")        'U2C0_SELO5_O_1
    Case ("U2C1")
      If IsControllerTypeOK(r) = 1 Then
        If IsAlternateOutputPinFree(r, "U2C1_SELO1_O_1") Then cboCrtl.AddItem ("P3.3")        'U2C1_SELO1_O_1
        If IsAlternateOutputPinFree(r, "U2C1_SELO0_O_1") Then cboCrtl.AddItem ("P3.4")        'U2C1_SELO0_O_1
      End If
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIS_cboWAOUT")) Then
        AddWAOUTPINSnGetIndex = i
    End If
  Next i

  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function
'*****************************************************************************
'Description:
'        This function adds SCLKOUT pins and returns the listindex to the cboSCLKOUT.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         SCLKOUT combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to SCLKOUT Pins combobox
'*****************************************************************************
Function AddSCLKOUTPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
    
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModuleName)
    Case ("U0C0")
        If IsAlternateOutputPinFree(r, "U0C0_SCLKOUT_O_1") Then cboCrtl.AddItem ("P2.5")        'U0C0_SCLKOUT_O_1
        If IsAlternateOutputPinFree(r, "U0C0_SCLKOUT_O_2") Then cboCrtl.AddItem ("P10.2")       'U0C0_SCLKOUT_O_2
    Case ("U0C1")
        If IsAlternateOutputPinFree(r, "U0C1_SCLKOUT_O_1") Then cboCrtl.AddItem ("P2.8")        'U0C1_SCLKOUT_O_1
        If IsAlternateOutputPinFree(r, "U0C1_SCLKOUT_O_2") Then cboCrtl.AddItem ("P10.5")       'U0C1_SCLKOUT_O_2
    Case ("U1C0")
        If IsAlternateOutputPinFree(r, "U1C0_SCLKOUT_O_1") Then cboCrtl.AddItem ("P0.2")          'U1C0_SCLKOUT_O_1
        If IsAlternateOutputPinFree(r, "U1C0_SCLKOUT_O_2") Then cboCrtl.AddItem ("P10.11")        'U1C0_SCLKOUT_O_2
    Case ("U1C1")
        If IsAlternateOutputPinFree(r, "U1C1_SCLKOUT_O_1") Then cboCrtl.AddItem ("P0.5")          'U1C1_SCLKOUT_O_1
        If IsAlternateOutputPinFree(r, "U1C1_SCLKOUT_O_2") Then cboCrtl.AddItem ("P6.2")          'U1C1_SCLKOUT_O_2
    Case ("U2C0")
        If IsAlternateOutputPinFree(r, "U2C0_SCLKOUT_O_1") Then cboCrtl.AddItem ("P1.7")          'U2C0_SCLKOUT_O_1
        If IsControllerTypeOK(r) = 1 Then
        If IsAlternateOutputPinFree(r, "U2C0_SCLKOUT_O_2") Then cboCrtl.AddItem ("P3.2")          'U2C0_SCLKOUT_O_2
        End If
    Case ("U2C1")
       
        If IsAlternateOutputPinFree(r, "U2C1_SCLKOUT_O_2") Then cboCrtl.AddItem ("P1.2")          'U2C1_SCLKOUT_O_2
        
        
        If IsControllerTypeOK(r) = 1 Then
        If IsAlternateOutputPinFree(r, "U2C1_SCLKOUT_O_1") Then cboCrtl.AddItem ("P3.5")          'U2C1_SCLKOUT_O_1
        End If
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIS_cboSCLKOUT")) Then
        AddSCLKOUTPINSnGetIndex = i
    End If
  Next i

  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function


'*****************************************************************************
'Description:
'        This function adds DIN pins and returns the listindex to the cboDIN.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         DIN combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to DIN Pins combobox
'*****************************************************************************
Function AddDINPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")
 
  Select Case (ModuleName)
    Case ("U0C0")
      If IsAlternateInputPinFree(r, "U0C0_DX0F_I") Then cboCrtl.AddItem ("P2.4")        'P2.4
      If IsAlternateInputPinFree(r, "U0C0_DX0A_I") Then cboCrtl.AddItem ("P10.0")       'P10.0
    
    Case ("U0C1")
      If IsAlternateInputPinFree(r, "U0C1_DX0A_I") Then cboCrtl.AddItem ("P10.0")       'P10.0
      If IsAlternateInputPinFree(r, "U0C1_DX0B_I") Then cboCrtl.AddItem ("P10.7")       'P10.7
    
    Case ("U1C0")
      If IsAlternateInputPinFree(r, "U1C0_DX0A_I") Then cboCrtl.AddItem ("P0.0")        'P0.0
    
      If IsAlternateInputPinFree(r, "U1C0_DX0B_I") Then cboCrtl.AddItem ("P0.1")        'P0.1
   
   
    Case ("U1C1")
      If IsAlternateInputPinFree(r, "U1C1_DX0A_I") Then cboCrtl.AddItem ("P0.6")        'P0.6
      If IsAlternateInputPinFree(r, "U1C1_DX0B_I") Then cboCrtl.AddItem ("P0.7")        'P0.7
      'If IsAlternateInputPinFree(r, "U1C1_DX0E_I") Then cboCrtl.AddItem ("P6.0")        'P6.0
 
   Case ("U2C0")
      If IsAlternateInputPinFree(r, "U2C0_DX0C_I") Then cboCrtl.AddItem ("P1.5")        'P1.5
      If IsAlternateInputPinFree(r, "U2C0_DX0D_I") Then cboCrtl.AddItem ("P1.6")        'P1.6
      
   Case ("U2C1")
      If IsAlternateInputPinFree(r, "U2C1_DX0C_I") Then cboCrtl.AddItem ("P1.1")        'P1.1
      If IsAlternateInputPinFree(r, "U2C1_DX0D_I") Then cboCrtl.AddItem ("P1.2")        'P1.2
      
   Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIS_cboDIN")) Then
        AddDINPINSnGetIndex = i
    End If
  Next i
  
  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function


'*****************************************************************************
'Description:
'        This function adds SCLKINpins and returns the listindex to the cboSCLKOUT.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         SCLKOUT combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to SCLKIN Pins combobox
'*****************************************************************************

Function AddSCLKINPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
    
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModuleName)
    Case ("U0C0")
        If IsAlternateInputPinFree(r, "U0C0_DX1A_I") Then cboCrtl.AddItem ("P10.1")         'U0C0_DX1A_I
        If IsAlternateInputPinFree(r, "U0C0_DX1B_I") Then cboCrtl.AddItem ("P10.2")         'U0C0_DX1B_I
        
    Case ("U0C1")
        If IsAlternateInputPinFree(r, "U0C1_DX1A_I") Then cboCrtl.AddItem ("P10.10")         'U0C1_DX1A_I
        If IsAlternateInputPinFree(r, "U0C1_DX1B_I") Then cboCrtl.AddItem ("P10.5")          'U0C1_DX1B_I
        
    Case ("U1C0")
        If IsAlternateInputPinFree(r, "U1C0_DX1A_I") Then cboCrtl.AddItem ("P0.1")             'U1C0_DX1A_I
        If IsAlternateInputPinFree(r, "U1C0_DX1B_I") Then cboCrtl.AddItem ("P0.2")             'U1C0_DX1B_I
    Case ("U1C1")
        If IsAlternateInputPinFree(r, "U1C1_DX1A_I") Then cboCrtl.AddItem ("P0.5")                'U1C1_DX1A_I
        If IsAlternateInputPinFree(r, "U1C1_DX1C_I") Then cboCrtl.AddItem ("P6.2")               'U1C1_DX1C_I
      
    Case ("U2C0")
        If (IsControllerTypeOK(r) = 1) Then
            If IsAlternateInputPinFree(r, "U2C0_DX1B_I") Then cboCrtl.AddItem ("P3.2")              'U2C0_DX1B_I
        End If
        If IsAlternateInputPinFree(r, "U2C0_DX1C_I") Then cboCrtl.AddItem ("P1.7")                'U2C0_DX1C_I
        
    Case ("U2C1")
        If IsControllerTypeOK(r) = 1 Then
            If IsAlternateInputPinFree(r, "U2C1_DX1A_I") Then cboCrtl.AddItem ("P3.5")              'U2C1_DX1A_I
            If IsAlternateInputPinFree(r, "U2C1_DX1B_I") Then cboCrtl.AddItem ("P3.6")              'U2C1_DX1B_I
        Else
            If IsAlternateInputPinFree(r, "U2C1_DX1C_I") Then cboCrtl.AddItem ("P1.2")              'U2C1_DX1C_I
        End If
      
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIS_cboSCLKOUT")) Then
        AddSCLKINPINSnGetIndex = i
    End If
  Next i

  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function
'*****************************************************************************
'Description:
'        This function adds WAINpins and returns the listindex to the cboWAOUT.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         WAOUT combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to WAIN Pins combobox
'*****************************************************************************

Function AddWAINPINSnGetIndex(r As ProjectData, ModuleName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
    
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModuleName)
    
    Case ("U0C0")
        If IsAlternateInputPinFree(r, "U0C0_DX2A_I") Then cboCrtl.AddItem ("P10.3")         'U0C0_DX2A_I
        If IsAlternateInputPinFree(r, "U0C0_DX2B_I") Then cboCrtl.AddItem ("P10.4")         'U0C0_DX2B_I
    
    Case ("U0C1")
        If IsAlternateInputPinFree(r, "U0C1_DX2A_I") Then cboCrtl.AddItem ("P10.3")         'U0C1_DX2A_I
        If IsAlternateInputPinFree(r, "U0C1_DX2B_I") Then cboCrtl.AddItem ("P10.4")         'U0C1_DX2B_I
    
    Case ("U1C0")
        If IsAlternateInputPinFree(r, "U1C0_DX2A_I") Then cboCrtl.AddItem ("P0.3")          'U1C0_DX2A_I
        If IsAlternateInputPinFree(r, "U1C0_DX2D_I") Then cboCrtl.AddItem ("P10.6")         'U1C0_DX2D_I
    Case ("U1C1")
        If IsAlternateInputPinFree(r, "U1C1_DX2A_I") Then cboCrtl.AddItem ("P0.4")          'U1C1_DX2A_I
        If IsControllerTypeOK(r) = 1 Then
            If IsAlternateInputPinFree(r, "U1C1_DX2D_I ") Then cboCrtl.AddItem ("P6.3")     'U1C1_DX2D_I
        End If
    
    Case ("U2C0")
        If IsAlternateInputPinFree(r, "U2C0_DX2B_I") Then cboCrtl.AddItem ("P1.4")          'U2C0_DX2B_I
        If IsControllerTypeOK(r) = 1 Then
            If IsAlternateInputPinFree(r, "U2C0_DX2A_I") Then cboCrtl.AddItem ("P3.3")      'U2C0_DX2A_I
        End If
    
    Case ("U2C1")
        If IsControllerTypeOK(r) = 1 Then
            If IsAlternateInputPinFree(r, "U2C1_DX2A_I") Then cboCrtl.AddItem ("P3.4")      'U2C1_DX2A_I
        End If
    
    Case Else
  
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_IIS_cboWAOUT")) Then
        AddWAINPINSnGetIndex = i
    End If
  Next i

  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function

'*****************************************************************************
'Description:
'        This function set the selected SCLKOUT pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetSCLKOUTPins(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P10.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")                          ''U0C0_SCLKOUT_O_2
      ElseIf (PinNo = "P2.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")                          'U0C0_SCLKOUT_O_1
      End If
      
    Case ("U0C1")
      If (PinNo = "P2.8") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")                          '_SCLKOUT_O_1
      ElseIf (PinNo = "P10.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")                          '_SCLKOUT_O_2
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")                          'U1C0_SCLKOUT_O_1
      ElseIf (PinNo = "P10.11") Then                                                            'U1C0_SCLKOUT_O_2
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")                          ''U1C1_SCLKOUT_O_1
      ElseIf (PinNo = "P6.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")                          'U1C1_SCLKOUT_O_2
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")                          ''U2C0_SCLKOUT_O_1
      ElseIf (PinNo = "P3.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")                          ''U2C0_SCLKOUT_O_2
      End If
      
    Case ("U2C1")
      If (PinNo = "P1.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")                                  ' 'U2C1_SCLKOUT_O_2
      ElseIf (PinNo = "P3.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")                                   'U2C1_SCLKOUT_O_1
      End If
      
    Case Else
    
  End Select
  
  
End Sub

'*****************************************************************************
'Description:
'        This function set the selected WAOUT pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetWAOUTPins(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P2.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO0_O_1")
      ElseIf (PinNo = "P2.11") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO2_O_1")
      End If
      
    Case ("U0C1")
      If (PinNo = "P2.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO0_O_1")
      ElseIf (PinNo = "P2.6") Then
     
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO1_O_1")
      
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO0_O_1")
      ElseIf (PinNo = "P10.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO0_O_2")
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.4") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO0_O_1")
      ElseIf (PinNo = "P0.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO1_O_1")
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO4_O_1")
      ElseIf (PinNo = "P1.4") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO5_O_1")
      End If
      
    Case ("U2C1")
      If (PinNo = "P3.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO1_O_1")
      ElseIf (PinNo = "P3.4") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_SELO0_O_1")
      End If
      
    Case Else
    
  End Select
  
End Sub

'*****************************************************************************
'Description:
'        This function set the selected DOUT pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetDOUTPins(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P2.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")           'P2.3(U0C0_DOUT_O_1)
      ElseIf (PinNo = "P10.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")           'P10.1(U0C0_DOUT_O_3)
      End If
      
    Case ("U0C1")
        If (PinNo = "P10.0") Then
            Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_5")       'P10.0(U0C1_DOUT_O_5)
        ElseIf (PinNo = "P2.10") Then
            Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")       'P2.10(U0C1_DOUT_O_2)
        End If
      
    Case ("U1C0")
      If (PinNo = "P0.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")            '(P0.0)U1C0_DOUT_O_1
      ElseIf (PinNo = "P0.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")            '(P0.1)U1C0_DOUT_O_2
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")                     '(P0.6)U1C1_DOUT_O_1
      ElseIf (PinNo = "P0.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")                     '(P0.7)U1C1_DOUT_O_2
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")                 '(P1.6)U2C0_DOUT_O_1
      ElseIf (PinNo = "P9.4") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")                 '(P9.4)U2C0_DOUT_O_4
      End If
      
    Case ("U2C1")
      If (PinNo = "P3.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")                 '(P3.6)U2C1_DOUT_O_1
      ElseIf (PinNo = "P3.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")                 '(P3.7)U2C1_DOUT_O_2
      ElseIf (PinNo = "P1.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")                 '(P1.1)U2C1_DOUT_O_3
      End If
      
    Case Else
    
  End Select
  
  
End Sub


'*****************************************************************************
'Description:
'        This function set the selected DIN pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetDINPins(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  r.v(RegName & "DX0CR_INSW") = 1
  r.v(RegName & "DX0CR_SFSEL") = 1
  
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P2.4") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0F_I")            'P2.4
        r.v(RegName & "DX0CR_DSEL") = 5
      ElseIf (PinNo = "P10.0") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0A_I")           'P10.0
        r.v(RegName & "DX0CR_DSEL") = 0
      End If
      
    Case ("U0C1")
      If (PinNo = "P10.0") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0A_I")            'P10.0
        r.v(RegName & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P10.7") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0B_I")            'P10.7
        r.v(RegName & "DX0CR_DSEL") = 1
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.0") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0A_I")            'P0.0
        r.v(RegName & "DX0CR_DSEL") = 0
       ElseIf (PinNo = "P0.1") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0B_I")            'P0.1
        r.v(RegName & "DX0CR_DSEL") = 1
       End If
    
    Case ("U1C1")
      If (PinNo = "P0.6") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0A_I")            'P0.6
        r.v(RegName & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P0.7") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0B_I")            'P0.7
        r.v(RegName & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P6.0") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0E_I")              'P6.0
        r.v(RegName & "DX0CR_DSEL") = 4
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.5") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0C_I")          'P1.5
        r.v(RegName & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P1.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DX0D_I")         'P1.6
        r.v(RegName & "DX0CR_DSEL") = 3
      End If
      
    Case ("U2C1")
      If (PinNo = "P1.1") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX0C_I")            'P1.1
        r.v(RegName & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P1.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DX0D_I")           'P1.2
        r.v(RegName & "DX0CR_DSEL") = 3
      End If
      
    Case Else
    
  End Select
  
  

End Sub



'*****************************************************************************
'Description:
'        This function set the selected WAIN pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns
'*****************************************************************************
Sub SetWAINPins(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  r.v(RegName & "DX2CR_INSW") = 1
  r.v(RegName & "DX2CR_SFSEL") = 1
   
  
  Select Case (ModuleName)
  
    Case ("U0C0")
        If (PinNo = "P10.3") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2A_I")            'P10.3  U0C0_DX2A_I
            r.v(RegName & "DX2CR_DSEL") = 0
        ElseIf (PinNo = "P10.4") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2B_I")            'U0C0_DX2B_I
            r.v(RegName & "DX2CR_DSEL") = 1
        End If
      
    Case ("U0C1")
        If (PinNo = "P10.3") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2A_I")            'U0C1_DX2A_I
            r.v(RegName & "DX2CR_DSEL") = 0
        ElseIf (PinNo = "P10.4") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2B_I")            'U0C1_DX2B_I
            r.v(RegName & "DX2CR_DSEL") = 1
        End If
      
    Case ("U1C0")
        If (PinNo = "P0.3") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2A_I")            'U1C0_DX2A_I
            r.v(RegName & "DX2CR_DSEL") = 0
        ElseIf (PinNo = "P10.6") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2D_I")            'U1C0_DX2D_I
            r.v(RegName & "DX2CR_DSEL") = 3
        End If
    
    Case ("U1C1")
        If (PinNo = "P0.4") Then
       
            Call RequestAlternateInputPin(r, ModuleName & "_DX2A_I")           'U1C1_DX2A_I
            
            
            r.v(RegName & "DX2CR_DSEL") = 0
        ElseIf (PinNo = "P6.3") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2D_I")            'U1C1_DX2D_I
            r.v(RegName & "DX2CR_DSEL") = 3
        End If
      
    Case ("U2C0")
        If (PinNo = "P1.4") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2B_I")            'U2C0_DX2B_I
            r.v(RegName & "DX2CR_DSEL") = 1
        ElseIf (PinNo = "P3.3") Then
            Call RequestAlternateOutputPin(r, ModuleName & "_DX2A_I")           'U2C0_DX2A_I
            r.v(RegName & "DX2CR_DSEL") = 0
        End If
      
    Case ("U2C1")
        If (PinNo = "P3.4") Then
            Call RequestAlternateInputPin(r, ModuleName & "_DX2A_I")            'U2C1_DX2A_I
            r.v(RegName & "DX2CR_DSEL") = 0
        End If
      
    Case Else
    
  End Select
  
  

End Sub
'*****************************************************************************
'Description:
'        This function set the selected SCLKIN pin for Data
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        RegName         USIC channel index
'        PinNo           Selected pin
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetSCLKINPins(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
   
  r.v(RegName & "DX1CR_INSW") = 1
  r.v(RegName & "DX1CR_DPOL") = 1
  r.v(RegName & "DX1CR_SFSEL") = 1
   
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P10.1") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")            'P10.1         U0C0_DX1A_I
        r.v(RegName & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P10.2") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")           'P10.2          U0C0_DX1B_I
        r.v(RegName & "DX1CR_DSEL") = 1
      End If
      
    Case ("U0C1")
      If (PinNo = "P10.10") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")                            'U0C1_DX1A_I
        r.v(RegName & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P10.5") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")                            'U0C1_DX1B_I
        r.v(RegName & "DX1CR_DSEL") = 1
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.2") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")                            'U1C0_DX1B_I
        r.v(RegName & "DX1CR_DSEL") = 1
       ElseIf (PinNo = "P0.1") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")                       'U1C0_DX1A_I
        r.v(RegName & "DX1CR_DSEL") = 0
       End If
    
    Case ("U1C1")
    
      If (PinNo = "P0.5") Then
        
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")                           'U1C1_DX1A_I
        r.v(RegName & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P0.6") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")                                  'U1C1_DX1B_I
     
        r.v(RegName & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P6.2") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")                                  'U1C1_DX1C_I
        r.v(RegName & "DX1CR_DSEL") = 2
      End If
      
    Case ("U2C0")
      If (PinNo = "P3.2") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")          ''U2C0_DX1B_I
        r.v(RegName & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P1.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DX1C_I")         'U2C0_DX1C_I
        r.v(RegName & "DX1CR_DSEL") = 2
      End If
      
    Case ("U2C1")
      If (PinNo = "P3.5") Then
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")            'U2C1_DX1A_I
        r.v(RegName & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P3.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DX1B_I")           'U2C1_DX1B_I
        r.v(RegName & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P1.2") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DX1C_I")           'U2C1_DX1C_I
        r.v(RegName & "DX1CR_DSEL") = 2
      End If
      
    Case Else
    
  End Select
  
  

End Sub


'*****************************************************************************
'Description:
'        This function releases the selected DOUTpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseDOUTPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
      
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIS_cboDOUT"))
      Case ("P2.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U0C0        'P2.3(U0C0_DOUT_O_1)
      Case ("P10.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U0C0       P10.1(U0C0_DOUT_O_3)
      Case ("P10.0")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_o_5")  'U0C1        P10.0(0C1_DOUT_o_5)
      Case ("P2.10")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U0C1        P2.10(U0C1_DOUT_O_2)
      Case ("P0.0")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U1C0        (P0.0)U1C0_DOUT_O_1
      Case ("P0.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U1C0        (P0.1)U1C0_DOUT_O_2
      Case ("P0.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U1C1        '(P0.6)U1C1_DOUT_O_1
      Case ("P0.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U1C1        '(P0.7)U1C1_DOUT_O_2
      Case ("P1.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U2C0        '(P1.6)U2C0_DOUT_O_1
      Case ("P9.4")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")  'U2C0        '(P9.4)U2C0_DOUT_O_4
      Case ("P3.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")  'U2C1         '(P3.6)U2C1_DOUT_O_1
      Case ("P3.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")  'U2C1        '(P3.7)U2C1_DOUT_O_2
      Case ("P1.1")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")  'U2C1        '(P1.1)U2C1_DOUT_O_3
          
    End Select

    r.v(ModuleName & "_IIS_cboDOUT") = "None"
    
End Sub

'*****************************************************************************
'Description:
'        This function releases the selected WAOUTPin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseWAOUTPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
    
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIS_cboWAOUT"))
      Case ("P2.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_1")  'U0C0
      Case ("P2.11")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO2_O_1")  'U0C0
      
      Case ("P2.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_1")  'U0C1
'      Case ("P10.8")
'          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_2")  'U0C1
      
      Case ("P0.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_1")  'U1C0
      Case ("P10.6")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_2")  'U1C0
      
      
      Case ("P0.4")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_1")  'U1C1
      Case ("P0.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO1_O_1")  'U1C1
      
      
      Case ("P1.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO4_O_1")  'U2C0
      Case ("P1.4")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO5_O_1")  'U2C0
      
      
      
      Case ("P3.3")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO1_O_1")  'U2C1
      Case ("P3.4")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SELO0_O_1")  'U2C1
    
    End Select
    
    r.v(ModuleName & "_IIS_cboWAOUT") = "None"
    
End Sub

'*****************************************************************************
'Description:
'        This function releases the selected SCLKOUTPin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseSCLKOUTPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
    
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIS_cboSCLKOUT"))
      Case ("P2.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U0C0
      Case ("P10.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U0C0
      Case ("P2.8")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U0C1
      Case ("P10.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U0C1
      Case ("P0.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U1C0
      Case ("P10.11")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U1C0
      Case ("P0.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U1C1
      Case ("P6.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U1C1
      Case ("P1.7")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U2C0
      Case ("P3.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U2C0
      Case ("P1.2")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_2")  'U2C1
      Case ("P3.5")
          Call ReleaseAlternateOutputPin(r, ModuleName & "_SCLKOUT_O_1")  'U2C1
    End Select
    
    r.v(ModuleName & "_IIS_cboSCLKOUT") = "None"
    
End Sub




'*****************************************************************************
'Description:
'        This function releases the selected DINpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseDINPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
      
    '--select the pin to be released--
    
    Select Case (r.v(ModuleName & "_IIS_cboDIN"))
      
      Case ("P2.4")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0F_I")  'U0C0           'P2.4
      Case ("P10.0")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")  'U0C0 and U0C1  'P10.0
      Case ("P10.7")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")  'U0C1           'P10.7
      
      Case ("P0.0")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")  'U1C0           'P0.0
      Case ("P0.1")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")  'U1C0           'P0.1
      
      Case ("P0.6")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")  'U1C1           'P0.6
      Case ("P0.7")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")  'U1C1           'P0.7
      Case ("P6.0")
        Call ReleaseAlternateInputPin(r, ModuleName & "_DX0E_I")  'U1C1             'P6.0
        
      Case ("P1.5")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")  'U2C0           'P1.5
      Case ("P1.6")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0D_I")  'U2C0           'P1.6
      
      Case ("P1.1")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")  'U2C1           'P1.1
      Case ("P1.2")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX0D_I")  'U2C1           'P1.2
          
    End Select

    r.v(ModuleName & "_IIS_cboDIN") = "None"
    
End Sub

'*****************************************************************************
'Description:
'        This function releases the selected WAINpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseWAINPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
      
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIS_cboWAOUT"))
        Case ("P10.3")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2A_I")  'U0C0 and U0C1                       'U0C0_DX2A_I
        Case ("P10.4")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2B_I")  'U0C0 and U0C1                      'U0C0_DX2B_I
      
        Case ("P0.3")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2A_I")  'U1C0                                'U1C0_DX2A_I
        Case ("P10.6")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2D_I")  'U1C0                                'U1C0_DX2D_I
      
        Case ("P0.4")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2A_I")  'U1C1                                'U1C0_DX2A_I
        Case ("P6.3")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2D_I")  'U1C1                              '  U1C0_DX2D_I
      
        Case ("P1.4")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2B_I")  'U2C0                                'U2C0_DX2B_I
        Case ("P3.3")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2A_I")  'U2C0                                'U2C0_DX2A_I
      
        Case ("P3.4")
            Call ReleaseAlternateInputPin(r, ModuleName & "_DX2A_I")  'U2C1                                'U2C1_DX2A_I
      
      End Select

    r.v(ModuleName & "_IIS_cboWAOUT") = "None"
    
End Sub

'*****************************************************************************
'Description:
'        This function releases the selected SCLKINpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseSCLKINPin(r As ProjectData, ModuleName As String)
  On Error Resume Next
      
    '--select the pin to be released--
    Select Case (r.v(ModuleName & "_IIS_cboSCLKOUT"))
      
      Case ("P10.1")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1A_I")  'U0C0           'U0C0_DX1A_I
      Case ("P10.2")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1B_I")  'U0C0          'U0C0_DX1B_I
      
      Case ("P10.10")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1A_I")  'U0C1          U0C1_DX1A_I
      Case ("P10.5")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1B_I")  'U0C1          U0C1_DX1B_I
      
      Case ("P0.2")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1B_I")  'U1C0          U1C0_DX1B_I
      Case ("P0.1")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1A_I")  'U1C0          U1C0_DX1A_I
      
      Case ("P0.5")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1A_I")  'U1C1                 U1C1_DX1A_I
      Case ("P0.6")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1B_I")  'U1C1                   U1C1_DX1B_I
      Case ("P6.2")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1C_I")  'U1C1                 U1C1_DX1C_I
      
      Case ("P3.2")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1B_I")   'U2C0                   U2C0_DX1B_I
      Case ("P1.7")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1C_I")  'U2C0                  U2C0_DX1C_I
      
      Case ("P3.5")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1A_I")  'U2C1                   U2C1_DX1A_I
      Case ("P3.6")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1B_I")  'U2C1                   U2C1_DX1B_I
      Case ("P1.2")
          Call ReleaseAlternateInputPin(r, ModuleName & "_DX1C_I")  'U2C1                   U2C1_DX1B_I
    
    End Select

    r.v(ModuleName & "_IIS_cboSCLKOUT") = "None"
    
End Sub



'*****************************************************************************
'Description:
 '*****************************************************************************
'Description:
'        This function sets the STEP and PDIV values for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetWordLength(r As ProjectData, ModuleName As String, WordLength As Variant)
On Error Resume Next

  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  
  sVarPre = ModuleName
  sRegPre = sVarPre & "_"
  
    Select Case (WordLength)
    
        Case ("8")
            r.v(sRegPre & "SCTRH_WLE") = 7                   '8 Bits
            r.v(sRegPre & "SCTRH_FLE") = 7                   '8 Bits
        Case ("9")
            r.v(sRegPre & "SCTRH_WLE") = 8                   '9 Bits
            r.v(sRegPre & "SCTRH_FLE") = 8                   '9 Bits
        Case ("10")
            r.v(sRegPre & "SCTRH_WLE") = 9                   '10 Bits
            r.v(sRegPre & "SCTRH_FLE") = 9                   '10 Bits
        Case ("11")
           r.v(sRegPre & "SCTRH_WLE") = 10                   '11 Bits
           r.v(sRegPre & "SCTRH_FLE") = 10                   '11 Bits
        Case ("12")
            r.v(sRegPre & "SCTRH_WLE") = 11                  '12 Bits
            r.v(sRegPre & "SCTRH_FLE") = 11                  '12 Bits
        Case ("13")
            r.v(sRegPre & "SCTRH_WLE") = 12                  '13 Bits
            r.v(sRegPre & "SCTRH_FLE") = 12                  '13 Bits
        Case ("14")
            r.v(sRegPre & "SCTRH_WLE") = 13                  '14 Bits
            r.v(sRegPre & "SCTRH_FLE") = 13                  '14 Bits
        Case ("15")
            r.v(sRegPre & "SCTRH_WLE") = 14                  '15 Bits
            r.v(sRegPre & "SCTRH_FLE") = 14                  '15 Bits
        Case ("16")
            r.v(sRegPre & "SCTRH_WLE") = 15                  '16 Bits
            r.v(sRegPre & "SCTRH_FLE") = 15                  '16 Bits
    
    End Select
End Sub

'*****************************************************************************
'Description:
'        This function returns disabled tool tip of DOUTpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   DOUTDisabledToolTip
'*****************************************************************************
Function GetDOUTDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get DOUT disabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DOUT_O_1")  'P2.3
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DOUT_O_2")  'P10.1

      Case ("U0C1")
          
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_3")  'P2.10
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DOUT_O_5")  'P10.0

      Case ("U1C0")
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DOUT_O_1")  'P0.0
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DOUT_O_2")  'P0.1


      Case ("U1C1")
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DOUT_O_1")  'P0.6
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DOUT_O_2")  'P0.7

      Case ("U2C0")
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DOUT_O_1")  'P1.6
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DOUT_O_4")  'P9.4

      Case ("U2C1")
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DOUT_O_1")  'P3.6
          GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DOUT_O_2")  'P3.7
            GetDOUTDisabledToolTip = GetDOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DOUT_O_3")  'P1.1
     
     End Select
   
End Function

'*****************************************************************************
'Description:
'        This function returns disabled tool tip of WAOUTpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   WAOUTDisabledToolTip
'*****************************************************************************
Function GetWAOUTDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get WAOUT disabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_SELO0_O_1")  'P2.6
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_SELO2_O_1")  'P2.11
        
      Case ("U0C1")
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_SELO0_O_1")  'P2.7
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_SELO1_O_1")  'P2.6
        
      Case ("U1C0")
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_SELO0_O_1")  'P0.3
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_SELO0_O_2")  'P10.6
        
      Case ("U1C1")
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_SELO0_O_1")  'P0.4
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_SELO1_O_1")  'P0.3
        
      Case ("U2C0")
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_SELO4_O_1")  'P1.3
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_SELO5_O_1")  'P1.4
        
      Case ("U2C1")
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_SELO1_O_1")  'P3.3
        GetWAOUTDisabledToolTip = GetWAOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_SELO0_O_1")  'P3.4
        
     End Select
   
End Function


'*****************************************************************************
'Description:
'        This function returns disabled tool tip of SCLKOUTpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   SCLKOUTDisabledToolTip
'*****************************************************************************
Function GetSCLKOUTDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get SCLKOUT disabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_SCLKOUT_O_2")  'P10.2
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_SCLKOUT_O_1")  ''P2.5
      
      Case ("U0C1")
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_SCLKOUT_O_1")  ''P2.8
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_SCLKOUT_O_2")  'P10.5
      
      
      Case ("U1C0")
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_SCLKOUT_O_1")  ''P0.2
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_SCLKOUT_O_2")  'P10.11
      
      Case ("U1C1")
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_SCLKOUT_O_1")  'P0.5
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_SCLKOUT_O_2")  'P6.2
      
      
      Case ("U2C0")
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_SCLKOUT_O_1")  'P1.7
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_SCLKOUT_O_2")  'P3.2
      
      Case ("U2C1")
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_SCLKOUT_O_2")  'P1.2
        GetSCLKOUTDisabledToolTip = GetSCLKOUTDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_SCLKOUT_O_1")  'P3.5
     
     End Select
   
End Function



'*****************************************************************************
'Description:
'        This function returns disabled tool tip of DINpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   DINDisabledToolTip
'*****************************************************************************
Function GetDINDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get DINdisabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DX0F_I")  'P2.4
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DX0A_I")  'P10.0
          
      Case ("U0C1")
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DX0A_I")  'P10.0
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DX0B_I")  'P10.7
          
      Case ("U1C0")
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DX0A_I")  'P0.0
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DX0B_I")  'P0.1
          
      Case ("U1C1")
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DX0A_I")  'P0.6
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DX0B_I")  'P0.7
          
      Case ("U2C0")
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DX0C_I")  'P1.5
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DX0D_I")  'P1.6
            
      Case ("U2C1")
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DX0C_I")  'P1.1
          GetDINDisabledToolTip = GetDINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DX0D_I")  'P1.2

     End Select
   
End Function
'*****************************************************************************
'Description:
'        This function returns disabled tool tip of WAINpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   WAINDisabledToolTip
'*****************************************************************************
Function GetWAINDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get DINdisabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DX2A_I")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DX2B_I")
          
      Case ("U0C1")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DX2A_I")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DX2B_I")
          
      Case ("U1C0")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DX2A_I")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DX2D_I")
          
      Case ("U1C1")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DX2A_I")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DX2D_I")
          
      Case ("U2C0")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DX2B_I")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DX2A_I")
            
      Case ("U2C1")
          GetWAINDisabledToolTip = GetWAINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DX2A_I")
          

     End Select
   
End Function
'*****************************************************************************
'Description:
'        This function returns disabled tool tip of SCLKINpin for UxCy IIS mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      Name of the channel
'-----------------------------------------------------------------------------
'Returns:   SCLKINDisabledToolTip
'*****************************************************************************
Function GetSCLKINDisabledToolTip(r As ProjectData, ModuleName As String) As String
  On Error Resume Next
      
    '--Get DINdisabled tooltips--
    Select Case (ModuleName)
      Case ("U0C0")
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DX1A_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C0_DX1B_I")  '
          
      Case ("U0C1")
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DX1A_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U0C1_DX1B_I")  '
          
      Case ("U1C0")
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DX1A_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C0_DX1B_I")  '
          
      Case ("U1C1")
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DX1A_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U1C1_DX1C_I")  '
          
      Case ("U2C0")
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DX1B_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C0_DX1C_I")  '
            
      Case ("U2C1")
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DX1A_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DX1B_I")  '
          GetSCLKINDisabledToolTip = GetSCLKINDisabledToolTip & GetDisabledAlternatePinTooltip(r, "U2C1_DX1C_I")
     End Select
   
End Function


'*****************************************************************************
'Description:
'          This function calculates Real IIS Baudrate from the values of the
'          components of the formulae
'-----------------------------------------------------------------------------
'Parameters:
'      r                  reference to the Registers object
'      vIndex             As Variant
'-----------------------------------------------------------------------------
'Returns:
'      RealIISBaudrate    Real Baudrate that would be generated by the MC
'*****************************************************************************
Function RealIISBaudrate(r As ProjectData, vIndex As Variant) As Double
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"


  RealIISBaudrate = (GetSystemClock(r) * 1000000 * _
                     r.v(sRegPre & "FDRL_STEP")) / _
                    (2048 * _
                    (r.v(sRegPre & "BRGH_PDIV") + 1))
                      
End Function

'*****************************************************************************
'Description:
'         This function updates the IIS BRG PDIV and STEP values.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           As Variant
'
'-----------------------------------------------------------------------------
'*****************************************************************************
Sub UpdateIISBaudrate(r As ProjectData, vIndex As Variant)
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String
    Dim fPIN As Double

    sVarPre = Format$(vIndex)
    sRegPre = Format$(vIndex) & "_"
    'Default IIS BuadRate configuration
     r.v(sRegPre & "FDRL_DM") = 2          ' Fractional Divider

     r.v(sRegPre & "BRGH_PDIV") = 1000      ' Divider factor
        
     fPIN = IISGetfPIN(r, vIndex, "IIS") * (2 * 2 ^ (r.v(sRegPre & "BRGL_PPPEN")))
      
     While (fPIN > (GetSystemClock(r) * 1000000))
        r.v(sRegPre & "BRGH_PDIV") = r.v(sRegPre & "BRGH_PDIV") / 2
        fPIN = IISGetfPIN(r, vIndex, "IIS") * (2 * 2 ^ (r.v(sRegPre & "BRGL_PPPEN")))
     Wend
    
     r.v(sRegPre & "FDRL_STEP") = (fPIN * 1024) / (GetSystemClock(r) * 1000000)

End Sub
