Attribute VB_Name = "Module1"
'#Uses "include.inc"
'#Uses "..\include\Global.inc"
Option Explicit
'*****************************************************************************
' Module:
'        CC6
'-----------------------------------------------------------------------------
' Description:
'        This file contains the 'Update' functions for the module.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1   als          20.11.04     initial version for XC866
'
'*****************************************************************************

'*****************************************************************************
'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
'            r.sfr(sVarPre & "_PISEL0H") = &H3F

'
            ' init function, parameters and file names
            r.v(sVarPre & "_CFile") = "CC6.C"
            r.v(sVarPre & "_HFile") = "CC6.H"
            r.v(sVarPre & "_Notes") = ""
            r.v(sVarPre & "_NAME_Init") = "CC6_vInit"

'            r.v(sVarPre & "_NAME_NodeI0") = "CC6_viNodeI0"
'            r.v(sVarPre & "_NAME_NodeI1") = "CC6_viNodeI1"
'            r.v(sVarPre & "_NAME_NodeI2") = "CC6_viNodeI2"
'            r.v(sVarPre & "_NAME_NodeI3") = "CC6_viNodeI3"
            If (IsCpuTypeOK(r)) Then
                r.v(sVarPre & "_NAME_NodeI0") = "SHINT_viXINTR10Isr"
                r.v(sVarPre & "_NAME_NodeI1") = "SHINT_viXINTR11Isr"
                r.v(sVarPre & "_NAME_NodeI2") = "SHINT_viXINTR12Isr"
                r.v(sVarPre & "_NAME_NodeI3") = "SHINT_viXINTR13Isr"
            Else
                r.v(sVarPre & "_NAME_NodeI0") = "CC6_viNodeI0"
                r.v(sVarPre & "_NAME_NodeI1") = "CC6_viNodeI1"
                r.v(sVarPre & "_NAME_NodeI2") = "CC6_viNodeI2"
                r.v(sVarPre & "_NAME_NodeI3") = "CC6_viNodeI3"
            End If

            r.v(sVarPre & "_NAME_StartTmr") = "CC6_vStartTmr"
            r.v(sVarPre & "_NAME_StopTmr") = "CC6_vStopTmr"
            r.v(sVarPre & "_NAME_ResetTmr") = "CC6_vResetTmr"
            r.v(sVarPre & "_NAME_SetTmrPeriod") = "CC6_vSetTmrPeriod"
            r.v(sVarPre & "_NAME_SetDeadTimePeriod") = "CC6_vSetDeadTimePeriod"
            r.v(sVarPre & "_NAME_EnableShadowTransfer") = "CC6_vEnableShadowTransfer"
            r.v(sVarPre & "_NAME_LoadChannelShadowRegister") = "CC6_vLoadChannelShadowRegister"
            r.v(sVarPre & "_NAME_GetChannelShadowRegister") = "CC6_uwGetChannelShadowRegister"
            r.v(sVarPre & "_NAME_GetChannelRegister") = "CC6_uwGetChannelRegister"
            r.v(sVarPre & "_NAME_GetTmrCounter") = "CC6_uwGetTmrCounter"
            r.v(sVarPre & "_NAME_SetTmrCounter") = "CC6_uwSetTmrCounter"
            r.v(sVarPre & "_NAME_SetStatusBit") = "CC6_vSetStatusBit"
            r.v(sVarPre & "_NAME_ResetStatusBit") = "CC6_vResetStatusBit"
            
            r.v("CAN_USE_WriteCANAddress_I") = 0
            r.v("CAN_NAME_WriteCANAddress_I") = "CC6_uwGetTmrPeriod"
            
            r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) = "CC6_TIMER_" & iTmr_12
            r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) = "CC6_TIMER_" & iTmr_13

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

            Call SetCC6Register_L_and_H(r, "T12PR", 1)
            Call SetCC6Register_L_and_H(r, "T13PR", 1)

            r.v("CCU6_T12DTCL_DTM") = 1
            r.v("CCU6_TCTR2L_T13TED") = 0

            '...

        Case 1

            '...
       'Case...
    End Select

    UpdateProjectData = True
    Exit Function

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

