'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"
Option Explicit
'*****************************************************************************
' Module:
'        SCU
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'SCU'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        3.0   ahe          13.09.00    final version for C161CS/JC/JI (PM)
'
'        ----------------------------------------------------------------------
'        1.0   ahe          02.05.01    final version for Pegasus
'        1.1   ste          06.01.03    spelling correction
'
'
'*****************************************************************************

Const TOOLTIP_PERDISx = "This setting cannot be changed from here. It reflects the actual setting of the related peripheral."
Const TOOLTIP_GRP_PERDISx = "The peripheral group disable flag can be changed at runtime by using the functions 'SCU_vDisableModule' and 'SCU_vEnableModule'"

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

    OnLoad = False

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

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

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

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(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, "SCU\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 successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error Goto OnChangingPageError

    OnChangingPage = False

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

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

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

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

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

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes (ps, Pagename, "SCU")) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


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

    OnShow = False

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

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

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

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(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, "SCU", v)) Then Exit Function


    OnShow = True
    Exit Function

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


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

    OnClick = False

    Dim np As Peripherals


    OnClick = True
    Exit Function

OnClickError:
    Exit Function
End Function


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

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "SCU\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 'SystemControl'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageSystemControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageSystemControl = False

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

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

  OnChangingPageSystemControl = False
  
  If (Not ps.ExtenderCollection("System Control").Loaded) And (Pagename = "System Control") Then
    ps.ExtenderCollection("System Control").Loaded = True
  

    '-------------------------------
    ' frame: frmPDCFG
    '-------------------------------
    If (Not ps.AddFrame("frmPDCFG",100,100, 4150, 1500, _
      "Port Driver Configuration (PDCFG)")) Then Exit Function
        If (Not ps.AddOption("optPDCFG_0", 200, 250, 3800, 400, _
          "Port drivers are always on")) Then Exit Function
        If (Not ps.AddOption("optPDCFG_1", 200, 650, 3800, 400, _
          "Port drivers are off in IDLE or Sleep mode")) Then Exit Function
        If (Not ps.AddOption("optPDCFG_2", 200, 1050, 3800, 400, _
          "Port drivers are off in power down mode")) Then Exit Function

    '-------------------------------
    ' frame: frmPFCFG
    '-------------------------------
    If (Not ps.AddFrame("frmPFCFG",100,1650, 4150, 1100, _
      "Programm Flash Configuration (PFCFG)")) Then Exit Function
        If (Not ps.AddOption("optPFCFG_0", 200, 250, 3800, 400, _
          "Programm Flash is always on")) Then Exit Function
        If (Not ps.AddOption("optPFCFG_1", 200, 650, 3800, 400, _
          "Programm Flash is off in IDLE or Sleep mode")) Then Exit Function

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

  OnShowPageSystemControl = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim sVarPre As String

  sVarPre = "SCU"

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

  If (Pagename = "System Control") Then
    '-------------------------------------------------------------------------
    ' page: SystemControl (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optPDCFG_0 (action)
        '---------------------------------------------------------------------
        Case "optPDCFG_0"
            r.v("SYSCON1_PDCFG") = 0

        '---------------------------------------------------------------------
        ' control: optPDCFG_1 (action)
        '---------------------------------------------------------------------
        Case "optPDCFG_1"
            r.v("SYSCON1_PDCFG") = 1

        '---------------------------------------------------------------------
        ' control: optPDCFG_2 (action)
        '---------------------------------------------------------------------
        Case "optPDCFG_2"
            r.v("SYSCON1_PDCFG") = 2

        '---------------------------------------------------------------------
        ' control: optPFCFG_0 (action)
        '---------------------------------------------------------------------
        Case "optPFCFG_0"
            r.v("SYSCON1_PFCFG") = 0

        '---------------------------------------------------------------------
        ' control: optPFCFG_1 (action)
        '---------------------------------------------------------------------
        Case "optPFCFG_1"
            r.v("SYSCON1_PFCFG") = 1

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: SystemControl (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optPDCFG_0 (show)
    '-------------------------------------------------------------------------
    With c("optPDCFG_0")
        .Value = -CInt(r.v("SYSCON1_PDCFG") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optPDCFG_1 (show)
    '-------------------------------------------------------------------------
    With c("optPDCFG_1")
        .Value = -CInt(r.v("SYSCON1_PDCFG") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optPDCFG_2 (show)
    '-------------------------------------------------------------------------
    With c("optPDCFG_2")
        .Value = -CInt(r.v("SYSCON1_PDCFG") = 2)
    End With

    '-------------------------------------------------------------------------
    ' control: optPFCFG_0 (show)
    '-------------------------------------------------------------------------
    With c("optPFCFG_0")
        .Value = -CInt(r.v("SYSCON1_PFCFG") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optPFCFG_1 (show)
    '-------------------------------------------------------------------------
    With c("optPFCFG_1")
        .Value = -CInt(r.v("SYSCON1_PFCFG") = 1)
    End With

  End If

  OnShowPageSystemControl = True
  Exit Function

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

  OnLoadPageClockControl = False

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

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

  OnChangingPageClockControl = False
  
  If (Not ps.ExtenderCollection("Clock Control").Loaded) And (Pagename = "Clock Control") Then
    ps.ExtenderCollection("Clock Control").Loaded = True
  

    '-------------------------------
    ' frame: frmCLKEN
    '-------------------------------
    If (Not ps.AddFrame("frmCLKEN",100,100, 3500, 900, "System Clock")) Then Exit Function
        If (Not ps.AddCheck("chkCKLEN", 200, 350, 3000, 300, "Use pin CLKOUT (" & GetPinName("CLKOUT") & ") as output")) Then Exit Function

    '-------------------------------
    ' frame: frmUsePin
    '-------------------------------
    If (Not ps.AddFrame("frmUsePin",3750,100, 4850, 900, "Configure FOUT Port Pin")) Then Exit Function
        If (Not ps.AddCheck("chkPinFOUT", 200, 350, 3000, 300, "Use pin FOUT (" & GetPinName("FOUT") & ") as output")) Then Exit Function

    '-------------------------------
    ' frame: frmFOEN
    '-------------------------------
    If (Not ps.AddFrame("frmFOEN",100,1100, 3500, 1150, "Frequency Output Enable")) Then Exit Function
        If (Not ps.AddCheck("chkFOEN", 200, 450, 3075, 300, "Start counter after initialization (FOEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmFOSS
    '-------------------------------
    If (Not ps.AddFrame("frmFOSS",3750,1100, 4850, 1150, "Frequency Output Signal Select (FOSS)")) Then Exit Function
        If (Not ps.AddOption("optFOSS_0", 200, 300, 3150, 300, "Output of the toggle latch (DC = 50 %)")) Then Exit Function
        If (Not ps.AddOption("optFOSS_1", 200, 700, 4175, 300, "Output of the reload counter (DC depends on FORV)")) Then Exit Function

    '-------------------------------
    ' frame: frmFORV
    '-------------------------------
    If (Not ps.AddFrame("frmFORV",100,2300, 8500, 2350, "Configure Output Frequency")) Then Exit Function
        If (Not ps.AddLabel("lblFORV", 0, 4800, 1000, 1575, 305, "Reload Value (FORV)")) Then Exit Function
        If (Not ps.AddText("txtReqFreq", 2700, 350, 1000, 315)) Then Exit Function
        If (Not ps.AddText("txtFORV", 7100, 950, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_MaxFreq", 0, 200, 1600, 2200, 305, "Max. frequency output [MHz]")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_MinFreq", 0, 200, 1000, 2250, 305, "Min. frequency output [kHz]")) Then Exit Function
        If (Not ps.AddLabel("lblReqFreq", 0, 200, 400, 2400, 305, "Required output frequency [kHz]")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_RealFreq", 0, 4800, 400, 2075, 305, "Real output frequency [kHz]")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_RealFreq", 1, 7100, 400, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_MinFreq", 1, 2700, 950, 1000, 305, "")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_MaxFreq", 1, 2700, 1550, 1000, 305, "")) Then Exit Function


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

  OnShowPageClockControl = False

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

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

  If (Pagename = "Clock Control") Then
    '-------------------------------------------------------------------------
    ' page: ClockControl (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkCKLEN (action)
        '---------------------------------------------------------------------
        Case "chkCKLEN"
             If (v(1) = 1) Then
               If (GetPinFunction(r, "FOUT") = 2) Then
                 Call ReleaseAlternateOutputPin(r, "FOUT")
               End If
               Call RequestAlternateOutputPin(r, "CLKOUT")
               r.sfr("FOCON") = 0
             Else
               Call ReleaseAlternateOutputPin(r, "CLKOUT")
             End If
             r.v("FOCON_CLKEN") = v(1)
 
        '---------------------------------------------------------------------
        ' control: chkPinFOUT (action)
        '---------------------------------------------------------------------
        Case "chkPinFOUT"
             If (v(1) = 1) Then
               Call RequestAlternateOutputPin(r, "FOUT")
             Else
               Call ReleaseAlternateOutputPin(r, "FOUT")
               r.v("FOCON_FOEN") = 0
               r.v("SCU_USE_StartCount") = 0
               r.v("SCU_USE_StopCount") = 0
               r.v("SCU_USE_SetReloadValue") = 0
             End If

        '---------------------------------------------------------------------
        ' control: chkFOEN (action)
        '---------------------------------------------------------------------
        Case "chkFOEN"
             r.v("FOCON_FOEN") = v(1)

        '---------------------------------------------------------------------
        ' control: txtFORV (action)
        '---------------------------------------------------------------------
        Case "txtFORV"
             If (IsInputFormatOK(v(1), "H", c("lblFORV"), 0, 63)) Then
               r.v("FOCON_FORV") = v(1)
               r.v("SCU_ReqFreq") = GetRealOutputFrequency(r)
             Else
               Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: optFOSS_0 (action)
        '---------------------------------------------------------------------
        Case "optFOSS_0"
             r.v("FOCON_FOSS") = 0
             Call UpdateOutputFrequency(r)

        '---------------------------------------------------------------------
        ' control: optFOSS_1 (action)
        '---------------------------------------------------------------------
        Case "optFOSS_1"
             r.v("FOCON_FOSS") = 1
             Call UpdateOutputFrequency(r)

        '---------------------------------------------------------------------
        ' control: txtReqFreq (action)
        '---------------------------------------------------------------------
        Case "txtReqFreq"
             If (IsInputFormatOK(v(1), "F", c("lblFORV"), Format(GetMinOutputFrequency(r) * 1000, "0.000"), _
                 Format(GetMaxOutputFrequency(r) * 1000, "0.000"))) Then
               r.v("SCU_ReqFreq") = v(1) / 1000
               Call UpdateOutputFrequency(r)
             Else
               Exit Function
             End If


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: ClockControl (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkCKLEN (show)
    '-------------------------------------------------------------------------
    With c("chkCKLEN")
      bDisabled = (IsAlternateOutputPinFree(r, "CLKOUT") = False)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("FOCON_CLKEN") = 1)
    End With

    With e("chkCKLEN")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsAlternateOutputPinFree(r, "CLKOUT") = False) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CLKOUT")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkPinFOUT (show)
    '-------------------------------------------------------------------------
    With c("chkPinFOUT")
      bDisabled = (IsAlternateOutputPinFree(r, "FOUT") = False)
      .Enabled = Not(bDisabled)
      .Value = -CInt(GetPinFunction(r, "FOUT") = 2)
    End With

    With e("chkPinFOUT")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsAlternateOutputPinFree(r, "FOUT") = False) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "FOUT")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkFOEN (show)
    '-------------------------------------------------------------------------
    With c("chkFOEN")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("FOCON_FOEN") = 1)
    End With

    With e("chkFOEN")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblFORV (show)
    '-------------------------------------------------------------------------
    With c("lblFORV")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
    End With

    With e("lblFORV")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtFORV (show)
    '-------------------------------------------------------------------------
    With c("txtFORV")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Text = FormatTextOutput(r.v("FOCON_FORV"), "H2")
    End With

    With e("txtFORV")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optFOSS_0 (show)
    '-------------------------------------------------------------------------
    With c("optFOSS_0")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("FOCON_FOSS") = 0)
    End With

    With e("optFOSS_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optFOSS_1 (show)
    '-------------------------------------------------------------------------
    With c("optFOSS_1")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("FOCON_FOSS") = 1)
    End With

    With e("optFOSS_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_MaxFreq (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_MaxFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
    End With

    With e("lbl_txt_MaxFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_MinFreq (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_MinFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
    End With

    With e("lbl_txt_MinFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblReqFreq (show)
    '-------------------------------------------------------------------------
    With c("lblReqFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
    End With

    With e("lblReqFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_RealFreq (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_RealFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
    End With

    With e("lbl_txt_RealFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_RealFreq (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_RealFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Caption = Format(GetRealOutputFrequency(r) * 1000, "0.000")
    End With

    With e("lbl_box_RealFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_MinFreq (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_MinFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Caption = Format(GetMinOutputFrequency(r) * 1000, "0.000")
    End With

    With e("lbl_box_MinFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_MaxFreq (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_MaxFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Caption = Format(GetMaxOutputFrequency(r), "0.000")
    End With

    With e("lbl_box_MaxFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtReqFreq (show)
    '-------------------------------------------------------------------------
    With c("txtReqFreq")
      bDisabled = (r.v("FOCON_CLKEN") = 1 Or GetPinFunction(r, "FOUT") <> 2)
      .Enabled = Not(bDisabled)
      .Text = Format(r.v("SCU_ReqFreq") * 1000, "0.000")
    End With

    With e("txtReqFreq")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (r.v("FOCON_CLKEN") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("CLKOUT is enabled")
        End If
        If (GetPinFunction(r, "FOUT") <> 2) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
        End If
      End If
    End With

  End If

  OnShowPageClockControl = True
  Exit Function

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

  OnLoadPagePeripheralManagement = False

  If (Not ps.AddPage("Peripheral Management")) Then Exit Function

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

  OnChangingPagePeripheralManagement = False
  Dim i As Integer
  Dim r As ProjectData
  
  Set r = ps.ProjectData

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

    '-------------------------------
    ' frame: frmPERDISx
    '-------------------------------
    If (Not ps.AddFrame("frmPERDISx",100,100, 4950, 4200, _
      "Peripherals Disable Flag's")) Then Exit Function
        i = 250
        If (Not ps.AddCheck("chkADCDIS", 200, i, 4400, 300, _
          "Disable analog/digital converter ADC (ADCDIS)")) Then Exit Function
        i = i + 300
        If (Not ps.AddCheck("chkASC0DIS", 200, i, 4400, 300, _
          "Disable asynchronous serial channel ASC0 (ASC0DIS)")) Then Exit Function
        i = i + 300
        If (Not ps.AddCheck("chkSSC0DIS", 200, i, 4400, 300, _
          "Disable synchronous serial channel SSC0 (SSC0DIS)")) Then Exit Function
        i = i + 300
        If (Not ps.AddCheck("chkGPTDIS", 200, i, 4400, 300, _
          "Disable general purpose timer block GPT1/2 (GPTDIS)")) Then Exit Function
        i = i + 300
        If (Not ps.AddCheck("chkPFMDIS", 200, i, 4400, 300, _
          "Disable on-chip programm flash memory module (PFMDIS)")) Then Exit Function
        i = i + 300
        If (Not ps.AddCheck("chkCC1DIS", 200, i, 4400, 300, _
          "Disable CAPCOM unit 1 (CC1DIS)")) Then Exit Function
        i = i + 300
        If (Not ps.AddCheck("chkCC2DIS", 200, i, 4400, 300, _
          "Disable CAPCOM unit 2 (CC2DIS)")) Then Exit Function
        i = i + 300
        
        If (r.Regs.BitFind("SYSCON3_CC6DIS") = True) Then
            If (Not ps.AddCheck("chkCC6DIS", 200, i, 4400, 300, _
              "Disable CAPCOM unit 6 (CC6DIS)")) Then Exit Function
            i = i + 300
        End If

        If (r.Regs.BitFind("SYSCON3_ASC1DIS") = True) Then
            If (Not ps.AddCheck("chkASC1DIS", 200, i, 4400, 300, _
              "Disable asynchronous serial channel ASC1 (ASC1DIS)")) Then Exit Function
            i = i + 300
        End If

        If (r.Regs.BitFind("SYSCON3_I2CDIS") = True) Then
            If (Not ps.AddCheck("chkI2CDIS", 200, i, 4400, 300, _
              "Disable on-chip I2C bus module (I2CDIS)")) Then Exit Function
            i = i + 300
        End If
        
        If (r.Regs.BitFind("SYSCON3_SDLMDIS") = True) Then
            If (Not ps.AddCheck("chkSDLMDIS", 200, i, 4400, 300, _
              "Disable on-chip SDLM (J1850) module (SDLMDIS)")) Then Exit Function
            i = i + 300
        End If
        
        If (r.Regs.BitFind("SYSCON3_CANDIS") = True) Then
            If (Not ps.AddCheck("chkCANDIS", 200, i, 4400, 300, _
              "Disable on-chip CAN module 1 (CANDIS)")) Then Exit Function
            i = i + 300
        End If
        
        If (r.Regs.BitFind("SYSCON3_SSC1DIS") = True) Then
            If (Not ps.AddCheck("chkSSC1DIS", 200, i, 4400, 300, _
              "Disable synchronous serial channel SSC1 (SSC1DIS)")) Then Exit Function
            i = i + 300
        End If

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

  OnShowPagePeripheralManagement = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim sRegPre As String
  Dim sVarPre As String

  sVarPre = "SCU"
  sRegPre = "SYSCON3"

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

  If (Pagename = "Peripheral Management") Then
    '-------------------------------------------------------------------------
    ' page: PeripheralManagement (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkADCDIS (action)
        '---------------------------------------------------------------------
        Case "chkADCDIS"
             r.v(sRegPre & "_ADCDIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkASC0DIS (action)
        '---------------------------------------------------------------------
        Case "chkASC0DIS"
             r.v(sRegPre & "_ASC0DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkASC1DIS (action)
        '---------------------------------------------------------------------
        Case "chkASC1DIS"
             r.v(sRegPre & "_ASC1DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkSSC0DIS (action)
        '---------------------------------------------------------------------
        Case "chkSSC0DIS"
             r.v(sRegPre & "_SSC0DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkSSC1DIS (action)
        '---------------------------------------------------------------------
        Case "chkSSC1DIS"
             r.v(sRegPre & "_SSC1DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkGPTDIS (action)
        '---------------------------------------------------------------------
        Case "chkGPTDIS"
             r.v(sRegPre & "_GPTDIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkPFMDIS (action)
        '---------------------------------------------------------------------
        Case "chkPFMDIS"
             r.v(sRegPre & "_PFMDIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkCC1DIS (action)
        '---------------------------------------------------------------------
        Case "chkCC1DIS"
             r.v(sRegPre & "_CC1DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkCC2DIS (action)
        '---------------------------------------------------------------------
        Case "chkCC2DIS"
             r.v(sRegPre & "_CC2DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkCC6DIS (action)
        '---------------------------------------------------------------------
        Case "chkCC6DIS"
             r.v(sRegPre & "_CC6DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkASC1DIS (action)
        '---------------------------------------------------------------------
        Case "chkASC1DIS"
             r.v(sRegPre & "_ASC1DIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkI2CDIS (action)
        '---------------------------------------------------------------------
        Case "chkI2CDIS"
             r.v(sRegPre & "_I2CDIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkSDLMDIS (action)
        '---------------------------------------------------------------------
        Case "chkSDLMDIS"
             r.v(sRegPre & "_SDLMDIS") = v(1)

        '---------------------------------------------------------------------
        ' control: chkCANDIS (action)
        '---------------------------------------------------------------------
        Case "chkCANDIS"
             r.v(sRegPre & "_CANDIS") = v(1)

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: PeripheralManagement (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkADCDIS (show)
    '-------------------------------------------------------------------------
    With c("chkADCDIS")
      bDisabled = True
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_ADCDIS") = 1)
    End With

    With e("chkADCDIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkASC0DIS (show)
    '-------------------------------------------------------------------------
    With c("chkASC0DIS")
      bDisabled = True
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_ASC0DIS") = 1)
    End With

    With e("chkASC0DIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkSSC0DIS (show)
    '-------------------------------------------------------------------------
    With c("chkSSC0DIS")
      bDisabled = True
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_SSC0DIS") = 1)
    End With

    With e("chkSSC0DIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkGPTDIS (show)
    '-------------------------------------------------------------------------
    With c("chkGPTDIS")
      bDisabled = True
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_GPTDIS") = 1)
    End With

    With e("chkGPTDIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkPFMDIS (show)
    '-------------------------------------------------------------------------
    With c("chkPFMDIS")
      bDisabled = False
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_PFMDIS") = 1)
    End With

    With e("chkPFMDIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkCC1DIS (show)
    '-------------------------------------------------------------------------
    With c("chkCC1DIS")
      bDisabled = True
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_CC1DIS") = 1)
    End With

    With e("chkCC1DIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkCC2DIS (show)
    '-------------------------------------------------------------------------
    With c("chkCC2DIS")
      bDisabled = True
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "_CC2DIS") = 1)
    End With

    With e("chkCC2DIS")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        If (1 = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
        End If
      End If
    End With

    
    If (r.Regs.BitFind("SYSCON3_CC6DIS") = True) Then
        '-------------------------------------------------------------------------
        ' control: chkCC6DIS (show)
        '-------------------------------------------------------------------------
        With c("chkCC6DIS")
          bDisabled = True
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v(sRegPre & "_CC6DIS") = 1)
        End With

        With e("chkCC6DIS")
          If (bDisabled) Then
            .DisabledTooltipText = ""
            If (1 = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
            End If
          End If
        End With
    End If

    If (r.Regs.BitFind("SYSCON3_ASC1DIS") = True) Then
        '-------------------------------------------------------------------------
        ' control: chkASC1DIS (show)
        '-------------------------------------------------------------------------
        With c("chkASC1DIS")
          bDisabled = True
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v(sRegPre & "_ASC1DIS") = 1)
        End With

        With e("chkASC1DIS")
          If (bDisabled) Then
            .DisabledTooltipText = ""
            If (1 = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
            End If
          End If
        End With
    End If

    If (r.Regs.BitFind("SYSCON3_SSC1DIS") = True) Then
        '-------------------------------------------------------------------------
        ' control: chkSSC1DIS (show)
        '-------------------------------------------------------------------------
        With c("chkSSC1DIS")
          bDisabled = True
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v(sRegPre & "_SSC1DIS") = 1)
        End With

        With e("chkSSC1DIS")
          If (bDisabled) Then
            .DisabledTooltipText = ""
            If (1 = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
            End If
          End If
        End With
    End If

    If (r.Regs.BitFind("SYSCON3_I2CDIS") = True) Then
        '-------------------------------------------------------------------------
        ' control: chkI2CDIS (show)
        '-------------------------------------------------------------------------
        With c("chkI2CDIS")
          bDisabled = True
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v(sRegPre & "_I2CDIS") = 1)
        End With

        With e("chkI2CDIS")
          If (bDisabled) Then
            .DisabledTooltipText = ""
            If (1 = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
            End If
          End If
        End With
    End If

    If (r.Regs.BitFind("SYSCON3_SDLMDIS") = True) Then
        '-------------------------------------------------------------------------
        ' control: chkSDLMDIS (show)
        '-------------------------------------------------------------------------
        With c("chkSDLMDIS")
          bDisabled = True
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v(sRegPre & "_SDLMDIS") = 1)
        End With

        With e("chkSDLMDIS")
          If (bDisabled) Then
            .DisabledTooltipText = ""
            If (1 = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
            End If
          End If
        End With
    End If

    If (r.Regs.BitFind("SYSCON3_CANDIS") = True) Then
        '-------------------------------------------------------------------------
        ' control: chkCANDIS (show)
        '-------------------------------------------------------------------------
        With c("chkCANDIS")
          bDisabled = True
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v(sRegPre & "_CANDIS") = 1)
        End With

        With e("chkCANDIS")
          If (bDisabled) Then
            .DisabledTooltipText = ""
            If (1 = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip(TOOLTIP_PERDISx)
            End If
          End If
        End With
    End If


  End If

  OnShowPagePeripheralManagement = True
  Exit Function

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

  OnChangingPageFunctions = False

  Dim i As Integer
  Dim aFunctions(1 To 16) As String

  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 , 100, 4150, 700, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400 , 100, 4150, 700, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 300, 1250, 275, 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)

    aFunctions(i) = "GetSystemStatus"
    i = i + 1
    aFunctions(i) = "SetPowerDown"
    i = i + 1
    aFunctions(i) = "SetIdle"
    i = i + 1
    aFunctions(i) = "SetSleep"
    i = i + 1
    aFunctions(i) = "EnableModule"
    i = i + 1
    aFunctions(i) = "DisableModule"
    i = i + 1

    If (Not ps.AddFrame("fraLibrary1", 100 , 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = Lbound(aFunctions) To Ubound(aFunctions)
        If Not(aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    ' initialize the array
    For i = Lbound(aFunctions) To Ubound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = Lbound(aFunctions)

    aFunctions(i) = "StartCount"
    i = i + 1
    aFunctions(i) = "StopCount"
    i = i + 1
    aFunctions(i) = "SetReloadValue"

    If (Not ps.AddFrame("fraLibrary2", 4400 , 900, 4150, 4400, CAPTION_FRA_LIBRARY2)) Then Exit Function
      For i = Lbound(aFunctions) To Ubound(aFunctions)
        If Not(aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

      

    ' Functions and Macros
  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 successfull 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 r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim sName As String
  Dim d As String

  vIndex = ""
  sVarPre = "SCU"

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

  If (Pagename = "Functions") Then

    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func , Controlname, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init" 
    ' disable condition
    func.Disabled(sName) = False
    ' tooltip if control is disabled
    'func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_GetSystemStatus" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetPowerDown" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetIdle" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetSleep" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_EnableModule" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_DisableModule" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_StartCount" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or GetPinFunction(r, "FOUT") <> 2)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    If (GetPinFunction(r, "FOUT") <> 2) Then 
      d = d & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_StopCount" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or GetPinFunction(r, "FOUT") <> 2)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    If (GetPinFunction(r, "FOUT") <> 2) Then 
      d = d & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetReloadValue" 
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or GetPinFunction(r, "FOUT") <> 2)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    If (GetPinFunction(r, "FOUT") <> 2) Then 
      d = d & FormatDisabledTooltip("FOUT (" & GetPinName("FOUT") & ") is not used as output")
    End If
    func.DisabledToolTip(sName) = d


    If (Not ShowFunction(sVarPre, ps, func , v)) Then Exit Function


  End If         ' if Pagename

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

  OnChangingPageParameters = False

  Dim r As ProjectData
  Dim i As Integer
  Dim aParameters(1 To 16) As String

  Set r = ps.ProjectData

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

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fra_HFile", 100 , 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile",0 , 200 , 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function   

    
    '-------------------------------
    ' frame: fraParameters1
    '-------------------------------
    ' initialize the array
    For i = Lbound(aParameters) To Ubound(aParameters)
      aParameters(i) = ""
    Next i

    i = Lbound(aParameters)
    aParameters(i) = "ADC"
    i = i + 1
    aParameters(i) = "ASC0"
    i = i + 1
    aParameters(i) = "SSC0"
    i = i + 1
    aParameters(i) = "GPT1_2"
    i = i + 1
    aParameters(i) = "PFM"
    i = i + 1
    aParameters(i) = "CC1"
    i = i + 1
    aParameters(i) = "CC2"
    i = i + 1

    If (r.Regs.BitFind("SYSCON3_CC6DIS") = True) Then
        aParameters(i) = "CC6"
        i = i + 1
    End If

    If (r.Regs.BitFind("SYSCON3_ASC1DIS") = True) Then
        aParameters(i) = "ASC1"
        i = i + 1
    End If

    If (r.Regs.BitFind("SYSCON3_I2CDIS") = True) Then
        aParameters(i) = "I2C"
        i = i + 1
    End If

    If (r.Regs.BitFind("SYSCON3_SDLMDIS") = True) Then
        aParameters(i) = "SDLM"
        i = i + 1
    End If

    aParameters(i) = "CAN"
    i = i + 1
    aParameters(i) = "SSC1"
    i = i + 1

    If (Not ps.AddFrame("fraParameters1", 100 , 900, 4150, 4500, CAPTION_FRA_PARAMETERS1)) Then Exit Function
      For i = Lbound(aParameters) To Ubound(aParameters)
        If Not(aParameters(i) = "") Then
          If (Not ps.AddText("txt_" & aParameters(i), 200, 200 + 300 * (i - 1), 3800, 325)) Then Exit Function
        End If
      Next i



  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 successfull 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 para As ParameterClass
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName As String
  Dim d As String
  Dim i As Integer

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

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para , Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2" 
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

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


