Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"

Option Explicit

'*****************************************************************************
' Module:
'        SSC
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'SSC'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author            Date           Description
'        ----------------------------------------------------------------------
'        1.0    ahe             17.02.00    final version for
'                                               C165UTAH
'                                               C165H
'                                               C161U
'
'        ----------------------------------------------------------------------
'        2.0    ahe             05.09.00    final version for
'                                               C167CS
'                                               C161PI
'                                               C161CS/JC/JI
'
'
'        ----------------------------------------------------------------------
'        3.0    ahe             25.10.00     final version for
'                                               C167CS
'                                               C161PI
'                                               C161CS/JC/JI
'                                               C167CR/SR r2
'
'                                            - changes module clock pages (check SYSCON3)
'
'               ahe             31.10.00     - changes the disabled tooltip for fct 'ErrorCheck'
'
'        ----------------------------------------------------------------------
'        4.0    ahe             20.04.01     final version for Pegasus
'
'        4.1    ahe             08.08.02     - neu interrupt pages
'        4.2    ste             16.12.02     no changes
'        4.3    ste             24.02.03     caption for module clock changed
'        ----------------------------------------------------------------------
'        5.0    raj            14.08.04     final version for XC164CM Pegasus light
'                                          - Pin Selection Page added

'*****************************************************************************

Const TOOLTIP_DISABLED_IF_MASTER_SELECTED = "the master mode is selected"


'*****************************************************************************
'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: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModuleClock(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Pin Selection
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePinSelection(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl(ps)) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePEC(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, "SSCx\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
    Dim sVarPre As String
    Dim vIndex  As Variant

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

    OnChangingPage = False

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

    '-------------------------------------------------------------------------
    'page: Pin Selection
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePinSelection(ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: SSC
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function

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

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

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

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

    Dim sVarPre As String
    Dim vIndex  As Variant

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

    OnShow = False

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

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

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

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

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

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnShowPagePEC(ps, Controlname, v, Pagename)) 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, sVarPre, 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

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function


    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not Text in OnClick.", Err.Description
    Exit Function
End Function


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

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "SSCx\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
  Dim sVarPre As String
  Dim vIndex  As Variant
  Dim r       As ProjectData

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


  Set r = ps.ProjectData

  If Not (GetSSCDisebleBitName(r, vIndex) = "") Then
      If (Not ps.AddPage("Module Clock")) Then Exit Function
  End If

  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

  OnChangingPageModuleClock = False
  Dim sVarPre As String
  Dim vIndex  As Variant
  Dim r       As ProjectData

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

  Set r = ps.ProjectData
  
  If Not (GetSSCDisebleBitName(r, vIndex) = "") Then
      If (Not ps.ExtenderCollection("Module Clock").Loaded) And (Pagename = "Module Clock") Then
        ps.ExtenderCollection("Module Clock").Loaded = True
  

        '-------------------------------
        ' frame: frmMD
        '-------------------------------
        If (Not ps.AddFrame("frmMD", 100, 100, 5400, 1375, sVarPre & " Disabled Flag (" & GetSSCDisebleBitName(r, vIndex) & ")")) Then Exit Function
            If (Not ps.AddOption("optDISx_0", 200, 350, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
            If (Not ps.AddOption("optDISx_1", 200, 825, 4800, 300, "Disable module; the clock input of peripheral is disabled")) Then Exit Function

        '-------------------------------
        ' frame: frmInputClock
        '-------------------------------
        If (Not ps.AddFrame("frmInputClock", 100, 1600, 5400, 1000, "Input Clock")) Then Exit Function
            If (Not ps.AddLabel("lbl_txt_InputClock", 0, 200, 450, 3225, 300, "Input clock of the " & sVarPre & " module [MHz]")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) 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

  OnShowPageModuleClock = False

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

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

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

  If Not (GetSSCDisebleBitName(r, vIndex) = "") Then
      If (Pagename = "Module Clock") Then
        '-------------------------------------------------------------------------
        ' page: ModuleClock (action)
        '-------------------------------------------------------------------------
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: optPERDISx_0 (action)
            '---------------------------------------------------------------------
            Case "optDISx_0"
                 r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 0

            '---------------------------------------------------------------------
            ' control: optPERDISx_1 (action)
            '---------------------------------------------------------------------
            Case "optDISx_1"
                 r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1
                 r.v(sRegPre & "CON_EN") = 0
                 Call SetSSCDefault(r, vIndex)
                 r.v(sRegPre & "CON_MS") = 0
                 r.v(sRegPre & "SRIS") = 0
                 r.v(sRegPre & "SCIS") = 0
                 r.v(sRegPre & "STOS") = 0


          Case Else
        End Select

        '-------------------------------------------------------------------------
        ' page: ModuleClock (show)
        '-------------------------------------------------------------------------

        '-------------------------------------------------------------------------
        ' control: optPERDISx_0 (show)
        '-------------------------------------------------------------------------
        With c("optDISx_0")
          bDisabled = False
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 0)
        End With

        With e("optDISx_0")
          If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("")
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: optPERDISx_1 (show)
        '-------------------------------------------------------------------------
        With c("optDISx_1")
          bDisabled = False
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1)
        End With

        With e("optDISx_1")
          If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("")
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: lbl_txt_InputClock (show)
        '-------------------------------------------------------------------------
        With c("lbl_txt_InputClock")
          bDisabled = (IsModuleDisabled(r, vIndex))
          .Enabled = Not (bDisabled)
        End With

        With e("lbl_txt_InputClock")
          If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, vIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
            End If
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: lbl_box_InputClock (show)
        '-------------------------------------------------------------------------
        With c("lbl_box_InputClock")
          bDisabled = (IsModuleDisabled(r, vIndex))
          .Enabled = Not (bDisabled)
          If (GetSSCModuleClock(r, vIndex) > GetMaxPeripheralClock(r)) Then
              .Caption = TO_HIGH
          Else
              .Caption = GetSSCModuleClock(r, vIndex)
          End If
        End With

        With e("lbl_box_InputClock")
          If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, vIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
            End If
          End If
        End With

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

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

  OnLoadPagePinSelection = True
End Function

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

  OnChangingPagePinSelection = False

  Dim vIndex As Variant
  Dim sIndex As String
  Dim v As Variant
  Dim sPrefix As String
  'Dim sVarPre As String
  
  vIndex = ps.Parameters.v("x")
  sIndex = "SSC" & vIndex
  sPrefix = sIndex & "_"
  'sVarPre = "SSC" & vIndex
  
  If (Not ps.ExtenderCollection("Pin Selection").Loaded) And (Pagename = "Pin Selection") Then
    ps.ExtenderCollection("Pin Selection").Loaded = True

    '-------------------------------
    ' frame: frmSSCxMS
    '-------------------------------
    If (Not ps.AddFrame("frmSSCxMS", 100, 100, 8500, 800, "Master Select (MS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxMS_0", 150, 300, 1975, 380, "Slave mode selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxMS_1", 4450, 300, 1975, 375, "Master mode selected")) Then Exit Function
        
    '-------------------------------
    ' frame: frmSSCxSRIS
    '-------------------------------
    If (Not ps.AddFrame("frmSSCxSRIS", 100, 2450, 4200, 1350, "Slave Mode Receive Input Select (SRIS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxSRIS_0", 150, 350, 3950, 300, "No slave receive input selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxSRIS_1", 150, 800, 3950, 300, "Slave receive input " & sPrefix & "MTSR (" & GetPinName(sIndex & "_MTSR_I") & ") selected")) Then Exit Function
    
    '-------------------------------
    ' frame: frmSSCxSCIS
    '-------------------------------
        
    If (Not ps.AddFrame("frmSSCxSCIS", 100, 1000, 4200, 1350, "Slave Mode Clock Input Select (SCIS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxSCIS_0", 150, 350, 3950, 300, "No slave clock input selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxSCIS_1", 150, 800, 3950, 300, "Slave clock input " & sPrefix & "SCLK (" & GetPinName(sIndex & "_SCLK_I") & ") selected")) Then Exit Function
        
    '-------------------------------
    ' frame: frmSSCxSTOS
    '-------------------------------
    If (Not ps.AddFrame("frmSSCxSTOS", 100, 3900, 4200, 1350, "Slave Mode Transmit Output Select (STOS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxSTOS_0", 150, 350, 3950, 300, "No slave transmit output selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxSTOS_1", 150, 800, 3950, 400, "Slave transmit output " & sPrefix & "MRST (" & GetPinName(sIndex & "_MRST_O") & ") selected")) Then Exit Function
    '-------------------------------
    ' frame: frmSSCxMRIS
    '-------------------------------
    If (Not ps.AddFrame("frmSSCxMRIS", 4450, 2450, 4150, 1350, "Master Mode Receive input Select (MRIS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxMRIS_0", 150, 350, 3950, 300, "No master receive input selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxMRIS_1", 150, 800, 3950, 400, "Master receive input " & sPrefix & "MRST (" & GetPinName(sIndex & "_MRST_I") & ") selected")) Then Exit Function
        
    '-------------------------------
    ' frame: frmSSCxMCOS
    '-------------------------------

    If (Not ps.AddFrame("frmSSCxMCOS", 4450, 1000, 4150, 1350, "Master Mode Clock Output Select (MCOS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxMCOS_0", 150, 350, 3950, 300, "No master clock output selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxMCOS_1", 150, 800, 3950, 300, "Master clock output " & sPrefix & "SCLK (" & GetPinName(sIndex & "_SCLK_O") & ") selected")) Then Exit Function

    '-------------------------------
    ' frame: frmSSCxMTOS
    '-------------------------------
    If (Not ps.AddFrame("frmSSCxMTOS", 4450, 3900, 4150, 1350, "Master Mode Transmit Output Select (MTOS)")) Then Exit Function
        If (Not ps.AddOption("optSSCxMTOS_0", 150, 350, 3950, 300, "No master transmit output selected")) Then Exit Function
        If (Not ps.AddOption("optSSCxMTOS_1", 150, 800, 3950, 400, "Master transmit output " & sPrefix & "MTSR (" & GetPinName(sIndex & "_MTSR_O") & ") selected")) Then Exit Function

  End If
  OnChangingPagePinSelection = True
End Function

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

  OnShowPagePinSelection = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim i As Integer
  Dim sRegPre As String
  Dim sVarPre As String
  
  vIndex = ps.Parameters.v("x")
  sVarPre = "SSC" & vIndex
  sRegPre = sVarPre & "_"
 
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Pin Selection") Then
    '-------------------------------------------------------------------------
    ' page: Pin Selection (action)
    '-------------------------------------------------------------------------
      Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optSSCxMS_0 (action)
        '---------------------------------------------------------------------
        Case "optSSCxMS_0"
             r.v(sRegPre & "CON_MS") = 0
             If GetPinFunction(r, sVarPre & "_MRST_I") <> 0 Then
               Call ReleaseAlternateInputPin(r, sVarPre & "_MRST_I")
             End If
             If GetPinFunction(r, sVarPre & "_MTSR_O") <> 0 Then
               Call ReleaseAlternateOutputPin(r, sVarPre & "_MTSR_O")
             End If
             If GetPinFunction(r, sVarPre & "_SCLK_O") <> 0 Then
               Call ReleaseAlternateOutputPin(r, sVarPre & "_SCLK_O")
             End If
             r.v(sRegPre & "CON_EN") = 0
             Call SetSSCDefault(r, vIndex)
             r.v(sRegPre & "SRIS") = 0
             r.v(sRegPre & "SCIS") = 0
             r.v(sRegPre & "STOS") = 0
             r.v(sRegPre & "MRIS") = 0
             r.v(sRegPre & "MCOS") = 0
             r.v(sRegPre & "MTOS") = 0
        
        '---------------------------------------------------------------------
        ' control: optSSCxMS_1 (action)
        '---------------------------------------------------------------------
        Case "optSSCxMS_1"
             r.v(sRegPre & "CON_MS") = 1
             r.v(sRegPre & "CON_TEN_TE") = 0
             r.v(sRegPre & "CON_BEN_BE") = 0

             If GetPinFunction(r, sVarPre & "_MRST_O") <> 0 Then
               Call ReleaseAlternateOutputPin(r, sVarPre & "_MRST_O")
             End If
             If GetPinFunction(r, sVarPre & "_MTSR_I") <> 0 Then
               Call ReleaseAlternateInputPin(r, sVarPre & "_MTSR_I")
             End If
             If GetPinFunction(r, sVarPre & "_SCLK_I") <> 0 Then
               Call ReleaseAlternateInputPin(r, sVarPre & "_SCLK_I")
             End If
             r.v(sRegPre & "CON_EN") = 0
             Call SetSSCDefault(r, vIndex)
             r.v(sRegPre & "SRIS") = 0
             r.v(sRegPre & "SCIS") = 0
             r.v(sRegPre & "STOS") = 0
             r.v(sRegPre & "MRIS") = 0
             r.v(sRegPre & "MCOS") = 0
             r.v(sRegPre & "MTOS") = 0

        '---------------------------------------------------------------------
        ' control: optSSCxSRIS_0 (action) _1
        '---------------------------------------------------------------------
         Case "optSSCxSRIS_0"
            r.v(sRegPre & "SRIS") = 0
            If ((r.v(sRegPre & "SCIS")) And ((r.v(sRegPre & "SRIS")) Or (r.v(sRegPre & "STOS"))) = 0) Then
                r.v(sRegPre & "CON_EN") = 0
                Call SetSSCDefault(r, vIndex)
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 0 Then
                     Call ReleaseAlternateInputPin(r, sVarPre & "_MTSR_I")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxSRIS_1 (action)
        '---------------------------------------------------------------------
         Case "optSSCxSRIS_1"
            r.v(sRegPre & "SRIS") = 1
            If ((r.v(sRegPre & "SCIS")) And ((r.v(sRegPre & "SRIS")) Or (r.v(sRegPre & "STOS"))) = 1) Then
                r.v(sRegPre & "CON_EN") = 1
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 0 Then
                    Call RequestAlternateInputPin(r, sVarPre & "_MTSR_I")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxSCIS_0 (action) _2
        '---------------------------------------------------------------------
         Case "optSSCxSCIS_0"
            r.v(sRegPre & "SCIS") = 0
            r.v(sRegPre & "CON_EN") = 0
            Call SetSSCDefault(r, vIndex)
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 0 Then
                     Call ReleaseAlternateInputPin(r, sVarPre & "_SCLK_I")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxSCIS_1 (action)
        '---------------------------------------------------------------------
         Case "optSSCxSCIS_1"
            r.v(sRegPre & "SCIS") = 1
            If ((r.v(sRegPre & "SCIS")) And ((r.v(sRegPre & "SRIS")) Or (r.v(sRegPre & "STOS"))) = 1) Then
                r.v(sRegPre & "CON_EN") = 1
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 0 Then
                    Call RequestAlternateInputPin(r, sVarPre & "_SCLK_I")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxSTOS_0 (action) _3 SCLK
        '---------------------------------------------------------------------
         Case "optSSCxSTOS_0"
            r.v(sRegPre & "STOS") = 0
            If ((r.v(sRegPre & "SCIS")) And ((r.v(sRegPre & "SRIS")) Or (r.v(sRegPre & "STOS"))) = 0) Then
                r.v(sRegPre & "CON_EN") = 0
                Call SetSSCDefault(r, vIndex)
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 0 Then
                     Call ReleaseAlternateOutputPin(r, sVarPre & "_MRST_O")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxSTOS_1 (action)
        '---------------------------------------------------------------------
         Case "optSSCxSTOS_1"
            r.v(sRegPre & "STOS") = 1
            If ((r.v(sRegPre & "SCIS")) And ((r.v(sRegPre & "SRIS")) Or (r.v(sRegPre & "STOS"))) = 1) Then
                r.v(sRegPre & "CON_EN") = 1
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 0 Then
                    Call RequestAlternateOutputPin(r, sVarPre & "_MRST_O")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxMRIS_0 (action) _4
        '---------------------------------------------------------------------
         Case "optSSCxMRIS_0"
            r.v(sRegPre & "MRIS") = 0
            If ((r.v(sRegPre & "MCOS")) And ((r.v(sRegPre & "MRIS")) Or (r.v(sRegPre & "MTOS"))) = 0) Then
                r.v(sRegPre & "CON_EN") = 0
                Call SetSSCDefault(r, vIndex)
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 1 Then
                    Call ReleaseAlternateInputPin(r, sVarPre & "_MRST_I")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxMRIS_1 (action)
        '---------------------------------------------------------------------
         Case "optSSCxMRIS_1"
            r.v(sRegPre & "MRIS") = 1
            If ((r.v(sRegPre & "MCOS")) And ((r.v(sRegPre & "MRIS")) Or (r.v(sRegPre & "MTOS"))) = 1) Then
                r.v(sRegPre & "CON_EN") = 1
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 1 Then
                    Call RequestAlternateInputPin(r, sVarPre & "_MRST_I")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxMCOS_0 (action) _5 MCLK
        '---------------------------------------------------------------------
         Case "optSSCxMCOS_0"
            r.v(sRegPre & "MCOS") = 0
            r.v(sRegPre & "CON_EN") = 0
            Call SetSSCDefault(r, vIndex)
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 1 Then
                    Call ReleaseAlternateOutputPin(r, sVarPre & "_SCLK_O")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxMCOS_1 (action)
        '---------------------------------------------------------------------
         Case "optSSCxMCOS_1"
            r.v(sRegPre & "MCOS") = 1
            If ((r.v(sRegPre & "MCOS")) And ((r.v(sRegPre & "MRIS")) Or (r.v(sRegPre & "MTOS"))) = 1) Then
                r.v(sRegPre & "CON_EN") = 1
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 1 Then
                    Call RequestAlternateOutputPin(r, sVarPre & "_SCLK_O")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxMTOS_0 (action) _6
        '---------------------------------------------------------------------
         Case "optSSCxMTOS_0"
            r.v(sRegPre & "MTOS") = 0
            If ((r.v(sRegPre & "MCOS")) And ((r.v(sRegPre & "MRIS")) Or (r.v(sRegPre & "MTOS"))) = 0) Then
                r.v(sRegPre & "CON_EN") = 0
                Call SetSSCDefault(r, vIndex)
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 1 Then
                    Call ReleaseAlternateOutputPin(r, sVarPre & "_MTSR_O")
                End If
            End If
        '---------------------------------------------------------------------
        ' control: optSSCxMTOS_1 (action)
        '---------------------------------------------------------------------
         Case "optSSCxMTOS_1"
            r.v(sRegPre & "MTOS") = 1
            If ((r.v(sRegPre & "MCOS")) And ((r.v(sRegPre & "MRIS")) Or (r.v(sRegPre & "MTOS"))) = 1) Then
                r.v(sRegPre & "CON_EN") = 1
            End If
            If v(1) = 1 Then
                If r.v(sRegPre & "CON_MS") = 1 Then
                    Call RequestAlternateOutputPin(r, sVarPre & "_MTSR_O")
                End If
            End If
    End Select

    '-------------------------------------------------------------------------
    ' page: PinSelection (show)
    '-------------------------------------------------------------------------
    
        '-------------------------------------------------------------------------
        ' control: optSSCxMS_0 (show)
        '-------------------------------------------------------------------------
        With c("optSSCxMS_0")
            bDisabled = (IsModuleDisabled(r, vIndex))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "CON_MS") = 0)
            If (r.v(sRegPre & "CON_MS") = 0) Then
                r.v(sRegPre & "MRIS") = 0
                r.v(sRegPre & "MCOS") = 0
                r.v(sRegPre & "MTOS") = 0
            End If
        End With

        With e("optSSCxMS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                End If
            End If
        End With


        '-------------------------------------------------------------------------
        ' control: optSSCxMS_1 (show)
        '-------------------------------------------------------------------------
        With c("optSSCxMS_1")
            bDisabled = (IsModuleDisabled(r, vIndex))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "CON_MS") = 1)
            If (r.v(sRegPre & "CON_MS") = 1) Then
                r.v(sRegPre & "SRIS") = 0
                r.v(sRegPre & "SCIS") = 0
                r.v(sRegPre & "STOS") = 0
            End If
        End With

        With e("optSSCxMS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                End If
            End If
        End With
        
        '---------------------------------------------------------------------
        ' control: optSSCxSRIS_0 (show) _1
        '---------------------------------------------------------------------
        With c("optSSCxSRIS_0")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 1) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "SRIS") = 0)
        End With

        With e("optSSCxSRIS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the slave mode is not selected")
                End If
            End If
        End With
        
        '---------------------------------------------------------------------
        ' control: optSSCxSRIS_1 (show)
        '---------------------------------------------------------------------
        With c("optSSCxSRIS_1")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 1) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "SRIS") = 1)
        End With

        With e("optSSCxSRIS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the slave mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxSCIS_0 (show) _2
        '---------------------------------------------------------------------
        With c("optSSCxSCIS_0")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 1) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "SCIS") = 0)
        End With
        
        With e("optSSCxSCIS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the slave mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxSCIS_1 (show)
        '---------------------------------------------------------------------
        With c("optSSCxSCIS_1")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 1) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "SCIS") = 1)
        End With
        
        With e("optSSCxSCIS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the slave mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxSTOS_0 (show) _3
        '---------------------------------------------------------------------
        With c("optSSCxSTOS_0")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 1) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "STOS") = 0)
        End With
        
        With e("optSSCxSTOS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the slave mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxSTOS_1 (show)
        '---------------------------------------------------------------------
        With c("optSSCxSTOS_1")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 1) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "STOS") = 1)
        End With
        
        With e("optSSCxSTOS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the slave mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxMRIS_0 (show) _4
        '---------------------------------------------------------------------
        With c("optSSCxMRIS_0")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 0) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "MRIS") = 0)
        End With
        
        With e("optSSCxMRIS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the master mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxMRIS_1 (show)
        '---------------------------------------------------------------------
        With c("optSSCxMRIS_1")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 0) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "MRIS") = 1)
        End With
        
        With e("optSSCxMRIS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the master mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxMCOS_0 (show) _5
        '---------------------------------------------------------------------
        With c("optSSCxMCOS_0")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 0) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "MCOS") = 0)
        End With
        
        With e("optSSCxMCOS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the master mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxMCOS_1 (show)
        '---------------------------------------------------------------------
        With c("optSSCxMCOS_1")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 0) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "MCOS") = 1)
        End With
        
        With e("optSSCxMCOS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the master mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxMTOS_0 (show) _6
        '---------------------------------------------------------------------
        With c("optSSCxMTOS_0")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 0) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "MTOS") = 0)
        End With
        
        With e("optSSCxMTOS_0")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the master mode is not selected")
                End If
            End If
        End With
        '---------------------------------------------------------------------
        ' control: optSSCxMTOS_1 (show)
        '---------------------------------------------------------------------
        With c("optSSCxMTOS_1")
            bDisabled = ((r.v(sRegPre & "CON_MS") = 0) Or (r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 1))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "MTOS") = 1)
        End With
        
        With e("optSSCxMTOS_1")
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
                Else
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("the master mode is not selected")
                End If
            End If
        End With

  End If

  OnShowPagePinSelection = True
  Exit Function

OnShowPagePinSelectionError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

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

  OnLoadPageControl = True
End Function


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

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

  OnChangingPageControl = False
  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  
    '-------------------------------
    ' frame: Data Control
    '-------------------------------
     If (Not ps.AddFrame("Data Control", 100, 100, 4200, 800, "Data Control")) Then Exit Function
        If (Not ps.AddCombo("cboSSCBM", 2325, 300, 1300, 315)) Then Exit Function
        If (Not ps.AddLabel("lblSSCBM", 0, 200, 350, 1700, 395, "Data Width (BM)")) Then Exit Function
     
    '-------------------------------
    ' frame: frmSSCHB
    '-------------------------------
    If (Not ps.AddFrame("frmSSCHB", 4450, 100, 4150, 1400, "Heading Control (HB)")) Then Exit Function
        If (Not ps.AddOption("optSSCHB_0", 200, 350, 2500, 300, "Transmit/Receive LSB first")) Then Exit Function
        If (Not ps.AddOption("optSSCHB_1", 200, 850, 2500, 300, "Transmit/Receive MSB first")) Then Exit Function
    '-------------------------------
    ' frame: frmErrCon
    '-------------------------------
    If (Not ps.AddFrame("frmErrCon", 100, 1000, 4200, 2100, "Error Control")) Then Exit Function
        If (Not ps.AddCheck("chkSSCTEN", 200, 200, 3100, 380, "Check transmit errors (TEN)")) Then Exit Function
        If (Not ps.AddCheck("chkSSCREN", 200, 550, 3100, 380, "Check receive errors (REN)")) Then Exit Function
        If (Not ps.AddCheck("chkSSCPEN", 200, 900, 3100, 380, "Check phase errors (PEN)")) Then Exit Function
        If (Not ps.AddCheck("chkSSCBEN", 200, 1250, 3100, 380, "Check baud rate errors (BEN)")) Then Exit Function
        If (Not ps.AddCheck("chkSSCAREN", 350, 1600, 3475, 380, sVarPre & " is automatically reset upon baud rate error (AREN)")) Then Exit Function
    '-------------------------------
    ' frame: frmIC
    '-------------------------------
    If (Not ps.AddFrame("frmIC", 4450, 1600, 4150, 1500, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkSSCTIE", 200, 250, 3100, 380, "Enable transmit interrupt (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkSSCRIE", 200, 650, 3100, 380, "Enable receive interrupt (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkSSCEIE", 200, 1050, 3100, 380, "Enable error interrupt (IE)")) Then Exit Function
    '-------------------------------
    ' frame: frmSSCPO
    '-------------------------------
    If (Not ps.AddFrame("frmSSCPO", 100, 3200, 4200, 1200, "Clock Polarity Control (PO)")) Then Exit Function
        If (Not ps.AddOption("optSSCPO_0", 200, 250, 3350, 375, "Idle clock line is low, leading clock edge is low-to-high transition")) Then Exit Function
        If (Not ps.AddOption("optSSCPO_1", 200, 700, 3450, 380, "Idle clock line is high, leading clock edge is high-to-low transition")) Then Exit Function
    '-------------------------------
    ' frame: frmSSCPH
    '-------------------------------
    If (Not ps.AddFrame("frmSSCPH", 4425, 3200, 4150, 1200, "Clock Phase Control (PH)")) Then Exit Function
        If (Not ps.AddOption("optSSCPH_0", 200, 250, 3600, 380, "Shift transmit data on the leading clock edge, latch on trailing edge")) Then Exit Function
        If (Not ps.AddOption("optSSCPH_1", 200, 700, 3600, 380, "Latch receive data on the leading clock edge, shift on trailing edge")) Then Exit Function

  End If
  OnChangingPageControl = True
End Function


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

  OnShowPageControl = False

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

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

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

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

        '---------------------------------------------------------------------
        ' control: chkSSCTEN (action)
        '---------------------------------------------------------------------
        Case "chkSSCTEN"
             r.v(sRegPre & "CON_TEN_TE") = v(1)
             Call ReleaseErrorInterrupt(r, vIndex)
             
        '---------------------------------------------------------------------
        ' control: chkSSCREN (action)
        '---------------------------------------------------------------------
        Case "chkSSCREN"
             r.v(sRegPre & "CON_REN_RE") = v(1)
             Call ReleaseErrorInterrupt(r, vIndex)

        '---------------------------------------------------------------------
        ' control: chkSSCPEN (action)
        '---------------------------------------------------------------------
        Case "chkSSCPEN"
             r.v(sRegPre & "CON_PEN_PE") = v(1)
             Call ReleaseErrorInterrupt(r, vIndex)

        '---------------------------------------------------------------------
        ' control: chkSSCBEN (action)
        '---------------------------------------------------------------------
        Case "chkSSCBEN"
             r.v(sRegPre & "CON_BEN_BE") = v(1)
             If v(1) = 0 Then
               r.v(sRegPre & "CON_AREN_BSY") = 0
             End If
             Call ReleaseErrorInterrupt(r, vIndex)

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

        '---------------------------------------------------------------------
        ' control: chkSSCTIE (action)
        '---------------------------------------------------------------------
        Case "chkSSCTIE"
             If v(1) = 1 Then
               Call EnableSRN(r, sVarPre, sRegPre & "TIC", "Tx")
               r.v(sVarPre & "_USE_TxBufFree") = 0
             Else
               Call DisableSRN(r, sVarPre, sRegPre & "TIC", "Tx")
               r.v(sVarPre & "_USE_TransData") = 0
             End If

        '---------------------------------------------------------------------
        ' control: chkSSCRIE (action)
        '---------------------------------------------------------------------
        Case "chkSSCRIE"
             If v(1) = 1 Then
               Call EnableSRN(r, sVarPre, sRegPre & "RIC", "Rx")
               r.v(sVarPre & "_USE_RxDataReady") = 0
             Else
               Call DisableSRN(r, sVarPre, sRegPre & "RIC", "Rx")
               r.v(sVarPre & "_USE_TransData") = 0
             End If

        '---------------------------------------------------------------------
        ' control: chkSSCEIE (action)
        '---------------------------------------------------------------------
        Case "chkSSCEIE"
             If v(1) = 1 Then
               Call EnableSRN(r, sVarPre, sRegPre & "EIC", "Error")
               If (IsErrorCheckDisabled(r, vIndex) = False) Then
                  r.v(sVarPre & "_USE_ErrorCheck") = 0
               End If
             Else
               Call DisableSRN(r, sVarPre, sRegPre & "EIC", "Error")
             End If

        '---------------------------------------------------------------------
        ' control: cboSSCBM (action)
        '---------------------------------------------------------------------
        Case "cboSSCBM"
             For i = 2 To 16
               If v(1) = i & "-bit data" Then
                  r.v(sRegPre & "CON_BM_BC") = i - 1
               End If
             Next i

        '---------------------------------------------------------------------
        ' control: optSSCHB_0 (action)
        '---------------------------------------------------------------------
        Case "optSSCHB_0"
             r.v(sRegPre & "CON_HB") = 0

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

        '---------------------------------------------------------------------
        ' control: optSSCPH_0 (action)
        '---------------------------------------------------------------------
        Case "optSSCPH_0"
             r.v(sRegPre & "CON_PH") = 0

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

        '---------------------------------------------------------------------
        ' control: optSSCPO_0 (action)
        '---------------------------------------------------------------------
        Case "optSSCPO_0"
             r.v(sRegPre & "CON_PO") = 0

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

      Case Else
    End Select

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

    '-------------------------------------------------------------------------
    ' control: chkSSCTEN (show)
    '-------------------------------------------------------------------------
    With c("chkSSCTEN")
       bDisabled = Not ((r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 0) And _
            (r.v(sRegPre & "SCIS") = 1) And ((r.v(sRegPre & "SRIS") = 1) Or (r.v(sRegPre & "STOS") = 1)))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_TEN_TE") = 1)
    End With

    With e("chkSSCTEN")
       If (bDisabled) Then
         .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (r.v(sRegPre & "CON_MS") = 1) Then
                    'tooltip if SSCMS = 1
                    .DisabledToolTipText = .DisabledToolTipText & _
                    FormatDisabledToolTip(TOOLTIP_DISABLED_IF_MASTER_SELECTED)
                End If
            End If
         End If
       End If
    End With


    '-------------------------------------------------------------------------
    ' control: chkSSCREN (show)
    '-------------------------------------------------------------------------
    With c("chkSSCREN")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_REN_RE") = 1)
    End With

    With e("chkSSCREN")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With
    '-------------------------------------------------------------------------
    ' control: chkSSCPEN (show)
    '-------------------------------------------------------------------------
    With c("chkSSCPEN")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_PEN_PE") = 1)
    End With

    With e("chkSSCPEN")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkSSCBEN (show)
    '-------------------------------------------------------------------------
    With c("chkSSCBEN")
     bDisabled = Not ((r.v("SYSCON3_" & GetSSCDisebleBitName(r, vIndex)) = 0) And _
            (r.v(sRegPre & "SCIS") = 1) And ((r.v(sRegPre & "SRIS") = 1) Or (r.v(sRegPre & "STOS") = 1)))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_BEN_BE") = 1)
    End With

    With e("chkSSCBEN")
       If (bDisabled) Then
         .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (r.v(sRegPre & "CON_MS") = 1) Then
                    'tooltip if SSCMS = 1
                    .DisabledToolTipText = .DisabledToolTipText & _
                    FormatDisabledToolTip(TOOLTIP_DISABLED_IF_MASTER_SELECTED)
                End If
            End If
         End If
       End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkSSCAREN (show)
    '-------------------------------------------------------------------------
    With c("chkSSCAREN")
      bDisabled = (IsModuleDisabled(r, vIndex) Or _
                   IsPinInterfaceDeselected(r, vIndex) Or _
                   r.v(sRegPre & "CON_MS") = 1 Or _
                   r.v(sRegPre & "CON_BEN_BE") = 0)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_AREN_BSY") = 1)
    End With

    With e("chkSSCAREN")
       If (bDisabled) Then
         .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         End If
         If (r.v(sRegPre & "CON_MS") = 1) Then
           ' tooltip if SSCMS = 1
           .DisabledToolTipText = .DisabledToolTipText & _
             FormatDisabledToolTip(TOOLTIP_DISABLED_IF_MASTER_SELECTED)
         ElseIf (IsPinInterfaceDeselected(r, vIndex)) Then
           .DisabledToolTipText = .DisabledToolTipText & _
             GetTooltipPinInterfaceDisabled(r, vIndex)
         End If
         If (r.v(sRegPre & "CON_BEN_BE") = 0) Then
           .DisabledToolTipText = .DisabledToolTipText & _
             FormatDisabledToolTip("check baud rate error (BEN) ist disabled")
         End If
       End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkSSCTIE (show)
    '-------------------------------------------------------------------------
    With c("chkSSCTIE")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "TIC_IE") = 1)
    End With

    With e("chkSSCTIE")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkSSCRIE (show)
    '-------------------------------------------------------------------------
    With c("chkSSCRIE")
     bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "RIC_IE") = 1)
    End With

    With e("chkSSCRIE")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkSSCEIE (show)
    '-------------------------------------------------------------------------
    With c("chkSSCEIE")
      bDisabled = (IsModuleDisabled(r, vIndex) Or _
                   IsPinInterfaceDeselected(r, vIndex) Or _
                   IsErrorCheckDisabled(r, vIndex))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "EIC_IE") = 1)
    End With

    With e("chkSSCEIE")
       If (bDisabled) Then
         .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         End If
         If (IsPinInterfaceDeselected(r, vIndex)) Then
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipPinInterfaceDisabled(r, vIndex)
         End If
         If (IsErrorCheckDisabled(r, vIndex)) Then
           ' tooltip if error controls disabled
           .DisabledToolTipText = .DisabledToolTipText & _
             FormatDisabledToolTip("no 'error control' selected")
         End If
       End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboSSCBM (show)
    '-------------------------------------------------------------------------
    With c("cboSSCBM")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Clear
      For i = 2 To 16
        .AddItem i & "-bit data"
      Next i
      .ListIndex = r.v(sRegPre & "CON_BM_BC") - 1
    End With

    With e("cboSSCBM")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblSSCBM (show)
    '-------------------------------------------------------------------------
    With c("lblSSCBM")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
    End With

    With e("lblSSCBM")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With


    '-------------------------------------------------------------------------
    ' control: optSSCHB_0 (show)
    '-------------------------------------------------------------------------
    With c("optSSCHB_0")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_HB") = 0)
    End With

    With e("optSSCHB_0")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSSCHB_1 (show)
    '-------------------------------------------------------------------------
    With c("optSSCHB_1")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_HB") = 1)
    End With

    With e("optSSCHB_1")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSSCPH_0 (show)
    '-------------------------------------------------------------------------
    With c("optSSCPH_0")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_PH") = 0)
    End With

    With e("optSSCPH_0")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSSCPH_1 (show)
    '-------------------------------------------------------------------------
    With c("optSSCPH_1")
     bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_PH") = 1)
    End With

    With e("optSSCPH_1")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSSCPO_0 (show)
    '-------------------------------------------------------------------------
    With c("optSSCPO_0")
     bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_PO") = 0)
    End With

    With e("optSSCPO_0")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSSCPO_1 (show)
    '-------------------------------------------------------------------------
    With c("optSSCPO_1")
      bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_PO") = 1)
    End With

    With e("optSSCPO_1")
       If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

  End If

  OnShowPageControl = True
  Exit Function

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


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

  OnLoadPageBaudrate = False

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

  OnLoadPageBaudrate = True
End Function



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

  OnChangingPageBaudrate = False

  Dim vIndex  As Variant
  Dim sVarPre As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "SSC" & vIndex
  
  If (Not ps.ExtenderCollection("Baud Rate").Loaded) And (Pagename = "Baud Rate") Then
    ps.ExtenderCollection("Baud Rate").Loaded = True
  

    '-------------------------------
    ' frame: frmSSCBR
    '-------------------------------
    If (Not ps.AddFrame("frmSSCBR", 100, 100, 8475, 2550, "Baud Rate ")) Then Exit Function

        If (Not ps.AddText("txtRequiredBaudrate", 1800, 600, 1000, 300)) Then Exit Function
        If (Not ps.AddLabel("lblRequiredBaudrate", 0, 200, 600, 1450, 400, "Required baud rate [kbaud]")) Then Exit Function

        If (Not ps.AddLabel("txtMinBaudrate", 1, 1800, 1200, 1000, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblMinBaudrate", 0, 200, 1200, 1175, 400, "Min. baud rate [kbaud]")) Then Exit Function

        If (Not ps.AddLabel("txtMaxBaudrate", 1, 1800, 1800, 1000, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblMaxBaudrate", 0, 200, 1800, 1175, 400, "Max. baud rate [kbaud]")) Then Exit Function

        If (Not ps.AddLabel("txtRealBaudrate", 1, 6125, 600, 1000, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblRealBaudrate", 0, 4500, 600, 1200, 400, "Real baud rate [kbaud]")) Then Exit Function

        If (Not ps.AddLabel("txtPercentage", 1, 6125, 1200, 1000, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblPercentage", 0, 4500, 1200, 1200, 400, "Percentage of deviation [%]")) Then Exit Function

        If (Not ps.AddText("txtSSCBR", 6125, 1800, 1000, 300)) Then Exit Function
        If (Not ps.AddLabel("lblSSCBR", 0, 4500, 1800, 1200, 400, "Reload value (" & sVarPre & "_BR)")) Then Exit Function

  End If
  OnChangingPageBaudrate = True
End Function


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

  OnShowPageBaudrate = False

  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim bDisabled   As Boolean
  Dim vIndex      As Variant
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim Baudrate    As UnitType
  Dim MaxBaudRate As UnitType

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

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  If (Pagename = "Baud Rate") Then
    '-------------------------------------------------------------------------
    ' page: Baudrate (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: txtRequiredBaudrate (action)
        '---------------------------------------------------------------------
        Case "txtRequiredBaudrate"
             Baudrate = ConvertBaudrate(r.v(sVarPre & "_Baudrate"))
             MaxBaudRate = ConvertBaudrate(GetSSCMaxBaudrate(r, vIndex))

             If (IsInputFormatOK(v(1), "F", c("lblRequiredBaudrate").Caption, , )) Then
               If (IsInputValueOK(Format(v(1) * Baudrate.dDivider, SSC_PRECISION), _
                   Format(GetSSCMinBaudrate(r, vIndex), SSC_PRECISION), _
                   Format(Format(GetSSCMaxBaudrate(r, vIndex) / MaxBaudRate.dDivider, _
                   SSC_PRECISION) * MaxBaudRate.dDivider, SSC_PRECISION))) Then
                 r.d(sVarPre & "_Baudrate") = v(1) * Baudrate.dDivider  ' convert to baud
                 Call UpdateSSCBaudrate(r, vIndex)
               Else
                 Exit Function
               End If
             Else
               Exit Function
             End If


        '---------------------------------------------------------------------
        ' control: txtSSCBR (action)
        '---------------------------------------------------------------------
        Case "txtSSCBR"
             If (IsInputFormatOK(v(1), "H4", c("lblSSCBR").Caption, _
                 1 - r.l(sRegPre & "CON_MS"), 65535)) Then
               r.sfr(sRegPre & "BR") = v(1)
               r.d(sVarPre & "_Baudrate") = Format(GetSSCRealBaudrate(r, vIndex), "0.0000")
             Else
                 Exit Function
             End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Baudrate (show)
    '-------------------------------------------------------------------------
    bDisabled = GetMasterSlaveConfigurationdisabled(r, vIndex)
    '-------------------------------------------------------------------------
    ' control: txtRequiredBaudrate (show)
    '-------------------------------------------------------------------------
    With c("txtRequiredBaudrate")
      ' disable condition
      .Enabled = Not (bDisabled)

      If (bDisabled) Then
        .Text = CALCULATION_NOT_POSSIBLE
        c("lblRequiredBaudrate").Caption = "Required baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(r.d(sVarPre & "_Baudrate"))
        .Text = Format(Baudrate.dValue, SSC_PRECISION)
        c("lblRequiredBaudrate").Caption = "Required baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

    With e("txtRequiredBaudrate")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

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

    '-------------------------------------------------------------------------
    ' control: txtRealBaudrate (show)
    '-------------------------------------------------------------------------
    With c("txtRealBaudrate")
      ' disable condition
      .Enabled = Not (bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lblRealBaudrate").Caption = "Real baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(GetSSCRealBaudrate(r, vIndex))
        .Caption = Format(Baudrate.dValue, SSC_PRECISION)
        c("lblRealBaudrate").Caption = "Real baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

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

    '-------------------------------------------------------------------------
    ' control: txtMinBaudrate (show)
    '-------------------------------------------------------------------------
    With c("txtMinBaudrate")
      .Enabled = Not (bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lblMinBaudrate").Caption = "Min. baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(GetSSCMinBaudrate(r, vIndex))
        .Caption = Format(Baudrate.dValue, SSC_PRECISION)
        c("lblMinBaudrate").Caption = "Min. baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

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

    '-------------------------------------------------------------------------
    ' control: txtPercentage (show)
    '-------------------------------------------------------------------------
    With c("txtPercentage")
      ' disable condition
      .Enabled = Not (bDisabled)
      ' show condition
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
      Else
        .Caption = Format((GetSSCRealBaudrate(r, vIndex) - r.d(sVarPre & "_Baudrate")) / _
                         r.d(sVarPre & "_Baudrate") * 100, "0.000")
      End If

    End With

    '-------------------------------------------------------------------------
    ' control: lblPercentage (show)
    '-------------------------------------------------------------------------
    With c("lblPercentage")
      ' disable condition
      .Enabled = Not (bDisabled)
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtMaxBaudrate (show)
    '-------------------------------------------------------------------------
    With c("txtMaxBaudrate")
      .Enabled = Not (bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lblMaxBaudrate").Caption = "Max. baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(GetSSCMaxBaudrate(r, vIndex))
        .Caption = Format(Baudrate.dValue, SSC_PRECISION)
        c("lblMaxBaudrate").Caption = "Max. baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

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

    '-------------------------------------------------------------------------
    ' control: txtSSCBR (show)
    '-------------------------------------------------------------------------
    With c("txtSSCBR")
      ' disable condition
      .Enabled = Not (bDisabled)
      ' show condition
      If (bDisabled) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        .Text = FormatTextOutput(r.sfr(sRegPre & "BR"), "H4")
      End If
    End With

    With e("txtSSCBR")
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledToolTipText = TOOLTIP_DISABLED_IF
         If (IsModuleDisabled(r, vIndex)) Then
           ' tooltip if module disabled
           .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleDisabled(r, vIndex)
         Else
            If (IsSlaveModeConfigurationCorrectForToolTip(r, vIndex)) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("slave mode clock input should be selected")
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("SRIS or STOS should be selected")
            Else
                If (IsMasterModeConfigurationCorrectForToolTip(r, vIndex)) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("master mode clock output should be selected")
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("MRIS or MTOS should be selected")
                End If
            End If
         End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblSSCBR (show)
    '-------------------------------------------------------------------------
    With c("lblSSCBR")
      ' disable condition
      .Enabled = Not (bDisabled)
    End With

  End If

  OnShowPageBaudrate = True
  Exit Function

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


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add 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

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


  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, 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) = "SendData"
    i = i + 1
    aFunctions(i) = "GetData"
    i = i + 1
    aFunctions(i) = "TxBufFree"
    i = i + 1
    aFunctions(i) = "RxDataReady"
    i = i + 1
    aFunctions(i) = "ErrorCheck"
    i = i + 1
    aFunctions(i) = "Tx"
    i = i + 1
    aFunctions(i) = "Rx"
    i = i + 1
    aFunctions(i) = "Error"
    i = i + 1
    aFunctions(i) = "TransData"
    i = i + 1
    aFunctions(i) = "Busy"
    i = i + 1
    aFunctions(i) = "EnTransmitter"
    i = i + 1
    aFunctions(i) = "DisTransmitter"
    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) = "SetLoopBackMode"
    i = i + 1
    aFunctions(i) = "ResetLoopBackMode"
    i = i + 1

    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


  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 d           As String
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim vIndex      As Variant
  Dim sName       As String

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

  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) = r.v(sRegPre & "CON_EN") = 0
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sRegPre & "CON_EN") = 0) Then
      d = d & GetTooltipSSCModuleDisabled(r, vIndex)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SendData"
    ' 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_GetData"
    ' 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_TxBufFree"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or r.v(sRegPre & "TIC_IE") = 1)
    ' 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 (r.v(sRegPre & "TIC_IE") = 1) Then
      d = d & FormatDisabledToolTip("the transmit interrupt is enabled")
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_RxDataReady"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or r.v(sRegPre & "RIC_IE") = 1)
    ' 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 (r.v(sRegPre & "RIC_IE") = 1) Then
      d = d & FormatDisabledToolTip("the receive interrupt is enabled")
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_ErrorCheck"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or _
                            r.v(sRegPre & "EIC_IE") = 1 Or _
                            IsErrorCheckDisabled(r, vIndex))
    ' 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 (r.v(sRegPre & "EIC_IE") = 1) Then
      d = d & FormatDisabledToolTip("the error interrupt is enabled")
    End If
    If (IsErrorCheckDisabled(r, vIndex)) Then
      d = d & FormatDisabledToolTip("no error check is enabled")
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_Tx"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "TIC", "Tx")

    sName = sVarPre & "_NAME_Rx"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "RIC", "Rx")

    sName = sVarPre & "_NAME_Error"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "EIC", "Error")

    sName = sVarPre & "_NAME_TransData"
    ' disable condition
    func.Disabled(sName) = (r.v(sRegPre & "TIC_ILVL") = 0 Or _
                            r.v(sRegPre & "TIC_ILVL") > 13 Or _
                            r.v(sRegPre & "RIC_ILVL") = 0 Or _
                            r.v(sRegPre & "RIC_ILVL") > 13 Or _
                            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
    If (r.v(sVarPre & "_USE_Tx") = 0) Then
      d = d & FormatDisabledToolTip("the transmit interrupt routine is not selected")
    End If
    If (r.v(sRegPre & "TIC_ILVL") = 0) Then
      d = d & FormatDisabledToolTip("the level of transmit interrupt is 0.")
    End If
    If (r.v(sRegPre & "TIC_ILVL") > 13) Then
        d = d & FormatDisabledToolTip("the level of transmit interrupts ist greater than 13.")
    End If
    If (r.v(sVarPre & "_USE_Rx") = 0) Then
      d = d & FormatDisabledToolTip("the receive interrupt routine is not selected")
    End If
    If (r.v(sRegPre & "RIC_ILVL") = 0) Then
      d = d & FormatDisabledToolTip("the level of receive interrupt is 0.")
    End If
    If (r.v(sRegPre & "RIC_ILVL") > 13) Then
        d = d & FormatDisabledToolTip("the level of receive interrupts ist greater than 13.")
    End If
    func.DisabledToolTip(sName) = d
    func.Value(sName) = (r.v(sRegPre & "TIC_ILVL") > 0 And _
                         r.v(sRegPre & "TIC_ILVL") < 14 And _
                         r.v(sRegPre & "RIC_ILVL") > 0 And _
                         r.v(sRegPre & "RIC_ILVL") < 14)

    sName = sVarPre & "_NAME_Busy"
    ' 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_EnTransmitter"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or r.v(sRegPre & "CON_MS") = 1)
    ' 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 (r.v(sRegPre & "CON_MS") = 1) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DISABLED_IF_MASTER_SELECTED)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_DisTransmitter"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0 Or r.v(sRegPre & "CON_MS") = 1)
    ' 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 (r.v(sRegPre & "CON_MS") = 1) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DISABLED_IF_MASTER_SELECTED)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetLoopBackMode"
    ' 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_ResetLoopBackMode"
    ' 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


    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

  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
    

  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 = "SSC" & 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





