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"
'#Uses "Include.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
'        ---------------------------------------------------------------------
'        0.1  JaiSankar                 16.04.07        XC22xx v0.01
'
'
'*****************************************************************************

' use this constant in the Format statement for all calculated outputs like
' baud rates or deviation
'Global Const USIC_PRECISION = "0.000"

'*****************************************************************************
'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 RefreshASCFunctionDescriptions(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) & "_"

  RefreshASCFunctionDescriptions = 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 UxCy_NAME_ASCInit
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sVarPre)
  sReturnValue = "None"

  If (Not func.AddFunction(sVarPre & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASCSendData
  '------------------------------------------------------------------------------------------------
  sDescription = "This function clears the transmit buffer Indication flag first " & _
                 " & then writes the send data initialization word into " & _
                 "the transmit buffer register." & vbCrLf & vbCrLf & _
                 "Note: " & vbCrLf & _
                 "In a multiprocessor system the master with this function " & _
                 "has the possibility to send data to the selected slave."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCSendData", "void", sDescription, sReturnValue, 1)) Then Exit Function
  sDescription = "Data to be send"
  If (Not func.AddParameter(sVarPre & "_NAME_ASCSendData_Par1", "uwData", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASCGetData
  '------------------------------------------------------------------------------------------------
  sDescription = "This function reads out the content of the receive buffer register " & _
                  "which contains the received data."

  sReturnValue = "Data that has been received"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCGetData", "uword", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASCTxDataReady
  '------------------------------------------------------------------------------------------------
  sDescription = "This function can be used for checking up the status of the transmit " & _
                 "shift indication flag " & sRegPre & "PSR_TSIF. This function shows " & _
                 "when the sending of data has terminated. By continuously " & _
                 "polling this flag after the function " & r.v(sVarPre & "_NAME_ASCSendData") & " has been called, it is " & _
                 "possible to establish when " & sVarPre & " has terminated its task."

  sReturnValue = "0 if transmitter is busy, else 1"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCTxDataReady", "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASCTxBufFree
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro can be used for checking the status of " & sVarPre & " " & _
                 "transmit buffer register. The transmit buffer may only " & _
                 "be written to if it is empty, this implies that the previous " & _
                 "content of the transmit buffer have been loaded into the transmit shift " & _
                 "register."

  sReturnValue = "0 if buffer is empty, else 1"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCTxBufFree", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASCRxDataReady
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro can be used for calling the status of " & sVarPre & " " & _
                 "receiver interrupt flag. This is to recognize that " & _
                 "the " & sVarPre & " received a byte. If a byte has been received, the " & _
                 "function " & r.v(sVarPre & "_NAME_ASCGetData") & " must be called."

  sReturnValue = "0 receive data is invalid, else 1"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCRxDataReady", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASC0IC
  '------------------------------------------------------------------------------------------------
  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_ASC0IC", "void", sDescription, sReturnValue, 2)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASC1IC
  '------------------------------------------------------------------------------------------------
  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_ASC1IC", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASC2IC
  '------------------------------------------------------------------------------------------------
  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_ASC2IC", "void", sDescription, sReturnValue, 2)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UxCy_NAME_ASC3IC
  '------------------------------------------------------------------------------------------------
  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_ASC3IC", "void", sDescription, sReturnValue, 2)) Then Exit Function

'  '------------------------------------------------------------------------------------------------
'  ' Description for ASC UxCy_NAME_ASCFillTxFIFO
'  '------------------------------------------------------------------------------------------------
'  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_ASCFillTxFIFO", "", sDescription, sReturnValue, 1)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCFillTxFIFO
  '------------------------------------------------------------------------------------------------
  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_ASCFillTxFIFO", "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Pointer to user data buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_ASCFillTxFIFO" & "_Para1", "*uwUDTxfifo", "uword", sDescription)) Then Exit Function
    sDescription = "Amount of data to transmit"
    If (Not func.AddParameter(sVarPre & "_NAME_ASCFillTxFIFO" & "_Para2", "uwUDTxfifoSize", "uword", sDescription)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCGetRxFIFOData
  '------------------------------------------------------------------------------------------------
  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_ASCGetRxFIFOData", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCIsRxFIFObusy
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is currently updated by FIFO handler."

  sReturnValue = "1 if receive buffer is busy, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCIsRxFIFObusy", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCIsTxFIFObusy
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is currently updated by FIFO handler."

  sReturnValue = "1 if transmit buffer is busy, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCIsTxFIFObusy", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCIsRxFIFOfull
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is full or not."

  sReturnValue = "1 if receive buffer is full, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCIsRxFIFOfull", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCIsTxFIFOfull
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is full or not."

  sReturnValue = "1 if transmit buffer is full, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCIsTxFIFOfull", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCIsRxFIFOempty
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the receive buffer" & _
                 " is empty or not."

  sReturnValue = "1 if receive buffer is empty, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCIsRxFIFOempty", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCIsTxFIFOempty
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status whether the transmit buffer" & _
                 " is empty or not."

  sReturnValue = "1 if transmit buffer is empty, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCIsTxFIFOempty", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCGetRxFIFOFillingLevel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status of the receive buffer filling level."

  sReturnValue = "Value of the bitfield " & sVarPre & "_TRBSRH_RBFLVL"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCGetRxFIFOFillingLevel", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCGetTxFIFOFillingLevel
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro is used to get the status of the transmit buffer filling level."

  sReturnValue = "Value of the bitfield " & sVarPre & "_TRBSRH_TBFLVL"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCGetTxFIFOFillingLevel", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCFlushRxFIFO
  '------------------------------------------------------------------------------------------------
  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 = "1 if receive buffer is cleared, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCFlushRxFIFO", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ASC UxCy_NAME_ASCFlushTxFIFO
  '------------------------------------------------------------------------------------------------
  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 = "1 if transmit buffer is cleared, else 0"
  If (Not func.AddFunction(sVarPre & "_NAME_ASCFlushTxFIFO", "", sDescription, sReturnValue, 0)) Then Exit Function
  
  If (Not func.Sort) Then Exit Function

  RefreshASCFunctionDescriptions = True
End Function


'*****************************************************************************
'Description:
'         This function updates the ASC BRG PDIV and STEP values.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           As Variant
'
'-----------------------------------------------------------------------------
'*****************************************************************************
Sub UpdateASCBaudrate(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 ASC BuadRate configuration
    r.v(sRegPre & "FDRL_DM") = 2          ' Fractional Divider
    r.v(sRegPre & "BRGL_PCTQ") = 1        ' PreDivider for CTQ
    r.v(sRegPre & "BRGL_DCTQ") = 15       ' Denominator for CTQ
    r.v(sRegPre & "BRGH_PDIV") = 99       ' Divider factor
    
    fPIN = GetfPIN(r, vIndex, "ASC")
     
    While (fPIN > (GetSystemClock(r) * 1000000))
        r.v(sRegPre & "BRGH_PDIV") = r.v(sRegPre & "BRGH_PDIV") / 2
        fPIN = GetfPIN(r, vIndex, "ASC")
    Wend
    
    r.v(sRegPre & "FDRL_STEP") = (fPIN * 1024) / (GetSystemClock(r) * 1000000)
     
End Sub

Function IsBaudRateok(r As ProjectData, vIndex As Variant, Optional BRate As Double)
  On Error Resume Next

  Dim sVarPre   As String
  Dim sRegPre   As String
  Dim fPIN      As Double
  Dim iPDIV As Integer
  Dim iSTEP As Integer

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

  IsBaudRateok = False
    
    iPDIV = r.v(sRegPre & "BRGH_PDIV")
    iSTEP = r.v(sRegPre & "FDRL_STEP")
    
    'Default ASC BuadRate configuration
    r.v(sRegPre & "BRGH_PDIV") = 99       ' Divider factor
    
    fPIN = ASCGetfPIN(r, vIndex, BRate)
     
    While (fPIN > (GetSystemClock(r) * 1000000))
      r.v(sRegPre & "BRGH_PDIV") = r.v(sRegPre & "BRGH_PDIV") / 2
      fPIN = ASCGetfPIN(r, vIndex, BRate)
    Wend
    
    If (r.v(sRegPre & "BRGH_PDIV") >= 1) Then
      IsBaudRateok = True
    Else
      r.v(sRegPre & "BRGH_PDIV") = iPDIV
      IsBaudRateok = False
    End If

End Function


Function ASCGetfPIN(r As ProjectData, vIndex As Variant, BRate As Double) As Double
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  ASCGetfPIN = BRate * _
            (r.v(sRegPre & "BRGH_PDIV") + 1) * _
            (r.v(sRegPre & "BRGL_PCTQ") + 1) * _
            (r.v(sRegPre & "BRGL_DCTQ") + 1)

End Function


'*****************************************************************************
'Description:
'          This function calculates Real ASC Baudrate from the values of the
'          components of the formulae
'-----------------------------------------------------------------------------
'Parameters:
'      r                  reference to the Registers object
'      vIndex             As Variant
'-----------------------------------------------------------------------------
'Returns:
'      RealASCBaudrate    Real Baudrate that would be generated by the MC
'*****************************************************************************
Function RealASCBaudrate(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) & "_"

  RealASCBaudrate = (GetSystemClock(r) * 1000000 * _
                     r.v(sRegPre & "FDRL_STEP")) / _
                    (1024 * _
                    (r.v(sRegPre & "BRGH_PDIV") + 1) * _
                    (r.v(sRegPre & "BRGL_PCTQ") + 1) * _
                    (r.v(sRegPre & "BRGL_DCTQ") + 1))

End Function


'*****************************************************************************
'Description:
'        This function adds ASC transmit pins and returns its index value
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         TxD combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to TxD Pins combobox
'*****************************************************************************
Function AddASCTxDPINSnGetIndex(r As ProjectData, ModuleName As String, RegName As String, ProtoName As String, cboCrtl As Variant) As Integer
  On Error Resume Next

  Dim i As Integer
  Dim sVarPre As String
  Dim sRegPre As String
  
  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")
      
  Select Case (ModuleName)
    
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_1") Then cboCrtl.AddItem ("P2.3")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_2") Then cboCrtl.AddItem ("P7.3")
      
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.1")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_4") Then cboCrtl.AddItem ("P10.6")
              
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_1") Then cboCrtl.AddItem ("P2.9")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_2") Then cboCrtl.AddItem ("P2.10")
      
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_3") Then cboCrtl.AddItem ("P7.3")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_4") Then cboCrtl.AddItem ("P7.4")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_5") Then cboCrtl.AddItem ("P10.0")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_6") Then cboCrtl.AddItem ("P10.7")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_7") Then cboCrtl.AddItem ("P10.14")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_8") Then cboCrtl.AddItem ("P10.15")
            
    Case ("U1C0")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.12")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_4") Then cboCrtl.AddItem ("P10.13")
      
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_1") Then cboCrtl.AddItem ("P0.0")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_2") Then cboCrtl.AddItem ("P0.1")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_5") Then cboCrtl.AddItem ("P10.15")
      
    Case ("U1C1")
      'Chk if this pin P6.0 is there for this channel?
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_3") Then cboCrtl.AddItem ("P6.0")
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_4") Then cboCrtl.AddItem ("P6.1")
      
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_1") Then cboCrtl.AddItem ("P0.6")
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_2") Then cboCrtl.AddItem ("P0.7")

    Case ("U2C0")
      If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_1") Then cboCrtl.AddItem ("P1.6")
      
'      If (DefGetValue("Name") = "XC2287" Or DefGetValue("Name") = "XE167F") Then
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_2") Then cboCrtl.AddItem ("P3.0")
        If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_3") Then cboCrtl.AddItem ("P3.1")
        If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_4") Then cboCrtl.AddItem ("P9.4")
        If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_5") Then cboCrtl.AddItem ("P9.5")
      End If
      
    Case ("U2C1")
      If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_3") Then cboCrtl.AddItem ("P1.1")
      
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_1") Then cboCrtl.AddItem ("P3.6")
        If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_2") Then cboCrtl.AddItem ("P3.7")
      End If
      
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_ASC_cboTxD")) Then
        AddASCTxDPINSnGetIndex = i
    End If
  Next i
  
    If ((cboCrtl.ListCount) = 1) Then
      cboCrtl.Enabled = False
    End If
    

End Function


'*****************************************************************************
'Description:
'        This function adds ASC half duplex transmit pins and returns its index value
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         TxD combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to TxD Pins combobox
'*****************************************************************************
Function AddASCHDTxDPINSnGetIndex(r As ProjectData, ModuleName As String, RegName As String, ProtoName As String, cboCrtl As Variant) As Integer
  On Error Resume Next

  Dim i As Integer
  Dim sVarPre As String
  Dim sRegPre As String
  
  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")
      
  Select Case (ModuleName)
    
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.1")
              
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_DOUT_O_8") Then cboCrtl.AddItem ("P10.15")
            
    Case ("U1C0")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_3") Then cboCrtl.AddItem ("P10.12")
      If IsAlternateOutputPinFree(r, "U1C0_DOUT_O_2") Then cboCrtl.AddItem ("P0.1")
      
    Case ("U1C1")
      If IsAlternateOutputPinFree(r, "U1C1_DOUT_O_1") Then cboCrtl.AddItem ("P0.6")

    Case ("U2C0")
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateOutputPinFree(r, "U2C0_DOUT_O_2") Then cboCrtl.AddItem ("P3.0")
      End If
      
    Case ("U2C1")
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateOutputPinFree(r, "U2C1_DOUT_O_1") Then cboCrtl.AddItem ("P3.6")
      End If
      
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_ASC_cboTxD")) Then
        AddASCHDTxDPINSnGetIndex = i
    End If
  Next i
  
    If ((cboCrtl.ListCount) = 1) Then
      cboCrtl.Enabled = False
    End If
    

End Function


'*****************************************************************************
'Description:
'        This function
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        ModuleName      USIC Channel name
'        cboCrtl         RxD combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to RxD Pins combobox
'*****************************************************************************
Function AddASCRxDPINSnGetIndex(r As ProjectData, ModuleName As String, RegName As String, ProtoName As String, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
  Dim sVarPre As String
  Dim sRegPre As String
  
  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModuleName)
    
    Case ("U0C0")
      If IsAlternateInputPinFree(r, "U0C0_DX0D_I") Then cboCrtl.AddItem ("P7.4")
      If IsAlternateInputPinFree(r, "U0C0_DX0A_I") Then cboCrtl.AddItem ("P10.0")
      
      If IsAlternateInputPinFree(r, "U0C0_DX0B_I") Then cboCrtl.AddItem ("P10.1")
      If IsAlternateInputPinFree(r, "U0C0_DX0C_I") Then cboCrtl.AddItem ("P10.6")
      If IsAlternateInputPinFree(r, "U0C0_DX0E_I") Then cboCrtl.AddItem ("P2.3")
      If IsAlternateInputPinFree(r, "U0C0_DX0F_I") Then cboCrtl.AddItem ("P2.4")
    
    Case ("U0C1")
      If IsAlternateInputPinFree(r, "U0C1_DX0B_I") Then cboCrtl.AddItem ("P10.7")
      If IsAlternateInputPinFree(r, "U0C1_DX0C_I") Then cboCrtl.AddItem ("P10.14")
      
      If IsAlternateInputPinFree(r, "U0C1_DX0A_I") Then cboCrtl.AddItem ("P10.0")
      'If IsAlternateInputPinFree(r, "U0C1_DX0D_I") Then cboCrtl.AddItem ("P")
      If IsAlternateInputPinFree(r, "U0C1_DX0E_I") Then cboCrtl.AddItem ("P2.10")
      If IsAlternateInputPinFree(r, "U0C1_DX0F_I") Then cboCrtl.AddItem ("P7.3")
      
    Case ("U1C0")
      If IsAlternateInputPinFree(r, "U1C0_DX0A_I") Then cboCrtl.AddItem ("P0.0")
      If IsAlternateInputPinFree(r, "U1C0_DX0B_I") Then cboCrtl.AddItem ("P0.1")
      
      If IsAlternateInputPinFree(r, "U1C0_DX0C_I") Then cboCrtl.AddItem ("P10.12")
      If IsAlternateInputPinFree(r, "U1C0_DX0D_I") Then cboCrtl.AddItem ("P10.13")
      
    Case ("U1C1")
      If IsAlternateInputPinFree(r, "U1C1_DX0A_I") Then cboCrtl.AddItem ("P0.6")
      If IsAlternateInputPinFree(r, "U1C1_DX0B_I") Then cboCrtl.AddItem ("P0.7")
      
      If IsAlternateInputPinFree(r, "U1C1_DX0E_I") Then cboCrtl.AddItem ("P6.0")

    Case ("U2C0")
      If IsAlternateInputPinFree(r, "U2C0_DX0C_I") Then cboCrtl.AddItem ("P1.5")
      
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateInputPinFree(r, "U2C0_DX0A_I") Then cboCrtl.AddItem ("P3.0")
        If IsAlternateInputPinFree(r, "U2C0_DX0B_I") Then cboCrtl.AddItem ("P3.1")
      End If
      
      If IsAlternateInputPinFree(r, "U2C0_DX0D_I") Then cboCrtl.AddItem ("P1.6")
      
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateInputPinFree(r, "U2C0_DX0E_I") Then cboCrtl.AddItem ("P9.5")
      End If

    Case ("U2C1")
      If IsAlternateInputPinFree(r, "U2C1_DX0D_I") Then cboCrtl.AddItem ("P1.2")
      
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateInputPinFree(r, "U2C1_DX0A_I") Then cboCrtl.AddItem ("P3.6")
        If IsAlternateInputPinFree(r, "U2C1_DX0B_I") Then cboCrtl.AddItem ("P3.7")
      End If
      
      If IsAlternateInputPinFree(r, "U2C1_DX0C_I") Then cboCrtl.AddItem ("P1.1")

    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_ASC_cboRxD")) Then
        AddASCRxDPINSnGetIndex = i
    End If
  Next i
  
  If ((cboCrtl.ListCount) = 1) Then
    cboCrtl.Enabled = False
  End If
  
End Function

 
'*****************************************************************************
'Description:
'        This function
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Function AddASCClkPINSnGetIndex(r As ProjectData, ModuleName As String, RegName As String, ProtoName As String, cboCrtl As Variant) As Integer
On Error Resume Next
  
  Dim i As Integer
  Dim sVarPre As String
  Dim sRegPre As String
   

  sVarPre = ModuleName
  sRegPre = sVarPre & "_"
  
  cboCrtl.Clear
  cboCrtl.AddItem ("None")
   
  Select Case (ModuleName)
    
    Case ("U0C0")
      If IsAlternateOutputPinFree(r, "U0C0_DX1A_I") Then
        cboCrtl.AddItem ("P10.1")
      End If
      If IsAlternateOutputPinFree(r, "U0C0_DX1B_I") Then
        cboCrtl.AddItem ("P10.2")
      End If
      If IsAlternateOutputPinFree(r, "U0C0_DX1C_I") Then
        cboCrtl.AddItem ("P10.8")
      End If
      If IsAlternateOutputPinFree(r, "U0C0_DX1D_I") Then
        cboCrtl.AddItem ("P2.5")
      End If
            
    Case ("U0C1")
      If IsAlternateOutputPinFree(r, "U0C1_DX1A_I") Then
        cboCrtl.AddItem ("P10.10")
      End If
      If IsAlternateOutputPinFree(r, "U0C1_DX1B_I") Then
        cboCrtl.AddItem ("P10.5")
      End If
      If IsAlternateOutputPinFree(r, "U0C1_DX1C_I") Then
        cboCrtl.AddItem ("P10.15")
      End If
      If IsAlternateOutputPinFree(r, "U0C1_DX1D_I") Then
        cboCrtl.AddItem ("P2.8")
      End If
      If IsAlternateOutputPinFree(r, "U0C1_DX1E_I") Then
        cboCrtl.AddItem ("P7.4")
      End If
      
    Case ("U1C0")
      If IsAlternateOutputPinFree(r, "U1C0_DX1A_I") Then
        cboCrtl.AddItem ("P0.1")
      End If
      If IsAlternateOutputPinFree(r, "U1C0_DX1B_I") Then
        cboCrtl.AddItem ("P0.2")
      End If
      If IsAlternateOutputPinFree(r, "U1C0_DX1C_I") Then
        cboCrtl.AddItem ("P0.5")
      End If
      If IsAlternateOutputPinFree(r, "U1C0_DX1D_I") Then
        cboCrtl.AddItem ("P10.11")
      End If
      If IsAlternateOutputPinFree(r, "U1C0_DX1E_I") Then
        cboCrtl.AddItem ("P10.12")
      End If
      
    Case ("U1C1")
      If IsAlternateOutputPinFree(r, "U1C1_DX1A_I") Then
        cboCrtl.AddItem ("P0.5")
      End If
      If IsAlternateOutputPinFree(r, "U1C1_DX1B_I") Then
        cboCrtl.AddItem ("P0.6")
      End If
      If IsAlternateOutputPinFree(r, "U1C1_DX1C_I") Then
        cboCrtl.AddItem ("P6.2")
      End If
      
    Case ("U2C0")
      If IsAlternateOutputPinFree(r, "U2C0_DX1C_I") Then
        cboCrtl.AddItem ("P1.7")
      End If
      
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateOutputPinFree(r, "U2C0_DX1A_I") Then
            cboCrtl.AddItem ("P3.0")
        End If
        If IsAlternateOutputPinFree(r, "U2C0_DX1B_I") Then
            cboCrtl.AddItem ("P3.2")
        End If
        If IsAlternateOutputPinFree(r, "U2C0_DX1D_I") Then
            cboCrtl.AddItem ("P9.7")
        End If
      End If
      
    Case ("U2C1")
      If IsAlternateOutputPinFree(r, "U2C1_DX1C_I") Then
        cboCrtl.AddItem ("P1.2")
      End If
      
      If (IsControllerTypeOK(r) = 1) Then
        If IsAlternateOutputPinFree(r, "U2C1_DX1A_I") Then
            cboCrtl.AddItem ("P3.5")
        End If
        If IsAlternateOutputPinFree(r, "U2C1_DX1B_I") Then
            cboCrtl.AddItem ("P3.6")
        End If
      End If
    
    Case Else
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
    If (cboCrtl.List(i) = r.v(ModuleName & "_ASC_cboClk")) Then
        AddASCClkPINSnGetIndex = i
    End If
  Next i
  
  If ((cboCrtl.ListCount) = 1) Then
    cboCrtl.Enabled = False
  End If

End Function


'*****************************************************************************
'Description:
'        This function
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetASCTxDPins(r As ProjectData, ModuleName As String, RegName As String, ProtoName 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")
      ElseIf (PinNo = "P7.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      ElseIf (PinNo = "P10.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      ElseIf (PinNo = "P10.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
      End If
      
    Case ("U0C1")
      If (PinNo = "P2.9") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
      ElseIf (PinNo = "P2.10") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      ElseIf (PinNo = "P7.3") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      ElseIf (PinNo = "P7.4") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
      ElseIf (PinNo = "P10.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
      ElseIf (PinNo = "P10.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_6")
      ElseIf (PinNo = "P10.14") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_7")
      ElseIf (PinNo = "P10.15") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_8")
      End If
      
    Case ("U1C0")
      If (PinNo = "P10.12") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      ElseIf (PinNo = "P10.13") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
      ElseIf (PinNo = "P0.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
      ElseIf (PinNo = "P0.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      ElseIf (PinNo = "P10.15") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
      ElseIf (PinNo = "P6.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      ElseIf (PinNo = "P6.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
      ElseIf (PinNo = "P0.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
      ElseIf (PinNo = "P3.0") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      ElseIf (PinNo = "P3.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      ElseIf (PinNo = "P9.4") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
      ElseIf (PinNo = "P9.5") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
      End If
      
    Case ("U2C1")
      If (PinNo = "P1.1") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      ElseIf (PinNo = "P3.6") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
      ElseIf (PinNo = "P3.7") Then
        Call RequestAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      End If
      
    Case Else
  End Select

End Sub


'*****************************************************************************
'Description:
'        This function
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetASCRxDPins(r As ProjectData, ModuleName As String, RegName As String, ProtoName As String, PinNo As String)
  On Error Resume Next
  
  Dim sRegPre As String
  Dim sVarPre As String

  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
    
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P7.4") Then
        r.v("P7_IOCR04_PC") = 2 'Value 2 is used in Example code
        Call RequestAlternateInputPin(r, sVarPre & "_DX0D_I")
        r.v(sRegPre & "DX0CR_DSEL") = 3
      ElseIf (PinNo = "P10.0") Then
        r.v("P10_IOCR00_PC") = 2 'Value 2 is used in Example code
        Call RequestAlternateInputPin(r, sVarPre & "_DX0A_I")
        r.v(sRegPre & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P10.1") Then
        r.v("P10_IOCR01_PC") = 2 'Value 2 is used in Example code
        Call RequestAlternateInputPin(r, sVarPre & "_DX0B_I")
        r.v(sRegPre & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P10.6") Then
        r.v("P10_IOCR06_PC") = 2 'Value 2 is used in Example code
        Call RequestAlternateInputPin(r, sVarPre & "_DX0C_I")
        r.v(sRegPre & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P2.3") Then
        r.v("P2_IOCR03_PC") = 2 'Value 2 is used in Example code
        Call RequestAlternateInputPin(r, sVarPre & "_DX0E_I")
        r.v(sRegPre & "DX0CR_DSEL") = 4
      ElseIf (PinNo = "P2.4") Then
        r.v("P2_IOCR04_PC") = 2 'Value 2 is used in Example code
        Call RequestAlternateInputPin(r, sVarPre & "_DX0F_I")
        r.v(sRegPre & "DX0CR_DSEL") = 5
      End If
      
    Case ("U0C1")
      If (PinNo = "P10.7") Then
        r.v("P10_IOCR07_PC") = 2 'If value 0 is not working out then use value 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0B_I")
        r.v(sRegPre & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P10.14") Then
        r.v("P10_IOCR14_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0C_I")
        r.v(sRegPre & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P10.0") Then
        r.v("P10_IOCR00_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0A_I")
        r.v(sRegPre & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P2.10") Then
        r.v("P2_IOCR10_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0E_I")
        r.v(sRegPre & "DX0CR_DSEL") = 4
      ElseIf (PinNo = "P7.3") Then
        r.v("P7_IOCR03_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0F_I")
        r.v(sRegPre & "DX0CR_DSEL") = 5
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.0") Then
        r.v("P0_IOCR00_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0A_I")
        r.v(sRegPre & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P0.1") Then
        r.v("P0_IOCR01_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0B_I")
        r.v(sRegPre & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P10.12") Then
        r.v("P10_IOCR12_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0C_I")
        r.v(sRegPre & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P10.13") Then
        r.v("P10_IOCR13_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0D_I")
        r.v(sRegPre & "DX0CR_DSEL") = 3
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.6") Then
        r.v("P0_IOCR06_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0A_I")
        r.v(sRegPre & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P0.7") Then
        r.v("P0_IOCR07_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0B_I")
        r.v(sRegPre & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P6.0") Then
        r.v("P6_IOCR00_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0E_I")
        r.v(sRegPre & "DX0CR_DSEL") = 4
      End If
      
    Case ("U2C0")
      If (PinNo = "P1.5") Then
        r.v("P1_IOCR05_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0C_I")
        r.v(sRegPre & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P3.0") Then
        r.v("P3_IOCR00_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0A_I")
        r.v(sRegPre & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P3.1") Then
        r.v("P3_IOCR01_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0B_I")
        r.v(sRegPre & "DX0CR_DSEL") = 1
      ElseIf (PinNo = "P1.6") Then
        r.v("P1_IOCR06_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0D_I")
        r.v(sRegPre & "DX0CR_DSEL") = 3
      ElseIf (PinNo = "P9.5") Then
        r.v("P9_IOCR05_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0E_I")
        r.v(sRegPre & "DX0CR_DSEL") = 4
      End If
      
    Case ("U2C1")
      If (PinNo = "P1.1") Then
        r.v("P1_IOCR01_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0C_I")
        r.v(sRegPre & "DX0CR_DSEL") = 2
      ElseIf (PinNo = "P1.2") Then
        r.v("P1_IOCR02_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0D_I")
        r.v(sRegPre & "DX0CR_DSEL") = 3
      ElseIf (PinNo = "P3.6") Then
        r.v("P3_IOCR06_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0A_I")
        r.v(sRegPre & "DX0CR_DSEL") = 0
      ElseIf (PinNo = "P3.7") Then
        r.v("P3_IOCR07_PC") = 2
        Call RequestAlternateInputPin(r, sVarPre & "_DX0B_I")
        r.v(sRegPre & "DX0CR_DSEL") = 1
      End If
    
    Case Else
  End Select

End Sub


'*****************************************************************************
'Description:
'        This function
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetASCClkPins(r As ProjectData, ModuleName As String, RegName As String, ProtoName As String, PinNo As String)
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  
  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
  
  Select Case (ModuleName)
  
    Case ("U0C0")
      If (PinNo = "P2.5") Then
        r.v("P2_IOCR05_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1D_I")
        r.v(sRegPre & "DX1CR_DSEL") = 3
      ElseIf (PinNo = "P10.1") Then
        r.v("P10_IOCR01_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")
        r.v(sRegPre & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P10.2") Then
        r.v("P10_IOCR02_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")
        r.v(sRegPre & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P10.8") Then
        r.v("P10_IOCR08_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")
        r.v(sRegPre & "DX1CR_DSEL") = 2
      End If
      
    Case ("U0C1")
      If (PinNo = "P10.10") Then
        r.v("P10_IOCR10_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")
        r.v(sRegPre & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P10.5") Then
        r.v("P10_IOCR05_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")
        r.v(sRegPre & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P10.15") Then
        r.v("P10_IOCR15_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")
        r.v(sRegPre & "DX1CR_DSEL") = 2
      ElseIf (PinNo = "P2.8") Then
        r.v("P2_IOCR08_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1D_I")
        r.v(sRegPre & "DX1CR_DSEL") = 3
      ElseIf (PinNo = "P7.4") Then
        r.v("P7_IOCR04_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1E_I")
        r.v(sRegPre & "DX1CR_DSEL") = 4
      End If
      
    Case ("U1C0")
      If (PinNo = "P0.1") Then
        r.v("P0_IOCR01_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")
        r.v(sRegPre & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P0.2") Then
        r.v("P0_IOCR02_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")
        r.v(sRegPre & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P0.5") Then
        r.v("P0_IOCR05_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")
        r.v(sRegPre & "DX1CR_DSEL") = 2
      ElseIf (PinNo = "P10.11") Then
        r.v("P10_IOCR11_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1D_I")
        r.v(sRegPre & "DX1CR_DSEL") = 3
      ElseIf (PinNo = "P10.12") Then
        r.v("P10_IOCR12_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1E_I")
        r.v(sRegPre & "DX1CR_DSEL") = 4
      End If
    
    Case ("U1C1")
      If (PinNo = "P0.5") Then
        r.v("P0_IOCR05_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")
        r.v(sRegPre & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P0.6") Then
        r.v("P0_IOCR06_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")
        r.v(sRegPre & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P6.2") Then
        r.v("P6_IOCR02_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")
        r.v(sRegPre & "DX1CR_DSEL") = 2
      End If
      
    Case ("U2C0")
      If (PinNo = "P3.0") Then
        r.v("P3_IOCR00_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")
        r.v(sRegPre & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P3.2") Then
        r.v("P3_IOCR02_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")
        r.v(sRegPre & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P1.7") Then
        r.v("P1_IOCR07_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")
        r.v(sRegPre & "DX1CR_DSEL") = 2
      ElseIf (PinNo = "P9.7") Then
        r.v("P9_IOCR07_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1D_I")
        r.v(sRegPre & "DX1CR_DSEL") = 3
      End If
      
    Case ("U2C1")
      If (PinNo = "P3.5") Then
        r.v("P3_IOCR05_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1A_I")
        r.v(sRegPre & "DX1CR_DSEL") = 0
      ElseIf (PinNo = "P3.6") Then
        r.v("P3_IOCR06_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1B_I")
        r.v(sRegPre & "DX1CR_DSEL") = 1
      ElseIf (PinNo = "P1.2") Then
        r.v("P1_IOCR02_PC") = 0
        Call RequestAlternateInputPin(r, ModuleName & "_DX1C_I")
        r.v(sRegPre & "DX1CR_DSEL") = 2
      End If
      
    Case Else
  End Select
  
End Sub


'*****************************************************************************
'Description:
'        This function sets DX1 register for Half Duplex operation
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetASCHDDX1Reg(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
  
  Dim sRegPre As String
  Dim sVarPre As String

  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
    
  Select Case (PinNo)
    Case ("P10.1")
      r.v(sRegPre & "DX1CR_DSEL") = 0
    Case ("P10.15")
      r.v(sRegPre & "DX1CR_DSEL") = 2
    Case ("P0.1")
      r.v(sRegPre & "DX1CR_DSEL") = 0
    Case ("P10.12")
      r.v(sRegPre & "DX1CR_DSEL") = 4
    Case ("P0.6")
      r.v(sRegPre & "DX1CR_DSEL") = 1
    Case ("P3.0")
      r.v(sRegPre & "DX1CR_DSEL") = 0
    Case ("P3.6")
      r.v(sRegPre & "DX1CR_DSEL") = 1
  End Select
    
End Sub


'*****************************************************************************
'Description:
'        This function sets DX0 reg for Half Duplex-Internal Connection Type
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetASCHDDX0Reg(r As ProjectData, ModuleName As String, RegName As String, PinNo As String)
  On Error Resume Next
  
  Dim sRegPre As String
  Dim sVarPre As String

  sVarPre = ModuleName
  sRegPre = ModuleName & "_"
    
  Select Case (PinNo)
    Case ("P10.1")
      r.v(sRegPre & "DX0CR_DSEL") = 1
    Case ("P0.1")
      r.v(sRegPre & "DX0CR_DSEL") = 1
    Case ("P10.12")
      r.v(sRegPre & "DX0CR_DSEL") = 2
    Case ("P0.6")
      r.v(sRegPre & "DX0CR_DSEL") = 0
    Case ("P3.0")
      r.v(sRegPre & "DX0CR_DSEL") = 0
    Case ("P3.6")
      r.v(sRegPre & "DX0CR_DSEL") = 0
  End Select
    
End Sub


'*****************************************************************************
'Description:
'        This function releases the selected TxDpin for UxCy mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseASCTxDPin(r As ProjectData, ModuleName As Variant)
  On Error Resume Next
    
  Dim sVarPre As String
  Dim sRegPre As String
  Dim s As String
  Dim v As String
'  Dim sTxDPin As String
        
  sVarPre = ModuleName
  sRegPre = sVarPre & "_"

  Select Case (r.v(sVarPre & "_" & r.v(sVarPre & "_Proto") & "_cboTxD"))
    'U0C0
    Case ("P2.3")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
    Case ("P7.3") 'Repeated
      If (sVarPre = "U0C0") Then
        Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      
      ElseIf (sVarPre = "U0C1") Then
        Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
      End If
    Case ("P10.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
    Case ("P10.6")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
    
    'U0C1
    Case ("P2.9")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
    Case ("P2.10")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
    
'    Case ("P7.3") 'Repeated
'      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
    Case ("P7.4")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
    Case ("P10.0")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
    Case ("P10.7")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_6")
    Case ("P10.14")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_7")
    Case ("P10.15")
    If (sVarPre = "U0C1") Then
        Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_8")
    ElseIf (sVarPre = "U1C0") Then
        Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
    End If
      
    'U1C0
    Case ("P10.12")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
    Case ("P10.13")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
    
    Case ("P0.0")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
    Case ("P0.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      
    'U1C1
    Case ("P0.6")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
    Case ("P6.0")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
    Case ("P6.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
    
    Case ("P0.7")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
      
    'U2C0
    Case ("P1.6")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
    
    Case ("P3.0")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
    Case ("P3.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
    Case ("P9.4")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_4")
    Case ("P9.5")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_5")
    
    'U2C1
    Case ("P1.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_3")
    
    Case ("P3.6")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_1")
    Case ("P3.7")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DOUT_O_2")
    
    End Select

    r.v(sVarPre & "_" & r.v(sVarPre & "_Proto") & "_cboTxD") = "None"
    
End Sub


'*****************************************************************************
'Description:
'        This function releases the selected RxDpin for UxCy mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseASCRxDPin(r As ProjectData, ModuleName As Variant)
  On Error Resume Next
    
  Dim sVarPre As String
  Dim sRegPre As String
  Dim s As String
  Dim v As String
        
  sVarPre = ModuleName
  sRegPre = sVarPre & "_"
    
  Select Case (r.v(sVarPre & "_" & r.v(sVarPre & "_Proto") & "_cboRxD"))
    'U0C0
    Case ("P7.4")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0D_I")
    Case ("P10.0") 'Repeated
      If (sVarPre = "U0C0") Then
        Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
      
      ElseIf (sVarPre = "U0C1") Then
        Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
      End If
    Case ("P10.1")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")
    Case ("P10.6")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")
    Case ("P2.3")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0E_I")
    Case ("P2.4")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0F_I")
      
    'U0C1
    Case ("P10.7")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")
    Case ("P10.14")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")
    
'    Case ("P10.0") 'Repeated
'      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
    Case ("P2.10")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0E_I")
    Case ("P7.3")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0F_I")
      
    'U1C0
    Case ("P0.0")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
    Case ("P0.1")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")
    
    Case ("P10.12")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")
    Case ("P10.13")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0D_I")
      
    'U1C1
    Case ("P0.6")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
    Case ("P0.7")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")
    
    Case ("P6.0")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0E_I")
      
    'U2C0
    Case ("P1.5")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")
      
    Case ("P3.0")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
    Case ("P3.1")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")
    Case ("P1.6")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0D_I")
    Case ("P9.5")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0E_I")
    
    'U2C1
    Case ("P1.1")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0C_I")
    Case ("P1.2")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0D_I")
    
    Case ("P3.6")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0A_I")
    Case ("P3.7")
      Call ReleaseAlternateInputPin(r, ModuleName & "_DX0B_I")
      
  End Select
    
  r.v(sRegPre & "DX0CR_DSEL") = 0
  r.v(sVarPre & "_" & r.v(sVarPre & "_Proto") & "_cboRxD") = "None"
    
End Sub


'*****************************************************************************
'Description:
'        This function releases the selected ClkPin for UxCy mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseASCClkPin(r As ProjectData, ModuleName As Variant)
  On Error Resume Next
    
  Dim sVarPre As String
  Dim sRegPre As String
  Dim s As String
  Dim v As String
  Dim sClkPin As String
        
  sVarPre = ModuleName
  sRegPre = sVarPre & "_"
  
  Select Case (r.v(sVarPre & "_ASC_cboClk"))
    Case ("P10.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1A_I")
    Case ("P10.2")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1B_I")
    Case ("P10.8")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1C_I")
    Case ("P2.5")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1D_I")
    
    Case ("P10.10")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1A_I")
    Case ("P10.5")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1B_I")
    Case ("P10.15")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1C_I")
    Case ("P2.8")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1D_I")
    Case ("P7.4")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1E_I")
    
    Case ("P0.1")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1A_I")
    Case ("P0.2")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1B_I")
    Case ("P0.5")
     If (ModuleName = "U1C0") Then
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1C_I")
     ElseIf (ModuleName = "U1C1") Then
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1A_I")
    End If
    Case ("P10.11")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1D_I")
    Case ("P10.12")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1E_I")
      
    Case ("P0.6")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1B_I")
    Case ("P6.2")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1C_I")
      
    Case ("P3.0")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1A_I")
    Case ("P3.2")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1B_I")
    Case ("P1.7")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1C_I")
    Case ("P9.7")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1D_I")
      
    Case ("P3.5")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1A_I")
    Case ("P3.6")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1B_I")
    Case ("P1.2")
      Call ReleaseAlternateOutputPin(r, ModuleName & "_DX1C_I")
    
      
    End Select
    'Reset Pin (Vars)
    r.v(sVarPre & "_ASC_cboClk") = "None"
    
End Sub


'*****************************************************************************
'Description:
'        This function resets all Tx dependents of USIC-ASC.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ResetTxDpinAndDependents(r As ProjectData, vIndex As String)
  On Error Resume Next

  Dim sVarPre As String
  Dim sRegPre As String
  Dim sCCR   As String
  Dim sINPRL As String      'Interrupt Node Pointer Register L
'  Dim sINPRH As String      'Interrupt Node Pointer Register H
  
  sVarPre = vIndex
  sRegPre = vIndex & "_"
  sCCR = sRegPre & "CCR_"
  sINPRL = sRegPre & "INPRL_"
'  sINPRH = sRegPre & "INPRH_"
    
    '**************************************************************************
    'Release TxD pin
    '**************************************************************************
    Call ReleaseASCTxDPin(r, sVarPre)
    
    '**************************************************************************
    'General Page controls
    '**************************************************************************
    'Pulse length
    r.v(sVarPre & "_ASC_cboPl") = 0
    r.v(sRegPre & "PCRL_CTR13") = 0
    r.v(sRegPre & "PCRL_CTR14") = 0
    r.v(sRegPre & "PCRL_CTR15") = 0
    
    '**************************************************************************
    'Control Page controls
    '**************************************************************************
    'Tx Data Transfer Interrupts
    r.v(sRegPre & "CCR_TBIEN") = 0
    r.v(sRegPre & "CCR_TSIEN") = 0
    'Reset Tx Protocol Interrupts
    r.v(sRegPre & "PCRL_CTR4") = 0      '(Collision Detection)

    'DisableSRN (Tx) - Data Transfer Interrupts
    Call EnableOrDisableSRN(r, vIndex, sCCR & "TBIEN", sINPRL & "TBINP")
    Call EnableOrDisableSRN(r, vIndex, sCCR & "TSIEN", sINPRL & "TSINP")
    'DisableSRN (Tx) - Protocol Interrupts
    
    '**************************************************************************
    'Fifo Page controls
    '**************************************************************************
    r.sfr(sRegPre & "TBCTRL") = &H0
    r.sfr(sRegPre & "TBCTRH") = &H0
    
    '**************************************************************************
    'Function Page controls
    '**************************************************************************
    'General Functions
    r.v(sVarPre & "_USE_ASCSendData") = 0
    r.v(sVarPre & "_USE_ASCTxBufFree") = 0
    r.v(sVarPre & "_USE_ASCTxDataReady") = 0
    'Fifo Functions
    r.v(sVarPre & "_USE_ASCFillTxFIFO") = 0
    r.v(sVarPre & "_USE_ASCIsTxFIFObusy") = 0
    r.v(sVarPre & "_USE_ASCIsTxFIFOfull") = 0
    r.v(sVarPre & "_USE_ASCIsTxFIFOempty") = 0
    r.v(sVarPre & "_USE_ASCGetTxFIFOFillingLevel") = 0
    r.v(sVarPre & "_USE_ASCFlushTxFIFO") = 0
                    
End Sub


'*****************************************************************************
'Description:
'        This function resets all Rx dependents of USIC-ASC.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ResetRxDpinAndDependents(r As ProjectData, vIndex As String)
  On Error Resume Next

  Dim sVarPre As String
  Dim sRegPre As String
  Dim sCCR   As String
  Dim sINPRL As String      'Interrupt Node Pointer Register L
  Dim sINPRH As String      'Interrupt Node Pointer Register H
  
  sVarPre = vIndex
  sRegPre = vIndex & "_"
  sCCR = sRegPre & "CCR_"
  sINPRL = sRegPre & "INPRL_"
  sINPRH = sRegPre & "INPRH_"
               
    '**************************************************************************
    'Release RxD pin
    '**************************************************************************
    Call ReleaseASCRxDPin(r, sVarPre)
    
    '**************************************************************************
    'General Page controls
    '**************************************************************************
    'Sampling Point
    r.v(sVarPre & "_ASC_cboSp") = 7
    r.v(sRegPre & "PCRL_CTR8") = 1
    r.v(sRegPre & "PCRL_CTR9") = 1
    r.v(sRegPre & "PCRL_CTR10") = 1
    r.v(sRegPre & "PCRL_CTR11") = 0
    r.v(sRegPre & "PCRL_CTR12") = 0

    '**************************************************************************
    'Control Page controls
    '**************************************************************************
    'Rx Data Transfer Interrupts
    r.v(sRegPre & "CCR_AIEN") = 0
    r.v(sRegPre & "CCR_RIEN") = 0
    r.v(sRegPre & "CCR_RSIEN") = 0
    r.v(sRegPre & "CCR_DLIEN") = 0
    'Rx Protocol Interrupts
    r.v(sRegPre & "PCRL_CTR5") = 0      '(Rx Noise detection)
    r.v(sRegPre & "PCRL_CTR6") = 0      '(Format error)
        
    'DisableSRN (Rx) - Data Transfer Interrupts
    Call EnableOrDisableSRN(r, vIndex, sCCR & "AIEN", sINPRL & "AINP")
    Call EnableOrDisableSRN(r, vIndex, sCCR & "RIEN", sINPRL & "RINP")
    Call EnableOrDisableSRN(r, vIndex, sCCR & "RSIEN", sINPRL & "TBINP")
    Call EnableOrDisableSRN(r, vIndex, sCCR & "DLIEN", sINPRH & "PINP")
    'DisableSRN (Rx) - Protocol Interrupts
    
    '**************************************************************************
    'Fifo Page controls
    '**************************************************************************
    r.sfr(sRegPre & "RBCTRL") = &H0
    r.sfr(sRegPre & "RBCTRH") = &H0
    
    '**************************************************************************
    'Function Page controls
    '**************************************************************************
    'General Functions
    r.v(sVarPre & "_USE_ASCGetData") = 0
    r.v(sVarPre & "_USE_ASCRxDataReady") = 0
    'Fifo Functions
    r.v(sVarPre & "_USE_ASCGetRxFIFOData") = 0
    r.v(sVarPre & "_USE_ASCIsRxFIFObusy") = 0
    r.v(sVarPre & "_USE_ASCIsRxFIFOfull") = 0
    r.v(sVarPre & "_USE_ASCIsRxFIFOempty") = 0
    r.v(sVarPre & "_USE_ASCGetRxFIFOFillingLevel") = 0
    r.v(sVarPre & "_USE_ASCFlushRxFIFO") = 0
    
End Sub

'*****************************************************************************
'Description:
'        This function resets all Tx and Rx dependents of USIC-ASC.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ResetTxDpinRxDpinAndDependents(r As ProjectData, vIndex As String)
  On Error Resume Next

  Dim sVarPre As String
  Dim sRegPre As String
'  Dim sCCR   As String
'  Dim sINPRL As String      'Interrupt Node Pointer Register L
  Dim sINPRH As String      'Interrupt Node Pointer Register H
  
  sVarPre = vIndex
  sRegPre = vIndex & "_"
'  sCCR = sRegPre & "CCR_"
  sINPRH = sRegPre & "INPRH_"
    
    '**************************************************************************
    'TxD And RxD pins
    '**************************************************************************
    Call ResetTxDpinAndDependents(r, sVarPre)
    Call ResetRxDpinAndDependents(r, sVarPre)
    
    '**************************************************************************
    'General Page controls
    '**************************************************************************
'    'Half-Duplex external connection type
'    r.v(sVarPre & "_ASC_optHDCT") = 0
    'Parity
    r.v(sRegPre & "CCR_PM") = 0
    'StopBits
    r.v(sRegPre & "PCRL_CTR1") = 0
    'AB combination mode - Trigger is disabled
'    r.v(sRegPre & "DX1CR_CM") = 0
    'Irda Settings
    'Inverted shift data value
    r.v(sRegPre & "SCTRL_DOCFG") = 0
    'Data polartiy
    r.v(sRegPre & "DX0CR_DPOL") = 0
    
    '**************************************************************************
    'Control Page controls
    '**************************************************************************
    'Protocol Interrupts
    r.v(sRegPre & "PCRL_CTR6") = 0      '(Format error)
    r.v(sRegPre & "PCRL_CTR7") = 0      '(Frame finished)
    
    'Protocol Interrupt selection variable
    r.v(sVarPre & "_ASC_ProtoInt") = 0
    
    'DisableSRN (Tx) - Protocol Interrupts
    Call DisableSRN(r, sVarPre, sRegPre & r.v(sINPRH & "PINP") & "IC", "ASC" & r.v(sINPRH & "PINP") & "IC")
    
    '**************************************************************************
    'Fifo Page controls
    '**************************************************************************
    
    '**************************************************************************
    'Function Page controls
    '**************************************************************************
    'Initialisation Function
    r.v(sVarPre & "_USE_Init") = 0
    
    'Default settings
    r.v(sRegPre & "SCTRL_PDL") = 0
    r.v(sRegPre & "SCTRH_WLE") = 0
    r.v(sRegPre & "SCTRH_FLE") = 0
    r.v(sRegPre & "TCSRL_TDEN") = 0
    r.v(sRegPre & "TCSRL_TDSSM") = 0
    r.v(sRegPre & "PCRL_CTR0") = 0
    r.v(sRegPre & "PSR_TBIF") = 0
                    
End Sub


'*****************************************************************************
'Description:
'        This function checks if Rx dependencies can be enabled or not.
'        Operation Mode "0" is Full-Duplex Mode
'        Operation Mode "1" is Half-Duplex Mode
'        Operation Mode "2" is Loop Back Mode
'        Operation Mode "3" is AutoBaud Mode
'        Operation Mode "4" is IrDA Mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            not enough port pins selected
'        False           else
'*****************************************************************************
Function IsRxDependencyEnableOK(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim n As String
  Dim sRegSRN As String
  
  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  IsRxDependencyEnableOK = False
  
  If (r.v(sVarPre & "_ASC_OptOperMode") = 0) And (IsRxPinSet(r, vIndex)) Then
    IsRxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 1) And (r.v(sVarPre & "_ASC_optHDCT") = 0) And (IsRxPinSet(r, vIndex)) Then
    IsRxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 1) And (r.v(sVarPre & "_ASC_optHDCT") = 1) And (IsTxPinSet(r, vIndex)) Then
    IsRxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 2) Then
    IsRxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 4) And (IsRxPinSet(r, vIndex)) Then
    IsRxDependencyEnableOK = True
  Else
    IsRxDependencyEnableOK = False
  End If
    
End Function


'*****************************************************************************
'Description:
'        This function checks if Rx pin is configured or not.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            Rx pin is configured
'        False           else
'*****************************************************************************
Function IsRxPinSet(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  
  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  IsRxPinSet = False
  
  If (r.v(sVarPre & "_ASC_cboRxD") <> "None") Then
    IsRxPinSet = True
  End If
  
End Function


'*****************************************************************************
'Description:
'        This function checks if Tx dependencies can be enabled or not.
'        Operation Mode "0" is Full-Duplex Mode
'        Operation Mode "1" is Half-Duplex Mode
'        Operation Mode "2" is Loop Back Mode
'        Operation Mode "3" is AutoBaud Mode
'        Operation Mode "4" is IrDA Mode
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            not enough port pins selected
'        False           else
'*****************************************************************************
Function IsTxDependencyEnableOK(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim n As String
  Dim sRegSRN As String
  
  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  IsTxDependencyEnableOK = False
  
  If (r.v(sVarPre & "_ASC_OptOperMode") = 0) And (IsTxPinSet(r, vIndex)) Then
    IsTxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 1) And (r.v(sVarPre & "_ASC_optHDCT") = 0) And (IsTxPinSet(r, vIndex)) Then
    IsTxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 1) And (r.v(sVarPre & "_ASC_optHDCT") = 1) And (IsTxPinSet(r, vIndex)) Then
    IsTxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 2) Then
    IsTxDependencyEnableOK = True
  ElseIf (r.v(sVarPre & "_ASC_OptOperMode") = 4) And (IsTxPinSet(r, vIndex)) Then
    IsTxDependencyEnableOK = True
  Else
    IsTxDependencyEnableOK = False
  End If
    
End Function


'*****************************************************************************
'Description:
'        This function checks if Tx pin is configured or not.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            Tx pin is configured
'        False           else
'*****************************************************************************
Function IsTxPinSet(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  
  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  IsTxPinSet = False
  
  If (r.v(sVarPre & "_ASC_cboTxD") <> "None") Then
    IsTxPinSet = True
  End If
  
End Function


'*****************************************************************************
'Description:
'        This function checks if TBIEN selected and configured for glvl & ilvl.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            TBIEN is configured
'        False           else
'*****************************************************************************
Function IsTBIENIConfigured(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim n As String
  Dim sRegSRN As String
  
  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  IsTBIENIConfigured = False
  
  For i = 0 To 3
    n = r.v(sVarPre & "_Proto") & i & "IC"
    sRegSRN = sRegPre & i & "IC"
    If i = 3 Then sRegSRN = GetCC2SRN(sVarPre)
    
    If (IsISRSelected(r, sVarPre, sRegSRN, n)) Then
      If r.v(sRegPre & "CCR_TBIEN") = 1 And r.v(sRegPre & "INPRL_TBINP") = i Then   'TBI
        IsTBIENIConfigured = True
      End If
    End If
  Next i
    
  
End Function


'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            RIEN is configured
'        False           else
'*****************************************************************************
Function IsRIENIConfigured(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim n As String
  Dim sRegSRN As String
  
  sVarPre = Format$(vIndex)
  sRegPre = Format$(vIndex) & "_"
  
  IsRIENIConfigured = False
  
  For i = 0 To 3
    n = r.v(sVarPre & "_Proto") & i & "IC"
    sRegSRN = sRegPre & i & "IC"
    If i = 3 Then sRegSRN = GetCC2SRN(sVarPre)
    
    If (IsISRSelected(r, sVarPre, sRegSRN, n)) Then
      If r.v(sRegPre & "CCR_RIEN") = 1 And r.v(sRegPre & "INPRL_RINP") = i Then   'RIEN
        IsRIENIConfigured = True
      End If
    End If
  Next i
    
  
End Function

