Attribute VB_Name = "Module1"

Option Explicit
'*****************************************************************************
' Module:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains the 'Update' functions for the module.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         18.05.01     final version for XC164CS
'
'        1.1   ahe         05.06.02     no changes
'        1.2   ste         18.12.02     final version for XC167CI

'        ---------------------------------------------------------------------
'        2.0               26.08.04    final version for XC164CM Pegasus light
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        This function is called by the main module in order to reset or update
'        the project variables and register contents of this peripheral
'-----------------------------------------------------------------------------
'Parameters:
'        r                      reference to the project data variables
'        vIndex                 a parameter
'        lngUpdateDescriptor    identification of the update context
'                  0          = initialization for a new project
'                  1, 2, 3... = value that identifies which project settings have
'                               been changed (e.g. CPU-Type, CPU-Clock etc.)
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function UpdateProjectData(r As ProjectData, vIndex As Variant, lngUpdateDescriptor As Long) As Boolean
    On Error GoTo UpdateProjectDataError

    Dim sVarPre As String
    Dim sRegPre As String
    Dim i As Integer
    Dim iTmr_12 As Integer
    Dim iTmr_13 As Integer
    Dim iCh_low As Integer
    Dim iCh_high As Integer

    UpdateProjectData = False
    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
    
    iCh_low = 0
    iCh_high = 3
    iTmr_12 = 12
    iTmr_13 = 13

    Select Case lngUpdateDescriptor
        Case 0
            ' init reset values for registers
'
            ' init function, parameters and file names
            r.v(sVarPre & "_CFile") = sVarPre & ".C"
            r.v(sVarPre & "_HFile") = sVarPre & ".H"
            r.v(sVarPre & "_Notes") = ""
            r.v(sVarPre & "_NAME_Init") = sVarPre & "_vInit"

            r.v(sVarPre & "_NAME_NodeI0") = sVarPre & "_viNodeI0"
            r.v(sVarPre & "_NAME_NodeI1") = sVarPre & "_viNodeI1"
            r.v(sVarPre & "_NAME_NodeI2") = sVarPre & "_viNodeI2"
            r.v(sVarPre & "_NAME_NodeI3") = sVarPre & "_viNodeI3"

            r.v(sVarPre & "_NAME_StartTmr") = sVarPre & "_vStartTmr"
            r.v(sVarPre & "_NAME_StopTmr") = sVarPre & "_vStopTmr"
            r.v(sVarPre & "_NAME_ResetTmr") = sVarPre & "_vResetTmr"
            r.v(sVarPre & "_NAME_SetTmrPeriod") = sVarPre & "_vSetTmrPeriod"
            r.v(sVarPre & "_NAME_SetDeadTimePeriod") = sVarPre & "_vSetDeadTimePeriod"
            r.v(sVarPre & "_NAME_EnableShadowTransfer") = sVarPre & "_vEnableShadowTransfer"
            r.v(sVarPre & "_NAME_LoadChannelShadowRegister") = sVarPre & "_vLoadChannelShadowRegister"
            r.v(sVarPre & "_NAME_GetChannelShadowRegister") = sVarPre & "_uwGetChannelShadowRegister"
            r.v(sVarPre & "_NAME_GetChannelRegister") = sVarPre & "_uwGetChannelRegister"
            r.v(sVarPre & "_NAME_GetTmrCounter") = sVarPre & "_uwGetTmrCounter"
            r.v(sVarPre & "_NAME_SetTmrCounter") = sVarPre & "_uwSetTmrCounter"
            r.v(sVarPre & "_NAME_SetStatusBit") = sVarPre & "_vSetStatusBit"
            r.v(sVarPre & "_NAME_ResetStatusBit") = sVarPre & "_vResetStatusBit"
            
            r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) = sVarPre & "_TIMER_" & iTmr_12
            r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) = sVarPre & "_TIMER_" & iTmr_13

            For i = iCh_low To iCh_high
                r.v(sVarPre & "_PARA_CHANNEL_" & i) = sVarPre & "_CHANNEL_" & i
                r.v(sVarPre & "_REQ_DUTY_CYCLE_" & i) = 100
            Next i

            r.sfr(sRegPre & "T" & iTmr_12 & "PR") = 1
            r.sfr(sRegPre & "T" & iTmr_13 & "PR") = 1
            r.l(sRegPre & "T12DTC_DTM") = 1
            r.v(sRegPre & "TCTR2_T13TED") = 1
            '...

        Case 1

            '...
       'Case...
    End Select

    UpdateProjectData = True
    Exit Function

UpdateProjectDataError:
    ErrorBox "Error in function UpdateProjectData", Err.Description
    Exit Function
End Function

