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("UART1_Baudrate") = GetUartMaxBaudrate(r)
        Call UpdateUartBaudrate(r)
        
        r.v("GEN_UserDef2") = 1
        r.v("UART1_CFile") = "UART1.C"
        r.v("UART1_HFile") = "UART1.H"
        r.v("UART1_NAME_GetData8") = "UART1_ubGetData8"
        r.v("UART1_NAME_GetData9") = "UART1_uwGetData9"
        r.v("UART1_NAME_GotoSleep") = "UART1_vGotoSleep"
        r.v("UART1_NAME_Init") = "UART1_vInit"
        'r.v("UART1_NAME_Isr") = "UART1_viIsr"
        r.v("UART1_NAME_Isr") = "SHINT_viXINTR8Isr"
        'r.v("BRG_NAME_Isr") = "BRG_viIsr"
        r.v("BRG1_NAME_Isr") = "SHINT_viXINTR8Isr"
        r.v("UART1_NAME_OwnAddress") = "UART1_bOwnAddress"
        r.v("UART1_NAME_RxEnable") = "UART1_vRxEnable"
        r.v("UART1_NAME_RxDisable") = "UART1_vRxDisable"
        r.v("UART1_NAME_RxReady") = "UART1_bRxReady"
        r.v("UART1_NAME_SendAddr") = "UART1_vSendAddr"
        r.v("UART1_NAME_SendData8") = "UART1_vSendData8"
        r.v("UART1_NAME_SendData9") = "UART1_vSendData9"
        r.v("UART1_NAME_TxReady") = "UART1_bTxReady"
        r.v("UART1_NAME_WakeUp") = "UART1_vWakeUp"
        r.v("UART1_Notes") = ""
        r.v("UART1_USE_GetData8") = 0
        r.v("UART1_USE_GetData9") = 0
        r.v("UART1_USE_GotoSleep") = 0
        r.v("UART1_USE_Init") = 0
        r.v("UART1_USE_Isr") = 0
        r.v("UART1_USE_OwnAddress") = 0
        r.v("UART1_USE_RxEnable") = 0
        r.v("UART1_USE_RxDisable") = 0
        r.v("UART1_USE_RxReady") = 0
        r.v("UART1_USE_SendAddr") = 0
        r.v("UART1_USE_SendData8") = 0
        r.v("UART1_USE_SendData9") = 0
        r.v("UART1_USE_SetBaudrate") = 0
        r.v("UART1_USE_TxReady") = 0
        r.v("UART1_USE_WakeUp") = 0
        r.v("UART1_TxPin_P0.4_Used") = 0
        r.v("UART1_TxPin_P3.1_Used") = 0
        r.v("UART1_RxPin_P3.2_Used") = 0
        r.v("UART1_RxPin_P0.5_Used") = 0
        r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
        r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
        r.v("BRG1_Interrupt_Select") = 0
        r.v("UART1_Interrupt_Select") = 0
        Call SetUartMode(r, DEFAULT_UART1_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

