mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/enc28j60: register with netdev
This commit is contained in:
parent
ab37c9fba1
commit
1afe72a5e5
@ -1,6 +1,7 @@
|
||||
FEATURES_REQUIRED += periph_gpio
|
||||
FEATURES_REQUIRED += periph_gpio_irq
|
||||
FEATURES_REQUIRED += periph_spi
|
||||
|
||||
USEMODULE += eui_provider
|
||||
USEMODULE += netdev_eth
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += luid
|
||||
|
@ -21,12 +21,11 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "luid.h"
|
||||
#include "mutex.h"
|
||||
#include "xtimer.h"
|
||||
#include "assert.h"
|
||||
#include "net/ethernet.h"
|
||||
#include "net/eui48.h"
|
||||
#include "net/eui_provider.h"
|
||||
#include "net/netdev/eth.h"
|
||||
|
||||
#include "enc28j60.h"
|
||||
@ -424,12 +423,11 @@ static int nd_init(netdev_t *netdev)
|
||||
cmd_wcr(dev, REG_B2_MABBIPG, 2, MABBIPG_FD);
|
||||
/* set non-back-to-back inter packet gap -> 0x12 is default */
|
||||
cmd_wcr(dev, REG_B2_MAIPGL, 2, MAIPGL_FD);
|
||||
|
||||
/* set default MAC address */
|
||||
uint8_t macbuf[ETHERNET_ADDR_LEN];
|
||||
luid_get(macbuf, ETHERNET_ADDR_LEN);
|
||||
eui48_set_local((eui48_t*)macbuf); /* locally administered address */
|
||||
eui48_clear_group((eui48_t*)macbuf); /* unicast address */
|
||||
mac_set(dev, macbuf);
|
||||
eui48_t addr;
|
||||
netdev_eui48_get(netdev, &addr);
|
||||
mac_set(dev, addr.uint8);
|
||||
|
||||
/* PHY configuration */
|
||||
cmd_w_phy(dev, REG_PHY_PHCON1, PHCON1_PDPXMD);
|
||||
@ -541,10 +539,12 @@ static const netdev_driver_t netdev_driver_enc28j60 = {
|
||||
.set = nd_set,
|
||||
};
|
||||
|
||||
void enc28j60_setup(enc28j60_t *dev, const enc28j60_params_t *params)
|
||||
void enc28j60_setup(enc28j60_t *dev, const enc28j60_params_t *params, uint8_t index)
|
||||
{
|
||||
dev->netdev.driver = &netdev_driver_enc28j60;
|
||||
dev->p = *params;
|
||||
mutex_init(&dev->lock);
|
||||
dev->tx_time = 0;
|
||||
|
||||
netdev_register(&dev->netdev, NETDEV_ENC28J60, index);
|
||||
}
|
||||
|
@ -57,8 +57,10 @@ typedef struct {
|
||||
*
|
||||
* @param[in] dev device descriptor
|
||||
* @param[in] params peripheral configuration to use
|
||||
* @param[in] index Index of @p params in a global parameter struct array.
|
||||
* If initialized manually, pass a unique identifier instead.
|
||||
*/
|
||||
void enc28j60_setup(enc28j60_t *dev, const enc28j60_params_t *params);
|
||||
void enc28j60_setup(enc28j60_t *dev, const enc28j60_params_t *params, uint8_t index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ typedef enum {
|
||||
NETDEV_AT86RF2XX,
|
||||
NETDEV_CC2538,
|
||||
NETDEV_DOSE,
|
||||
NETDEV_ENC28J60,
|
||||
NETDEV_MRF24J40,
|
||||
NETDEV_NRF802154,
|
||||
/* add more if needed */
|
||||
|
@ -218,7 +218,7 @@ void lwip_bootstrap(void)
|
||||
}
|
||||
#elif defined(MODULE_ENC28J60)
|
||||
for (unsigned i = 0; i < LWIP_NETIF_NUMOF; i++) {
|
||||
enc28j60_setup(&enc28j60_devs[i], &enc28j60_params[i]);
|
||||
enc28j60_setup(&enc28j60_devs[i], &enc28j60_params[i], i);
|
||||
if (_netif_add(&netif[0], &enc28j60_devs[i], lwip_netdev_init,
|
||||
tcpip_input) == NULL) {
|
||||
DEBUG("Could not add enc28j60 device\n");
|
||||
|
@ -60,7 +60,7 @@ void auto_init_enc28j60(void)
|
||||
LOG_DEBUG("[auto_init_netif] initializing enc28j60 #%u\n", i);
|
||||
|
||||
/* setup netdev device */
|
||||
enc28j60_setup(&dev[i], &enc28j60_params[i]);
|
||||
enc28j60_setup(&dev[i], &enc28j60_params[i], i);
|
||||
gnrc_netif_ethernet_create(&_netif[i], stack[i], ENC28J60_MAC_STACKSIZE,
|
||||
ENC28J60_MAC_PRIO, "enc28j60",
|
||||
(netdev_t *)&dev[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user