can: add a CAN stack for RIOT#5793
Conversation
|
Great to see it's here! |
|
Since googling for CAN just gives me a bunch of pictures of beverage containers I would appreciate some information about this stack ;-) |
|
Try this one ;) |
|
thanks :-) |
drivers/include/can/candev.h
Outdated
| const struct candev_driver *driver; /**< ptr to that driver's interface. */ | ||
| candev_event_cb_t event_callback; /**< callback for device events */ | ||
| void *isr_arg; /**< argument to pass on isr event */ | ||
| kernel_pid_t pid; /**< device thread pid */ |
There was a problem hiding this comment.
is this necessary?
netdev2 has been designed to not force usage of a thread per device. maybe that architecture can be re-used here?
There was a problem hiding this comment.
if we want the candev to be completely thread-agnostic, we can remove that from this struct, then we would need to add it into a struct in the can/device.h file.
I'll propose something.
18ad903 to
8c8454c
Compare
|
Apart from |
|
A few words about CAN and filters. With CAN you don't address nodes but frames, then every frame is broadcasted in the bus. Every CAN controller provide hardware filtering, to allow a node to receive only the frames it wants to receive. The
Another difference between Which leads to another difference, there is an additional parameter in the I'm wondering whether merging |
|
Okay. Thanks for the explanation :) |
cpu/native/can/candev_linux.c
Outdated
| candev_linux_t *dev = (candev_linux_t *)candev; | ||
|
|
||
| mutex_init(&dev->rx_mutex); | ||
| mutex_init(&dev->rx_mutex); |
There was a problem hiding this comment.
the mutex was already initialized in the line above, maybe here should be tx_mutex instead
There was a problem hiding this comment.
both mutex are actually useless, I will remove them
|
squashed and rebased |
|
Needs squashing label was still set. I removed it and restarted Murdock. I guess I'll merge when everything is green (and after lunch :) ) |
We need libsocketcan to build on native, RIOT-OS/riotdocker#31 is ready but needs review. |
|
Ah yes, I forgot this... |
|
@smlng @kaspar030 can you merge RIOT-OS/riotdocker#31 or can I do it myself ? Does the CI workers need special update afterwards or is it automatic once merged ? |
|
@vincent-d CI still complains. |
|
CI docker container is rebuilding as we speak. |
|
All green, finally! Thanks @kaspar030 |
|
Let's merge this one then ! GO! |
|
Thanks for your patience @vincent-d :) |
|
@vincent-d congrats! |
Hi,
This PR propose a CAN stack for RIOT.
It includes a device driver interface (drivers/include/can/candev.h) and a reference driver for native cpu and board (under Linux only using socketCAN).
The architecture of the device driver is inspired by netdev2, with a thread per device communicating with messages with the upper layer threads.
A basic conn API is also provided for user applications, for raw CAN and isotp.
This PR implements only the data link layer (raw CAN) and provide support for simultaneous reception from multiple user threads.
A common area is used to allocate CAN packets (frame + stack data) (implementation in sys/can/pkt.c) and the routing of the messages to the user threads is done by the "router" part (sys/can/router.c).
We are still working on 2 others drivers for stm32 internal CAN controller and MCP2515 (SPI CAN controller) and on a common interface to manage CAN transceivers.
Still to do:
power management and wake up from the CAN busimprove bittiming settingimplementation of ISO-TPYou can test under Linux by setting up virtual CAN interface:
Then you can run one the test app (tests/conn_cann) as usual:
Sending on can0 from RIOT, frame id 0x100, data 0x11 0x22:
Receiving on can0 from RIOT, with thread 0, frame id 0x101:
Sending from Linux (with canutils), frame id 0x100, data 0x11 0x22:
Receiving from Linux (any frame)
Comments are welcommed :)