Local Interconnect Network (LIN) provides a low-cost communication network alternative to CAN where lower bandwidth and less versatility are acceptable. LIN is a serial communication protocol that efficiently supports the control of mechatronic nodes in distributed applications. LIN uses a master/slave bus access concept with one master per bus.
LIN is a message-based protocol with message identifiers and message content similar to CAN. Also similar to CAN, the LIN standard does not specify the content or meaning of the messages which are to be transmitted within a LIN network, which are application specific and up to the application developer. The LIN standard introduces the LIN description file (*.LDF file) which is used to describe the LIN network. This file is analogous to a the *.DBC file used in CAN networks.
In a similar way to how Raptor-Dev automatically handles the details of CAN message packing and unpacking for you based on the DBC file using code-generation, the details for LIN messages are handled with Raptor-Dev for you using the LDF file. This user tip shows you how to configure a simple LIN master that communicates with two LIN slave nodes. The sample model is available for download.
Below you will see the model, starting at the top-level (with the model shown above). First, you must define the LIN bus using the “LIN Definition” block. This configures the LIN hardware driver for a particular channel, providing the baud rate and time base. This block also configures the software driver based on the LDF file you specify.
Next looking inside the ‘Foreground’ block, the architecture of the LIN network is more apparent:
The master (GCM80) will operate according to the schedule(s) defined in the LDF file–if one is present in the LDF. If there is no schedule present in the LDF, Raptor-Dev will automatically create a simple round-robin schedule for you based on the messages used in your model. In this example, there is only one schedule defined in the example LDF file, so there is one schedule available in the “LIN Set Schedule” block. You can define multiple schedules from which to choose. Schedule 0 will be “Empty,” meaning no schedule is selected, thus no messages will be sent on the bus.
Referencing the LDF with a text editor, shown here, you can see how the schedule is composed.
In the example model, using the“LIN_SCHED” variable as an adjustment block in Raptor-Dev, you are able to change the value to select a different schedule in Raptor-Cal. This will cause the bus traffic on the LIN network to change.
It is helpful to be able to read the state of the current schedule, which can be done with the “LIN Get Schedule” block:
As with CAN, errors may occur with the message transmission in LIN. The “LIN State” block allows monitoring of the LIN bus:
Now, having configured the master, it is important to recall the way in which slaves operate on a LIN bus. The master will tell the slaves what to do, and when to do it according to the schedule.
In this example, the master sends data to a slave with the “LIN Tx Message” block, and data sent from a slave to the master is received with the “LIN Rx Message” block. These blocks handle all the packing and unpacking for you automatically based on the LDF file identified in the LIN Definition block.
Within these subsystems for sending and receiving LIN messages, a LIN Trigger block can be used to do extra logic based on the transmission or reception of a message. For receiving messages, the trigger will fire AFTER the message arrives and the receive block output data ports will contain the newly arrived data. For transmitting messages, the trigger will fire BEFORE the message is sent to the bus, the data in the outgoing messages will be collected from the transmit block if the block is inside the trigger callback.
In this example, a counter is incremented every time a particular frame is sent, and another counter is incremented every time a particular frame is received:
Triggers can be particularly helpful for creating internal logic for handling LIN frame events, and also to assure that you are processing or transmitting the latest data.
This user tip has shown how LIN is supported within Raptor-Dev. Hopefully, it will feel very familiar since LIN is exposed in the tool in a very similar way to CAN.