Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\PortPin.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"
'#Uses "..\main\include.inc"
'#Uses "..\CC6\include.inc"
'#Uses "..\T2\include.inc"
'#Uses "..\T21\include.inc"
'#Uses "..\SSC\include.inc"
'#Uses "..\can\include.inc"
'#Uses "..\UART1\include.inc"
'#Uses "..\ADC\include.inc"
Option Explicit
'*****************************************************************************
' Module:
'        PS
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions for generating code for the
'        module 'PS'.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  radhish       18-10-04    initial version
'        0.2  radhish       17-12-04    Modification made as per observation
'                                        made during verification
'        0.3  radhish       27-12-04    Module name appended before register names
'        0.4  radhish       27-12-04    Modification made in the disabled tooltip text of SSC,ADC,T2,CCU checkbox
'        0.5  radhish       06-01-05    In "OnShowPageControl" the disable condition is removed for RXD and EXINT0 wake-up
'                                       source.
'        0.6  radhish        03-02-05    GUI for showing status of module is modified
'        0.7  Ashish        21-11-06        reset from option's are updated
'
'
'*****************************************************************************



Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    If (Not OnLoadPageControl(ps)) Then Exit Function
    If (Not OnLoadPageFunctions(ps)) Then Exit Function
    If (Not OnLoadPageParameters(ps)) Then Exit Function
    If (Not OnLoadPageNotes(ps)) Then Exit Function
    
    ' call function to initialize the menu
    If (Not InitMenu(ps, "PS\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function

Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError

    OnChangingPage = False
    
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageNotes(ps, Pagename, "PS")) Then Exit Function

    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function

Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error Resume Next

    OnShow = False

    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageNotes(ps, Controlname, Pagename, "PS", v)) Then Exit Function

    OnShow = True
End Function

Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False
    ' no buttons implemented
    OnClick = True
    Exit Function

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

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, "PS\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function
    
Public Function OnLoadPageControl(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageControl = False

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

  OnLoadPageControl = True
End Function

Public Function OnChangingPageControl(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageControl = False

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

    '-------------------------------
    ' frame: fraGlobal
    '-------------------------------
    If (Not ps.AddFrame("fraWakeOpts", 120, 70, 3960, 900, "Wakeup Options")) Then Exit Function
        If (Not ps.AddOption("optWhReset", 240, 200, 1100, 350, "With Reset")) Then Exit Function
        If (Not ps.AddOption("optWReset", 240, 500, 1330, 350, "Without Reset")) Then Exit Function

    '-------------------------------
    ' frame: fraWakeUpSource
    '-------------------------------
    If (Not ps.AddFrame("fraWakeUpSource", 120, 1000, 3960, 1550, "Wake-up Source via RXD (WS)")) Then Exit Function
    
        If (Not ps.AddCheck("chkWSRXD", 120, 240, 2500, 350, "Wake-up source RXD")) Then Exit Function
            If (Not ps.AddOption("optWSRXD0", 240, 550, 3200, 350, "Wake-up source RXD is not selected")) Then Exit Function
            If (Not ps.AddOption("optWSRXD1", 240, 850, 2900, 350, "Wake-up source pin P1.0(RxD_0)")) Then Exit Function
            If (Not ps.AddOption("optWSRXD2", 240, 1150, 2900, 350, "Wake-up source pin P0.1(RxD_1)")) Then Exit Function
        
     
    '-------------------------------
    ' frame: fraWakeUpSourceEXINT0
    '-------------------------------
       If (Not ps.AddFrame("fraWakeUpSourceEXINT0", 120, 2650, 3960, 1300, "Wake-up Source via EXINT0 (WS)")) Then Exit Function
        If (Not ps.AddCheck("chkWSEXINT", 120, 240, 2500, 320, "Wake-up source EXINT0")) Then Exit Function
        If (Not ps.AddOption("optWSEXINT_pin0.5", 240, 550, 3200, 350, "Wake-up source EXINT0_0 pin P0.5")) Then Exit Function
        If (Not ps.AddOption("optWSEXINT_pin1.4", 240, 850, 3200, 350, "Wake-up source EXINT0_1 pin P1.4")) Then Exit Function
          
    '-------------------------------
    ' frame: fraSDDClock
    '-------------------------------
    If (Not ps.AddFrame("fraSDDClock", 120, 4000, 3960, 1280, "Slow Down Divider (REL)")) Then Exit Function
'        If (Not ps.AddText("txtDivider", 2520, 720, 1080, 315)) Then Exit Function
        If (Not ps.AddLabel("lblDividerLabel", 0, 240, 420, 1920, 200, "Slow Down Divider ")) Then Exit Function
        If (Not ps.AddCombo("cboClkDIV", 2350, 420, 1350, 200)) Then Exit Function

        If (Not ps.AddLabel("lblfClk_cal", 1, 2320, 870, 1350, 320, "0.625")) Then Exit Function
        If (Not ps.AddLabel("lblfClk", 0, 240, 870, 1920, 300, "Slow Down Clock [MHz]")) Then Exit Function
        

        
       
 
If (Not ps.AddFrame("fraPerDis", 4320, 70, 4200, 550, "Peripheral Status ")) Then Exit Function

' If (Not ps.AddLabel("lblADCSTAT", 1, 1500, 225, 1150, 280)) Then Exit Function
 If (Not ps.AddLabel("lblADCSTATLabel", 0, 200, 220, 1450, 380, "ADC")) Then Exit Function
 If (Not ps.AddOption("optEnADC", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisADC", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblCCU6STAT", 1, 1500, 625, 1150, 280)) Then Exit Function

If (Not ps.AddFrame("fraCCUDis", 4320, 650, 4200, 550, "")) Then Exit Function
    If (Not ps.AddLabel("lblCCU6STATLabel", 0, 200, 220, 1450, 380, "CapComUnit")) Then Exit Function
     If (Not ps.AddOption("optEnCCU", 1500, 150, 800, 380, "Enable")) Then Exit Function
     If (Not ps.AddOption("optDisCCU", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblSSCSTAT", 1, 1500, 1025, 1150, 280)) Then Exit Function

If (Not ps.AddFrame("fraSSCDis", 4320, 1230, 4200, 550, "")) Then Exit Function

 If (Not ps.AddLabel("lblSSCSTATLabel", 0, 200, 220, 1450, 380, "SSC")) Then Exit Function
 If (Not ps.AddOption("optEnSSC", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisSSC", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblT2STAT", 1, 1500, 1425, 1150, 280)) Then Exit Function

If (Not ps.AddFrame("fraT2is", 4320, 1810, 4200, 550, "")) Then Exit Function
 If (Not ps.AddLabel("lblT2STATLabel", 0, 200, 220, 1450, 380, "TIMER2")) Then Exit Function
 If (Not ps.AddOption("optEnT2", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisT2", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblMDUSTAT", 1, 1500, 1825, 1150, 280)) Then Exit Function


If (Not ps.AddFrame("fraT21is", 4320, 2390, 4200, 550, "")) Then Exit Function
 If (Not ps.AddLabel("lblT21STATLabel", 0, 200, 220, 1450, 380, "TIMER21")) Then Exit Function
 If (Not ps.AddOption("optEnT21", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisT21", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblUART1STAT", 1, 1500, 3425, 1150, 280)) Then Exit Function

If (Not ps.AddFrame("fraCDCis", 4320, 2970, 4200, 550, "")) Then Exit Function
' If (Not ps.AddLabel("lblCDCSTAT", 1, 1500, 2625, 1150, 280)) Then Exit Function
 If (Not ps.AddLabel("lblCDCSTATLabel", 0, 200, 220, 1450, 380, "CDC")) Then Exit Function
 If (Not ps.AddOption("optEnCDC", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisCDC", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblT21STAT", 1, 1500, 3025, 1150, 280)) Then Exit Function

If (Not ps.AddFrame("fraMDUis", 4320, 3550, 4200, 550, "")) Then Exit Function
 If (Not ps.AddLabel("lblMDUSTATLabel", 0, 200, 220, 1450, 380, "MDU")) Then Exit Function
 If (Not ps.AddOption("optEnMDU", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisMDU", 3000, 150, 900, 380, "Disable")) Then Exit Function
' If (Not ps.AddLabel("lblUART1STAT", 1, 1500, 3425, 1150, 280)) Then Exit Function

If (Not ps.AddFrame("fraUart1is", 4320, 4130, 4200, 550, "")) Then Exit Function
 If (Not ps.AddLabel("lblUART1STATLabel", 0, 200, 220, 1450, 380, "UART1")) Then Exit Function
 If (Not ps.AddOption("optEnUART1", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisUART1", 3000, 150, 900, 380, "Disable")) Then Exit Function
 
 If (Not ps.AddFrame("fraCANis", 4320, 4710, 4200, 550, "")) Then Exit Function
 If (Not ps.AddLabel("lblMultiCANSTATLabel", 0, 200, 220, 1450, 380, "CAN")) Then Exit Function
 If (Not ps.AddOption("optEnCAN", 1500, 150, 800, 380, "Enable")) Then Exit Function
 If (Not ps.AddOption("optDisCAN", 3000, 150, 900, 380, "Disable")) Then Exit Function
  End If
  OnChangingPageControl = True
End Function

Public Function OnShowPageControl(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageControl = False
   Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim iTemp, j, i As Integer
  Dim d As String
 ' Dim vIndex As Variant
  ' vIndex = ps.Parameters.v("x")
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  Select Case Controlname

 Case "optWReset"
      r.v(SCU_PREFIX & "PMCON0_WKSEL") = 0


  Case "optWhReset"
              r.v(SCU_PREFIX & "PMCON0_WKSEL") = 1


  Case "chkWSRXD"
        r.v("PS_Pin_Rx_0_Used") = v(1)
        If (r.v("PS_Pin_Rx_0_Used") = 0) Then
            Call ResetRXDpins(r)
            r.v("PS_Pin_Rx_1_Used") = 0
        End If

  Case "optWSRXD0"
        Call ResetRXDpins(r)
        r.v("PS_Pin_Rx_1_Used") = 0
        

  Case "optWSRXD1"
        r.v("PS_Pin_Rx_1_Used") = 1
        r.v("UART_RxPin_P1.0_Used") = 1
        r.v(SCU_PREFIX & "MODPISEL_URRIS") = 0
        Call RequestAlternateInputPin(r, "RXD_0")
        If r.v("UART_RxPin_P0.1_Used") = 1 Then
            r.v("UART_RxPin_P0.1_Used") = 0
            Call ReleaseAlternateInputPin(r, "RXD_1")
        End If

  Case "optWSRXD2"
        r.v("PS_Pin_Rx_1_Used") = 2
        r.v("UART_RxPin_P0.1_Used") = 1
        r.v(SCU_PREFIX & "MODPISEL_URRIS") = 1
        Call RequestAlternateInputPin(r, "RXD_1")
        If r.v("UART_RxPin_P1.0_Used") = 1 Then
            r.v("UART_RxPin_P1.0_Used") = 0
            Call ReleaseAlternateInputPin(r, "RXD_0")
        End If

  Case "chkWSEXINT"
       r.v("PS_Pin_Ex_0_Used") = v(1)
       r.v(SCU_PREFIX & "TCON_IT0") = 1
       If (v(1) = 1) Then
            ''r.v(CORE_PREFIX & "IEN0_EX0") = 1
             If ((r.v("EXINT0_Pin_P0.5_Used") = 0) And (r.v("EXINT0_Pin_P1.4_Used") = 0)) Then
              If IsAlternatePinFree(r, "EXINT0_0") Then
                r.v("EXINT0_Pin_P0.5_Used") = 1
                Call RequestAlternateInputPin(r, "EXINT0_0")
             Else
                r.v("EXINT0_Pin_P1.4_Used") = 1
                Call RequestAlternateInputPin(r, "EXINT0_1")
             End If
         End If
        Else
              r.v(SCU_PREFIX & "TCON_IT0") = 0
             If r.v(CORE_PREFIX & "IEN0_EX0") = 1 Then
               Else
                r.v(CORE_PREFIX & "IEN0_EX0") = 0
                r.v(SCU_PREFIX & "MODPISEL_EXINT0IS") = 0
                Call ResetEXTINTpins(r)
             End If
            ''Call ResetEXTINTpins(r)
            ''r.v(CORE_PREFIX & "IEN0_EX0") = 0
            ''r.v(SCU_PREFIX & "MODPISEL_EXINT0IS") = 0
        End If
              
  Case "optWSEXINT_pin0.5"
    
        If (r.v("PS_Pin_Ex_0_Used") = 1) Then
                r.v("EXINT0_Pin_P0.5_Used") = 1
                r.v(SCU_PREFIX & "MODPISEL_EXINT0IS") = 0
            If r.v("EXINT0_Pin_P1.4_Used") = 1 Then
                r.v("EXINT0_Pin_P1.4_Used") = 0
                Call ReleaseAlternateInputPin(r, "EXINT0_1")
            End If
               Call RequestAlternateInputPin(r, "EXINT0_0")
         Else
        End If

    Case "optWSEXINT_pin1.4"
    If (r.v("PS_Pin_Ex_0_Used") = 1) Then
                r.v("EXINT0_Pin_P1.4_Used") = 1
                r.v(SCU_PREFIX & "MODPISEL_EXINT0IS") = 1
            If r.v("EXINT0_Pin_P0.5_Used") = 1 Then
                r.v("EXINT0_Pin_P0.5_Used") = 0
                Call ReleaseAlternateInputPin(r, "EXINT0_0")
            End If
              Call RequestAlternateInputPin(r, "EXINT0_1")
    End If


      Case "cboClkDIV"
            If (ask(MSG_CHANGE_CLKREL)) Then
                r.v(SCU_PREFIX & "CMCON_CLKREL") = c("cboClkDIV").ListIndex
            End If

   Case "txtDivider"
            If (IsInputFormatOK(v(1), "", "Slow Down Divider", 1, 12)) Then
                r.v(SCU_PREFIX & "CMCON_CLKREL") = v(1) - 1
            Else
                Exit Function
            End If
   
   Case "optEnADC"
            r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0
   
   Case "optDisADC"
               d = "This will disable the ADC module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                           DisableADC (r)
                       End If
   
    Case "optEnCCU"
            r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 0
            
     Case "optDisCCU"
               d = "This will disable the CCU module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1
                           r.v("CCU6_USE_Init") = 0
                         Call DisableCC6Module(r, 6)
                         Call CheckResetCCU6_Pins(r)
                         End If
                        
     Case "optEnSSC"
            r.v(SCU_PREFIX & "PMCON1_SSC_DIS") = 0
            
     Case "optDisSSC"
               d = "This will disable the SSC module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON1_SSC_DIS") = 1
                          Call CheckResetSSC(r)
            
                        End If
                        
                        
     Case "optEnT2"
            r.v(SCU_PREFIX & "PMCON1_T2_DIS") = 0
            
     Case "optDisT2"
               d = "This will disable the Timer 2 module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON1_T2_DIS") = 1
                           SetT2Default (r)
                        End If
                        
                         
     Case "optEnT21"
            r.v(SCU_PREFIX & "PMCON2_T21_DIS") = 0
            
     Case "optDisT21"
               d = "This will disable the Timer 21 module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON2_T21_DIS") = 1
                           SetT21Default (r)

                        End If
                        
                        
     Case "optEnCDC"
            r.v(SCU_PREFIX & "PMCON1_CDC_DIS") = 0
            
     Case "optDisCDC"
               d = "This will disable the CDC module clock . " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON1_CDC_DIS") = 1
                        End If
        
     
     Case "optEnMDU"
            r.v(SCU_PREFIX & "PMCON1_MDU_DIS") = 0
            
     Case "optDisMDU"
               d = "This will disable the MDU module clock . " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON1_MDU_DIS") = 1
                        End If
                        
      Case "optEnUART1"
            r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 0
            
     Case "optDisUART1"
               d = "This will disable the UART1 module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1
                          Call ResetUART1(r)
                        End If
                        
        
     Case "optEnCAN"
            r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 0
            
     Case "optDisCAN"
               d = "This will disable the CAN module clock in module page itself. " & vbCrLf & _
                          "Do you really want to continue ?"
                          If ((ask(d))) Then
                          r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1
                           r.v("CAN_USE_Init") = 0
                            Call DisableModule(r, "")
                            r.v("CAN_USE_NODE0_RXD_PIN") = 0
                            r.v("CAN_USE_NODE0_TXD_PIN") = 0
                            r.v("CAN_USE_NODE1_RXD_PIN") = 0
                            r.v("CAN_USE_NODE1_TXD_PIN") = 0
                            r.v("CMCON_FCCFG") = 1
                            r.v("CAN_USE_SRN14") = 0
                            r.v("CAN_USE_SRN13") = 0
End If
        
  End Select     ' case Controlname
   '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------
    With c("optWReset")
        ' bDisabled = (r.v(SCU_PREFIX & "PMCON0_WKSEL") = 0)
        .Enabled = Not bDisabled
        .Value = r.v(SCU_PREFIX & "PMCON0_WKSEL") = 0
    End With
    With e("optWReset")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("external wake-up from software power down is not enabled")
        End If
    End With
     With c("optWhReset")
         'bDisabled = (r.v(SCU_PREFIX & "PMCON0_WKSEL") = 1)
        .Enabled = Not bDisabled
        .Value = r.v(SCU_PREFIX & "PMCON0_WKSEL") = 1
    End With
    With e("optWhReset")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("external wake-up from software power down is not enabled")
        End If
    End With

    
    With c("chkWSRXD")
            .Enabled = Not (bDisabled)
            .Value = r.v("PS_Pin_Rx_0_Used")
            
            If (r.v("PS_Pin_Rx_0_Used") = 0) Then
                Call ResetRXDpins(r)
            End If
            
    End With

    With e("chkWSRXD")
          If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("wake-up source is not enabled")
          End If
    End With

    With c("optWSRXD0")
         bDisabled = (r.v("PS_Pin_Rx_0_Used") = 0)
        .Enabled = Not bDisabled
        .Value = r.v("PS_Pin_Rx_0_Used") = 1
    End With
    With e("optWSRXD0")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("wake-up source is not enabled")
        End If
    End With

    With c("optWSRXD1")
         bDisabled = (r.v("PS_Pin_Rx_0_Used") = 0 Or Not (IsAlternatePinFree(r, "RXD_0")))
        .Enabled = Not bDisabled
        .Value = (r.v("PS_Pin_Rx_0_Used") = 1 And r.v("UART_RxPin_P1.0_Used") = 1)
    End With
    With e("optWSRXD1")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (r.v("PS_Pin_Rx_0_Used") = 0) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("wake-up source is not enabled")
            Else
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXD_0")
            End If
        End If
    End With

    With c("optWSRXD2")
         bDisabled = (r.v("PS_Pin_Rx_0_Used") = 0 Or Not (IsAlternatePinFree(r, "RXD_1")))
        .Enabled = Not bDisabled
        .Value = (r.v("PS_Pin_Rx_0_Used") = 1 And r.v("UART_RxPin_P0.1_Used") = 1)
    End With
    With e("optWSRXD2")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (r.v("PS_Pin_Rx_0_Used") = 0) Then
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("wake-up source is not enabled")
            Else
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "RXD_1")
            End If
        End If
    End With

    With c("chkWSEXINT")
        bDisabled = ((Not (IsAlternatePinFree(r, "EXINT0_0"))) And (Not (IsAlternatePinFree(r, "EXINT0_1"))))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("PS_Pin_Ex_0_Used") = 1)
    End With
    With e("chkWSEXINT")
         If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "EXINT0_0") & GetDisabledAlternatePinTooltip(r, "EXINT0_1")
         End If
    End With
      
     With c("optWSEXINT_pin0.5")
              bDisabled = (r.v("PS_Pin_Ex_0_Used") = 0) Or (Not (IsAlternatePinFree(r, "EXINT0_0"))) ' And r.v(CORE_PREFIX & "IEN0_EX0") = 1))
              .Enabled = Not (bDisabled)
              If (bDisabled) Then
              .Value = 0
              Else
              .Value = r.v("EXINT0_Pin_P0.5_Used")
              End If
    End With
    With e("optWSEXINT_pin0.5")
         If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (r.v("PS_Pin_Ex_0_Used") = 0) Then
               .DisabledToolTipText = .DisabledToolTipText & vbCrLf & _
               " Wake-Up source Via EXINT0 is not selected."
            Else
                .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "EXINT0_0")
            End If
         End If
    End With
    With c("optWSEXINT_pin1.4")
              bDisabled = (r.v("PS_Pin_Ex_0_Used") = 0) Or (Not (IsAlternatePinFree(r, "EXINT0_1"))) ' And r.v(CORE_PREFIX & "IEN0_EX0") = 1))
              .Enabled = Not (bDisabled)
              If (bDisabled) Then
              .Value = 0
              Else
              .Value = r.v("EXINT0_Pin_P1.4_Used")
              End If
    End With
    With e("optWSEXINT_pin1.4")
         If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            If (r.v("PS_Pin_Ex_0_Used") = 0) Then
               .DisabledToolTipText = .DisabledToolTipText & vbCrLf & _
               " Wake-Up source Via EXINT0 is not selected."
            Else
               .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(r, "EXINT0_1")
            End If
         End If
    End With

'    c("txtDivider").Text = FormatTextOutput(r.v(SCU_PREFIX & "CMCON_CLKREL") + 1, "")
   With c("cboClkDIV")
            .Clear
            .AddItem " fSYS/ " & 4
            .AddItem " fSYS/ " & 6
            .AddItem " fSYS/ " & 8
            .AddItem " fSYS/ " & 12
            .AddItem " fSYS/ " & 16
            .AddItem " fSYS/ " & 24
            .AddItem " fSYS/ " & 32
            .AddItem " fSYS/ " & 48
            .AddItem " fSYS/ " & 64
            .AddItem " fSYS/ " & 96
            .AddItem " fSYS/ " & 128
            .AddItem " fSYS/ " & 192
            .AddItem " fSYS/ " & 256
            .AddItem " fSYS/ " & 384
            .AddItem " fSYS/ " & 512
            .AddItem " fSYS/ " & 768
                .ListIndex = r.v(SCU_PREFIX & "CMCON_CLKREL")
        End With
       With c("lblfClk_cal")
            .Caption = Get_fFCLK(r)
        End With

    
    
         With c("OptEnCCU")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 0)
    End With
    
        With c("OptDisCCU")
           .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
        End With
        
    
        
         With c("OptEnADC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0)
    End With
    
    
    
     With c("OptDisADC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1)
    End With
    
      With c("OptEnSSC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_SSC_DIS") = 0)
    End With
    
    
    
      With c("OptDisSSC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_SSC_DIS") = 1)
    End With
    
       With c("OptEnT2")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_T2_DIS") = 0)
    End With
    
    
    With c("OptDisT2")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_T2_DIS") = 1)
    End With
     
     
     With c("OptEnT21")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON2_T21_DIS") = 0)
    End With
    
    
    With c("OptDisT21")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON2_T21_DIS") = 1)
    End With
    
      With c("OptEnCDC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CDC_DIS") = 0)
    End With
    
    
    With c("OptDisCDC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CDC_DIS") = 1)
    End With
    
      With c("OptEnMDU")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_MDU_DIS") = 0)
    End With
    
    With c("OptDisCDC")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CDC_DIS") = 1)
    End With
    
      With c("OptEnUART1")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 0)
    End With
    
    With c("OptDisUART1")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
    End With
    
     With c("OptEnCAN")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 0)
    End With
    
    With c("OptDisCAN")
       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CAN_DIS") = 1)
    End With
    
'        With e("OptEnADC")
'     If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Then
'     .DisabledToolTipText = "ADC module is disabled"
'     Else
'     .DisabledToolTipText = "ADC module is enabled."
'   End If
'    End With
'
'
'
'     With e("OptDisADC")
'     If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Then
'     .DisabledToolTipText = "ADC module is disabled"
'     Else
'     .DisabledToolTipText = "ADC module is enabled."
'   End If
'    End With
    
''     With c("OptEnCCU")
''       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 0)
''    End With
''
''     With e("OptEnCCU")
''     If (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Then
''     .DisabledToolTipText = "CCU module is disabled"
''     Else
''     .DisabledToolTipText = "CCU module is enabled."
''   End If
''    End With
''
''    With c("OptDisCCU")
''       .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
''    End With
''
''    With e("OptDisADC")
''     If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Then
''     .DisabledToolTipText = "CCU module is disabled"
''     Else
''     .DisabledToolTipText = "CCU module is enabled."
''   End If
''    End With
''
''
'End If         ' if Pagename

  OnShowPageControl = True
  Exit Function

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

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

Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFunctions = False

  Dim pos As Long

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

    If (Not ps.AddFrame("fraPS_USE_Init", 100, 100, 4150, 700, "Initialization Funtion")) Then Exit Function
    If (Not ps.AddCheck("chkPS_USE_Init", 200, 270, 930, 380, "PS_vInit")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_Init", 2150, 300, 1900, 315)) Then Exit Function

    If (Not ps.AddFrame("fraPS_CFile", 4400, 100, 4150, 700, "Source File")) Then Exit Function
    If (Not ps.AddText("txtPS_CFile", 1500, 300, 2550, 315)) Then Exit Function
    If (Not ps.AddLabel("lblPS_CFile", 0, 200, 300, 1575, 380, "File name")) Then Exit Function

    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, "Function Library")) Then Exit Function
    pos = 0
    ' Functions and Macros
    If (Not ps.AddCheck("chkPS_USE_SetSlowDown", 200, 270 + pos * 300, 1695, 380, "PS_vSetSlowDown")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_SetSlowDown", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkPS_USE_ResetSlowDown", 200, 270 + pos * 300, 1900, 380, "PS_vResetSlowDown")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_ResetSlowDown", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkPS_USE_SetIdle", 200, 270 + pos * 300, 1200, 380, "PS_vSetIdle")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_SetIdle", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    

    If (Not ps.AddCheck("chkPS_USE_SetPowerDown", 200, 270 + pos * 300, 1800, 380, "PS_vSetPowerDown")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_SetPowerDown", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkPS_USE_DisableModule", 200, 270 + pos * 300, 1750, 380, "PS_vDisableModule")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_DisableModule", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkPS_USE_EnableModule", 200, 270 + pos * 300, 1710, 380, "PS_vEnableModule")) Then Exit Function
    If (Not ps.AddText("txtPS_NAME_EnableModule", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1


  End If

  OnChangingPageFunctions = True
End Function

Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
   
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "chkPS_USE_Init"
             r.v("PS_USE_Init") = v(1)
    
        Case "txtPS_NAME_Init"
             If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkPS_USE_Init").Caption)) Then
                r.v("PS_NAME_Init") = v(1)
             End If
    
        Case "txtPS_CFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblPS_CFile").Caption)) Then
                r.v("PS_CFile") = v(1)
             End If
    End Select     ' case Controlname

    If (Not UpdateFunction(ps, Controlname, v, "SetSlowDown")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ResetSlowDown")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetIdle")) Then Exit Function
  
    If (Not UpdateFunction(ps, Controlname, v, "SetPowerDown")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "DisableModule")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "EnableModule")) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' control: chkPS_USE_Init (show)
    '-------------------------------------------------------------------------
    c("chkPS_USE_Init").Value = -CInt(r.v("PS_USE_Init") = 1)
    e("chkPS_USE_Init").EnabledTooltipText = FormatFunctionToolTip(r, func, "PS_NAME_Init")

    '-------------------------------------------------------------------------
    ' control: txtPS_NAME_Init (show)
    '-------------------------------------------------------------------------
    With c("txtPS_NAME_Init")
        bDisabled = r.v("PS_USE_Init") = 0
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("PS_NAME_Init"), "S")
    End With

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

    If (Not ShowFunction(ps, v, func, "SetSlowDown")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ResetSlowDown")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetIdle")) Then Exit Function
   
    If (Not ShowFunction(ps, v, func, "SetPowerDown")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "DisableModule")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "EnableModule")) Then Exit Function

  
    '-------------------------------------------------------------------------
    ' control: lblPS_CFile (show)
    '-------------------------------------------------------------------------
    With c("lblPS_CFile")
        bDisabled = r.v("PS_USE_Init") = 0
        .Enabled = Not bDisabled
    End With

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

    '-------------------------------------------------------------------------
    ' control: txtPS_CFile (show)
    '-------------------------------------------------------------------------
    With c("txtPS_CFile")
      bDisabled = (r.v("PS_USE_Init") = 0)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.v("PS_CFile"), "S")
    End With

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

  End If         ' if Pagename
     
  OnShowPageFunctions = True
  Exit Function

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

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

  Dim r As ProjectData
  Dim c As Collection

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

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

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

  UpdateFunction = True
ExitLabel:
End Function


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

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

  '-------------------------------------------------------------------------
  ' control: chkPS_USE_.. (show)
  '-------------------------------------------------------------------------
  With c("chkPS_USE_" & sName)
     bDisabled = (r.v("PS_USE_Init") = 0)

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


  With e("chkPS_USE_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        
                .DisabledToolTipText = GetDisabledFunctionTooltipEntry(func, "PS_NAME_" & sName)
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)

       
    Else
        ' tooltip if control is enabled
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "PS_NAME_" & sName)
    End If
  End With

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

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

  ShowFunction = True
ExitLabel:
End Function
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

Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim iPos As Integer
  Dim sName As String

  OnChangingPageParameters = False

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

    If (Not ps.AddFrame("fraPS_HFile", 100, 100, 8450, 700, "Header File")) Then Exit Function
    If (Not ps.AddText("txtPS_HFile", 1825, 250, 5000, 315)) Then Exit Function
    If (Not ps.AddLabel("lblPS_HFile", 0, 200, 300, 1575, 380, "File name")) Then Exit Function

    If (Not ps.AddFrame("fraParameters1", 100, 900, 4150, 4400, "Parameters")) Then Exit Function

    For iPos = 0 To 8
        sName = ModuleId(iPos)
        If (Not ps.AddLabel("lblPar_" & sName, 0, 200, 370 + iPos * 300, 1575, 380, sName)) Then Exit Function
        If (Not ps.AddText("txtPar_" & sName, 1825, 300 + iPos * 300, 1900, 315)) Then Exit Function
    Next iPos

  End If

  OnChangingPageParameters = True
End Function

Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageParameters = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim sName As String
  Dim iMod As Integer

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


  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtPS_HFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblPS_HFile").Caption)) Then
                r.v("PS_HFile") = v(1)
            Else
                Exit Function
            End If
            
        Case Else

            For iMod = 0 To NUMBER_OF_PM_MODULES - 1
                sName = ModuleId(iMod)
                If (Controlname = "txtPar_" & sName) Then
                    If (IsInputFormatOK(v(1), FORMAT_PARAMETERS, c("lblPar_" & sName).Caption)) Then
                        r.v("PS_PARA_MODULE_" & sName) = v(1)
                    Else
                        Exit Function
                    End If
                End If
            Next iMod

    End Select

    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------
    With c("lblPS_HFile")
        bDisabled = (r.v("PS_USE_Init") = 0)
        .Enabled = Not bDisabled
    End With
    With e("lblPS_HFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

    With c("txtPS_HFile")
        bDisabled = (r.v("PS_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("PS_HFile"), "S")
    End With
    With e("txtPS_HFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

    For iMod = 0 To NUMBER_OF_PM_MODULES - 1
        sName = ModuleId(iMod)
        With c("txtPar_" & sName)
            bDisabled = (r.v("PS_USE_Init") = 0)
            .Enabled = Not bDisabled
            .Text = FormatTextOutput(r.v("PS_PARA_MODULE_" & sName), "S")
        End With
        With e("txtPar_" & sName)
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_PARAMETER
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
            End If
        End With
        c("lblPar_" & sName).Enabled = Not bDisabled
    Next iMod

  End If         ' if Pagename


  OnShowPageParameters = True
  Exit Function

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

Public Function ResetRXDpins(r As ProjectData) As Boolean

        If (r.v("PS_Pin_Rx_1_Used") = 1) Then
            If r.v("UART_RxPin_P1.0_Used") = 1 Then
                r.v("UART_RxPin_P1.0_Used") = 0
                Call ReleaseAlternateInputPin(r, "RXD_0")
                r.v(SCU_PREFIX & "MODPISEL_URRIS") = 0
            End If
        End If
        
        If (r.v("PS_Pin_Rx_1_Used") = 2) Then
            If r.v("UART_RxPin_P0.1_Used") = 1 Then
                r.v("UART_RxPin_P0.1_Used") = 0
                Call ReleaseAlternateInputPin(r, "RXD_1")
                r.v(SCU_PREFIX & "MODPISEL_URRIS") = 0
            End If
        End If

End Function

Public Function ResetEXTINTpins(r As ProjectData) As Boolean

             If r.v("EXINT0_Pin_P0.5_Used") = 1 Then
                r.v("EXINT0_Pin_P0.5_Used") = 0
                Call ReleaseAlternateInputPin(r, "EXINT0_0")
              End If
              
              If r.v("EXINT0_Pin_P1.4_Used") = 1 Then
                  r.v("EXINT0_Pin_P1.4_Used") = 0
                  Call ReleaseAlternateInputPin(r, "EXINT0_1")
               End If

End Function
