RA Flexible Software Package Documentation  Release v5.2.0

 
NetX Duo Ethernet Driver (rm_netxduo_ether)

Overview

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

Please refer to the NetXDuo documentation for further details.

Features

Configuration

Configurations for Networking > NetX Duo Ethernet Driver (rm_netxduo_ether)

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_netxduo_ether_0 Module name.
IP MTUValue must be in the range [576, 1500] bytes.1500 IP MTU

Usage Notes

Calculating the Packet Size for an IP instance

In order to ensure that there is enough space to store an entire Ethernet frame, the packet pool used for receiving packets must have a payload size that is 32 bytes larger than the configured ether_cfg_t::ether_buffer_size. The extra 32 bytes is needed in order to ensure that the allocated packets are properly aligned to 32 bytes.

ether_cfg_t::ether_buffer_size is calcualted from the IP MTU using the following formula:

ceil(( rm_netxduo_ether_cfg_t::mtu + Ethernet Header (14) + Padding Bytes (2)) / 32 ) * 32

Examples

Basic Example

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

#define NETXDUO_EXAMPLE_IP_STACK_SIZE (2048U)
#define NETXDUO_EXAMPLE_ARP_CACHE_SIZE (2048U)
#define NETXDUO_EXAMPLE_PACKET_SIZE (1568U)
#define NETXDUO_EXAMPLE_PACKET_NUM (100U)
#define NETXDUO_EXAMPLE_PACKET_POOL_SIZE ((sizeof(NX_PACKET) + NETXDUO_EXAMPLE_PACKET_SIZE) * \
NETXDUO_EXAMPLE_PACKET_NUM)
#define NETXDUO_EXAMPLE_MAC_ADDRESS_MSW (0)
#define NETXDUO_EXAMPLE_MAC_ADDRESS_LSW (0)
static NX_IP g_ip;
static NX_PACKET_POOL g_packet_pool;
static uint8_t g_ip_stack_memory[NETXDUO_EXAMPLE_IP_STACK_SIZE] BSP_ALIGN_VARIABLE(4);
static uint8_t g_packet_pool_memory[NETXDUO_EXAMPLE_PACKET_POOL_SIZE] BSP_ALIGN_VARIABLE(4);
static uint8_t g_ip_arp_cache_memory[NETXDUO_EXAMPLE_ARP_CACHE_SIZE] BSP_ALIGN_VARIABLE(4);
static void rm_netxduo_ether0 (NX_IP_DRIVER * driver_req_ptr)
{
/* Pass the driver request and ethernet driver configuration to the NetX Duo Ether Driver. */
rm_netxduo_ether(driver_req_ptr, &g_netxduo_ether_instance);
}
void rm_netxduo_ether_example ()
{
UINT status;
nx_system_initialize();
/* Create a packet pool for the IP instance. */
status = nx_packet_pool_create(&g_packet_pool,
"Packet Pool",
NETXDUO_EXAMPLE_PACKET_SIZE,
&g_packet_pool_memory[0],
NETXDUO_EXAMPLE_PACKET_POOL_SIZE);
assert(NX_SUCCESS == status);
/* Create an IP instance using the rm_netxduo_ether driver and packet pool instance. */
status = nx_ip_create(&g_ip,
"IP Instance",
IP_ADDRESS(192, 168, 1, 2),
IP_ADDRESS(255, 255, 255, 0),
&g_packet_pool,
rm_netxduo_ether0,
&g_ip_stack_memory[0],
sizeof(g_ip_stack_memory),
0);
assert(NX_SUCCESS == status);
/* Enable all modules that are required by the application. */
status = nx_arp_enable(&g_ip, g_ip_arp_cache_memory, sizeof(g_ip_arp_cache_memory));
assert(NX_SUCCESS == status);
status = nx_tcp_enable(&g_ip);
assert(NX_SUCCESS == status);
status = nx_icmp_enable(&g_ip);
assert(NX_SUCCESS == status);
}

Changing MAC address Example

This is an example of changing the MAC address after an IP instance has already been created.

void rm_netxduo_ether_change_mac_address_example ()
{
ULONG driver_status;
UINT status;
/* Disable the link. */
status = nx_ip_driver_interface_direct_command(&g_ip, NX_LINK_DISABLE, 0, &driver_status);
assert(NX_SUCCESS == status);
/* Update the MAC address. */
status = nx_ip_interface_physical_address_set(&g_ip,
0,
NETXDUO_EXAMPLE_MAC_ADDRESS_MSW,
NETXDUO_EXAMPLE_MAC_ADDRESS_LSW,
NX_TRUE);
assert(NX_SUCCESS == status);
/* Re-enable the link. */
status = nx_ip_driver_interface_direct_command(&g_ip, NX_LINK_ENABLE, 0, &driver_status);
assert(NX_SUCCESS == status);
}