Attribute VB_Name = "Module1"
'#Uses "Include.inc"
Option Explicit
'*****************************************************************************
' Module:
'        UART
'-----------------------------------------------------------------------------
' Description:
'        This file contains the 'Update' functions for the module.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        0.1  Sunil          25-10-04    initial version
'        0.2  Sunil          22-11-04    code added for lngUpdateDescriptor = 1
'                                        condition (i.e., when clock is changed).
'        0.3  Sunil          29-12-04    default baudrate is initialized to maximum value.
'                                        (default value of BG is 0x00)
'
'*****************************************************************************


'*****************************************************************************
'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 successful operation
'        False           else
'*****************************************************************************
Function UpdateProjectData(r As ProjectData, vIndex As Variant, lngUpdateDescriptor As Long) As Boolean
    On Error GoTo UpdateProjectDataError

    Dim rate As Double
    Dim min  As Double
    Dim max  As Double

    UpdateProjectData = False

    If (lngUpdateDescriptor = 0) Then
        r.d("UART_Baudrate") = GetUartMaxBaudrate(r)
        Call UpdateUartBaudrate(r)
        r.v("GEN_UserDef3") = 1
        r.v("UART_CFile") = "UART.C"
        r.v("UART_HFile") = "UART.H"
        r.v("UART_NAME_GetData8") = "UART_ubGetData8"
        r.v("UART_NAME_GetData9") = "UART_uwGetData9"
        r.v("UART_NAME_GotoSleep") = "UART_vGotoSleep"
        r.v("UART_NAME_Init") = "UART_vInit"
        r.v("UART_NAME_Isr") = "UART_viIsr"
        'r.v("BRG_NAME_Isr") = "BRG_viIsr"
        r.v("BRG_NAME_Isr") = "SHINT_viXINTR5Isr"
        r.v("UART_NAME_OwnAddress") = "UART_bOwnAddress"
        r.v("UART_NAME_RxEnable") = "UART_vRxEnable"
        r.v("UART_NAME_RxDisable") = "UART_vRxDisable"
        r.v("UART_NAME_RxReady") = "UART_bRxReady"
        r.v("UART_NAME_SendAddr") = "UART_vSendAddr"
        r.v("UART_NAME_SendData8") = "UART_vSendData8"
        r.v("UART_NAME_SendData9") = "UART_vSendData9"
        r.v("UART_NAME_TxReady") = "UART_bTxReady"
        r.v("UART_NAME_WakeUp") = "UART_vWakeUp"
        r.v("UART_Notes") = ""
        r.v("UART_USE_GetData8") = 0
        r.v("UART_USE_GetData9") = 0
        r.v("UART_USE_GotoSleep") = 0
        r.v("UART_USE_Init") = 0
        r.v("UART_USE_Isr") = 0
        r.v("UART_USE_OwnAddress") = 0
        r.v("UART_USE_RxEnable") = 0
        r.v("UART_USE_RxDisable") = 0
        r.v("UART_USE_RxReady") = 0
        r.v("UART_USE_SendAddr") = 0
        r.v("UART_USE_SendData8") = 0
        r.v("UART_USE_SendData9") = 0
        r.v("UART_USE_SetBaudrate") = 0
        r.v("UART_USE_TxReady") = 0
        r.v("UART_USE_WakeUp") = 0
        r.v("UART_TxPin_P0.2_Used") = 0
        r.v("UART_TxPin_P1.1_Used") = 0
        r.v("UART_RxPin_P0.1_Used") = 0
        r.v("UART_RxPin_P1.0_Used") = 0
        r.v("UART_RXDO_Pin_P0.0_Used") = 0
        r.v("UART_RXDO_Pin_P1.5_Used") = 0
        r.v("BRG_Interrupt_Select") = 0

        Call SetUartMode(r, DEFAULT_UART_MODE)
    Else
       ' r.d("UART_Baudrate") = GetUartMaxBaudrate(r)
        Call UpdateUartBaudrate(r)
    End If

    ' Some "project settings" may be changed independently from the settings
    ' of the peripheral modules. Therefore the UART module has to solve any
    ' possible conflicts with the project settings...
    

    UpdateProjectData = True
    Exit Function

UpdateProjectDataError:
    Exit Function
End Function

