'#Uses "include.inc"

Option Explicit
'*****************************************************************************
' Module:
'        ASC
'-----------------------------------------------------------------------------
' Description:
'        This file contains the 'Update' functions for the module.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0  rkt            10.12.99    initialize version
'        1.1  ste            04.02.00    final version
'        1.2  ste            09.03.00    IrDA mode deleted
'
'        1.3  ahe            08.10.00    final version
'                                        automatic calculation of FDV
'                                        - no changes
'        ---------------------------------------------------------------------
'        3.0  ste            25.01.01    final version for S-GOLDv1
'
'        ---------------------------------------------------------------------
'        4.0  ahe            14.02.01    final version for Pegasus
'
'        4.1  ahe            08.08.02     no changes
'
'*****************************************************************************


'*****************************************************************************
'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          = system clock was changed
'                  2          = a pin was deselected out of the PADx.dave script
'                  ..
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function UpdateProjectData(r As ProjectData, vIndex As Variant, lngUpdateDescriptor As Long) As Boolean
    On Error GoTo UpdateProjectDataError

    UpdateProjectData = False

    Dim sRegPre As String
    Dim sVarPre As String

    sVarPre = "ASC" & Format$(vIndex)
    sRegPre = "ASC" & Format$(vIndex) & "_"

    Select Case lngUpdateDescriptor
        Case 0 
            ' init reset values for registers

            r.v(sVarPre & "_NAME_Init")             = sVarPre & "_vInit"
            r.v(sVarPre & "_CFile")                 = sVarPre & ".C"
            r.v(sVarPre & "_HFile")                 = sVarPre & ".H"
            r.v(sVarPre & "_Notes")                 = "" 
            r.v(sVarPre & "_NAME_SendData")         = sVarPre & "_vSendData"
            r.v(sVarPre & "_NAME_GetData")          = sVarPre & "_uwGetData"
            r.v(sVarPre & "_NAME_Tx")               = sVarPre & "_viTx"
            r.v(sVarPre & "_NAME_Rx")               = sVarPre & "_viRx"
            r.v(sVarPre & "_NAME_Error")            = sVarPre & "_viError"
            
            If (r.Regs.SfrFind(sRegPre & "TBIC") = True) Then
                r.v(sVarPre & "_NAME_TxBuffer")         = sVarPre & "_viTxBuffer"
                r.v(sVarPre & "_NAME_TxBufFree")        = sVarPre & "_ubTxBufFree"
            End If

            r.v(sVarPre & "_NAME_RxDataReady")      = sVarPre & "_ubRxDataReady"
            r.v(sVarPre & "_NAME_ErrorCheck")       = sVarPre & "_ubErrorCheck"
            
            If (IsAutobaudAvailable(r, vIndex)) Then
                r.v(sVarPre & "_NAME_Autobaud")  = sVarPre & "_viAutobaud"
                r.v(sVarPre & "_NAME_GetAutobaudStatus") = sVarPre & "_uwGetAutobaudStatus"
            End If
            
            r.v(sVarPre & "_NAME_TxDataReady")      = sVarPre & "_ubTxDataReady"
            r.v(sVarPre & "_NAME_ReceiverOn")       = sVarPre & "_vReceiverOn"
            r.v(sVarPre & "_NAME_ReceiverOff")      = sVarPre & "_vReceiverOff"
            r.v(sVarPre & "_NAME_SendSlaveAdr")     = sVarPre & "_vSendSlaveAdr"
            r.v(sVarPre & "_NAME_OwnAddress")       = sVarPre & "_ubOwnAddress"
            r.v(sVarPre & "_NAME_WakeUp")           = sVarPre & "_vWakeUp"
            r.v(sVarPre & "_NAME_GotoSleep")        = sVarPre & "_vGotoSleep"
            r.v(sVarPre & "_NAME_SetBaudrate")      = sVarPre & "_vSetBaudrate"
            r.v(sVarPre & "_NAME_StopBaudGen")      = sVarPre & "_vStopBaudGen"
            r.v(sVarPre & "_NAME_StartBaudGen")     = sVarPre & "_vStartBaudGen"
            
            If (IsFIFOAvailable(r, vIndex)) Then
              r.v(sVarPre & "_NAME_FlushRxFIFO")           = sVarPre & "_vFlushRxFIFO"
              r.v(sVarPre & "_NAME_GetRxFIFOFillingLevel") = sVarPre & "_ubGetRxFIFOFillingLevel"
              r.v(sVarPre & "_NAME_FlushTxFIFO")           = sVarPre & "_vFlushTxFIFO"
              r.v(sVarPre & "_NAME_GetTxFIFOFillingLevel") = sVarPre & "_ubGetTxFIFOFillingLevel"
            End If

            If (IsAutobaudAvailable(r, vIndex)) Then
              r.v(sVarPre & "_PARA_AUTOBAUD_WAITING")         = sVarPre & "_AUTOBAUD_WAITING"
              r.v(sVarPre & "_PARA_FIRST_CHARACTER_SMALL")    = sVarPre & "_FIRST_CHARACTER_SMALL"
              r.v(sVarPre & "_PARA_FIRST_CHARACTER_CAPITAL")  = sVarPre & "_FIRST_CHARACTER_CAPITAL"
              r.v(sVarPre & "_PARA_SECOND_CHARACTER_SMALL")   = sVarPre & "_SECOND_CHARACTER_SMALL"
              r.v(sVarPre & "_PARA_SECOND_CHARACTER_CAPITAL") = sVarPre & "_SECOND_CHARACTER_CAPITAL"
            End If
                                                                
            If (IsFIFOAvailable(r, vIndex)) Then
              r.v(sRegPre & "RXFCON_RXFITL")        = 1
              r.v(sRegPre & "TXFCON_TXFITL")        = 1
            End If
            
            r.v(sRegPre & "CON_M")                  = 1
            r.v(sRegPre & "CON_R")                  = 1
            
            If (IsIrDAAvailable(r, vIndex)) Then
              r.v(sVarPre & "_IRDA_REQ")            = 0.1 
            End If
            
            r.v(sVarPre & "_Baudrate")              = 19200          
            Call UpdateASCxBaudrate(r, vIndex)
            Call UpdateIrDA(r, vIndex)

        Case 1
            If (IsAutobaudSelected(r, vIndex)) Then
              Call SetDefaultFDVForAutobaud(r, vIndex)
            Else
              Call UpdateASCxBaudrate(r, vIndex)
              Call UpdateIrDA(r, vIndex)
            End If

       'Case...
    End Select

    UpdateProjectData = True
    Exit Function

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

