Attribute VB_Name = "Global"
'#Uses "..\classes\FunctionClass.cls
'#Uses "Format.inc"
'#Uses "Const.inc"
'#Uses "..\classes\ParameterClass.cls







Option Explicit
'*****************************************************************************
' @Doc
' @Module        GLOBAL.INC
'-----------------------------------------------------------------------------
' @Controllers   
'
' @Description   This module contains global functions that can 
'                be used in all other script files.
'
'-----------------------------------------------------------------------------
' @History       Date           Author     Description
' 2-1-0          24.08.99       ste        final version
'                17.02.00       ahe
'                               ConvertFrequency function
'
'*****************************************************************************

' this type is for the calculation of a time 
' it is used in the function ConvertTime()
Type UnitType
  dValue As Double   ' value of the time / frequency
  sUnit As String    ' unit of the time / frequency
  dDivider As Double    ' divider factor referring to µs / MHz
End Type


'------------------------------------------------------------------------------------
' Function Description
'------------------------------------------------------------------------------------
Function GetSystemClock(r As ProjectData) As Variant
  On Error GoTo GetSystemClockError

  GetSystemClock = r.v("MAIN_OSC") * r.v("MAIN_OSC_Factor") 
    
  Exit Function

GetSystemClockError:
  ErrorBox "Error in function GetSystemClock", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function makes all activities to enable an interrupt.
'        It sets the service request enable bit and selectes the service 
'        request routine.
'        Example:
'        Call EnableSRN(r, "SSC0", "SRCT", "Tx")
'    
'        For this example the register SSC0_SRCT and the variable
'        SSC0_USE_Tx must exist. 
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the ProjectData object
'        ModulName        the name of the Modul (e.g. SSC)
'        RegName          the name of the register (e.g. SSCRIC)
'        BitName          the name of the bit (e.g. SSCRIE)
'        ISRName          the name of the service request routine (e.g Tx)
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub EnableSRN(r As ProjectData, ModuleName As String, RegName As String, BitName As String, ISRName As String)
On Error Resume Next
  r.v(RegName & "_" & BitName) = 1
  r.v(ModuleName & "_USE_" & ISRName) = 1
'  r.v(ModuleName & "_" & SRCName & "_TOS") = 0
'  r.v(ModuleName & "_" & SRCName & "_SRPN") = 0
End Sub



'*****************************************************************************
'Description:
'        This function makes all activities to disable an interrupt.
'        It resets the service request enable bit, set the priority to zero
'        and deselectes the service request routine.
'        Example:
'        Call DisableSRN(r, "SSC0", "SRCT", "Tx")
'    
'        For this example the register SSC0_SRCT and the variable
'        SSC0_USE_Tx must exist. 
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the ProjectData object
'        ModuleName       the name of the module (e.g. SSC0)
'        RegName          the name of the register (e.g. SSCRIC)
'        BitName          the name of the bit (e.g. SSCRIE)
'        ISRName          the name of the service request routine (e.g Tx)
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub DisableSRN(r As ProjectData, ModuleName As String, RegName As String, BitName As String, ISRName As String)
  On Error Resume Next
  Dim iChannel As Integer

  r.v(RegName & "_" & BitName) = 0
  r.v(ModuleName & "_USE_" & ISRName) = 0
  
  If r.v(RegName & "_ILVL") = 15 Then
    r.v("PEC_CHANNEL_" & (r.v(RegName & "_GLVL") + 4)) = ""
    iChannel = r.v(RegName & "_GLVL") + 4
    Call SetPECChannelToDefault(r, iChannel)
  End If

  If r.v(RegName & "_ILVL") = 14 Then
    r.v("PEC_CHANNEL_" & r.v(RegName & "_GLVL")) = ""
    iChannel = r.v(RegName & "_GLVL")
    Call SetPECChannelToDefault(r, iChannel)
  End If
   
  r.v(RegName & "_GLVL") = 0
  r.v(RegName & "_ILVL") = 0

End Sub



'*****************************************************************************
'Description:
'        This function checks if the requested interrupt service routine 
'        is selected.
'        Example:
'        IsISRSelected(r, "SSC", "SSCTIC_SSCTIE", "Tx")
'    
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the ProjectData object
'        ModuleName       the name of the module (e.g. SSC)
'        RegName          the name of the service request control register (e.g SSCTIC)
'        BitName          the name of the service request control bit (e.g SSCTIE)
'        ISRName          the name of the service request routine (e.g Tx)
'-----------------------------------------------------------------------------
'Returns:
'       Fales             if not seleected
'       True              else
'*****************************************************************************
Function IsISRSelected(r As ProjectData, ModuleName As String, RegName As String, BitName As String, ISRName As String) As Boolean
On Error Resume Next
  IsISRSelected = False
  If (r.v(RegName & "_GLVL") > 0 Or r.v(RegName & "_ILVL") > 0) Then
    IsISRSelected = (r.v(ModuleName & "_USE_Init") = 1 And r.v(RegName & "_" & BitName) = 1 And r.v(ModuleName & "_USE_" & ISRName) = 1)
  End If
End Function



'*****************************************************************************
'Description:
'        This function checks if the function is selected.
'        Example:
'        IsIFctSelected(r, "SSC", "Tx")
'    
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the ProjectData object
'        ModuleName       the name of the module (e.g. SSC)
'        FctName          the name of the function (e.g ReadCAPREL)
'-----------------------------------------------------------------------------
'Returns:
'       Fales             if not seleected
'       True              else
'*****************************************************************************
Function IsFctSelected(r As ProjectData, ModuleName As String, FctName As String) As Boolean
On Error Resume Next
  IsFctSelected = False
  IsFctSelected = (r.v(ModuleName & "_USE_Init") = 1 And r.v(ModuleName & "_USE_" & FctName) = 1)
End Function


'*****************************************************************************
'Description:
'        This functions generates the statments for the interrupt service 
'        request node.
'        Example:
'        Call GenerateIR(f, r, "SSCTIC", "SSCTIE", "transmit")
'    
'-----------------------------------------------------------------------------
'Parameters:
'        f                file handle
'        r                reference to the ProjectData object
'        RegName          the name of the service request control register 
'                         (e.g. SSCTIC)
'        BitName          the name of the service request control bit (e.g. SSCTIE)
'        ISRName          the name of the interrupt node (e.g transmit )
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub GenerateIR(f As Variant, r As ProjectData, RegName As String, BitName As String, IntName As String)
    On Error Resume Next
       
    Dim v As Variant
    Dim iHelp As Integer
    Dim d As String

    If (r.v(RegName & "_" & BitName ) = 1) Then
      Print #f, FormatCommentsForInit(1, IntName & " service request node configuration:")    
    
      If (r.v(RegName & "_ILVL") = 0) Then
        Print #f, FormatCommentsForInit(2, IntName & " interrupt is enabled but NO INTERRUPT WILL BE GENERATED because priority level is 0")    
      Else
        Print #f, FormatCommentsForInit(1, IntName & " interrupt priority level (ILVL) = " & Format(r.v(RegName & "_ILVL")))         
        Print #f, FormatCommentsForInit(1, IntName & " interrupt group level (GLVL) = " & Format(r.v(RegName & "_GLVL")))         
      End If    
      
      v = 0
      v = v + r.sfr(RegName)
      Print #f, ""
      Print #f, FormatCodeStatemente(2, RegName, "=", FormatTextOutput(v, "H4"), "")
      Print #f, ""

      If (r.v(RegName & "_ILVL") > 13) Then
        iHelp = 4 * (r.v(RegName & "_ILVL") - 14) + r.v(RegName & "_GLVL")
        
        '------------------------------------------------------------------------------------------------
        ' Use PEC channel " & iHelp & " for " & r.v("PEC_CHANNEL_" & iHelp) & ":"
        '------------------------------------------------------------------------------------------------
        Print #f, "  /// Use PEC channel " & iHelp & " for " & r.v("PEC_CHANNEL_" & iHelp) & ":"

        '--------------------------------------------- PECCx_COUNT
        If (r.v("PECC" & iHelp & "_COUNT") = 255) Then
          d = "continuous transfer"
        Else
          If (r.v("PECC" & iHelp & "_COUNT") = 0) Then
            d = "normal interrupt"
          Else
            d = "decrement counter"
          End If
        End If
        Print #f, FormatCommentsForInit(1, d)

        '--------------------------------------------- PECCx_INC
        Select Case (r.v("PECC" & iHelp & "_INC"))
                Case (0)
                      d = "pointers are not modified"
                Case (1)
                      d = "increment destination pointer"
                Case (2)
                      d = "increment source pointer"
        End Select
        Print #f, FormatCommentsForInit(1, d)

        '--------------------------------------------- PECCx_BWT
        If (r.v("PECC" & iHelp & "_BWT") = 0) Then
          d = "transfer a word"
        Else
          d = "transfer a byte"
        End If
        Print #f, FormatCommentsForInit(1, d)
        Print #f, ""
    
        v = 0
        v = v + r.sfr("PECC" & iHelp)
        Print #f, FormatCodeStatemente(2, "PECC" & iHelp, "=", FormatTextOutput(v, "H4"), "load PECC" & iHelp & " control register")
        Print #f, ""


        '--------------------------------------------- SRCPx_SRCPx
        If (r.v("PECC" & iHelp & "_COUNT") <> 0) Then
          If (r.v("SRCP" & iHelp & "_SRCP" & iHelp) = "0") Then
            d = "DO NOT FORGET TO SET THE SOURCE-POINTER FOR PECC CHANNEL " & iHelp & " BECAUSE IT IS SELECTED FOR USER DEFINED"
            Print #f, FormatCommentsForInit(2, d)
          Else
            If (InStr(r.v("MAIN_COMPILER"), "Tasking")) Then
              Print #f, "  SRCP" & iHelp & "  =  (uword)(&" & r.v("SRCP" & iHelp & "_SRCP" & iHelp) & ");
            End If
            If (InStr(r.v("MAIN_COMPILER"), "Keil")) Then
              Print #f, "  SRCP" & iHelp & "  =  _sof_(&" & r.v("SRCP" & iHelp & "_SRCP" & iHelp) & ");
            End If
          End If
        End If

        '--------------------------------------------- DSTPx_DSTPx
        If (r.v("PECC" & iHelp & "_COUNT") <> 0) Then
          If (r.v("DSTP" & iHelp & "_DSTP" & iHelp) = "0") Then
            d = "DO NOT FORGET TO SET THE DESTINATION-POINTER FOR PECC CHANNEL " & iHelp & " BECAUSE IT IS SELECTED FOR USER DEFINED"
            Print #f, FormatCommentsForInit(2, d)
          Else
            If (InStr(r.v("MAIN_COMPILER"), "Tasking")) Then
              Print #f, "  DSTP" & iHelp & "  =  (uword)(&" & r.v("DSTP" & iHelp & "_DSTP" & iHelp) & ");
            End If
            If (InStr(r.v("MAIN_COMPILER"), "Keil")) Then
              Print #f, "  DSTP" & iHelp & "  =  _sof_(&" & r.v("DSTP" & iHelp & "_DSTP" & iHelp) & ");
            End If
          End If
        End If

        Print #f, ""
        Print #f, ""
      End If
      
    End If
    
End Sub



'*****************************************************************************
'Description:
'        This function generates the declaration for the interrupt service 
'        routine in the generated code.
'    
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the ProjectData object
'        ISRName          the name of the service request routine (e.g SSC0_viTx)
'        VectorName       the name of the service request routine vector (e.g TX_INT)
'-----------------------------------------------------------------------------
'Returns:
'        Service request declaration
'*****************************************************************************
Function GenerateIsrDeclaration(r, ISRName As String, VectorName As Variant) As String
    On Error Resume Next
    
    If (InStr(r.v("MAIN_COMPILER"), "Tasking")) Then
        GenerateIsrDeclaration = "interrupt (" & VectorName & ") void " & ISRName & "(void)"
    End If

    If (InStr(r.v("MAIN_COMPILER"), "Keil")) Then
        GenerateIsrDeclaration = "void " & ISRName & "(void) interrupt " & VectorName
    End If

End Function


'*****************************************************************************
'Description:
'        This function converts a time in µs to an other unit
'    
'-----------------------------------------------------------------------------
'Parameters:
'        dValue           the time in µs
'-----------------------------------------------------------------------------
'Returns:
'        .dValue          the new value for the time
'        .sUnit           the new unit of the time
'        .bDivider        the new divider of the new time, referring to µs
'*****************************************************************************
Function ConvertTime(dValue As Double) As UnitType
  On Error Goto ConvertTimeError
  Dim dHelp As Double
  Dim sHelp As String
  Dim dDivider As Double

  dHelp = dValue
  sHelp = "µs"
  dDivider = 1

  If (dHelp < 1) Then
    dHelp = dHelp * 1000
    sHelp = "ns"
    dDivider = dDivider / 1000
  End If
 
  If (dHelp >= 1000) Then
    dHelp = dHelp / 1000
    sHelp = "ms"
    dDivider = 1000
    If (dHelp >= 1000) Then
      dHelp = dHelp / 1000
      sHelp = "s"
      dDivider = dDivider * 1000
      If (dHelp >= 60) Then
        dHelp = dHelp / 60
        sHelp = "min"
        dDivider = dDivider * 60
        If (dHelp >= 60) Then
          dHelp = dHelp / 60
          sHelp = "h"
          dDivider = dDivider * 60
          If (dHelp >= 24) Then
            dHelp = dHelp / 24
            sHelp = "days"
            dDivider = dDivider * 24
            If (dHelp >= 30) Then
              dHelp = dHelp / 30
              sHelp = "months"
              dDivider = dDivider * 30
              If (dHelp >= 12) Then
                dHelp = dHelp / 12
                sHelp = "years"
                dDivider = dDivider * 12
              End If
            End If
          End If
        End If
      End If
    End If
  End If

  ConvertTime.dValue = dHelp
  ConvertTime.sUnit = sHelp
  ConvertTime.dDivider = dDivider
     

  Exit Function

ConvertTimeError:
  ConvertTime.dValue = dValue
  ConvertTime.sUnit = "µs"
  ConvertTime.dDivider = 1
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function converts a frequency in MHz to an other unit
'    
'-----------------------------------------------------------------------------
'Parameters:
'        dValue           the time in MHz
'-----------------------------------------------------------------------------
'Returns:
'        .dValue          the new value for the frequency
'        .sUnit           the new unit of the frequency
'        .bDivider        the new divider of the new time, referring to MHz
'*****************************************************************************
Function ConvertFrequency(dValue As Double) As UnitType
  On Error Goto ConvertFrequencyError
  Dim dHelp As Double
  Dim sHelp As String
  Dim dDivider As Double

  dHelp = dValue
  sHelp = "MHz"
  dDivider = 1

  If (dHelp < 1) Then
    dHelp = dHelp * 1000
    sHelp = "kHz"
    dDivider = dDivider / 1000
  
    If (dHelp < 1) Then
      dHelp = dHelp * 1000
      sHelp = "Hz"
      dDivider = dDivider / 1000
    End If
  
  End If
 

  ConvertFrequency.dValue = dHelp
  ConvertFrequency.sUnit = sHelp
  ConvertFrequency.dDivider = dDivider
     

  Exit Function

ConvertFrequencyError:
  ConvertFrequency.dValue = dValue
  ConvertFrequency.sUnit = "MHz"
  ConvertFrequency.dDivider = 1
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function converts a baud rate in [baud] to an other unit
'    
'-----------------------------------------------------------------------------
'Parameters:
'        dValue           the baudrate in [baud]
'-----------------------------------------------------------------------------
'Returns:
'        .dValue          the new value for the baud rate
'        .sUnit           the new unit of the baud rate
'        .bDivider        the new divider of the new baud rate, referring to [baud]
'*****************************************************************************
Function ConvertBaudrate(dValue As Double) As UnitType
  On Error Goto ConvertBaudrateError
  Dim dHelp As Double
  Dim sHelp As String
  Dim dDivider As Double

  dHelp = dValue
  sHelp = "baud"
  dDivider = 1

  If (dHelp >= 1000) Then
    dHelp = (dHelp / 1000)
    sHelp = "kbaud"
    dDivider = dDivider * 1000
    
    If (dHelp >= 1000) Then
      dHelp = (dHelp / 1000)
      sHelp = "Mbaud"
      dDivider = dDivider * 1000
    End If
  
  End If

  ConvertBaudrate.dValue = dHelp
  ConvertBaudrate.sUnit = sHelp
  ConvertBaudrate.dDivider = dDivider  

  Exit Function

ConvertBaudrateError:
  ConvertBaudrate.dValue = dValue
  ConvertBaudrate.sUnit = "baud"
  ConvertBaudrate.dDivider = 1
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function makes all update activities for the page Functions. 
'-----------------------------------------------------------------------------
'Parameters:
'        sIndex          module name (prefix of the functions)
'        ps              reference to the Peripherals object
'        func            reference to the FunctionClass object
'        Controlname     control name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function UpdateFunction(sIndex As String, ps As Peripherals, func As FunctionClass, Controlname As String, v() As Variant) As Boolean
  On Error Goto UpdateFunctionError
  UpdateFunction = False

  Dim r As ProjectData
  Dim sName As String
  Dim d As String
  Dim l As Long

  Set r = ps.ProjectData

  ' for each function in this FunctionClass object
  For l = 1 To func.FunctionCount
    ' get the function name which was insert in 'Include.inc' with 'AddFunction()'
    d = func.FunctionName(l)
    ' get only the third part of the function name (e.g "Init")
    sName = Right(d, Len(d) - Instr(d, "NAME") - Len("NAME"))

    '---------------------------------------------------------------------
    ' control: chk_.. (action)
    '---------------------------------------------------------------------
    If (Controlname = "chk_" & sName) Then
      ' action on clicking the selected control
      r.v(sIndex & "_USE_" & sName) = v(1)
      Exit For
    End If  

    '---------------------------------------------------------------------
    ' control: txt_.. (action)
    '---------------------------------------------------------------------
    If (Controlname = "txt_" & sName) Then
      ' action on clicking the selected control
      If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, , , )) Then
        r.s(d) = v(1)
      Else
        Exit Function
      End If
      Exit For
    End If
  Next l


  '---------------------------------------------------------------------
  ' control: txt_CFile (action)
  '---------------------------------------------------------------------
  If (Controlname = "txt_CFile") Then
    ' action on clicking the selected control
    If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, , , )) Then
      r.v(sIndex & "_CFile") = v(1)
    Else
      Exit Function
    End If
  End If


  UpdateFunction = True
  Exit Function

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


'*****************************************************************************
'Description:
'        This function makes all show activities for the page Functions 
'-----------------------------------------------------------------------------
'Parameters:
'        sIndex          module name (prefix of the functions)
'        ps              reference to the Peripherals object
'        func            reference to the FunctionClass object
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function ShowFunction(sIndex As String, ps As Peripherals, func As FunctionClass, v() As Variant) As Boolean
  On Error Goto ShowFunctionError
  ShowFunction = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim sName As String
  Dim d As String
  Dim l As Long

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

  ' for each function in this 'func' object
  For l = 1 To func.FunctionCount
    ' get the function name which was insert in 'Include.inc' with 'AddFunction()'
    d = func.FunctionName(l)

    ' get only the third part of the function name (e.g "Init")
    sName = Right(d, Len(d) - Instr(d, "NAME") - Len("NAME"))

    '-------------------------------------------------------------------------
    ' control: chk_.. (show)
    '-------------------------------------------------------------------------
    ' action on showing the control
    With c("chk_" & sName)
      ' disable condition
      bDisabled = func.Disabled(d)
      .Enabled = Not(bDisabled)
      ' show condition
      If (sName = "Init") Then
        .Value = -CInt(r.v(sIndex & "_USE_" & sName) = 1)
      Else
        If (func.FunctionSort(d) = 2) Then ' if ISR
          .Value = -CInt(func.Value(d))
        Else
          .Value = -CInt(r.v(sIndex & "_USE_" & sName) = 1 AND r.v(sIndex & "_USE_Init") = 1 AND func.Value(d))
        End If
      End If
    End With

    With e("chk_" & sName)
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = func.DisabledToolTip(d)
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txt_... (show)
    '-------------------------------------------------------------------------
    ' action on showing the control
    With c("txt_" & sName)
      ' disable condition
      If (func.FunctionSort(d) = 2) Then ' if ISR
          bDisabled = (r.v(sIndex & "_USE_" & sName) = 0 Or r.v(sIndex & "_USE_Init") = 0 Or Not(func.Value(d)) ) 
      Else
          bDisabled = (r.v(sIndex & "_USE_" & sName) = 0 Or r.v(sIndex & "_USE_Init") = 0) 
      End If
      .Enabled = Not(bDisabled)
      ' show condition
      .Text = FormatTextOutput(r.s(d), "S")
    End With   

    With e("txt_" & sName)
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
      Else
        ' tooltip if control is enabled 
        .EnabledTooltipText = FormatFunctionToolTip(r, func, d)
      End If
    End With

  Next l


  '-------------------------------------------------------------------------
  ' control: lbl_CFile (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("lbl_CFile")
    ' disable condition
    bDisabled = (r.v(sIndex & "_USE_Init") = 0) 
    .Enabled = Not(bDisabled)
  End With

  With e("lbl_CFile")
    If (bDisabled) Then
      ' tooltip if control is disabled 
      .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
    Else
      ' tooltip if control is enabled 
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txt_CFile (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("txt_CFile")
    ' disable condition
    bDisabled = (r.v(sIndex & "_USE_Init") = 0) 
    .Enabled = Not(bDisabled)
    ' show condition
    .Text = FormatTextOutput(r.v(sIndex & "_CFile"), "S")
  End With

  With e("txt_CFile")
    If (bDisabled) Then
      ' tooltip if control is disabled 
      .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
    Else
      ' tooltip if control is enabled 
    End If
  End With

  ShowFunction = True
  Exit Function

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


'*****************************************************************************
'Description:
'        This function makes all update activities for the page Parameters. 
'-----------------------------------------------------------------------------
'Parameters:
'        sIndex          module name (prefix of the parameters)
'        ps              reference to the Peripherals object
'        para            reference to the ParameterClass object
'        Controlname     control name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function UpdateParameter(sIndex As String, ps As Peripherals, para As ParameterClass, Controlname As String, v() As Variant) As Boolean
  On Error Goto UpdateParameterError
  UpdateParameter = False

  Dim r As ProjectData
  Dim sName As String
  Dim d As String
  Dim l As Long

  Set r = ps.ProjectData

  ' for each parameter in this ParameterClass object
  For l = 1 To para.ParameterCount
    ' get the parameter name which was insert in 'Include.inc' with 'AddParameter()'
    d = para.ParameterName(l)
    ' get only the third part of the parameter name (e.g "T2")
    sName = Right(d, Len(d) - Instr(d, "PARA") - Len("PARA"))

    '---------------------------------------------------------------------
    ' control: txt_.. (action)
    '---------------------------------------------------------------------
    If (Controlname = "txt_" & sName) Then
      ' action on clicking the selected control
      If (IsInputFormatOK(v(1), FORMAT_PARAMETERS, , , )) Then
        r.s(d) = v(1)
      Else
        Exit Function
      End If
      Exit For
    End If
  Next l

  '---------------------------------------------------------------------
  ' control: txt_HFile (action)
  '---------------------------------------------------------------------
  If (Controlname = "txt_HFile") Then
    ' action on clicking the selected control
    If (IsInputFormatOK(v(1), FORMAT_PARAMETERS, , , )) Then
      r.v(sIndex & "_HFile") = v(1)
    Else
      Exit Function
    End If
  End If

  UpdateParameter = True
  Exit Function

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


'*****************************************************************************
'Description:
'        This parameter makes all show activities for the page Parameters 
'-----------------------------------------------------------------------------
'Parameters:
'        sIndex          module name (prefix of the parameters)
'        ps              reference to the Peripherals object
'        para            reference to the ParameterClass object
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function ShowParameter(sIndex As String, ps As Peripherals, para As ParameterClass, v() As Variant) As Boolean
  On Error Goto ShowParameterError
  ShowParameter = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim sName As String
  Dim d As String
  Dim l As Long

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

  ' for each parameter in this 'para' object
  For l = 1 To para.ParameterCount
    ' get the parameter name which was insert in 'Include.inc' with 'AddParameter()'
    d = para.ParameterName(l)

    ' get only the third part of the parameter name (e.g "T2")
    sName = Right(d, Len(d) - Instr(d, "PARA") - Len("PARA"))

    '-------------------------------------------------------------------------
    ' control: txt_... (show)
    '-------------------------------------------------------------------------
    ' action on showing the control
    With c("txt_" & sName)
      ' disable condition
      bDisabled = (r.v(sIndex & "_USE_Init") = 0 Or para.Disabled(d)) 
      .Enabled = Not(bDisabled)
      ' show condition
      .Text = FormatTextOutput(r.s(d), "S")
    End With   

    With e("txt_" & sName)
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = TOOLTIP_DISABLED_PARAMETER
        If (para.Disabled(d) = True) Then 
          .DisabledTooltipText = .DisabledTooltipText & para.DisabledTooltip(d)  
        End If
        If (r.v(sIndex & "_USE_Init") = 0) Then
          .DisabledTooltipText =  .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
        End If
      Else
        ' tooltip if control is enabled 
        .EnabledTooltipText = FormatParameterToolTip(r, para, d)
      End If
    End With

  Next l

  '-------------------------------------------------------------------------
  ' control: lbl_HFile (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("lbl_HFile")
    ' disable condition
    bDisabled = (r.v(sIndex & "_USE_Init") = 0) 
    .Enabled = Not(bDisabled)
  End With

  With e("lbl_HFile")
    If (bDisabled) Then
      ' tooltip if control is disabled 
      .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
    Else
      ' tooltip if control is enabled 
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txt_HFile (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("txt_HFile")
    ' disable condition
    bDisabled = (r.v(sIndex & "_USE_Init") = 0) 
    .Enabled = Not(bDisabled)
    ' show condition
    .Text = FormatTextOutput(r.v(sIndex & "_HFile"), "S")
  End With

  With e("txt_HFile")
    If (bDisabled) Then
      ' tooltip if control is disabled 
      .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
    Else
      ' tooltip if control is enabled 
    End If
  End With


  ShowParameter = True
  Exit Function

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

'*****************************************************************************
'Description:
'        This function checks the paramter v if he is lower as the parameter
'        MinValue or greater as the parameter MaxValue. If so then a massage
'        box is opened.
'-----------------------------------------------------------------------------
'Parameters:
'        v               value which should be checked
'        MinValue        minimum value for the parameter v
'        MaxValue        maximum value for the parameter v
'-----------------------------------------------------------------------------
'Returns:
'        True            the value v is in range
'        False           else
'*****************************************************************************
Function IsInputValueOK(v As Variant, MinValue As Double, MaxValue As Double) As Boolean
  On Error Resume Next

  IsInputValueOK = False

  If (v < MinValue) Then  ' if the value is to low
    msgbox ("The input value must be greater.", vbCritical ,"DAvE")
    Exit Function
  Else
    If (v > MaxValue) Then   ' if the value is to high
      msgbox ("The input value must be lower.", vbCritical ,"DAvE")
      Exit Function
    Else
      IsInputValueOK = True  ' the value is OK
    End If
  End If

End Function


Function SetDefaultPropertiesForAllControlsOnPage(szPagename As String, c As Object, e As Object, bDisabled As Boolean, szDisabledTooltip As String, szEnabledTooltip As String)
  On Error Resume Next

  Dim o As Object
  Dim s As String

  ' for each control
  For Each o In c
    ' on this page
    s = ""
    s = o.Container.Container.Tag
    If (s = szPagename) Then
      o.Enabled = Not bDisabled
      ' determine tooltip
      If (bDisabled) Then
        ' tooltip if control is disabled 
        e(o.Tag).DisabledTooltipText = szDisabledTooltip
      Else
        ' tooltip if control is enabled 
        e(o.Tag).EnabledTooltipText = szEnabledTooltip
      End If
    End If
  Next
End Function

Function SetDefaultPropertiesForAllControlsOnFrame(szFramename As String, c As Object, e As Object, bDisabled As Boolean, szDisabledTooltip As String, szEnabledTooltip As String)
  On Error Resume Next

  Dim o As Object
  Dim s As String

  ' for each control
  For Each o In c
    ' on this frame
    s = ""
    s = o.Container.Caption
    If (s = szFramename) Then
      o.Enabled = Not bDisabled
      ' determine tooltip
      If (bDisabled) Then
        ' tooltip if control is disabled 
        e(o.Tag).DisabledTooltipText = szDisabledTooltip
      Else
        ' tooltip if control is enabled 
        e(o.Tag).EnabledTooltipText = szEnabledTooltip
      End If
    End If
  Next
End Function


'*****************************************************************************
'Description:
'         This function sets the PEC channel in to the default.
'         If the channel is linked to or from the other channel and 
'         the channel has no interrupt, then the pair channel is set to
'         the default too.
'-----------------------------------------------------------------------------
'Parameters:
'        r               ProjectData
'        iChannel        PEC channel
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub SetPECChannelToDefault(r As ProjectData, iChannel As Integer)
  On Error Resume Next

  r.sfr("PECC" & iChannel) = 0
  r.v("SRCP" & iChannel & "_SRCP" & iChannel) = 0
  r.v("DSTP" & iChannel & "_DSTP" & iChannel) = 0

End Sub
