Attribute VB_Name = "Module1"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Port.inc"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\ParameterClass.cls

Option Explicit

'*****************************************************************************
' Module:
'        CAN
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the
'        CAN dialog script and in the CAN codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        1.0  ste            05.05.00    final version for TC1775A
'        1.1  ste            20.07.00    function GetNodexClock added, because
'                                        the TC1775B has a new clock divider for
'                                        each node;
'                                        4 new functions added (...Error..)
'        1.2  ste            02.11.00    1 new function added (SetMSGVAL)
'
'        ----------------------------------------------------------------------
'        3.1  ahe            13.08.02     final version for TC1775B, TC1765
'                                         - changed function IsObjFIFOSlave()
'        ----------------------------------------------------------------------
'        4.0  ste            21.08.02     final version for TC1796
'        ----------------------------------------------------------------------
'             ste            01.08.03     version for TC1766
'                                         only 2 node available (new Const added)
'                                         only 64 message objects available (new Const added)
'                                         only 6 SRNs available (new Const added)
'             ste            28.08.03     function IsTTCANAvailable added
'                                         function DisableNodex changed (TTCAN
'                                         disable added)
'                                         4 node available (new Const added)
'                                         128 message objects available (new Const added)
'                                         16 SRNs available (new Const added)
'             ste            18.09.03     function ConfigureSchedulerEntries added
'        ----------------------------------------------------------------------
'             ste            14.11.03     - TC1766 and TC1796 merged
'                                         - CONST CAN_MAX_NODES,CAN_MAX_OBJECTS,
'                                           CAN_MAX_SRNS and CAN_MAX_SENTRIES replaced
'                                           with public functions
'        ----------------------------------------------------------------------
'        5.0  SankaraNarayana   02.05.07   Modifications changed for P11
'
'*****************************************************************************


'*****************************************************************************
' @Constants
'*****************************************************************************
' use this constant in the Format statement for all calculated outputs like
' baud rates or deviation
Global Const CAN_PRECISION = "0.000"
Global Const CAN_REQ_BAUDRATE = 100000
'********************************************************************************

'Public Function CAN_MAX_NODES() As Integer ' number of max. CAN nodes (0 to max - 1)
'Global Const CAN_MAX_NODES = 5  ' 0 - 1
'End Function

'Public Function CAN_MAX_OBJECTS() As Integer ' number of max. CAN objects (0 to max - 1)
'Global Const CAN_MAX_OBJECTS = 32   ' 0 - 31
'End Function

'Public Function CAN_MAX_SRNS() As Integer ' number of max. CAN service request nodes (0 to max - 1)
Global Const CAN_MAX_SRNS = 16       ' 0 - 7
'End Function

Public Function MSG_NODE_INIT_DIS(iNr As Integer) As String		'message for Node initialization disabled
    MSG_NODE_INIT_DIS = "All message objects which are connected to node " & iNr & " will be disabled . " & vbCrLf & _
                        "Do you really want to continue ?"
End Function

Public Function MSG_NODE_TXPIN_DIS(iNr As Integer) As String    ' message for LBM selected & TXPIN disabled
    MSG_NODE_TXPIN_DIS = "Node" & iNr & " TXPIN will be disabled . " & vbCrLf & _
                         "Do you really want to continue ?"
End Function

Public Function MSG_NODE_RXPIN_DIS(iNr As Integer) As String    ' message for LBM selected & RXPIN disabled
    MSG_NODE_RXPIN_DIS = "Node" & iNr & " RXPIN will be disabled . " & vbCrLf & _
                         "Do you really want to continue ?"
End Function

'added by Sankar for DAvE FULL
Public Function TXDPIN_DEF_MSG(iNr As Integer) As String 'default message for TXDPIN selection
    TXDPIN_DEF_MSG = "Pin TXDC" & iNr & " is not Used"
End Function

Public Function RXDPIN_DEF_MSG(iNr As Integer) As String 'default message for RXDPIN selection
    RXDPIN_DEF_MSG = "Pin RXDC" & iNr & " is not Used"
End Function


'*****************************************************************************
' @Function descriptions
'*****************************************************************************

'*****************************************************************************
'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
'        "CAN_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex           parameter of the module which was added with AddModule
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  RefreshFunctionDescriptions = False

  Dim sDescription As String
  Dim sReturnValue As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim sFctName As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"


  ' 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. CAN_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, 3 => Trap)


    ' 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

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription(sVarPre)
  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_GetMsgObj
  '------------------------------------------------------------------------------------------------
  sFctName = "GetMsgObj"
  sDescription = "This function fills the forwarded SW message object with the " & _
                 "content of the chosen HW message object." & vbCrLf & _
                 "" & vbCrLf & _
                 "For Receive Message object use function " & r.v(sVarPre & "_NAME_ReleaseObj") &", to " & _
                 "release the message object. " & vbCrLf & _
                 "" & vbCrLf & _
                 "The structure of the SW message object is defined in the " & vbCrLf & _
                 "header file " & r.v(sVarPre & "_HFILE") & " (see st" & sVarPre & "_SWObj)."



  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of the message object to be read (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    sDescription = "Pointer on a message object to be filled by this function"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "*pstObj", "st" & sVarPre & "_SWObj", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_RequestMsgObj
  '------------------------------------------------------------------------------------------------
  sFctName = "RequestMsgObj"
  sDescription = "If a TRANSMIT OBJECT is to be reconfigured it must first be " & _
                 "accessed. The access to the transmit object is exclusive. " & _
                 "This function checks whether the choosen message object is " & _
                 "still executing a transmit request, or if the object can " & _
                 "be accessed exclusively." & vbCrLf & _
                 "After the message object is reserved, it can be reconfigured " & _
                 "by using the function " & r.v(sVarPre & "_NAME_ConfigMsgObj") & " or " & _
                 r.v(sVarPre & "_NAME_LoadData") & "." & vbCrLf & _
                 "Both functions enable access to the object for the " & sVarPre & _
                 " controller. " & vbCrLf & _
                 "By calling the function " & r.v(sVarPre & "_NAME_Transmit") & " transfering of data " & _
                 "is started."

  sReturnValue = "0 message object is busy (a transfer is active), else 1"
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ObjNr", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_NewData
  '------------------------------------------------------------------------------------------------
  sFctName = "NewData"
  sDescription = "This function checks whether the selected RECEIVE OBJECT has " & _
                 "received a new message. If so the function returns the " & _
                 "value '1'."

  sReturnValue = "1 the message object has received a new message, else 0"
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ObjNr", "", sDescription)) Then Exit Function 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_Transmit
  '------------------------------------------------------------------------------------------------
  sFctName = "Transmit"
  sDescription = "This function triggers the " & sVarPre & " controller to send the " & _
                 "selected message." & vbCrLf & _
                 "If the selected message object is a TRANSMIT OBJECT then " & _
                 "this function triggers the sending of a data frame. " & _
                 "If however the selected message object is a RECEIVE OBJECT " & _
                 "this function triggers the sending of a remote frame."
        
  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_ConfigMsgObj
  '------------------------------------------------------------------------------------------------
  sFctName = "ConfigMsgObj"
  sDescription = "This function sets up the message objects. This includes " & _
                 "the 8 data bytes, the identifier (11- or 29-bit), the acceptance mask (11- or 29-bit), the data " & _
                 "number (0-8 bytes), the DIR-bit (transmit or receive object), the IDE-bit (standard or extended " & _
                 " identifier), the MIDE-bit (accepts reception of both frames or matching IDE-bit frame) and  the" & _
                 " frame counter value. " & vbCrLf & _
                 "The message is not sent; for this the function " & _
                 r.v(sVarPre & "_NAME_Transmit") & " must be called." & vbCrLf & _
                 "" & vbCrLf & _
                 "The structure of the SW message object is defined in the " & _
                 "header file " & r.v(sVarPre & "_HFILE") & " (see st" & sVarPre & "_SWObj)."
        
  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of the message object to be configured (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    sDescription = "Pointer on a message object"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "*pstObj", "st" & sVarPre & "_SWObj", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_LoadData
  '------------------------------------------------------------------------------------------------
  sFctName = "LoadData"
  sDescription = "If a hardware TRANSMIT OBJECT has to be loaded with data " & _
                 "but not with a new identifier, this function may be used " & _
                 "instead of the function " & r.v(sVarPre & "_NAME_ConfigMsgObj") & ". " & _
                 "The message object should be accessed by calling the function " & _
                 r.v(sVarPre & "_NAME_RequestMsgObj") & " before calling this function. This " & _
                 "prevents the " & sVarPre & " controller from working with invalid data."

  sReturnValue = "None"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of the message object to be configured (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    sDescription = "Pointer on a data buffer"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "*ubpubData", "ubyte", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_MsgLost
  '------------------------------------------------------------------------------------------------
  sFctName = "MsgLost"
  sDescription = "If a RECEIVE OBJECT receives new data before the old object " & _
                 "has been read, the old object is lost. The " & sVarPre & " controller " & _
                 "indicates this by setting the message lost bit (MSGLST). " & _
                 "This function returns the status of this bit. " & vbCrLf & _
                 "" & vbCrLf & _
                 "Note:" & vbCrLf & _
                 "This function resets the message lost bit (MSGLST)."
        
  sReturnValue = "1 the message object has lost a message, else 0"
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ObjNr", "", sDescription)) Then Exit Function 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_DelMsgObj
  '------------------------------------------------------------------------------------------------
  sFctName = "DelMsgObj"
  sDescription = "This function marks the selected message object as not valid. " & _
                 "This means that this object cannot be sent or receive data. " & _
                 "If the selected object is busy (meaning the object is " & _
                 "transmitting a message or has received a new message) this " & _
                 "function returns the value ""0"" and the object is not deleted."
        
  sReturnValue = "1 the message object was deleted, else 0"
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ObjNr", "", sDescription)) Then Exit Function
 
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_ReleaseObj
  '------------------------------------------------------------------------------------------------
  sFctName = "ReleaseObj"
  sDescription = "This function resets the NEWDAT flag of the selected RECEIVE " & _
                 "OBJECT, so that the " & sVarPre & " controller have access to it. " & _
                 "This function must be called if the function " & r.v(sVarPre & "_NAME_NewData") & _
                 " detects, that new data are present in the message object and " & _
                 "the actual data have been read by calling the function " & _
                 r.v(sVarPre & "_NAME_GetMsgObj") & ". "

  sReturnValue = "None"
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ObjNr", "", sDescription)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_SetMSGVAL
  '------------------------------------------------------------------------------------------------
  sFctName = "SetMSGVAL"
  sDescription = "This function sets the MSGVAL flag of the selected object. " & _
                 "This is only necessary if the single data transfer mode (SDT) for the selected " & _
                 "object is enabled. If SDT is set to '1', the " & sVarPre & " controller automatically " & _
                 "resets bit MSGVAL after receiving or tranmission of a frame."

  sReturnValue = "None"
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the message object (0-" & (r.v("CAN_MAX_OBJECTS")-1) & ")"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ObjNr", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_WriteFIFO
  '------------------------------------------------------------------------------------------------
  sFctName = "WriteFIFO"
  sDescription = "This function sets up the next free TRANSMIT message object " & _
                 "which is part of a FIFO. This includes the 8 data bytes, " & _
                 "the identifier (11- or 29-bit) and the data number (0-8 bytes). " & _
                 "The direction bit (DIR) and the EDE-bit " & _
                 "can not be changed. The acceptance mask register " & _
                 "and the Frame Counter remains unchanged. " & _
                 "This function checks whether the choosen message object is " & _
                 "still executing a transmit request, or if the object can " & _
                 "be accessed exclusively. " & vbCrLf & _
                 "The structure of the SW message object is defined in the " & _
                 "header file " & r.v(sVarPre & "_HFILE") & " (see " & sVarPre & "_SWObj)." & vbCrLf & _
                 "Note: " & vbCrLf & _
                 "This function can only used for TRANSMIT objects which are " & _
                 "configured for FIFO base functionality. "
        
  sReturnValue = "0: message object is busy (a transfer is active); " & _
                 "1: the message object was configured and the transmite is requested; " & _
                 "2: this is not a FIFO base object"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of the FIFO base object"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    sDescription = "Pointer on a message object"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "*pstObj", "st" & sVarPre & "_SWObj", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_NAME_ReadFIFO
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadFIFO"
  sDescription = "This function reads the next RECEIVE message object " & _
                 "which is part of a FIFO. " & _
                 "It checks whether the selected RECEIVE OBJECT has " & _
                 "received a new message. If so the forwarded SW message " & _
                 "object is filled with the content of the HW message object " & _
                 "and the functions returns the value ""1"". " & _
                 "The structure of the SW message object is defined in the " & _
                 "header file " & r.v(sVarPre & "_HFILE") & " (see " & sVarPre & "_SWObj)." & vbCrLf & _
                 "Note: " & vbCrLf & _
                 "This function can only used for RECEIVE objects which are " & _
                 "configured for FIFO base functionality. " & vbCrLf & _
                 "Be sure that no interrupt is enabled for the FIFO objects. "
        
  sReturnValue = "0: the message object has not received a new message; " & _
                 "1: the message object has received a new message; " & _
                 "2: this is not a FIFO base object; " & _
                 "3: a previous message was lost; " & _
                 "4: the received message is corrupted"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Number of the FIFO base object"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function
    sDescription = "Pointer on a message object to be filled by this function"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para2", "*pstObj", "st" & sVarPre & "_SWObj", sDescription)) Then Exit Function

'  '------------------------------------------------------------------------------------------------
'  ' Description for CAN_NAME_FlushReadFIFO
'  '------------------------------------------------------------------------------------------------
'  sFctName = "FlushReadFIFO"
'  sDescription = "This function flushes the selected RECEIVE FIFO. " & _
'                 "After a lost or corrupted message in the receive FIFO " & _
'                 "the hardware and software FIFO-pointers are no longer synchron. " & vbcrlf & _
'                 "Note: " & vbcrlf & _
'                 "This function can only used for RECEIVE objects which are " & _
'                 "configured for FIFO base functionality. "
'
'  sReturnValue = "0: this is not a FIFO base object; " & _
'                 "1: the receive FIFO was flushed; "
'  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
'    sDescription = "Number of the FIFO base object"
'    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "ubObjNr", "ubyte", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_ubGetTxErrorCounter
  '------------------------------------------------------------------------------------------------
  sFctName = "GetTxErrorCounter"
  sDescription = "This macro returns the current value of the transmit error counter of the selected node. "
'                 "The following definitions for NODE_NAME are available:" & vbCrLf
'    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
'      sDescription = sDescription & sVarPre & "_NODE" & i & "        (node " & i & ")" & vbCrLf
'    Next i
                                   
  sReturnValue = "Value of the transmit error counter"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the node (0-" & (r.v("CAN_MAX_NODES")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "NodeNr", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_ubGetRxErrorCounter
  '------------------------------------------------------------------------------------------------
  sFctName = "GetRxErrorCounter"
  sDescription = "This macro returns the current value of the receive error counter of the selected node. "
'                 "The following definitions for NODE_NAME are available:" & vbCrLf
'    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
'      sDescription = sDescription & sVarPre & "_NODE" & i & "        (node " & i & ")" & vbCrLf
'    Next i
        
  sReturnValue = "Value of the receive error counter"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the node (0-" & (r.v("CAN_MAX_NODES")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "NodeNr", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_ubGetErrorTransferDirection
  '------------------------------------------------------------------------------------------------
  sFctName = "GetErrorTransferDirection"
  sDescription = "This macro returns the current value of the Last Error Transfer Direction flag. " & _
                 "0 indicates that the last error occurred while the selected CAN node was receiving a message. " & _
                 "The receive error counter has been incremented. " & _
                 "1 indicates that the last error occurred while the selected CAN node was transmitting a message. " & _
                 "The transmit error counter has been incremented. "
'                 "The following definitions for NODE_NAME are available:" & vbCrLf
'    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
'      sDescription = sDescription & sVarPre & "_NODE" & i & "        (node " & i & ")" & vbCrLf
'    Next i
        
  sReturnValue = "0 receive error, else transmit error"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the node (0-" & (r.v("CAN_MAX_NODES")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "NodeNr", "", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for CAN_ubGetErrorIncrement
  '------------------------------------------------------------------------------------------------
  sFctName = "GetErrorIncrement"
  sDescription = "This macro returns the current value of the Last Error Increment flag. " & _
                 "If the Bit Stream Processor itself detects an error while a transmit operation " & _
                 "is running, the Transmit Error Counter is incremented by 8. An increment of 1 is " & _
                 "used, when the error condition was reported by an external CAN node via an error " & _
                 "frame generation. "
'                 "The following definitions for NODE_NAME are available:" & vbCrLf
'    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
'      sDescription = sDescription & sVarPre & "_NODE" & i & "        (node " & i & ")" & vbCrLf
'    Next i
        
  sReturnValue = "0 counter is incrementd by 1, counter is incremented by 8"
  If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "", sDescription, sReturnValue, 0)) Then Exit Function
    sDescription = "Number of the node (0-" & (r.v("CAN_MAX_NODES")-1) & ")"
    If (Not func.AddParameter(sVarPre & "_NAME_" & sFctName & "_Para1", "NodeNr", "", sDescription)) Then Exit Function


  If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
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
'        "CAN_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        vIndex           parameter of the module which was added with AddModule
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions2(vIndex As Variant, func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  RefreshFunctionDescriptions2 = False

  Dim sDescription As String
  Dim sReturnValue As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim sFctName As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"


  ' 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. CAN_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, 3 => Trap)


    ' 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

  For i = 0 To (CAN_MAX_SRNS - 1)
    '------------------------------------------------------------------------------------------------
    ' Description for CAN_NAME_SRNx
    '------------------------------------------------------------------------------------------------
    sFctName = "SRN" & i
    sDescription = "This is the interrupt service routine for the Service " & _
                        "Request Node " & i & " of the MultiCAN module. " & vbCrLf & _
                        TOOLTIP_ISR_USERCODE


    sReturnValue = "None"
    If (Not func.AddFunction(sVarPre & "_NAME_" & sFctName, "void", sDescription, sReturnValue, 2)) Then Exit Function
  Next i


  If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions2 = True
End Function


'*****************************************************************************
'Description:
'        This function makes all show activities for the page Functions2
'-----------------------------------------------------------------------------
'Parameters:
'        sIndex          module name (prefix of the functions)
'        ps              reference to the Peripherals object
'        func            reference to the FunctionClass object
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function ShowFunction2(sIndex As String, ps As Peripherals, func As FunctionClass, v() As Variant) As Boolean
  On Error GoTo ShowFunction2Error
  ShowFunction2 = False
    
  Dim r         As ProjectData
  Dim c         As Collection
  Dim e         As Collection
  Dim bDisabled As Boolean
  Dim sName     As String
  Dim d         As String
  Dim l         As Long

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  ' for each function in this 'func' object
  For l = 1 To func.FunctionCount
    ' get the function name which was insert in 'Include.inc' with 'AddFunction()'
    d = func.FunctionName(l)

    ' get only the third part of the function name (e.g "Init")
    sName = Right(d, Len(d) - InStr(d, "NAME") - Len("NAME"))

    '-------------------------------------------------------------------------
    ' control: chk_.. (show)
    '-------------------------------------------------------------------------
    ' action on showing the control
    With c("chk_" & sName)
      ' disable condition
      bDisabled = func.Disabled(d)
      .Enabled = Not (bDisabled)
      ' show condition
      If (sName = "Init") Then
        .Value = -CInt(r.v(sIndex & "_USE_" & sName) = 1)
      Else
        If (func.FunctionSort(d) = 2) Then ' if ISR
          .Value = -CInt(func.Value(d))
        Else
          .Value = -CInt(r.v(sIndex & "_USE_" & sName) = 1 And r.v(sIndex & "_USE_Init") = 1 And func.Value(d))
        End If
      End If
    End With
    
    With e("chk_" & sName)
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = func.DisabledTooltip(d)
      Else
        ' tooltip if control is enabled
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txt_... (show)
    '-------------------------------------------------------------------------
    ' action on showing the control
    With c("txt_" & sName)
      ' disable condition
      If (func.FunctionSort(d) = 2) Then ' if ISR
          bDisabled = (r.v(sIndex & "_USE_" & sName) = 0 Or r.v(sIndex & "_USE_Init") = 0 Or Not (func.Value(d)))
      Else
          bDisabled = (r.v(sIndex & "_USE_" & sName) = 0 Or r.v(sIndex & "_USE_Init") = 0)
      End If
      .Enabled = Not (bDisabled)
      ' show condition
      .Text = FormatTextOutput(r.s(d), "S")
    End With

    With e("txt_" & sName)
      If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME) & vbCrLf & vbCrLf & FormatFunctionToolTip(r, func, d)
      Else
        ' tooltip if control is enabled
        .EnabledTooltipText = FormatFunctionToolTip(r, func, d)
      End If
    End With
  Next l

  ShowFunction2 = True
  Exit Function

ShowFunction2Error:
  errorbox "Can not show page", Err.Description
  Exit Function
End Function

'*****************************************************************************
' @Functions
'*****************************************************************************
'Description:
'        This function returns the module clock (in MHz) of the
'        CAN module depending on the configured modes
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        module clock (in MHz)
'*****************************************************************************

Function GetCANModuleClock(r As ProjectData, vIndex As Variant) As Double
  On Error GoTo GetCANModuleClockError
   
'      GetCANModuleClock = GetSystemClock(r) / 2
'      r.v("CAN_FDRL_STEP") = &H3FE                'Normal Divider mode fCAN = fSYS/2

    If(r.v("CAN_FDRL_DM") <= 1) Then 'Normal Divider mode
      GetCANModuleClock = GetSystemClock(r) / (1024 - r.l("CAN_FDRL_STEP"))

    ElseIf(r.v("CAN_FDRL_DM") = 2) Then 'Fractional Divider mode
      GetCANModuleClock = GetSystemClock(r) * r.l("CAN_FDRL_STEP") / 1024
    End If
  Exit Function
    
GetCANModuleClockError:
    Errorbox "Error"
End Function


'*****************************************************************************
'Description:
'             This functoin returns a minimal module clock in MHz.
'-----------------------------------------------------------------------------
'Parameters:
'       r         As Projectdata
'       sRegPre   Register Prefix
'       sVarPre   Module Prefix
'
'-----------------------------------------------------------------------------
'Returns:
'        minimal module clock [MHz]
'*****************************************************************************
Function GetCANMinModuleClock(r As ProjectData, vIndex As Variant) As Double
  On Error GoTo GetCANMinModuleClockError
    
    GetCANMinModuleClock = 1 / 1024 * GetSystemClock(r)

  Exit Function
GetCANMinModuleClockError:
    Errorbox "Error"
End Function

'*****************************************************************************
'Description:
'             This functoin returns a maximal module clock in MHz.
'-----------------------------------------------------------------------------
'Parameters:
'       r   As Projectdata
'       sRegPre   Register Prefix
'       sVarPre   Module Prefix
'
'-----------------------------------------------------------------------------
'Returns:
'        maximal module clock [MHz]
'*****************************************************************************
Function GetCANMaxModuleClock(r As ProjectData, vIndex As Variant) As Double
  On Error GoTo GetCANMaxModuleClockError
    
    If (r.v("CAN_FDRL_DM") <= 1) Then 'Normal Divider mode
        GetCANMaxModuleClock = GetSystemClock(r)

    ElseIf (r.v("CAN_FDRL_DM") = 2) Then 'Fractional Divider mode
        GetCANMaxModuleClock = 1023 / 1024 * GetSystemClock(r)
    End If

  Exit Function
GetCANMaxModuleClockError:
    Errorbox "Error"
End Function

'*****************************************************************************
'Description:
'        This function updates the CAN module clock.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub UpdateCANModuleClock(r As ProjectData, vIndex As Variant)
    On Error GoTo UpdateCANModuleClockError

    Dim sVarPre As String
    Dim sRegPre As String
    Dim lStepVal As Long
    Dim i As Integer

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"

    If (r.d(sVarPre & "_RequiredClock") > GetCANMaxModuleClock(r, vIndex)) Then
        r.d(sVarPre & "_RequiredClock") = GetCANMaxModuleClock(r, vIndex)
    End If
    If (r.d(sVarPre & "_RequiredClock") < GetCANMinModuleClock(r, vIndex)) Then
        r.d(sVarPre & "_RequiredClock") = GetCANMinModuleClock(r, vIndex)
    End If

    If(r.v("CAN_FDRL_DM") = 0) Then 'switch off
      r.d(sVarPre & "_RequiredClock") = GetCANModuleClock(r,vIndex)
      lStepVal = &H3FF

	ElseIf(r.v("CAN_FDRL_DM") = 1) Then 'Normal Divider mode
      lStepVal = 1024 - (GetSystemClock(r) / r.d(sVarPre & "_RequiredClock"))

      If(lStepVal > &H3FF) Then
        lStepVal = &H3FF
      End If

    ElseIf(r.v("CAN_FDRL_DM") = 2) Then 'Fractional Divider mode
      lStepVal = (r.d(sVarPre & "_RequiredClock") * 1024) / GetSystemClock(r)

      If(lStepVal > &H3FF) Then
        lStepVal = &H3FF
      End If

    End If

    r.l("CAN_FDRL_STEP") = lStepVal

    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
      Call UpdateNodexBaudrate(r, vIndex, i)     ' update the node baud rate
    Next i

  Exit Sub
UpdateCANModuleClockError:
    Errorbox "Error"
End Sub

'*****************************************************************************
'Description:
'        This function returns the clock (in MHz) of the
'        requested node.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the node
'-----------------------------------------------------------------------------
'Returns:
'        node x clock (in MHz)
'*****************************************************************************
Function GetNodexClock(r As ProjectData, vIndex As Variant, iNr As Integer) As Double
  On Error Resume Next
  Dim sVarPre As String
  Dim v As String
  Dim sRegPre As String
  Dim sNBTRx As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
  sNBTRx = sRegPre & "NBTR" & iNr

  GetNodexClock = 1

  If (r.v(sNBTRx & "L_DIV8") = 0) Then
    GetNodexClock = GetCANModuleClock(r, vIndex)
  Else
    GetNodexClock = GetCANModuleClock(r, vIndex) / 8
  End If

End Function


'*****************************************************************************
'Description:
'        This function checks if the module clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            the module clock is disabled
'        False           else
'*****************************************************************************
Function IsModuleClockDisabled(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
  IsModuleClockDisabled = False
  IsModuleClockDisabled = r.v("MCAN_KSCCFG_MODEN") = 0
End Function


'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if the module
'        clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************
Function GetTooltipModuleClockDisabled(r As ProjectData, vIndex As Variant) As String
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
  
  GetTooltipModuleClockDisabled = "CAN module clock is disabled"
End Function



'*****************************************************************************
'Description:
'        This function checks if enough port pins selected for the node.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the CAN node
'-----------------------------------------------------------------------------
'Returns:
'        True            not enough port pins selected
'        False           else
'*****************************************************************************
Function IsPinInterfaceDeselected(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN_USE" & vIndex
  sRegPre = sVarPre & "_"

  IsPinInterfaceDeselected = False

   If ((r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = RXDPIN_DEF_MSG(iNr)) Or (r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") = TXDPIN_DEF_MSG(iNr))) Then
    IsPinInterfaceDeselected = True
  End If

'   If ((r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = 0) Or (r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") = 0)) Then
'    IsPinInterfaceDeselected = True
'  End If

End Function


'*****************************************************************************
'Description:
'        This function returns the min value of bit TSEG1.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        vValue          input value
'        iNr             number of the node
'-----------------------------------------------------------------------------
'Returns:
'       min value of TSEG1
'*****************************************************************************
Function GetMinTseg1Value(r As ProjectData, vIndex As Variant, vValue As Variant, iNr As Integer) As Integer
    On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String
    Dim iMin As Integer
    Dim sNBTRx As String

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"
    sNBTRx = sRegPre & "NBTR" & iNr
    iMin = r.d(sNBTRx & "L_SJW") + 1

    If (vValue < iMin) Then
        If (vValue < 3) Then
            GetMinTseg1Value = 3
        Else
            GetMinTseg1Value = r.d(sNBTRx & "L_SJW") + 1
        End If
    Else
        GetMinTseg1Value = 3
    End If
 
End Function

'*****************************************************************************
'Description:
'        This function returns the min value of bit TSEG2.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        vValue          input value
'        iNr             number of the node
'
'-----------------------------------------------------------------------------
'Returns:
'       min value of TSEG2
'*****************************************************************************
Function GetMinTseg2Value(r As ProjectData, vIndex As Variant, vValue As Variant, iNr As Integer) As Integer
    On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String
    Dim iMin As Integer
    Dim sNBTRx As String

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"
    sNBTRx = sRegPre & "NBTR" & iNr
    iMin = r.d(sNBTRx & "L_SJW") + 1

    If (vValue < iMin) Then
        If (vValue < 2) Then
            GetMinTseg2Value = 2
        Else
            GetMinTseg2Value = r.d(sNBTRx & "L_SJW") + 1
        End If
    Else
        GetMinTseg2Value = 2
    End If

End Function

'*****************************************************************************
'Description:
'        This function returns the min value of bit SJW.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        vValue          input value
'        iNr             number of the node
'
'-----------------------------------------------------------------------------
'Returns:
'       min value of SJW
'*****************************************************************************
Function GetMinSJWValue(r As ProjectData, vIndex As Variant, vValue As Variant, iNr As Integer) As Integer
    On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String
    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"

    GetMinSJWValue = 1

End Function

'*****************************************************************************
'Description:
'        This function returns the max value of bit SJW.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        vValue          input value
'        iNr             number of the node
'
'-----------------------------------------------------------------------------
'Returns:
'       max value of SJW
'*****************************************************************************
Function GetMaxSJWValue(r As ProjectData, vIndex As Variant, vValue As Variant, iNr As Integer) As Integer
    On Error Resume Next
Dim sVarPre As String
Dim sRegPre As String
Dim sNBTRx As String

sVarPre = "CAN" & vIndex
sRegPre = sVarPre & "_"
sNBTRx = sRegPre & "NBTR" & iNr

If (((vValue - 1) > r.d(sNBTRx & "L_TSEG1")) Or ((vValue - 1) > r.d(sNBTRx & "L_TSEG2"))) Then
    If (vValue > 4) Then
        GetMaxSJWValue = 4
    Else
        If (vValue > (r.d(sNBTRx & "L_TSEG1") + 1)) Then
            GetMaxSJWValue = r.d(sNBTRx & "L_TSEG1") + 1
        End If
        If (vValue > (r.d(sNBTRx & "L_TSEG2") + 1)) Then
            GetMaxSJWValue = r.d(sNBTRx & "L_TSEG2") + 1
        End If
    End If
Else
   GetMaxSJWValue = 4
End If

End Function


'*****************************************************************************
'Description:
'        This function returns the min required baud rate [Baud].
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the node
'
'-----------------------------------------------------------------------------
'Returns:
'       min required baud rate [Baud]
'*****************************************************************************
Function GetMinReqBR(r As ProjectData, vIndex As Variant, iNr As Integer) As Long
    On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String
    Dim sNBTRx As String

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"
    sNBTRx = sRegPre & "NBTR" & iNr

    GetMinReqBR = GetNodexClock(r, vIndex, iNr) * 1000000 / (64 * 2 ^ (1 - 1) * _
                  (3 + r.d(sNBTRx & "L_TSEG1") + r.d(sNBTRx & "L_TSEG2")))

End Function

'*****************************************************************************
'Description:
'        This function returns the max required baud rate [Baud].
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the node
'
'-----------------------------------------------------------------------------
'Returns:
'       max required baud rate [Baud]
'*****************************************************************************
Function GetMaxReqBR(r As ProjectData, vIndex As Variant, iNr As Integer) As Long
    On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String
    Dim sNBTRx As String

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"
    sNBTRx = sRegPre & "NBTR" & iNr

    GetMaxReqBR = GetNodexClock(r, vIndex, iNr) * 1000000 / (2 ^ (1 - 1) * _
                  (3 + r.d(sNBTRx & "L_TSEG1") + r.d(sNBTRx & "L_TSEG2")))

    If(GetMaxReqBR > 1000000) Then
      GetMaxReqBR = 1000000
    End If

End Function


'*****************************************************************************
'Description:
'        This function checks if all nodes are deselected.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Return:
'        True            the module clock is disabled
'        False           else
'*****************************************************************************
Function IsAllNodesDeselected(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
  
  IsAllNodesDeselected = True
  For i = 0 To (r.v("CAN_MAX_NODES") - 1)
    If (r.v(sRegPre & "NCR" & i & "_INIT") = 0) Then
      IsAllNodesDeselected = False
      Exit For
    End If
  Next i
End Function

'*****************************************************************************
'Description:
'        This function checks if a object is used as a FIFO slave and which
'        object is the base FIFO object.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number message object
'-----------------------------------------------------------------------------
'Returns: -1 if the object is not used as FIFO slave, else returns the number
'         of the base object
'*****************************************************************************
Function IsObjFIFOSlave(r As ProjectData, vIndex As Variant, iNr As Integer) As Integer
  On Error Resume Next
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim iFirstNr As Integer
  Dim iLastNr As Integer
  Dim iNextNr As Integer
  Dim iBase As Integer

  IsObjFIFOSlave = -1

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
                        
' fr alle MO's
' if MO = FIFO Base (MMC = 1)
' dann suche alle Slaves
  For iBase = 0 To (r.v("CAN_MAX_OBJECTS") - 1)
    If (r.v(sRegPre & "MOFCR" & iBase & "L_MMC") = 1 Or r.v(sRegPre & "MOFCR" & iBase & "L_MMC") = 2 Or r.v(sRegPre & "MOFCR" & iBase & "L_MMC") = 4) Then  ' only if the FIFO or Gateway mode is selected
      ' suche alle MOs von BOT bis TOP des MOs iBase
      iFirstNr = r.v(sRegPre & "MOFGPR" & iBase & "L_BOT")
      iLastNr = r.v(sRegPre & "MOFGPR" & iBase & "L_TOP")
      If (iFirstNr <= (r.v("CAN_MAX_OBJECTS") - 1) And iLastNr <= (r.v("CAN_MAX_OBJECTS") - 1)) Then
        iNextNr = iFirstNr

        Do
          If (iNextNr = iNr And iNr <> iBase) Then
            IsObjFIFOSlave = iBase
          End If
          If (iNextNr = iLastNr) Then
          Else
            iNextNr = GetPNEXT(r, vIndex, iNextNr)
          End If
        Loop Until iNextNr = iLastNr

        If (iLastNr = iNr And iNr <> iBase) Then
          IsObjFIFOSlave = iBase
        End If
      End If
    End If
  Next iBase

End Function


'*****************************************************************************
'Description:
'        This function checks if a object is connected to a node which is
'        configured for analyzer mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number message object
'-----------------------------------------------------------------------------
'Returns: true if assigned node is in analyzer mode else false
'*****************************************************************************
Function IsObjConnectedToAnalyzer(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim iNode As Integer

  IsObjConnectedToAnalyzer = False

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  iNode = r.v(sRegPre & "MOCTR" & iNr & "L_LIST") - 1 ' number of the node
  If (iNode >= 0) Then
    If (r.v(sRegPre & "NCR" & iNode & "_CALM") = 1) Then ' Analyser mode
      IsObjConnectedToAnalyzer = True
    End If
  End If
End Function


'*****************************************************************************
'Description:
'        This function sets initialization values for the fractional divider.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub InitFDR(r As ProjectData, vIndex As Variant)
  On Error Resume Next
    Dim sVarPre As String
    Dim sRegPre As String

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"

    r.sfr(sRegPre & "FDRL") = &H43FE 'Noramal Divider mode
    r.d(sVarPre & "_RequiredClock") = GetCANModuleClock(r,vIndex)
End Sub

'*****************************************************************************
'Description:
'        This function used to release the ERU Module's CAN pin when RXDC is 
' disabled(no pin selection).
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub ReleaseERU(r As ProjectData, vIndex As Variant, iNr As Integer)
  On Error Resume Next

  If(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") = RXDPIN_DEF_MSG(iNr)) Then 'if no RXD pin selected

    Select Case(iNr)
      Case (0)
          If (r.v("SCU_USE_ERU3B") = 2) Then
            r.v("SCU_USE_ERU3B") = 0
          End If
      Case (1)
          If (r.v("SCU_USE_ERU3A") = 2) Then
            r.v("SCU_USE_ERU3A") = 0
          End If
      Case (2)
          If (r.v("SCU_USE_ERU2B") = 2) Then
            r.v("SCU_USE_ERU2B") = 0
          End If
      Case (3)
          If (r.v("SCU_USE_ERU2A") = 2) Then
            r.v("SCU_USE_ERU2A") = 0
          End If
      Case (4)
          If (r.v("SCU_USE_ERU1B") = 2) Then
            r.v("SCU_USE_ERU1B") = 0
          End If

      Case Else

    End Select

  End If

End Sub
'*****************************************************************************
'Description:
'        This function updates the node x baud rate.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the node
'
'-----------------------------------------------------------------------------
'Returns:
'       none
'*****************************************************************************
Sub UpdateNodexBaudrate(r As ProjectData, vIndex As Variant, iNr As Integer)
    On Error GoTo UpdateNodexBaudrateError
    Dim sVarPre As String
    Dim sRegPre As String
    Dim sNBTRx As String

    sVarPre = "CAN" & vIndex
    sRegPre = sVarPre & "_"
    sNBTRx = sRegPre & "NBTR" & iNr

    If (r.v(sVarPre & "_BaudrateNode" & iNr) > GetMaxReqBR(r, vIndex, iNr)) Then
        r.v(sVarPre & "_BaudrateNode" & iNr) = GetMaxReqBR(r, vIndex, iNr)
    End If
    If (r.v(sVarPre & "_BaudrateNode" & iNr) < GetMinReqBR(r, vIndex, iNr)) Then
        r.v(sVarPre & "_BaudrateNode" & iNr) = GetMinReqBR(r, vIndex, iNr)
    End If

    r.l(sNBTRx & "L_BRP") = (1000000 * GetNodexClock(r, vIndex, iNr) / (r.v(sVarPre & "_BaudrateNode" & iNr) * _
                           2 ^ (1 - 1) * (3 + r.d(sNBTRx & "L_TSEG1") + r.d(sNBTRx & "L_TSEG2"))) - 1)
    Exit Sub

UpdateNodexBaudrateError:
    r.d(sNBTRx & "L_BRP") = 10
    Exit Sub
End Sub


'*****************************************************************************
'Description:
'        This function disables all CAN interrupts.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub DisableSRNs(r As ProjectData, vIndex As Variant)
  On Error Resume Next
  Dim i As Integer
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  For i = 0 To (CAN_MAX_SRNS - 1)
    Call DisableSRN(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
  Next i

End Sub

'*****************************************************************************
'Description:
'        This function disables all CAN objects which are connected to the
'        node specified with 'iNodeNr' and sets all registers to default values.
'        Also all objects configured for gateway mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNodeNr         number of the node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub DisableObjx(r As ProjectData, vIndex As Variant, iNodeNr As Integer)
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim iNr As Integer

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  For iNr = 0 To (r.v("CAN_MAX_OBJECTS") - 1)
    If (r.v(sRegPre & "MOCTR" & iNr & "L_LIST") = (iNodeNr + 1)) Then ' only if the object is assigned to the Node iNodeNr
      ' if the MO is configured as FIFO base object then all slaves must be released
      SetStandardMode(r, vIndex, iNr)

      r.sfr(sRegPre & "MOCTR" & iNr & "H") = &H0000
      r.sfr(sRegPre & "MOCTR" & iNr & "L") = &H0000
      r.sfr(sRegPre & "MOFCR" & iNr & "H") = &H0000
      r.sfr(sRegPre & "MOFCR" & iNr & "L") = &H0000
      If (Not GetObjXIntrStatus(r, vIndex, iNr)) Then
'        r.sfr(sRegPre & r.v(sRegPre & "MOIPR" & iNr & "L_TXINP") & "IC") = &H0000
        Call DisableSRN(r, sVarPre, sRegPre & r.v(sRegPre & "MOIPR" & iNr & "L_TXINP") & "IC", "SRN" & r.v(sRegPre & "MOIPR" & iNr & "L_TXINP"))
      End If
      r.v(sVarPre & "_MO" & iNr & "_LISTPOS") = 0
    End If
  Next iNr

End Sub


'*****************************************************************************
'Description:
'        This function disables the CAN Node x and sets all registers to
'        default values. All node dependend objects are disabled too.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub DisableNodex(r As ProjectData, vIndex As Variant, iNr As Integer)
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sNCRx As String  ' Node x Control Register
  Dim sNIPRx As String ' Node x Interrupt Pointer Register
  Dim sNPCRx As String ' Node x Port Control Register
  Dim sNBTRx As String ' Node x Bit Timing Register
  Dim sNECNTx As String ' Node x Error Counter Register
  Dim sNFCRx As String ' Node x Frame Counter Register
  Dim sTTCRx As String
  Dim sTTCFGRx As String
  Dim sTTIERx As String
  Dim sTURRx As String
  Dim i As Integer
  Dim j As Integer

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  sNCRx = sRegPre & "NCR" & iNr
  sNIPRx = sRegPre & "NIPR" & iNr
  sNPCRx = sRegPre & "NPCR" & iNr
  sNBTRx = sRegPre & "NBTR" & iNr
  sNECNTx = sRegPre & "NECNT" & iNr
  sNFCRx = sRegPre & "NFCR" & iNr
                   
  sTTCRx = sRegPre & "TTCR" ' & iNr
  sTTCFGRx = sRegPre & "TTCFGR" ' & iNr
  sTTIERx = sRegPre & "TTIER" ' & iNr
  sTURRx = sRegPre & "TURR" ' & iNr
  If (r.v(sNCRx & "_INIT") = 0) Then ' only if the node was selected
    ' set defaults for page "Control"
    r.sfr(sNCRx) = &H1
    If (Not GetNodeXIntrStatus(r, vIndex, iNr)) Then
'      r.sfr(sRegPre & r.v(sNIPRx & "_TRINP") & "IC") = &H0000
       Call DisableSRN(r, sVarPre, sRegPre & r.v(sNIPRx & "_TRINP") & "IC", "SRN" & r.v(sNIPRx & "_TRINP"))
    End If
    r.sfr(sNIPRx) = r.sfr(sNIPRx) And &H0F00       'retains node SRN pointer
   ' r.v(sNPCRx & "_LBM") = 0 --->by ashish for LBM
      
     ' set defaults for page "Baud Rate"
    Call UpdateNodexBaudrate(r, vIndex, iNr)

    ' set defaults for page "Frame Counter"
    r.v(sNFCRx & "H_CFSEL") = 0
    r.v(sNFCRx & "H_CFCIE") = 0

    ' disable all objects which are connected to node "iNr"
    Call DisableObjx(r, vIndex, iNr)

    ' check if no node is active, if so then disable the Init function
    ' and all interrupts
    j = 0
    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
      If (r.v(sRegPre & "NCR" & i & "_INIT") = 1) Then
        j = j + 1
      End If
    Next i
    If (j = r.v("CAN_MAX_NODES")) Then
      r.v(sVarPre & "_USE_Init") = 0
      Call DisableSRNs(r, vIndex)
    End If
    
  End If

End Sub

'*****************************************************************************
'Description:
'        This function intialize the Function Page variables
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************

Sub DisableAllFuncVars(r As ProjectData, vIndex As Variant)
  On Error Resume Next

  r.v("CAN_USE_GetMsgObj")                 = 0
  r.v("CAN_USE_RequestMsgObj")             = 0
  r.v("CAN_USE_NewData")                   = 0
  r.v("CAN_USE_Transmit")                  = 0
  r.v("CAN_USE_ConfigMsgObj")              = 0
  r.v("CAN_USE_LoadData")                  = 0
  r.v("CAN_USE_DelMsgObj")                 = 0
  r.v("CAN_USE_MsgLost")                   = 0
  r.v("CAN_USE_ReleaseObj")                = 0
  r.v("CAN_USE_SetMSGVAL")                 = 0
  r.v("CAN_USE_WriteFIFO")                 = 0
  r.v("CAN_USE_ReadFIFO")                  = 0
  r.v("CAN_USE_FlushReadFIFO")             = 0
  r.v("CAN_USE_GetTxErrorCounter")         = 0
  r.v("CAN_USE_GetRxErrorCounter")         = 0
  r.v("CAN_USE_GetErrorTransferDirection") = 0
  r.v("CAN_USE_GetErrorIncrement")         = 0

End Sub

'*****************************************************************************
'Description:
'        This functions disable LBM .
'-----------------------------------------------------------------------------
Sub DisableLBMx(r As ProjectData, vIndex As Variant, iNr As Integer)
        On Error Resume Next

 Dim bDisabled As Boolean
 Dim sVarPre As String
 Dim sRegPre As String
 Dim sNPCRx As String ' Node x Port Control Register

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"
  sNPCRx = sRegPre & "NPCR" & iNr
  r.v(sNPCRx & "_LBM") = 0

End Sub


'*****************************************************************************
'Description:
'        This function disables the CAN module and sets all registers to
'        default values. All requested pins are released.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub DisableModule(r As ProjectData, vIndex As Variant)
  On Error Resume Next
  Dim i As Integer
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Call InitFDR(r,vIndex)  ' set default settings for fractional divider 

  For i = 0 To (r.v("CAN_MAX_NODES") - 1)
    Call ReleaseAllNodexPins(r, vIndex, i)
    r.v("CAN_USE_NODE" & i & "_RXD_PIN") = RXDPIN_DEF_MSG(i)
    r.v("CAN_USE_NODE" & i & "_TXD_PIN") = TXDPIN_DEF_MSG(i)
    Call DisableNodex(r, vIndex, i)
    Call DisableLBMx(r, vIndex, i)
  Next i

  Call DisableSRNs(r, vIndex)
  Call DisableAllFuncVars(r, vIndex)
  
End Sub

'*****************************************************************************
'Description:
'        This function returns the PNEXT pointer from the given MO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        MOIndex         index of the Message Object
'-----------------------------------------------------------------------------
'Returns:
'        PNEXT
'*****************************************************************************
Function GetPNEXT(r As ProjectData, vIndex As Variant, MOIndex As Integer) As Integer
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  GetPNEXT = r.v(sRegPre & "MOCTR" & MOIndex & "H_CTRL") \ 2 ^ 8

End Function

'*****************************************************************************
'Description:
'        This function returns the PPREV pointer from the given MO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        MOIndex         index of the Message Object
'-----------------------------------------------------------------------------
'Returns:
'        PPREV
'*****************************************************************************
Function GetPPREV(r As ProjectData, vIndex As Variant, MOIndex As Integer) As Integer
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  GetPPREV = r.v(sRegPre & "MOCTR" & MOIndex & "H_CTRL") Mod 2 ^ 8

End Function


'*****************************************************************************
'Description:
'        This function used to reset the FIFO related registers.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the FIFO base object
'        iNextNr         number of the next FIFO base object
'-----------------------------------------------------------------------------
'Returns:
'        True
'*****************************************************************************

Function ResetValuesForFIFOSlave(r As ProjectData, vIndex As Variant, iNr As Integer, iNextNr As Integer) As Boolean
  On Error Resume Next
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer

  ResetValuesForFIFOSlave = True

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  ' if iNr = iNextNr then the base object is part of the FIFO and must not be changed
  If (iNr <> iNextNr) Then
    Debug.Print "Reset FIFO slave " & iNextNr
    ' receive FIFO slave for a receive base object
    If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 1) Then
      r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL") = 0
      r.v(sRegPre & "MOFCR" & iNextNr & "L_MMC") = 0
      r.v(sRegPre & "MOFGPR" & iNextNr & "H_CUR") = 0
    End If

    ' transmit FIFO slave for a transmit base object
    If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 2) Then
      r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL") = 0
      r.v(sRegPre & "MOFCR" & iNextNr & "L_MMC") = 0
      r.v(sRegPre & "MOFGPR" & iNextNr & "H_CUR") = 0
    End If

    ' FIFO Settings for a Gateway destination
    If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 4) Then
      r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL") = 0
      r.v(sRegPre & "MOFCR" & iNextNr & "L_MMC") = 0
      r.v(sRegPre & "MOFCR" & iNextNr & "H_FRREN") = 0
      r.v(sRegPre & "MOFGPR" & iNextNr & "H_CUR") = 0
    End If

    If(r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL")=0) Then
      'Disable TXIE
      r.v(sRegPre & "MOFCR" & iNextNr &"H_TXIE") = 0
	  If (Not IsSRNUsed(r, vIndex, r.v(sRegPre & "MOIPR" & iNextNr &"L_TXINP"))) Then
        Call DisableSRN(r, sVarPre, sRegPre & r.v(sRegPre & "MOIPR" & iNextNr &"L_TXINP") & "IC", "SRN" & r.v(sRegPre & "MOIPR" & iNextNr &"L_TXINP"))
      End If
      'Disable RXIE
      r.v(sRegPre & "MOFCR" & iNextNr &"H_RXIE") = 0
      If (Not IsSRNUsed(r, vIndex, r.v(sRegPre & "MOIPR" & iNextNr &"L_RXINP"))) Then
        Call DisableSRN(r, sVarPre, sRegPre & r.v(sRegPre & "MOIPR" & iNextNr &"L_RXINP") & "IC", "SRN" & r.v(sRegPre & "MOIPR" & iNextNr &"L_RXINP"))
      End If

    End If

  End If

End Function

'*****************************************************************************
'Description:
'        This function used to configure the FIFO related registers for 
'      FIFO/GATEWAY functionality
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the FIFO base object
'        iNextNr         number of the next FIFO base object
'-----------------------------------------------------------------------------
'Returns:
'        True
'*****************************************************************************

Function SetValuesForFIFOSlave(r As ProjectData, vIndex As Variant, iNr As Integer, iNextNr As Integer) As Boolean
  On Error Resume Next
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer

  SetValuesForFIFOSlave = True

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  ' if iNr = iNextNr then the base object is part of the FIFO and must not be changed
  If (iNr <> iNextNr) Then
    ' receive FIFO slave for a receive base object
    If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 1) Then
      r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL") = 1
      r.v(sRegPre & "MOFGPR" & iNextNr & "H_CUR") = &HFF
      ' the values for MMC, DIR, ID ... are ignored, but it looks better if
      ' they are set
      r.v(sRegPre & "MOCTR" & iNextNr & "L_DIR") = 0
      r.sfr(sRegPre & "MOFCR" & iNextNr & "H") = 0 ' MMC = 0
      r.sfr(sRegPre & "MOFCR" & iNextNr & "L") = 0 ' MMC = 0
      r.sfr(sRegPre & "MOAMR" & iNextNr & "H") = r.sfr(sRegPre & "MOAMR" & iNr & "H")
      r.sfr(sRegPre & "MOAMR" & iNextNr & "L") = r.sfr(sRegPre & "MOAMR" & iNr & "L")
      r.sfr(sRegPre & "MOAR" & iNextNr & "H") = r.sfr(sRegPre & "MOAR" & iNr & "H")
      r.sfr(sRegPre & "MOAR" & iNextNr & "L") = r.sfr(sRegPre & "MOAR" & iNr & "L")
    End If

    ' transmit FIFO slave for a transmit base object
    If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 2) Then
      r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL") = 1
      r.v(sRegPre & "MOCTR" & iNextNr & "L_DIR") = 1
      r.sfr(sRegPre & "MOFCR" & iNextNr & "H") = 0 ' MMC = 3
      r.sfr(sRegPre & "MOFCR" & iNextNr & "L") = 3
      r.v(sRegPre & "MOFGPR" & iNextNr & "H_CUR") = iNr
      r.sfr(sRegPre & "MOAMR" & iNextNr & "H") = r.sfr(sRegPre & "MOAMR" & iNr & "H")
      r.sfr(sRegPre & "MOAMR" & iNextNr & "L") = r.sfr(sRegPre & "MOAMR" & iNr & "L")
      r.sfr(sRegPre & "MOAR" & iNextNr & "H") = r.sfr(sRegPre & "MOAR" & iNr & "H")
      r.sfr(sRegPre & "MOAR" & iNextNr & "L") = r.sfr(sRegPre & "MOAR" & iNr & "L")
    End If

    ' FIFO Settings for a Gateway destination
    If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 4) Then
      r.v(sRegPre & "MOCTR" & iNextNr & "L_MSGVAL") = 1
      r.v(sRegPre & "MOCTR" & iNextNr & "L_DIR") = 1 - r.v(sRegPre & "MOCTR" & iNr & "L_DIR")
      r.sfr(sRegPre & "MOFCR" & iNextNr & "H") = 0 ' MMC = 0
      r.sfr(sRegPre & "MOFCR" & iNextNr & "L") = 0
      r.v(sRegPre & "MOFGPR" & iNextNr & "H_CUR") = iNr
      r.sfr(sRegPre & "MOAR" & iNextNr & "H") = r.sfr(sRegPre & "MOAR" & iNr & "H")
      r.sfr(sRegPre & "MOAR" & iNextNr & "L") = r.sfr(sRegPre & "MOAR" & iNr & "L")
    End If

  End If
End Function

'*****************************************************************************
'Description:
'        This function sets the standard mode for the selected object.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the gateway object
'-----------------------------------------------------------------------------
'Returns:  true if all settings are made, else false
'
'*****************************************************************************
Function SetStandardMode(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim bReturn As Boolean

  SetStandardMode = False

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  bReturn = True
  If (bReturn) Then
    ' if the last mode was FIFO mode then all slaves are unused
    ' and the pointer are cleared
    bReturn = ResetFIFOBaseMode(r, vIndex, iNr)
  End If

  If (bReturn) Then
    '---------------------------------
    ' settings for the standard mode
    '---------------------------------
    Call ResetMofcrBitFields(r, vIndex, iNr)
   ''r.sfr(sRegPre & "MOFCR" & iNr) = 0 ' MMC = 0
    ' mark SEL, BOT, TOP and CUR as unused
    r.sfr(sRegPre & "MOFGPR" & iNr & "H") = &HFFFF
    r.sfr(sRegPre & "MOFGPR" & iNr & "L") = &HFFFF

    SetStandardMode = True
  End If

End Function


'*****************************************************************************
'Description:
'        This function makes all settings for the FIFO base mode.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the FIFO base object
'-----------------------------------------------------------------------------
'Returns:  true if all settings are made, else false
'
'*****************************************************************************
Function SetFIFOBaseMode(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim iOldMMC As Integer
  Dim bReturn As Boolean

  SetFIFOBaseMode = False

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  bReturn = True

  If (bReturn) Then
    ' save the current value of MMC for the case that the function
    ' ChangeFIFOSettings returns a False
'    iOldMMC = r.v(sRegPre & "MOFCR" & iNr & "_MMC")
'    r.v(sRegPre & "MOFCR" & iNr & "_MMC") = 1
    bReturn = SetFIFOSlaves(r, vIndex, iNr)

    If (bReturn) Then
      ' settings for the FIFO base object
      r.v(sRegPre & "MOFCR" & iNr & "L_DLCC") = 0
      r.v(sRegPre & "MOFCR" & iNr & "L_IDC") = 0
      r.v(sRegPre & "MOFCR" & iNr & "L_GDFS") = 0
      r.v(sRegPre & "MOFCR" & iNr & "L_DATC") = 0
      r.v(sRegPre & "MOFCR" & iNr & "H_FRREN") = 0

      SetFIFOBaseMode = True
    Else
      ' restore old value of MMC
'      r.v(sRegPre & "MOFCR" & iNr & "_MMC") = iOldMMC
    End If
  End If

End Function


'*****************************************************************************
'Description:
'        This function resets all slave objects for a FIFO which are no
'        longer part of the FIFO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the FIFO base object
'-----------------------------------------------------------------------------
'Returns:  true if all settings are made or no FIFO mode selected, else
'          false
'*****************************************************************************
Function ResetFIFOBaseMode(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim bReturn As Boolean

  ResetFIFOBaseMode = True

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 1 Or r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 2 Or r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 4) Then  ' only if the FIFO or Gateway mode is selected
    
    ' clear all used FIFO slaves
    bReturn = ResetFIFOSlaves(r, vIndex, iNr)

    If (bReturn) Then
      ' default settings for the FIFO base object
'      r.v(sRegPre & "MOFCR" & iNr & "_FD") = 0
    Else
      ResetFIFOBaseMode = False
    End If
  End If
End Function


'*****************************************************************************
'Description:
'        This function changes the settings of the slave FIFO objects when
'        they are changed in the base object.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the FIFO base object
'-----------------------------------------------------------------------------
'Returns:  true if all settings are made or no FIFO mode selected, else
'          false
'*****************************************************************************
Function SetFIFOSlaves(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim s As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim iFirstNr As Integer
  Dim iLastNr As Integer
  Dim iNextNr As Integer

  SetFIFOSlaves = True

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 1 Or r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 2 Or r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 4) Then  ' only if the FIFO or Gateway mode is selected
    ' suche alle MOs von BOT bis TOP des MOs iNr
    iFirstNr = r.v(sRegPre & "MOFGPR" & iNr & "L_BOT")
    iLastNr = r.v(sRegPre & "MOFGPR" & iNr & "L_TOP")
    If (iFirstNr <= (r.v("CAN_MAX_OBJECTS") - 1) And iLastNr <= (r.v("CAN_MAX_OBJECTS") - 1)) Then
      If (iFirstNr <> iLastNr) Then
        iNextNr = iFirstNr
        Do
          SetValuesForFIFOSlave(r, vIndex, iNr, iNextNr)
          If (iNextNr = iLastNr) Then
          Else
            iNextNr = GetPNEXT(r, vIndex, iNextNr)
          End If
        Loop Until iNextNr = iLastNr
      End If
      SetValuesForFIFOSlave(r, vIndex, iNr, iLastNr)
    End If

  End If
End Function


'*****************************************************************************
'Description:
'        This function resets all slave objects for a FIFO which are no
'        longer part of the FIFO.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the FIFO base object
'-----------------------------------------------------------------------------
'Returns:  true if all settings are made or no FIFO mode selected, else
'          false
'*****************************************************************************
Function ResetFIFOSlaves(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
  On Error Resume Next
  Dim sVarPre As String
  Dim sRegPre As String
  Dim bReturn As Boolean
  Dim iFirstNr As Integer
  Dim iLastNr As Integer
  Dim iNextNr As Integer

  ResetFIFOSlaves = True

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  If (r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 1 Or r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 2 Or r.v(sRegPre & "MOFCR" & iNr & "L_MMC") = 4) Then  ' only if the FIFO or Gateway mode is selected
    ' suche alle MOs von BOT bis TOP des MOs iNr
    iFirstNr = r.v(sRegPre & "MOFGPR" & iNr & "L_BOT")
    iLastNr = r.v(sRegPre & "MOFGPR" & iNr & "L_TOP")
    If (iFirstNr <= (r.v("CAN_MAX_OBJECTS") - 1) And iLastNr <= (r.v("CAN_MAX_OBJECTS") - 1)) Then
      If (iFirstNr <> iLastNr) Then
        iNextNr = iFirstNr
        Do
          ResetValuesForFIFOSlave(r, vIndex, iNr, iNextNr)
          If (iNextNr = iLastNr) Then
          Else
            iNextNr = GetPNEXT(r, vIndex, iNextNr)
          End If
        Loop Until iNextNr = iLastNr
      End If
      ResetValuesForFIFOSlave(r, vIndex, iNr, iLastNr)
    End If

  End If
End Function

'*****************************************************************************
'Description:
'        This functions Reset MOFCR reg. bits.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'        iNr             number of the node
'-----------------------------------------------------------------------------
'Returns:  
'*****************************************************************************

Function ResetMofcrBitFields(r As ProjectData, vIndex As Variant, iNr As Integer)

On Error Resume Next

 Dim s As String
 Dim sVarPre As String
 Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  r.v(sRegPre & "MOFCR" & iNr & "L_MMC")  = 0
  r.v(sRegPre & "MOFCR" & iNr & "L_GDFS") = 0
  r.v(sRegPre & "MOFCR" & iNr & "L_IDC")  = 0
  r.v(sRegPre & "MOFCR" & iNr & "L_DLCC") = 0
  r.v(sRegPre & "MOFCR" & iNr & "L_DATC") = 0
  'r.v(sRegPre & "MOFCR" & iNr & "H_RXIE")= 0
  'r.v(sRegPre & "MOFCR" & iNr & "H_TXIE")= 0
  r.v(sRegPre & "MOFCR" & iNr & "H_OVIE") = 0
  r.v(sRegPre & "MOFCR" & iNr & "H_FRREN")= 0
  r.v(sRegPre & "MOFCR" & iNr & "H_RMM")  = 0
  r.v(sRegPre & "MOFCR" & iNr & "H_SDT")  = 0
  r.v(sRegPre & "MOFCR" & iNr & "H_STT")  = 0
  'r.v(sRegPre & "MOFCR" & iNr & "H_DLC") = 0
End Function

'*****************************************************************************
'Description:
'        This function is used to check the status of the SRN's allocation in 
'       Nodes(rest of the current Node) and Objs
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the node
'-----------------------------------------------------------------------------
'Returns:  True if current SRN is occupied by any one of the Node or Obj
'          false if Current SRN is Free
'*****************************************************************************

Function GetNodeXIntrStatus(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
        On Error Resume Next

  GetNodeXIntrStatus = False

  Dim c As Object
  Dim e As Object
  Dim i As Integer
  Dim j As Integer
  Dim sVarPre As String
  Dim sRegPre As String

  Dim sNCRx As String  ' Node x Control Register
  Dim sNIPRx As String ' Node x Interrupt Pointer Register
  Dim sNPCRx As String ' Node x Port Control Register

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  sNCRx = sRegPre & "NCR" & iNr
  sNIPRx = sRegPre & "NIPR" & iNr
  sNPCRx = sRegPre & "NPCR" & iNr

    'Checking NodeX SRNs
	For i = 0 To (r.v("CAN_MAX_NODES") - 1)
      If ((r.v(sRegPre & "NCR" & i & "_TRIE") = 1) And (i <> iNr)) Then 'Check Nodex Transfer interrupt Enble
        If (r.v(sRegPre & "NIPR" & i & "_TRINP") = r.v(sNIPRx & "_TRINP")) Then
            GetNodeXIntrStatus = True
            Exit For
        End If
      End If
    Next i
    'Checking ObjX SRNs
    For j = 0 To (r.v("CAN_MAX_OBJECTS") - 1)
      If (r.v(sRegPre & "MOFCR" & j & "H_TXIE") = 1) Then             'Check Objx Transfer intterrupt Enble
        If (r.v(sRegPre & "MOIPR" & j & "L_TXINP") = r.v(sNIPRx & "_TRINP")) Then
            GetNodeXIntrStatus = True
            Exit For
        End If
      End If
    Next j
End Function

'*****************************************************************************
'Description:
'        This function is used to check the status of the SRN's allocation in 
'       Nodes and Objs(rest of the current Obj)
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        iNr             number of the message object
'-----------------------------------------------------------------------------
'Returns:  True if current SRN is occupied by any one of the Node or Obj
'          false if Current SRN is Free
'*****************************************************************************

Function GetObjXIntrStatus(r As ProjectData, vIndex As Variant, iNr As Integer) As Boolean
        On Error Resume Next

  GetObjXIntrStatus = False

  Dim c As Object
  Dim e As Object
  Dim i As Integer
  Dim j As Integer
  Dim sVarPre As String
  Dim sRegPre As String

  Dim sNCRx As String  ' Node x Control Register
  Dim sNIPRx As String ' Node x Interrupt Pointer Register
  Dim sNPCRx As String ' Node x Port Control Register

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  sNCRx = sRegPre & "NCR" & iNr
  sNIPRx = sRegPre & "NIPR" & iNr
  sNPCRx = sRegPre & "NPCR" & iNr
    'Checking ObjX SRNs
    For i = 0 To (r.v("CAN_MAX_NODES") - 1)
      If ((r.v(sRegPre & "NCR" & i & "_TRIE") = 1)) Then                   'Check Nodex Transfer interrupt Enble
        If (r.v(sRegPre & "NIPR" & i & "_TRINP") = r.v(sRegPre & "MOIPR" & iNr & "L_TXINP")) Then
            GetObjXIntrStatus = True
            Exit For
        End If
      End If
    Next i
    'Checking NodeX SRNs
    For j = 0 To (r.v("CAN_MAX_OBJECTS") - 1)
      If ((r.v(sRegPre & "MOFCR" & j & "H_TXIE") = 1) And (j <> iNr)) Then 'Check Objx Transfer interrupt Enble
        If (r.v(sRegPre & "MOIPR" & j & "L_TXINP") = r.v(sRegPre & "MOIPR" & iNr & "L_TXINP")) Then
            GetObjXIntrStatus = True
            Exit For
        End If
      End If
    Next j
End Function

'*****************************************************************************
'Description:
'        This function is used to check the status of the SRN's allocation in 
'       Nodes(rest of the current Node) and Objs
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          ParameterValue
'        sIntrName       name of the interrupt
'-----------------------------------------------------------------------------
'Returns:  True if current SRN is occupied by any one of the Node or Obj
'          false if Current SRN is Free
'*****************************************************************************
Function IsSRNUsed(r As ProjectData, vIndex As Variant, sIntrNr As Integer) As Boolean
  On Error Resume Next

  IsSRNUsed = False

  Dim i As Integer
  Dim j As Integer
'  Dim sIntrNr As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

'  sIntrNr = Mid(sIntrName, 14,2)

	For i = 0 To (r.v("CAN_MAX_NODES") - 1)
      'Nodex transfer interrupt
	  If ((r.v(sRegPre & "NCR" & i & "_TRIE") = 1) And (r.v(sRegPre & "NIPR" & i & "_TRINP") = sIntrNr)) Then
        IsSRNUsed = True
        Exit For
      End If
      'Nodex last-error code interrupt
      If ((r.v(sRegPre & "NCR" & i & "_LECIE") = 1) And (r.v(sRegPre & "NIPR" & i & "_LECINP") = sIntrNr)) Then
        IsSRNUsed = True
        Exit For
      End If
      'Nodex alert interrupt
      If ((r.v(sRegPre & "NCR" & i & "_ALIE") = 1) And (r.v(sRegPre & "NIPR" & i & "_ALINP") = sIntrNr)) Then
        IsSRNUsed = True
        Exit For
      End If
      'Nodex frame counter overflow interrupt
      If ((r.v(sRegPre & "NFCR" & i & "H_CFCIE") = 1) And (r.v(sRegPre & "NIPR" & i & "_CFCINP") = sIntrNr)) Then
        IsSRNUsed = True
        Exit For
      End If
    Next i
    
    For j = 0 To (r.v("CAN_MAX_OBJECTS") - 1)
      'MOx transmit interrupt
      If ((r.v(sRegPre & "MOFCR" & j & "H_TXIE") = 1) And (r.v(sRegPre & "MOIPR" & j & "L_TXINP") = sIntrNr)) Then
        IsSRNUsed = True
        Exit For
      End If
      'MOx receive interrupt
      If ((r.v(sRegPre & "MOFCR" & j & "H_RXIE") = 1) And (r.v(sRegPre & "MOIPR" & j & "L_RXINP") = sIntrNr)) Then
        IsSRNUsed = True
        Exit For
      End If
      'MOx FIFO overflow interrupt
      If (r.v(sRegPre & "MOCTR" & j & "L_DIR") = 1) Then 'transmit direction
        If ((r.v(sRegPre & "MOFCR" & j & "H_OVIE") = 1) And (r.v(sRegPre & "MOIPR" & j & "L_RXINP") = sIntrNr)) Then
          IsSRNUsed = True
          Exit For
        End If

      Else                                                 'receive direction
        If ((r.v(sRegPre & "MOFCR" & j & "H_OVIE") = 1) And (r.v(sRegPre & "MOIPR" & j & "L_TXINP") = sIntrNr)) Then
          IsSRNUsed = True
          Exit For
        End If
      End If
    Next j

End Function

'*******************************************************************************
'Description:
'        This function is used to reads the signal name of the selected receive
'     pin
'-------------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'        ListIndex   Index of the receive pin selection
'-------------------------------------------------------------------------------
'Returns: Receive Pin Name
'*******************************************************************************

Function GetCANRxSgnlName(r As ProjectData, vIndex As Variant, iNr As Integer, ListIndex As Integer) As String
        On Error Resume Next

GetCANRxSgnlName = ""

  If (iNr = 0) Then
    If (ListIndex = 1) Then
        GetCANRxSgnlName = "CAN_RXDC0C"
    ElseIf (ListIndex = 2) Then
        GetCANRxSgnlName = "CAN_RXDC0D"
    End If
  ElseIf (iNr = 1) Then
    If (ListIndex = 1) Then
        GetCANRxSgnlName = "CAN_RXDC1A"
    ElseIf (ListIndex = 2) Then
        GetCANRxSgnlName = "CAN_RXDC1C"
    End If
  End If

End Function

'********************************************************************************
'Description:
'        This function is used to reads the signal name of the selected transmit
'     pin
'--------------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'        ListIndex   Index of the transmit pin selection
'--------------------------------------------------------------------------------
'Returns: Transmit Pin Name
'********************************************************************************

Function GetCANTxSgnlName(r As ProjectData, vIndex As Variant, iNr As Integer, ListIndex As Integer) As String
    On Error Resume Next

GetCANTxSgnlName = ""

  If (iNr = 0) Then
    If (ListIndex = 1) Then
        GetCANTxSgnlName = "CAN_TXDC0C"
    ElseIf (ListIndex = 2) Then
        GetCANTxSgnlName = "CAN_TXDC0E"
    End If
  ElseIf (iNr = 1) Then
    If (ListIndex = 1) Then
        GetCANTxSgnlName = "CAN_TXDC1B"
    ElseIf (ListIndex = 2) Then
        GetCANTxSgnlName = "CAN_TXDC1C"
    End If
  End If

End Function

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub ReleaseAllNodexPins(r As ProjectData, vIndex As Variant, iNr As Integer)
  On Error Resume Next

'Dim sPinName As String
'
'  sPinName = GetCANRxSgnlName(r, vIndex, iNr, r.v("CAN_USE_NODE" & iNr & "_RXD_PIN"))
'  If (sPinName <> "") Then
'    Call ReleaseAlternateInputPin(r, sPinName)
'  End If
'  
'  sPinName = GetCANTxSgnlName(r, vIndex, iNr, r.v("CAN_USE_NODE" & iNr & "_TXD_PIN"))
'  If (sPinName <> "") Then
'    Call ReleaseAlternateOutputPin(r, sPinName)
'  End If

  Dim sPinName As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

'  sPinName = Mid(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN"),9, 6) 'releasing RxD-Pins
'  If(r.v("CAN_USE_NODE" & iNr & "_RXD_PIN") <> RXDPIN_DEF_MSG(iNr)) Then
'    Call ReleaseAlternateInputPin(r, sRegPre & sPinName)
'  End If
  Call ReleaseRxDPin(r, vIndex, iNr, r.v("CAN_USE_NODE" & iNr & "_RXD_PIN"))
  Call ReleaseERU(r, vIndex, iNr)
'  sPinName = Mid(r.v("CAN_USE_NODE" & iNr & "_TXD_PIN"),9, 6)  'releasing TxD-Pins
'  If(r.v("CAN_USE_NODE" & iNr & "_TXD_PIN") <> TXDPIN_DEF_MSG(iNr)) Then
'    Call ReleaseAlternateOutputPin(r, sRegPre & sPinName)
'  End If
  Call ReleaseTxDPin(r, vIndex, iNr, r.v("CAN_USE_NODE" & iNr & "_TXD_PIN"))


End Sub


'*****************************************************************************
'Description:
'        This functions convert 32-bit Data to 16-Bit Data.
'-----------------------------------------------------------------------------
Public Function Format16BitStatement(v As Variant, iNr As Integer) As Variant
    On Error GoTo Format16BitStatementError
    Dim tVal As String               ' used as index for loops
 '   Dim val As String
tVal = FormatTextOutput(v, "H8")
'val = Mid(tVal, 4, Len(tVal))
        Format16BitStatement = Mid(tVal, iNr, 4)
  Exit Function
Format16BitStatementError:
  Format16BitStatement = ""
End Function


'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Function GetIndexAddRxDPin(r As ProjectData, vIndex As Variant, iNr As Integer, cboName As Variant) As Integer
  On Error Resume Next

  Dim ListCount As Integer
  Dim sPreCPUType As String

  sPreCPUType = Mid(r.v("MAIN_CPU_TYPE"),1, 6)
  
' show condition
  cboName.Clear
  cboName.AddItem "Pin RXDC" & iNr & " is not Used"

  Select Case (sPreCPUType)

    Case ("XC2287")     'XC22xx series family

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case (2)
          If(IsAlternateInputPinFree(r, "CAN_RXDC2A")) Then
            cboName.AddItem "Use Pin RXDC2A(P4.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC2B")) Then
            cboName.AddItem "Use Pin RXDC2B(P10.11) as Input"
          End If

	    Case (3)
          If(IsAlternateInputPinFree(r, "CAN_RXDC3A")) Then
            cboName.AddItem "Use Pin RXDC3A(P3.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3B")) Then
            cboName.AddItem "Use Pin RXDC3B(P3.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3C")) Then
            cboName.AddItem "Use Pin RXDC3C(P10.14) as Input"
          End If

	    Case (4)
          If(IsAlternateInputPinFree(r, "CAN_RXDC4A")) Then
            cboName.AddItem "Use Pin RXDC4A(P3.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4B")) Then
            cboName.AddItem "Use Pin RXDC4B(P7.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4C")) Then
            cboName.AddItem "Use Pin RXDC4C(P10.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XC2287

    Case ("XC2267")

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case (2)
          If(IsAlternateInputPinFree(r, "CAN_RXDC2A")) Then
            cboName.AddItem "Use Pin RXDC2A(P4.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC2B")) Then
            cboName.AddItem "Use Pin RXDC2B(P10.11) as Input"
          End If

	    Case (3)
'          If(IsAlternateInputPinFree(r, "CAN_RXDC3A")) Then
'            cboName.AddItem "Use Pin RXDC3A(P3.3) as Input"
'          End If
'          If(IsAlternateInputPinFree(r, "CAN_RXDC3B")) Then
'            cboName.AddItem "Use Pin RXDC3B(P3.0) as Input"
'          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3C")) Then
            cboName.AddItem "Use Pin RXDC3C(P10.14) as Input"
          End If

	    Case (4)
'          If(IsAlternateInputPinFree(r, "CAN_RXDC4A")) Then
'            cboName.AddItem "Use Pin RXDC4A(P3.4) as Input"
'          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4B")) Then
            cboName.AddItem "Use Pin RXDC4B(P7.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4C")) Then
            cboName.AddItem "Use Pin RXDC4C(P10.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XC2267

    Case ("XE167F")     'XE16xx series family

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case (2)
          If(IsAlternateInputPinFree(r, "CAN_RXDC2A")) Then
            cboName.AddItem "Use Pin RXDC2A(P4.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC2B")) Then
            cboName.AddItem "Use Pin RXDC2B(P10.11) as Input"
          End If

	    Case (3)
          If(IsAlternateInputPinFree(r, "CAN_RXDC3A")) Then
            cboName.AddItem "Use Pin RXDC3A(P3.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3B")) Then
            cboName.AddItem "Use Pin RXDC3B(P3.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3C")) Then
            cboName.AddItem "Use Pin RXDC3C(P10.14) as Input"
          End If

	    Case (4)
          If(IsAlternateInputPinFree(r, "CAN_RXDC4A")) Then
            cboName.AddItem "Use Pin RXDC4A(P3.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4B")) Then
            cboName.AddItem "Use Pin RXDC4B(P7.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4C")) Then
            cboName.AddItem "Use Pin RXDC4C(P10.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XE167F

    Case ("XE167G")     '144-Pin Package

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XE167G

    Case ("XE164F")

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case (2)
          If(IsAlternateInputPinFree(r, "CAN_RXDC2A")) Then
            cboName.AddItem "Use Pin RXDC2A(P4.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC2B")) Then
            cboName.AddItem "Use Pin RXDC2B(P10.11) as Input"
          End If

	    Case (3)
'          If(IsAlternateInputPinFree(r, "CAN_RXDC3A")) Then
'            cboName.AddItem "Use Pin RXDC3A(P3.3) as Input"
'          End If
'          If(IsAlternateInputPinFree(r, "CAN_RXDC3B")) Then
'            cboName.AddItem "Use Pin RXDC3B(P3.0) as Input"
'          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3C")) Then
            cboName.AddItem "Use Pin RXDC3C(P10.14) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XE164F

    Case ("XE164G")     '100-Pin Package

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XE164G

    Case ("XC2387")     'XC23xx series family

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case (2)
          If(IsAlternateInputPinFree(r, "CAN_RXDC2A")) Then
            cboName.AddItem "Use Pin RXDC2A(P4.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC2B")) Then
            cboName.AddItem "Use Pin RXDC2B(P10.11) as Input"
          End If

	    Case (3)
          If(IsAlternateInputPinFree(r, "CAN_RXDC3A")) Then
            cboName.AddItem "Use Pin RXDC3A(P3.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3B")) Then
            cboName.AddItem "Use Pin RXDC3B(P3.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3C")) Then
            cboName.AddItem "Use Pin RXDC3C(P10.14) as Input"
          End If

	    Case (4)
          If(IsAlternateInputPinFree(r, "CAN_RXDC4A")) Then
            cboName.AddItem "Use Pin RXDC4A(P3.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4B")) Then
            cboName.AddItem "Use Pin RXDC4B(P7.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4C")) Then
            cboName.AddItem "Use Pin RXDC4C(P10.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XC2387

    Case ("XC2365")

      Select Case (iNr)
        Case (0)
          If(IsAlternateInputPinFree(r, "CAN_RXDC0A")) Then
		    cboName.AddItem "Use Pin RXDC0A(P2.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0B")) Then
            cboName.AddItem "Use Pin RXDC0B(P0.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0C")) Then
            cboName.AddItem "Use Pin RXDC0C(P2.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC0D")) Then
            cboName.AddItem "Use Pin RXDC0D(P2.6) as Input"
          End If

	    Case (1)
          If(IsAlternateInputPinFree(r, "CAN_RXDC1A")) Then
            cboName.AddItem "Use Pin RXDC1A(P2.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1B")) Then
            cboName.AddItem "Use Pin RXDC1B(P0.4) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC1C")) Then
            cboName.AddItem "Use Pin RXDC1C(P2.7) as Input"
          End If

	    Case (2)
          If(IsAlternateInputPinFree(r, "CAN_RXDC2A")) Then
            cboName.AddItem "Use Pin RXDC2A(P4.3) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC2B")) Then
            cboName.AddItem "Use Pin RXDC2B(P10.11) as Input"
          End If

	    Case (3)
'          If(IsAlternateInputPinFree(r, "CAN_RXDC3A")) Then
'            cboName.AddItem "Use Pin RXDC3A(P3.3) as Input"
'          End If
'          If(IsAlternateInputPinFree(r, "CAN_RXDC3B")) Then
'            cboName.AddItem "Use Pin RXDC3B(P3.0) as Input"
'          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC3C")) Then
            cboName.AddItem "Use Pin RXDC3C(P10.14) as Input"
          End If

	    Case (4)
'          If(IsAlternateInputPinFree(r, "CAN_RXDC4A")) Then
'            cboName.AddItem "Use Pin RXDC4A(P3.4) as Input"
'          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4B")) Then
            cboName.AddItem "Use Pin RXDC4B(P7.0) as Input"
          End If
          If(IsAlternateInputPinFree(r, "CAN_RXDC4C")) Then
            cboName.AddItem "Use Pin RXDC4C(P10.7) as Input"
          End If

	    Case Else

      End Select  'End of Inner Select XC2365

    Case Else  'No MCAN module is available for remaining derivatives

  End Select  'End of Outer Select CPU_TYPE

  For ListCount = 0 To cboName.ListCount-1
    If(cboName.List(ListCount) = r.v("CAN_USE_NODE" & iNr & "_RXD_PIN")) Then
      GetIndexAddRxDPin = ListCount
    End If
  Next ListCount
 
    If ((cboName.ListCount) = 1) Then
'      cboName.RemoveItem 0
'      cboName.AddItem "Pin RXDC" & iNr & " is not available"
      cboName.Enabled = False
    End If

End Function

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Function GetIndexAddTxDPin(r As ProjectData, vIndex As Variant, iNr As Integer, cboName As Variant) As Integer
  On Error Resume Next

  Dim ListCount As Integer
  Dim sPreCPUType As String

  sPreCPUType = Mid(r.v("MAIN_CPU_TYPE"),1, 6)

' show condition
  cboName.Clear
  cboName.AddItem "Pin TXDC" & iNr & " is not Used"

  Select Case (sPreCPUType)

    Case ("XC2287")     'XC22xx series family

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

     	Case (2)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2A")) Then
            cboName.AddItem "Use Pin TXDC2A(P4.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2B")) Then
            cboName.AddItem "Use Pin TXDC2B(P4.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2C")) Then
            cboName.AddItem "Use Pin TXDC2C(P10.12) as Output"
          End If

	    Case (3)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3A")) Then
            cboName.AddItem "Use Pin TXDC3A(P3.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3B")) Then
            cboName.AddItem "Use Pin TXDC3B(P3.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3C")) Then
            cboName.AddItem "Use Pin TXDC3C(P10.13) as Output"
          End If

    	Case (4)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4A")) Then
            cboName.AddItem "Use Pin TXDC4A(P3.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4B")) Then
            cboName.AddItem "Use Pin TXDC4B(P7.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4C")) Then
            cboName.AddItem "Use Pin TXDC4C(P7.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4D")) Then
            cboName.AddItem "Use Pin TXDC4D(P10.6) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XC2287

    Case ("XC2267")

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

     	Case (2)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2A")) Then
            cboName.AddItem "Use Pin TXDC2A(P4.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2B")) Then
            cboName.AddItem "Use Pin TXDC2B(P4.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2C")) Then
            cboName.AddItem "Use Pin TXDC2C(P10.12) as Output"
          End If

	    Case (3)
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC3A")) Then
'            cboName.AddItem "Use Pin TXDC3A(P3.1) as Output"
'          End If
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC3B")) Then
'            cboName.AddItem "Use Pin TXDC3B(P3.2) as Output"
'          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3C")) Then
            cboName.AddItem "Use Pin TXDC3C(P10.13) as Output"
          End If

    	Case (4)
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC4A")) Then
'            cboName.AddItem "Use Pin TXDC4A(P3.6) as Output"
'          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4B")) Then
            cboName.AddItem "Use Pin TXDC4B(P7.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4C")) Then
            cboName.AddItem "Use Pin TXDC4C(P7.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4D")) Then
            cboName.AddItem "Use Pin TXDC4D(P10.6) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XC2267

    Case ("XE167F")     'XE16xx series family

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

     	Case (2)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2A")) Then
            cboName.AddItem "Use Pin TXDC2A(P4.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2B")) Then
            cboName.AddItem "Use Pin TXDC2B(P4.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2C")) Then
            cboName.AddItem "Use Pin TXDC2C(P10.12) as Output"
          End If

	    Case (3)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3A")) Then
            cboName.AddItem "Use Pin TXDC3A(P3.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3B")) Then
            cboName.AddItem "Use Pin TXDC3B(P3.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3C")) Then
            cboName.AddItem "Use Pin TXDC3C(P10.13) as Output"
          End If

    	Case (4)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4A")) Then
            cboName.AddItem "Use Pin TXDC4A(P3.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4B")) Then
            cboName.AddItem "Use Pin TXDC4B(P7.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4C")) Then
            cboName.AddItem "Use Pin TXDC4C(P7.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4D")) Then
            cboName.AddItem "Use Pin TXDC4D(P10.6) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XE167F

    Case ("XE167G")     '144-Pin Package

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XE167G

    Case ("XE164F")     '100-Pin Package

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

     	Case (2)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2A")) Then
            cboName.AddItem "Use Pin TXDC2A(P4.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2B")) Then
            cboName.AddItem "Use Pin TXDC2B(P4.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2C")) Then
            cboName.AddItem "Use Pin TXDC2C(P10.12) as Output"
          End If

	    Case (3)
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC3A")) Then
'            cboName.AddItem "Use Pin TXDC3A(P3.1) as Output"
'          End If
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC3B")) Then
'            cboName.AddItem "Use Pin TXDC3B(P3.2) as Output"
'          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3C")) Then
            cboName.AddItem "Use Pin TXDC3C(P10.13) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XE164F

    Case ("XE164G")     '100-Pin Package

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XE167G

    Case ("XC2387")     'XC23xx series family

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

     	Case (2)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2A")) Then
            cboName.AddItem "Use Pin TXDC2A(P4.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2B")) Then
            cboName.AddItem "Use Pin TXDC2B(P4.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2C")) Then
            cboName.AddItem "Use Pin TXDC2C(P10.12) as Output"
          End If

	    Case (3)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3A")) Then
            cboName.AddItem "Use Pin TXDC3A(P3.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3B")) Then
            cboName.AddItem "Use Pin TXDC3B(P3.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3C")) Then
            cboName.AddItem "Use Pin TXDC3C(P10.13) as Output"
          End If

    	Case (4)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4A")) Then
            cboName.AddItem "Use Pin TXDC4A(P3.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4B")) Then
            cboName.AddItem "Use Pin TXDC4B(P7.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4C")) Then
            cboName.AddItem "Use Pin TXDC4C(P7.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4D")) Then
            cboName.AddItem "Use Pin TXDC4D(P10.6) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XC2387

    Case ("XC2365")

      Select Case (iNr)
        Case (0)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0A")) Then
            cboName.AddItem "Use Pin TXDC0A(P0.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0B")) Then
            cboName.AddItem "Use Pin TXDC0B(P0.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0C")) Then
            cboName.AddItem "Use Pin TXDC0C(P2.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0D")) Then
            cboName.AddItem "Use Pin TXDC0D(P2.4) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC0E")) Then
            cboName.AddItem "Use Pin TXDC0E(P2.5) as Output"
          End If

	    Case (1)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1A")) Then
            cboName.AddItem "Use Pin TXDC1A(P0.6) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1B")) Then
            cboName.AddItem "Use Pin TXDC1B(P2.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC1C")) Then
            cboName.AddItem "Use Pin TXDC1C(P2.9) as Output"
          End If

     	Case (2)
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2A")) Then
            cboName.AddItem "Use Pin TXDC2A(P4.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2B")) Then
            cboName.AddItem "Use Pin TXDC2B(P4.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC2C")) Then
            cboName.AddItem "Use Pin TXDC2C(P10.12) as Output"
          End If

	    Case (3)
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC3A")) Then
'            cboName.AddItem "Use Pin TXDC3A(P3.1) as Output"
'          End If
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC3B")) Then
'            cboName.AddItem "Use Pin TXDC3B(P3.2) as Output"
'          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC3C")) Then
            cboName.AddItem "Use Pin TXDC3C(P10.13) as Output"
          End If

    	Case (4)
'          If(IsAlternateOutputPinFree(r, "CAN_TXDC4A")) Then
'            cboName.AddItem "Use Pin TXDC4A(P3.6) as Output"
'          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4B")) Then
            cboName.AddItem "Use Pin TXDC4B(P7.1) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4C")) Then
            cboName.AddItem "Use Pin TXDC4C(P7.2) as Output"
          End If
          If(IsAlternateOutputPinFree(r, "CAN_TXDC4D")) Then
            cboName.AddItem "Use Pin TXDC4D(P10.6) as Output"
          End If

	    Case Else

      End Select  'End of Inner Select XC2365

    Case Else  'No MCAN module is available for remaining derivatives

  End Select  'End of Outer Select CPU_TYPE

  For ListCount = 0 To cboName.ListCount-1
    If(cboName.List(ListCount) = r.v("CAN_USE_NODE" & iNr & "_TXD_PIN")) Then
      GetIndexAddTxDPin = ListCount
    End If
  Next ListCount

    If ((cboName.ListCount) = 1) Then
'      cboName.RemoveItem 0
'      cboName.AddItem "Pin TXDC" & iNr & " is not available"
      cboName.Enabled = False
    End If

End Function

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************

Sub RequestRxDPin(r As ProjectData, vIndex As Variant, iNr As Integer, sPinNo As String)
  On Error Resume Next

  Dim SgnlName As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  SgnlName = Mid(sPinNo,9, 6)

    If (SgnlName = "RXDC" & iNr & "A") Then
      Call RequestAlternateInputPin(r, "CAN_RXDC" & iNr & "A")
      r.v(sRegPre & "NPCR" & iNr & "_RXSEL") = 0
    ElseIf (SgnlName = "RXDC" & iNr & "B") Then
      Call RequestAlternateInputPin(r, "CAN_RXDC" & iNr & "B")
      r.v(sRegPre & "NPCR" & iNr & "_RXSEL") = 1
	ElseIf (SgnlName = "RXDC" & iNr & "C") Then
      Call RequestAlternateInputPin(r, "CAN_RXDC" & iNr & "C")
      r.v(sRegPre & "NPCR" & iNr & "_RXSEL") = 2
    ElseIf (SgnlName = "RXDC" & iNr & "D") Then
      Call RequestAlternateInputPin(r, "CAN_RXDC" & iNr & "D")
       r.v(sRegPre & "NPCR" & iNr & "_RXSEL") = 3
    ElseIf (SgnlName = "RXDC" & iNr & "E") Then
      Call RequestAlternateInputPin(r, "CAN_RXDC" & iNr & "E")
      r.v(sRegPre & "NPCR" & iNr & "_RXSEL") = 4
    End If

End Sub

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************

Sub RequestTxDPin(r As ProjectData, vIndex As Variant, iNr As Integer, sPinNo As String)
  On Error Resume Next

  Dim SgnlName As String

  SgnlName = Mid(sPinNo,9, 6)

    If (SgnlName = "TXDC" & iNr & "A") Then
      Call RequestAlternateOutputPin(r, "CAN_TXDC" & iNr & "A")
    ElseIf (SgnlName = "TXDC" & iNr & "B") Then
      Call RequestAlternateOutputPin(r, "CAN_TXDC" & iNr & "B")
    ElseIf (SgnlName = "TXDC" & iNr & "C") Then
      Call RequestAlternateOutputPin(r, "CAN_TXDC" & iNr & "C")
    ElseIf (SgnlName = "TXDC" & iNr & "D") Then
      Call RequestAlternateOutputPin(r, "CAN_TXDC" & iNr & "D")
    ElseIf (SgnlName = "TXDC" & iNr & "E") Then
      Call RequestAlternateOutputPin(r, "CAN_TXDC" & iNr & "E")
    End If

End Sub

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************

Sub ReleaseRxDPin(r As ProjectData, vIndex As Variant, iNr As Integer, sPinNo As String)
  On Error Resume Next
  Dim SgnlName As String
  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"


  SgnlName = Mid(sPinNo,9, 6)

    If (SgnlName = "RXDC" & iNr & "A") Then
      Call ReleaseAlternateInputPin(r, "CAN_RXDC" & iNr & "A")
    ElseIf (SgnlName = "RXDC" & iNr & "B") Then
      Call ReleaseAlternateInputPin(r, "CAN_RXDC" & iNr & "B")
    ElseIf (SgnlName = "RXDC" & iNr & "C") Then
      Call ReleaseAlternateInputPin(r, "CAN_RXDC" & iNr & "C")
    ElseIf (SgnlName = "RXDC" & iNr & "D") Then
      Call ReleaseAlternateInputPin(r, "CAN_RXDC" & iNr & "D")
    ElseIf (SgnlName = "RXDC" & iNr & "E") Then
      Call ReleaseAlternateInputPin(r, "CAN_RXDC" & iNr & "E")
    End If

    r.v(sRegPre & "NPCR" & iNr & "_RXSEL") = 0
End Sub

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************

Sub ReleaseTxDPin(r As ProjectData, vIndex As Variant, iNr As Integer, sPinNo As String)
  On Error Resume Next
  Dim SgnlName As String

  SgnlName = Mid(sPinNo,9, 6)

    If (SgnlName = "TXDC" & iNr & "A") Then
      Call ReleaseAlternateOutputPin(r, "CAN_TXDC" & iNr & "A")
    ElseIf (SgnlName = "TXDC" & iNr & "B") Then
      Call ReleaseAlternateOutputPin(r, "CAN_TXDC" & iNr & "B")
    ElseIf (SgnlName = "TXDC" & iNr & "C") Then
      Call ReleaseAlternateOutputPin(r, "CAN_TXDC" & iNr & "C")
    ElseIf (SgnlName = "TXDC" & iNr & "D") Then
      Call ReleaseAlternateOutputPin(r, "CAN_TXDC" & iNr & "D")
    ElseIf (SgnlName = "TXDC" & iNr & "E") Then
      Call ReleaseAlternateOutputPin(r, "CAN_TXDC" & iNr & "E")
    End If

End Sub

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
'
'Public Function CAN_MAX_NODES(r as ProjectData) As Integer
'
'    CAN_MAX_NODES = r.v("CAN_UserDef0")
'
'End Function

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
'
'Public Function CAN_MAX_OBJECTS(r as ProjectData) As Integer
'
'    CAN_MAX_OBJECTS = r.v("CAN_UserDef1")
'
'End Function

'*****************************************************************************
'Description:
'        This function sets all necessary registers to release all NodexPins from
'        an alternate function which was requested with the function
'        'RequestAlternatePin'.
'-----------------------------------------------------------------------------
'Parameters:
'        r           reference to this object
'        iNr         number of the Node
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************

Sub SetDefaultSettings(r as ProjectData, vIndex As Variant)
  On Error Resume Next


  Select Case (r.v("MAIN_CPU_TYPE"))

    Case ("XC2287-96F80")     'XC22xx series family
      r.v("CAN_MAX_NODES") = 5        'used for no.of nodes
      r.v("CAN_MAX_OBJECTS") = 128    'used for no.of MOs

    Case ("XC2287-96F66")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XC2267-96F80")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XC2267-96F66")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128


    Case ("XE167F-96F80")     'XE16xx series Family
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XE167F-96F66")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XE167G-96F80")
      r.v("CAN_MAX_NODES") = 2
      r.v("CAN_MAX_OBJECTS") = 32

    Case ("XE167G-96F66")
      r.v("CAN_MAX_NODES") = 2
      r.v("CAN_MAX_OBJECTS") = 32

    Case ("XE167H-96F80")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE167H-96F66")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE167K-96F80")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE167K-96F66")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE164F-96F80")
      r.v("CAN_MAX_NODES") = 4
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XE164F-96F66")
      r.v("CAN_MAX_NODES") = 4
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XE164G-96F80")
      r.v("CAN_MAX_NODES") = 2
      r.v("CAN_MAX_OBJECTS") = 32

    Case ("XE164G-96F66")
      r.v("CAN_MAX_NODES") = 2
      r.v("CAN_MAX_OBJECTS") = 32

    Case ("XE164H-96F80")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE164H-96F66")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE164K-96F80")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XE164K-96F66")
      r.v("CAN_MAX_NODES") = 0
      r.v("CAN_MAX_OBJECTS") = 0

    Case ("XC2387-96F80")     'XC23xx series family
      r.v("CAN_MAX_NODES") = 5        'used for no.of nodes
      r.v("CAN_MAX_OBJECTS") = 128    'used for no.of MOs

    Case ("XC2387-96F66")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XC2365-96F80")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128

    Case ("XC2365-96F66")
      r.v("CAN_MAX_NODES") = 5
      r.v("CAN_MAX_OBJECTS") = 128


    Case Else

  End Select

End Sub


