enc28j60: Reuse read/writedata() for read/writedatabyte()

The read/writedatabyte() functions are just a special case of read/writedata()
with a simpler API, so reuse these instead of duplicating code.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Fix RCR command for MAC and MII registers

The Read Control Register command requires that a dummy byte be read before the
register value.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Add workaround for erratum #2 'CLKRDY set early'

A delay of 1 ms must be added after a reset. Still wait for ESTAT.CLKRDY
afterwards as a precaution.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Print revision during initialization

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: The MACON2 register is reserved

The register 0x01 in bank 2, named MACON2 in the code, is actually reserved, so
do not touch it.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Do not initialize MAIPGH for full duplex

MAIPGH should be programmed only if half duplex is used.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: ERXFCON needs to be set only once

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Implement and use the BFS and BFC commands

The Bit Field Set and Bit Field Clear commands are more efficient than the Read
Control Register + Write Control Register combination, so use them whenever
possible, i.e. for the ETH registers.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Use hardware padding for transmissions

There is no reason to use software when a feature is available in hardware.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Program ETXND after the data packet

Just follow the steps from the data sheet to transmit a packet.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Print the status vector in case of transmit error

This makes debugging easier.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Fix workaround for erratum #14

Only odd addresses may be programmed to the ERXRDPT registers, so initialize
them to RX_BUF_END instead of RX_BUF_START.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Prevent enc28j60_read() from running before init

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
enc28j60: Try to prevent Ethernet -> RF overrun

The Ethernet receptions are way faster than RF transmissions, so it is very
likely that packet queue overrun conditions occur, which then results in 'drop
incoming frag' errors on mesh nodes because some Ethernet packets could not be
forwarded to the RF.

Unfortunately, there is no easy way to know if more Ethernet packets can be
queued for RF forwarding before reading them from the controller. Hence, this is
only a workaround based on timings. After reading an Ethernet packet, the delay
before reading the next one is made proportional to the packet length. In that
way, the Ethernet controller handles the flow control itself.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Update contiki

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
cc2538dk: enc28j60: Use the SPI module instead of GPIOs

According to the ENC28J60 erratum #1, when the SPI clock from the host
microcontroller is run at frequencies of less than 8 MHz, reading from or
writing to the MAC registers may be unreliable. Hence, use the CC2538 SPI module
at 8 MHz rather than slower GPIO operations to drive the SPI pins. This also
makes the code simpler, and it gives more time to the CC2538 to perform other
tasks.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>