Attribute VB_Name = "Module1"
'#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:
'        CAN
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CAN'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0  ste            04.04.00    final version for TC1775A
'        1.1  ste            20.07.00    the TC1775B has a new clock divider for
'                                        each node;
'                                        the frame counter can be incremenzed by
'                                        additional events (new bitfield for modes);
'                                        error warning threshold added;
'
'        ---------------------------------------------------------------------
'        3.0  ahe            05.11.01    final version for Pegasus
'
'        3.1  ahe            02.07.02    changed text "The counter work" to
'                                                     "The counter works"
'
'        ---------------------------------------------------------------------
'        4.0                 26.08.04    final version for XC164CM Pegasus light
'*****************************************************************************

Const TOOLTIP_DISABLED_NOTE = "the node initialization is not selected"

Const sSP_Graphic = " *****************************  Bit Timing Definition  ********************************" & vbCrLf & _
                    "" & vbCrLf & _
                    " |<----------------------------------------------- 1 bit time ------------------------------------------------>|" & vbCrLf & _
                    " |                                                                                                                   |" & vbCrLf & _
                    " |  Sync-   |                     TSeg1                  ||                  TSeg2                     |" & vbCrLf & _
                    " |   Seg     |                                                  ||                                                 |" & vbCrLf & _
                    " |--------------|------------|------------|------------|------------||-----------|------------|------------|------------|" & vbCrLf & _
                    "                            |            |                         ||                                 " & vbCrLf & _
                    "                            |<-------->|                         ||                                 " & vbCrLf & _
                    "                      1 time quantum           sample point                            " & vbCrLf & _
                    "                                 (tq)                                                                       " & vbCrLf & _
                    "" & vbCrLf


Const sSamplePoint = "The importance of the sample point is explained in the users manual!"



'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: OnLoadPagePinSelection
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePinSelection(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Baudrate
    '-------------------------------------------------------------------------
    If (Not OnLoadPageBaudrate(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: FrameCounter
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFrameCounter(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' End of pages
    '-------------------------------------------------------------------------
    
    ' call function to initialize the menu
    If (Not InitMenu(ps, "CAN\Nodex")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError

    Dim vIndex As Variant
    Dim sVarPre As String

    vIndex = ps.Parameters.v("x")
    sVarPre = "CAN" & vIndex

    OnChangingPage = False

    '-------------------------------------------------------------------------
    'page: OnChangingPagePinSelection
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePinSelection(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Control
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Baudrate
    '-------------------------------------------------------------------------
    If (Not OnChangingPageBaudrate(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: FrameCounter
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFrameCounter(ps, Pagename)) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError

    Dim vIndex As Variant
    Dim sVarPre As String

    vIndex = ps.Parameters.v("x")
    sVarPre = "CAN" & vIndex

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: OnShowPagePinSelection
    '-------------------------------------------------------------------------
    If (Not OnShowPagePinSelection(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Baudrate
    '-------------------------------------------------------------------------
    If (Not OnShowPageBaudrate(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: FrameCounter
    '-------------------------------------------------------------------------
    If (Not OnShowPageFrameCounter(ps, Controlname, Pagename, v)) Then Exit Function

    OnShow = True
    Exit Function

OnShowError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    Dim np As Peripherals


    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not process the click", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "CAN\Nodex")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function


'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

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

  OnLoadPagePinSelection = False

  If (Not ps.AddPage("Pin Selection")) Then Exit Function

  OnLoadPagePinSelection = 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 OnChangingPagePinSelection(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim r       As ProjectData
  Dim sChr    As String
  Dim vIndex  As Variant
  Dim sVarPre As String
  Dim s       As String
  Dim s2      As String
  Dim i       As Integer
  Dim iPin    As Integer


  vIndex = ps.Parameters.v("x")
  sVarPre = "CAN" & vIndex
  sChr = ps.Parameters.v("Number")

  Set r = ps.ProjectData

  OnChangingPagePinSelection = False
  
  If (Not ps.ExtenderCollection("Pin Selection").Loaded) And (Pagename = "Pin Selection") Then
    ps.ExtenderCollection("Pin Selection").Loaded = True
  

    '-------------------------------
    ' frame: frmRX
    '-------------------------------
    If (Not ps.AddFrame("frmRX", 100, 100, 4150, 2400, "Receive Input Selection")) Then Exit Function
        If (Not ps.AddOption("optRX_NoPin", 200, 300, 3000, 400, "Disable receive input pin")) Then Exit Function
        i = 0
        For iPin = 0 To 3
            If (r.Exist("MuxFor_CAN_RxD" & sChr & "_" & iPin)) Then
                If (Not ps.AddOption("optRIS_" & iPin, 200, 300 + (i + 1) * 400, 3000, 400, _
                  "Select for input RXDC" & sChr & " pin " & GetPinName("CAN_RxD" & sChr & "_" & iPin))) Then Exit Function
                i = i + 1
            End If
        Next iPin

    '-------------------------------
    ' frame: frmTX
    '-------------------------------
    If (Not ps.AddFrame("frmTX", 4400, 100, 4150, 2400, "Transmit Output Selection")) Then Exit Function
        If (Not ps.AddOption("optTX_NoPin", 200, 300, 3000, 400, "Disable transmit output pin")) Then Exit Function
        i = 0
        For iPin = 0 To 2
            If (r.Exist("MuxFor_CAN_TxD" & sChr & "_" & iPin)) Then
                If (Not ps.AddOption("optTX_" & iPin, 200, 300 + (i + 1) * 400, 3000, 400, _
                  "Select for output TXDC" & sChr & " pin " & GetPinName("CAN_TxD" & sChr & "_" & iPin))) Then Exit Function
                i = i + 1
            End If
        Next iPin

  End If
  OnChangingPagePinSelection = 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 OnShowPagePinSelection(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPagePinSelectionError

  OnShowPagePinSelection = False

  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim bDisabled   As Boolean
  Dim vIndex      As Variant
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim d           As String
  Dim s           As String
  Dim s2          As String
  Dim sChr        As String
  Dim i           As Integer
  Dim iPin        As Integer
  Dim iNr         As Integer
  Dim bFirstTime  As Boolean

  vIndex = ps.Parameters.v("x")
  sChr = ps.Parameters.v("Number")
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Pin Selection") Then
    '-------------------------------------------------------------------------
    ' page: PinSelection (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optNoPin (action)
        '---------------------------------------------------------------------
        Case "optRX_NoPin"
            If (r.v(sRegPre & sChr & "CR_INIT") = 0) Then
                d = "All message objects which are connected to node " & sChr & " will be disabled . " & vbCrLf & _
                    "Also all message objects which are configured for gateway mode. " & vbCrLf & _
                    "Do you really want to continue ?"
                If (Ask(d)) Then
                    Call SelectPinInterface(r, vIndex, sChr, "Rx", 7)
                    Call DisableNodex(r, vIndex, sChr)
                End If
            Else
                Call SelectPinInterface(r, vIndex, sChr, "Rx", 7)
            End If

        '---------------------------------------------------------------------
        ' control: optRIS_0 (action)
        '---------------------------------------------------------------------
        Case "optRIS_0"
            Call SelectPinInterface(r, vIndex, sChr, "Rx", 0)

        '---------------------------------------------------------------------
        ' control: optRIS_1 (action)
        '---------------------------------------------------------------------
        Case "optRIS_1"
            Call SelectPinInterface(r, vIndex, sChr, "Rx", 1)

        '---------------------------------------------------------------------
        ' control: optRIS_2 (action)
        '---------------------------------------------------------------------
        Case "optRIS_2"
            Call SelectPinInterface(r, vIndex, sChr, "Rx", 2)

        '---------------------------------------------------------------------
        ' control: optRIS_3 (action)
        '---------------------------------------------------------------------
        Case "optRIS_3"
            Call SelectPinInterface(r, vIndex, sChr, "Rx", 3)

        '---------------------------------------------------------------------
        ' control: optTX_0 (action)
        '---------------------------------------------------------------------
        Case "optTX_NoPin"
            If (r.v(sRegPre & sChr & "CR_INIT") = 0) Then
                d = "All message objects which are connected to node " & sChr & " will be disabled . " & vbCrLf & _
                    "Also all message objects which are configured for gateway mode. " & vbCrLf & _
                    "Do you really want to continue ?"
                If (Ask(d)) Then
                    Call SelectPinInterface(r, vIndex, sChr, "Tx", 7)
                    Call DisableNodex(r, vIndex, sChr)
                End If
            Else
                Call SelectPinInterface(r, vIndex, sChr, "Tx", 7)
            End If

        '---------------------------------------------------------------------
        ' control: optTX_1 (action)
        '---------------------------------------------------------------------
        Case "optTX_0"
            Call SelectPinInterface(r, vIndex, sChr, "Tx", 0)

        '---------------------------------------------------------------------
        ' control: optTX_2 (action)
        '---------------------------------------------------------------------
        Case "optTX_1"
            Call SelectPinInterface(r, vIndex, sChr, "Tx", 1)

        '---------------------------------------------------------------------
        ' control: optTX_3 (action)
        '---------------------------------------------------------------------
        Case "optTX_2"
            Call SelectPinInterface(r, vIndex, sChr, "Tx", 2)

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: PinSelection (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optNoPin (show)
    '-------------------------------------------------------------------------
    With c("optRX_NoPin")
        bDisabled = IsModuleClockDisabled(r, vIndex)
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sVarPre & "_Use_Rx" & sChr) = 7)
    End With

    With e("optRX_NoPin")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                    GetTooltipModuleClockDisabled(r, vIndex)
            End If
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optRIS_0 .. 3 (show)
    '-------------------------------------------------------------------------
    For iPin = 0 To 3
        s = sVarPre & "_RxD" & sChr & "_" & iPin
        If (r.Exist("MuxFor_" & s)) Then
            '-------------------------------------------------------------------------
            ' control: optRIS_x (show)
            '-------------------------------------------------------------------------
            With c("optRIS_" & iPin)
                bDisabled = IsModuleClockDisabled(r, vIndex) Or _
                            Not (IsAlternateInputPinFree(r, s))
                .Enabled = Not (bDisabled)
                .Value = -CInt(r.v(sVarPre & "_Use_Rx" & sChr) = iPin)
            End With

            With e("optRIS_" & iPin)
                If (bDisabled) Then
                    .DisabledTooltipText = TOOLTIP_DISABLED_IF
                    If (IsModuleClockDisabled(r, vIndex)) Then
                        .DisabledTooltipText = .DisabledTooltipText & _
                            GetTooltipModuleClockDisabled(r, vIndex)
                    End If
                    If (Not (IsAlternateInputPinFree(r, s))) Then
                        .DisabledTooltipText = .DisabledTooltipText & _
                            GetDisabledAlternatePinTooltip(r, s)
                    End If
                End If
            End With
        End If
    Next iPin

    '-------------------------------------------------------------------------
    ' control: optTX_0 (show)
    '-------------------------------------------------------------------------
    With c("optTX_NoPin")
        bDisabled = IsModuleClockDisabled(r, vIndex)
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sVarPre & "_Use_Tx" & sChr) = 7)
    End With

    With e("optTX_NoPin")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                    GetTooltipModuleClockDisabled(r, vIndex)
            End If
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optTX_0 .. 2 (show)
    '-------------------------------------------------------------------------
    For iPin = 0 To 2
        s = sVarPre & "_TxD" & sChr & "_" & iPin
        If (r.Exist("MuxFor_" & s)) Then
            '-------------------------------------------------------------------------
            ' control: optTX_x (show)
            '-------------------------------------------------------------------------
            With c("optTX_" & iPin)
                bDisabled = IsModuleClockDisabled(r, vIndex) Or _
                            Not (IsAlternateOutputPinFree(r, s))
                .Enabled = Not (bDisabled)
                .Value = -CInt(r.v(sVarPre & "_Use_Tx" & sChr) = iPin)
            End With

            With e("optTX_" & iPin)
                If (bDisabled) Then
                    .DisabledTooltipText = TOOLTIP_DISABLED_IF
                    If (IsModuleClockDisabled(r, vIndex)) Then
                        .DisabledTooltipText = .DisabledTooltipText & _
                            GetTooltipModuleClockDisabled(r, vIndex)
                    End If
                    If (Not (IsAlternateOutputPinFree(r, s))) Then
                        .DisabledTooltipText = .DisabledTooltipText & _
                            GetDisabledAlternatePinTooltip(r, s)
                    End If
                End If
            End With
        End If
    Next iPin

  End If

  OnShowPagePinSelection = True
  Exit Function

OnShowPagePinSelectionError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function

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

  OnLoadPageControl = False

  If (Not ps.AddPage("Control")) Then Exit Function

  OnLoadPageControl = 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 OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim r As ProjectData
  Dim sChr As String
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim s As String
  Dim s2 As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "CAN" & vIndex
  sChr = ps.Parameters.v("Number")

  Set r = ps.ProjectData

  OnChangingPageControl = False
  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  
    '-------------------------------
    ' frame: frmINIT
    '-------------------------------
    If (Not ps.AddFrame("frmINIT", 100, 100, 4800, 900, "Initialization")) Then Exit Function
        If (Not ps.AddCheck("chkINIT", 200, 300, 4500, 400, _
          "Initialize the " & sVarPre & " node " & sChr & " (INIT)")) Then Exit Function

    '-------------------------------
    ' frame: frmInterrupts
    '-------------------------------
    If (Not ps.AddFrame("frmInterrupts", 5100, 100, 3450, 1900, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkSIE", 200, 300, 3200, 400, "Enable interrupt generation when a message transfer is completed (SIE)")) Then Exit Function
        If (Not ps.AddCheck("chkEIE", 200, 800, 3200, 400, "Enable interrupt generation on a change of bit BOFF or EWARN (EIE)")) Then Exit Function
        If (Not ps.AddCheck("chkLECIE", 200, 1300, 3200, 400, "Enable interrupt generation on setting an error code in bit field LEC (LECIE)")) Then Exit Function

    '-------------------------------
    ' frame: frmCALM
    '-------------------------------
    If (Not ps.AddFrame("frmCALM", 100, 1100, 4800, 900, "Analyzer Mode")) Then Exit Function
        If (Not ps.AddCheck("chkCALM", 200, 300, 4550, 400, "Enable the " & sVarPre & " analyzer mode; monitoring " & sVarPre & " bus traffic without participating in the " & sVarPre & " bus protocol itself (CALM)")) Then Exit Function

    '-------------------------------
    ' frame: frmINP
    '-------------------------------
    If (Not ps.AddFrame("frmINP", 100, 2100, 8450, 1850, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddCombo("cboTRINP", 4400, 350, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTRINP", 0, 200, 350, 3400, 400, "Transmit / receive OK interrupt node pointer (TRINP)")) Then Exit Function
        If (Not ps.AddCombo("cboEINP", 4400, 850, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblEINP", 0, 200, 850, 3900, 400, "Error (BusOff and ErrorWarning) interrupt node pointer (EINP)")) Then Exit Function
        If (Not ps.AddCombo("cboLECINP", 4400, 1350, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblLECINP", 0, 200, 1350, 3100, 385, "Last error code interrupt node pointer (LECINP)")) Then Exit Function

    '-------------------------------
    ' frame: frmEWRNLVL
    '-------------------------------
    If (Not ps.AddFrame("frmEWRNLVL", 100, 4050, 8450, 1000, "Error Warning Level")) Then Exit Function
        If (Not ps.AddText("txtEWRNLVL", 4400, 400, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblEWRNLVL", 0, 200, 450, 3900, 400, "Error warning threshold value (EWRNLVL)")) Then Exit Function

  End If
  OnChangingPageControl = 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 OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim d As String
  Dim s As String
  Dim s2 As String
  Dim sChr As String
  Dim i As Integer
  Dim iNr As Integer
  Dim bFirstTime As Boolean

  vIndex = ps.Parameters.v("x")
  sChr = ps.Parameters.v("Number")
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Control") Then

    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkINIT (action)
        '---------------------------------------------------------------------
        Case "chkINIT"

            If (v(1) = 1) Then
              r.v(sRegPre & sChr & "CR_INIT") = 0
            Else
              d = "All message objects which are connected to node " & sChr & " will be disabled . " & vbCrLf & _
                  "Also all message objects which are configured for gateway mode. " & vbCrLf & _
                  "Do you really want to continue ?"
              If (Ask(d)) Then
                Call DisableNodex(r, vIndex, sChr)
                If (sChr = "A") Then
                  If (r.v(sRegPre & "BCR_INIT") = 1) Then
                    r.v(sVarPre & "_USE_Init") = 0
                    Call DisableSRNs(r, vIndex)
                  End If
                Else
                  If (r.v(sRegPre & "ACR_INIT") = 1) Then
                    r.v(sVarPre & "_USE_Init") = 0
                    Call DisableSRNs(r, vIndex)
                  End If
                End If
              End If
            End If

        '---------------------------------------------------------------------
        ' control: chkSIE (action)
        '---------------------------------------------------------------------
        Case "chkSIE"
            r.v(sRegPre & sChr & "CR_SIE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkEIE (action)
        '---------------------------------------------------------------------
        Case "chkEIE"
            r.v(sRegPre & sChr & "CR_EIE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkLECIE (action)
        '---------------------------------------------------------------------
        Case "chkLECIE"
            r.v(sRegPre & sChr & "CR_LECIE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkCALM (action)
        '---------------------------------------------------------------------
        Case "chkCALM"
            If (v(1) = 1) Then
              r.v(sRegPre & sChr & "CR_CALM") = 1
              bFirstTime = True
              ' check if an object is configured for gateway mode
              For iNr = 0 To 31
                If (r.v(sRegPre & "MSGCTRL" & iNr & "_MSGVAL") = 2) Then  ' only if the object was selected
                  If (r.v(sRegPre & "MSGFGCRH" & iNr & "_MMC") > 3) Then
                    ' ask only one times and only if min. one object is configured for gateway mode
                    If (bFirstTime) Then
                      bFirstTime = False
                      d = "All message objects which are configured for gateway mode will be disabled . " & vbCrLf & _
                          "Do you really want to continue ?"
                      If Not (Ask(d)) Then
                        ' restore CALM
                        r.v(sRegPre & sChr & "CR_CALM") = 0
                        Exit For
                      End If
                    End If
                    r.sfr(sRegPre & "MSGCTRH" & iNr) = &H0
                    r.sfr(sRegPre & "MSGCTRL" & iNr) = &H5555

                    r.sfr(sRegPre & "MSGCFGH" & iNr) = &H0
                    r.sfr(sRegPre & "MSGCFGL" & iNr) = &H0

                    r.sfr(sRegPre & "MSGFGCRH" & iNr) = &H0
                    r.sfr(sRegPre & "MSGFGCRL" & iNr) = &H0
                  End If
                End If
              Next iNr
            Else
              r.v(sRegPre & sChr & "CR_CALM") = 0
            End If

        '---------------------------------------------------------------------
        ' control: cboTRINP (action)
        '---------------------------------------------------------------------
        Case "cboTRINP"
            For i = 0 To 7
              If ("Use TwinCAN SRN " & i = v(1)) Then
                r.v(sRegPre & sChr & "GINP_TRINP") = i
                Exit For
              End If
            Next i

        '---------------------------------------------------------------------
        ' control: cboLECINP (action)
        '---------------------------------------------------------------------
        Case "cboLECINP"
            For i = 0 To 7
              If ("Use TwinCAN SRN " & i = v(1)) Then
                r.v(sRegPre & sChr & "GINP_LECINP") = i
                Exit For
              End If
            Next i

        '---------------------------------------------------------------------
        ' control: cboEINP (action)
        '---------------------------------------------------------------------
        Case "cboEINP"
            For i = 0 To 7
              If ("Use TwinCAN SRN " & i = v(1)) Then
                r.v(sRegPre & sChr & "GINP_EINP") = i
                Exit For
              End If
            Next i

        '---------------------------------------------------------------------
        ' control: txtEWRNLVL (action)
        '---------------------------------------------------------------------
        Case "txtEWRNLVL"
             If (IsInputFormatOK(v(1), "D", c("lblEWRNLVL").Caption, 0, 255)) Then
               r.v(sRegPre & sChr & "ECNTH_EWRNLVL") = v(1)
             Else
                 Exit Function
             End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkINIT (show)
    '-------------------------------------------------------------------------
    With c("chkINIT")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or Not (IsPinInterfaceSelected(r, vIndex, sChr))
      .Enabled = Not (bDisabled)
      ' show condition
      .Value = -CInt(r.v(sRegPre & sChr & "CR_INIT") = 0)
    End With

    With e("chkINIT")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipIfPinInterfaceNotSelected(r, vIndex, sChr)
      Else
        ' tooltip if control is enabled
'        .EnabledToolTipText = EnabledTooltipForInputSignals(r, vIndex, iNr, 0)
      End If
    End With


    '-------------------------------------------------------------------------
    ' frame: frmInterrupts and frmCALM (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
      d = d & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmInterrupts").Caption, c, e, bDisabled, d, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCALM").Caption, c, e, bDisabled, d, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmEWRNLVL").Caption, c, e, bDisabled, d, "")

    '-------------------------------------------------------------------------
    ' control: chkSIE (show)
    '-------------------------------------------------------------------------
    With c("chkSIE")
      .Value = -CInt(r.v(sRegPre & sChr & "CR_SIE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkEIE (show)
    '-------------------------------------------------------------------------
    With c("chkEIE")
      .Value = -CInt(r.v(sRegPre & sChr & "CR_EIE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkLECIE (show)
    '-------------------------------------------------------------------------
    With c("chkLECIE")
      .Value = -CInt(r.v(sRegPre & sChr & "CR_LECIE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkCALM (show)
    '-------------------------------------------------------------------------
    With c("chkCALM")
      .Value = -CInt(r.v(sRegPre & sChr & "CR_CALM") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: cboTRINP (show)
    '-------------------------------------------------------------------------
    With c("cboTRINP")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or r.v(sRegPre & sChr & "CR_SIE") = 0
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To 7
        .AddItem "Use TwinCAN SRN " & i
      Next i
      .ListIndex = r.v(sRegPre & sChr & "GINP_TRINP")
    End With

    With e("cboTRINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
        End If
        If (r.v(sRegPre & sChr & "CR_SIE") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("interrupt generation when a message transfer is completed is disabled")
        End If
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblTRINP (show)
    '-------------------------------------------------------------------------
    With c("lblTRINP")
      ' same as for cboTRINP
      .Enabled = Not (bDisabled)
    End With

    With e("lblTRINP")
      If (bDisabled) Then
        .DisabledTooltipText = e("cboTRINP").DisabledTooltipText
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboLECINP (show)
    '-------------------------------------------------------------------------
    With c("cboLECINP")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or r.v(sRegPre & sChr & "CR_LECIE") = 0
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To 7
        .AddItem "Use TwinCAN SRN " & i
      Next i
      .ListIndex = r.v(sRegPre & sChr & "GINP_LECINP")
    End With

    With e("cboLECINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
        End If
        If (r.v(sRegPre & sChr & "CR_LECIE") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("interrupt generation on setting an error code in bit field LEC is disabled")
        End If
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblLECINP (show)
    '-------------------------------------------------------------------------
    With c("lblLECINP")
      ' same as for cboLECINP
      .Enabled = Not (bDisabled)
    End With

    With e("lblLECINP")
      If (bDisabled) Then
        .DisabledTooltipText = e("cboLECINP").DisabledTooltipText
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboEINP (show)
    '-------------------------------------------------------------------------
    With c("cboEINP")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or r.v(sRegPre & sChr & "CR_EIE") = 0
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To 7
        .AddItem "Use TwinCAN SRN " & i
      Next i
      .ListIndex = r.v(sRegPre & sChr & "GINP_EINP")
    End With

    With e("cboEINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
        End If
        If (r.v(sRegPre & sChr & "CR_EIE") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("interrupt generation on a change of bit BOFF or EWARN is disabled")
        End If
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblEINP (show)
    '-------------------------------------------------------------------------
    With c("lblEINP")
      ' same as for cboEINP
      .Enabled = Not (bDisabled)
    End With

    With e("lblEINP")
      If (bDisabled) Then
        .DisabledTooltipText = e("cboEINP").DisabledTooltipText
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtEWRNLVL (show)
    '-------------------------------------------------------------------------
    With c("txtEWRNLVL")
        .Text = FormatTextOutput(r.v(sRegPre & sChr & "ECNTH_EWRNLVL"), "D")
    End With

    '-------------------------------------------------------------------------
    ' control: lblEWRNLVL (show)
    '-------------------------------------------------------------------------
    With c("lblEWRNLVL")
    End With

  End If


  OnShowPageControl = True
  Exit Function

OnShowPageControlError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


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

  OnLoadPageBaudrate = False

  If (Not ps.AddPage("Baud Rate")) Then Exit Function

  OnLoadPageBaudrate = 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 OnChangingPageBaudrate(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageBaudrate = False
  
  If (Not ps.ExtenderCollection("Baud Rate").Loaded) And (Pagename = "Baud Rate") Then
    ps.ExtenderCollection("Baud Rate").Loaded = True
  
    '-------------------------------
    ' frame: frmDIV8X
    '-------------------------------
    If (Not ps.AddFrame("frmDIV8X", 100, 100, 8450, 1050, "Division of Module Clock by 8 (DIV8X)")) Then Exit Function
        If (Not ps.AddOption("optDIV8X_0", 200, 300, 4000, 300, "")) Then Exit Function
        If (Not ps.AddOption("optDIV8X_1", 200, 650, 4000, 300, "")) Then Exit Function

    '-------------------------------
    ' frame: frmTime
    '-------------------------------
    If (Not ps.AddFrame("frmTime", 100, 1250, 8450, 2250, "Bit Timing (in time quanta)")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_tq", 1, 2200, 425, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_tq", 0, 200, 400, 1575, 385, "Synchronization Segment [tq]")) Then Exit Function
        If (Not ps.AddText("txtTSEG1", 2200, 1075, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTSEG1", 0, 200, 1050, 1700, 385, "Time Segment (TSeg1) before sample point [tq]")) Then Exit Function
        If (Not ps.AddText("txtTSEG2", 2200, 1725, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTSEG2", 0, 200, 1700, 1700, 385, "Time Segment (TSeg2) after sample point [tq]")) Then Exit Function
        If (Not ps.AddText("txtSJW", 6000, 425, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblSJW", 0, 4200, 400, 1575, 385, "(Re)Synchronization jump width [tq]")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_perc", 1, 6000, 1075, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_perc", 0, 4200, 1050, 1575, 385, "Sample point of the total bit time [%]")) Then Exit Function

    '-------------------------------
    ' frame: frmBaudrate
    '-------------------------------
    If (Not ps.AddFrame("frmBaudrate", 100, 3600, 8450, 1650, "Baud Rate")) Then Exit Function
        If (Not ps.AddText("txtReqBR", 2200, 425, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblReqBR", 0, 250, 400, 1875, 385, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_RealBR", 1, 6000, 425, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_RealBR", 0, 4200, 400, 1575, 385, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_Time_tq", 1, 2200, 1025, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_Time_tq", 0, 250, 1000, 1275, 385, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_BRP", 1, 6000, 1000, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_BRP", 0, 4200, 1050, 1575, 305, "Baud rate prescaler")) Then Exit Function

  End If
  OnChangingPageBaudrate = 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 OnShowPageBaudrate(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageBaudrateError

  OnShowPageBaudrate = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim sRegPre As String
  Dim sChr As String
  Dim d As String
  Dim uBR As UnitType
  Dim uTime As UnitType


  vIndex = ps.Parameters.v("x")
  sChr = ps.Parameters.v("Number")
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_" & sChr

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Baud Rate") Then
    '-------------------------------------------------------------------------
    ' page: Baudrate (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)

        '---------------------------------------------------------------------
        ' control: optDIV8X_0 (action)
        '---------------------------------------------------------------------
        Case "optDIV8X_0"
            r.v(sRegPre & "BTRL_DIV8X") = 0
            Call UpdateCAN(r, vIndex, sChr)

        '---------------------------------------------------------------------
        ' control: optDIV8X_1 (action)
        '---------------------------------------------------------------------
        Case "optDIV8X_1"
            r.v(sRegPre & "BTRL_DIV8X") = 1
            Call UpdateCAN(r, vIndex, sChr)

        '---------------------------------------------------------------------
        ' control: txtReqBR (action)
        '---------------------------------------------------------------------
        Case "txtReqBR"
            uBR = ConvertBaudrate(r.v(sVarPre & "_BaudrateNode" & sChr))
            If (IsInputFormatOK(v(1), "F", c("lblReqBR").Caption, GetMinReqBR(r, vIndex, sChr) / uBR.dDivider, GetMaxReqBR(r, vIndex, sChr) / uBR.dDivider)) Then
                r.v(sVarPre & "_BaudrateNode" & sChr) = v(1) * uBR.dDivider
                Call UpdateCAN(r, vIndex, sChr)
            Else
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: txtTSEG1 (action)
        '---------------------------------------------------------------------
        Case "txtTSEG1"
            If (IsInputFormatOK(v(1), "D", c("lblTSEG1").Caption, GetMinTseg1Value(r, vIndex, v(1), sChr), 16)) Then
                r.d(sRegPre & "BTRL_TSEG1") = v(1) - 1
                Call UpdateCAN(r, vIndex, sChr)
            Else
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: txtTSEG2 (action)
        '---------------------------------------------------------------------
        Case "txtTSEG2"
            If (IsInputFormatOK(v(1), "D", c("lblTSEG2").Caption, GetMinTseg2Value(r, vIndex, v(1), sChr), 8)) Then
                r.d(sRegPre & "BTRL_TSEG2") = v(1) - 1
                Call UpdateCAN(r, vIndex, sChr)
            Else
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: txtSJW (action)
        '---------------------------------------------------------------------
        Case "txtSJW"
            If (IsInputFormatOK(v(1), "D", c("lblSJW").Caption, GetMinSJWValue(r, vIndex, v(1), sChr), GetMaxSJWValue(r, vIndex, v(1), sChr))) Then
                r.d(sRegPre & "BTRL_SJW") = v(1) - 1
            Else
                Exit Function
            End If


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Baudrate (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & "CR_INIT") = 1
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & "CR_INIT") = 1) Then
      d = d & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
    End If
    Call SetDefaultPropertiesForAllControlsOnPage(Pagename, c, e, bDisabled, d, "")


    '-------------------------------------------------------------------------
    ' control: optDIV8X_0 (show)
    '-------------------------------------------------------------------------
    With c("optDIV8X_0")
       .Value = r.v(sRegPre & "BTRL_DIV8X") = 0
       .Caption = "Use the module clock directly (= " & Format(GetCANModuleClock(r, vIndex), "0.000") & " MHz)"
    End With

    '-------------------------------------------------------------------------
    ' control: optDIV8X_1 (show)
    '-------------------------------------------------------------------------
    With c("optDIV8X_1")
       .Value = r.v(sRegPre & "BTRL_DIV8X") = 1
       .Caption = "Divide the module clock by 8 (= " & Format(GetCANModuleClock(r, vIndex) / 8, "0.000") & " MHz)"
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_RealBR (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_RealBR")
      ' bDisabled from Page disable condition
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lbl_txt_RealBR").Caption = "Real baud rate " & vbCrLf & "[kbaud]"
      Else
        uBR = ConvertBaudrate(GetNodexClock(r, vIndex, sChr) * 1000000 / _
              (2 ^ (1 - 1) * (r.v(sRegPre & "BTRL_BRP") + 1) * _
              (3 + r.d(sRegPre & "BTRL_TSEG1") + r.d(sRegPre & "BTRL_TSEG2"))))
        .Caption = Format(uBR.dValue, CAN_PRECISION)
        c("lbl_txt_RealBR").Caption = "Real baud rate " & vbCrLf & "[" & uBR.sUnit & "]"
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_RealBR (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_RealBR")
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_Time_tq (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_Time_tq")
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lbl_txt_Time_tq").Caption = "Time Quantum tq " & vbCrLf & "[s]"
      Else
        uTime = ConvertTime((1 / GetNodexClock(r, vIndex, sChr)) * 2 ^ (1 - 1) * _
                (r.v(sRegPre & "BTRL_BRP") + 1))
        .Caption = Format(uTime.dValue, CAN_PRECISION)
        c("lbl_txt_Time_tq").Caption = "Time Quantum tq " & vbCrLf & "[" & uTime.sUnit & "]"
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_Time_tq (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_Time_tq")
    End With

    '-------------------------------------------------------------------------
    ' control: txtReqBR (show)
    '-------------------------------------------------------------------------
    With c("txtReqBR")
      If (bDisabled) Then
        .Text = CALCULATION_NOT_POSSIBLE
        c("lblReqBR").Caption = "Required baud rate [kbaud]"
      Else
        uBR = ConvertBaudrate(r.v(sVarPre & "_BaudrateNode" & sChr))
        .Text = Format(uBR.dValue, CAN_PRECISION)
        c("lblReqBR").Caption = "Required baud rate " & vbCrLf & "[" & uBR.sUnit & "]"
      End If
    End With

    With e("txtReqBR")
        If (bDisabled) Then
          'disabled tooltip
        Else
          .EnabledTooltipText = FormatNormalTooltip("The maximum input baud rate is to be achieved if '" & c("lblTSEG1").Caption & "' = 3 and '" & c("lblTSEG2").Caption & "' = 2." & vbCrLf & vbCrLf)
          .EnabledTooltipText = .EnabledTooltipText & FormatNormalTooltip("The minimum input baud rate is to be achieved if '" & c("lblTSEG1").Caption & "' = 16 and '" & c("lblTSEG2").Caption & "' = 8.")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblReqBR (show)
    '-------------------------------------------------------------------------
    With c("lblReqBR")
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_BRP (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_BRP")
        .Caption = r.d(sRegPre & "BTRL_BRP")
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_BRP (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_BRP")
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_tq (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_tq")
        .Caption = 1
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_tq (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_tq")
    End With

    '-------------------------------------------------------------------------
    ' control: txtTSEG1 (show)
    '-------------------------------------------------------------------------
    With c("txtTSEG1")
        .Text = FormatTextOutput(r.v(sRegPre & "BTRL_TSEG1") + 1, "D")
    End With

    With e("txtTSEG1")
        If (bDisabled) Then
            'disabled tooltip
        Else
            .EnabledTooltipText = sSP_Graphic & sSamplePoint
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblTSEG1 (show)
    '-------------------------------------------------------------------------
    With c("lblTSEG1")
    End With

    '-------------------------------------------------------------------------
    ' control: txtTSEG2 (show)
    '-------------------------------------------------------------------------
    With c("txtTSEG2")
        .Text = FormatTextOutput(r.v(sRegPre & "BTRL_TSEG2") + 1, "D")
    End With

    With e("txtTSEG2")
        If (bDisabled) Then
            'disabled tooltip
        Else
            .EnabledTooltipText = sSP_Graphic & sSamplePoint
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblTSEG2 (show)
    '-------------------------------------------------------------------------
    With c("lblTSEG2")
    End With

    '-------------------------------------------------------------------------
    ' control: txtSJW (show)
    '-------------------------------------------------------------------------
    With c("txtSJW")
        .Text = FormatTextOutput(r.v(sRegPre & "BTRL_SJW") + 1, "D")
    End With

    '-------------------------------------------------------------------------
    ' control: lblSJW (show)
    '-------------------------------------------------------------------------
    With c("lblSJW")
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_perc (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_perc")
        .Caption = Format((2 + r.d(sRegPre & "BTRL_TSEG1")) / (3 + r.d(sRegPre & "BTRL_TSEG1") + r.d(sRegPre & "BTRL_TSEG2")) * 100, "0.00")
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_perc (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_perc")
    End With

  End If

  OnShowPageBaudrate = True
  Exit Function

OnShowPageBaudrateError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


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

  OnLoadPageFrameCounter = False

  If (Not ps.AddPage("Frame Counter")) Then Exit Function

  OnLoadPageFrameCounter = 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 OnChangingPageFrameCounter(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFrameCounter = False
  
  If (Not ps.ExtenderCollection("Frame Counter").Loaded) And (Pagename = "Frame Counter") Then
    ps.ExtenderCollection("Frame Counter").Loaded = True
  
    '-------------------------------
    ' frame: frmCFCMD3
    '-------------------------------
    If (Not ps.AddFrame("frmCFCMD3", 100, 100, 8400, 1100, "Frame Counter Mode (CFCMD.3)")) Then Exit Function
        If (Not ps.AddOption("optCFCMD3_0", 200, 300, 3750, 300, "The counter works on frame base (frame count)")) Then Exit Function
        If (Not ps.AddOption("optCFCMD3_1", 200, 700, 3750, 300, "The counter works on time base (time stamp)")) Then Exit Function

    '-------------------------------
    ' frame: frmCount
    '-------------------------------
    If (Not ps.AddFrame("frmCount", 100, 1300, 4700, 2050, "Frame Count")) Then Exit Function
        If (Not ps.AddCheck("chkCFCMD2", 200, 350, 4100, 400, "The counter is incremented each time a frame was transmitted correctly (CFCMD.2)")) Then Exit Function
        If (Not ps.AddCheck("chkCFCMD1", 200, 950, 4100, 400, "The counter is incremented each time a frame was received correctly (CFCMD.1)")) Then Exit Function
        If (Not ps.AddCheck("chkCFCMD0", 200, 1500, 4300, 400, "The counter is incremented each time a correct foreign frame was monitored on the CAN bus (CFCMD.0)")) Then Exit Function

    '-------------------------------
    ' frame: frmCFCMD0
    '-------------------------------
    If (Not ps.AddFrame("frmCFCMD0", 5000, 1300, 3500, 2050, "Time Stamp (CFCMD.0)")) Then Exit Function
        If (Not ps.AddOption("optCFCMD0_0", 200, 350, 3100, 650, "The counter is incremented with the beginning of a new bit time. The value is sampled during the SOF bit.")) Then Exit Function
        If (Not ps.AddOption("optCFCMD0_1", 200, 1100, 3100, 700, "The counter is incremented with the beginning of a new bit time. The value is sampled during the last bit of EOF.")) Then Exit Function

    '-------------------------------
    ' frame: frmInterrupt
    '-------------------------------
    If (Not ps.AddFrame("frmInterrupt", 100, 3500, 4700, 1700, "Frame Counter Interrupt")) Then Exit Function
        If (Not ps.AddCheck("chkCFCIE", 200, 350, 4100, 380, "Enable the frame counter overflow interrupt (CFCIE)")) Then Exit Function
        If (Not ps.AddCombo("cboCFCINP", 2350, 1025, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblCFCINP", 0, 200, 1000, 2025, 405, "Frame counter interrupt node pointer (CFCINP)")) Then Exit Function

    '-------------------------------
    ' frame: frmCFC
    '-------------------------------
    If (Not ps.AddFrame("frmCFC", 5000, 3500, 3500, 1700, "Frame Counter")) Then Exit Function
        If (Not ps.AddText("txtCFC", 2000, 600, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblCFC", 0, 200, 650, 1575, 400, "Counter value (CFC)")) Then Exit Function

  End If
  OnChangingPageFrameCounter = 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 OnShowPageFrameCounter(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFrameCounterError

  OnShowPageFrameCounter = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim d As String
  Dim s As String
  Dim s2 As String
  Dim sChr As String
  Dim i As Integer

  vIndex = ps.Parameters.v("x")
  sChr = ps.Parameters.v("Number")
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Frame Counter") Then
    '-------------------------------------------------------------------------
    ' page: FrameCounter (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optCFCMD3_0 (action)
        '---------------------------------------------------------------------
        Case "optCFCMD3_0"
            r.v(sRegPre & sChr & "FCRH_CFCMD") = 0
            r.v(sRegPre & sChr & "FCRH_CFCIE") = 0

        '---------------------------------------------------------------------
        ' control: optCFCMD3_1 (action)
        '---------------------------------------------------------------------
        Case "optCFCMD3_1"
            r.v(sRegPre & sChr & "FCRH_CFCMD") = 8

        '---------------------------------------------------------------------
        ' control: chkCFCMD2 (action)
        '---------------------------------------------------------------------
        Case "chkCFCMD2"
            If (v(1) = 1) Then
              r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") + 4
            Else
              r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") - 4
              If (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0) Then  ' if no error count selected
                r.v(sRegPre & sChr & "FCRH_CFCIE") = 0
              End If
            End If

        '---------------------------------------------------------------------
        ' control: chkCFCMD1 (action)
        '---------------------------------------------------------------------
        Case "chkCFCMD1"
            If (v(1) = 1) Then
              r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") + 2
            Else
              r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") - 2
              If (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0) Then  ' if no error count selected
                r.v(sRegPre & sChr & "FCRH_CFCIE") = 0
              End If
            End If

        '---------------------------------------------------------------------
        ' control: chkCFCMD0 (action)
        '---------------------------------------------------------------------
        Case "chkCFCMD0"
            If (v(1) = 1) Then
              r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") + 1
            Else
              r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") - 1
              If (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0) Then  ' if no error count selected
                r.v(sRegPre & sChr & "FCRH_CFCIE") = 0
              End If
            End If

        '---------------------------------------------------------------------
        ' control: optCFCMD0_0 (action)
        '---------------------------------------------------------------------
        Case "optCFCMD0_0"
            r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") - 1

        '---------------------------------------------------------------------
        ' control: optCFCMD0_1 (action)
        '---------------------------------------------------------------------
        Case "optCFCMD0_1"
            r.v(sRegPre & sChr & "FCRH_CFCMD") = r.v(sRegPre & sChr & "FCRH_CFCMD") + 1

        '---------------------------------------------------------------------
        ' control: chkCFCIE (action)
        '---------------------------------------------------------------------
        Case "chkCFCIE"
            r.v(sRegPre & sChr & "FCRH_CFCIE") = v(1)

        '---------------------------------------------------------------------
        ' control: cboCFCINP (action)
        '---------------------------------------------------------------------
        Case "cboCFCINP"
            For i = 0 To 7
              If ("Use TwinCAN SRN " & i = v(1)) Then
                r.v(sRegPre & sChr & "GINP_CFCINP") = i
                Exit For
              End If
            Next i

        '---------------------------------------------------------------------
        ' control: txtCFC (action)
        '---------------------------------------------------------------------
        Case "txtCFC"
             If (IsInputFormatOK(v(1), "H4", c("lblCFC").Caption, 0, &HFFFF)) Then
               r.v(sRegPre & sChr & "FCRL_CFC") = v(1)
             Else
                 Exit Function
             End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: FrameCounter (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' frame: frmCFCMD3 (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
      d = d & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCFCMD3").Caption, c, e, bDisabled, d, "")

    '-------------------------------------------------------------------------
    ' control: optCFCMD3_0 (show)
    '-------------------------------------------------------------------------
    With c("optCFCMD3_0")
      .Value = ((r.v(sRegPre & sChr & "FCRH_CFCMD") And 8) = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optCFCMD3_1 (show)
    '-------------------------------------------------------------------------
    With c("optCFCMD3_1")
      .Value = ((r.v(sRegPre & sChr & "FCRH_CFCMD") And 8) = 8)
    End With

    '-------------------------------------------------------------------------
    ' frame: frmCount (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or ((r.v(sRegPre & sChr & "FCRH_CFCMD") And 8) = 8)
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
      d = d & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
    End If
    If ((r.v(sRegPre & sChr & "FCRH_CFCMD") And 8) = 8) Then
      d = d & FormatDisabledTooltip("the counter do not work on frame base")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCount").Caption, c, e, bDisabled, d, "")

    '-------------------------------------------------------------------------
    ' control: chkCFCMD2 (show)
    '-------------------------------------------------------------------------
    With c("chkCFCMD2")
      .Value = -CInt((r.v(sRegPre & sChr & "FCRH_CFCMD") And 12) = 4)
    End With

    '-------------------------------------------------------------------------
    ' control: chkCFCMD1 (show)
    '-------------------------------------------------------------------------
    With c("chkCFCMD1")
      .Value = -CInt((r.v(sRegPre & sChr & "FCRH_CFCMD") And 10) = 2)
    End With

    '-------------------------------------------------------------------------
    ' control: chkCFCMD0 (show)
    '-------------------------------------------------------------------------
    With c("chkCFCMD0")
      .Value = -CInt((r.v(sRegPre & sChr & "FCRH_CFCMD") And 9) = 1)
    End With


    '-------------------------------------------------------------------------
    ' frame: frmCFCMD0 (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or ((r.v(sRegPre & sChr & "FCRH_CFCMD") And 8) = 0)
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
      d = d & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
    End If
    If ((r.v(sRegPre & sChr & "FCRH_CFCMD") And 8) = 0) Then
      d = d & FormatDisabledTooltip("the counter do not work on time base")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCFCMD0").Caption, c, e, bDisabled, d, "")

    '-------------------------------------------------------------------------
    ' control: optCFCMD0_0 (show)
    '-------------------------------------------------------------------------
    With c("optCFCMD0_0")
      .Value = -CInt((r.v(sRegPre & sChr & "FCRH_CFCMD")) = 8)
    End With

    '-------------------------------------------------------------------------
    ' control: optCFCMD0_1 (show)
    '-------------------------------------------------------------------------
    With c("optCFCMD0_1")
      .Value = -CInt((r.v(sRegPre & sChr & "FCRH_CFCMD")) = 9)
    End With

    '-------------------------------------------------------------------------
    ' frame: frmInterrupt and frmCFC (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0)
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
      d = d & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
    End If
    If (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0) Then
      d = d & FormatDisabledTooltip("no counter increment is selected")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmInterrupt").Caption, c, e, bDisabled, d, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCFC").Caption, c, e, bDisabled, d, "")
    '-------------------------------------------------------------------------
    ' control: chkCFCIE (show)
    '-------------------------------------------------------------------------
    With c("chkCFCIE")
      .Value = -CInt(r.v(sRegPre & sChr & "FCRH_CFCIE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: cboCFCINP (show)
    '-------------------------------------------------------------------------
    With c("cboCFCINP")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sRegPre & sChr & "CR_INIT") = 1 Or (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0) Or r.v(sRegPre & sChr & "FCRH_CFCIE") = 0
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To 7
        .AddItem "Use TwinCAN SRN " & i
      Next i
      .ListIndex = r.v(sRegPre & sChr & "GINP_CFCINP")
    End With

    With e("cboCFCINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        If (r.v(sRegPre & sChr & "CR_INIT") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip(TOOLTIP_DISABLED_NOTE)
        End If
        If (r.v(sRegPre & sChr & "FCRH_CFCMD") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("no counter increment is selected")
        End If
        If (r.v(sRegPre & sChr & "FCRH_CFCIE") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("the frame counter overflow interrupt is disabled")
        End If
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblCFCINP (show)
    '-------------------------------------------------------------------------
    With c("lblCFCINP")
      ' same as for cboCFCINP
      .Enabled = Not (bDisabled)
    End With

    With e("lblCFCINP")
      If (bDisabled) Then
        .DisabledTooltipText = e("cboCFCINP").DisabledTooltipText
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtCFC (show)
    '-------------------------------------------------------------------------
    With c("txtCFC")
        .Text = FormatTextOutput(r.v(sRegPre & sChr & "FCRL_CFC"), "H4")
    End With

    '-------------------------------------------------------------------------
    ' control: lblCFC (show)
    '-------------------------------------------------------------------------
    With c("lblCFC")
    End With

  End If

  OnShowPageFrameCounter = True
  Exit Function

OnShowPageFrameCounterError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function

