Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\ParameterClass.cls
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "Include.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            25.05.00    final version for TC1775A
'        1.1  ste            20.07.00    the TC1775B has a new Loop-Back mode;
'                                        4 new function added
'        1.2  ste            02.11.00    1 new function added
'
'        ----------------------------------------------------------------------
'        3.1  ahe            13.08.02     final version for TC1775B, TC1765
'                                         - no changes
'        ----------------------------------------------------------------------
'        4.0  ste            21.08.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            18.09.03     function ConfigureSchedulerEntries added
'        ----------------------------------------------------------------------
'             ste            14.11.03     TC1766 and TC1796 merged
'        ----------------------------------------------------------------------
'             Sheshadri      21.10.05     OnShowPageLists modified wrt to TC1130
'                                         Listpos bug
'
'
'*****************************************************************************

'*****************************************************************************
' @Global Variables
'*****************************************************************************

Dim bFirstTime As Boolean


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

    OnLoad = False

    Dim vIndex As Variant
    Dim sVarPre As String
    Dim sRegPre As String

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

    '-------------------------------------------------------------------------
    ' page: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModuleClock(ps)) Then Exit Function

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

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

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

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

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

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

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

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

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

    '-------------------------------------------------------------------------
    ' End of pages
    '-------------------------------------------------------------------------
    
    ' call function to initialize the menu
    If (Not InitMenu(ps, "CAN\Dialog")) 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 successful operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError
    Dim vIndex As Variant
    Dim sVarPre As String
    Dim sRegPre As String

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

    OnChangingPage = False

    '-------------------------------------------------------------------------
    'page: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModuleClock(ps, Pagename)) Then Exit Function

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

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

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

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

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

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

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

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

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes(ps, Pagename, sVarPre)) 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 successful operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError

    Dim vIndex As Variant
    Dim sVarPre As String
    Dim sRegPre As String
    Dim sModule(0 To 0) As String

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

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: Module Clock
    '-------------------------------------------------------------------------
    sModule(0) = "CAN"
    If (Not OnShowPageModuleClock(ps, Controlname, Pagename, v)) Then Exit Function

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

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

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

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

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

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

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

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, sVarPre, v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    Exit Function
End Function


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

    OnClick = False

    '-------------------------------------------------------------------------
    ' Page : Nodes
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageNodes(ps, Controlname)) Then Exit Function

    '-------------------------------------------------------------------------
    ' Page : Control
    '-------------------------------------------------------------------------
   If (Not OnButtonClickOnPageControl(ps, Controlname)) Then Exit Function

    OnClick = True
    Exit Function

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


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful 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\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function


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

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

  OnLoadPageModuleClock = False
      If (Not ps.AddPage("Module Clock")) Then Exit Function

  OnLoadPageModuleClock = 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 OnChangingPageModuleClock(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
    
    Dim sIndex As String
    Dim sPrefix As String

    sIndex = "CAN"
    sPrefix = sIndex & "_"

  OnChangingPageModuleClock = False
      
      If (Not ps.ExtenderCollection("Module Clock").Loaded) And (Pagename = "Module Clock") Then
    
        ps.ExtenderCollection("Module Clock").Loaded = True
  
        '-------------------------------
        ' frame: frmMD
        '-------------------------------
        If (Not ps.AddFrame("frmCANEn", 100, 50, 5400, 1075, " CAN Disabled Flag (PMCON1) ")) Then Exit Function
            If (Not ps.AddOption("optCAN_DIS_0", 200, 250, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
            If (Not ps.AddOption("optCAN_DIS_1", 200, 625, 4800, 300, "Disable module; the clock input of peripheral is disabled")) Then Exit Function

        '-------------------------------
        ' frame: frmInputClock
        '-------------------------------
        If (Not ps.AddFrame("frmInputClock", 100, 1150, 5400, 1600, "Input Clock")) Then Exit Function
            If (Not ps.AddOption("optCAN_doubleFCLK", 200, 250, 4800, 300, "FCLK runs at 2 times the frequency as PCLK")) Then Exit Function
            If (Not ps.AddOption("optCAN_FCLK", 200, 625, 4800, 300, "FCLK runs at the same frequency as PCLK")) Then Exit Function
            If (Not ps.AddLabel("lbl_txt_InputClock", 0, 300, 1100, 3225, 300, "Input clock of the module [MHz]")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 1100, 1000, 300, "")) Then Exit Function

        '-----------------------------------
        ' frame: Access Mediator Protection
        '-----------------------------------
        If (Not ps.AddFrame("frmAMP", 100, 2850, 8500, 2500, "Access Mediator Protection")) Then Exit Function
        If (Not ps.AddOption("optWithAMP", 200, 250, 4800, 300, "Generate Functions with Access Mediator Protection :")) Then Exit Function
        If (Not ps.AddOption("optWithoutAMP", 200, 725, 4800, 300, "Generate Functions without Access Mediator Protection")) Then Exit Function
        If (Not ps.AddCombo("cboAMPChoice", 4700, 250, 1750, 200)) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_AMPNote", 0, 200, 1050, 3225, 300, "Note :")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_AMP", 0, 300, 1250, 8000, 400, "Access Mediator Registers {DATA0 to DATA3, ADL, ADH} are protected in functions of Functions2 page using below options :-")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_AMPPush/pop", 0, 300, 1750, 7000, 300, "Push/Pop :-  Pushes to stack in the beginning of function, Pops out of stack at the end of function.")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_AMPInt", 0, 300, 2000, 8000, 400, "ISR Enable/Disable :-  Disables Global ISR {EA=0} in the beginning of function, Enables Global ISR {EA=1} at the end of function.")) Then Exit Function
      End If
'  End If
  OnChangingPageModuleClock = 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 OnShowPageModuleClock(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageModuleClockError
   
    Dim sVarPre As String
    Dim sRegPre As String

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

  OnShowPageModuleClock = False
  
  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim bDisabled   As Boolean
  Dim vIndex As Variant
  
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
    
If (Pagename = "Module Clock") Then
  
      Select Case (Controlname)
      
         Case "optCAN_DIS_0"
            r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 0
 
           
        Case "optCAN_DIS_1"
            r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1
           r.v("CAN_USE_Init") = 0
            
         Call DisableModule(r, vIndex)
         r.v("CAN_USE_NODE0_RXD_PIN") = 0
         r.v("CAN_USE_NODE0_TXD_PIN") = 0
         r.v("CAN_USE_NODE1_RXD_PIN") = 0
         r.v("CAN_USE_NODE1_TXD_PIN") = 0
         Call DisableLBMx(r, vIndex, 0)
         Call DisableLBMx(r, vIndex, 1)
         r.v(SCU_PREFIX & "CMCON_FCCFG") = 1
         'r.v(sRegPre & "NAME_SRN14") = 0'by ashish for Access modifier protection
         r.v(sRegPre & "USE_SRN14") = 0  'by ashish for Access modifier protection
         r.v(sRegPre & "USE_SRN13") = 0
         
         Case "optCAN_doubleFCLK"
          r.v(SCU_PREFIX & "CMCON_FCCFG") = 1
          
          Case "optCAN_FCLK"
           r.v(SCU_PREFIX & "CMCON_FCCFG") = 0
       
        Case "optWithAMP"
          ' r.v(sRegPre & "NAME_SRN14") = 0
          r.v(sRegPre & "USE_SRN13") = 0

        Case "optWithoutAMP"
          ' r.v(sRegPre & "NAME_SRN14") = 1
          r.v(sRegPre & "USE_SRN13") = 1
           r.v(sRegPre & "USE_SRN14") = 0
           

          Case "cboAMPChoice"
          r.v(sRegPre & "USE_SRN14") = c("cboAMPChoice").ListIndex
     End Select
   

     With c("optCAN_DIS_0")
         bDisabled = False
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 0)
         If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 0) Then
         
         End If
     End With

    With c("optCAN_DIS_1")
         bDisabled = False
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
         If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Then
         End If
     End With
   
     
    With c("optCAN_doubleFCLK")
         If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Then
         bDisabled = True
         End If
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(SCU_PREFIX & "CMCON_FCCFG") = 1)
         Call UpdateNodexBaudrate(r, vIndex, 0)
         Call UpdateNodexBaudrate(r, vIndex, 1)
     End With
     
     With c("optCAN_FCLK")
         If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Then
         bDisabled = True
         End If
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(SCU_PREFIX & "CMCON_FCCFG") = 0)
          Call UpdateNodexBaudrate(r, vIndex, 0)
          Call UpdateNodexBaudrate(r, vIndex, 1)
     End With
      
      With c("lbl_box_InputClock")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
        .Enabled = Not (bDisabled)
          If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Then
             .Caption = CALCULATION_NOT_POSSIBLE
           Else
           .Caption = Get_fFCLK(r)
          End If
      End With
      
      With e("optCAN_FCLK")
        If (bDisabled) Then
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End With
      
       With e("optCAN_doubleFCLK")
        If (bDisabled) Then
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End With
      
      With e("lbl_box_InputClock")
        If (bDisabled) Then
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End With

      With c("lbl_txt_InputClock")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
        .Enabled = Not (bDisabled)
          If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Then
          End If
      End With
     
     With c("optWithAMP")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
        .Enabled = Not (bDisabled)
        
       ' .Value = -CInt(r.v(sRegPre & "NAME_SRN14") = 0)
       .Value = -CInt(r.v(sRegPre & "USE_SRN13") = 0)
       End With


      With c("optWithoutAMP")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
        .Enabled = Not (bDisabled)
       ' .Value = -CInt(r.v(sRegPre & "NAME_SRN14") = 1)
       .Value = -CInt(r.v(sRegPre & "USE_SRN13") = 1)
       
      End With

        With c("cboAMPChoice")
         .Clear
           .AddItem "Push / Pop"
           .AddItem "ISR Enable/Disable"
         .ListIndex = r.v(sRegPre & "USE_SRN14")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Or (r.v(sRegPre & "USE_SRN13") = 1))
          .Enabled = Not bDisabled
         End With
         
          With e("optWithAMP")
        If (bDisabled) Then
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End With
      
        With e("optWithoutAMP")
        If (bDisabled) Then
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End With
      
        With e("cboAMPChoice")
        If (bDisabled) Then
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          If (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1) Then
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
          Else
           .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Option Generate Functions with Access mediator protection is not selected")
        End If
        End If
      End With
         
End If

  OnShowPageModuleClock = True
  Exit Function

OnShowPageModuleClockError:
  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 'Nodes'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageNodes(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageNodes = False

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

  OnLoadPageNodes = 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 successful operation
'        False           else
'*****************************************************************************
Function OnChangingPageNodes(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim j As Integer
  Dim iNode As Integer

  OnChangingPageNodes = False
  
  If (Not ps.ExtenderCollection("Nodes").Loaded) And (Pagename = "Nodes") Then
    ps.ExtenderCollection("Nodes").Loaded = True
  
    '-------------------------------
    ' frame: frmNode
    '-------------------------------
    If (Not ps.AddFrame("frmNode", 100, 100, 8400, 1000, "CAN Nodes")) Then Exit Function
      For j = 0 To 0
        For i = 0 To (CAN_MAX_NODES - 1)
          iNode = i + j * 4
          If (CAN_MAX_NODES < 4) Then
            If (Not ps.AddButton("btnNode" & iNode, 2200 + i * 2300, 400 + j * 550, 1800, 350, "Node " & iNode)) Then Exit Function
          Else
            If (Not ps.AddButton("btnNode" & iNode, 250 + i * 2050, 400 + j * 550, 1800, 350, "Node " & iNode)) Then Exit Function
          End If
        Next i
      Next j

  End If
  OnChangingPageNodes = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageNodes(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageNodesError

  OnShowPageNodes = False

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

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

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

  If (Pagename = "Nodes") Then
   
    '-------------------------------------------------------------------------
    ' page: Nodes (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)

        Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Nodes (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' frame: frmNode (show)
    '-------------------------------------------------------------------------
   bDisabled = IsModuleClockDisabled(r, vIndex)
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmNode").Caption, c, e, bDisabled, d, "")


    For i = 0 To (CAN_MAX_NODES - 1)
      '-------------------------------------------------------------------------
      ' control: btnNode0 (show)
      '-------------------------------------------------------------------------
      With c("btnNode" & i)
      End With
    Next i

  End If
  
  OnShowPageNodes = True
  Exit Function

OnShowPageNodesError:
  errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Nodes' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageNodes(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageNodesError

  OnButtonClickOnPageNodes = False

  Dim np As Peripherals
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim j As Integer

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

  '------------------------------------------------------------------------------------
  ' btnNodex (click)   (x = 0- )
  '------------------------------------------------------------------------------------
  For j = 0 To (CAN_MAX_NODES - 1)
    If (Controlname = "btnNode" & j) Then
      Set np = New Peripherals
      np.Parameters.Add ("x")
      np.Parameters.v("x") = vIndex
      np.Parameters.Add ("Number")
      np.Parameters.v("Number") = j
      Set np.ProjectData = ps.ProjectData
      np.Caption = "Configure " & sVarPre & " Node " & j
      np.Scriptfile = DefGetPath("Scripts") & "\CAN\Nodex.DAVE"
      np.Show
    End If
  Next j

  OnButtonClickOnPageNodes = True
  Exit Function

OnButtonClickOnPageNodesError:
  errorbox "Can not process the click", 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

  If (Not ps.AddPage("MOs")) 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 successful operation
'        False           else
'*****************************************************************************
Function OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim j As Integer
  Dim iNode As Integer

  OnChangingPageControl = False
  
  If (Not ps.ExtenderCollection("MOs").Loaded) And (Pagename = "MOs") Then
    ps.ExtenderCollection("MOs").Loaded = True

    '-------------------------------
    ' frame: frmMO
    '-------------------------------
    If (Not ps.AddFrame("frmMO", 50, 100, 8550, 4500, "CAN Message Objects (MO)")) Then Exit Function
      If (CAN_MAX_OBJECTS > 64) Then
        For i = 0 To (CAN_MAX_OBJECTS - 1)
          If (Not ps.AddButton("btnMO" & i, 200 + (i Mod 10) * 830, 400 + (i \ 10) * 300, 730, 300, "MO " & i)) Then Exit Function
        Next i
      Else
        For i = 0 To (CAN_MAX_OBJECTS - 1)
          If (Not ps.AddButton("btnMO" & i, 300 + (i Mod 8) * 1000, 400 + (i \ 8) * 450, 900, 300, "MO " & i)) Then Exit Function
        Next i
      End If
  
  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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

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

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

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

  If (Pagename = "MOs") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)

        Case Else
    End Select

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

    bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)

    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (IsAllNodesDeselected(r, vIndex)) Then
      d = d & FormatDisabledToolTip("all " & sVarPre & " nodes are deselected")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmMO").Caption, c, e, bDisabled, d, "")
    
    '-------------------------------------------------------------------------
    ' control: btnMO0 (show)
    '-------------------------------------------------------------------------
    With c("btnMO0")
    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 OnClick function of the associated
'        module if a button on the page 'Control' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageControl(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageControlError

  OnButtonClickOnPageControl = False

  Dim np As Peripherals
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim j As Integer

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

  '------------------------------------------------------------------------------------
  ' btnMOx (click)   (x = 0-)
  '------------------------------------------------------------------------------------
  For j = 0 To (CAN_MAX_OBJECTS - 1)
    If (Controlname = "btnMO" & j) Then
      Set np = New Peripherals
      np.Parameters.Add ("x")
      np.Parameters.v("x") = vIndex
      np.Parameters.Add ("Number")
      np.Parameters.v("Number") = j
      Set np.ProjectData = ps.ProjectData
      np.Caption = "Configure " & sVarPre & " Message Object (MO" & j & ")"
      np.Scriptfile = DefGetPath("Scripts") & "\CAN\Objx.DAVE"
      np.Show

      Exit For
    End If
  Next j

  OnButtonClickOnPageControl = True
  Exit Function

OnButtonClickOnPageControlError:
  errorbox "Can not process the click", 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 'Lists'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageLists(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageLists = False

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

  OnLoadPageLists = 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 successful operation
'        False           else
'*****************************************************************************
Function OnChangingPageLists(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim j As Integer
  Dim iNode As Integer

  OnChangingPageLists = False
  
  If (Not ps.ExtenderCollection("Lists").Loaded) And (Pagename = "Lists") Then
    ps.ExtenderCollection("Lists").Loaded = True

    If (Not ps.AddIRTab32("List")) Then Exit Function
    If (Not ps.AddFrame("frmDummy1", 6120, 200, 2500, 350, "")) Then Exit Function
      If (Not ps.AddLabel("lblDummy1", 0, 100, 120, 2000, 300, "List 0 (unallocated MOs)")) Then Exit Function
    If (Not ps.AddFrame("frmDummy", 0, 4500, 8600, 800, "")) Then Exit Function
      If (Not ps.AddLabel("lblDummy", 0, 100, 250, 8400, 400, "Note: To change the level (position in the list) and the list of an message object (MO), click on it, drag it to its new position and drop it. To set an message object to the unallocated list, click on it, drag it to the 'List 0' list and drop it.")) Then Exit Function
    bFirstTime = True

  End If
  OnChangingPageLists = 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 successful operation
'        False           else
'*****************************************************************************

Public Function OnShowPageLists(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error Resume Next
  OnShowPageLists = False

    Dim sVarPre As String
    Dim sRegPre As String
    Dim vIndex As Variant
    Dim r As ProjectData
    Dim p As Parameters
    Dim c As Collection
    Dim vHighestLevel As Variant
    Dim iNr As Integer
    Dim f() As Integer
    Dim s() As String
    ReDim s(1 To CAN_MAX_NODES)
    ReDim f(1 To CAN_MAX_NODES)

    Dim iBase As Integer

    ' Previous MO
    Dim PMO_OldIndex As Integer
    Dim PMO_OldListNumber As Integer
    Dim PMO_OldListPosition As Integer
    Dim PMO_NewIndex As Integer
    Dim PMO_NewListNumber As Integer
    Dim PMO_NewListPosition As Integer

    ' Next MO
    Dim NMO_OldIndex As Integer
    Dim NMO_OldListNumber As Integer
    Dim NMO_OldListPosition As Integer
    Dim NMO_NewIndex As Integer
    Dim NMO_NewListNumber As Integer
    Dim NMO_NewListPosition As Integer

    ' Current MO
    Dim MO_OldIndex As Integer
    Dim MO_OldListNumber As Integer
    Dim MO_OldListPosition As Integer
    Dim MO_NewIndex As Integer         ' 0 to (CAN_MAX_OBJECTS - 1)
    Dim MO_NewListNumber As Integer    ' 0 to (CAN_MAX_NODES - 1)
    Dim MO_NewListPosition As Integer  ' 1 to CAN_MAX_OBJECTS  (0 is List 0)

    Set c = ps.ControlCollection
    Set r = ps.ProjectData
    Set p = ps.Parameters

    vIndex = ps.Parameters.v("x")
    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"
    MO_NewIndex = GetIndexFromName(v(1)) ' 0 to (CAN_MAX_OBJECTS - 1)
    MO_NewListNumber = v(3) + 1   ' v(3) is 0 to (CAN_MAX_NODES - 1); List is 1 to CAN_MAX_NODES
    MO_NewListPosition = v(2) ' 1 to CAN_MAX_OBJECTS  (0 is List 0)
    MO_OldIndex = MO_NewIndex
    MO_OldListNumber = r.v(sRegPre & "MOCTR" & MO_OldIndex & "_LIST")
    MO_OldListPosition = r.v(sVarPre & "_MO" & MO_OldIndex & "_LISTPOS")
    
    ' the index of the previous MO is saved as PPREV of the MO_OldIndex
    PMO_OldIndex = GetPPREV(r, vIndex, MO_OldIndex)
    
    ' the index of the next MO is saved as PNEXT of the MO_OldIndex
    NMO_OldIndex = GetPNEXT(r, vIndex, MO_OldIndex)

    If (Pagename = "Lists") Then
      '-------------------------------------------------------------------------
      ' page: List (action)
      '-------------------------------------------------------------------------
      If (Controlname = "List") Then
        If (MO_OldListNumber = 0) Then ' MO from List0 to List x
          ' update LIST of MO_NewIndex
          r.v(sRegPre & "MOCTR" & MO_NewIndex & "_LIST") = MO_NewListNumber
          r.v(sVarPre & "_MO" & MO_NewIndex & "_LISTPOS") = MO_NewListPosition

          ' update PPREV of MO_NewIndex
          Call UpdatePPREV(r, vIndex, MO_NewIndex)
          ' update PNEXT of MO_NewIndex
          Call UpdatePNEXT(r, vIndex, MO_NewIndex)

          PMO_NewIndex = GetPPREV(r, vIndex, MO_NewIndex)
          NMO_NewIndex = GetPNEXT(r, vIndex, MO_NewIndex)

          ' update PPREV of MO_NewIndex
          Call UpdatePPREV(r, vIndex, NMO_NewIndex)
          ' update PNEXT of MO_NewIndex
          Call UpdatePNEXT(r, vIndex, PMO_NewIndex)

          ' if MO_NewIndex will be part of a FIFO
          iBase = IsObjFIFOSlave(r, vIndex, MO_NewIndex)
          If (iBase >= 0) Then
            Debug.Print "Set FIFO slave " & MO_NewIndex & " of Base object " & iBase
            SetValuesForFIFOSlave(r, vIndex, iBase, MO_NewIndex)
          End If
        Else
          If (MO_NewListPosition = 0) Then ' MO from Listx to List0

            '------- Update the TOP and BOT pointer of a FIFO base object if the TOP or BOT slave is moved ---
            ' if MO_OldIndex was part of a FIFO
            iBase = IsObjFIFOSlave(r, vIndex, MO_OldIndex)
            If (iBase >= 0) Then
              ' if MO_OldIndex = TOP of the FIFO Base Objects then set TOP of the Base objects to PREV of the MO_OldIndex
              If (r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = MO_OldIndex) Then
                ' if TOP = BOT then set 0xFF for the pointer
                If (r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = r.v(sRegPre & "MOFGPR" & iBase & "_BOT")) Then ' only one MO for the FIFO
                  Debug.Print "Update Base Object " & iBase & " mit 0xFF"
                  r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = &HFF
                  r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = &HFF
                Else
                  Debug.Print "Update Base Object " & iBase & " mit Slave Object " & PMO_OldIndex
                  r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = PMO_OldIndex
                End If
              End If

              ' if MO_OldIndex = BOT of the FIFO Base Objects then set BOT of the Base objects to NEXT of the MO_OldIndex
              If (r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = MO_OldIndex) Then
                ' if TOP = BOT then set 0xFF for the pointer
                If (r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = r.v(sRegPre & "MOFGPR" & iBase & "_BOT")) Then ' only one MO for the FIFO
                  Debug.Print "Update Base Object " & iBase & " mit 0xFF"
                  r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = &HFF
                  r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = &HFF
                Else
                  Debug.Print "Update Base Object " & iBase & " mit Slave Object " & NMO_OldIndex
                  r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = NMO_OldIndex
                End If
              End If
            End If

                        '--------- for an FIFO base object all slaves are released
            ' the MO is no longer valid
            ' the standard mode was set and all FIFO slaves are released
             SetStandardMode(r, vIndex, MO_NewIndex)
             r.v(sRegPre & "MOCTR" & MO_NewIndex & "_MSGVAL") = 0
            '--------- the actual object is released ----------------------
            ' update LIST of MO_NewIndex
            r.v(sRegPre & "MOCTR" & MO_NewIndex & "_LIST") = 0
            r.v(sVarPre & "_MO" & MO_NewIndex & "_LISTPOS") = 0
            r.v(sRegPre & "MOCTR" & MO_NewIndex & "_CTRL") = 0

            '--------- the pointer PPREV and PNEXT are updated ------------
            If (NMO_OldIndex <> MO_NewIndex) Then
              ' update PPREV of NMO_OldIndex
              Call UpdatePPREV(r, vIndex, NMO_OldIndex)
            End If
            If (PMO_OldIndex <> MO_NewIndex) Then
              ' update PNEXT of PMO_OldIndex
              Call UpdatePNEXT(r, vIndex, PMO_OldIndex)
            End If

          Else ' MO from Listx to Listy

            ' if MO_OldIndex was part of a FIFO
            iBase = IsObjFIFOSlave(r, vIndex, MO_OldIndex)
            If (iBase >= 0) Then
              Debug.Print "Reset FIFO slave " & MO_OldIndex & " of Base object " & iBase 'NOT ASH
              If (iBase <> MO_OldIndex) Then
                ResetValuesForFIFOSlave(r, vIndex, iBase, MO_OldIndex)
              End If
            End If
            
            '------- Update the TOP and BOT pointer of a FIFO base object if the TOP or BOT slave is moved ---
            ' if MO_OldIndex was part of a FIFO
            iBase = IsObjFIFOSlave(r, vIndex, MO_OldIndex)
            If (iBase >= 0) Then
              ' if MO_OldIndex = TOP of the FIFO Base Objects then set TOP of the Base objects to PREV of the MO_OldIndex
              If (r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = MO_OldIndex) Then
                ' if TOP = BOT then set 0xFF for the pointer
                If (r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = r.v(sRegPre & "MOFGPR" & iBase & "_BOT")) Then ' only one MO for the FIFO
                  Debug.Print "Update Base Object " & iBase & " mit 0xFF"
                  r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = &HFF
                  r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = &HFF
                Else
                  Debug.Print "Update Base Object " & iBase & " mit Slave Object " & PMO_OldIndex
                  r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = PMO_OldIndex
                End If
              End If

              ' if MO_OldIndex = BOT of the FIFO Base Objects then set BOT of the Base objects to NEXT of the MO_OldIndex
              If (r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = MO_OldIndex) Then
                ' if TOP = BOT then set 0xFF for the pointer
                If (r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = r.v(sRegPre & "MOFGPR" & iBase & "_BOT")) Then ' only one MO for the FIFO
                  Debug.Print "Update Base Object " & iBase & " mit 0xFF"
                  r.v(sRegPre & "MOFGPR" & iBase & "_TOP") = &HFF
                  r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = &HFF
                Else
                  Debug.Print "Update Base Object " & iBase & " mit Slave Object " & NMO_OldIndex
                  r.v(sRegPre & "MOFGPR" & iBase & "_BOT") = NMO_OldIndex
                  r.v(sRegPre & "MOFGPR" & iBase & "_CUR") = NMO_OldIndex
                End If
              End If
            End If

            

            ' update LIST of MO_NewIndex
            r.v(sRegPre & "MOCTR" & MO_NewIndex & "_LIST") = MO_NewListNumber
            r.v(sVarPre & "_MO" & MO_NewIndex & "_LISTPOS") = MO_NewListPosition
'Sheshadri:- Following code modifications are imported from TC1130 to fix the bug
'Commented by Kazmi to fix the CAN Listpos bug
'Reason for change - All Objects are not getting updated here
            ' update PPREV of NMO_OldIndex
            'Call UpdatePPREV(r, vIndex, NMO_OldIndex)
            ' update PNEXT of PMO_OldIndex
            'Call UpdatePNEXT(r, vIndex, PMO_OldIndex)

            ' update PPREV of MO_NewIndex
            'Call UpdatePPREV(r, vIndex, MO_NewIndex)
            ' update PNEXT of MO_NewIndex
            'Call UpdatePNEXT(r, vIndex, MO_NewIndex)
'End Commented by Kazmi
                        Dim iKaz As Integer
                        For iKaz = 0 To (CAN_MAX_OBJECTS - 1)
'                        For iKaz = 0 To 63
                                If (r.v(sVarPre & "_MO" & iKaz & "_LISTPOS") <> 0) Then
                                        Call UpdatePPREV(r, vIndex, iKaz)
                                        Call UpdatePNEXT(r, vIndex, iKaz)
                                End If
                        Next iKaz

           ' PMO_NewIndex = GetPPREV(r, vIndex, MO_NewIndex)
           ' NMO_NewIndex = GetPNEXT(r, vIndex, MO_NewIndex)

            ' update PPREV of MO_NewIndex
            Call UpdatePPREV(r, vIndex, NMO_NewIndex)
            ' update PNEXT of MO_NewIndex
            Call UpdatePNEXT(r, vIndex, PMO_NewIndex)

            ' if MO_NewIndex will be part of a FIFO
            iBase = IsObjFIFOSlave(r, vIndex, MO_NewIndex)
            If (iBase >= 0) Then
              ' the MO was an FIFO base object and is now a FIFO slave, so the
              ' complete old FIFO with all slaves are released
              SetStandardMode(r, vIndex, MO_NewIndex)
              Debug.Print "Set FIFO slave " & MO_NewIndex & " of Base object " & iBase
'             SetValuesForFIFOSlave(r, vIndex, iBase, MO_NewIndex)
            End If
          End If
        End If
      End If

      '-------------------------------------------------------------------------
      ' page: List (show)
      '-------------------------------------------------------------------------
      For iNr = 1 To CAN_MAX_NODES
        If (r.v(sRegPre & "NCR" & iNr - 1 & "_INIT") = 0) Then
          f(iNr) = (CAN_MAX_OBJECTS + 1)
          s(iNr) = "List " & iNr & " (Node " & iNr - 1 & ")"
        Else
          f(iNr) = 1
          s(iNr) = "List " & iNr & " (n.c.)"
        End If
      Next iNr


      With c("List")
        .Freeze
        .Clear
        .Init s, f
        vHighestLevel = 0
        For iNr = 0 To (CAN_MAX_OBJECTS - 1)
'          If (r.v(ir.Enabled) = 1) Then
            .Level = r.v(sVarPre & "_MO" & iNr & "_LISTPOS")
            If (r.v(sVarPre & "_MO" & iNr & "_LISTPOS") > vHighestLevel) Then
              vHighestLevel = r.v(sVarPre & "_MO" & iNr & "_LISTPOS")
            End If
            .Group = r.v(sRegPre & "MOCTR" & iNr & "_LIST") - 1
            .Sourcename = "MO" & iNr
'          End If
        Next iNr
'        .SeekList MO_Name
       ' If (bFirstTime = True) Then
          .TopLevel = vHighestLevel
       '   bFirstTime = False
        'End If
        .Melt
      End With
    End If

  OnShowPageLists = True
End Function


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

  OnLoadPageSRNs = False

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

  OnLoadPageSRNs = 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 successful operation
'        False           else
'*****************************************************************************
Function OnChangingPageSRNs(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim i As Integer

  OnChangingPageSRNs = False
  
  If (Not ps.ExtenderCollection("SRNs").Loaded) And (Pagename = "SRNs") Then
    ps.ExtenderCollection("SRNs").Loaded = True
  
    '-------------------------------
    ' frame: frmSRN
    '-------------------------------
    If (Not ps.AddFrame("frmSRN", 100, 100, 8400, 200 + CAN_MAX_SRNS * 315, "MultiCAN Service Request Node Enable Control")) Then Exit Function
      For i = 0 To (CAN_MAX_SRNS - 1)
        If (Not ps.AddCheck("chkSRC" & i, 200, 250 + i * 300, 4500, 300, "Enable the MultiCAN service request node " & i & " (SRE)")) Then Exit Function
      Next i

  End If
  OnChangingPageSRNs = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageSRNs(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageSRNsError

  OnShowPageSRNs = False

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

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

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

  If (Pagename = "SRNs") Then
         Select Case (Controlname)
             Case "chkSRC0"
                  If (v(1) = 1) Then
                    'r.v("IEN0_ET2") = 1    ' Commented by jag on 29/03/06 bcoz itz affecting in T2 Int checkbox in T2 module
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR5_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
                   r.v("CAN_USE_SRN0") = 1
                   
                Else
                   'r.v("IEN0_ET2") = 0
                     r.v("CAN_USE_SRN0") = 0  ' Commented by jag on 29/03/06 bcoz itz affecting in T2 Int checkbox in T2 module
                    
             End If
             
             Case "chkSRC1"
                  If (v(1) = 1) Then
                    'r.v("IEN1_EADC") = 1
                    If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                  End If
                  r.v("CAN_USE_SRN1") = 1
                Else
                     r.v("CAN_USE_SRN1") = 0
                    If (r.v("CAN_USE_SRN2") = 0) Then
                        'r.v("IEN1_EADC") = 0
                    End If
             End If
             
             Case "chkSRC2"
                  If (v(1) = 1) Then
                    'r.v("IEN1_EADC") = 1
                    If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                    End If
                   r.v("CAN_USE_SRN2") = 1
                Else
                    r.v("CAN_USE_SRN2") = 0
                    If (r.v("CAN_USE_SRN1") = 0) Then
                        'r.v("IEN1_EADC") = 0
                   End If
                     
             End If
             
             Case "chkSRC3"
                  If (v(1) = 1) Then
                    'r.v("IEN1_EXM") = 1
                    If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR9_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                    End If
                    r.v("CAN_USE_SRN3") = 1
                Else
                   'r.v("IEN1_EXM") = 0
                     r.v("CAN_USE_SRN3") = 0
             End If
             
             Case "chkSRC4"
                  If (v(1) = 1) Then
                    'r.v("IEN1_ECCIP0") = 1
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR10_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
                   r.v("CAN_USE_SRN4") = 1
                Else
                   'r.v("IEN1_ECCIP0") = 0
                     r.v("CAN_USE_SRN4") = 0
             End If
             
             Case "chkSRC5"
                  If (v(1) = 1) Then
                    'r.v("IEN1_ECCIP1") = 1
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR11_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
                   r.v("CAN_USE_SRN5") = 1
                Else
                   'r.v("IEN1_ECCIP1") = 0
                     r.v("CAN_USE_SRN5") = 0
             End If
             
             Case "chkSRC6"
                  If (v(1) = 1) Then
                    'r.v("IEN1_ECCIP2") = 1
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR12_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
                   r.v("CAN_USE_SRN6") = 1
                Else
                   'r.v("IEN1_ECCIP2") = 0
                     r.v("CAN_USE_SRN6") = 0
             End If
             
             Case "chkSRC7"
                  If (v(1) = 1) Then
                    'r.v("IEN1_ECCIP3") = 1
                   If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR13_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                   End If
                   r.v("CAN_USE_SRN7") = 1
                Else
                   r.v("IEN1_ECCIP3") = 0
                     r.v("CAN_USE_SRN7") = 0
             End If
             
       End Select
                 
             
                 With c("chkSRC0")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
        '.Value = -CInt(r.v("IEN0_ET2") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN0") = 1)
         End With
         
          With c("chkSRC1")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_EADC") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN1") = 1)
         End With
         
         With c("chkSRC2")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_EADC") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN2") = 1)
         End With
         
          With c("chkSRC3")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_EXM") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN3") = 1)
         End With
         
         With c("chkSRC4")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_ECCIP0") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN4") = 1)
         End With
         
          With c("chkSRC5")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_ECCIP1") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN5") = 1)
         End With
         
          With c("chkSRC6")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_ECCIP2") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN6") = 1)
         End With
         
          With c("chkSRC7")
         bDisabled = IsModuleClockDisabled(r, vIndex) Or IsAllNodesDeselected(r, vIndex)
        .Enabled = Not (bDisabled)
         '.Value = -CInt(r.v("IEN1_ECCIP3") = 1)
         .Value = -CInt(r.v("CAN_USE_SRN7") = 1)
         End With
     '' End Select
     '' End With
      
   For i = 0 To (CAN_MAX_SRNS - 1)
      With e("chkSRC" & i)
        If (bDisabled) Then
          ' tooltip if control is disabled
          .DisabledToolTipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
          If (IsAllNodesDeselected(r, vIndex)) Then
            
          .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("node pin selection is not made")
          .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("node initialzation is not selected")
          End If
        Else
          ' tooltip if control is enabled
        End If
      End With
    Next i

  End If

  OnShowPageSRNs = True
  Exit Function

OnShowPageSRNsError:
  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 a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions = False

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

  OnLoadPageFunctions = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next


  Dim vIndex As Variant
  Dim sVarPre As String
  Dim n As String
  Dim i As Integer
  Dim j As Integer
  Dim pos As Long
  Dim aFunctions(1 To 16) As String

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

  OnChangingPageFunctions = False

  If (Not ps.ExtenderCollection("Functions").Loaded) And (Pagename = "Functions") Then
    ps.ExtenderCollection("Functions").Loaded = True
    '  --------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100, 30, 4300, 680, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chkCAN_USE_Init", 200, 230, 1100, 325, "CAN_vInit")) Then Exit Function
      If (Not ps.Addtext("txtCAN_NAME_Init", 2000, 230, 1800, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4300, 30, 4275, 680, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.Addtext("txtCAN_CFile", 1600, 230, 2100, 325)) Then Exit Function
      If (Not ps.AddLabel("lblCAN_CFile", 0, 200, 230, 1800, 270, CAPTION_LBL_CFILE)) Then Exit Function

    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
 '    initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

'     Functions and Macros
    i = LBound(aFunctions)
    For j = 0 To (CAN_MAX_SRNS - 1)
      aFunctions(i) = "SRN" & j
      i = i + 1
    Next j

    If (Not ps.AddFrame("fraLibrary3", 100, 800, 4300, 4500, "Function Library for Interrupt Service Routines")) Then Exit Function
			If (Not ps.AddOption("optWithGernericISR", 200, 250, 3800, 300, "Generate Source code in ISR")) Then Exit Function
			If (Not ps.AddOption("optWithoutGernericISR", 200, 625, 3800, 300, "Generate Empty ISR")) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          'If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 325 + (300 * (i - 1)), 1300, 350, "CAN_vi" & aFunctions(i))) Then Exit Function
          If (i = 1) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR5Isr")) Then Exit Function
          ElseIf (i = 2) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR6Isr")) Then Exit Function
          ElseIf (i = 3) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR6Isr")) Then Exit Function
          ElseIf (i = 4) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR9Isr")) Then Exit Function
          ElseIf (i = 5) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR10Isr")) Then Exit Function
          ElseIf (i = 6) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR11Isr")) Then Exit Function
          ElseIf (i = 7) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR12Isr")) Then Exit Function
          ElseIf (i = 8) Then
              If (Not ps.AddCheck("chk_" & aFunctions(i), 200, 1000 + (300 * (i - 1)), 2000, 350, "SHINT_viXINTR13Isr")) Then Exit Function
          End If
        ''  If (Not ps.Addtext("txt_" & aFunctions(i), 4500, 240 + (300 * (i - 1)), 3800, 270)) Then Exit Function
        End If
      Next i
      If (Not ps.AddLabel("lblNOTE", 0, 200, 3500, 3820, 900, "NOTE:")) Then Exit Function
      If (Not ps.AddLabel("lblNOTE1", 0, 200, 3750, 3820, 900, "In Generate Empty ISR option user needs to explicitly handle NODE, Message objects interrupts.")) Then Exit Function
      
       If (Not ps.AddFrame("fraFunLibraryX", 4300, 800, 4275, 4500, "Function Library")) Then Exit Function
    pos = 0
    
    If (Not ps.AddCheck("chkCAN_USE_ReadEN", 200, 325 + pos * 300, 2300, 350, "CAN_vReadEN")) Then Exit Function
    'If (Not ps.Addtext("txtCAN_NAME_GetCANAdrValue", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function

     pos = pos + 1
     
    If (Not ps.AddCheck("chkCAN_USE_WriteEN", 200, 325 + pos * 300, 2400, 350, "CAN_vWriteEN")) Then Exit Function
    'If (Not ps.Addtext("txtCAN_NAME_GetCANAdrValue", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function
     pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_WriteCANAddress", 200, 325 + pos * 300, 2500, 350, "CAN_vWriteCANAddress")) Then Exit Function
    'If (Not ps.Addtext("txtCAN_NAME_WriteCANAddress", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function
    pos = pos + 1
    
     If (Not ps.AddCheck("chkCAN_USE_WriteCANAdrValue", 200, 325 + pos * 300, 2500, 350, "CAN_vWriteAMData")) Then Exit Function
    'If (Not ps.Addtext("txtCAN_NAME_WriteCANAddress", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_WriteCANData", 200, 325 + pos * 300, 2600, 350, "CAN_vWriteCANData")) Then Exit Function
   ' If (Not ps.Addtext("txtCAN_NAME_WriteCANData", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function
    pos = pos + 1
     
     If (Not ps.AddCheck("chkCAN_USE_SetListCommand", 200, 325 + pos * 300, 2600, 350, "CAN_vSetListCommand")) Then Exit Function
   ' If (Not ps.Addtext("txtCAN_NAME_SetListCommand", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function
    pos = pos + 1
    
     If (Not ps.AddCheck("chkCAN_USE_GetCANData", 200, 325 + pos * 300, 2500, 350, "CAN_ulGetCANData")) Then Exit Function
   ' If (Not ps.Addtext("txtCAN_NAME_GetCANData", 4500, 250 + pos * 300, 3800, 270)) Then Exit Function
    pos = pos + 1
    
  End If

  OnChangingPageFunctions = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFunctionsError

  OnShowPageFunctions = False
    
  Dim i As Integer
  Dim j As Integer
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String
  Dim vIndex As Variant
  Dim sFctName As String
  Dim d As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim iNr As Integer
  Dim sNCRx As String
  Dim sNPCRx As String ' Node x Port Control Register
  
  sVarPre = "CAN"
  sRegPre = sVarPre & "_"
  sNCRx = sRegPre & "NCR" & iNr
  sNPCRx = sRegPre & "NPCR" & iNr
 
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass
  
  If (Pagename = "Functions") Then
  
        r.v("CAN_USE_SRN15") = 1
        r.v("CAN_USE_WriteCANAdrValue") = 1  'sVarPre & "_vWriteCANAdrValue"

        r.v("CAN_NAME_SRN15") = "CAN_pushAMRegs/_popAMRegs"
        r.v("CAN_NAME_WriteCANAdrValue") = "CAN_vWriteAMData"  'sVarPre & "_vWriteCANAdrValue"
    
    Call RefreshFunctionDescriptions(func, r)
    
     Select Case Controlname
        Case "chkCAN_USE_Init"

            r.v("CAN_USE_Init") = v(1)
                     
        Case "txtCAN_NAME_Init"
            If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkCAN_USE_Init").Caption)) Then
                r.v("CAN_NAME_Init") = v(1)
         Else
                Exit Function
            End If
        
        Case "txtCAN_CFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblCAN_CFile").Caption)) Then
                r.v("CAN_CFile") = v(1)
            Else
               Exit Function
            End If
          
        Case "optWithGernericISR"
            If (Ask("By selecting 'Generate Source code in ISR'" & vbCrLf & "Generic code for NODE & MO ISR will be generated by DAvE." & vbCrLf & "Do you want to continue ?")) Then
		        r.v("CAN_USE_UserDefined2") = 2
			End if
           
        Case "optWithoutGernericISR"
            If (Ask("By selecting 'Generate Empty ISR'" & vbCrLf & "Generic code for NODE & MO ISR will not be generated. User needs to handle in USER CODE section." & vbCrLf & "Do you want to continue ?")) Then
		        r.v("CAN_USE_UserDefined2") = 0
			End if
    End Select     ' case Controlname

    
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)
     If (r.v("CAN_USE_Init") = 1) Then
        r.v("CAN_USE_WriteCANAddress") = 1
        r.v("CAN_USE_WriteCANData") = 1
        r.v("CAN_USE_WriteCANAdrValue") = 1
        r.v("CAN_USE_SetListCommand") = 1
        r.v("CAN_USE_ReadEN") = 1
        r.v("CAN_USE_WriteEN") = 1
        r.v(sVarPre & "_USE_SRN15") = 1
    End If

    '-------------------------------------------------------------------------
    ' control: chkCAN_USE_Init (show)
    '-------------------------------------------------------------------------
   If (IsModuleClockDisabled(r, vIndex)) Then
        bDisabled = True
   ElseIf (IsAllNodesDeselected(r, vIndex)) Then
        bDisabled = True
   Else
        bDisabled = False
   End If
   
    c("chkCAN_USE_Init").Enabled = Not bDisabled
    c("chkCAN_USE_Init").Value = -CInt(r.v("CAN_USE_Init") = 1)

    With e("chkCAN_USE_Init")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, "")) Then
                .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
             ElseIf (IsPinInterfaceDeselected(r, vIndex, iNr)) And (r.v(sNPCRx & "_LBM") = 0) Then 'And IsPinInterfaceDeselected(r, vindex, 1)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("nodes pin selection is not made")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Loop Back Mode is not selected")
            ElseIf (r.v(sNCRx & "_INIT") = 1) Then
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Nodes initialization is not selected")
            End If
        Else
            .EnabledTooltipText = FormatFunctionToolTip(r, func, "CAN_NAME_Init")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtCAN_NAME_Init (show)
    '-------------------------------------------------------------------------
    With c("txtCAN_NAME_Init")
        bDisabled = (r.v("CAN_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.s("CAN_NAME_Init"), "S")
    End With

    With e("txtCAN_NAME_Init")
        If (bDisabled) Then
               .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End With

     With c("lblCAN_CFile")
        bDisabled = (r.v("CAN_USE_Init") = 0)
        .Enabled = Not bDisabled
    End With

    With e("lblCAN_CFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

    With c("txtCAN_CFile")
        bDisabled = (r.v("CAN_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("CAN_CFile"), "S")
    End With

    With e("txtCAN_CFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With
    
     With c("optWithGernericISR")
         bDisabled = (r.v("CAN_USE_Init") = 0)
         .Enabled = Not (bDisabled)
		 .Value = -CInt(r.v("CAN_USE_UserDefined2") = 2)
     End With

    With e("optWithGernericISR")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

    With c("optWithoutGernericISR")
         bDisabled = (r.v("CAN_USE_Init") = 0)
         .Enabled = Not (bDisabled)
		 .Value = -CInt(r.v("CAN_USE_UserDefined2") = 0)
     End With
    With e("optWithoutGernericISR")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

    With c("lblNOTE")
    bDisabled = (r.v("CAN_USE_Init") = 0)
       .Enabled = Not (bDisabled)
    End With

    With c("lblNOTE1")
    bDisabled = (r.v("CAN_USE_Init") = 0)
       .Enabled = Not (bDisabled)
    End With
     If (Not UnableShowFunction(ps, v, func, "ReadEN")) Then Exit Function
     If (Not UnableShowFunction(ps, v, func, "WriteEN")) Then Exit Function
     If (Not UnableShowFunction(ps, v, func, "WriteCANAddress")) Then Exit Function
     If (Not UnableShowFunction(ps, v, func, "WriteCANAdrValue")) Then Exit Function
     If (Not UnableShowFunction(ps, v, func, "WriteCANData")) Then Exit Function
     If (Not UnableShowFunction(ps, v, func, "SetListCommand")) Then Exit Function
        
        For i = 0 To (CAN_MAX_SRNS - 1)
              sFctName = "SRN" & i
              sName = sVarPre & "_NAME_" & sFctName

          With c("chk_SRN" & i)
            .Enabled = False 'Not bDisabled
            .Value = -CInt((r.v("CAN_USE_Init") = 1)) And (r.v("CAN_USE_" & sFctName) = 1)
          End With
        
          bDisabled = True
        
          With e("chk_SRN" & i)
              If (bDisabled) Then
                If (IsModuleClockDisabled(r, vIndex)) Then
                      .DisabledToolTipText = TOOLTIP_DISABLED_IF
                      .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
                Else
                        .DisabledToolTipText = TOOLTIP_DISABLED_ISR & vbCrLf & FormatFunctionToolTip(r, func, sName)
                End If
                    .EnabledTooltipText = FormatFunctionToolTip(r, func, sName)
            End If

          End With
        Next i
     Call RefreshFunctionDescriptions(func, r)
    If (Not UpdateFunction(ps, Controlname, v, "GetCANData")) Then Exit Function
    bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
    

     If (Not ShowFunction(ps, v, func, "GetCANData")) Then Exit Function
      Call RefreshFunctionDescriptions(func, r)
''    If ((r.v("CAN_USE_GetMsgObj") = 1) Or (r.v("CAN_USE_ReadFIFO") = 1) Or (r.v("CAN_USE_GetCANData") = 1)) Then
''          r.v("CAN_USE_GetCANData") = 1
''      Else
''          r.v("CAN_USE_GetCANData") = 0
''    End If
''
''    If (Not UpdateFunction(ps, Controlname, v, "GetCANData")) Then Exit Function
''
''    If (r.v("CAN_USE_GetMsgObj") = 1) Or (r.v("CAN_USE_ReadFIFO") = 1) Then
''         If (Not UnableShowFunction(ps, v, func, "GetCANData")) Then Exit Function
''     Else
''         If (Not ShowFunction(ps, v, func, "GetCANData")) Then Exit Function
''    End If

  End If
  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionsError:
  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 a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions2(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions2 = False

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

  OnLoadPageFunctions2 = 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 successful operation
'        False           else
'''''*****************************************************************************
Public Function OnChangingPageFunctions2(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  OnChangingPageFunctions2 = False

  Dim vIndex As Variant
  Dim sVarPre As String
  Dim n As String
  Dim i As Integer
  Dim j As Integer
  Dim aFunctions(1 To 16) As String

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

 Dim pos As Long
 If (Not ps.ExtenderCollection("Functions2").Loaded) And (Pagename = "Functions2") Then
   ps.ExtenderCollection("Functions2").Loaded = True

 
 If (Not ps.AddFrame("fraFunLibrary2", 100, 50, 8475, 5300, "Function Library 1")) Then Exit Function
    pos = 0
    
    If (Not ps.AddCheck("chkCAN_USE_GetMsgObj", 200, 250 + pos * 300, 1700, 380, "CAN_vGetMsgObj")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_GetMsgObj", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_RequestMsgObj", 200, 250 + pos * 300, 2300, 380, "CAN_ubRequestMsgObj")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_RequestMsgObj", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_NewData", 200, 250 + pos * 300, 2400, 380, "CAN_ubNewData")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_NewData", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_Transmit", 200, 250 + pos * 300, 2500, 380, "CAN_vTransmit")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_Transmit", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_ConfigMsgObj", 200, 250 + pos * 300, 2500, 380, "CAN_vConfigMsgObj")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_ConfigMsgObj", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_LoadData", 200, 250 + pos * 300, 2300, 380, "CAN_vLoadData")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_LoadData", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_DelMsgObj", 200, 250 + pos * 300, 2300, 380, "CAN_ubDelMsgObj")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_DelMsgObj", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_MsgLost", 200, 250 + pos * 300, 2900, 380, "CAN_ubMsgLost")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_MsgLost", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_ReleaseObj", 200, 250 + pos * 300, 2600, 380, "CAN_vReleaseObj")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_ReleaseObj", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
        
    If (Not ps.AddCheck("chkCAN_USE_SetMSGVAL", 200, 250 + pos * 300, 2600, 380, "CAN_vSetMSGVAL")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_SetMSGVAL", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
       
    If (Not ps.AddCheck("chkCAN_USE_WriteFIFO", 200, 250 + pos * 300, 2800, 380, "CAN_ubWriteFIFO")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_WriteFIFO", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_ReadFIFO", 200, 250 + pos * 300, 2800, 380, "CAN_ubReadFIFO")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_ReadFIFO", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_GetTxErrorCounter", 200, 250 + pos * 300, 2800, 380, "CAN_ubGetTxErrorCounter")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_GetTxErrorCounter", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_GetRxErrorCounter", 200, 250 + pos * 300, 2800, 380, "CAN_ubGetRxErrorCounter")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_GetRxErrorCounter", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkCAN_USE_GetErrorTransferDirection", 200, 250 + pos * 300, 3000, 380, "CAN_ubGetErrorTransferDirection")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_GetErrorTransferDirection", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkCAN_USE_GetErrorIncrement", 200, 250 + pos * 300, 3000, 380, "CAN_ubGetErrorIncrement")) Then Exit Function
    If (Not ps.Addtext("txtCAN_NAME_GetErrorIncrement", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function

    
  End If

  OnChangingPageFunctions2 = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions2(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  
  On Error GoTo OnShowPageFunctions2Error
  OnShowPageFunctions2 = False

  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean

  Dim func As FunctionClass
  Dim sName As String
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim d As String
  Dim i As Integer
  Dim sFctName As String
Dim aFunctions(1 To 16) As String

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


  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

If (Pagename = "Functions2") Then
    Call RefreshFunctionDescriptions(func, r)

    If (Not UpdateFunction(ps, Controlname, v, "GetMsgObj")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "RequestMsgObj")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "NewData")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "Transmit")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ConfigMsgObj")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "LoadData")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "DelMsgObj")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "MsgLost")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReleaseObj")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetMSGVAL")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "WriteFIFO")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadFIFO")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetTxErrorCounter")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetRxErrorCounter")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetErrorTransferDirection")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetErrorIncrement")) Then Exit Function

''    If (r.v("CAN_USE_GetMsgObj") = 1) Or (r.v("CAN_USE_ReadFIFO") = 1) Then
''          r.v("CAN_USE_GetCANData") = 1
''    End If
''    If (r.v("CAN_USE_GetMsgObj") = 0) And (r.v("CAN_USE_ReadFIFO") = 0) Then
''          r.v("CAN_USE_GetCANData") = 0
''    End If
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)

     'For i = 0 To (CAN_MAX_SRNS - 1)
'      If (Not UpdateFunction(ps, Controlname, v, "CAN_viSRN0")) Then Exit Function

   'Next i

    
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)

    '-------------------------------------------------------------------------
    ' control: chkCAN_USE_Init (show)
    '-------------------------------------------------------------------------
    bDisabled = (r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
    

     If (Not ShowFunction(ps, v, func, "GetMsgObj")) Then Exit Function
    
    If (Not ShowFunction(ps, v, func, "RequestMsgObj")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "NewData")) Then Exit Function

    If (Not ShowFunction(ps, v, func, "Transmit")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ConfigMsgObj")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "LoadData")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "DelMsgObj")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "MsgLost")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReleaseObj")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetMSGVAL")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "WriteFIFO")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadFIFO")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "GetTxErrorCounter")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "GetRxErrorCounter")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "GetErrorTransferDirection")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "GetErrorIncrement")) Then Exit Function
''    If (Not ShowFunction2(sVarPre, ps, func, v)) Then Exit Function
  End If
  OnShowPageFunctions2 = True
  Exit Function

OnShowPageFunctions2Error:
  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 a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParameters = False

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

  OnLoadPageParameters = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageParameters = False

  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fraCAN_HFile", 100, 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.Addtext("txtCAN_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lblCAN_HFile", 0, 200, 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function

  End If

  OnChangingPageParameters = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageParametersError
  OnShowPageParameters = False
    
Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim iChannel As Integer

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


  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtCAN_HFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblCAN_HFile").Caption)) Then
                r.v("CAN_HFile") = v(1)
            End If

    End Select

    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' control: lblCAN_HFile (show)
    '-------------------------------------------------------------------------
    With c("lblCAN_HFile")
      bDisabled = (r.v("CAN_USE_Init") = 0)
      .Enabled = Not bDisabled
    End With

    With e("lblCAN_HFile")
      If (bDisabled) Then
        .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtSSC_HFile (show)
    '-------------------------------------------------------------------------
    With c("txtCAN_HFile")
      bDisabled = (r.v("CAN_USE_Init") = 0)
      .Enabled = Not bDisabled
      .Text = FormatTextOutput(r.v("CAN_HFile"), "S")
    End With

    With e("txtCAN_HFile")
      If (bDisabled) Then
        .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
      End If
    End With


  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowPageParametersError:
    errorbox "Can not show page", Err.Description
    Exit Function
End Function
'*****************************************************************************
'Description:
'        This function extracts the index of a Message Object (MO) from the
'        MO name.
'-----------------------------------------------------------------------------
'Parameters:
'        MONmae          name of the Message Object
'-----------------------------------------------------------------------------
'Returns:
'        index of a MO
'*****************************************************************************
Function GetIndexFromName(MOName As Variant) As Integer
  On Error Resume Next
  Dim iNr As Integer

  GetIndexFromName = 0
  For iNr = 0 To (CAN_MAX_OBJECTS - 1)
    If (MOName = "MO" & iNr) Then
      GetIndexFromName = iNr
      Exit For
    End If
  Next iNr
End Function
'*****************************************************************************
'Description:
'        This function sets the PPREV pointer of the given MO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        MOIndex         index of the Message Object
'        Value           new value of the PPREV
'-----------------------------------------------------------------------------
'Returns:
'
'*****************************************************************************
Sub SetPPREV(r As ProjectData, vIndex As Variant, MOIndex As Integer, Value As Integer)
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
 
  r.v(sRegPre & "MOCTR" & MOIndex & "_CTRL") = GetPNEXT(r, vIndex, MOIndex) * 2 ^ 8 + Value

End Sub


'*****************************************************************************
'Description:
'        This function sets the PNEXT pointer of the given MO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        MOIndex         index of the Message Object
'        Value           new value of the PNEXT
'-----------------------------------------------------------------------------
'Returns:
'
'*****************************************************************************
Sub SetPNEXT(r As ProjectData, vIndex As Variant, MOIndex As Integer, Value As Integer)
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

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

  r.v(sRegPre & "MOCTR" & MOIndex & "_CTRL") = Value * 2 ^ 8 + GetPPREV(r, vIndex, MOIndex)
End Sub


'*****************************************************************************
'Description:
'        This function updates the PNEXT pointer of the given MO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        MOIndex         index of the Message Object
'-----------------------------------------------------------------------------
'Returns:
'
'*****************************************************************************
Sub UpdatePNEXT(r As ProjectData, vIndex As Variant, MOIndex As Integer)
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim tmp As Integer
  Dim tmpPos As Integer
  Dim iNr As Integer

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

  ' search the next MO
  tmp = MOIndex ' for the last MO in the list; pointer to itself
  tmpPos = 200 ' for the first found MO
  For iNr = 0 To (CAN_MAX_OBJECTS - 1) ' search all MO numbers
    ' only if the same lists are used
    If (r.v(sRegPre & "MOCTR" & iNr & "_LIST") = r.v(sRegPre & "MOCTR" & MOIndex & "_LIST")) Then
      ' if the position in the list of the found MO greater then the position of the actual MO
      If (r.v(sVarPre & "_MO" & iNr & "_LISTPOS") > r.v(sVarPre & "_MO" & MOIndex & "_LISTPOS")) Then
        ' if the position in the list of the found MO lower then the position of the last found MO
        If (r.v(sVarPre & "_MO" & iNr & "_LISTPOS") < tmpPos) Then
          tmp = iNr
          tmpPos = r.v(sVarPre & "_MO" & iNr & "_LISTPOS")
        End If
      End If
    End If
  Next iNr
  
  Call SetPNEXT(r, vIndex, MOIndex, tmp)
End Sub


'*****************************************************************************
'Description:
'        This function updates the PPREV pointer of the given MO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        MOIndex         index of the Message Object
'-----------------------------------------------------------------------------
'Returns:
'
'*****************************************************************************
Sub UpdatePPREV(r As ProjectData, vIndex As Variant, MOIndex As Integer)
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim tmp As Integer
  Dim tmpPos As Integer
  Dim iNr As Integer

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

  ' search the previous MO
  tmp = MOIndex ' for the last MO in the list; pointer to itself
  tmpPos = -1 ' for the first found MO
  For iNr = 0 To (CAN_MAX_OBJECTS - 1) ' search all MO numbers
    ' only if the same lists are used
    If (r.v(sRegPre & "MOCTR" & iNr & "_LIST") = r.v(sRegPre & "MOCTR" & MOIndex & "_LIST")) Then
      ' LISTPOS must be greater then 0
      If (r.v(sVarPre & "_MO" & iNr & "_LISTPOS") > 0) Then
        ' if the position in the list of the found MO lower then the position of the actual MO
        If (r.v(sVarPre & "_MO" & iNr & "_LISTPOS") < r.v(sVarPre & "_MO" & MOIndex & "_LISTPOS")) Then
          ' if the position in the list of the found MO greater then the position of the last found MO
          If (r.v(sVarPre & "_MO" & iNr & "_LISTPOS") > tmpPos) Then
            tmp = iNr
            tmpPos = r.v(sVarPre & "_MO" & iNr & "_LISTPOS")
          End If
        End If
      End If
    End If
  Next iNr

  Call SetPPREV(r, vIndex, MOIndex, tmp)
End Sub

'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the Project Data Object
'        Controlname     control name
'        v()             value array
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function UpdateFunction(ps As Peripherals, Controlname As String, v() As Variant, sName As String) As Boolean
  On Error GoTo ExitLabel
  UpdateFunction = False

  Dim r As ProjectData
  Dim c As Collection

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

  '---------------------------------------------------------------------
  ' control: chkCAN_USE_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "chkCAN_USE_" & sName) Then
    r.v("CAN_USE_" & sName) = v(1)
  End If

  '---------------------------------------------------------------------
  ' control: txtCAN_NAME_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "txtCAN_NAME_" & sName) Then
    If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkCAN_USE_" & sName).Caption)) Then
        r.v("CAN_NAME_" & sName) = v(1)
    Else
        Exit Function
    End If
  End If

  UpdateFunction = True
ExitLabel:
End Function

'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        v()             value array
'        func            reference to the function object
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function ShowFunction(ps As Peripherals, v() As Variant, func As FunctionClass, sName As String) As Boolean
  On Error GoTo ExitLabel
  ShowFunction = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  
  Dim vIndex As Variant

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

  '-------------------------------------------------------------------------
  ' control: chkCAN_USE_.. (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("chkCAN_USE_" & sName)
    ' disable condition
    Select Case sName
    
       Case Else
            bDisabled = (r.v("CAN_USE_Init") = 0)

    End Select

    .Enabled = Not bDisabled
    .Value = -CInt((r.v("CAN_USE_Init") = 1) And (r.v("CAN_USE_" & sName) = 1))
  End With


  With e("chkCAN_USE_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        Select Case sName
            
            Case "Isr"      ' ISR functions are always disabled
                .DisabledToolTipText = TOOLTIP_DISABLED_ISR & vbCrLf & FormatFunctionToolTip(r, func, "CAN_NAME_" & sName)

            Case Else
                If (IsModuleClockDisabled(r, vIndex)) Then
                      .DisabledToolTipText = TOOLTIP_DISABLED_IF
                      .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = GetDisabledFunctionToolTipEntry(func, "CAN_NAME_" & sName)
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                End If
        End Select
    Else
        ' tooltip if control is enabled
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "CAN_NAME_" & sName)
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txtCAN_NAME_... (show)
  '-------------------------------------------------------------------------
 With c("txtCAN_NAME_" & sName)
    bDisabled = c("chkCAN_USE_" & sName).Value = 0
    .Enabled = Not bDisabled
    .Text = FormatTextOutput(r.s("CAN_NAME_" & sName), "S")
  End With

  With e("txtCAN_NAME_" & sName)
    If (bDisabled) Then
        .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
    End If
  End With

  ShowFunction = True
ExitLabel:
End Function

'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        v()             value array
'        func            reference to the function object
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function UnableShowFunction(ps As Peripherals, v() As Variant, func As FunctionClass, sName As String) As Boolean
  On Error GoTo ExitLabel
  UnableShowFunction = False

  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean

  Dim vIndex As Variant

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

  '-------------------------------------------------------------------------
  ' control: chkCAN_USE_.. (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("chkCAN_USE_" & sName)
    ' disable condition
    .Enabled = False 'Not bDisabled
    .Value = -CInt((r.v("CAN_USE_Init") = 1))
  End With

  bDisabled = True

  With e("chkCAN_USE_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_ISR & vbCrLf & FormatFunctionToolTip(r, func, "CAN_NAME_" & sName)
    Else
        ' tooltip if control is enabled
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "CAN_NAME_" & sName)
    End If
  End With

  UnableShowFunction = True
ExitLabel:
End Function
