[riot-notifications] [RIOT-OS/RIOT] drivers: net: add ethocan (Ethernet-over-CAN) driver (#10710)

Juergen Fitschen notifications at github.com
Sun Jan 6 16:48:19 CET 2019


### Contribution description

This contribution adds a new driver for communicating Ethernet over (electrical) CAN. The goal is to create an easy and cheap way to interconnect several RIOT nodes using a shared bus wire.

Technically, a CAN transceiver chip is connected to the UART (!) of a RIOT device. Ethernet frames are sent onto the CAN bus using `uart_write()` while observing the received echo from the bus. This way collisions are detected (received echo != transmitted octet) and retransmissions are scheduled. The frames are appended with a CRC16 to protect the system from transmission errors.

Additional to the two UART pins, another GPIO is connected to the RX pin to sense start bits on the bus and detect that another node just started sending an Ethernet frame. Just waiting for the UART interrupt would add a delay, since started transmissions are detected after the first octet has been fully received. This would increase the probability of collisions.

Since this driver is utilising the UART and GPIO driver to interface with the underlaying hardware, every 
board offering a UART and GPIO driver should be capable of utilising this driver.

Please let me know if this kind of driver is welcome in the RIOT codebase. If the maintainers like the idea, I am willing to create some benchmarks how good this driver performs.

I created a finite state machine diagram that hopefully helps to understand what's going on:

![ethocan-state](https://user-images.githubusercontent.com/6105784/50738041-fc482600-11cf-11e9-9c26-4d8efa890a77.png)

 * `BLOCKED`: The driver waits for incoming frames but blocks send requests of the underlaying netif.
 * `IDLE`: The driver waits for incoming frames and is also able to send frames to the bus.
 * `RECV`: The driver receives a frame from a remote node.
 * `SEND`: The driver sends a frame to the bus.

### Testing procedure

I used a slightly modified version of examples/gnrc_networking and patched its Makefile:
```diff
--- a/examples/gnrc_networking/Makefile
+++ b/examples/gnrc_networking/Makefile
@@ -18,7 +18,9 @@ BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-mega2560 arduino-uno \
 
 # Include packages that pull up and auto-init the link layer.
 # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
-USEMODULE += gnrc_netdev_default
+USEMODULE += ethocan
+CFLAGS += '-DETHOCAN_UART=UART_DEV(2)'
+CFLAGS += '-DETHOCAN_SENSE_PIN=GPIO_PIN(PORT_B, 1)'
 USEMODULE += auto_init_gnrc_netif
 # Activate ICMPv6 error messages
 USEMODULE += gnrc_icmpv6_error
```

I used the board "Bluepill" to test everything: `make BOARD=bluepill CPU_MODEL=stm32f103cb`

<img width="886" alt="testbed" src="https://user-images.githubusercontent.com/6105784/50738025-d02ca500-11cf-11e9-9903-6fccbf07fbdb.png">

(Any other 3.3V CAN transceiver should do the job, as well.)

After flashing, connect the Bluepill using a RS232 adapter to UART 2 (Pin A3 and A2) and execute: `ping6 ff02::1`.
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/10710

-- Commit Summary --

  * drivers: net: add ethocan (Ethernet-over-CAN) driver

-- File Changes --

    M drivers/Makefile.dep (9)
    A drivers/ethocan/Makefile (1)
    A drivers/ethocan/ethocan.c (537)
    A drivers/include/ethocan.h (121)
    M sys/auto_init/auto_init.c (5)
    A sys/auto_init/netif/auto_init_ethocan.c (71)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/10710.patch
https://github.com/RIOT-OS/RIOT/pull/10710.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10710
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190106/8ab81b2b/attachment.html>


More information about the notifications mailing list