-
Notifications
You must be signed in to change notification settings - Fork 161
[eppp]: Support for transport via Ethernet (phy or emac) #622
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
Merged
david-cermak
merged 1 commit into
espressif:master
from
david-cermak:feat/eppp_emac2emac
Apr 30, 2025
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 hidden or 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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
idf_component_register(SRCS eppp_link.c eppp_sdio_slave.c eppp_sdio_host.c | ||
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "5.3") | ||
set(driver_deps esp_driver_gpio esp_driver_spi) | ||
else() | ||
set(driver_deps driver) | ||
endif() | ||
|
||
if(CONFIG_EPPP_LINK_DEVICE_ETH) | ||
set(transport_src eppp_eth.c) | ||
endif() | ||
|
||
if(CONFIG_EPPP_LINK_DEVICE_SDIO) | ||
set(transport_src eppp_sdio_slave.c eppp_sdio_host.c) | ||
endif() | ||
|
||
idf_component_register(SRCS eppp_link.c ${transport_src} | ||
INCLUDE_DIRS "include" | ||
PRIV_REQUIRES esp_netif esp_driver_spi esp_driver_gpio esp_timer driver) | ||
PRIV_REQUIRES esp_netif esp_timer esp_eth ${driver_deps}) | ||
|
||
if(CONFIG_EPPP_LINK_DEVICE_ETH) | ||
idf_component_get_property(ethernet_init espressif__ethernet_init COMPONENT_LIB) | ||
target_link_libraries(${COMPONENT_LIB} PRIVATE ${ethernet_init}) | ||
endif() |
This file contains hidden or 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 hidden or 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 hidden or 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,119 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include <string.h> | ||
#include <stdint.h> | ||
#include <inttypes.h> | ||
#include "esp_log.h" | ||
#include "esp_netif.h" | ||
#include "esp_check.h" | ||
#include "esp_event.h" | ||
#include "esp_mac.h" | ||
#include "eppp_link.h" | ||
#include "eppp_transport.h" | ||
#include "esp_eth_driver.h" | ||
#include "ethernet_init.h" | ||
#include "esp_eth_spec.h" | ||
|
||
typedef struct header { | ||
uint8_t dst[ETH_ADDR_LEN]; | ||
uint8_t src[ETH_ADDR_LEN]; | ||
uint16_t len; | ||
} __attribute__((packed)) header_t; | ||
|
||
static const char *TAG = "eppp_ethernet"; | ||
static bool s_is_connected = false; | ||
static esp_eth_handle_t *s_eth_handles = NULL; | ||
static uint8_t s_out_buffer[ETH_MAX_PACKET_SIZE]; | ||
static uint8_t s_their_mac[ETH_ADDR_LEN]; | ||
static uint8_t s_our_mac[ETH_ADDR_LEN]; | ||
|
||
static void event_handler(void *arg, esp_event_base_t event_base, | ||
int32_t event_id, void *event_data) | ||
{ | ||
switch (event_id) { | ||
case ETHERNET_EVENT_CONNECTED: | ||
ESP_LOGI(TAG, "Ethernet Link Up"); | ||
s_is_connected = true; | ||
break; | ||
case ETHERNET_EVENT_DISCONNECTED: | ||
ESP_LOGI(TAG, "Ethernet Link Down"); | ||
s_is_connected = false; | ||
break; | ||
case ETHERNET_EVENT_START: | ||
ESP_LOGI(TAG, "Ethernet Started"); | ||
break; | ||
case ETHERNET_EVENT_STOP: | ||
ESP_LOGI(TAG, "Ethernet Stopped"); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
static esp_err_t receive(esp_eth_handle_t h, uint8_t *buffer, uint32_t len, void *netif) | ||
{ | ||
header_t *head = (header_t *)buffer; | ||
size_t packet_len = head->len; | ||
if (len >= packet_len) { | ||
esp_err_t ret = esp_netif_receive(netif, buffer + ETH_HEADER_LEN, packet_len, NULL); | ||
free(buffer); | ||
return ret; | ||
} | ||
return ESP_FAIL; | ||
} | ||
|
||
__attribute__((weak)) esp_err_t eppp_transport_ethernet_init(esp_eth_handle_t *handle_array[]) | ||
david-cermak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
uint8_t eth_port_cnt = 0; | ||
ESP_RETURN_ON_ERROR(ethernet_init_all(handle_array, ð_port_cnt), TAG, "Failed to init common eth drivers"); | ||
ESP_RETURN_ON_FALSE(eth_port_cnt == 1, ESP_ERR_INVALID_ARG, TAG, "multiple Ethernet devices detected, please init only one"); | ||
return ESP_OK; | ||
} | ||
|
||
__attribute__((weak)) void eppp_transport_ethernet_deinit(esp_eth_handle_t *handle_array) | ||
{ | ||
ethernet_deinit_all(s_eth_handles); | ||
} | ||
|
||
|
||
esp_err_t eppp_transport_init(eppp_config_t *config, esp_netif_t *esp_netif) | ||
{ | ||
ESP_RETURN_ON_ERROR(eppp_transport_ethernet_init(&s_eth_handles), TAG, "Failed to initialize Ethernet driver"); | ||
ESP_RETURN_ON_ERROR(esp_eth_update_input_path(s_eth_handles[0], receive, esp_netif), TAG, "Failed to set Ethernet Rx callback"); | ||
sscanf(CONFIG_EPPP_LINK_ETHERNET_OUR_ADDRESS, "%2" PRIu8 ":%2" PRIu8 ":%2" PRIi8 ":%2" PRIu8 ":%2" PRIu8 ":%2" PRIu8, | ||
&s_our_mac[0], &s_our_mac[1], &s_our_mac[2], &s_our_mac[3], &s_our_mac[4], &s_our_mac[5]); | ||
|
||
sscanf(CONFIG_EPPP_LINK_ETHERNET_THEIR_ADDRESS, "%2" PRIu8 ":%2" PRIu8 ":%2" PRIi8 ":%2" PRIu8 ":%2" PRIu8 ":%2" PRIu8, | ||
&s_their_mac[0], &s_their_mac[1], &s_their_mac[2], &s_their_mac[3], &s_their_mac[4], &s_their_mac[5]); | ||
esp_eth_ioctl(s_eth_handles[0], ETH_CMD_S_MAC_ADDR, s_our_mac); | ||
ESP_RETURN_ON_ERROR(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler, NULL), TAG, "Failed to register Ethernet handlers"); | ||
euripedesrocha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ESP_RETURN_ON_ERROR(esp_eth_start(s_eth_handles[0]), TAG, "Failed to start Ethernet driver"); | ||
return ESP_OK; | ||
} | ||
|
||
void eppp_transport_deinit(void) | ||
{ | ||
esp_eth_stop(s_eth_handles[0]); | ||
eppp_transport_ethernet_deinit(s_eth_handles); | ||
} | ||
|
||
esp_err_t eppp_transport_tx(void *h, void *buffer, size_t len) | ||
{ | ||
if (!s_is_connected) { | ||
return ESP_FAIL; | ||
} | ||
// setup Ethernet header | ||
header_t *head = (header_t *)s_out_buffer; | ||
memcpy(head->dst, s_their_mac, ETH_ADDR_LEN); | ||
memcpy(head->src, s_our_mac, ETH_ADDR_LEN); | ||
head->len = len; | ||
// support only payloads with len <= ETH_MAX_PAYLOAD_LEN | ||
if (len > ETH_MAX_PAYLOAD_LEN) { | ||
return ESP_FAIL; | ||
} | ||
memcpy(s_out_buffer + ETH_HEADER_LEN, buffer, len); | ||
return esp_eth_transmit(s_eth_handles[0], s_out_buffer, len + ETH_HEADER_LEN); | ||
} | ||
david-cermak marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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,14 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
esp_err_t eppp_transport_init(eppp_config_t *config, esp_netif_t *esp_netif); | ||
|
||
esp_err_t eppp_transport_tx(void *h, void *buffer, size_t len); | ||
|
||
esp_err_t eppp_transport_rx(esp_netif_t *netif); | ||
|
||
void eppp_transport_deinit(void); |
This file contains hidden or 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 @@ | ||
CONFIG_IDF_TARGET="esp32" | ||
CONFIG_EPPP_LINK_DEVICE_ETH=y |
This file contains hidden or 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 @@ | ||
CONFIG_IDF_TARGET="esp32p4" | ||
CONFIG_EPPP_LINK_DEVICE_SDIO=y |
This file contains hidden or 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 @@ | ||
CONFIG_IDF_TARGET="esp32" | ||
CONFIG_EPPP_LINK_DEVICE_ETH=y |
This file contains hidden or 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 @@ | ||
CONFIG_IDF_TARGET="esp32c6" | ||
CONFIG_EPPP_LINK_DEVICE_SDIO=y |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.