124 lines
2.7 KiB
C
124 lines
2.7 KiB
C
/**
|
|
* Network Manager Header
|
|
* Handles dual interface management for ESP32-P4-NANO:
|
|
* - ESP32-P4: Ethernet interface (LAN8720 RMII PHY)
|
|
* - ESP32-C6: Wi-Fi Access Point
|
|
*
|
|
* Enhanced with comprehensive debugging and error handling
|
|
*/
|
|
|
|
#ifndef NETWORK_MANAGER_H
|
|
#define NETWORK_MANAGER_H
|
|
|
|
#include <esp_err.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "esp_netif.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Network interface types
|
|
typedef enum {
|
|
NETIF_TYPE_ETHERNET,
|
|
NETIF_TYPE_WIFI_AP
|
|
} network_interface_type_t;
|
|
|
|
// Network statistics structure
|
|
typedef struct {
|
|
bool link_up;
|
|
uint32_t rx_packets;
|
|
uint32_t tx_packets;
|
|
uint32_t rx_bytes;
|
|
uint32_t tx_bytes;
|
|
uint32_t rx_errors;
|
|
uint32_t tx_errors;
|
|
} network_stats_t;
|
|
|
|
// GPIO Configuration for ESP32-P4-NANO with IP101GRI PHY
|
|
#define ETH_MDC_GPIO 31
|
|
#define ETH_MDIO_GPIO 52
|
|
#define ETH_PHY_RST_GPIO 51
|
|
#define ETH_PHY_ADDR 0
|
|
#define ETH_REF_CLK_GPIO 50
|
|
#define ETH_TX_EN_GPIO 49
|
|
#define ETH_TXD0_GPIO 34
|
|
#define ETH_TXD1_GPIO 35
|
|
#define ETH_RXD0_GPIO 30
|
|
#define ETH_RXD1_GPIO 29
|
|
#define ETH_CRS_DV_GPIO 28
|
|
|
|
// Function declarations
|
|
|
|
/**
|
|
* Enable/disable debug output
|
|
*/
|
|
esp_err_t network_manager_set_debug(bool enable);
|
|
|
|
/**
|
|
* Enable/disable matrix debug output
|
|
*/
|
|
esp_err_t network_manager_set_matrix_debug(bool enable);
|
|
|
|
/**
|
|
* Initialize Ethernet interface (LAN8720 RMII PHY)
|
|
*/
|
|
esp_err_t network_manager_init_ethernet(void);
|
|
|
|
/**
|
|
* Initialize Wi-Fi Access Point using ESP-Hosted-FG
|
|
*/
|
|
esp_err_t network_manager_init_wifi_ap(void);
|
|
|
|
/**
|
|
* Monitor Ethernet interface status with enhanced debugging
|
|
*/
|
|
void network_manager_monitor_ethernet(void);
|
|
|
|
/**
|
|
* Monitor Wi-Fi AP status with enhanced debugging
|
|
*/
|
|
void network_manager_monitor_wifi(void);
|
|
|
|
/**
|
|
* Update network statistics with debugging
|
|
*/
|
|
void network_manager_update_stats(void);
|
|
|
|
/**
|
|
* Get network statistics for specified interface
|
|
*/
|
|
esp_err_t network_manager_get_stats(network_interface_type_t type, network_stats_t *stats);
|
|
|
|
/**
|
|
* Get Ethernet interface handle
|
|
*/
|
|
esp_netif_t* network_manager_get_ethernet_netif(void);
|
|
|
|
/**
|
|
* Get Wi-Fi AP interface handle
|
|
*/
|
|
esp_netif_t* network_manager_get_wifi_ap_netif(void);
|
|
|
|
/**
|
|
* Check if Ethernet link is up
|
|
*/
|
|
bool network_manager_ethernet_link_up(void);
|
|
|
|
/**
|
|
* Get Ethernet MAC address
|
|
*/
|
|
esp_err_t network_manager_get_ethernet_mac(uint8_t *mac);
|
|
|
|
/**
|
|
* Get Wi-Fi AP MAC address
|
|
*/
|
|
esp_err_t network_manager_get_wifi_mac(uint8_t *mac);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // NETWORK_MANAGER_H
|