mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #16544 from benpicco/drivers/ethos-multi
drivers/ethos: enable multiple instances
This commit is contained in:
commit
3eb6b602a4
2
drivers/ethos/Makefile.include
Normal file
2
drivers/ethos/Makefile.include
Normal file
@ -0,0 +1,2 @@
|
||||
USEMODULE_INCLUDES_ethos := $(LAST_MAKEFILEDIR)/include
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_ethos)
|
@ -26,11 +26,11 @@
|
||||
#include "periph/uart.h"
|
||||
#include "tsrb.h"
|
||||
#include "irq.h"
|
||||
#include "luid.h"
|
||||
|
||||
#include "net/netdev.h"
|
||||
#include "net/netdev/eth.h"
|
||||
#include "net/eui64.h"
|
||||
#include "net/eui_provider.h"
|
||||
#include "net/ethernet.h"
|
||||
|
||||
#ifdef USE_ETHOS_FOR_STDIO
|
||||
@ -53,8 +53,8 @@ static const netdev_driver_t netdev_driver_ethos;
|
||||
static const uint8_t _esc_esc[] = {ETHOS_ESC_CHAR, (ETHOS_ESC_CHAR ^ 0x20)};
|
||||
static const uint8_t _esc_delim[] = {ETHOS_ESC_CHAR, (ETHOS_FRAME_DELIMITER ^ 0x20)};
|
||||
|
||||
|
||||
void ethos_setup(ethos_t *dev, const ethos_params_t *params)
|
||||
void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t idx,
|
||||
void *inbuf, size_t inbuf_size)
|
||||
{
|
||||
dev->netdev.driver = &netdev_driver_ethos;
|
||||
dev->uart = params->uart;
|
||||
@ -64,10 +64,11 @@ void ethos_setup(ethos_t *dev, const ethos_params_t *params)
|
||||
dev->last_framesize = 0;
|
||||
dev->accept_new = true;
|
||||
|
||||
tsrb_init(&dev->inbuf, params->buf, params->bufsize);
|
||||
tsrb_init(&dev->inbuf, inbuf, inbuf_size);
|
||||
mutex_init(&dev->out_mutex);
|
||||
|
||||
luid_get_eui48((eui48_t *) &dev->mac_addr);
|
||||
netdev_register(&dev->netdev, NETDEV_ETHOS, idx);
|
||||
netdev_eui48_get(&dev->netdev, (eui48_t *)&dev->mac_addr);
|
||||
|
||||
uart_init(params->uart, params->baudrate, ethos_isr, (void*)dev);
|
||||
|
||||
|
49
drivers/ethos/include/ethos_params.h
Normal file
49
drivers/ethos/include/ethos_params.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_ethos
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Default configuration for the ethos device driver
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
#ifndef ETHOS_PARAMS_H
|
||||
#define ETHOS_PARAMS_H
|
||||
|
||||
#include "board.h"
|
||||
#include "ethos.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef ETHOS_PARAMS
|
||||
#define ETHOS_PARAMS { .uart = ETHOS_UART, \
|
||||
.baudrate = ETHOS_BAUDRATE }
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief ethos configuration
|
||||
*
|
||||
* The first element in this array will be used to multiplex stdio if
|
||||
* `stdio_ethos` is included.
|
||||
*/
|
||||
static const ethos_params_t ethos_params[] = {
|
||||
ETHOS_PARAMS
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ETHOS_PARAMS_H */
|
||||
/** @} */
|
@ -102,8 +102,6 @@ typedef struct {
|
||||
typedef struct {
|
||||
uart_t uart; /**< UART device to use */
|
||||
uint32_t baudrate; /**< baudrate to UART device */
|
||||
uint8_t *buf; /**< buffer for incoming packets */
|
||||
size_t bufsize; /**< size of ethos_params_t::buf */
|
||||
} ethos_params_t;
|
||||
|
||||
/**
|
||||
@ -117,8 +115,13 @@ typedef struct {
|
||||
*
|
||||
* @param[out] dev handle of the device to initialize
|
||||
* @param[in] params parameters for device initialization
|
||||
* @param[in] index Index of @p params in a global parameter struct array.
|
||||
* If initialized manually, pass a unique identifier instead.
|
||||
* @param[in] inbuf buffer to store a received frame in
|
||||
* @param[in] inbuf_size size of the receive buffer
|
||||
*/
|
||||
void ethos_setup(ethos_t *dev, const ethos_params_t *params);
|
||||
void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t index,
|
||||
void *inbuf, size_t inbuf_size);
|
||||
|
||||
/**
|
||||
* @brief Send frame over serial port using ethos' framing
|
||||
|
@ -320,6 +320,7 @@ typedef enum {
|
||||
NETDEV_SOCKET_ZEP,
|
||||
NETDEV_SX126X,
|
||||
NETDEV_CC2420,
|
||||
NETDEV_ETHOS,
|
||||
/* add more if needed */
|
||||
} netdev_type_t;
|
||||
/** @} */
|
||||
|
@ -20,15 +20,18 @@
|
||||
#include "log.h"
|
||||
#include "debug.h"
|
||||
#include "ethos.h"
|
||||
#include "ethos_params.h"
|
||||
#include "periph/uart.h"
|
||||
#include "net/gnrc/netif/ethernet.h"
|
||||
|
||||
#define ETHOS_NUM ARRAY_SIZE(ethos_params)
|
||||
|
||||
/**
|
||||
* @brief global ethos object, used by stdio_uart
|
||||
*/
|
||||
ethos_t ethos;
|
||||
ethos_t ethos[ETHOS_NUM];
|
||||
|
||||
static gnrc_netif_t _netif;
|
||||
static gnrc_netif_t _netif[ETHOS_NUM];
|
||||
|
||||
/**
|
||||
* @brief Define stack parameters for the MAC layer thread
|
||||
@ -42,24 +45,21 @@ static gnrc_netif_t _netif;
|
||||
/**
|
||||
* @brief Stacks for the MAC layer threads
|
||||
*/
|
||||
static char _netdev_eth_stack[ETHOS_MAC_STACKSIZE];
|
||||
static char _netdev_eth_stack[ETHOS_NUM][ETHOS_MAC_STACKSIZE];
|
||||
|
||||
static uint8_t _inbuf[2048];
|
||||
static uint8_t _inbuf[ETHOS_NUM][2048];
|
||||
|
||||
void auto_init_ethos(void)
|
||||
{
|
||||
LOG_DEBUG("[auto_init_netif] initializing ethos #0\n");
|
||||
for (unsigned i = 0; i < ETHOS_NUM; ++i) {
|
||||
LOG_DEBUG("[auto_init_netif] initializing ethos #%u\n", i);
|
||||
|
||||
/* setup netdev device */
|
||||
ethos_params_t p;
|
||||
p.uart = ETHOS_UART;
|
||||
p.baudrate = ETHOS_BAUDRATE;
|
||||
p.buf = _inbuf;
|
||||
p.bufsize = sizeof(_inbuf);
|
||||
ethos_setup(ðos, &p);
|
||||
/* setup netdev device */
|
||||
ethos_setup(ðos[i], ðos_params[i], i, _inbuf[i], sizeof(_inbuf[i]));
|
||||
|
||||
/* initialize netdev<->gnrc adapter state */
|
||||
gnrc_netif_ethernet_create(&_netif, _netdev_eth_stack, ETHOS_MAC_STACKSIZE,
|
||||
ETHOS_MAC_PRIO, "ethos", (netdev_t *)ðos);
|
||||
/* initialize netdev<->gnrc adapter state */
|
||||
gnrc_netif_ethernet_create(&_netif[i], _netdev_eth_stack[i], ETHOS_MAC_STACKSIZE,
|
||||
ETHOS_MAC_PRIO, "ethos", (netdev_t *)ðos[i]);
|
||||
}
|
||||
}
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user