-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
driver/w5500: driver for the W5500 ethernet chip #20301
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2023 Stefan Schmidt | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @defgroup drivers_w5500 W5500 ethernet driver | ||
* @ingroup drivers_netdev | ||
* @brief Driver for W5500 ethernet devices | ||
* | ||
* This device driver only exposes the MACRAW mode of W5500 devices, so it does | ||
* not offer any support for the on-chip IPv4, UDP, and TCP capabilities of | ||
* these chips. In connection with RIOT we are only interested in the RAW | ||
* Ethernet packets, which we can use through netdev with any software network | ||
* stack provided by RIOT (e.g. GNRC). This enables W5500 devices to communicate | ||
* via IPv6, enables unlimited connections, and more... | ||
* | ||
* @note This driver can be used in polling or interrupt mode. | ||
* On some shields the interrupt line is not enabled by default, | ||
* you have to close the corresponding solder bridge to make the | ||
* interrupt mode work... | ||
* | ||
* @{ | ||
* | ||
* @file | ||
* @brief Interface definition for the W5500 device driver | ||
* | ||
* @author Stefan Schmidt <stemschmidt@gmail.com> | ||
*/ | ||
|
||
#ifndef W5500_H | ||
#define W5500_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "periph/spi.h" | ||
#include "periph/gpio.h" | ||
#include "net/netdev.h" | ||
#include "kernel_defines.h" | ||
#include "ztimer.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief W5500 device descriptor | ||
*/ | ||
typedef struct { | ||
spi_t spi; /**< SPI bus used */ | ||
spi_clk_t clk; /**< clock speed used on the selected SPI bus */ | ||
gpio_t cs; /**< pin connected to the chip select line */ | ||
gpio_t irq; /**< pin connected to the INT line */ | ||
uint32_t polling_interval_ms; /**< interval for polling, 0 if interrupt mode */ | ||
} w5500_params_t; | ||
|
||
/** | ||
* @brief Device descriptor for W5500 devices | ||
*/ | ||
typedef struct w5500 { | ||
netdev_t netdev; /**< extends the netdev structure */ | ||
w5500_params_t p; /**< device configuration parameters */ | ||
uint16_t frame_size; /**< size of the frame which has been send */ | ||
bool link_up; /**< used to prevent sending the same LINK event twice */ | ||
bool frame_sent; /**< indicates that the frame has been transmitted */ | ||
ztimer_t timerInstance; /**< stores the polling interval timer in polling mode */ | ||
} w5500_t; | ||
|
||
/** | ||
* @brief So the initial device setup | ||
* | ||
* This function pre-initializes the netdev structure, saves the configuration | ||
* parameters and finally initializes the SPI bus and the used GPIO pins. | ||
* | ||
* @param [out] dev the 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. | ||
*/ | ||
void w5500_setup(w5500_t *dev, const w5500_params_t *params, uint8_t index); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* W5500_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (C) 2023 Stefan Schmidt | ||
# | ||
# 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. | ||
# | ||
|
||
menuconfig MODULE_W5500 | ||
bool "W5500 Ethernet Adapter" | ||
depends on HAS_PERIPH_GPIO | ||
depends on HAS_PERIPH_GPIO_IRQ | ||
depends on HAS_PERIPH_SPI | ||
depends on TEST_KCONFIG | ||
select MODULE_LUID | ||
select MODULE_NETDEV_ETH | ||
select MODULE_PERIPH_GPIO | ||
select MODULE_PERIPH_GPIO_IRQ | ||
select MODULE_PERIPH_SPI | ||
|
||
config HAVE_W5500 | ||
bool | ||
select MODULE_W5500 if MODULE_NETDEV_DEFAULT | ||
help | ||
Indicates that a w5500 ethernet adapter is present. | ||
|
||
if MODULE_W5500 | ||
|
||
config W5500_USE_POLLING | ||
bool "Use driver in polling mode" | ||
default y | ||
|
||
if W5500_USE_POLLING | ||
|
||
config W5500_POLLING_INTERVAL | ||
int "Polling interval in ms" | ||
default 100 | ||
|
||
#endif # W5500_USE_POLLING | ||
|
||
config W5500_MAC_FILTER | ||
bool "Enable hardware MAC filter" | ||
default n | ||
|
||
config W5500_BROADCAST_FILTER | ||
bool "Enable hardware broadcast filter" | ||
default n | ||
|
||
config W5500_MULTICAST_FILTER | ||
bool "Enable hardware multicast filter" | ||
default n | ||
|
||
endif # MODULE_W5500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FEATURES_REQUIRED += periph_gpio_irq | ||
FEATURES_REQUIRED += periph_spi | ||
USEMODULE += luid | ||
USEMODULE += iolist | ||
USEMODULE += netdev_eth | ||
USEMODULE += ztimer_msec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
USEMODULE_INCLUDES_w5500 := $(LAST_MAKEFILEDIR)/include | ||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_w5500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2023 Stefan Schmidt | ||
* | ||
* 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_w5500 | ||
* @{ | ||
* | ||
* @file | ||
* @brief Default parameters for W5500 Ethernet devices | ||
* | ||
* @author Stefan Schmidt <stemschmidt@gmail.com> | ||
*/ | ||
|
||
#ifndef W5500_PARAMS_H | ||
#define W5500_PARAMS_H | ||
|
||
#include "board.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @name Default configuration parameters for the W5500 driver | ||
* @{ | ||
*/ | ||
#ifndef W5500_PARAM_SPI | ||
#define W5500_PARAM_SPI (SPI_DEV(0)) /**< Default SPI device */ | ||
#endif | ||
#ifndef W5500_PARAM_SPI_CLK | ||
#define W5500_PARAM_SPI_CLK (SPI_CLK_10MHZ) /**< Default SPI speed */ | ||
#endif | ||
#ifndef W5500_PARAM_CS | ||
#define W5500_PARAM_CS (GPIO_PIN(0, 27)) /**< Default SPI chip select pin */ | ||
#endif | ||
#ifndef W5500_PARAM_INT | ||
#define W5500_PARAM_INT GPIO_UNDEF /**< set to invalid */ | ||
#endif | ||
#ifndef CONFIG_W5500_POLLING_INTERVAL | ||
#define CONFIG_W5500_POLLING_INTERVAL 100u /**< default polling interval 100 ms */ | ||
#endif | ||
|
||
#ifndef W5500_PARAMS | ||
/** | ||
* @brief W5500 initialization parameters | ||
*/ | ||
|
||
#define W5500_PARAMS { .spi = W5500_PARAM_SPI, \ | ||
.clk = W5500_PARAM_SPI_CLK, \ | ||
.cs = W5500_PARAM_CS, \ | ||
.irq = W5500_PARAM_INT, \ | ||
.polling_interval_ms = CONFIG_W5500_POLLING_INTERVAL } | ||
#endif | ||
/** @} */ | ||
|
||
/** | ||
* @brief W5500 configuration | ||
*/ | ||
static const w5500_params_t w5500_params[] = { | ||
W5500_PARAMS | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* W5500_PARAMS_H */ | ||
/** @} */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered doing a compile-time check, so we don't even need to compile the polling code in if we have a IRQ pin connected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The w5500.h header is independent of the configuration, it does not include w5500_params.h. So I do not have the information W5500_PARAM_IRQ == GPIO_UNDEF available in the header