Attribute VB_Name = "Module1"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\classes\FunctionClass.cls
Option Explicit
'*****************************************************************************
' Module:
'        UART
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the
'        UART dialog script and in the UART codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        0.1  Sunil          25-10-04    initial version
'        0.2  Sunil          29-12-04    module prefix added.
'        0.3  Jagadeesha     23-11-06    added function FDV_Calculation() to
'                                        calculate baudrate , STEP, BG value when
'                                        fractional divider is enabled.
'
'*****************************************************************************

'*****************************************************************************
' Constants
'*****************************************************************************

'Global Const DEFAULT_UART_BAUD_RATE = 9600
Global Const DEFAULT_UART_MODE = 0

' Baudrate Generator factor
Global Const BRG_FACTOR = 16
Global Const BR_FACTOR_MODE_2 = 64
Global Const BR_FACTOR_MODE_0 = 2


'*****************************************************************************
'Description:
'        This function returns if multiprocessor communication mode is selected
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True = Multi. Com. Mode is selected
'*****************************************************************************
Public Function IsMultiComMode(r As ProjectData) As Boolean
    On Error Resume Next
    IsMultiComMode = (GetUartMode(r) > 1) And (r.v(UART_PREFIX & "SCON_SM2") = 1)
End Function

'*****************************************************************************
'Description:
'        This function returns if the function library uses data parameters
'        of 9 bit size instead of 8 bit
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True = data size is 9 bit
'*****************************************************************************
Public Function DataSize9Bit(r As ProjectData) As Boolean
    On Error Resume Next
    DataSize9Bit = (GetUartMode(r) > 1) And (r.v(UART_PREFIX & "SCON_SM2") = 0)
End Function

'*****************************************************************************
'Description:
'        This function returns the current UART mode (bits SM0, SM1)
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        mode 0..3
'*****************************************************************************
Public Function GetUartMode(r As ProjectData) As Integer
    On Error Resume Next
    GetUartMode = r.l(UART_PREFIX & "SCON_SM0") * 2 + r.l(UART_PREFIX & "SCON_SM1")
End Function

'*****************************************************************************
'Description:
'        This subroutine sets the UART mode (bits SM0, SM1)
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        mode             UART mode 0..3
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetUartMode(r As ProjectData, iMode As Integer)
    On Error Resume Next
    r.l(UART_PREFIX & "SCON_SM0") = iMode \ 2
    r.l(UART_PREFIX & "SCON_SM1") = iMode Mod 2
    
End Sub

'*****************************************************************************
'Description:
'        This function returns the minimum UART baudrate.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        Minimum baudrate
'*****************************************************************************
Function GetUartMinBaudrate(r As ProjectData) As Double
    On Error Resume Next
    
    GetUartMinBaudrate = GetCoreClock(r) * 1000000 / (BRG_FACTOR * (2 ^ r.l(BRG_PREFIX & "BCON_BRPRE")) * (255 + 1))
    
    If r.v(BRG_PREFIX & "FDCON_FDEN") = 1 Then
        GetUartMinBaudrate = GetUartMinBaudrate * 1 / 256    'Changed by jag on 24/11/2006 because minimum baudrate should not be 0
                                                             ' This is done according to 16 bit and 32 bit microcontrollers.
    End If
    
End Function

'*****************************************************************************
'Description:
'        This function returns the maximum UART baudrate.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        Maximum baudrate
'*****************************************************************************
Function GetUartMaxBaudrate(r As ProjectData) As Double
    On Error Resume Next
    
    GetUartMaxBaudrate = GetCoreClock(r) * 1000000 / (BRG_FACTOR * (2 ^ r.l(BRG_PREFIX & "BCON_BRPRE")) * (0 + 1))
    
    If r.v(BRG_PREFIX & "FDCON_FDEN") = 1 Then
        GetUartMaxBaudrate = (GetUartMaxBaudrate * 255) / 256
    End If
    
End Function

'*****************************************************************************
'Description:
'        This function returns the actual UART baudrate.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        actual baudrate
'*****************************************************************************
Function GetActualUartBaudrate(r As ProjectData) As Double
    On Error Resume Next
    
    GetActualUartBaudrate = GetCoreClock(r) * 1000000 / (BRG_FACTOR * (2 ^ r.l(BRG_PREFIX & "BCON_BRPRE")) * (r.l(BRG_PREFIX & "BG_BR_VALUE") + 1))
    
    If r.v(BRG_PREFIX & "FDCON_FDEN") = 1 Then
       'GetActualUartBaudrate = GetActualUartBaudrate * r.v(BRG_PREFIX & "FDSTEP_STEP") / 256
        If (r.v(BRG_PREFIX & "FDSTEP_STEP") <> 0) Then
           GetActualUartBaudrate = GetActualUartBaudrate * r.v(BRG_PREFIX & "FDSTEP_STEP") / 256
        End If
    End If
    
End Function

'*****************************************************************************
'Description:
'         This function updates the Uart baudrate.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'
'*****************************************************************************
Sub UpdateUartBaudrate(r As ProjectData)
    On Error Resume Next
    
    Dim vBaudrate As Variant

    vBaudrate = r.d("Uart_Baudrate")
    
      If (vBaudrate < GetUartMinBaudrate(r)) Then
        vBaudrate = GetUartMinBaudrate(r)
      End If
      
      If (vBaudrate > GetUartMaxBaudrate(r)) Then
        vBaudrate = GetUartMaxBaudrate(r)
      End If

    r.d("Uart_Baudrate") = Format(vBaudrate, "0.0000")
    
    If r.v(BRG_PREFIX & "FDCON_FDEN") = 1 Then
         Call FDV_Calculation(r)
    Else
        r.sfr(BRG_PREFIX & "BG") = Round((GetCoreClock(r) * 1000000 / (BRG_FACTOR * r.d("Uart_Baudrate") * (2 ^ r.l(BRG_PREFIX & "BCON_BRPRE"))))) - 1
    End If
    

End Sub
'*****************************************************************************
'Description:
'        This function calculate the optimum for baud rate if FDV is use.
'-----------------------------------------------------------------------------
'Parameters:
'        r        As ProjectData
'        vIndex   module identifier
'*****************************************************************************
Sub FDV_Calculation(r As ProjectData)
  On Error GoTo SubError

    Dim lBG_low As Long
    Dim lBG_high As Long
    Dim lMin_FDV As Long
    Dim lFDV_Counter As Long
    Dim lFDV As Long
    Dim lBG As Long
    Dim vADB_BG_l As Variant
    Dim vADB_BG_h As Variant
    Dim vADB_BG As Variant
    Dim iFDV_Start As Integer
    Dim dClock As Double

    Dim sUART_Req_Baudrate_Reg As String
    Dim sUART_BG_Reg As String
    Dim sUART_FDV_Reg As String
    Dim sUART_Pre_Reg As String
    Dim sVarPre As String
    Dim sRegPre As String

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '!!! BEI 16-BIT und 32-BIT UNTERSCHIEDLICH !!!
    '!!! BITTE ANPASSEN !!!
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    sVarPre = "UART"
    sRegPre = "UART" & "_"

    sUART_Req_Baudrate_Reg = sVarPre & "_Baudrate"   'rquired bazd rate
    sUART_BG_Reg = BRG_PREFIX & "BG_BR_VALUE"           'baud rate Register
    sUART_FDV_Reg = BRG_PREFIX & "FDSTEP_STEP"          'FDV Register
    sUART_Pre_Reg = BRG_PREFIX & "BCON_BRPRE"
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    dClock = GetCoreClock(r) * 1000000
    
    lMin_FDV = Fix((r.v(sUART_Req_Baudrate_Reg) * (2 ^ r.v(sUART_Pre_Reg)) * 16 * 256) / dClock)    'Ermittlung von FDV_min und Abschneiden der Nachkomastellen

    If (lMin_FDV = 0) Then            'wenn FDV = 0 dann lMin_FDV = 1
        lMin_FDV = 1
    End If

    lBG_low = Fix(lMin_FDV * dClock / (r.v(sUART_Req_Baudrate_Reg) * (2 ^ r.v(sUART_Pre_Reg)) * 256 * 16) - 1)
    lBG_high = lBG_low + 1

    If (Abs(lMin_FDV / 256 * dClock / (16 * (lBG_low + 1) * (2 ^ r.v(sUART_Pre_Reg))) - r.v(sUART_Req_Baudrate_Reg)) < Abs(lMin_FDV / 256 * dClock / (16 * (lBG_high + 1) * (2 ^ r.v(sUART_Pre_Reg))) - r.v(sUART_Req_Baudrate_Reg))) Then
        lBG = lBG_low
    Else
        lBG = lBG_high
    End If
    
    If (lBG > 255) Then    '8191 ist der max-Wert fr das baut rate - Register
        lBG = 0             'lBG = 0 ist wilkrlich gewhlt
        lFDV = 256          'lFDV = 512 ist wilkrlich gewhlt
    Else
        lFDV = lMin_FDV     'lFDV gehrt mit oben berechneten lBG zu einem Rechenpaar
    End If

    iFDV_Start = lMin_FDV + 1     'starten der For-Next-Schleife von FDV_Min + 1

    For lFDV_Counter = iFDV_Start To 256
        lBG_low = Fix(lFDV_Counter * dClock / (r.v(sUART_Req_Baudrate_Reg) * (2 ^ r.v(sUART_Pre_Reg)) * 256 * 16) - 1)   'Berechnung von lBG oberhalb und unterhalb der 0-Achse
        lBG_high = lBG_low + 1

        If (lBG_low < 256 Or lBG_high < 256) Then   ' nur wenn 1 Wert kleiner als max-Wert fr das baud rate - Register

            vADB_BG_l = (Abs(lFDV_Counter / 256 * dClock / (16 * (lBG_low + 1) * (2 ^ r.v(sUART_Pre_Reg))) - r.v(sUART_Req_Baudrate_Reg)))
            vADB_BG_h = (Abs(lFDV_Counter / 256 * dClock / (16 * (lBG_high + 1) * (2 ^ r.v(sUART_Pre_Reg))) - r.v(sUART_Req_Baudrate_Reg)))
            vADB_BG = (Abs(lFDV / 256 * dClock / (16 * (lBG + 1) * (2 ^ r.v(sUART_Pre_Reg))) - r.v(sUART_Req_Baudrate_Reg)))

            If (vADB_BG_l < vADB_BG And lBG_low < 256) Then   ' nur wenn kleiner als max-Wert fr das baud rate - Register
                lBG = lBG_low
                lFDV = lFDV_Counter
            End If

            If (vADB_BG_h < vADB_BG And lBG_high < 256) Then  ' nur wenn kleiner als max-Wert fr das baud rate - Register
                lBG = lBG_high
                lFDV = lFDV_Counter
            End If

        End If

    Next lFDV_Counter

    
    r.l(sUART_BG_Reg) = lBG
    r.v(sUART_FDV_Reg) = lFDV
    
    If (r.v(sUART_FDV_Reg) = 256) Then    'weil max-Wert 511, wenn jedoch 512 dann FDV = 0
        r.v(sUART_FDV_Reg) = 0
    End If
    
    
    Exit Sub

SubError:

    r.l(sUART_BG_Reg) = 0
    r.v(sUART_FDV_Reg) = 0

End Sub

'*****************************************************************************
'Description:
'        This function returns the effective baud rate for mode 2
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        baudrate, unit = kbaud
'*****************************************************************************
Public Function UartBaudrateMode2(r As ProjectData) As Double
    On Error Resume Next
    UartBaudrateMode2 = GetCoreClock(r) * 1000 * (1 + r.l(UART_PREFIX & "PCON_SMOD")) / BR_FACTOR_MODE_2
End Function


'*****************************************************************************
'Description:
'        This function returns the effective baud rate for mode 0
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        baudrate, unit = kbaud
'*****************************************************************************
Public Function UartBaudrateMode0(r As ProjectData) As Double
    On Error Resume Next
    UartBaudrateMode0 = GetCoreClock(r) * 1000 / BR_FACTOR_MODE_0
End Function

'*****************************************************************************
'Description:
'       If UART baudrate derived from the timer 1 overflow can be determined,
'       the baudrate will be returned as a string, otherwise an empty string
'       will be returned.
'-----------------------------------------------------------------------------
'Parameters:
'-----------------------------------------------------------------------------
'Returns:
'       baudrate        e.g. "9600"
'*****************************************************************************
Function GetTimer1Baudrate(r As ProjectData) As String
    On Error Resume Next

'counter pin not available    If ( ((r.l("TMOD_M1_1") * 2 + r.l("TMOD_M0_1")) = 2) And (r.l("TMOD_C/T_1") = 0) ) Then
    If r.l(T01_PREFIX & "TMOD_T1M") = 2 And r.v(BRG_PREFIX & "FDCON_BGS") = 1 Then
        ' typical configuration for baudrate generation: 8-bit auto-reload mode in timer operation
        GetTimer1Baudrate = FormatTextOutput(Format$(((2 ^ r.d(UART_PREFIX & "PCON_SMOD")) * (GetCoreClock(r) * 1000000)) / (32 * RATIO_FSYS_T01 * (256 - r.d(T01_PREFIX & "TH1_VAL"))), "0"), "F")
    Else
        ' baudrate calculation with other timer modes is not supported...
        ' ...because the runtime of the user's ISR which has to reload the timer is unknown
        GetTimer1Baudrate = ""
    End If
End Function
'*****************************************************************************
'Description:
'        This function returns the overflow rate of BRG Timer when it is in Normal Divider Mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        Overflow value as a string
'*****************************************************************************
Public Function GetBRGTmrOverflow(r As ProjectData) As String
    On Error Resume Next
    
    GetBRGTmrOverflow = FormatTextOutput(Format$((2 ^ r.l(BRG_PREFIX & "BCON_BRPRE") * (256 - r.l(BRG_PREFIX & "FDSTEP_STEP"))) / GetCoreClock(r), "0.000"), "F")
End Function

'*****************************************************************************
'Description:
'        For each function which should be used for this module a line
'        "If (Not func.AddFunction .." must be insert in this function.
'        For each parameter that should be used for this function a
'        line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added function a project variable with the name
'        "UART_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions(func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  Dim sDescription As String
  Dim sReturnValue As String

  RefreshFunctionDescriptions = False

  ' for each function of this module the property AddFunction must be called
  '
  ' AddFunction(sFuncName As String, sFuncType As String, sFuncDescription As String,
  '             sReturnvalue As String, lSort As Long) As Boolean
  '
  ' sFuncName          | String | function name as key (use the name of the variable
  '                               for the function name e.g. SSC_NAME_Init)
  ' sFuncType          | String | type of the function
  ' sFuncDescription   | String | description of the function
  ' sReturnvalue       | String | description of the return value
  ' lSort              | Long   | ' sort of the function (0 => macro, 1 => function, 2 => ISR)

    ' for each parameter of a function the property AddParameter must be called
    '
    'AddParameter(sParName As String, sPar As String, sParType As String, sParDescription As String) As Boolean
    '
    ' sParName         | String | parameter name (key)
    ' sPar             | String | parameter name
    ' sParType         | String | type of the parameter
    ' sParDescription  | String | description of the parameter

  '************** Miscellaneous Functions

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription("UART") & vbCrLf & vbCrLf & _
                 "The following SFR fields will be initialized:" & vbCrLf & _
                 "- register SCON" & vbCrLf & _
                 "- bits SMOD and ES"
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_Isr
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the service routine for the UART interrupt. " & _
                "It is called after each transmission (flag TI set) or reception (flag RI set) of a data unit." & vbCrLf & _
                TOOLTIP_ISR_USERCODE
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_Isr", "void", sDescription, sReturnValue, 2)) Then Exit Function
    
  '------------------------------------------------------------------------------------------------
  ' Description for BRG_NAME_Isr
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the service routine for the BRG timer overflow interrupt. " & _
                "It is called after the BRG timer overflows and sets the NDOV bit." & vbCrLf & _
                TOOLTIP_ISR_USERCODE
  sReturnValue = "None"
  If (Not func.AddFunction("BRG_NAME_Isr", "void", sDescription, sReturnValue, 2)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_RxEnable
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro releases the receive function of the UART by setting bit REN."
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_RxEnable", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_RxDisable
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro disables the receive function of the UART by clearing bit REN." & vbCrLf & _
                 "Note: Any data that is currently being received is received " & _
                 "to completion, including the setting of interrupt flag RI."
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_RxDisable", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_RxReady
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro determines if a new data unit has been received by reading bit RI."
  sReturnValue = "1 if new data received, 0 if not"
  If (Not func.AddFunction("UART_NAME_RxReady", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_TxReady
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro determines if a data unit can be transmitted by reading bit TI. " & vbCrLf & _
                 "Note: TI will be initialized with '1' so that this macro is also usable " & _
                 "before any data has been transmitted."
  sReturnValue = "1 if data can be transmitted, 0 if not"
  If (Not func.AddFunction("UART_NAME_TxReady", "", sDescription, sReturnValue, 0)) Then Exit Function

  '************** 8-Bit Data Unit

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_GetData8
  '------------------------------------------------------------------------------------------------
  If (IsMultiComMode(r)) Then
    sDescription = "This function returns the last received 8-bit data unit. " & _
                   "Interrupt flag RI will be cleared." & vbCrLf & _
                   "Note: The 9th bit is not available for user data, " & _
                   "because it is used to distinguish between 'data' and 'address' bytes."
  Else
    sDescription = "This function returns the last received 8-bit data unit. " & _
                   "Interrupt flag RI will be cleared."
  End If
  sReturnValue = "received data unit"
  If (Not func.AddFunction("UART_NAME_GetData8", "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_SendData8
  '------------------------------------------------------------------------------------------------
  If (IsMultiComMode(r)) Then
    sDescription = "This function transmits an 8-bit data unit with the 9th bit set to '0'. " & _
                   "At first interrupt flag TI is cleared, then buffer SBUF is written." & vbCrLf & _
                   "Note: No receiver interrupt will occur with slaves having bit SM2 set to 1."
  Else
    sDescription = "This function transmits an 8-bit data unit. " & _
                   "At first interrupt flag TI is cleared, then buffer SBUF is written."
  End If
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_SendData8", "void", sDescription, sReturnValue, 1)) Then Exit Function

  sDescription = "data to be transmitted"
  If (Not func.AddParameter("UART_NAME_SendData8_Par1", "ubData", "ubyte", sDescription)) Then Exit Function

  '************** 9-Bit Data Units

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_GetData9
  '------------------------------------------------------------------------------------------------
  sDescription = "This function returns the last received 9-bit data unit. " & _
                 "Interrupt flag RI will be cleared."
  sReturnValue = "received data unit"
  If (Not func.AddFunction("UART_NAME_GetData9", "uword", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_SendData9
  '------------------------------------------------------------------------------------------------
  sDescription = "This function transmits an 9-bit data unit. " & _
                 "At first interrupt flag TI is cleared, then buffer SBUF is written."
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_SendData9", "void", sDescription, sReturnValue, 1)) Then Exit Function

  sDescription = "data to be transmitted"
  If (Not func.AddParameter("UART_NAME_SendData9_Par1", "uwData", "uword", sDescription)) Then Exit Function

  '************** Multiprocessor Communication

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_SendAddr
  '------------------------------------------------------------------------------------------------
  sDescription = "This function transmits an 8-bit address with the 9th bit set to '1'. " & _
                 "At first interrupt flag TI is cleared, then buffer SBUF is written." & vbCrLf & _
                 "Note: In contrast to function '" & r.v("UART_NAME_SendData8") & _
                 "' a receiver interrupt can occur with slaves having bit SM2 set to 1."
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_SendAddr", "void", sDescription, sReturnValue, 1)) Then Exit Function

  sDescription = "address to be transmitted"
  If (Not func.AddParameter("UART_NAME_SendAddr_Par1", "ubAddress", "ubyte", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_OwnAddress
  '------------------------------------------------------------------------------------------------
  sDescription = "This function compares the passed address value with the last received data byte. " & _
                 "Interrupt flag RI will be cleared." & vbCrLf & _
                 "Note: If the slave has been addressed, it must take care of receiving " & _
                 "the next data bytes. To achieve this, the function '" & _
                 r.v("UART_NAME_WakeUp") & "' must be called. After all data " & _
                 "bytes have been received from the master, the function '" & _
                 r.v("UART_NAME_GotoSleep") & "' has to be executed."
  sReturnValue = "1 if passed address matches received data, else 0"
  If (Not func.AddFunction("UART_NAME_OwnAddress", "bit", sDescription, sReturnValue, 1)) Then Exit Function

  sDescription = "address for comparison"
  If (Not func.AddParameter("UART_NAME_OwnAddress_Par1", "ubAddress", "ubyte", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_WakeUp
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro clears bit SM2. In turn data units with the 9th bit set to '0' " & _
                 "can be received by the slave, i.e. flag RI will be set for each received data unit."
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_WakeUp", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for UART_NAME_GotoSleep
  '------------------------------------------------------------------------------------------------
  sDescription = "This macro sets bit SM2. In turn data units with the 9th bit set to '0' " & _
                 "can not be received by the slave any longer, " & _
                 "i.e. flag RI will only be set if the 9th bit is '1'."
  sReturnValue = "None"
  If (Not func.AddFunction("UART_NAME_GotoSleep", "", sDescription, sReturnValue, 0)) Then Exit Function

  '------------------------------------------------------------------------------------------------
        If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
End Function



