Skip to main content

tkl_lwip | lwIP Ethernet Interface

tkl_lwip adapts the lwIP network stack to the underlying Ethernet hardware. It initializes the Ethernet interface and transmits and receives packets in lwIP pbuf form. The implementation lives in tkl_lwip.c, which TuyaOS generates and maintains; add your own code between the BEGIN and END markers so it survives regeneration.

You only need to adapt these interfaces when ENABLE_LIBLWIP is enabled.

The interface uses two opaque handle types:

TypeDescription
TKL_NETIF_HANDLEHandle to a network interface (void *).
TKL_PBUF_HANDLEHandle to a packet buffer in lwIP pbuf form (void *).

tkl_ethernetif_init

OPERATE_RET tkl_ethernetif_init(TKL_NETIF_HANDLE netif);

Initializes the Ethernet interface hardware.

Parameters:

Input/OutputNameDescription
[in]netifThe network interface to initialize.

Return value:

The lwIP error code: ERR_OK on success, other values on failure. See err_enum_t in lwip/err.h.

tkl_ethernetif_output

OPERATE_RET tkl_ethernetif_output(TKL_NETIF_HANDLE netif, TKL_PBUF_HANDLE p);

Sends a packet through the Ethernet interface.

Parameters:

Input/OutputNameDescription
[in]netifThe network interface to send the packet on.
[in]pThe packet to send, in pbuf form.

Return value:

The lwIP error code: ERR_OK on success, other values on failure. See err_enum_t in lwip/err.h.

tkl_ethernetif_recv

OPERATE_RET tkl_ethernetif_recv(TKL_NETIF_HANDLE netif, TKL_PBUF_HANDLE p);

Receives a packet from the Ethernet interface.

Parameters:

Input/OutputNameDescription
[in]netifThe network interface that received the packet.
[in]pThe received packet, in pbuf form.

Return value:

The lwIP error code: ERR_OK on success, other values on failure. See err_enum_t in lwip/err.h.