跳转到内容

EthernetPHY::LwipPlatform API

文档稀疏
符号
32
已记录
18
类型
1
继承关系
0
源码分支
main

14 / 32 个公开 API 符号没有说明。

共 1 个类型

类型目录
类

bsp::ethernet_phy::LwipPlatform

查看源码

借用 ETH 句柄与 IPhy 的 LwIP 平台状态机。

构造与析构

4

LwipPlatform

函数公开
        bsp::ethernet_phy::LwipPlatform::LwipPlatform (ETH_HandleTypeDef &eth, IPhy &phy) noexcept
      

只保存借用引用并初始化成员;不访问 HAL、PHY 或 RTOS,不失败。 eth STM32 ETH 句柄,借用,生命周期须覆盖本对象全部使用期。 phy 具体 PHY 的 IPhy 接口,借用,生命周期须覆盖本对象全部使用期。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:63

成员函数

10

init

函数公开
        bool bsp::ethernet_phy::LwipPlatform::init (struct netif &netif, const PhyLinkConfig &config) noexcept
      

一次性初始化:绑定 netif、置 link down,并把 config 原样交给 PHY 启动。 config 被原样传递给 phy_.start();本类不覆盖调用方配置,也不静默取能力交集, 不支持的模式由具体 IPhy::start 报错并令本函数返回 false。 netif 已建立的 LwIP 接口,仅借用,不拥有。 config 期望的链路配置,原样传递。 true 平台可用于 poll;false(未 prepare、重复 init 或 PHY 启动失败)。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:89

input

函数公开
        void bsp::ethernet_phy::LwipPlatform::input (struct netif &netif, osSemaphoreId_t rx_semaphore, ReceiveFunction receive_fn)
      

RX 线程入口:等待给定信号量,逐包提交给 LwIP,提交失败则释放。 未 prepare、信号量为空、回调为空或 netif.input 为空时直接返回,不访问 HAL; 本函数不创建/删除任务或信号量。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:110

poll

函数公开
        bool bsp::ethernet_phy::LwipPlatform::poll () noexcept
      

读取 PHY 链路并按需切换 MAC 与 netif link。 true 本轮状态已处理(含正常断链/协商);false 表示 PHY 读取或 MAC 配置/启停失败,链路保持在 down。本函数不重试,错误处理留给调用方。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:96

prepare

函数公开
        bool bsp::ethernet_phy::LwipPlatform::prepare () noexcept
      

创建本实例的静态 RX 互斥体;不注册 MSP、不启动 PHY。 true 已就绪(可重复调用,幂等);false 互斥体创建失败,调用方须终止初始化。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:77

receive

函数公开
        struct pbuf * bsp::ethernet_phy::LwipPlatform::receive (struct netif &netif, ReceiveFunction receive_fn)
      

在 RX 互斥体内执行原始接收回调,返回前释放互斥体。 收到的 pbuf,或 nullptr(未 prepare、空回调或取锁失败)。不得从 ISR 调用。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:102

startMacLocked

函数私有
        bool bsp::ethernet_phy::LwipPlatform::startMacLocked (std::uint32_t speed, std::uint32_t duplex) noexcept
      

配置并启动 MAC;前置:已持 core lock 且 MAC 已停止。 true 仅当 Get/Set/Start 全部成功。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:127

stopMacLocked

函数私有
        bool bsp::ethernet_phy::LwipPlatform::stopMacLocked () noexcept
      

停止 MAC;前置:已持 core lock,内部获取/释放 RX 互斥体。 true 已停止或本就未启动;false 取锁失败或 HAL_ETH_Stop_IT 失败, 此时保留 mac_started_(停止失败不得谎称已停)。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:121

成员变量

10

嵌套类型

1

ReceiveFunction

类型定义公开
        using bsp::ethernet_phy::LwipPlatform::ReceiveFunction = struct pbuf* (*)(struct netif*)
      

原始接收回调类型;负责 DMA/RX pool 读取,返回收到的 pbuf 或 nullptr。

bsp/ethernet/lwip_platform/LwipPlatform.hpp:56

其他公开符号

函数

1

bsp::ethernet_phy::anonymous_namespace{LwipPlatform.cpp}::mac_mode_for

函数
        bool bsp::ethernet_phy::anonymous_namespace{LwipPlatform.cpp}::mac_mode_for (PhyLinkState state, std::uint32_t &speed, std::uint32_t &duplex) noexcept
      

按符号映射四种 Up 状态的 MAC 速度/双工;非 Up 返回 false。

bsp/ethernet/lwip_platform/LwipPlatform.cpp:33

文件

2

bsp/ethernet/lwip_platform/LwipPlatform.cpp

文件

PHY 无关的 STM32 ETH MAC 与 LwIP netif 平台状态机实现。 SPDX-License-Identifier: GPL-3.0-or-later core lock 保护 netif link 变更与 MAC 转换(Get/Set/Start/Stop)。 RX 互斥体额外串行化 MAC 转换与底层 low_level_input 的 HAL_ETH_ReadData。 netif_set_link_down 在取得 RX 互斥体之前执行,netif_set_link_up 在释放之后执行, 避免 link 回调内发送数据造成重入。 锁序固定为 LwIP core lock → 本实例 RX 互斥体,且 PHY 的 start()/readLink() 始终在锁外:

bsp/ethernet/lwip_platform/LwipPlatform.cpp

bsp/ethernet/lwip_platform/LwipPlatform.hpp

文件

PHY 无关的 STM32 ETH MAC 与 LwIP netif 平台状态机。 SPDX-License-Identifier: GPL-3.0-or-later 只通过借用的 IPhy& 启动 PHY、查询链路并切换 MAC 速度/双工;不依赖具体 PHY 类型、地址、MDIO 总线或板级 MSP,器件复位与寄存器配置由具体 PHY 驱动负责。 不实现自动重试、遥测或工程错误处理策略;prepare/init/poll 返回 false 时由 调用方决定终止流程。 不拥有 ETH 句柄、PHY、netif 或 RX 信号量;这些由调用方创建并保证生命周期覆盖 接收线程与链路线程的全部运行期。 职责边界: 构造只保存引用并初始化成员,不访问 HAL、PHY 或 RTOS,不产生总线流量,不失败; 因此可安全地声明为静态存储期对象。 借用 eth 与 phy 必须在其整个使用期内有效;对象不被拷贝/移动(静态 mutex 控制块 地址属于本实例),也不提供 shutdown 或运行期替换 PHY。 析构不销毁 PHY、不停止 MAC、不操作 RTOS。 生命周期与所有权: 固定锁序为 LwIP core lock → 本实例 RX 互斥体。 PHY 的 start()/readLink() 始终在 core lock 外调用。 MAC 转换(Get/Set/Start/Stop)同时受 core lock 与 RX 互斥体保护;原始接收回调 在 RX 互斥体内执行,netif link 变更与 netif->input/pbuf_free 在 RX 互斥体外。 init()/poll() 只由同一 EthLink 线程串行调用,不得并发。 锁序与并发: 依赖 LWIP_TCPIP_CORE_LOCKING=1(在 .cpp 中以 #error 强制)。 编译前提:

bsp/ethernet/lwip_platform/LwipPlatform.hpp