97 lines
2.6 KiB
C
97 lines
2.6 KiB
C
/**
|
|
* @file ethernetif.h
|
|
* @brief Ethernet interface header for CH390 + LwIP + FreeRTOS
|
|
*/
|
|
|
|
#ifndef __ETHERNETIF_H__
|
|
#define __ETHERNETIF_H__
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "lwip/netif.h"
|
|
#include "lwip/err.h"
|
|
#include "lwip/ip4_addr.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Ethernet interface state structure */
|
|
struct ethernetif {
|
|
uint16_t rx_len;
|
|
uint8_t rx_status;
|
|
};
|
|
|
|
/* Global network interface */
|
|
extern struct netif ch390_netif;
|
|
|
|
/**
|
|
* @brief Initialize the ethernet interface
|
|
* @param netif Network interface structure
|
|
* @return ERR_OK on success
|
|
*/
|
|
err_t ethernetif_init(struct netif *netif);
|
|
|
|
/**
|
|
* @brief Process received ethernet packets
|
|
* @param netif Network interface structure
|
|
* @note Call this from the LwIP task when packets are available
|
|
*/
|
|
void ethernetif_input(struct netif *netif);
|
|
|
|
/**
|
|
* @brief Initialize LwIP network interface with static IP
|
|
* @param ipaddr IP address
|
|
* @param netmask Network mask
|
|
* @param gw Gateway address
|
|
*/
|
|
void lwip_netif_init(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw);
|
|
|
|
/**
|
|
* @brief Initialize CH390 hardware without lwIP netif bring-up
|
|
*/
|
|
void ethernetif_diag_ch390_init(void);
|
|
|
|
/**
|
|
* @brief Poll CH390 status and update diagnostic globals without lwIP RX handoff
|
|
*/
|
|
void ethernetif_diag_poll_status(void);
|
|
|
|
/**
|
|
* @brief Check and handle CH390 interrupt status
|
|
* @note Call this from the LwIP task periodically or on interrupt
|
|
*/
|
|
void ethernetif_check_link(void);
|
|
void ethernetif_apply_runtime_netif_config(const ip4_addr_t *ipaddr,
|
|
const ip4_addr_t *netmask,
|
|
const ip4_addr_t *gw,
|
|
const uint8_t *mac);
|
|
void ethernetif_force_full_recovery(const ip4_addr_t *ipaddr,
|
|
const ip4_addr_t *netmask,
|
|
const ip4_addr_t *gw,
|
|
const uint8_t *mac);
|
|
void ethernetif_force_link_down(void);
|
|
uint16_t ethernetif_ch390_get_vendor_id(void);
|
|
uint16_t ethernetif_ch390_get_product_id(void);
|
|
uint8_t ethernetif_ch390_get_revision(void);
|
|
uint8_t ethernetif_ch390_health_ok(void);
|
|
uint8_t ethernetif_get_effective_mac(uint8_t *mac);
|
|
|
|
/**
|
|
* @brief Query whether physical Ethernet link is currently up
|
|
* @return 1 if link is up, 0 otherwise
|
|
*/
|
|
uint8_t ethernetif_link_is_up(void);
|
|
|
|
/**
|
|
* @brief Process all pending RX packets
|
|
* @note Call this from the LwIP task when RX interrupt occurs
|
|
*/
|
|
void ethernetif_poll(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __ETHERNETIF_H__ */
|