'#Uses "..\include\Global.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\classes\FunctionClass.cls""
Option Explicit
'*****************************************************************************
' Module:
'        PM
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the 
'        PM dialog script and in the PM codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0   ahe          14.06.00    final version for C167CS
'
'        ----------------------------------------------------------------------
'        3.0   ahe          02.08.00    final version for C161CS/JC/JI
'                                       - delete PWM parameter
'                                       - added ASC1, I2C and SDLM parameters
'                                       - added fct 'PM_vSetRTCClockSource'
'                                       - added fct 'PM_vSetSDDClockSource'
'                                       - added parameters MAIN_OSCILLATOR
'                                       - added parameters AUX_OSCILLATOR
'
'*****************************************************************************


'*****************************************************************************
' Constants
'*****************************************************************************

'*****************************************************************************
'Description:
'        For each function which should be used for this module a line 
'        "If (Not func.AddFunction .." must be insert in this function.
'        For each parameter that should be used for this function a  
'        line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added function a project variable with the name 
'        "PM_NAME_Functionname" must be exist in the *.vars file. 
'-----------------------------------------------------------------------------
'Parameters:
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next 

  Dim sDescription As String
  Dim sReturnValue As String
  Dim sVarPre As String
  Dim sName As String
  Dim i As Integer
  
  sVarPre = "PM"

  RefreshFunctionDescriptions = False

  ' for each function of this module the property AddFunction must be called
  '
  ' AddFunction(sFuncName As String, sFuncType As String, sFuncDescription As String, 
  '             sReturnvalue As String, lSort As Long) As Boolean
  '
  ' sFuncName          | String | function name as key (use the name of the variable 
  '                               for the function name e.g. SSC_NAME_Init) 
  ' sFuncType          | String | type of the function
  ' sFuncDescription   | String | description of the function
  ' sReturnvalue       | String | description of the return value
  ' lSort              | Long   | ' sort of the function (0 => macro, 1 => function, 2 => ISR, 3 => TRAP)

    ' for each parameter of a function the property AddParameter must be called
    '
    'AddParameter(sParName As String, sPar As String, sParType As String, sParDescription As String) As Boolean    
    '
    ' sParName         | String | parameter name (key)
    ' sPar             | String | parameter name
    ' sParType         | String | type of the parameter
    ' sParDescription  | String | description of the parameter


  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sVarPre)
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetSlowDown" 
  sDescription = "This function enters the slow down operation mode. " & _
                 "The oscillator frequency is divided by a factor stored in CLKREL." & vbCrLf  & _
                 "An implemented PLL may be switched off in this case or kept running, " & _
                 "depending on the requirements of the application. " & vbCrLf & _
                 "The following definitions are available for PllMode:" & vbCrLf & _
                 "" & r.v(sVarPre & "_PARA_PLL_ON") & vbCrLf & _
                 "" & r.v(sVarPre & "_PARA_PLL_OFF") & vbCrLf & _
                 "" & _
                 "Note:" & vbCrLf & _
                 "During slow down operation the whole device (including bus interface and " & _
                 "generation of signal CLKOUT) is clocked with the asymmetrical slow down clock. " & _
                 "Switching to slow down operation affects frequency sensitive peripherals " & _
                 "like serial interfaces, timers, etc. If these units are to be operated " & _
                 "in slow down mode their prescaler or reload values must be adapted." & vbCrLf  & _
                 "Sleep mode connot be entered in slow dowm mode."

  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "PLL mode"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "PllMode", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "ExitSlowDown" 
  sDescription = "This function exits the slow down operation mode." & vbCrLf & _
                 "The device is clocked with the configured basic frequency."

  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "GetClkStatus" 
  sDescription = "This macro returns the clock signal status bit. If the status bit is 0, " & _
                 "the main oscillator is unstable or the PLL is unlocked. If the status bit " & _
                 "is 1, the main oscillator is stable and the PLL is locked."

  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetPowerDown" 
  sDescription = "This function enters the power down mode. Clocking of all internal blocks " & _
                 "is stopped (RTC also). This mode can only be terminated by an external" & _
                 "hardware reset." & _
                 "" & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "This instruction is effective only if the #NMI pin is externally pulled low " & _
                 "while the PWRDN instruction is executed. The microcontroller will enter power " & _
                 "down mode after the PWRDN instruction has completed."

  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetIdle" 
  sDescription = "This function enters the idle mode. " & _
                 "In this mode all enabled peripherals, including the watchdog " & _
                 "timer, continue to operate normally, only the CPU operation " & _
                 "is halted and the on-chip memory modules are disabled. " & _
                 "The idle mode is terminated by interrupt requests from any " & _
                 "enabled interrupt source whose individual interrupt enable " & _
                 "flag was set before the idle mode was entered, regardless of " & _
                 "bit IEN (globally interrupt enable bit). " & _
                 "For details see User's Manual."
                 
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetSleep" 
  sDescription = "This function enters the sleep mode. " & _
                 "Clocking of all internal blocks is stopped (RTC optional). " & _
                 "Exit/Wakeup from sleep state is possible with all external interrupts, with #NMI " & _
                 "and with RTC interrupts." & _
                 "The parameter 'ubMode' has two settings:" & vbCrLf & _
                 "" & r.v(sVarPre & "_PARA_RTC_ON") & " - Sleep mode with running RTC"  & vbCrLf & _
                 "" & r.v(sVarPre & "_PARA_RTC_OFF") & " - Sleep mode with stopped RTC and stopped OSC"

  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Sleep mode"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "ubMode", "ubyte", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "EnableModule" 
  sDescription = "This function enables on-chip peripherals." & vbCrLf & _
                 "" & vbCrLf & _
                 "The following definitions are available for uwModule:" & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_ADC") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_ASC0") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_SSC") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_GPT1_2") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_DFM") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_PFM") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_CC1") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_CC2") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_ASC1") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_I2C") & vbCrLf & _
                 ""

                 If (r.Regs.BitFind("SYSCON3_SDLMDIS") = True) Then
                     sDescription = sDescription & _
                     "- " & r.v(sVarPre & "_PARA_SDLM") & vbCrLf & _
                     ""
                 End if

                 If (r.Regs.BitFind("SYSCON3_CAN1DIS") = True) Then
                     sDescription = sDescription & _
                     "- " & r.v(sVarPre & "_PARA_CAN1") & vbCrLf & _
                     ""
                 End If

                 If (r.Regs.BitFind("SYSCON3_CAN2DIS") = True) Then
                     sDescription = sDescription & _
                     "- " & r.v(sVarPre & "_PARA_CAN2") & vbCrLf & _
                     ""
                 End If

                 sDescription = sDescription & _
                 "- " & r.v(sVarPre & "_PARA_PCD")

  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the module"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "uwModule", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "DisableModule" 
  sDescription = "This function disables on-chip peripherals that are not required in a given system " & _
                 "status. If all modules that are fed by the peripheral clock driver (PCD) are " & _
                 "disabled and also the other functions fed by the PCD are not required, this clock " & _
                 "driver itself may also be disabled." & _
                 "" & vbCrLf & _
                 "The following definitions are available for uwModule:" & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_ADC") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_ASC0") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_SSC") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_GPT1_2") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_DFM") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_PFM") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_CC1") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_CC2") & vbCrLf & _
                 ""

                 If (r.Regs.BitFind("SYSCON3_SDLMDIS") = True) Then
                     sDescription = sDescription & _
                     "- " & r.v(sVarPre & "_PARA_SDLM") & vbCrLf & _
                     ""
                 End if

                 If (r.Regs.BitFind("SYSCON3_CAN1DIS") = True) Then
                     sDescription = sDescription & _
                     "- " & r.v(sVarPre & "_PARA_CAN1") & vbCrLf & _
                     ""
                 End If

                 If (r.Regs.BitFind("SYSCON3_CAN2DIS") = True) Then
                     sDescription = sDescription & _
                     "- " & r.v(sVarPre & "_PARA_CAN2") & vbCrLf & _
                     ""
                 End If

                 sDescription = sDescription & _
                 "- " & r.v(sVarPre & "_PARA_PCD") & _
                 "" & vbCrLf & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "The registers of the generic peripherals can be accessed even while the respective " & _
                 "modul is disabled, as long as PCD is running. The registers of X-peripherals cannot " & _
                 "be accessed while the respective module is disabled by any means. While a peripheral" & _
                 "is disabled its output pins remain in the state they had at the time of disabling."
                  
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the module"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "uwModule", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "StartCount" 
  sDescription = "This macro starts the counting of the programmable output frequency"
                  
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "StopCount" 
  sDescription = "This macro stops the counting of the programmable output frequency"
                  
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetReloadValue" 
  sDescription = "This macro loads the reload value ( 0x00 .. 0x3F ) of the programmable output frequency"
                  
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "reload value 0x00 .. 0x3F"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "uwValue", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetRTCClockSource" 
  sDescription = "This fnction sets the clock source for the RTC module." & vbcrlf & _
                 "" & vbCrLf & _
                 "The following definitions are available for uwSource:" & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_MAIN_OSCILLATOR") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_AUX_OSCILLATOR")
                 
                  
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "clock source for the RTC module"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "uwSource", "uword", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for PM_NAME_ ...
  '------------------------------------------------------------------------------------------------
  sName = "SetSDDClockSource" 
  sDescription = "This fnction sets the clock source for the slow down divider." & vbcrlf & _
                 "" & vbCrLf & _
                 "The following definitions are available for uwSource:" & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_MAIN_OSCILLATOR") & vbCrLf & _
                 "- " & r.v(sVarPre & "_PARA_AUX_OSCILLATOR")
                 
                  
  sReturnValue = "None" 
  If (Not func.AddFunction(sVarPre & "_NAME_" & sName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "clock source for the slow down divider"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sName & "_Par1", "uwSource", "uword", sDescription)) Then Exit Function


  	If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
End Function


'*****************************************************************************
'Description:
'        For each parameter that should be used as a constant (on page "Parameters")  
'        a line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added parameter a project variable with the name 
'        "DUMMY_PARA_Parametername" must be exist in the *.vars file. 
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex           parameter of the module which was added with AddModule
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshParameterDescriptions(vIndex As Variant, para As ParameterClass, r As ProjectData) As Boolean
  On Error Resume Next 

  RefreshParameterDescriptions = False

  Dim sDescription As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sParaName As String
  Dim i As Integer

  sVarPre = "PM" & vIndex
  sRegPre = sVarPre & "_"

  ' for each parameter of this module the property AddParameter must be called
  '
  ' AddParameter(sParameterName As String, sParameterDescription As String) As Boolean
  '
  ' sParameterName         | String | parameter name as key (use the name of the variable 
  '                                   for the parameter name e.g. SSC_PARA_MODE) 
  ' sParameterDescription  | String | description of the parameter

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the ADC module"
  sParaName = "ADC"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the ASC0 module"
  sParaName = "ASC0"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the SSC module"
  sParaName = "SSC"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the GPT1 and GPT2 module"
  sParaName = "GPT1_2"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  If (r.Regs.BitFind("SYSCON3_DFMDIS") = True) Then
      '------------------------------------------------------------------------------------------------
      ' Description for DUMMY_PARA_xx
      '------------------------------------------------------------------------------------------------
      sDescription = "This parameter identifies the on-chip data flash memory module"
      sParaName = "DFM"
      If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function
  End If
 
  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the on-chip programm flash memory module"
  sParaName = "PFM"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the CAPCOM1 module"
  sParaName = "CC1"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the CAPCOM2 module"
  sParaName = "CC2"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the ASC1 module"
  sParaName = "ASC1"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the I2C module"
  sParaName = "I2C"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  If (r.Regs.BitFind("SYSCON3_SDLMDIS") = True) Then
      '------------------------------------------------------------------------------------------------
      ' Description for DUMMY_PARA_xx
      '------------------------------------------------------------------------------------------------
      sDescription = "This parameter identifies the SDLM module"
      sParaName = "SDLM"
      If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function
  End If
  
  If (r.Regs.BitFind("SYSCON3_CAN1DIS") = True) Then
      '------------------------------------------------------------------------------------------------
      ' Description for DUMMY_PARA_xx
      '------------------------------------------------------------------------------------------------
      sDescription = "This parameter identifies the CAN1 module"
      sParaName = "CAN1"
      If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function
  End If
  
  If (r.Regs.BitFind("SYSCON3_CAN2DIS") = True) Then
      '------------------------------------------------------------------------------------------------
      ' Description for DUMMY_PARA_xx
      '------------------------------------------------------------------------------------------------
      sDescription = "This parameter identifies the CAN2 module"
      sParaName = "CAN2"
      If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function
  End If
  
  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the peripheral clock driver"
  sParaName = "PCD"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter is use in the function " & r.v(sVarPre & "_NAME_SetSleep") & " and identifies the RTC (ON) module"
  sParaName = "RTC_ON"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter is use in the function " & r.v(sVarPre & "_NAME_SetSleep") & " and identifies the RTC (OFF) module"
  sParaName = "RTC_OFF"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter is use in the function " & r.v(sVarPre & "_NAME_SetSlowDown") & " and identifies the RTC (ON) module"
  sParaName = "PLL_ON"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter is use in the function " & r.v(sVarPre & "_NAME_SetSlowDown") & " and identifies the RTC (ON) module"
  sParaName = "PLL_OFF"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the main oscillator"
  sParaName = "MAIN_OSCILLATOR"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for DUMMY_PARA_xx
  '------------------------------------------------------------------------------------------------
  sDescription = "This parameter identifies the auxiliary oscillator (32 kHz)"
  sParaName = "AUX_OSCILLATOR"
  If (Not para.AddParameter(sVarPre & "_PARA_" & sParaName, sDescription)) Then Exit Function

  
 	
 	If (Not para.Sort) Then Exit Function

  RefreshParameterDescriptions = True
End Function


'*****************************************************************************
'Description:
'          This function update the output frequency on port FOUT
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'-----------------------------------------------------------------------------
'Returns:
'       None
'
'*****************************************************************************
Sub UpdateOutputFrequency(r As ProjectData)
  On Error Resume Next
  Dim f As Double

  f = r.v("PM_ReqFreq")
  If (f < GetMinOutputFrequency(r)) Then
    f = GetMinOutputFrequency(r)
  End If
  If (f > GetMaxOutputFrequency(r)) Then
    f = GetMaxOutputFrequency(r)
  End If
  r.v("PM_ReqFreq") = f

  r.l("FOCON_FORV") = GetSystemClock(r) / (f * 2^(1 - r.v("FOCON_FOSS"))) - 1


End Sub



'*****************************************************************************
'Description:
'          This function returns the minimum output frequency on port FOUT
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'-----------------------------------------------------------------------------
'Returns:
'      minimum possible output frequency [MHz]
'
'*****************************************************************************
Function GetMinOutputFrequency(r As ProjectData)
  On Error Resume Next
  Dim f As Double

  f = GetSystemClock(r) / ( 64 * 2^(1 - r.v("FOCON_FOSS")) ) 
  GetMinOutputFrequency = f


End Function


'*****************************************************************************
'Description:
'          This function returns the maximum output frequency on port FOUT
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'-----------------------------------------------------------------------------
'Returns:
'      maximum possible output frequency [MHz]
'
'*****************************************************************************
Function GetMaxOutputFrequency(r As ProjectData)
  On Error Resume Next
  Dim f As Double

  f = GetSystemClock(r) / ( 2^(1 - r.v("FOCON_FOSS")) )
  GetMaxOutputFrequency = f


End Function


'*****************************************************************************
'Description:
'          This function returns the real output frequency on port FOUT
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'-----------------------------------------------------------------------------
'Returns:
'      real output frequency [MHz]
'
'*****************************************************************************
Function GetRealOutputFrequency(r As ProjectData)
  On Error Resume Next
  Dim f As Double

  f = GetSystemClock(r) / ( (r.v("FOCON_FORV") + 1) * 2^(1 - r.v("FOCON_FOSS")) )
  GetRealOutputFrequency = f


End Function

'*****************************************************************************
'Description:
'          This function returns the SDD output frequency
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'-----------------------------------------------------------------------------
'Returns:
'      real output frequency [MHz]
'
'*****************************************************************************
Function GetSDDOutputFrequency(r As ProjectData)
  On Error Resume Next
  Dim f As Double

  If (r.v("RP0H_CLKCFG") = 1) Then
    f = r.v("MAIN_OSC") / (r.v("SYSCON2_CLKREL") + 1) / 2
  Else
    f = r.v("MAIN_OSC") / (r.v("SYSCON2_CLKREL") + 1)
  End If
  
  GetSDDOutputFrequency = f


End Function

'*****************************************************************************
'Description:
'          This function returns the SDD input frequency
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'-----------------------------------------------------------------------------
'Returns:
'      real input frequency [MHz]
'
'*****************************************************************************
Function GetSDDInputFrequency(r As ProjectData)
  On Error Resume Next
  Dim f As Double

  f = r.v("MAIN_OSC")
  
  GetSDDInputFrequency = f

End Function
