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
'        ---------------------------------------------------------------------
'        1.0  JaiSankarVurimi & Raja            16.04.07        XC22xx v0.01
'
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFIFO(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageFIFO = False
  
  If (Not ps.AddPage("FIFO")) Then Exit Function

  OnLoadPageFIFO = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageFIFO(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFIFO = False
  
  If (Not ps.ExtenderCollection("FIFO").Loaded) And (Pagename = "FIFO") Then
      ps.ExtenderCollection("FIFO").Loaded = True

      '-------------------------------
      ' frame: frmTxFIFOCfg
      '-------------------------------
      If (Not ps.AddFrame("frmTxFIFOCfg", 100, 100, 4150, 1400, "Transmit FIFO Buffer Configuration")) Then Exit Function
          If (Not ps.Addlabel("lblTXFBSZ", 0, 200, 400, 3000, 400, "No. of FIFO buffer entries")) Then Exit Function
          If (Not ps.AddCombo("cboTXFBSZ", 2400, 350, 1000, 300)) Then Exit Function
          If (Not ps.Addlabel("lblTXDPTR", 0, 200, 850, 3000, 400, "Tx FIFO Data Pointer")) Then Exit Function
          If (Not ps.AddCombo("cboTXDPTR", 2400, 800, 1000, 300)) Then Exit Function

      '-------------------------------
      ' frame: frmRxFIFOCfg
      '-------------------------------
      If (Not ps.AddFrame("frmRxFIFOCfg", 4400, 100, 4200, 1400, "Receive FIFO Buffer Configuration")) Then Exit Function
          If (Not ps.Addlabel("lblRXFBSZ", 0, 200, 400, 3000, 400, "No. of FIFO buffer entries")) Then Exit Function
          If (Not ps.AddCombo("cboRXFBSZ", 2400, 350, 1000, 300)) Then Exit Function
          If (Not ps.Addlabel("lblRXDPTR", 0, 200, 850, 3000, 400, "Rx FIFO Data Pointer")) Then Exit Function
          If (Not ps.AddCombo("cboRXDPTR", 2400, 800, 1000, 300)) Then Exit Function

      '-------------------------------
      ' frame: frmTxFIFOINT
      '-------------------------------
      If (Not ps.AddFrame("frmTxFIFOINT", 100, 1600, 4150, 3500, "Transmit FIFO Interrupts Configuration")) Then Exit Function
          If (Not ps.Addlabel("lblTXLIMIT", 0, 200, 400, 3000, 400, "Limit for Interrupt Generation")) Then Exit Function
          If (Not ps.AddCombo("cboTXLIMIT", 2400, 350, 1000, 300)) Then Exit Function
          If (Not ps.AddCheck("chkTXLOF", 300, 700, 2450, 300, "Buffer Event on Limit Overflow")) Then Exit Function
          'Tx FIFO Interrupt controls
          If (Not ps.AddCheck("chkSTBIEN", 200, 1300, 1880, 300, "Standard Tx Buffer Int")) Then Exit Function
          If (Not ps.AddCheck("chkTBERIEN", 200, 1750, 1550, 300, "Tx Buffer Error Int")) Then Exit Function
          If (Not ps.AddCombo("cboSTBINP", 2400, 1300, 1500, 300)) Then Exit Function
          If (Not ps.AddCombo("cboATBINP", 2400, 1750, 1500, 300)) Then Exit Function
          
      '-------------------------------
      ' frame: frmRxFIFOINT
      '-------------------------------
      If (Not ps.AddFrame("frmRxFIFOINT", 4400, 1600, 4200, 3500, "Receive FIFO Interrupts Configuration")) Then Exit Function
          If (Not ps.Addlabel("lblRNM", 0, 200, 300, 3000, 400, "Receiver Notification Mode (RNM)")) Then Exit Function
          If (Not ps.AddOption("optRNM_0", 280, 600, 1600, 300, " Filling level mode")) Then Exit Function
          If (Not ps.AddOption("optRNM_1", 2400, 600, 1100, 300, " RCI mode")) Then Exit Function
          If (Not ps.Addlabel("lblRXLIMIT", 0, 200, 1200, 3000, 400, "Limit for Interrupt Generation")) Then Exit Function
          If (Not ps.AddCombo("cboRXLIMIT", 2400, 1150, 1000, 300)) Then Exit Function
          If (Not ps.AddCheck("chkRXLOF", 300, 1500, 2450, 300, "Buffer Event on Limit Overflow")) Then Exit Function
          'Rx FIFO Interrupt controls
          If (Not ps.AddCheck("chkSRBIEN", 200, 2100, 1880, 300, "Standard Rx Buffer Int")) Then Exit Function
          If (Not ps.AddCheck("chkARBIEN", 200, 2550, 1880, 300, "Alternate Rx Buffer Int")) Then Exit Function
          If (Not ps.AddCheck("chkRBERIEN", 200, 3000, 1580, 300, "Rx Buffer Error Int")) Then Exit Function
          If (Not ps.AddCombo("cboSRBINP", 2400, 2100, 1500, 300)) Then Exit Function
          If (Not ps.AddCombo("cboARBINP", 2400, 2550, 1500, 300)) Then Exit Function
          If (Not ps.AddCombo("cboRBERINP", 2400, 3000, 1500, 300)) Then Exit Function
          
  End If
  
  OnChangingPageFIFO = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFIFO(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFIFOError

  OnShowPageFIFO = False
  
  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim i           As Integer
  Dim j           As Integer
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim bDisabled   As Boolean
  Dim bDisabledT  As Boolean
  Dim bDisabledR  As Boolean
  Dim vIndex      As Variant
  Dim sDisabledToolTip   As String
  Dim sDisabledToolTipT  As String
  Dim sDisabledToolTipR  As String
  Dim sRBCTRH As String             'Receive Buffer Control Register
  Dim sTBCTRH As String             'Transmit Buffer Control Register
  
  vIndex = ps.Parameters.v("x")
  sVarPre = vIndex
  sRegPre = sVarPre & "_"
  sRBCTRH = sRegPre & "RBCTRH"
  sTBCTRH = sRegPre & "TBCTRH"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  If (Pagename = "FIFO") Then
    '-------------------------------------------------------------------------
    ' page: FIFO (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        
        '---------------------------------------------------------------------
        ' control: cboTXFBSZ (action)
        '---------------------------------------------------------------------
        Case "cboTXFBSZ"
            If v(1) = 0 Then
                r.v(sRegPre & "TBCTRH_SIZE") = 0
                r.sfr(sRegPre & "TBCTRL") = &H0
                r.sfr(sRegPre & "TBCTRH") = &H0
            Else
                For i = 1 To 6
                    If (v(1) = 2 ^ i) Then r.v(sRegPre & "TBCTRH_SIZE") = i
                Next i
                'initial dptr
                r.v(sRegPre & "TBCTRL_DPTR") = c("cboTXDPTR").List(0)
            End If
            
        '---------------------------------------------------------------------
        ' control: cboTXDPTR (action)
        '---------------------------------------------------------------------
        Case "cboTXDPTR"
            r.v(sRegPre & "TBCTRL_DPTR") = v(1)
        
        '---------------------------------------------------------------------
        ' control: cboTXLIMIT (action)
        '---------------------------------------------------------------------
        Case "cboTXLIMIT"
            r.v(sRegPre & "TBCTRL_LIMIT") = v(1)
            
        '---------------------------------------------------------------------
        ' control: chkTXLOF (action)
        '---------------------------------------------------------------------
        Case "chkTXLOF"
            r.v(sRegPre & "TBCTRH_LOF") = v(1)
            
        '---------------------------------------------------------------------
        ' control: cboRXFBSZ (action)
        '---------------------------------------------------------------------
        Case "cboRXFBSZ"
            If v(1) = 0 Then
                r.v(sRegPre & "RBCTRH_SIZE") = 0
                r.sfr(sRegPre & "RBCTRL") = &H0
                r.sfr(sRegPre & "RBCTRH") = &H0
            Else
                For i = 1 To 6
                    If (v(1) = 2 ^ i) Then r.v(sRegPre & "RBCTRH_SIZE") = i
                Next i
                'initial dptr
                r.v(sRegPre & "RBCTRL_DPTR") = c("cboRXDPTR").List(0)
            End If
        
        '---------------------------------------------------------------------
        ' control: cboRXDPTR (action)
        '---------------------------------------------------------------------
        Case "cboRXDPTR"
            r.v(sRegPre & "RBCTRL_DPTR") = v(1)
        
        '---------------------------------------------------------------------
        ' control: optRNM_0 (action)
        '---------------------------------------------------------------------
        Case "optRNM_0"
            r.v(sRegPre & "RBCTRH_RNM") = 0
            
        '---------------------------------------------------------------------
        ' control: optRNM_1 (action)
        '---------------------------------------------------------------------
        Case "optRNM_1"
            r.v(sRegPre & "RBCTRH_RNM") = 1
            
        '---------------------------------------------------------------------
        ' control: cboRXLIMIT (action)
        '---------------------------------------------------------------------
        Case "cboRXLIMIT"
            r.v(sRegPre & "RBCTRL_LIMIT") = v(1)
            
        '---------------------------------------------------------------------
        ' control: chkRXLOF (action)
        '---------------------------------------------------------------------
        Case "chkRXLOF"
            r.v(sRegPre & "RBCTRH_LOF") = v(1)
            
        '---------------------------------------------------------------------
        'FIFO Interrupts (action)
        '---------------------------------------------------------------------
        '---------------------------------------------------------------------
        ' control: chkSTBIEN (action)
        '---------------------------------------------------------------------
        Case "chkSTBIEN"
            r.v(sRegPre & "TBCTRH_STBIEN") = v(1)
            Call EnableOrDisableSRN(r, vIndex, sTBCTRH & "_STBIEN", sTBCTRH & "_STBINP")
            
        '---------------------------------------------------------------------
        ' control: cboSTBINP (action)
        '---------------------------------------------------------------------
        Case "cboSTBINP"
            Call SelectSRN(r, vIndex, c("cboSTBINP"), sTBCTRH & "_STBINP")
        
        '---------------------------------------------------------------------
        ' control: chkTBERIEN (action)
        '---------------------------------------------------------------------
        Case "chkTBERIEN"
            r.v(sRegPre & "TBCTRH_TBERIEN") = v(1)
            Call EnableOrDisableSRN(r, vIndex, sTBCTRH & "_TBERIEN", sTBCTRH & "_ATBINP")
            
        '---------------------------------------------------------------------
        ' control: cboATBINP (action)
        '---------------------------------------------------------------------
        Case "cboATBINP"
            Call SelectSRN(r, vIndex, c("cboATBINP"), sTBCTRH & "_ATBINP")
        
        '---------------------------------------------------------------------
        ' control: chkSRBIEN (action)
        '---------------------------------------------------------------------
        Case "chkSRBIEN"
            r.v(sRegPre & "RBCTRH_SRBIEN") = v(1)
            Call EnableOrDisableSRN(r, vIndex, sRBCTRH & "_SRBIEN", sRBCTRH & "_SRBINP")
            
        '---------------------------------------------------------------------
        ' control: cboSRBINP (action)
        '---------------------------------------------------------------------
        Case "cboSRBINP"
            Call SelectSRN(r, vIndex, c("cboSRBINP"), sRBCTRH & "_SRBINP")
            
        '---------------------------------------------------------------------
        ' control: chkARBIEN (action)
        '---------------------------------------------------------------------
        Case "chkARBIEN"
            r.v(sRegPre & "RBCTRH_ARBIEN") = v(1)
            Call EnableOrDisableSRN(r, vIndex, sRBCTRH & "_ARBIEN", sRBCTRH & "_ARBINP")
        
        '---------------------------------------------------------------------
        ' control: cboARBINP (action)
        '---------------------------------------------------------------------
        Case "cboARBINP"
            Call SelectSRN(r, vIndex, c("cboARBINP"), sRBCTRH & "_ARBINP")
            
        '---------------------------------------------------------------------
        ' control: chkRBERIEN (action)
        '---------------------------------------------------------------------
        Case "chkRBERIEN"
            r.v(sRegPre & "RBCTRH_RBERIEN") = v(1)
            Call EnableOrDisableSRN(r, vIndex, sRBCTRH & "_RBERIEN", sRBCTRH & "_ARBINP")
        
        '---------------------------------------------------------------------
        ' control: cboRBERINP (action)
        '---------------------------------------------------------------------
        Case "cboRBERINP"
            Call SelectSRN(r, vIndex, c("cboRBERINP"), sRBCTRH & "_ARBINP")
            
        Case Else
    End Select
        
    '-------------------------------------------------------------------------
    ' page: FIFO (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' bDisabled condition for the below controls
    '-------------------------------------------------------------------------
    Select Case (r.v(sVarPre & "_Proto"))
      Case ("ASC")
        bDisabled = r.v(sVarPre & "_Proto") <> "ASC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    (r.v(sVarPre & "_ASC_cboTxD") = "None")
      Case ("SSC")
        bDisabled = r.v(sVarPre & "_Proto") <> "SSC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    (r.v(sVarPre & "_SSC_cboTxD") = "None")
      Case ("IIC")
        bDisabled = r.v(sVarPre & "_Proto") <> "IIC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    Not IsPinInterfaceSelected(r, vIndex)
      Case ("IIS")
        bDisabled = r.v(sVarPre & "_Proto") <> "IIC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    (r.v(sVarPre & "_IIS_cboDOUT") = "None")
      Case Else
    End Select
                
    sDisabledToolTip = TOOLTIP_DISABLED_IF
    If r.v(sVarPre & "_Proto") = "None" Then
        sDisabledToolTip = sDisabledToolTip & _
        FormatDisabledToolTip("Protocol is not selected for " & sVarPre)
    End If
    If (r.v(sRegPre & "KSCFG_MODEN") = 0) Then
        sDisabledToolTip = sDisabledToolTip & _
        FormatDisabledToolTip("Module Clock is disabled")
    End If
    
    Select Case (r.v(sVarPre & "_Proto"))
      Case ("ASC")
        If (r.v(sVarPre & "_ASC_cboTxD") = "None") Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("TxD pin is not selected")
        End If
      Case ("SSC")
        If (r.v(sVarPre & "_SSC_cboTxD") = "None") Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("TxD pin is not selected")
        End If
      Case ("IIC")
        If (Not IsPinInterfaceSelected(r, vIndex)) Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("Pins are not selected")
        End If
      Case ("IIS")
        If (r.v(sVarPre & "_IIS_cboDOUT") = "None") Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("DOUT pin is not selected")
        End If
      Case Else
    End Select

    'TxFIFO controls -Disabled Tooltip
    sDisabledToolTipT = sDisabledToolTip
    If (r.v(sTBCTRH & "_SIZE") = 0) Then
        bDisabledT = bDisabled Or (r.v(sTBCTRH & "_SIZE") = 0)
        sDisabledToolTipT = sDisabledToolTipT & _
        FormatDisabledToolTip("Tx FIFO size not selected")
    End If
    'RxFIFO controls -Disabled Tooltip
    sDisabledToolTipR = sDisabledToolTip
    If (r.v(sRBCTRH & "_SIZE") = 0) Then
        bDisabledR = bDisabled Or (r.v(sRBCTRH & "_SIZE") = 0)
        sDisabledToolTipR = sDisabledToolTip & _
        FormatDisabledToolTip("Rx FIFO size not selected")
    End If
    
    '-------------------------------------------------------------------------
    ' control: cboTXFBSZ (show)
    '-------------------------------------------------------------------------
    With c("cboTXFBSZ")
        .Enabled = Not (bDisabled)
        Call GetFIFOsize(r, sVarPre, c("cboTXFBSZ"), sRegPre & "T")
    End With
    
    With e("cboTXFBSZ")
       If (bDisabled) Then
          .DisabledToolTipText = sDisabledToolTip
       End If
    End With
    
    'lblTXFBSZ
    c("lblTXFBSZ").Enabled = Not (bDisabled)

    '-------------------------------------------------------------------------
    ' control: cboTXDPTR (show)
    '-------------------------------------------------------------------------
    With c("cboTXDPTR")
        .Enabled = Not (bDisabledT)
        Call GetFIFOdptr(r, sVarPre, c("cboTXDPTR"), sRegPre & "T")
    End With
    
    With e("cboTXDPTR")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
    End With

    'lblTXDPTR
    c("lblTXDPTR").Enabled = Not (bDisabledT)
    
    '-------------------------------------------------------------------------
    ' control: cboTXLIMIT (show)
    '-------------------------------------------------------------------------
    With c("cboTXLIMIT")
        .Enabled = Not (bDisabledT)
        .Clear
If (r.v(sRegPre & "TBCTRH_SIZE")) Then
        For i = 0 To (2 ^ r.v(sRegPre & "TBCTRH_SIZE")) - 1
          .AddItem i
        Next i
        .ListIndex = r.v(sRegPre & "TBCTRL_LIMIT") '- 1
End If
    End With

    With e("cboTXLIMIT")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
    End With
    
    'lblTXLIMIT
    c("lblTXLIMIT").Enabled = Not (bDisabledT)
    
    '-------------------------------------------------------------------------
    ' control: chkTXLOF (show)
    '-------------------------------------------------------------------------
    With c("chkTXLOF")
        .Enabled = Not (bDisabledT)
        .Value = -CInt(r.v(sTBCTRH & "_LOF") = 1)
    End With
    
    With e("chkTXLOF")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
    End With
    
    '-------------------------------------------------------------------------
    'Tx FIFO Interrupts (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' control: chkSTBIEN (show)
    '-------------------------------------------------------------------------
    With c("chkSTBIEN")
        .Enabled = Not (bDisabledT)
        .Value = -CInt(r.v(sTBCTRH & "_STBIEN") = 1)
    End With
    
    With e("chkSTBIEN")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboSTBINP (Show)
    '-------------------------------------------------------------------------
    With c("cboSTBINP")
        .Enabled = (Not bDisabledT) And (r.v(sTBCTRH & "_STBIEN") = 1)
        .ListIndex = AddINTnodes(r, sVarPre, c("cboSTBINP"), "TBCTRH_STBINP")
    End With
    
    With e("cboSTBINP")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
       If (r.v(sTBCTRH & "_STBIEN") = 0) Then
          .DisabledToolTipText = sDisabledToolTipT & _
          FormatDisabledToolTip("Standard Tx Buffer interrupt not enabled")
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: chkTBERIEN (show)
    '-------------------------------------------------------------------------
    With c("chkTBERIEN")
        .Enabled = Not (bDisabledT)
        .Value = -CInt(r.v(sTBCTRH & "_TBERIEN") = 1)
    End With
    
    With e("chkTBERIEN")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboATBINP (Show)
    '-------------------------------------------------------------------------
    With c("cboATBINP")
        .Enabled = (Not bDisabledT) And (r.v(sTBCTRH & "_TBERIEN") = 1)
        .ListIndex = AddINTnodes(r, sVarPre, c("cboATBINP"), "TBCTRH_ATBINP")
    End With
    
    With e("cboATBINP")
       If (bDisabledT) Then
          .DisabledToolTipText = sDisabledToolTipT
       End If
       If (r.v(sTBCTRH & "_TBERIEN") = 0) Then
          .DisabledToolTipText = sDisabledToolTipT & _
          FormatDisabledToolTip("Tx Buffer Error interrupt not enabled")
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' bDisabled condition for the below controls
    '-------------------------------------------------------------------------
    Select Case (r.v(sVarPre & "_Proto"))
      Case ("ASC")
        bDisabled = r.v(sVarPre & "_Proto") <> "ASC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    (r.v(sVarPre & "_ASC_cboRxD") = "None")
      Case ("SSC")
        bDisabled = r.v(sVarPre & "_Proto") <> "SSC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    (r.v(sVarPre & "_SSC_cboRxD") = "None")
      Case ("IIC")
        bDisabled = r.v(sVarPre & "_Proto") <> "IIC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    Not IsPinInterfaceSelected(r, vIndex)
      Case ("IIS")
        bDisabled = r.v(sVarPre & "_Proto") <> "IIC" Or _
                    r.v(sRegPre & "KSCFG_MODEN") = 0 Or _
                    (r.v(sVarPre & "_IIS_cboDIN") = "None")
      Case Else
    End Select
                
    sDisabledToolTip = TOOLTIP_DISABLED_IF
    If r.v(sVarPre & "_Proto") = "None" Then
        sDisabledToolTip = sDisabledToolTip & _
        FormatDisabledToolTip("Protocol is not selected for " & sVarPre)
    End If
    If (r.v(sRegPre & "KSCFG_MODEN") = 0) Then
        sDisabledToolTip = sDisabledToolTip & _
        FormatDisabledToolTip("Module Clock is disabled")
    End If
    
    Select Case (r.v(sVarPre & "_Proto"))
      Case ("ASC")
        If (r.v(sVarPre & "_ASC_cboRxD") = "None") Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("RxD pin is not selected")
        End If
      Case ("SSC")
        If (r.v(sVarPre & "_SSC_cboRxD") = "None") Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("RxD pin is not selected")
        End If
      Case ("IIC")
        If (Not IsPinInterfaceSelected(r, vIndex)) Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("Pins are not selected")
        End If
      Case ("IIS")
        If (r.v(sVarPre & "_IIS_cboDIN") = "None") Then
          sDisabledToolTip = sDisabledToolTip & _
          FormatDisabledToolTip("DIN pin is not selected")
        End If
      Case Else
    End Select
    
    'TxFIFO controls -Disabled Tooltip
    sDisabledToolTipT = sDisabledToolTip
    If (r.v(sTBCTRH & "_SIZE") = 0) Then
        bDisabledT = bDisabled Or (r.v(sTBCTRH & "_SIZE") = 0)
        sDisabledToolTipT = sDisabledToolTipT & _
        FormatDisabledToolTip("Tx FIFO size not selected")
    End If
    'RxFIFO controls -Disabled Tooltip
    sDisabledToolTipR = sDisabledToolTip
    If (r.v(sRBCTRH & "_SIZE") = 0) Then
        bDisabledR = bDisabled Or (r.v(sRBCTRH & "_SIZE") = 0)
        sDisabledToolTipR = sDisabledToolTip & _
        FormatDisabledToolTip("Rx FIFO size not selected")
    End If
    
    '-------------------------------------------------------------------------
    ' control: cboRXFBSZ (show)
    '-------------------------------------------------------------------------
    With c("cboRXFBSZ")
        .Enabled = Not (bDisabled)
        Call GetFIFOsize(r, sVarPre, c("cboRXFBSZ"), sRegPre & "R")
    End With
    
    With e("cboRXFBSZ")
       If (bDisabled) Then
          .DisabledToolTipText = sDisabledToolTip
       End If
    End With
    
    'lblRXFBSZ
    c("lblRXFBSZ").Enabled = Not (bDisabled)
    
    '-------------------------------------------------------------------------
    ' control: cboRXDPTR (show)
    '-------------------------------------------------------------------------
    With c("cboRXDPTR")
        .Enabled = Not (bDisabledR)
        Call GetFIFOdptr(r, sVarPre, c("cboRXDPTR"), sRegPre & "R")
    End With
    
    With e("cboRXDPTR")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
    End With
    
    'lblRXDPTR
    c("lblRXDPTR").Enabled = Not (bDisabledR)
    'lblRNM
    c("lblRNM").Enabled = Not (bDisabledR)
    
    '-------------------------------------------------------------------------
    ' control: optRNM_0 (show)
    '-------------------------------------------------------------------------
    With c("optRNM_0")
        .Enabled = Not (bDisabledR)
        .Value = -CInt(r.v(sRBCTRH & "_RNM") = 0)
    End With
    
    With e("optRNM_0")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: optRNM_1 (show)
    '-------------------------------------------------------------------------
    With c("optRNM_1")
        .Enabled = Not (bDisabledR)
        .Value = -CInt(r.v(sRBCTRH & "_RNM") = 1)
    End With
    
    With e("optRNM_1")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: cboRXLIMIT (show)
    '-------------------------------------------------------------------------
    With c("cboRXLIMIT")
        .Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_RNM") = 0)
        .Clear
        
If (r.v(sRegPre & "RBCTRH_SIZE")) Then
        For i = 0 To (2 ^ r.v(sRegPre & "RBCTRH_SIZE")) - 1
          .AddItem i
        Next i
        .ListIndex = r.v(sRegPre & "RBCTRL_LIMIT") '- 1
End If
    End With

    With e("cboRXLIMIT")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
       If (r.v(sRBCTRH & "_RNM") = 1) Then
          .DisabledToolTipText = sDisabledToolTipR & _
          FormatDisabledToolTip("Limit is not used in RCI mode")
       End If
    End With
    
    'lblRXLIMIT
    c("lblRXLIMIT").Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_RNM") = 0)
    
    '-------------------------------------------------------------------------
    ' control: chkRXLOF (show)
    '-------------------------------------------------------------------------
    With c("chkRXLOF")
        .Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_RNM") = 0)
        .Value = -CInt(r.v(sRBCTRH & "_LOF") = 1)
    End With
    
    With e("chkRXLOF")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
       If (r.v(sRBCTRH & "_RNM") = 1) Then
          .DisabledToolTipText = sDisabledToolTipR & _
          FormatDisabledToolTip("Limit Overflow is not used in RCI mode")
       End If
    End With
    
    '-------------------------------------------------------------------------
    'Rx FIFO Interrupts (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' control: chkSRBIEN (show)
    '-------------------------------------------------------------------------
    With c("chkSRBIEN")
        .Enabled = Not (bDisabledR)
        .Value = -CInt(r.v(sRBCTRH & "_SRBIEN") = 1)
    End With
    
    With e("chkSRBIEN")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: cboSRBINP (Show)
    '-------------------------------------------------------------------------
    With c("cboSRBINP")
        .Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_SRBIEN") = 1)
        .ListIndex = AddINTnodes(r, sVarPre, c("cboSRBINP"), "RBCTRH_SRBINP")
    End With
    
    With e("cboSRBINP")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
       If (r.v(sRBCTRH & "_SRBIEN") = 0) Then
          .DisabledToolTipText = sDisabledToolTipR & _
          FormatDisabledToolTip("Standard Rx Buffer interrupt not enabled")
       End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkARBIEN (show)
    '-------------------------------------------------------------------------
    With c("chkARBIEN")
        .Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_RNM") = 1)
        .Value = -CInt(r.v(sRBCTRH & "_ARBIEN") = 1)
    End With
    
    With e("chkARBIEN")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
       If (r.v(sRBCTRH & "_RNM") = 0) Then
          .DisabledToolTipText = sDisabledToolTipR & _
          FormatDisabledToolTip("Alternate Rx Buffer int not used in filling level mode")
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: cboARBINP (Show)
    '-------------------------------------------------------------------------
    With c("cboARBINP")
        .Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_ARBIEN") = 1)
        .ListIndex = AddINTnodes(r, sVarPre, c("cboARBINP"), "RBCTRH_ARBINP")
    End With
    
    With e("cboARBINP")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
       If (r.v(sRBCTRH & "_ARBIEN") = 0) Then
          .DisabledToolTipText = sDisabledToolTipR & _
          FormatDisabledToolTip("Alternate Rx Buffer interrupt not enabled")
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: chkRBERIEN (show)
    '-------------------------------------------------------------------------
    With c("chkRBERIEN")
        .Enabled = Not (bDisabledR)
        .Value = -CInt(r.v(sRBCTRH & "_RBERIEN") = 1)
    End With
    
    With e("chkRBERIEN")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: cboRBERINP (Show)
    '-------------------------------------------------------------------------
    With c("cboRBERINP")
        .Enabled = (Not bDisabledR) And (r.v(sRBCTRH & "_RBERIEN") = 1)
        .ListIndex = AddINTnodes(r, sVarPre, c("cboRBERINP"), "RBCTRH_ARBINP")
    End With
    
    With e("cboRBERINP")
       If (bDisabledR) Then
          .DisabledToolTipText = sDisabledToolTipR
       End If
       If (r.v(sRBCTRH & "_RBERIEN") = 0) Then
          .DisabledToolTipText = sDisabledToolTipR & _
          FormatDisabledToolTip("Rx Buffer Error interrupt not enabled")
       End If
    End With
    
  End If
  
  OnShowPageFIFO = True
  Exit Function

OnShowPageFIFOError:
  ErrorBox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'          This function provides possible FIFO sizes that can be used.
'          calculates the free block sizes and decides the possible Max FIFO.
'-----------------------------------------------------------------------------
'        r               reference to the ProjectData object
'        vIndex          USIC channel no# UxCy,  x=0-2,y=0-1
'        cboCrtl         combo control of the interrupt (list of Sizes)
'        sFIFOtype       Transmit/Receive FIFO
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub GetFIFOsize(r As ProjectData, vIndex As Variant, cboCrtl As Variant, sFIFOtype As String)
  On Error Resume Next

  Dim i        As Integer
  Dim j        As Integer
  Dim iBuf     As Integer
  Dim iTemp    As Integer
  Dim iMaxBuf  As Integer
  Dim iDptrUB  As Integer
  Dim sUxCyCh  As String
  Dim iDptr(3) As Integer
  Dim iSize(3) As Integer
  Dim sBCTR(3) As String
  
  If InStr(vIndex, "U0") Then sUxCyCh = "U0"
  If InStr(vIndex, "U1") Then sUxCyCh = "U1"
  If InStr(vIndex, "U2") Then sUxCyCh = "U2"
  
  sBCTR(0) = sUxCyCh & "C0" & "_TBCTR"
  sBCTR(1) = sUxCyCh & "C0" & "_RBCTR"
  sBCTR(2) = sUxCyCh & "C1" & "_TBCTR"
  sBCTR(3) = sUxCyCh & "C1" & "_RBCTR"
  
  iDptrUB = 0
  For j = 0 To 3
    iDptr(j) = 0
    iSize(j) = 0
  Next j
  
  For j = 0 To 3
    If InStr(sBCTR(j), sFIFOtype) Then              'current FIFO
    Else
        If r.v(sBCTR(j) & "H_SIZE") Then            'existing FIFO if size > 0
            iDptr(iDptrUB) = r.v(sBCTR(j) & "L_DPTR")
            iSize(iDptrUB) = r.v(sBCTR(j) & "H_SIZE")
            iDptrUB = iDptrUB + 1
        End If
    End If
  Next j
  
  cboCrtl.Clear
  cboCrtl.AddItem 0
  
  If iDptrUB Then
    For i = 0 To iDptrUB - 1
      For j = i + 1 To iDptrUB - 1
          If (iDptr(i) > iDptr(j)) Then
              iTemp = iDptr(i)          'data pointers ascending order
              iDptr(i) = iDptr(j)
              iDptr(j) = iTemp
              iTemp = iSize(i)          'size to have same index as iDptr
              iSize(i) = iSize(j)
              iSize(j) = iTemp
          End If
      Next j
    Next i

    iBuf = 0
    iMaxBuf = 0                         'Max size available for a FIFO
    If iDptrUB = 1 Then
        iMaxBuf = 64 - (2 ^ iSize(0))
    Else
        For j = 0 To iDptrUB - 1
            iBuf = iDptr(j + 1) - (iDptr(j) + (2 ^ iSize(j)))
            If (iMaxBuf < iBuf) Then iMaxBuf = iBuf
        Next j
        iBuf = 64 - (iDptr(iDptrUB - 1) + (2 ^ iSize(iDptrUB - 1))) 'Chk the rest
        If (iMaxBuf < iBuf) Then iMaxBuf = iBuf
    End If
    For i = 1 To 6                      'list available FIFO sizes
        If ((2 ^ i) <= iMaxBuf) Or _
           ((2 ^ i) <= (2 ^ r.v(sFIFOtype & "BCTRH_SIZE"))) Then cboCrtl.AddItem (2 ^ i)
    Next i
  Else
    For i = 1 To 6
      cboCrtl.AddItem (2 ^ i)
    Next i
  End If
  
  cboCrtl.ListIndex = r.v(sFIFOtype & "BCTRH_SIZE")

End Sub


'*****************************************************************************
'Description:
'          This function provides possible FIFO start buffer no# that can be used.
'          calculates depends on the size and available free blocks.
'-----------------------------------------------------------------------------
'        r               reference to the ProjectData object
'        vIndex          USIC channel no# UxCy,  x=0-2,y=0-1
'        cboCrtl         combo control of the interrupt (list of dptr)
'        sFIFOtype       Transmit/Receive FIFO
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub GetFIFOdptr(r As ProjectData, vIndex As Variant, cboCrtl As Variant, sFIFOtype As String)
  On Error Resume Next

  Dim i As Integer
  Dim j As Integer
  Dim iDptr As Integer
  Dim sUxCyCh As String
  Dim sBCTR(3) As String
  Dim bDptr(3) As Boolean
  
  If InStr(vIndex, "U0") Then sUxCyCh = "U0"
  If InStr(vIndex, "U1") Then sUxCyCh = "U1"
  If InStr(vIndex, "U2") Then sUxCyCh = "U2"
  
  sBCTR(0) = sUxCyCh & "C0" & "_TBCTR"
  sBCTR(1) = sUxCyCh & "C0" & "_RBCTR"
  sBCTR(2) = sUxCyCh & "C1" & "_TBCTR"
  sBCTR(3) = sUxCyCh & "C1" & "_RBCTR"
  
  For i = 0 To 3
      bDptr(i) = False
  Next i
  cboCrtl.Clear

    For i = 0 To 62 Step (2 ^ r.v(sFIFOtype & "BCTRH_SIZE"))        'Dptr -> O(size of the FIFO)
        iDptr = i
        For j = 0 To 3
          If InStr(sBCTR(j), sFIFOtype) Then              'current FIFO
              bDptr(j) = True
          Else
              If r.v(sBCTR(j) & "H_SIZE") Then            'existing FIFO if size > 0
                bDptr(j) = (iDptr < r.v(sBCTR(j) & "L_DPTR")) Or (iDptr > ((r.v(sBCTR(j) & "L_DPTR") + (2 ^ r.v(sBCTR(j) & "H_SIZE")) - 1)))
              Else                                        'if no other FIFO
                bDptr(j) = True
              End If
          End If
        Next j                                              'if the FIFO can fit @ this DPTR
        If bDptr(0) And bDptr(1) And bDptr(2) And bDptr(3) Then
            cboCrtl.AddItem iDptr
        End If
    Next i
    
    For i = 0 To cboCrtl.ListCount - 1                      'List index
      If (cboCrtl.List(i) = r.v(sFIFOtype & "BCTRL_DPTR")) Then
        cboCrtl.ListIndex = i
      End If
    Next i

End Sub

