lin-bus / linux-lin

Linux kernel LIN bus support implemented as TTY line discipline for generic UART conrollers, documentation https://github.com/lin-bus/linux-lin/wiki, based on https://github.com/lin-bus/linux-lin/wiki/sllin-rtlws14-paper.pdf, more CAN related projects http://canbus.pages.fel.cvut.cz/
https://github.com/lin-bus/linux-lin/wiki
40 stars 26 forks source link

PEAK PCAN-USB Pro FD support? #17

Open ilanbiala opened 2 years ago

ilanbiala commented 2 years ago

Does this project support LIN interfaces on hardware like PEAK's PCAN-USB Pro FD (https://www.peak-system.com/PCAN-USB-Pro-FD.366.0.html?&L=1)?

ppisa commented 2 years ago

The actual version is intended to provide LIN support on serial port hardware. It implements LIN as TTY line discipline which means to include finite state automata above low level UART API to achieve LIN functionality. Because LIN replies has to be provided in time (without space to wait for application), the slave side is implemented as a cache/full array of all responses which can be updated asynchronously. The actual user access API is made through CAN messages, this means that it is possible to create even hardware box which has CAN channel on one side and LIN on another and is physically connected between some SoC CAN output and LIN connector.

As for hardware connected through USB, it can be useful to provide same API as slLIN provides to allow write applications portable. But because it will include cache and state automata inside external box then most of slLIN functionality is abundant. So I would suggest to write such device driver on the base of standard SocketCAN CAN driver for some USB device and provide mechanism to convert received CAN messages to appropriate USB commands of such device and in another direction covert received data in Peak specific encapsulation as CAN frames into created canX interface.

ilanbiala commented 2 years ago

Hi @ppisa I think you might have misunderstood - I'm not trying to use the CAN interface for LIN communication. PEAK's PCAN-USB Pro FD has 2x LIN transceivers in it, specifically the TJA1021/20. This device has hardware for LIN communication, I'm wondering whether linux-lin supports this type of device?

ppisa commented 2 years ago

I have described the situation in my previous comment. If the control of the LIN bus endpoint over CAN interface and CAN messages format introduced in slLIN is considered as the standard on GNU/Linux side then same interface can be used for PCAN-USB LIN interfaces which would appear as new SocketCAN interfaces under GNU/Linux. But very little of the slLIN code can be reused. It has to be supported by specific USB driver for PCAN-USB LIN interfaces which would convert CAN messages into device specific protocol sent over URBs to control internal state automatons in realized inside firmware of the USB connected devices.

Same SocketCAN API can be used for client applications working with PCAN-USB LIN interface as fis used when LIN signal levels converter is connected to UART which is operate dby slLIN. But code has to be developed from scratch and with knowledge of the device USB protocol.