Step 1: Ethernet up (IP101/RMII), DHCP, link and IP logged
- aes67_board: Waveshare ESP32-P4-ETH pin profile and EMAC + IP101 driver install (PHY addr 1, reset GPIO51, ref clock in on GPIO50). - aes67_net: Ethernet netif with DHCP client; logs link up/down (speed, duplex, MAC) and the DHCP lease. - Verified on board: 100 Mbps full duplex, DHCP lease in ~8 s, ping 0% loss, ~0.2 ms RTT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
idf_component_register(SRCS "aes67_net.c"
|
||||
INCLUDE_DIRS "include")
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES esp_eth esp_netif esp_event)
|
||||
|
||||
@@ -1,7 +1,58 @@
|
||||
#include "aes67_net.h"
|
||||
|
||||
// Stub (build step 0).
|
||||
esp_err_t aes67_net_init(void)
|
||||
#include "esp_eth.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_netif.h"
|
||||
|
||||
static const char *TAG = "net";
|
||||
|
||||
static void eth_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
{
|
||||
return ESP_OK;
|
||||
esp_eth_handle_t eth = *(esp_eth_handle_t *)data;
|
||||
|
||||
switch (id) {
|
||||
case ETHERNET_EVENT_CONNECTED: {
|
||||
uint8_t mac[6];
|
||||
eth_speed_t speed;
|
||||
eth_duplex_t duplex;
|
||||
esp_eth_ioctl(eth, ETH_CMD_G_MAC_ADDR, mac);
|
||||
esp_eth_ioctl(eth, ETH_CMD_G_SPEED, &speed);
|
||||
esp_eth_ioctl(eth, ETH_CMD_G_DUPLEX_MODE, &duplex);
|
||||
ESP_LOGI(TAG, "link up: %s Mbps %s duplex, MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
speed == ETH_SPEED_100M ? "100" : "10", duplex == ETH_DUPLEX_FULL ? "full" : "half",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
break;
|
||||
}
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
ESP_LOGW(TAG, "link down");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ip_event(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
{
|
||||
const ip_event_got_ip_t *ev = data;
|
||||
ESP_LOGI(TAG, "got IP " IPSTR " mask " IPSTR " gw " IPSTR,
|
||||
IP2STR(&ev->ip_info.ip), IP2STR(&ev->ip_info.netmask), IP2STR(&ev->ip_info.gw));
|
||||
}
|
||||
|
||||
esp_err_t aes67_net_init(esp_eth_handle_t eth)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
esp_err_t err = esp_event_loop_create_default();
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
esp_netif_t *netif = esp_netif_new(&netif_cfg);
|
||||
ESP_ERROR_CHECK(esp_netif_attach(netif, esp_eth_new_netif_glue(eth)));
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, ip_event, NULL));
|
||||
|
||||
return esp_eth_start(eth);
|
||||
}
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_eth_driver.h"
|
||||
|
||||
esp_err_t aes67_net_init(void);
|
||||
// Attach a netif (DHCP client) to the Ethernet driver and start it. Logs link and IP events.
|
||||
esp_err_t aes67_net_init(esp_eth_handle_t eth);
|
||||
|
||||
Reference in New Issue
Block a user