RA Flexible Software Package Documentation  Release v5.6.0

 
lwIP Ethernet Driver (rm_lwip_ether)

Functions

err_t rm_lwip_ether_init (struct netif *p_netif)
 
void rm_lwip_ether_callback (ether_callback_args_t *p_args)
 

Detailed Description

Overview

This module provides a lwIP driver that is implemented using the Ethernet Interface.

Please refer to the lwIP documentation for further details.

Features

Configuration

Configurations for Networking > lwIP Wrapper to r_ether (rm_lwip_ether)

ConfigurationOptionsDefaultDescription
RTOS
RX thread stacksizeMust be a positive integer1024 Stack size of RX thread.
RX thread priorityMust be a positive integer4 Priority of RX thread.
NameName must be a valid C symbolg_lwip_ether0 Module name.
MTUMust be an integer from 576 to 15001500 MTU size.
Netif flags
  • UP
  • BROADCAST
  • LINK_UP
  • ETHARP
  • ETHERNET
  • IGMP
  • MLD6
  • BROADCAST
  • ETHARP
Flags representing the capabilities of the Ethernet device
Zero-copy mode
  • Disable
  • Enable
Disable Enable or disable zero-copy mode.
RX buffer pool sizeMust be a positive integer10 Buffer pool size for zero-copy RX.
Link check intervalMust be a positive integer100 Interval for checking link status.

Usage Notes

Limitations

Examples

Basic Example

This is a basic example of minimal use of the lwIP Ether Driver in an application.

#include "lwip/tcp.h"
#include "lwip/timeouts.h"
#include "lwip/init.h"
#include "lwip/ip4.h"
#define LWIP_EXAMPLE_PORT_NUMBER 9000
/* TCP callback functions. */
static err_t lwip_example_connected_callback(void * arg, struct tcp_pcb * tpcb, err_t err);
err_t lwip_example_sent_callback(void * arg, struct tcp_pcb * tpcb, u16_t len);
volatile uint8_t g_lwip_example_connected_flag;
volatile uint8_t g_lwip_example_sent_flag;
void rm_lwip_ether_example () {
struct netif netif;
struct tcp_pcb * pcb = NULL;
ip_addr_t ipaddr;
ip_addr_t netmask;
ip_addr_t gw;
ip_addr_t server_ip;
const char data[] = "lwIP Hello world.";
/* Initializing lwIP core. */
lwip_init();
/* Set ip address of the board. */
IP4_ADDR(&ipaddr, 192, 168, 10, 4);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 10, 1);
/* Initialize netif. Please pass rm_lwip_ether_init() function and the instance of rm_lwip_ether to netif_add(). */
netif_add(&netif, &ipaddr, &netmask, &gw, &g_lwip_ether_instance, rm_lwip_ether_init, netif_input);
/* Set netif as default and enable */
netif_set_default(&netif);
netif_set_up(&netif);
netif_set_link_up(&netif);
/* Create a pcb for client. */
pcb = tcp_new();
/* Start connection to the server. */
g_lwip_example_connected_flag = false;
IP4_ADDR(&server_ip, 192, 168, 10, 1);
tcp_connect(pcb, &server_ip, LWIP_EXAMPLE_PORT_NUMBER, lwip_example_connected_callback);
/* Waiting for connection to be established. */
while (false == g_lwip_example_connected_flag)
{
sys_check_timeouts();
}
/* Set callback for sending complete. */
g_lwip_example_sent_flag = false;
tcp_sent(pcb, lwip_example_sent_callback);
/* Send a message. */
tcp_write(pcb, data, sizeof(data), TCP_WRITE_FLAG_COPY);
while (false == g_lwip_example_sent_flag)
{
sys_check_timeouts();
}
/* Close TCP client and netif. */
tcp_close(pcb);
netif_remove(&netif);
}
err_t lwip_example_connected_callback (void * arg, struct tcp_pcb * tpcb, err_t err) {
g_lwip_example_connected_flag = true;
return err;
}
err_t lwip_example_sent_callback (void * arg, struct tcp_pcb * tpcb, u16_t len) {
g_lwip_example_sent_flag = true;
return ERR_OK;
}

Function Documentation

◆ rm_lwip_ether_init()

err_t rm_lwip_ether_init ( struct netif *  p_netif)

Initialize ethernet hardware and lwIP network interface. This function is passed to netif_add()

◆ rm_lwip_ether_callback()

void rm_lwip_ether_callback ( ether_callback_args_t p_args)

Callback of Ethernet interrupt subroutine. This function is set to ethernet driver callback by configurator.