Attribute VB_Name = "Module1"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\InterruptClass.cls"
'#Uses "Include.inc"
'#Uses "..\include\Port.inc"
'#Uses "..\classes\LinSchedule.cls"
'#Uses "..\classes\LinFrame.cls"
'#Uses "..\classes\LinSignal.cls"
'#Uses "..\classes\LinNode.cls"

Option Explicit


'*****************************************************************************
' Module:
'        LIN
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'LIN'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev.    Author       Date           Description
'        ---------------------------------------------------------------------
'        1.0     Raja         30.05.2005     LIN for Pegasus lite XC164CM
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This functions initiates the code generation for the LIN module.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function StartGenerateCode(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo StartGenerateCodeError
    StartGenerateCode = False
   
    Dim i           As Integer
    Dim sLDFpath    As String
    Dim sVarPre     As String
    Dim cNode       As DAvECollection
    Dim uNode       As New LinNode
    Dim bListsExist As Boolean
    
    sVarPre = "LIN" & vIndex
    
    bListsExist = (r.v("LIN_NodeList_EXIST"))
    If (bListsExist) Then
        Set cNode = ObjectCollection("LinNodes")
    ' write file LIN.ncf
        If (r.v(sVarPre & "_GEN_NCF") = 1) Then
            For i = 1 To cNode.Count
                If (Not LINGenerateNCF(r, vIndex, i)) Then Exit Function
                    If (Not r.AddFile(r.s(sVarPre & "_NCF_FILE"))) Then Exit Function
            Next
        End If
    Else
        'ErrorBox CODE_GEN_ERROR
    End If
    
    If (r.v(sVarPre & "_GEN_LDF") = 2) Then
        If (r.v("LIN_USR_LDF") <> "") Then
            sLDFpath = DefGetPath("Scripts") & "LIN\ldf2c.exe  " & r.v("LIN_USR_LDF")
            Shell (sLDFpath)
        End If
    End If
    
    ' write file LIN.ldf
    If (r.v(sVarPre & "_GEN_LDF") = 1) Then
        If (Not LINGenerateLDF(r, vIndex)) Then Exit Function
            If (Not r.AddFile(r.s(sVarPre & "_LDF_FILE"))) Then Exit Function
    End If

    ' write files LDF.h
    If (r.v(sVarPre & "_GEN_LDF") = 1) Then
      If (Not LDFGenerateH(r, vIndex)) Then Exit Function
                   If (Not r.AddFile(r.s(sVarPre & "_HFILE"))) Then Exit Function
    End If

    ' write file LDF.c
    If (r.v(sVarPre & "_GEN_LDF") = 1) Then
      If (Not LDFGenerateC(r, vIndex)) Then Exit Function
                   If (Not r.AddFile(r.s(sVarPre & "_CFILE"))) Then Exit Function
    End If

    StartGenerateCode = True
     
    Exit Function
    
StartGenerateCodeError:
    errorbox "Code generation for " & sVarPre & " failed", Error$
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the LDF file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function LINGenerateLDF(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo LINGenerateLDFError

    Dim i           As Integer
    Dim j           As Integer
    Dim f           As Variant
    Dim v           As Variant
    Dim d           As String
    Dim slaves      As String
    Dim subscriber  As String
    Dim publisher   As String
    Dim sTempSub    As String
    Dim sTempSignal As String
    Dim sVarPre     As String
    Dim sEvtSPRDFrames  As String
    Dim sDiagsignal As Integer
    Dim sSporadic   As String
    Dim sDynamic    As String
    Dim sInitValue  As String
    Dim stmpSName   As String
    Dim iInitCount  As Integer
    Dim iSpace      As Integer
    Dim iFrameIndex As Integer
    Dim bDiagFlag0  As Boolean
    Dim bDiagFlag1  As Boolean
    Dim bDiagSig0  As Boolean
    Dim bDiagSig1  As Boolean
    
    Dim cNode       As New DAvECollection
    Dim cSignal     As New DAvECollection
    Dim cFrame      As New DAvECollection
    Dim cSchedule   As New DAvECollection
    Dim uNode       As New LinNode
    Dim uSignal     As New LinSignal
    Dim uFrame      As New LinFrame
    Dim uDiagFrame0   As New LinFrame
    Dim uDiagFrame1   As New LinFrame
    Dim uTmpFrame   As New LinFrame
    Dim uSchedule   As New LinSchedule
                    
    sVarPre = "LIN" & vIndex
    
    LINGenerateLDF = False
    
    If ((r.v("LIN_NodeList_EXIST"))) Then
        Set cNode = ObjectCollection("LinNodes")
    End If
    If ((r.v("LIN_SignalList_EXIST"))) Then
        Set cSignal = ObjectCollection("LinSignals")
    End If
    If ((r.v("LIN_FrameList_EXIST"))) Then
        Set cFrame = ObjectCollection("LinFrames")
    End If
    If ((r.v("LIN_ScheduleList_EXIST"))) Then
        Set cSchedule = ObjectCollection("LinSchedules")
    End If

    'open LIN.ldf
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_LDF_FILE") For Output As f
    
    'Header
    '-----------------------------------------------------------------------------------------------------------------------------
    iSpace = 15
    Print #f, FormatText(5, "", "", "/" & String(70, "*"), 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace) & "File:" & r.v(sVarPre & "_LDF_FILE"), 40)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Description:LIN Description file for the defined node cluster", 100)
    Print #f, FormatText(5, "", "", "*" & String(70, "*"), 100)
    Print #f, FormatText(5, "", "", "*/", 10)
    Print #f, ""
    
    Print #f, FormatText(5, "", "", "LIN_description_file;", 40)
    Print #f, FormatText(5, "", "", "LIN_protocol_version = " & INV_COMMA & r.v("LIN_Protocol_Version") & INV_COMMA & ";", 40)
    Print #f, FormatText(5, "", "", "LIN_language_version = " & INV_COMMA & r.v("LIN_Language_Version") & INV_COMMA & ";", 40)
    Print #f, FormatText(5, "", "", "LIN_speed = " & r.v("LIN_Speed") & " kbps;", 40)
    Print #f, ""
    
    Print #f, FormatText(5, "", "", "Nodes {", 20)
    Print #f, FormatText(9, "", "", "Master: " & r.v("LIN_M_Name") & ", " & r.v("LIN_M_TBase") & " ms, " & r.v("LIN_M_Jitter") & " ms;", 60)
    i = 0
    For Each uNode In cNode
        i = i + 1
        If (i <> 1) Then
         slaves = slaves & uNode.Name & ","
        End If
    Next
    If (Len(slaves)) Then
        slaves = Left(slaves, Len(slaves) - 1)
    End If
    Print #f, FormatText(9, "", "", "Slaves: " & slaves & ";", 60)
    Print #f, FormatText(5, "", "", "}", 10)
    Print #f, ""
    
    For Each uFrame In cFrame
        bDiagFlag0 = False
        If (uFrame.ID = 60) Then
            Set uDiagFrame0 = uFrame
            bDiagFlag0 = True
            Exit For
        End If
    Next
    For Each uFrame In cFrame
        bDiagFlag1 = False
        If (uFrame.ID = 61) Then
            Set uDiagFrame1 = uFrame
            bDiagFlag1 = True
            Exit For
        End If
    Next
    
    Print #f, FormatText(5, "", "", "Signals {", 20)
    For Each uSignal In cSignal
        bDiagSig0 = False
        bDiagSig1 = False
        If (bDiagFlag0) Then
            For j = 0 To (uDiagFrame0.Length * 8) - 1
                If (uDiagFrame0.FrmSignals(j) = uSignal.Name) Then
                    bDiagSig0 = True
                    Exit For
                End If
            Next
        End If
        
        If (bDiagFlag1) Then
            For j = 0 To (uDiagFrame1.Length * 8) - 1
                If (uDiagFrame1.FrmSignals(j) = uSignal.Name) Then
                    bDiagSig1 = True
                    Exit For
                End If
            Next
        End If
    

        If (bDiagSig0 Or bDiagSig1) Then
        ' do nothing
        Else
            i = 0
            subscriber = ""
            For Each uNode In cNode
                i = i + 1
                sTempSub = GetSubscriber(i, uSignal.Name, "Signal")
                If (sTempSub <> "") Then
                    subscriber = subscriber & sTempSub & ","
                End If
            Next
            If (Len(subscriber)) Then
                subscriber = Left(subscriber, Len(subscriber) - 1)
            End If
            If (uSignal.SignalType) Then
                iInitCount = uSignal.Size \ 8
                sInitValue = ""
                For i = 0 To iInitCount - 1
                    sInitValue = sInitValue & "," & CStr(uSignal.InitVal(i))
                Next i
                sInitValue = Right(sInitValue, Len(sInitValue) - 1)
                'sInitValue = "{" & sInitValue & "}"
            Else
                sInitValue = CStr(uSignal.InitVal(0))
            End If
            If (subscriber <> "") Then
                Print #f, FormatText(9, "", "", uSignal.Name & ": " & uSignal.Size & "," & _
                                 sInitValue & "," & GetPublisher(r, uSignal.Name, _
                                 "Signal") & "," & subscriber & ";", 100)
            Else
                Print #f, FormatText(9, "", "", uSignal.Name & ": " & uSignal.Size & "," & _
                                 sInitValue & "," & GetPublisher(r, uSignal.Name, _
                                 "Signal") & subscriber & ";", 100)
            End If
                                 
        End If
    Next
    Print #f, FormatText(5, "", "", "}", 10)
    Print #f, ""
    Print #f, FormatText(5, "", "", "Diagnostic_signals {", 30)
    For i = 0 To 7
    Print #f, FormatText(5, "", "", "MasterReqB" & i & ":8,0;", 40)
    Next
    For i = 0 To 7
    Print #f, FormatText(5, "", "", "SlaveRespB" & i & ":8,0;", 40)
    Next
    Print #f, FormatText(5, "", "", "}", 20)
    Print #f, ""
    
    Print #f, FormatText(5, "", "", "dynamic_frames {", 25)
    For Each uFrame In cFrame
        If (uFrame.FrmType = "Dynamic") Then
            sDynamic = sDynamic & "," & uFrame.ID
        End If
    Next
    If (Len(sDynamic)) Then
        sDynamic = Right(sDynamic, Len(sDynamic) - 1)
    End If
    Print #f, FormatText(9, "", "", sDynamic, 20)
    Print #f, FormatText(5, "", "", "}", 20)
    Print #f, ""
    
    Print #f, FormatText(5, "", "", "Frames {", 20)
    For Each uFrame In cFrame
    
        If (uFrame.FrmType = "Unconditional" And uFrame.ID <> 60 And uFrame.ID <> 61) Then
        Print #f, FormatText(9, "", "", uFrame.Name & ":" & uFrame.ID & "," & GetPublisher(r, uFrame.Name, "Frame") & "," & uFrame.Length & "{", 60)
        sTempSignal = ""
        For i = 0 To uFrame.FrmSigcount - 1
            If ((uFrame.FrmSignals(i) <> "") And uFrame.FrmSignals(i) <> sTempSignal) Then
                sTempSignal = uFrame.FrmSignals(i)
                Print #f, FormatText(13, "", "", sTempSignal & "," & i & ";", 80)
            End If
        Next
        Print #f, FormatText(9, "", "", "}", 15)
        End If
    Next
    Print #f, FormatText(5, "", "", "}", 10)
    Print #f, ""

    Print #f, FormatText(5, "", "", "Sporadic_frames {", 20)
    For Each uFrame In cFrame
        If (uFrame.FrmType = "Sporadic") Then
            sEvtSPRDFrames = ""
            If (uFrame.EvtSPRDCount) Then
                For i = 0 To uFrame.EvtSPRDCount - 1
                    For Each uTmpFrame In cFrame
                        If (uFrame.EvtSPRDFrm(i) = uTmpFrame.ID) Then
                            sEvtSPRDFrames = sEvtSPRDFrames & "," & uTmpFrame.Name
                        End If
                    Next
                Next i
                If (Len(sEvtSPRDFrames)) Then
                    sEvtSPRDFrames = Right(sEvtSPRDFrames, Len(sEvtSPRDFrames) - 1)
                End If
            Else
                sEvtSPRDFrames = "0"
            End If
            Print #f, FormatText(9, "", "", "sporadic_frame: " & sEvtSPRDFrames & ";", 20)
        End If
    Next
    Print #f, FormatText(5, "", "", "}", 20)
    Print #f, ""

    Print #f, FormatText(5, "", "", "Event_triggered_frames {", 20)
    For Each uFrame In cFrame
        If (uFrame.FrmType = "Event_Triggered") Then
            sEvtSPRDFrames = ""
            If (uFrame.EvtSPRDCount) Then
                For i = 0 To uFrame.EvtSPRDCount - 1
                    For Each uTmpFrame In cFrame
                        If (uFrame.EvtSPRDFrm(i) = uTmpFrame.ID) Then
                            sEvtSPRDFrames = sEvtSPRDFrames & "," & uTmpFrame.Name
                        End If
                    Next
                Next i
                If (Len(sEvtSPRDFrames)) Then
                    sEvtSPRDFrames = Right(sEvtSPRDFrames, Len(sEvtSPRDFrames) - 1)
                End If
            Else
                sEvtSPRDFrames = "0"
            End If
            Print #f, FormatText(9, "", "", uFrame.Name & ":" & uFrame.ID & "," & sEvtSPRDFrames & ";", 20)
        End If
    Next
    Print #f, FormatText(5, "", "", "}", 20)
    Print #f, ""
    
    Print #f, FormatText(5, "", "", "Diagnostic_frames {", 30)
    Print #f, FormatText(5, "", "", "MasterReq: 60{", 40)
    For i = 0 To 7
    Print #f, FormatText(9, "", "", "MasterReqB" & i & ":8," & i * 8 & ";", 40)
    Next
    Print #f, FormatText(9, "", "", "}", 20)
    
    Print #f, FormatText(5, "", "", "SlaveResp: 61{", 40)
    For i = 0 To 7
    Print #f, FormatText(9, "", "", "SlaveRespB" & i & ":8," & i * 8 & ";", 40)
    Next
    Print #f, FormatText(9, "", "", "}", 20)
    Print #f, FormatText(5, "", "", "}", 10)
    Print #f, ""
    
    Print #f, FormatText(5, "", "", "Node_attributes {", 25)
    For Each uNode In cNode
        If (uNode.Name <> "Master") Then
            Print #f, FormatText(9, "", "", uNode.Name & " {", 25)
            Print #f, FormatText(13, "", "", "LIN_protocol = " & r.v("LIN_Protocol_Version") & ";", 50)
            Print #f, FormatText(13, "", "", "configured_NAD = " & uNode.NAD & ";", 40)
            Print #f, FormatText(13, "", "", "product_id = " & r.v("LIN_supplier_id") & "," _
                                 & r.v("LIN_function_id") & "," & r.v("LIN_variant_id") & ";", 80)
            Print #f, FormatText(13, "", "", "P2_min = " & uNode.p2min & " ms;", 40)
            Print #f, FormatText(13, "", "", "ST_min = " & uNode.stmin & " ms;", 40)
            Print #f, FormatText(13, "", "", "configurable_frames {", 40)
            For Each uFrame In cFrame
                If (uFrame.FrmType = "Unconditional") Then
                For i = 0 To uNode.FPubCount - 1
                    If (uNode.FrmPublisher(i) = uFrame.Name) Then
                        Print #f, FormatText(17, "", "", uFrame.Name & " = " & FormatTextOutput(uFrame.MsgID, "H4") & ";", 40)
                    End If
                Next
                End If
            Next
            Print #f, FormatText(13, "", "", "}", 20)
            Print #f, FormatText(9, "", "", "}", 15)
        End If
    Next
    Print #f, FormatText(5, "", "", "}", 10)
    Print #f, ""
    Print #f, FormatText(5, "", "", "Schedule_tables {", 25)
    For Each uSchedule In cSchedule
        If uSchedule.Count Then
            Print #f, FormatText(9, "", "", uSchedule.Name & " {", 40)
            For i = 0 To (uSchedule.Count - 1)
                If (uSchedule.Frames(i) <> "") Then
                    iFrameIndex = GetFrame(uSchedule.Frames(i))
                    Set uTmpFrame = cFrame.Item(iFrameIndex)
                    Print #f, FormatText(13, "", "", uSchedule.Frames(i) & " delay " & _
                                         CStr(uTmpFrame.MaxPeriod) & " ms;", 50)
                End If
            Next
            Print #f, FormatText(9, "", "", "}", 10)
        End If
    Next
    Print #f, FormatText(5, "", "", "}", 10)
    
    'close file
    Close f
    
    LINGenerateLDF = True
    Exit Function

LINGenerateLDFError:
    Close f
    errorbox "Error-LDF", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the NCF file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function LINGenerateNCF(r As ProjectData, vIndex As Variant, iNodeIndex As Integer) As Boolean
    On Error GoTo LINGenerateNCFError

    Dim l           As Long
    Dim v           As Variant
    Dim f           As Variant
    Dim i           As Integer
    Dim j           As Integer
    Dim k           As Integer
    Dim icount      As Integer
    Dim iInitCount  As Integer
    Dim d           As String
    Dim n           As String
    Dim sVarPre     As String
    Dim sExtn       As String
    Dim sSubscriber As String
    Dim sTempSignal As String
    Dim sInitValue  As String
    Dim iSpace      As Integer
    Dim sSSID       As String
    
    Dim dc      As New DAvECollection
    Dim cFrame  As New DAvECollection
    Dim cNode   As New DAvECollection
    Dim cSignal As New DAvECollection
    Dim uFrame  As New LinFrame
    Dim uNode   As New LinNode
    Dim uSignal As New LinSignal
    
    sVarPre = "LIN" & vIndex

    Set cNode = ObjectCollection("LinNodes")
    If ((r.v("LIN_SignalList_EXIST"))) Then
        Set cSignal = ObjectCollection("LinSignals")
    End If
    If ((r.v("LIN_FrameList_EXIST"))) Then
        Set cFrame = ObjectCollection("LinFrames")
    End If
    
    Set uNode = cNode.Item(iNodeIndex)
    sExtn = ".ncf"
    r.v(sVarPre & "_NCF_FILE") = uNode.Name & sExtn

    'open LIN.ncf
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_NCF_FILE") For Output As f
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    iSpace = 15
    Print #f, FormatText(2, "", "", "/" & String(70, "*"), 100)
    Print #f, FormatText(2, "", "", "*" & Space(iSpace) & "File:" & r.v(sVarPre & "_NCF_FILE"), 40)
    Print #f, FormatText(2, "", "", "*" & Space(iSpace - 7) & "Description:Node Capability File for the node", 100)
    Print #f, FormatText(2, "", "", "*" & String(70, "*"), 100)
    Print #f, FormatText(2, "", "", "*/", 10)
    Print #f, ""
    
    Print #f, FormatText(2, "", "", "node_capability_file;", 40)
    Print #f, FormatText(2, "", "", "LIN_language_version = " & r.v("LIN_language_version") & ";", 40)
    Print #f, ""
    
    Print #f, FormatText(2, "", "", "node " & uNode.Name & " {", 40)
    Print #f, FormatText(4, "", "", "general {", 15)
    Print #f, FormatText(6, "", "", "LIN_protocol_version = " & r.v("LIN_protocol_version") & ";", 35)
    Print #f, FormatText(6, "", "", "supplier = " & r.v("LIN_supplier_id") & ";", 35)
    Print #f, FormatText(6, "", "", "function = " & r.v("LIN_function_id") & ";", 35)
    Print #f, FormatText(6, "", "", "variant = " & r.v("LIN_variant_id") & ";", 35)
    Print #f, FormatText(6, "", "", "bitrate = " & r.v("LIN_speed") & " kbps;", 35)
    Print #f, FormatText(4, "", "", "}", 6)
    Print #f, ""
    
    Print #f, FormatText(4, "", "", "diagnostic {", 16)
    Print #f, FormatText(6, "", "", "NAD = " & uNode.NAD & " ;", 35)
    Print #f, FormatText(6, "", "", "P2_min = " & uNode.p2min & " ms;", 25)
    Print #f, FormatText(6, "", "", "ST_min = " & uNode.stmin & " ms;", 25)
    sSSID = ""
    For i = 0 To 7
        If (uNode.SSID(i) = 1) Then
        sSSID = sSSID & FormatTextOutput(i + 176, "H2") & ","
        End If
    Next i
    If (sSSID <> "") Then
        sSSID = Left(sSSID, Len(sSSID) - 1)
    Else
        sSSID = "0"
    End If
    Print #f, FormatText(6, "", "", "support_sid" & " {" & sSSID & "};", 40)
    Print #f, FormatText(6, "", "", "max_message_length = " & uNode.MaxMsglen & ";", 40)
    Print #f, FormatText(4, "", "", "}", 6)
    Print #f, ""
    
    Print #f, FormatText(4, "", "", "frames {", 15)
    For i = 0 To uNode.FPubCount - 1
        If (uNode.FrmPublisher(i) <> "") Then
            Print #f, FormatText(6, "", "", "publish " & uNode.FrmPublisher(i) & " {", 30)
            For Each uFrame In cFrame
                If (uFrame.Name = uNode.FrmPublisher(i)) Then
                    Print #f, FormatText(8, "", "", "message_ID = " & FormatTextOutput(uFrame.MsgID, "H4") & ";", 35)
                    Print #f, FormatText(8, "", "", "length = " & uFrame.Length & ";", 25)
                    Print #f, FormatText(8, "", "", "min_period = " & uFrame.MinPeriod & " ms;", 30)
                    Print #f, FormatText(8, "", "", "max_period = " & uFrame.MaxPeriod & " ms;", 30)
                    Print #f, FormatText(8, "", "", "signals {", 20)
                    sTempSignal = ""
                    If (uFrame.FrmSigcount) Then
                    For j = 0 To uFrame.FrmSigcount - 1
                        For Each uSignal In cSignal
                            If ((uFrame.FrmSignals(j) = uSignal.Name) And (uFrame.FrmSignals(j) <> sTempSignal)) Then
                                sTempSignal = uSignal.Name
                                If (uSignal.SignalType) Then
                                    iInitCount = uSignal.Size \ 8
                                    sInitValue = ""
                                    For k = 0 To iInitCount - 1
                                        sInitValue = sInitValue & "," & CStr(uSignal.InitVal(k))
                                    Next k
                                    sInitValue = Right(sInitValue, Len(sInitValue) - 1)
                                    sInitValue = "{" & sInitValue & "}"
                                Else
                                    sInitValue = CStr(uSignal.InitVal(0))
                                End If
                                Print #f, FormatText(10, "", "", uSignal.Name & " {" & _
                                "init_value = " & sInitValue & ";" & "size = " & _
                                uSignal.Size & ";" & "offset = " & uSignal.offset & ";}", 100)
                            End If
                        Next
                    Next
                    End If
                    Print #f, FormatText(8, "", "", "}", 10)
                End If
            Next
            Print #f, FormatText(6, "", "", "}", 10)
        End If
    Next i
    For i = 0 To uNode.FSubCount - 1
    
        If (uNode.FrmSubscriber(i) <> "" And uNode.FrmSubscriber(i) <> sSubscriber) Then
            sSubscriber = uNode.FrmSubscriber(i)
            Print #f, FormatText(6, "", "", "subscribe " & sSubscriber & " {", 30)
            For Each uFrame In cFrame
                If (uFrame.Name = uNode.FrmSubscriber(i)) Then
                    Print #f, FormatText(8, "", "", "message_ID = " & FormatTextOutput(uFrame.MsgID, "H4") & ";", 35)
                    Print #f, FormatText(8, "", "", "length = " & uFrame.Length & ";", 25)
                    Print #f, FormatText(8, "", "", "min_period = " & uFrame.MinPeriod & " ms;", 30)
                    Print #f, FormatText(8, "", "", "max_period = " & uFrame.MaxPeriod & " ms;", 30)
                    Print #f, FormatText(8, "", "", "signals {", 20)
                    sTempSignal = ""
                    For j = 0 To uFrame.FrmSigcount - 1
                        For Each uSignal In cSignal
                            If ((uFrame.FrmSignals(j) = uSignal.Name) And (uFrame.FrmSignals(j) <> sTempSignal)) Then
                                sTempSignal = uSignal.Name
                                If (uSignal.SignalType) Then
                                    iInitCount = uSignal.Size \ 8
                                    sInitValue = ""
                                    For k = 0 To iInitCount - 1
                                        sInitValue = sInitValue & "," & CStr(uSignal.InitVal(k))
                                    Next k
                                    sInitValue = Right(sInitValue, Len(sInitValue) - 1)
                                    sInitValue = "{" & sInitValue & "}"
                                Else
                                    sInitValue = CStr(uSignal.InitVal(0))
                                End If
                                Print #f, FormatText(10, "", "", uSignal.Name & " {" & _
                                "init_value = " & sInitValue & ";" & "size = " & _
                                uSignal.Size & ";" & "offset = " & uSignal.offset & ";}", 100)
                            End If
                        Next
                    Next
                    Print #f, FormatText(8, "", "", "}", 10)
                End If
            Next
            Print #f, FormatText(6, "", "", "}", 10)
        End If
    Next i
    Print #f, FormatText(4, "", "", "}", 6)
    Print #f, ""

    Print #f, FormatText(4, "", "", "free_text {", 20)
    Print #f, FormatText(6, "", "", uNode.Remark, 40)
    Print #f, FormatText(4, "", "", "}", 6)
    Print #f, FormatText(2, "", "", "}", 6)
    'close file
    Close f
    
    LINGenerateNCF = True
    Exit Function
    
LINGenerateNCFError:
    errorbox "Error - " & uNode.Name & " " & ".NCF" & vbCrLf & uFrame.Name, Err.Description
    Close f
    Exit Function
End Function
Public Function GetFrame(sFrameName As String) As Integer
Dim uFrame As New LinFrame
Dim cFrame As New DAvECollection
Dim iIndex As Integer

Set cFrame = ObjectCollection("LinFrames")
    
For Each uFrame In cFrame
    iIndex = iIndex + 1
    If (uFrame.Name = sFrameName) Then
         GetFrame = iIndex
        Exit For
    End If
Next

End Function

'*****************************************************************************
'Description:
'        Generates the code for the LIN_LDF.c file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function LDFGenerateC(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo LDFGenerateCError
    
    Dim f         As Variant
    Dim sVarPre   As String
    Dim sRegPre   As String
    Dim l         As Long
    Dim remainder As Long
    Dim i           As Integer
    Dim j           As Integer
    Dim k           As Integer
    Dim iTcount     As Integer
    Dim iValid      As Integer
    Dim iEvtCnt     As Integer
    Dim iSPRDCnt    As Integer
    Dim iSPRDCid    As Integer
    Dim iTempFrmID  As Integer
    Dim v           As Variant
    Dim d           As String
    Dim slaves      As String
    Dim subscriber  As String
    Dim publisher   As String
    Dim sTempSub    As String
    Dim sTempSignal As String
    Dim sEvtSPRDFrames  As String
    Dim sSporadic   As String
    Dim sDynamic    As String
    Dim sInitValue  As String
    Dim sRmndr      As String
    Dim iInitCount  As Integer
    Dim iSpace      As Integer
    Dim iFrameIndex As Integer
    Dim iColflag    As Integer
    Dim iCrntFind   As Integer
    Dim iFDBcount   As Integer
    Dim SchFrmId    As String
    Dim sEvtSPRDFrms    As String
    Dim sSPRDids    As String
    Dim sSPRDflag   As String
    Dim sFrmPub     As String
    Dim sFrmType    As String
    Dim bFrmfound   As Boolean
    Dim bFrmChk   As Boolean
    Dim cNode       As New DAvECollection
    Dim cSignal     As New DAvECollection
    Dim cFrame      As New DAvECollection
    Dim cSchedule   As New DAvECollection
    Dim uNode       As New LinNode
    Dim uSignal     As New LinSignal
    Dim uFrame      As New LinFrame
    Dim uTmpFrame   As New LinFrame
    Dim uSchedule   As New LinSchedule
                    
    sVarPre = "LIN" & vIndex
    LDFGenerateC = False
       
    If ((r.v("LIN_NodeList_EXIST"))) Then
        Set cNode = ObjectCollection("LinNodes")
    End If
    If ((r.v("LIN_SignalList_EXIST"))) Then
        Set cSignal = ObjectCollection("LinSignals")
    End If
    If ((r.v("LIN_FrameList_EXIST"))) Then
        Set cFrame = ObjectCollection("LinFrames")
    End If
    If ((r.v("LIN_ScheduleList_EXIST"))) Then
        Set cSchedule = ObjectCollection("LinSchedules")
    End If

   'open LIN_LDF.c
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_CFILE") For Output As f
    
    'Header
    '-----------------------------------------------------------------------------------------------------------------------------
    iSpace = 15
    Print #f, FormatText(5, "", "", "/" & String(75, "*"), 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "File       :  " & r.v(sVarPre & "_CFILE"), 40)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Controller :  Infineon XC164CM-8FF", 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Tool       :  DAvE 2.0", 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Description:  LIN Description File for the defined LIN cluster", 100)
    Print #f, FormatText(5, "", "", "*" & String(75, "*"), 100)
    Print #f, FormatText(5, "", "", "*/", 10)
    Print #f, ""
    
    'Schedules
    Print #f, ""
    Print #f, "#include " & """" & r.v("LIN_HFILE") & """"
    Print #f, ""
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This file contains the Modules for LIN cluster.It provides the details about", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Schedules,Signals,Frames and its Types.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "This file information provided by DAvE tool, User may not change the values.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, ""
    If (cSchedule.Count) Then
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Schedules for LIN cluster.It provides the Schedule details ", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Schedule count and Frames packed(Frame ID,Frame Type and Frame delay).", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_SYS_SCHD_INFO LIN_schd_tab_base[LIN_SYS_CFG_NUM_OF_SCHD_TBL]" & " = {", 100)
    iTcount = 0
    For Each uSchedule In cSchedule
        If uSchedule.Count Then
            SchFrmId = ""
            For i = 0 To (uSchedule.Count - 1)
                If (uSchedule.Frames(i) <> "") Then
                    iFrameIndex = GetFrame(uSchedule.Frames(i))
                    Set uTmpFrame = cFrame.Item(iFrameIndex)
                        iSPRDCid = uTmpFrame.ID
                        If (uTmpFrame.FrmType = "Unconditional") Then
                        sFrmType = "UNCD"
                        ElseIf (uTmpFrame.FrmType = "Event_Triggered") Then
                        sFrmType = "EVNT"
                        ElseIf (uTmpFrame.FrmType = "Sporadic") Then
                        sFrmType = "SPRDC"
                        iSPRDCid = 0
                        End If
                    SchFrmId = SchFrmId & "{" & CStr(iSPRDCid) & "," & CStr(uTmpFrame.MaxPeriod) & "," & sFrmType & "}" & ","
                End If
            Next
            If (Len(SchFrmId)) Then
                SchFrmId = Left(SchFrmId, Len(SchFrmId) - 1)
            End If
        Else
            SchFrmId = "0"
        End If
            If (cSchedule.Count - 1 > iTcount) Then
                Print #f, FormatText(9, "", "", "{" & uSchedule.Count & ",{" & SchFrmId & "}" & "},", 100)
                iTcount = iTcount + 1
            Else
                Print #f, FormatText(9, "", "", "{" & uSchedule.Count & ",{" & SchFrmId & "}" & "}", 100)
            End If

    Next
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    End If
    
   'Frames
    Print #f, ""
    If 1 Then
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Frames for LIN cluster.It provides the Frame details ", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Frame ID,Frame Type,Frame Size, Signal validity and Signals packed.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_SYS_FRM_INFO LIN_frm_base[LIN_SYS_MAX_NUM_FRM]" & " = {", 100)
    iSPRDCnt = 0
    For Each uFrame In cFrame
        If (uFrame.FrmType = "Sporadic") Then
        iSPRDCnt = iSPRDCnt + 1
        End If
    Next
    iTcount = 0
    For j = 0 To 63
    bFrmChk = False
    For Each uFrame In cFrame

        If (uFrame.ID = j) Then
        bFrmChk = True
        iValid = 0
        l = 0
        sTempSignal = ""
        For i = 0 To uFrame.FrmSigcount - 1
            If ((uFrame.FrmSignals(i) <> "") And uFrame.FrmSignals(i) <> sTempSignal) Then
                sTempSignal = uFrame.FrmSignals(i)
                For Each uSignal In cSignal
                    If (uSignal.Name = sTempSignal) Then
                        If (uSignal.SignalType = 0) Then
                        l = l + (uSignal.InitVal(0) * (2 ^ uSignal.offset))
                        End If
                    End If
                Next
            End If
        Next
        sRmndr = ""
        iFDBcount = 1
        Do While (l > 256)
            remainder = l Mod 256
            l = l - remainder
            l = l / 256
            sRmndr = sRmndr & CStr(FormatTextOutput(remainder, "H2")) & ","
            iFDBcount = iFDBcount + 1
        Loop
        sRmndr = sRmndr & CStr(FormatTextOutput(l, "H2")) & ","
        If (l <> 0) Then
        iValid = 1
            For i = 0 To uFrame.Length - iFDBcount - 1
            sRmndr = sRmndr & CStr(FormatTextOutput(0, "H2")) & ","
            Next
            sRmndr = Left(sRmndr, Len(sRmndr) - 1)
            sRmndr = "{" & sRmndr & "}"
        Else
            sRmndr = ""
            For i = 0 To uFrame.Length - 1
            sRmndr = sRmndr & CStr(FormatTextOutput(l, "H2")) & ","
            Next
            sRmndr = Left(sRmndr, Len(sRmndr) - 1)
            sRmndr = "{" & sRmndr & "}"
        End If
            If (uFrame.FrmType = "Unconditional") Then
                sFrmType = "UNCD"
                ElseIf (uFrame.FrmType = "Event_Triggered") Then
                sFrmType = "EVNT"
            End If

            If (uFrame.ID < 63) Then
                If (uFrame.FrmType <> "Sporadic") Then
                Print #f, FormatText(9, "", "", "{" & uFrame.MsgID & "," & sFrmType & _
                                        "," & uFrame.Length & "," & iValid & "," & sRmndr & "}" & ",", 100)
                End If
            Else
                If (uFrame.FrmType <> "Sporadic") Then
                Print #f, FormatText(9, "", "", "{" & uFrame.MsgID & "," & sFrmType & _
                                        "," & uFrame.Length & "," & iValid & "," & sRmndr & "}", 100)
                                                                    'Frame data Valid
                End If
            End If
        Exit For
        End If
        
    Next
    If (bFrmChk = False) Then
    If (j < 32) Then
    Print #f, FormatText(9, "", "", "{" & "0,0,0,0,{0x00,0x00}" & "}" & ",", 100)
    ElseIf (j < 48) Then
    Print #f, FormatText(9, "", "", "{" & "0,0,0,0,{0x00,0x00,0x00,0x00}" & "}" & ",", 100)
    ElseIf (j < 63) Then
    Print #f, FormatText(9, "", "", "{" & "0,0,0,0,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}" & "}" & ",", 100)
    Else
    Print #f, FormatText(9, "", "", "{" & "0,0,0,0,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}" & "}", 100)
    End If
    End If
    Next j
    Print #f, FormatText(9, "", "", "};", 15)
    End If
    
    'Signals
    Print #f, ""
    If (cSignal.Count) Then
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Signals for LIN cluster.It provides the Signal details ", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Signal Name, Associated Frame ID, Size and Offset.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_SYS_SIG_INFO LIN_sig_base[LIN_SYS_CFG_NUM_OF_SIGS]" & " = {", 100)
    iTcount = 0
    iTempFrmID = 0
    
    For i = 0 To 7
    Print #f, "         {MasterReqB" & i & ",60,8," & (i * 8) & "},"
    Next
    
    For i = 0 To 7
    Print #f, "         {SlaveRespB" & i & ",61,8," & (i * 8) & "},"
    Next
        
    For Each uSignal In cSignal
        i = 0
        If (uSignal.SignalType) Then
            iInitCount = uSignal.Size \ 8
            sInitValue = ""
            For i = 0 To iInitCount - 1
                sInitValue = sInitValue & "," & CStr(uSignal.InitVal(i))
            Next i
            sInitValue = Right(sInitValue, Len(sInitValue) - 1)
            sInitValue = "{" & sInitValue & "}"
        Else
            sInitValue = CStr(uSignal.InitVal(0))
        End If

        For Each uFrame In cFrame
            If (uFrame.FrmSigcount) Then
            For j = 0 To uFrame.FrmSigcount - 1
                If (uFrame.FrmSignals(j) = uSignal.Name) Then
                iTempFrmID = uFrame.ID
                End If
            Next
            End If
        Next
        
        If (cSignal.Count - 1 > iTcount) Then
            Print #f, FormatText(9, "", "", "{" & uSignal.Name & "," & iTempFrmID & "," & _
                                 uSignal.Size & "," & uSignal.offset & "}" & ",", 100)
            iTcount = iTcount + 1
        Else
            Print #f, FormatText(9, "", "", "{" & uSignal.Name & "," & iTempFrmID & "," & _
                                 uSignal.Size & "," & uSignal.offset & "}", 100)
        End If
    Next
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    End If
    
    iSPRDCnt = 0
    iEvtCnt = 0
    For Each uFrame In cFrame
        If (uFrame.FrmType = "Sporadic") Then
        iSPRDCnt = iSPRDCnt + 1
        ElseIf (uFrame.FrmType = "Event_Triggered") Then
        iEvtCnt = iEvtCnt + 1
        End If
    Next

    'EventTriggered Frames
    Print #f, ""
    If (iEvtCnt) Then
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Event Triggered Frames for LIN cluster.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Evt_Trigger Frame IDs and its count", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_EVNT_FRM_INFO LIN_evnt_frm_base[LIN_SYS_CFG_NUM_OF_EVNT_FRMS]" & " = {", 100)
    iColflag = 0
    iCrntFind = 0
    For Each uFrame In cFrame
        sEvtSPRDFrms = ""
        If (uFrame.FrmType = "Event_Triggered") Then
        If (uFrame.EvtSPRDCount) Then
            For i = 0 To uFrame.EvtSPRDCount - 1
            sEvtSPRDFrms = sEvtSPRDFrms & uFrame.EvtSPRDFrm(i) & ","
            Next
        End If
        If (Len(sEvtSPRDFrms)) Then
            sEvtSPRDFrms = Left(sEvtSPRDFrms, Len(sEvtSPRDFrms) - 1)
        End If
        sEvtSPRDFrms = "{" & sEvtSPRDFrms & "}"
            If (iEvtCnt > 1) Then
            Print #f, FormatText(9, "", "", "{" & uFrame.ID & "," & iColflag & "," & uFrame.EvtSPRDCount & _
                                    "," & iCrntFind & "," & sEvtSPRDFrms & "}" & ",", 100)
            iEvtCnt = iEvtCnt - 1
            Else
            Print #f, FormatText(9, "", "", "{" & uFrame.ID & "," & iColflag & "," & uFrame.EvtSPRDCount & _
                                    "," & iCrntFind & "," & sEvtSPRDFrms & "}", 100)
            End If
        End If
    Next
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    
    Else
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Event Triggered Frames for LIN cluster.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Evt_Trigger Frame IDs and its count", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_EVNT_FRM_INFO LIN_evnt_frm_base[1]" & " = {", 100)
    Print #f, FormatText(9, "", "", "{0,0,1,0,{0}}", 15)
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    End If
    
    'Sporadic Frames
    Print #f, ""
    If (iSPRDCnt) Then
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Sporadic Frames for LIN cluster.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Sporadic Frame IDs and its count", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_SPRDC_FRM_INFO LIN_sprdc_frm_base" & " = {", 100)
    
    iColflag = 0
    iCrntFind = 0
    For Each uFrame In cFrame
        sSPRDflag = ""
        sEvtSPRDFrms = ""
        If (uFrame.FrmType = "Sporadic") Then
        If (uFrame.EvtSPRDCount) Then
            For i = 0 To uFrame.EvtSPRDCount - 1
            sEvtSPRDFrms = sEvtSPRDFrms & uFrame.EvtSPRDFrm(i) & ","
            sSPRDflag = sSPRDflag & "0" & ","
            Next
        End If
        If (Len(sEvtSPRDFrms)) Then
            sEvtSPRDFrms = Left(sEvtSPRDFrms, Len(sEvtSPRDFrms) - 1)
            sSPRDflag = Left(sSPRDflag, Len(sSPRDflag) - 1)
        End If
        sSPRDflag = "{" & sSPRDflag & "}"
        sEvtSPRDFrms = "{" & sEvtSPRDFrms & "}"
            If (iSPRDCnt > 1) Then
            Print #f, FormatText(9, "", "", "{" & uFrame.EvtSPRDCount & "," & sEvtSPRDFrms & "," & sSPRDflag & "},", 100)
            iSPRDCnt = iSPRDCnt - 1
            Else
            Print #f, FormatText(9, "", "", uFrame.EvtSPRDCount & "," & sEvtSPRDFrms & "," & sSPRDflag, 100)
            End If
        End If
    Next
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    Else
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section defines the Sporadic Frames for LIN cluster.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Sporadic Frame IDs and its count", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "LIN_SPRDC_FRM_INFO LIN_sprdc_frm_base" & " = {", 100)
    Print #f, FormatText(9, "", "", "0,{0},{0}", 15)
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    End If
     
    'Publishers and Subscribers of Frames infromation.
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "The LIN_publsh_frm_info and LIN_sbscrb_frm_info variables increase", 100)
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "the code execution speed and simplify the system generator task.  ", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section provides Publishers of Frames infromation.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "l_u8 LIN_publsh_frm_info[LIN_NUM_IFCS][LIN_SYS_MAX_NUM_FRM]" & " = {", 100)
    k = 0
    For Each uNode In cNode
    
    sFrmPub = ""
    For i = 0 To 63
        bFrmfound = False
        For Each uFrame In cFrame
            If (uNode.FPubCount) Then
            For j = 0 To uNode.FPubCount - 1
                If (uFrame.Name = uNode.FrmPublisher(j)) Then
                    If (uFrame.ID = i) Then
                        bFrmfound = True
                        Exit For
                    End If
                End If
            Next j
            End If
            
            If ((k = 0 And i = 60) Or (k > 0 And i = 61)) Then
                 bFrmfound = True
            End If

            If bFrmfound Then Exit For
        Next
        
        If bFrmfound Then
            sFrmPub = sFrmPub & "1" & ","
        Else
            sFrmPub = sFrmPub & "0" & ","
        End If
    Next i
    k = k + 1
    sFrmPub = Left(sFrmPub, Len(sFrmPub) - 1)
    If k < cNode.Count Then
        sFrmPub = "{" & sFrmPub & "},"
    Else
        sFrmPub = "{" & sFrmPub & "}"
    End If
    Print #f, "" & sFrmPub
    Next
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "This section provides Subscribers of Frames infromation.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, FormatText(5, "", "", "l_u8 LIN_sbscrb_frm_info[LIN_NUM_IFCS][LIN_SYS_MAX_NUM_FRM]" & " = {", 100)
    k = 0
    For Each uNode In cNode
    sFrmPub = ""
    For i = 0 To 63
        bFrmfound = False
        
        For Each uFrame In cFrame
            If (uNode.FSubCount) Then
            For j = 0 To uNode.FSubCount - 1
                If (uFrame.Name = uNode.FrmSubscriber(j)) Then
                    If (uFrame.ID = i) Then
                        bFrmfound = True
                        Exit For
                    End If
                End If
            Next j
            End If
            
            If ((k = 0 And i = 61) Or (k > 0 And i = 60)) Then
                        bFrmfound = True
            End If

            If bFrmfound Then Exit For
        Next
        
        If bFrmfound Then
            sFrmPub = sFrmPub & "1" & ","
        Else
            sFrmPub = sFrmPub & "0" & ","
        End If
    Next i
    k = k + 1
    sFrmPub = Left(sFrmPub, Len(sFrmPub) - 1)
    
        If k < cNode.Count Then
            sFrmPub = "{" & sFrmPub & "},"
        Else
            sFrmPub = "{" & sFrmPub & "}"
        End If
        Print #f, "" & sFrmPub
    Next
    Print #f, FormatText(9, "", "", "}" & ";", 15)
    'close file
    Close f

    LDFGenerateC = True
    Exit Function
    
LDFGenerateCError:
errorbox "Error - " & Err.Description
    Close f
    Exit Function
End Function




'*****************************************************************************
'Description:
'        Generates the code for the LIN_LDF.h file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function LDFGenerateH(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo LDFGenerateHError
    
    Dim f           As Variant
    Dim sVarPre     As String
    Dim sRegPre     As String
    Dim l           As Long
    Dim remainder   As Long
    Dim i           As Integer
    Dim v           As Variant
    Dim d           As String
    Dim slaves      As String
    Dim subscriber  As String
    Dim publisher   As String
    Dim sTempSub    As String
    Dim sTempSignal As String
    Dim sEvtSPRDFrames  As String
    Dim sSporadic   As String
    Dim sDynamic    As String
    Dim sInitValue  As String
    Dim iInitCount  As Integer
    Dim iSpace      As Integer
    Dim iFrameIndex As Integer
    Dim iSprCount   As Integer
    Dim dTBJT       As Double
    Dim iEvtSPRDTrCount As Integer
    Dim iSchCntMax  As Integer
    Dim iEvtSPRDCntMax  As Integer
    
    Dim cNode       As New DAvECollection
    Dim cSignal     As New DAvECollection
    Dim cFrame      As New DAvECollection
    Dim cSchedule   As New DAvECollection
    Dim uNode       As New LinNode
    Dim uSignal     As New LinSignal
    Dim uFrame      As New LinFrame
    Dim uTmpFrame   As New LinFrame
    Dim uSchedule   As New LinSchedule
                    
    sVarPre = "LIN" & vIndex
    LDFGenerateH = False
       
    If ((r.v("LIN_NodeList_EXIST"))) Then
        Set cNode = ObjectCollection("LinNodes")
    End If
    If ((r.v("LIN_SignalList_EXIST"))) Then
        Set cSignal = ObjectCollection("LinSignals")
    End If
    If ((r.v("LIN_FrameList_EXIST"))) Then
        Set cFrame = ObjectCollection("LinFrames")
    End If
    If ((r.v("LIN_ScheduleList_EXIST"))) Then
        Set cSchedule = ObjectCollection("LinSchedules")
    End If

    'open LIN_LDF.h
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_HFILE") For Output As f

    'Header
    '-----------------------------------------------------------------------------------------------------------------------------
    iSpace = 15
    Print #f, FormatText(5, "", "", "/" & String(70, "*"), 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "File       :  " & r.v(sVarPre & "_HFILE"), 40)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Controller :  Infineon XC164CM-8FF", 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Tool       :  DAvE 2.0", 100)
    Print #f, FormatText(5, "", "", "*" & Space(iSpace - 7) & "Description:  LIN Description File for the defined LIN cluster", 100)
    Print #f, FormatText(5, "", "", "*" & String(70, "*"), 100)
    Print #f, FormatText(5, "", "", "*/", 10)
    Print #f, ""
    Print #f, ""
    Print #f, "#ifndef " & StripExtension(r.v("LIN_HFILE")) & "_H"
    Print #f, "#define " & StripExtension(r.v("LIN_HFILE")) & "_H"
    Print #f, ""
    Print #f, "/*@doc API*/"
    Print #f, ""
    Print #f, "#include " & """" & "COMPILER.h" & """"
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@Topic LIN LDF Application Program Interface |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "This section defines the interface for LIN cluster. It defines the constants", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "typedef names and function names.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "This file information provided by DAvE tool, User may not change the values.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "LIN 2.0 protocol specificaton constraints.", 100)
    Print #f, FormatText(0, "", "", "*", 5)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "@def LIN_NUM_IFCS | LIN Protocol Version.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_NUM_IFCS  " & cNode.Count
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_MAX_NUM_FRM | Maximum no. of Frames.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_MAX_NUM_FRM  " & 64
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_MAX_FRM_SIZE | Maximum Size of a Frame.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_MAX_FRM_SIZE  " & 8
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_BAUD |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Baud rate defined by application in LDF file.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_BAUD  " & (r.v("LIN_Speed") * 1000)
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_NUM_OF_SIGS |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Total number of signals configured by application,Generated by DAvE tool.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_NUM_OF_SIGS  " & cSignal.Count + 16
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@enum LIN_LDF_SIG_INFO |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "To read, write or control signals, application uses the signal name as defined in LDF file", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "configuration, LIN LLD uses the corresponding enumerated value as defined to service the", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "requested operation.Generated by DAvE tool.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef enum"
    Print #f, "{"
    If (cSignal.Count) Then
    For i = 0 To 7
    Print #f, "MasterReqB" & i & "=" & i & ","
    Next
    For i = 0 To 7
    Print #f, "SlaveRespB" & i & "=" & (i + 8) & ","
    Next
    
    i = 0
    For Each uSignal In cSignal
    If (cSignal.Count - 1 > i) Then
        Print #f, "" & uSignal.Name & " = " & (i + 16) & ","
    Else
        Print #f, "" & uSignal.Name & " = " & (i + 16)
    End If
    i = i + 1
    Next
    Print #f, "}" & "LIN_LDF_SIG_INFO" & ";"
    Else
    Print #f, "SIGNAL = 0"
    Print #f, "}" & "LIN_LDF_SIG_INFO" & ";"
    End If
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "type l_signal_handle |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Used as an alias to read, write or control signal information.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef  LIN_LDF_SIG_INFO l_signal_handle;"
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@struct LIN_SYS_SIG_INFO |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Includes the signal information such as signal name, associated frame, signal size in bits", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "and offset location.Signal read and write APIs will use this information.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef struct"
    Print #f, "{"
    Print #f, FormatText(5, "", "", "l_signal_handle name;           " & "/*@field Signal name*/", 120)
    Print #f, FormatText(5, "", "", "l_u8         asctd_frame_num;   " & "/*@field Frame number to which the signal is associated.*/", 120)
    Print #f, FormatText(5, "", "", "l_u8         size_bits;         " & "/*@field Signal size in terms of bits.*/", 120)
    Print #f, FormatText(5, "", "", "l_u8         offest;            " & "/*@field Offset location of signal in associated frame,", 120)
    Print #f, FormatText(46, "", "", "offset value starts with 0 (zero) value.*/", 100)
    Print #f, "}" & "LIN_SYS_SIG_INFO" & ";"
    Print #f, "";
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@enum LIN_FRM_TYPE |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Defines the type of LIN frame.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef enum"
    Print #f, "{"
    Print #f, FormatText(5, "", "", "UNCD  = 0,         " & "/*@enum Unconditional frame*/", 120)
    Print #f, FormatText(5, "", "", "EVNT  = 1,         " & "/*@enum Event triggered frame.*/", 120)
    Print #f, FormatText(5, "", "", "SPRDC = 2          " & "/*@enum Sporadic frame.*/", 120)
    Print #f, "}" & "LIN_FRM_TYPE" & ";"
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@struct LIN_SYS_FRM_INFO |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Includes the frame information like message id, frame propagation time and frame type.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "This information will be used when master schedules a frame.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef struct"
    Print #f, "{"
    Print #f, FormatText(5, "", "", "l_u16        msg_id;               " & "/*@field Message id associated with frame as defined in LDF file.*/", 120)
    Print #f, FormatText(5, "", "", "LIN_FRM_TYPE frm_type;             " & "/*@field Frame type (unconditional or event triggered)*/", 120)
    Print #f, FormatText(5, "", "", "l_u8         frm_length;           " & "/*@field Length of the frame.*/", 120)
    Print #f, FormatText(5, "", "", "l_bool       info_updt_flag;       " & "/*@field Status flag of updated data information, will be set by LLD", 120)
    Print #f, FormatText(49, "", "", "on receiving frame data and resets the flag on successful", 100)
    Print #f, FormatText(49, "", "", "transmission of frame data. Application shall set and reset", 100)
    Print #f, FormatText(49, "", "", "this flag on writing and reading frame data respectively.", 100)
    Print #f, FormatText(49, "", "", "0 --> Data is new", 100)
    Print #f, FormatText(49, "", "", "1 --> old data. */", 100)
    Print #f, FormatText(5, "", "", "l_u8         frm_data[LIN_SYS_MAX_FRM_SIZE];         " & "/*@field Frame data.*/", 120)
    Print #f, "}" & "LIN_SYS_FRM_INFO" & ";"
    Print #f, ""
    iEvtSPRDCntMax = 0
    iSprCount = 0
    For Each uFrame In cFrame
        If (uFrame.FrmType = "Event_Triggered") Then
            iEvtSPRDTrCount = iEvtSPRDTrCount + 1
            If (iEvtSPRDCntMax < uFrame.EvtSPRDCount) Then
            iEvtSPRDCntMax = uFrame.EvtSPRDCount
            End If
        ElseIf (uFrame.FrmType = "Sporadic") Then
            If (iSprCount < uFrame.EvtSPRDCount) Then
            iSprCount = uFrame.EvtSPRDCount
            End If
        End If
    Next
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_NUM_OF_EVNT_FRMS |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Total number of event triggered frames defined in LDF file,Generated by DAvE tool.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_NUM_OF_EVNT_FRMS  " & iEvtSPRDTrCount
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_MAX_FRM_PER_EVNT_FRM |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Maximum number of unconditional frames associated with any of the,", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Event triggered frame.Generated by DAvE tool.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_MAX_FRM_PER_EVNT_FRM  " & iEvtSPRDCntMax
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@struct LIN_EVNT_FRM_INFO |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Provide the event triggered frames details. This information used in case of collisions.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Master set the collision flag in corresponding slot when collision occurs,", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "in the following slots associated unconditional frames are published by", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "master until all associated unconditional frames are published.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "At the end master reset the collision flag.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef struct"
    Print #f, "{"
    Print #f, FormatText(5, "", "", "l_u8 frm_id;                " & "/*@field Event triggered frame ID.*/", 120)
    Print #f, FormatText(5, "", "", "l_u8 coll_flag;             " & "/*@field Collision flag, master sets the flag when collision occurs.", 120)
    Print #f, FormatText(42, "", "", "Reset when all the associated unconditional frames are", 100)
    Print #f, FormatText(42, "", "", "published.*/", 100)
    Print #f, FormatText(5, "", "", "l_u8 max_num_of_uncd_frms;  " & "/*@field Number of unconditional frames are associated with this", 120)
    Print #f, FormatText(42, "", "", "event triggered frame*/", 100)
    Print #f, FormatText(5, "", "", "l_u8 curr_frm_index;        " & "/*@field Point to associated unconditional frame, after collision", 120)
    Print #f, FormatText(42, "", "", "corresponding frame ID published by master and index point", 100)
    Print #f, FormatText(42, "", "", "to next frame ID.*/", 100)
    If iEvtSPRDCntMax Then
    Print #f, FormatText(5, "", "", "l_u8 asctd_uncd_frm_ids[LIN_SYS_CFG_MAX_FRM_PER_EVNT_FRM];", 120)
    Else
    Print #f, FormatText(5, "", "", "l_u8 asctd_uncd_frm_ids[1];", 120)
    End If
    Print #f, FormatText(33, "", "", "/*@field Unconditional frame IDs associated with this", 100)
    Print #f, FormatText(42, "", "", "event triggered frame.*/", 100)
    Print #f, "}" & "LIN_EVNT_FRM_INFO" & ";"
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_NUM_OF_UNCD_FRMS_ASC_SPRDC |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Total number of sporadic frames defined in LDF file. It assumes that", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "sporadic frame slot in schedule table shared by all sporadic frames.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Value generated by DAvE tool.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_NUM_OF_UNCD_FRMS_ASC_SPRDC  " & iSprCount
    Print #f, ""
    '_
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@struct LIN_SPRDC_FRM_INFO |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Provide the sporadic frame details. This information used by master to publish", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "sporadic frame ID in sporadic frame slot defined in schedule table.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "typedef struct"
    Print #f, "{"
    Print #f, FormatText(5, "", "", "l_u8 max_num_of_frms;               " & "/*@field Number of frames are associated with this sporadic frame.*/", 120)
    If iSprCount > 0 Then
    Print #f, FormatText(5, "", "", "l_u8 asctd_frm_ids[LIN_SYS_CFG_NUM_OF_UNCD_FRMS_ASC_SPRDC];", 120)
    Print #f, FormatText(40, "", "", " /*@field Frame IDs associated with this sporadic frame.*/", 100)
    Print #f, FormatText(5, "", "", "l_u8 asctd_frm_flag[LIN_SYS_CFG_NUM_OF_UNCD_FRMS_ASC_SPRDC];", 120)
    Else
    Print #f, FormatText(5, "", "", "l_u8 asctd_frm_ids[1];", 120)
    Print #f, FormatText(40, "", "", " /*@field Frame IDs associated with this sporadic frame.*/", 100)
    Print #f, FormatText(5, "", "", "l_u8 asctd_frm_flag[1];", 120)
    End If
    Print #f, FormatText(40, "", "", " /*@field Flag associated with the sporadic frame,", 100)
    Print #f, FormatText(50, "", "", "this flag will be used by master to publish the sporadic", 100)
    Print #f, FormatText(50, "", "", "frame ID in corresponding schedule table slot. This flag will be", 100)
    Print #f, FormatText(50, "", "", "set/reset by using l_ifc_ioctl API*/", 100)
    Print #f, "}" & "LIN_SPRDC_FRM_INFO" & ";"
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_CFG_SCHD_TIME_BASE |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Specify time in milli seconds.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    dTBJT = r.v("LIN_M_TBase")
    dTBJT = dTBJT + r.v("LIN_M_Jitter")
    Print #f, "#define LIN_CFG_SCHD_TIME_BASE  " & dTBJT
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_NUM_OF_SCHD_TBL |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Total number of schedule tables defined in LDF file.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_NUM_OF_SCHD_TBL  " & cSchedule.Count
    Print #f, ""
    iSchCntMax = 0
    For Each uSchedule In cSchedule
        If (iSchCntMax < uSchedule.Count) Then
        iSchCntMax = uSchedule.Count
        End If
    Next
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@def LIN_SYS_CFG_MAX_FRM_PER_SCH_TAB |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Maximum number of frame slots associated with any of the schedule table.", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "This value provided by DAvE tool.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    Print #f, "#define LIN_SYS_CFG_MAX_SLTS_PER_SCH_TAB  " & iSchCntMax
    Print #f, ""
    Print #f, FormatText(0, "", "", "/*" & Space(iSpace - 10) & "@struct LIN_SYS_SCHD_INFO |", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "Define the schedule table information such as the number of frame slots ", 100)
    Print #f, FormatText(0, "", "", "* " & Space(iSpace - 10) & "and frame ID associated with each slot.", 100)
    Print #f, FormatText(0, "", "", "*/", 5)
    '-
    Print #f, "typedef struct"
    Print #f, "{"
    Print #f, FormatText(5, "", "", "l_u8   num_slots_ascted;         " & "/*@field Total number of frame slots with current schedule table.*/", 120)
    Print #f, FormatText(5, "", "", "struct", 100)
    Print #f, FormatText(5, "", "", "{", 10)
    Print #f, FormatText(10, "", "", "l_u8         frm_id;         " & "/*@field Frame ID, in case of unconditional or event triggered frame.", 120)
    Print #f, FormatText(48, "", "", "For sporadic frame the value will be 0 (zero). */", 100)
    Print #f, FormatText(10, "", "", "l_u8         slot_time;      " & "/*@field Slot timeout period in milli seconds*/", 100)
    Print #f, FormatText(10, "", "", "LIN_FRM_TYPE frm_type;       " & "/*@field Frame type (unconditional, event triggered or sporadic)*/", 120)
    If iSchCntMax Then
    Print #f, FormatText(5, "", "", "}" & "assctd_frm_info[LIN_SYS_CFG_MAX_SLTS_PER_SCH_TAB];", 100)
    Else
    Print #f, FormatText(5, "", "", "}" & "assctd_frm_info[1];", 100)
    End If
    Print #f, FormatText(10, "", "", "                             " & "/*@filed frame IDs associated with slots.*/", 120)
    Print #f, "}" & "LIN_SYS_SCHD_INFO" & ";"
    Print #f, ""
    If cSchedule.Count Then
    Print #f, "extern LIN_SYS_SCHD_INFO  LIN_schd_tab_base[LIN_SYS_CFG_NUM_OF_SCHD_TBL];"
    Else
    Print #f, "extern LIN_SYS_SCHD_INFO  LIN_schd_tab_base[1];"
    End If
    Print #f, "extern LIN_SYS_FRM_INFO   LIN_frm_base[LIN_SYS_MAX_NUM_FRM];"
    If cSignal.Count Then
    Print #f, "extern LIN_SYS_SIG_INFO   LIN_sig_base[LIN_SYS_CFG_NUM_OF_SIGS];"
    End If
    If iEvtSPRDTrCount Then
    Print #f, "extern LIN_EVNT_FRM_INFO  LIN_evnt_frm_base[LIN_SYS_CFG_NUM_OF_EVNT_FRMS];"
    Else
    Print #f, "extern LIN_EVNT_FRM_INFO  LIN_evnt_frm_base[1];"
    End If
    Print #f, "extern LIN_SPRDC_FRM_INFO LIN_sprdc_frm_base;"
    Print #f, "extern l_u8 LIN_publsh_frm_info[LIN_NUM_IFCS][LIN_SYS_MAX_NUM_FRM];"
    Print #f, "extern l_u8 LIN_sbscrb_frm_info[LIN_NUM_IFCS][LIN_SYS_MAX_NUM_FRM];"
    Print #f, ""
    Print #f, ""
    Print #f, "#endif  /* #ifndef " & StripExtension(r.v("LIN_HFILE")) & "_H */"
    
    'close file
    Close f
    
    LDFGenerateH = True
    Exit Function
    
LDFGenerateHError:
    Close f
    Exit Function
End Function

