Skip to content

Commit 772c84b

Browse files
committed
fix(eppp): Update per review comments
1 parent 1778b90 commit 772c84b

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

components/eppp_link/CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "5.3")
2+
set(driver_deps esp_driver_gpio esp_driver_spi)
3+
else()
4+
set(driver_deps driver)
5+
endif()
6+
17
if(CONFIG_EPPP_LINK_DEVICE_ETH)
28
set(transport_src eppp_eth.c)
39
endif()
@@ -8,7 +14,7 @@ endif()
814

915
idf_component_register(SRCS eppp_link.c ${transport_src}
1016
INCLUDE_DIRS "include"
11-
PRIV_REQUIRES esp_netif esp_driver_spi esp_driver_gpio esp_timer driver esp_eth)
17+
PRIV_REQUIRES esp_netif esp_timer esp_eth ${driver_deps})
1218

1319
if(CONFIG_EPPP_LINK_DEVICE_ETH)
1420
idf_component_get_property(ethernet_init espressif__ethernet_init COMPONENT_LIB)

components/eppp_link/eppp_eth.c

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -65,45 +65,55 @@ static esp_err_t receive(esp_eth_handle_t h, uint8_t *buffer, uint32_t len, void
6565
return ESP_FAIL;
6666
}
6767

68-
esp_err_t eppp_transport_init(eppp_config_t *config, esp_netif_t *esp_netif)
68+
__attribute__((weak)) esp_err_t eppp_transport_ethernet_init(esp_eth_handle_t *handle_array[])
6969
{
7070
uint8_t eth_port_cnt = 0;
71-
ESP_ERROR_CHECK(ethernet_init_all(&s_eth_handles, &eth_port_cnt));
72-
if (eth_port_cnt > 1) {
73-
ESP_LOGW(TAG, "multiple Ethernet devices detected, the first initialized is to be used!");
74-
}
75-
ESP_ERROR_CHECK(esp_eth_update_input_path(s_eth_handles[0], receive, esp_netif));
71+
ESP_RETURN_ON_ERROR(ethernet_init_all(handle_array, &eth_port_cnt), TAG, "Failed to init common eth drivers");
72+
ESP_RETURN_ON_FALSE(eth_port_cnt > 1, ESP_ERR_INVALID_ARG, TAG, "multiple Ethernet devices detected, please init only one");
73+
return ESP_OK;
74+
}
75+
76+
__attribute__((weak)) void eppp_transport_ethernet_deinit(esp_eth_handle_t *handle_array)
77+
{
78+
ethernet_deinit_all(s_eth_handles);
79+
}
80+
81+
82+
esp_err_t eppp_transport_init(eppp_config_t *config, esp_netif_t *esp_netif)
83+
{
84+
ESP_RETURN_ON_ERROR(eppp_transport_ethernet_init(&s_eth_handles), TAG, "Failed to initialize Ethernet driver");
85+
ESP_RETURN_ON_ERROR(esp_eth_update_input_path(s_eth_handles[0], receive, esp_netif), TAG, "Failed to set Ethernet Rx callback");
7686
sscanf(CONFIG_EPPP_LINK_ETHERNET_OUR_ADDRESS, "%2" PRIu8 ":%2" PRIu8 ":%2" PRIi8 ":%2" PRIu8 ":%2" PRIu8 ":%2" PRIu8,
7787
&s_our_mac[0], &s_our_mac[1], &s_our_mac[2], &s_our_mac[3], &s_our_mac[4], &s_our_mac[5]);
7888

7989
sscanf(CONFIG_EPPP_LINK_ETHERNET_THEIR_ADDRESS, "%2" PRIu8 ":%2" PRIu8 ":%2" PRIi8 ":%2" PRIu8 ":%2" PRIu8 ":%2" PRIu8,
8090
&s_their_mac[0], &s_their_mac[1], &s_their_mac[2], &s_their_mac[3], &s_their_mac[4], &s_their_mac[5]);
8191
esp_eth_ioctl(s_eth_handles[0], ETH_CMD_S_MAC_ADDR, s_our_mac);
82-
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler, NULL));
83-
ESP_ERROR_CHECK(esp_eth_start(s_eth_handles[0]));
92+
ESP_RETURN_ON_ERROR(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, event_handler, NULL), TAG, "Failed to register Ethernet handlers");
93+
ESP_RETURN_ON_ERROR(esp_eth_start(s_eth_handles[0]), TAG, "Failed to start Ethernet driver");
8494
return ESP_OK;
8595
}
8696

8797
void eppp_transport_deinit(void)
8898
{
89-
ethernet_deinit_all(s_eth_handles);
99+
esp_eth_stop(s_eth_handles[0]);
100+
eppp_transport_ethernet_deinit(s_eth_handles);
90101
}
91102

92103
esp_err_t eppp_transport_tx(void *h, void *buffer, size_t len)
93104
{
94105
if (!s_is_connected) {
95-
return ESP_OK;
106+
return ESP_FAIL;
96107
}
97108
// setup Ethernet header
98109
header_t *head = (header_t *)s_out_buffer;
99110
memcpy(head->dst, s_their_mac, ETH_ADDR_LEN);
100111
memcpy(head->src, s_our_mac, ETH_ADDR_LEN);
101112
head->len = len;
102-
// handle frame size: ETH_MIN_PAYLOAD_LEN <= len <= ETH_MAX_PAYLOAD_LEN
103-
size_t frame_payload_len = len < ETH_MIN_PAYLOAD_LEN ? ETH_MIN_PAYLOAD_LEN : len;
104-
if (frame_payload_len > ETH_MAX_PAYLOAD_LEN) {
113+
// support only payloads with len <= ETH_MAX_PAYLOAD_LEN
114+
if (len > ETH_MAX_PAYLOAD_LEN) {
105115
return ESP_FAIL;
106116
}
107117
memcpy(s_out_buffer + ETH_HEADER_LEN, buffer, len);
108-
return esp_eth_transmit(s_eth_handles[0], s_out_buffer, frame_payload_len + ETH_HEADER_LEN);
118+
return esp_eth_transmit(s_eth_handles[0], s_out_buffer, len + ETH_HEADER_LEN);
109119
}

components/eppp_link/include/eppp_link.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef enum eppp_transport {
6363
EPPP_TRANSPORT_UART,
6464
EPPP_TRANSPORT_SPI,
6565
EPPP_TRANSPORT_SDIO,
66+
EPPP_TRANSPORT_ETHERNET,
6667
} eppp_transport_t;
6768

6869

0 commit comments

Comments
 (0)