Support for the LIN protocol is provided via the BabyLIN™ USB adapter. The adapter connects to the RT host via a USB port and provides the functionality of either a LIN master node or LIN slave node.
Similar to the CAN bus, the LIN protocol allows transfer of 8 byte message associated to an ID. The ID is 1 byte and the values for the ID are between 0 and 63.
RTDB items can be mapped to multi bit/byte fields defined on the 8 byte buffer payload.
CS-Baby-LIN-x.
Provided via kernel usbserial.
ICS-SWB-1252.
Frame IDThe message identifier. This is a 6-bit value, The maximum value allowed is 63. FIFOSpecifies that the message is transmitted as soon as it changes. For output messages only. TX on changeWhen a message is defined as FIFO and TX on change is set, the output frame is sent as soon as the content change, when TX on change is not set, the frame is only sent on user request via an API call. Sched Rate (ms)The rate in milliseconds at which transmission/polling is scheduled. Contrary to the CAN network. Input messages (subscriber) need to be retrieved from the LIN slaves by the master node. Thus, the schedule rate must also be specified for subscribed messages. Message LengthThe number of bytes in the message (maximum 8). LIN VersionThe LIN protocol version for the frame. Either 1.2/1.3 or 2.0, The protocol will determine how the checksum on the message content is calculated.
Adds a new data field for RTDB mapping to the selected frame. Deletes the selected field including mappings. |
You map RTDB item to a LIN message by creating new fields byte/bit fields within the frame. Each individual field has a raw data type - Packed,int,float,etc. that can be map to individual RTDB items by selecting the field and clicking on the checkbox next to the item name in the right panel. Raw TypeHow to interpret the raw bits of the field. PackedInteger bit field. Location is specified by the Bit setting. charOne-byte integer. Location is specified by the Byte setting. shortTwo-byte integer. Location is specified by the Byte setting. intFour-byte integer. Location is specified by the Byte setting. floatFour-byte floating-point number. Location is specified by the Byte setting. doubleEight-byte floating-point number. Location must be specified as 0 by the Byte setting. Byte (offset)Byte offset within the 8-byte data of the non-bit field data. Bit (offset:size)Bit offset and number of bits to reserve for the field within the 64-bit data of the message. Big EndianInterprets the bytes as most significant byte first. |
To avoid the possibility of the BabyLIN USB device assignment changing upon reboot, you can use udev to specify the device node that is created in the /dev directory. The following steps describe how to automatically generate a symbolic link to /dev/ttyUSB0 from /dev/babyLIN0. If you have more BabyLIN devices, simply change the device number suffix as appropriate.
udevadm info --attribute-walk --path=/sys/bus/usb-serial/devices/ttyUSB0
/* snip */
looking at device '/devices/pci0000:00/0000:00:12.0/usb4/4-3/4-3:1.0/ttyUSB0':
KERNEL=="ttyUSB0"
SUBSYSTEM=="usb-serial"
DRIVER=="cp210x"
ATTR{port_number}=="0"
looking at parent device '/devices/pci0000:00/0000:00:12.0/usb4/4-3/4-3:1.0':
KERNELS=="4-3:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="cp210x"
ATTRS{bInterfaceClass}=="ff"
ATTRS{modalias}=="usb:v10C4p81E2d0201dc00dsc00dp00icFFisc00ip00"
ATTRS{bInterfaceSubClass}=="00"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bNumEndpoints}=="02"
ATTRS{supports_autosuspend}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceNumber}=="00"
ATTRS{interface}=="Baby-LIN LIN-Bus Interface"
looking at parent device '/devices/pci0000:00/0000:00:12.0/usb4/4-3':
KERNELS=="4-3"
SUBSYSTEMS=="usb"
/* snip */
98-ttyUSB.rules
to /etc/udev/rules.d/
. The contents of this file are as follows:
KERNEL=="ttyUSB*",KERNELS=="4-3",SYMLINK+="babyLIN0"
KERNEL=="ttyUSB*",KERNELS=="4-4",SYMLINK+="babyLIN1"
rmmod usbserial cp210x
).
dmesg
regarding the device.
ls -ltrah /dev/baby*
will result in an output similar to the following:
lrwxrwxrwx 1 root root 7 Sep 11 13:15 /dev/babyLIN0 -> ttyUSB0
lrwxrwxrwx 1 root root 7 Sep 11 13:15 /dev/babyLIN1 -> ttyUSB1
udevadm control --reload-rules && udevadm trigger
man udev
.
This process packs all BabyLIN raw output values corresponding to LIN output frames and places them in the BabyLIN output FIFO queue. The process will not queue a request into the FIFO queue if the raw LIN message is unchanged since the last test cycle.
The FIFO queue is read by the babylinasyncio asynchronous task which in turns reads from and writes to the Baby LIN device.