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.1  ahe            13.08.02     final version for TC1775B, TC1765
'                                         - no changes
'        ----------------------------------------------------------------------
'        4.0  ste            21.10.02     final version for TC1796
'        ----------------------------------------------------------------------
'             ste            01.08.03     version for TC1766
'                                         only 2 node available
'                                         only 64 message objects available
'                                         only 6 SRNs available
'             ste            28.08.03     pages for TTCAN added
'                                         16 SRNs available (new Const used)
'             ste            18.09.03     caption for "optTTM_1" changed
'        ----------------------------------------------------------------------
'             ste            14.11.03     TC1766 and TC1796 merged
'
'*****************************************************************************

Const TOOLTIP_DISABLED_NODE = "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

    Dim vIndex As Variant
    Dim iNr As Integer
    Dim sVarPre As String
    Dim r As ProjectData

    Set r = ps.ProjectData
  
    vIndex = ps.Parameters.v("x")
    iNr = ps.Parameters.v("Number")
    sVarPre = "CAN" & vIndex

    '-------------------------------------------------------------------------
    ' page: Pin Selection
    '-------------------------------------------------------------------------
    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 iNr As Integer
    Dim sVarPre As String
    Dim r As ProjectData

    Set r = ps.ProjectData
  
    vIndex = ps.Parameters.v("x")
    iNr = ps.Parameters.v("Number")
    sVarPre = "CAN" & vIndex

    OnChangingPage = False

   '-------------------------------------------------------------------------
    'page: Pin Selection
    '-------------------------------------------------------------------------
    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 iNr As Integer
    Dim sVarPre As String
    Dim r As ProjectData

    Set r = ps.ProjectData
  
    vIndex = ps.Parameters.v("x")
    iNr = ps.Parameters.v("Number")
    sVarPre = "CAN" & vIndex

    OnShow = False
    '-------------------------------------------------------------------------
    ' page: Pin Selection
    '-------------------------------------------------------------------------
    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 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 a page.
'-----------------------------------------------------------------------------
'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

  OnChangingPagePinSelection = False
  Dim iNr As Integer
  Dim vIndex As Variant
  Dim sIndex As String
  Dim v As Variant

  vIndex = ps.Parameters.v("x")
  iNr = ps.Parameters.v("Number")
  
  
  If (Not ps.ExtenderCollection("Pin Selection").Loaded) And (Pagename = "Pin Selection") Then
    ps.ExtenderCollection("Pin Selection").Loaded = True

    
    '-------------------------------
    ' frame: frmRXD
    '-------------------------------
    If (Not ps.AddFrame("frmCAN_RXD", 100, 100, 4150, 2400, "Receive Input Selection")) Then Exit Function
    
    If (iNr = 0) Then
    
        If (Not ps.AddOption("optCAN_NODE_RXD_0", 150, 300, 3000, 380, "Pin RXDC0 is not used ")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_1", 150, 700, 3000, 380, "Use pin RXDC0_0(P1.0) as input")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_2", 150, 1100, 3000, 380, "Use pin RXDC0_1(P3.4) as input")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_3", 150, 1500, 3000, 380, "Use pin RXDC0_2(P1.6) as input")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_4", 150, 1900, 3000, 380, "Use pin RXDC0_3(P4.0) as input")) Then Exit Function
   End If
    
    If (iNr = 1) Then
    
        If (Not ps.AddOption("optCAN_NODE_RXD_0", 150, 300, 3000, 380, "Pin RXDC1 is not used ")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_1", 150, 700, 3000, 380, "Use pin RXDC1_0(P0.1) as input")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_2", 150, 1100, 3000, 380, "Use pin RXDC1_1(P3.2) as intput")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_RXD_3", 150, 1500, 3000, 380, "Use pin RXDC1_3(P1.4) as input")) Then Exit Function
'        If (Not ps.AddOption("optCAN_NODE_RXD_4", 150, 3200, 3000, 380, "Temp is used")) Then Exit Function
    End If
   
 
    '-------------------------------
    ' frame: frmTXD
    '-------------------------------
    If (Not ps.AddFrame("frmCAN_TXD", 4400, 100, 4000, 2400, "Transmit Output Selection")) Then Exit Function
    
    If (iNr = 0) Then
    
        If (Not ps.AddOption("optCAN_NODE_TXD_0", 150, 300, 3000, 380, "Pin TXDC0 is not used")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_1", 150, 700, 3000, 380, "Use pin TXDC0_0(P1.1) as output")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_2", 150, 1100, 3000, 380, "Use pin TXDC0_1(P3.5) as output")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_3", 150, 1500, 3000, 380, "Use pin TXDC0_2(P1.7) as output")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_4", 150, 1900, 3000, 380, "Use pin TXDC0_3(P4.1) as output")) Then Exit Function
     End If
     
      If (iNr = 1) Then
    
        If (Not ps.AddOption("optCAN_NODE_TXD_0", 150, 300, 3000, 380, "Pin TXDC1 is not used")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_1", 150, 700, 3000, 380, "Use pin TXDC1_0(P0.2) as output")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_2", 150, 1100, 3000, 380, "Use pin TXDC1_1(P3.3) as output")) Then Exit Function
        If (Not ps.AddOption("optCAN_NODE_TXD_3", 150, 1500, 3000, 380, "Use pin TXDC1_3(P1.3) as output")) Then Exit Function
'        If (Not ps.AddOption("optCAN_NODE_TXD_4", 150, 3200, 3000, 380, "Temp.test is used")) Then Exit Function
     End If
     
     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 iNr As Integer
  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim vToolIndex As Variant
  Dim sIndex As String
  Dim sPrefix As String
  Dim sRegPre As String
  Dim i As Integer
  Dim pinid As Integer
  Dim sNCRx As String
  Dim sNPCRx As String ' Node x Port Control Register
  Dim d As String

  vIndex = ps.Parameters.v("x")
  sIndex = "CAN"
  sPrefix = sIndex & "_"
  sRegPre = sIndex & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  iNr = ps.Parameters.v("Number")
  sNCRx = sRegPre & "NCR" & iNr

  If (Pagename = "Pin Selection") Then

      Select Case (Controlname)
         Case "optCAN_NODE_RXD_0"
             If (iNr = 0) Then
             
                     If ((r.v(sNCRx & "_INIT") = 0) And (r.v("CAN_USE_NODE0_TXD_PIN") > 0)) And (Not (r.v("CAN_NPCR0_LBM") = 1)) Then
                           d = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                          "Do you really want to continue ?"
                                    If (Ask(d)) Then
                                        Call DisableNodex(r, vIndex, iNr)
                                        Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                                        r.v("CAN_USE_NODE0_RXD_PIN") = 0
                                        r.v(sRegPre & "NPCR0_RXSEL") = 0
''                                          Call ReleaseAlternateInputPin(r, "RXDC0_0")
''                                          Call ReleaseAlternateInputPin(r, "RXDC0_1")
''                                          Call ReleaseAlternateInputPin(r, "RXDC0_2")
''                                          Call ReleaseAlternateInputPin(r, "RXDC0_3")
                                    End If
                    Else
                       Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                        r.v("CAN_USE_NODE0_RXD_PIN") = 0
                        r.v(sRegPre & "NPCR0_RXSEL") = 0
''                        Call ReleaseAlternateInputPin(r, "RXDC0_0")
''                        Call ReleaseAlternateInputPin(r, "RXDC0_1")
''                        Call ReleaseAlternateInputPin(r, "RXDC0_2")
''                        Call ReleaseAlternateInputPin(r, "RXDC0_3")
                             
                    End If
            Else
            
                      If ((r.v(sNCRx & "_INIT") = 0) And (r.v("CAN_USE_NODE1_TXD_PIN") > 0)) And (Not (r.v("CAN_NPCR1_LBM") = 1)) Then
              d = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                  "Do you really want to continue ?"
                                If (Ask(d)) Then
                                  Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                                  MsgBox "iNr"
                                  Call DisableNodex(r, vIndex, iNr)
                                  r.v("CAN_USE_NODE1_RXD_PIN") = 0
                                  r.v(sRegPre & "NPCR1_RXSEL") = 0
''                                    Call ReleaseAlternateInputPin(r, "RXDC1_0")
''                                    Call ReleaseAlternateInputPin(r, "RXDC1_1")
''                                    Call ReleaseAlternateInputPin(r, "RXDC1_3")
                             End If
                     
                     Else
                        
                        Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                        r.v("CAN_USE_NODE1_RXD_PIN") = 0
                        r.v(sRegPre & "NPCR1_RXSEL") = 0
''                            Call ReleaseAlternateInputPin(r, "RXDC1_0")
''                            Call ReleaseAlternateInputPin(r, "RXDC1_1")
''                            Call ReleaseAlternateInputPin(r, "RXDC1_3")
                  End If
    End If
         
       Case "optCAN_NODE_RXD_1"
            If (iNr = 0) Then
                 Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                 r.v("CAN_USE_NODE0_RXD_PIN") = 1
                 r.v(sRegPre & "NPCR0_RXSEL") = 0
                 Call RequestAlternateInputPin(r, "RXDC0_0")
''                 Call ReleaseAlternateInputPin(r, "RXDC0_1")
''                 Call ReleaseAlternateInputPin(r, "RXDC0_2")
''                 Call ReleaseAlternateInputPin(r, "RXDC0_3")
            Else
               Call NodeRXDPinSelectionReset(r, vIndex, iNr)
               r.v("CAN_USE_NODE1_RXD_PIN") = 1
               r.v(sRegPre & "NPCR1_RXSEL") = 0
                 Call RequestAlternateInputPin(r, "RXDC1_0")
''                 Call ReleaseAlternateInputPin(r, "RXDC1_1")
''                 Call ReleaseAlternateInputPin(r, "RXDC1_3")
            End If
       
        Case "optCAN_NODE_RXD_2"
            If (iNr = 0) Then
                 Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_RXD_PIN") = 2
                r.v(sRegPre & "NPCR0_RXSEL") = 1
                    Call RequestAlternateInputPin(r, "RXDC0_1")
''                    Call ReleaseAlternateInputPin(r, "RXDC0_0")
''                    Call ReleaseAlternateInputPin(r, "RXDC0_2")
''                    Call ReleaseAlternateInputPin(r, "RXDC0_3")
             Else
               Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE1_RXD_PIN") = 2
                r.v(sRegPre & "NPCR1_RXSEL") = 1
                    Call RequestAlternateInputPin(r, "RXDC1_1")
''                    Call ReleaseAlternateInputPin(r, "RXDC1_0")
''                    Call ReleaseAlternateInputPin(r, "RXDC1_3")
             End If
         
        Case "optCAN_NODE_RXD_3"
                If (iNr = 0) Then
                Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_RXD_PIN") = 3
                r.v(sRegPre & "NPCR0_RXSEL") = 2
                    Call RequestAlternateInputPin(r, "RXDC0_2")
''                    Call ReleaseAlternateInputPin(r, "RXDC0_1")
''                    Call ReleaseAlternateInputPin(r, "RXDC0_3")
''                    Call ReleaseAlternateInputPin(r, "RXDC0_0")
            Else
                Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE1_RXD_PIN") = 3
                r.v(sRegPre & "NPCR1_RXSEL") = 3
                    Call RequestAlternateInputPin(r, "RXDC1_3")
''                    Call ReleaseAlternateInputPin(r, "RXDC1_1")
''    '                Call ReleaseAlternateInputPin(r, "RXDC1_3")
''                    Call ReleaseAlternateInputPin(r, "RXDC1_0")
            End If
            
        
        Case "optCAN_NODE_RXD_4"
            If (iNr = 0) Then
                Call NodeRXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_RXD_PIN") = 4
                r.v(sRegPre & "NPCR0_RXSEL") = 3
                Call RequestAlternateInputPin(r, "RXDC0_3")
''                Call ReleaseAlternateInputPin(r, "RXDC0_1")
''                Call ReleaseAlternateInputPin(r, "RXDC0_2")
''                Call ReleaseAlternateInputPin(r, "RXDC0_0")
            Else

            End If
            
        Case "optCAN_NODE_TXD_0"
            If (iNr = 0) Then
                  
                                
            If ((r.v(sNCRx & "_INIT") = 0) And (r.v("CAN_USE_NODE0_RXD_PIN") > 0)) And (Not (r.v("CAN_NPCR0_LBM") = 1)) Then
                   d = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                  "Do you really want to continue ?"
            If (Ask(d)) Then
                     Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                     Call DisableNodex(r, vIndex, iNr)
                      r.v("CAN_USE_NODE0_TXD_PIN") = 0

''                      Call ReleaseAlternateOutputPin(r, "TXDC0_0")
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_1")
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_2")
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_3")
              End If
               
               Else
                       pinid = r.v("CAN_USE_NODE0_TXD_PIN")
                       Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                       r.v("CAN_USE_NODE0_TXD_PIN") = 0
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_0")
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_1")
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_2")
''                      Call ReleaseAlternateOutputPin(r, "TXDC0_3")

            
            End If
       Else
            If ((r.v(sNCRx & "_INIT") = 0) And (r.v("CAN_USE_NODE1_RXD_PIN") > 0)) And (Not (r.v("CAN_NPCR1_LBM") = 1)) Then
                   d = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                  "Do you really want to continue ?"
            If (Ask(d)) Then
                Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                Call DisableNodex(r, vIndex, iNr)
                   r.v("CAN_USE_NODE1_TXD_PIN") = 0

''                       Call ReleaseAlternateOutputPin(r, "TXDC1_1")
''                       Call ReleaseAlternateOutputPin(r, "TXDC1_3")
''                       Call ReleaseAlternateOutputPin(r, "TXDC1_0")
                End If
             Else
               Call NodeTXDPinSelectionReset(r, vIndex, iNr)
               r.v("CAN_USE_NODE1_TXD_PIN") = 0

''                    Call ReleaseAlternateOutputPin(r, "TXDC1_1")
''                    Call ReleaseAlternateOutputPin(r, "TXDC1_3")
''                    Call ReleaseAlternateOutputPin(r, "TXDC1_0")
            End If
    End If
            
         Case "optCAN_NODE_TXD_1"
            If (iNr = 0) Then
                Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_TXD_PIN") = 1
''                Call ReleaseAlternateOutputPin(r, "TXDC0_1")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_2")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_3")
                Call RequestAlternateOutputPin(r, "TXDC0_0", ALT_FUN3)
                
            Else
               Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE1_TXD_PIN") = 1
                
''                Call ReleaseAlternateOutputPin(r, "TXDC1_1")
''                Call ReleaseAlternateOutputPin(r, "TXDC1_3")
                Call RequestAlternateOutputPin(r, "TXDC1_0", ALT_FUN3)
            End If
            
        Case "optCAN_NODE_TXD_2"
            
            If (iNr = 0) Then
                Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_TXD_PIN") = 2
''                Call ReleaseAlternateOutputPin(r, "TXDC0_2")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_3")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_0")
                Call RequestAlternateOutputPin(r, "TXDC0_1", ALT_FUN3)

            Else
                Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE1_TXD_PIN") = 2
                
''                Call ReleaseAlternateOutputPin(r, "TXDC1_3")
''                Call ReleaseAlternateOutputPin(r, "TXDC1_0")
                Call RequestAlternateOutputPin(r, "TXDC1_1", ALT_FUN3)
            
            End If
            
        Case "optCAN_NODE_TXD_3"
            
            If (iNr = 0) Then
                Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_TXD_PIN") = 3
''                Call ReleaseAlternateOutputPin(r, "TXDC0_1")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_0")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_3")
                Call RequestAlternateOutputPin(r, "TXDC0_2", ALT_FUN3)
           Else
                Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE1_TXD_PIN") = 3

''                Call ReleaseAlternateOutputPin(r, "TXDC1_1")
''                Call ReleaseAlternateOutputPin(r, "TXDC1_0")
                Call RequestAlternateOutputPin(r, "TXDC1_3", ALT_FUN3)
           End If
           
           Case "optCAN_NODE_TXD_4"
            If (iNr = 0) Then
                 Call NodeTXDPinSelectionReset(r, vIndex, iNr)
                r.v("CAN_USE_NODE0_TXD_PIN") = 4
''                Call ReleaseAlternateOutputPin(r, "TXDC0_1")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_2")
''                Call ReleaseAlternateOutputPin(r, "TXDC0_0")
                Call RequestAlternateOutputPin(r, "TXDC0_3", ALT_FUN3)
            Else
            
            End If
            
    End Select

     With c("optCAN_NODE_RXD_0")
            bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = 0)
    End With


        With e("optCAN_NODE_RXD_0")
            If (bDisabled) Then
              .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            End If
        End With

       With c("optCAN_NODE_RXD_1")
            bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "RXDC" & iNr & "_0")))
            .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = 1)
        End With

        With e("optCAN_NODE_RXD_1")
            If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXDC" & iNr & "_0")
            End If
            End If
        End With
        
        
         With c("optCAN_NODE_RXD_2")
             bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "RXDC" & iNr & "_1"))) 'Or (Not IsAlternatePinFree(r, "RXDC0_1")))
            .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = 2)
        End With

        With e("optCAN_NODE_RXD_2")

        If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXDC" & iNr & "_1")
            End If
            End If
        End With

         With c("optCAN_NODE_RXD_3")
        If (iNr = 0) Then
         bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "RXDC0_2")))
        Else
        bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "RXDC1_3")))
        End If
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = 3)
        End With

        With e("optCAN_NODE_RXD_3")
        If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
               .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (iNr = 0) Then
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXDC" & iNr & "_2")
                Else
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXDC1_3")
                End If
            End If
            End If
        End With

            If (iNr = 0) Then
         With c("optCAN_NODE_RXD_4")
           bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "RXDC0_3")))
            .Enabled = Not (bDisabled)
            If (iNr = 0) Then
                .Value = -CInt(r.v("CAN_USE_NODE0_RXD_PIN") = 4)
             End If
        End With

        With e("optCAN_NODE_RXD_4")
        If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXDC0_3")
            End If
        End If
        End With
End If
        With c("optCAN_NODE_TXD_0")
            bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
            .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") = 0)
        End With


        With e("optCAN_NODE_TXD_0")
            If (bDisabled) Then
              .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            End If
        End With

       With c("optCAN_NODE_TXD_1")
            bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "TXDC" & iNr & "_0")))
            .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") = 1)
        End With

        With e("optCAN_NODE_TXD_1")
            If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                 .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "TXDC" & iNr & "_0")
            End If
            End If
        End With
        
        
         With c("optCAN_NODE_TXD_2")
           bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "TXDC" & iNr & "_1")))
            .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") = 2)
        End With

        With e("optCAN_NODE_TXD_2")
            If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "TXDC" & iNr & "_1")
            End If
            End If
        End With
        
         With c("optCAN_NODE_TXD_3")
          If (iNr = 0) Then
            bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "TXDC0_2")))
            Else
            bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "TXDC1_3")))
            End If
            .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") = 3)
        End With

        With e("optCAN_NODE_TXD_3")
            If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (iNr = 0) Then
                  .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "TXDC" & iNr & "_2")
                Else
                    .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "TXDC1_3")
               End If
            End If
            End If
        End With

        If (iNr = 0) Then
            With c("optCAN_NODE_TXD_4")
               bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (Not IsAlternatePinFree(r, "TXDC0_3")))
                .Enabled = Not (bDisabled)
                .Value = -CInt(r.v("CAN_USE_NODE0_TXD_PIN") = 4)
        End With
             

        With e("optCAN_NODE_TXD_4")
           If (bDisabled) Then
            If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "TXDC0_3")
            End If
            End If
        End With
         End If
        
    
  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 iNr As Integer
  Dim vIndex As Variant
  Dim sVarPre As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "CAN" & vIndex
  iNr = 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", 50, 100, 3750, 1000, "Initialization")) Then Exit Function
        If (Not ps.AddCheck("chkINIT", 200, 300, 2750, 400, "Initialize the " & sVarPre & " node " & iNr & " (INIT)")) Then Exit Function

    '-------------------------------
    ' frame: frmCALM
    '-------------------------------
    If (Not ps.AddFrame("frmCALM", 50, 3600, 3750, 1300, "Analyzer Mode")) Then Exit Function
        If (Not ps.AddCheck("chkCALM", 200, 300, 3500, 800, "Enable the " & sVarPre & " analyzer mode; monitoring " & sVarPre & " bus traffic without participating in the " & sVarPre & " bus protocol itself (CALM)")) Then Exit Function

    '-------------------------------
    ' frame: frmInterrupts
    '-------------------------------
    If (Not ps.AddFrame("frmInterrupts", 50, 1300, 3750, 1850, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkTRIE", 200, 300, 3200, 400, "Enable interrupt generation when a message transfer is completed (TRIE)")) Then Exit Function
        If (Not ps.AddCheck("chkALIE", 200, 800, 3200, 400, "Enable interrupt upon a change/set of BOFF,EWARN, LLE, LOE or INIT (ALIE)")) Then Exit Function
        If (Not ps.AddCheck("chkLECIE", 200, 1300, 3200, 400, "Enable interrupt generation upon each update of the bit field LEC (LECIE)")) Then Exit Function

    '-------------------------------
    ' frame: frmINP
    '-------------------------------
    If (Not ps.AddFrame("frmINP", 3900, 1300, 4750, 1850, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddCombo("cboTRINP", 2600, 300, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTRINP", 0, 200, 300, 2300, 400, "Transfer OK interrupt node pointer (TRINP)")) Then Exit Function
        If (Not ps.AddCombo("cboALINP", 2600, 800, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblALINP", 0, 200, 800, 2300, 400, "Alert interrupt node pointer (ALINP)")) Then Exit Function
        If (Not ps.AddCombo("cboLECINP", 2600, 1300, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblLECINP", 0, 200, 1300, 2300, 400, "Last error code interrupt node pointer (LECINP)")) Then Exit Function

    '-------------------------------
    ' frame: frmLBM
    '-------------------------------
    If (Not ps.AddFrame("frmLBM", 3900, 100, 4750, 1000, "Loop Back Mode")) Then Exit Function
        If (Not ps.AddCheck("chkLBM", 200, 300, 3000, 300, "Enable the Loop-Back mode (LBM)")) Then Exit Function

    '-------------------------------
    ' frame: frmEWRNLVL
    '-------------------------------
    If (Not ps.AddFrame("frmEWRNLVL", 3900, 3600, 4750, 1300, "Error Warning Level")) Then Exit Function
        If (Not ps.AddText("txtEWRNLVL", 3550, 300, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblEWRNLVL", 0, 200, 350, 3150, 300, "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 bFrameDisabled As Boolean
  Dim sFrameDisabledTooltip As String
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim d As String
  Dim iNr As Integer
  Dim i As Integer
  Dim j As Integer
  Dim bFirstTime As Boolean
   
  Dim sNCRx As String  ' Node x Control Register
  Dim sNIPRx As String ' Node x Interrupt Pointer Register
  Dim sNPCRx As String ' Node x Port Control Register
  Dim sNBTRx As String ' Node x Bit Timing Register
  Dim sNECNTx As String ' Node x Error Counter Register

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

  sNCRx = sRegPre & "NCR" & iNr
  sNIPRx = sRegPre & "NIPR" & iNr
  sNPCRx = sRegPre & "NPCR" & iNr
  sNBTRx = sRegPre & "NBTR" & iNr
  sNECNTx = sRegPre & "NECNT" & iNr

  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(sNCRx & "_INIT") = 0
              
            Else
              d = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                  "Do you really want to continue ?"
              If (Ask(d)) Then
                Call DisableNodex(r, vIndex, iNr)
                If (r.v("CAN_NCR0_INIT") = 1 And r.v("CAN_NCR1_INIT") = 1) Then
                    r.v("CAN_USE_Init") = 0
                End If
              End If
            End If
        '---------------------------------------------------------------------
        ' control: chkCALM (action)
        '---------------------------------------------------------------------
        Case "chkCALM"
            If (v(1) = 1) Then
              r.v(sNCRx & "_CALM") = 1
              bFirstTime = True
            Else
              r.v(sNCRx & "_CALM") = 0
            End If

        '---------------------------------------------------------------------
        ' control: chkTRIE (action)
        '---------------------------------------------------------------------
        Case "chkTRIE"
            r.v(sNCRx & "_TRIE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkALIE (action)
        '---------------------------------------------------------------------
        Case "chkALIE"
            r.v(sNCRx & "_ALIE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkLECIE (action)
        '---------------------------------------------------------------------
        Case "chkLECIE"
            r.v(sNCRx & "_LECIE") = v(1)

        '---------------------------------------------------------------------
        ' control: cboTRINP (action)
        '---------------------------------------------------------------------
        Case "cboTRINP"
            r.v(sNIPRx & "_TRINP") = c("cboTRINP").ListIndex

        '---------------------------------------------------------------------
        ' control: cboLECINP (action)
        '---------------------------------------------------------------------
        Case "cboLECINP"
            r.v(sNIPRx & "_LECINP") = c("cboLECINP").ListIndex

        '---------------------------------------------------------------------
        ' control: cboALINP (action)
        '---------------------------------------------------------------------
        Case "cboALINP"
            r.v(sNIPRx & "_ALINP") = c("cboALINP").ListIndex

        '---------------------------------------------------------------------
        ' control: chkLBM (action)
        '---------------------------------------------------------------------
        Case "chkLBM"
        'If ((r.v(sNCRx & "_INIT") = 0) And ((r.v("CAN_USE_NODE"&iNr&"_TXD_PIN") > 0) and r.v("CAN_USE_NODE"&iNr&"_RXD_PIN")>0)))then
         If (r.v(sNCRx & "_INIT") = 0) And ((IsPinInterfaceDeselected(r, vIndex, iNr))) Then
         d = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                          "Do you really want to continue ?"
 
                    If (Ask(d)) Then
                     Call DisableNodex(r, vIndex, iNr)
                    r.v(sNPCRx & "_LBM") = v(1)
                    r.v(sNCRx & "_INIT") = 1
                   
                    End If
       Else
          r.v(sNPCRx & "_LBM") = v(1)
       End If

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

      Case Else
    End Select

   
    With c("chkINIT")
      ' disable condition
       ' bDisabled = IsModuleClockDisabled(r, vIndex) Or IsPinInterfaceDeselected(r, vIndex, iNr)
      If (IsModuleClockDisabled(r, vIndex)) Then
      bDisabled = True
      Else
      bDisabled = (IsPinInterfaceDeselected(r, vIndex, iNr) And (r.v(sNPCRx & "_LBM") = 0))
      End If
      .Enabled = Not (bDisabled)
      ' show condition
      .Value = -CInt(r.v(sNCRx & "_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 & GetTooltipPinInterfaceDeselected(r, vIndex, iNr)
        .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(" Loop Back Mode is not selected")
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' frame: frmInterrupts, frmCALM, frmINP, frmEWRNLVL and frmLBM (show)
    '-------------------------------------------------------------------------
  
    bFrameDisabled = IsModuleClockDisabled(r, vIndex) Or (r.v(sNCRx & "_INIT") = 1) 'Or IsPinInterfaceDeselected(r, vIndex, iNr) Or (r.v(sNCRx & "_INIT") = 1)
    ' tooltip if control is disabled
    sFrameDisabledTooltip = TOOLTIP_DISABLED_IF
    sFrameDisabledTooltip = sFrameDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    sFrameDisabledTooltip = sFrameDisabledTooltip & GetTooltipPinInterfaceDeselected(r, vIndex, iNr)
    If (r.v(sNCRx & "_INIT") = 1) Then
      sFrameDisabledTooltip = sFrameDisabledTooltip & FormatDisabledToolTip(TOOLTIP_DISABLED_NODE)
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCALM").Caption, c, e, bFrameDisabled, sFrameDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmInterrupts").Caption, c, e, bFrameDisabled, sFrameDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmINP").Caption, c, e, bFrameDisabled, sFrameDisabledTooltip, "")
  ''  Call SetDefaultPropertiesForAllControlsOnFrame(c("frmLBM").Caption, c, e, bFrameDisabled, sFrameDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmEWRNLVL").Caption, c, e, bFrameDisabled, sFrameDisabledTooltip, "")

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

    '-------------------------------------------------------------------------
    ' control: chkTRIE (show)
    '-------------------------------------------------------------------------
    With c("chkTRIE")
      .Value = -CInt(r.v(sNCRx & "_TRIE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkALIE (show)
    '-------------------------------------------------------------------------
    With c("chkALIE")
      .Value = -CInt(r.v(sNCRx & "_ALIE") = 1)
    End With

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

    '-------------------------------------------------------------------------
    ' control: cboTRINP (show)
    '-------------------------------------------------------------------------
    With c("cboTRINP")
      ' disable condition
      bDisabled = bFrameDisabled Or (r.v(sNCRx & "_TRIE") = 0)
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To (CAN_MAX_SRNS - 1)
        .AddItem "Use MultiCAN SRN " & i
      Next i
      .ListIndex = r.v(sNIPRx & "_TRINP")
    End With

    With e("cboTRINP")
      If (bDisabled) Then
        .DisabledToolTipText = sFrameDisabledTooltip
        If (r.v(sNCRx & "_TRIE") = 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 = bFrameDisabled Or (r.v(sNCRx & "_LECIE") = 0)
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To (CAN_MAX_SRNS - 1)
        .AddItem "Use MultiCAN SRN " & i
      Next i
      .ListIndex = r.v(sNIPRx & "_LECINP")
    End With

    With e("cboLECINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = sFrameDisabledTooltip
        If (r.v(sNCRx & "_LECIE") = 0) Then
          .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("interrupt generation upon each update of the 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: cboALINP (show)
    '-------------------------------------------------------------------------
    With c("cboALINP")
      ' disable condition
      bDisabled = bFrameDisabled Or (r.v(sNCRx & "_ALIE") = 0)
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To (CAN_MAX_SRNS - 1)
        .AddItem "Use MultiCAN SRN " & i
      Next i
      .ListIndex = r.v(sNIPRx & "_ALINP")
    End With

    With e("cboALINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = sFrameDisabledTooltip
        If (r.v(sNCRx & "_ALIE") = 0) Then
          .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("interrupt generation upon a change of BOFF or EWARN or upon a set LLE, LOE or INIT is disabled")
        End If
      Else
        ' tooltip if control is enabled
      End If
    End With

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

    With e("lblALINP")
      If (bDisabled) Then
        .DisabledToolTipText = e("cboALINP").DisabledToolTipText
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkLBM (show)
    '-------------------------------------------------------------------------
    With c("chkLBM")
    .Enabled = Not IsModuleClockDisabled(r, vIndex)
      .Value = -CInt(r.v(sNPCRx & "_LBM") = 1)
    End With
    
     With e("chkLBM")
     .DisabledToolTipText = TOOLTIP_DISABLED_IF
      If (bDisabled) Then
         If (IsModuleClockDisabled(r, vIndex)) Then
         .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Module clock is disabled")
        End If
    End If
      
        ' tooltip if control is enabled
      
    End With

    '-------------------------------------------------------------------------
    ' control: txtEWRNLVL (show)
    '-------------------------------------------------------------------------
    With c("txtEWRNLVL")
        .Text = FormatTextOutput(r.v(sNECNTx & "_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("frmDIV8", 100, 100, 8450, 1050, "Division of Module Clock by 8 (DIV8)")) Then Exit Function
        If (Not ps.AddOption("optDIV8_0", 200, 300, 4000, 300, "")) Then Exit Function
        If (Not ps.AddOption("optDIV8_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 iNr As Integer
  Dim d As String
  Dim uBR As BaudrateType
  Dim uTime As BaudrateType

  Dim sNCRx As String  ' Node x Control Register
  Dim sNIPRx As String ' Node x Interrupt Pointer Register
  Dim sNPCRx As String ' Node x Port Control Register
  Dim sNBTRx As String ' Node x Bit Timing Register
  Dim sNECNTx As String ' Node x Error Counter Register

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

  sNCRx = sRegPre & "NCR" & iNr
'  sNIPRx = sRegPre & "NIPR" & iNr
'  sNPCRx = sRegPre & "NPCR" & iNr
  sNBTRx = sRegPre & "NBTR" & iNr
'  sNECNTx = sRegPre & "NECNT" & iNr

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

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

        '---------------------------------------------------------------------
        ' control: optDIV8_0 (action)
        '---------------------------------------------------------------------
        Case "optDIV8_0"
            r.v(sNBTRx & "_DIV8") = 0
            Call UpdateNodexBaudrate(r, vIndex, iNr)

        '---------------------------------------------------------------------
        ' control: optDIV8_1 (action)
        '---------------------------------------------------------------------
        Case "optDIV8_1"
            r.v(sNBTRx & "_DIV8") = 1
            Call UpdateNodexBaudrate(r, vIndex, iNr)

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

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

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

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


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Baudrate (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or r.v(sNCRx & "_INIT") = 1  'Or IsPinInterfaceDeselected(r, vIndex, iNr)
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    ''d = d & GetTooltipPinInterfaceDeselected(r, vIndex, iNr)
    If (r.v(sNCRx & "_INIT") = 1) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DISABLED_NODE)
    End If
    Call SetDefaultPropertiesForAllControlsOnPage(Pagename, c, e, bDisabled, d, "")

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

    '-------------------------------------------------------------------------
    ' control: optDIV8_1 (show)
    '-------------------------------------------------------------------------
    With c("optDIV8_1")
       .Value = r.v(sNBTRx & "_DIV8") = 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, iNr) * 1000000 / _
              (2 ^ (1 - 1) * (r.v(sNBTRx & "_BRP") + 1) * _
              (3 + r.d(sNBTRx & "_TSEG1") + r.d(sNBTRx & "_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 & "[usec]"
      Else
        uTime = ConvertTime((1 / GetNodexClock(r, vIndex, iNr)) * 2 ^ (1 - 1) * _
                (r.v(sNBTRx & "_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" & iNr))
        .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(sNBTRx & "_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(sNBTRx & "_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(sNBTRx & "_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(sNBTRx & "_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(sNBTRx & "_TSEG1")) / (3 + r.d(sNBTRx & "_TSEG1") + r.d(sNBTRx & "_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: frmCFMOD
    '-------------------------------
    If (Not ps.AddFrame("frmCFMOD", 100, 100, 4150, 1200, "Frame Counter Mode (CFMOD)")) Then Exit Function
        If (Not ps.AddOption("optCFMOD_0", 200, 250, 1900, 300, "Frame counter mode")) Then Exit Function
        If (Not ps.AddOption("optCFMOD_1", 200, 550, 1900, 300, "Time stamp mode")) Then Exit Function
        If (Not ps.AddOption("optCFMOD_2", 200, 850, 1900, 300, "Bit timing mode")) Then Exit Function

    '-------------------------------
    ' frame: frmCFSEL2
    '-------------------------------
    If (Not ps.AddFrame("frmCFSEL2", 4400, 100, 4150, 5100, "Frame Counter Selection for Bit Timing Mode (CFSEL)")) Then Exit Function
        If (Not ps.AddOption("optCFSEL2_0", 200, 300, 3800, 650, "Whenever a dominant edge is monitored on the receive input the time between this edge and the most recent dominant edge is stored in CFC")) Then Exit Function
        If (Not ps.AddOption("optCFSEL2_1", 200, 1000, 3850, 700, "Whenever a recessive edge is monitored on the receive input the time between this edge and the most recent dominant edge is stored in CFC")) Then Exit Function
        If (Not ps.AddOption("optCFSEL2_2", 200, 1750, 3800, 700, "Whenever a dominant edge is received as a result of a transmitted dominant edge the time between both edges is stored in CFC")) Then Exit Function
        If (Not ps.AddOption("optCFSEL2_3", 200, 2500, 3850, 700, "Whenever a recessive edge is received as a result of a transmitted recessive edge the time between both edges is stored in CFC")) Then Exit Function
        If (Not ps.AddOption("optCFSEL2_4", 200, 3250, 3850, 850, "Whenever a dominant edge that qualifies for synchronization is monitored on the received input the time between this edge and the most recent sample point is stored in CFC")) Then Exit Function
        If (Not ps.AddOption("optCFSEL2_5", 200, 4150, 3850, 700, "With each start of a new bit time the time between the start of the new bit time and the start of the previous bit time is stored in CFC [11:0]")) Then Exit Function

    '-------------------------------
    ' frame: frmCount
    '-------------------------------
    If (Not ps.AddFrame("frmCount", 100, 1400, 4150, 1650, "Frame Count Selection for Frame Counter Mode")) Then Exit Function
        If (Not ps.AddCheck("chkCFSEL2", 200, 250, 3800, 400, "The counter is incremented each time a frame was transmitted correctly (CFSEL.2)")) Then Exit Function
        If (Not ps.AddCheck("chkCFSEL1", 200, 700, 3800, 400, "The counter is incremented each time a frame was received correctly (CFSEL.1)")) Then Exit Function
        If (Not ps.AddCheck("chkCFSEL0", 200, 1150, 3850, 400, "The counter is incremented each time a correct foreign frame was monitored on the bus (CFSEL.0)")) Then Exit Function

    '-------------------------------
    ' frame: frmInterrupt
    '-------------------------------
    If (Not ps.AddFrame("frmInterrupt", 100, 3150, 4150, 1250, "Frame Counter Interrupt")) Then Exit Function
        If (Not ps.AddCheck("chkCFCIE", 200, 300, 3600, 300, "Enable the counter overflow interrupt (CFCIE)")) Then Exit Function
        If (Not ps.AddCombo("cboCFCINP", 1950, 700, 2100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblCFCINP", 0, 200, 750, 1700, 300, "Node pointer (CFCINP)")) Then Exit Function

    '-------------------------------
    ' frame: frmCFC
    '-------------------------------
    If (Not ps.AddFrame("frmCFC", 100, 4450, 4150, 750, "Frame Counter")) Then Exit Function
        If (Not ps.AddText("txtCFC", 1950, 250, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblCFC", 0, 200, 300, 1575, 300, "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 bPageDisabled As Boolean
  Dim sPageDisabledTooltip As String
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim d As String
  Dim i As Integer

  Dim iNr As Integer
  Dim sNCRx As String  ' Node x Control Register
  Dim sNIPRx As String ' Node x Interrupt Pointer Register
  Dim sNPCRx As String ' Node x Port Control Register
  Dim sNBTRx As String ' Node x Bit Timing Register
  Dim sNECNTx As String ' Node x Error Counter Register
  Dim sNFCRx As String ' Node x Frame Counter Register

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

  sNCRx = sRegPre & "NCR" & iNr
  sNIPRx = sRegPre & "NIPR" & iNr
  sNFCRx = sRegPre & "NFCR" & iNr

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

  If (Pagename = "Frame Counter") Then
    '-------------------------------------------------------------------------
    ' page: FrameCounter (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optCFMOD_0 (action)
        '---------------------------------------------------------------------
        Case "optCFMOD_0"
            r.v(sNFCRx & "_CFMOD") = 0
            r.v(sNFCRx & "_CFCIE") = 0
            r.v(sNFCRx & "_CFSEL") = 0

        '---------------------------------------------------------------------
        ' control: optCFMOD_1 (action)
        '---------------------------------------------------------------------
        Case "optCFMOD_1"
            r.v(sNFCRx & "_CFMOD") = 1
            r.v(sNFCRx & "_CFSEL") = 0

        '---------------------------------------------------------------------
        ' control: optCFMOD_2 (action)
        '---------------------------------------------------------------------
        Case "optCFMOD_2"
            r.v(sNFCRx & "_CFMOD") = 2
            r.v(sNFCRx & "_CFSEL") = 0

        '---------------------------------------------------------------------
        ' control: chkCFSEL2 (action)
        '---------------------------------------------------------------------
        Case "chkCFSEL2"
            If (v(1) = 1) Then
              Call SetBit(r, sNFCRx & "_CFSEL", 2)
            Else
              Call ResetBit(r, sNFCRx & "_CFSEL", 2)
            End If

        '---------------------------------------------------------------------
        ' control: chkCFSEL1 (action)
        '---------------------------------------------------------------------
        Case "chkCFSEL1"
            If (v(1) = 1) Then
              Call SetBit(r, sNFCRx & "_CFSEL", 1)
            Else
              Call ResetBit(r, sNFCRx & "_CFSEL", 1)
            End If

        '---------------------------------------------------------------------
        ' control: chkCFSEL0 (action)
        '---------------------------------------------------------------------
        Case "chkCFSEL0"
            If (v(1) = 1) Then
              Call SetBit(r, sNFCRx & "_CFSEL", 0)
            Else
              Call ResetBit(r, sNFCRx & "_CFSEL", 0)
            End If

        '---------------------------------------------------------------------
        ' control: optCFSEL2_0 (action)
        '---------------------------------------------------------------------
        Case "optCFSEL2_0"
            r.v(sNFCRx & "_CFSEL") = 0

        '---------------------------------------------------------------------
        ' control: optCFSEL2_1 (action)
        '---------------------------------------------------------------------
        Case "optCFSEL2_1"
            r.v(sNFCRx & "_CFSEL") = 1

        '---------------------------------------------------------------------
        ' control: optCFSEL2_2 (action)
        '---------------------------------------------------------------------
        Case "optCFSEL2_2"
            r.v(sNFCRx & "_CFSEL") = 2

        '---------------------------------------------------------------------
        ' control: optCFSEL2_3 (action)
        '---------------------------------------------------------------------
        Case "optCFSEL2_3"
            r.v(sNFCRx & "_CFSEL") = 3

        '---------------------------------------------------------------------
        ' control: optCFSEL2_4 (action)
        '---------------------------------------------------------------------
        Case "optCFSEL2_4"
            r.v(sNFCRx & "_CFSEL") = 4

        '---------------------------------------------------------------------
        ' control: optCFSEL2_5 (action)
        '---------------------------------------------------------------------
        Case "optCFSEL2_5"
            r.v(sNFCRx & "_CFSEL") = 5

        '---------------------------------------------------------------------
        ' control: chkCFCIE (action)
        '---------------------------------------------------------------------
        Case "chkCFCIE"
            r.v(sNFCRx & "_CFCIE") = v(1)

        '---------------------------------------------------------------------
        ' control: cboCFCINP (action)
        '---------------------------------------------------------------------
        Case "cboCFCINP"
            r.v(sNIPRx & "_CFCINP") = c("cboCFCINP").ListIndex

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

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: FrameCounter (show)
    '-------------------------------------------------------------------------
    bPageDisabled = IsModuleClockDisabled(r, vIndex) Or (r.v(sNCRx & "_INIT") = 1) 'Or IsPinInterfaceDeselected(r, vIndex, iNr)
    ' tooltip if control is disabled
    sPageDisabledTooltip = TOOLTIP_DISABLED_IF
    sPageDisabledTooltip = sPageDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    ''sPageDisabledTooltip = sPageDisabledTooltip & GetTooltipPinInterfaceDeselected(r, vIndex, iNr)
    If (r.v(sNCRx & "_INIT") = 1) Then
      sPageDisabledTooltip = sPageDisabledTooltip & FormatDisabledToolTip(TOOLTIP_DISABLED_NODE)
    End If
    Call SetDefaultPropertiesForAllControlsOnPage(Pagename, c, e, bPageDisabled, sPageDisabledTooltip, "")

    '-------------------------------------------------------------------------
    ' control: optCFMOD_0 (show)
    '-------------------------------------------------------------------------
    With c("optCFMOD_0")
      .Value = (r.v(sNFCRx & "_CFMOD") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optCFMOD_1 (show)
    '-------------------------------------------------------------------------
    With c("optCFMOD_1")
      .Value = (r.v(sNFCRx & "_CFMOD") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optCFMOD_2 (show)
    '-------------------------------------------------------------------------
    With c("optCFMOD_2")
      .Value = (r.v(sNFCRx & "_CFMOD") = 2)
    End With

    '-------------------------------------------------------------------------
    ' frame: frmCount (show)
    '-------------------------------------------------------------------------
    bDisabled = bPageDisabled Or (r.v(sNFCRx & "_CFMOD") > 0)
    ' tooltip if control is disabled
    d = sPageDisabledTooltip
    If (r.v(sNFCRx & "_CFMOD") > 0) Then
      d = d & FormatDisabledToolTip("the frame counter mode is not selected")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCount").Caption, c, e, bDisabled, d, "")

    '-------------------------------------------------------------------------
    ' control: chkCFSEL2 (show)
    '-------------------------------------------------------------------------
    With c("chkCFSEL2")
      .Value = -CInt(IsBitSet(r, sNFCRx & "_CFSEL", 2) And r.v(sNFCRx & "_CFMOD") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: chkCFSEL1 (show)
    '-------------------------------------------------------------------------
    With c("chkCFSEL1")
      .Value = -CInt(IsBitSet(r, sNFCRx & "_CFSEL", 1) And r.v(sNFCRx & "_CFMOD") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: chkCFSEL0 (show)
    '-------------------------------------------------------------------------
    With c("chkCFSEL0")
      .Value = -CInt(IsBitSet(r, sNFCRx & "_CFSEL", 0) And r.v(sNFCRx & "_CFMOD") = 0)
    End With

    '-------------------------------------------------------------------------
    ' frame: frmCFSEL2 (show)
    '-------------------------------------------------------------------------
    bDisabled = bPageDisabled Or Not (r.v(sNFCRx & "_CFMOD") = 2)
    d = sPageDisabledTooltip
    If Not (r.v(sNFCRx & "_CFMOD") = 2) Then
      d = d & FormatDisabledToolTip("the bit timing mode is not selected")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCFSEL2").Caption, c, e, bDisabled, d, "")

    For i = 0 To 5
      '-------------------------------------------------------------------------
      ' control: optCFSEL2_x (show) (x = 0-5)
      '-------------------------------------------------------------------------
      With c("optCFSEL2_" & i)
        .Value = -CInt(r.v(sNFCRx & "_CFSEL") = i And r.v(sNFCRx & "_CFMOD") = 2)
      End With
    Next i

    '-------------------------------------------------------------------------
    ' frame: frmInterrupt and frmCFC (show)
    '-------------------------------------------------------------------------
    bDisabled = bPageDisabled
    d = sPageDisabledTooltip
    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(sNFCRx & "_CFCIE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: cboCFCINP (show)
    '-------------------------------------------------------------------------
    With c("cboCFCINP")
      ' disable condition
      bDisabled = bPageDisabled Or r.v(sNFCRx & "_CFCIE") = 0
      .Enabled = Not (bDisabled)
      ' show condition
      .Clear
      For i = 0 To (CAN_MAX_SRNS - 1)
        .AddItem "Use MultiCAN SRN " & i
      Next i
      .ListIndex = r.v(sNIPRx & "_CFCINP")
    End With

    With e("cboCFCINP")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = sPageDisabledTooltip
        If (r.v(sNFCRx & "_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(sNFCRx & "_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


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

  OnLoadPageTTCAN_Control = False

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

  OnLoadPageTTCAN_Control = True
End Function


'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if not enough
'        port pins are selected .
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the CAN node
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************
Function GetTooltipPinInterfaceDeselected(r As ProjectData, vIndex As Variant, iNr As Integer) As String
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim v As String
  Dim s As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  GetTooltipPinInterfaceDeselected = ""
  v = ""

     v = v & FormatDisabledToolTip("node pins are not selected")

  GetTooltipPinInterfaceDeselected = v
End Function
