merge_back #1

Merged
eyck merged 4 commits from Airbus/ADS-VP-Demo-FW:merge_back into main 2026-02-04 06:33:30 +00:00
8 changed files with 500 additions and 537 deletions

10
.clang-format Normal file
View File

@@ -0,0 +1,10 @@
BasedOnStyle: Microsoft
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: DontAlign
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
IndentCaseLabels: true
PointerAlignment: Left
BraceWrapping:
AfterCaseLabel: true

View File

@@ -6,7 +6,7 @@
"comment": "clang-format" "comment": "clang-format"
} }
], ],
"editor.formatOnSave": false, "editor.formatOnSave": true,
"clangd.arguments": [ "clangd.arguments": [
"--pretty", "--pretty",
"--background-index", "--background-index",

View File

@@ -15,7 +15,7 @@
#include "platform.h" #include "platform.h"
#define TICKNUM_PER_SECOND 32768 #define TICKNUM_PER_SECOND 32768
#define TICKNUM_PER_TIMER (TICKNUM_PER_SECOND / 1000) // ~ 1ms timer #define TICKNUM_PER_TIMER (TICKNUM_PER_SECOND / 100) // ~ 1ms timer
static inline int hwtimer_init(void) { static inline int hwtimer_init(void) {
uint64_t time = get_aclint_mtime(aclint); uint64_t time = get_aclint_mtime(aclint);

View File

@@ -41,7 +41,6 @@ extern int register_irq_handler(unsigned irq_num, void (*handler)());
#define NX_LINK_MTU 1514 #define NX_LINK_MTU 1514
#define NX_MAX_PACKET_SIZE 1536 #define NX_MAX_PACKET_SIZE 1536
/* Define Ethernet address format. This is prepended to the incoming IP /* Define Ethernet address format. This is prepended to the incoming IP
and ARP/RARP messages. The frame beginning is 14 bytes, but for speed and ARP/RARP messages. The frame beginning is 14 bytes, but for speed
purposes, we are going to assume there are 16 bytes free in front of the purposes, we are going to assume there are 16 bytes free in front of the
@@ -71,7 +70,6 @@ extern int register_irq_handler(unsigned irq_num, void (*handler)());
const ULONG mnrs_mac_address_msw = 0x0200; const ULONG mnrs_mac_address_msw = 0x0200;
const ULONG mnrs_mac_address_lsw = 0x00334450; const ULONG mnrs_mac_address_lsw = 0x00334450;
/* Define driver prototypes. */ /* Define driver prototypes. */
VOID _nx_mnrs_network_driver(NX_IP_DRIVER *driver_req_ptr); VOID _nx_mnrs_network_driver(NX_IP_DRIVER *driver_req_ptr);
@@ -82,7 +80,6 @@ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac);
VOID _nx_mnrs_eth_recv_packet_eth0(VOID); VOID _nx_mnrs_eth_recv_packet_eth0(VOID);
VOID _nx_mnrs_eth_recv_packet_eth1(VOID); VOID _nx_mnrs_eth_recv_packet_eth1(VOID);
#define NX_MAX_MNRS_INTERFACES 4
#define NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES 3 #define NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES 3
typedef struct MAC_ADDRESS_STRUCT typedef struct MAC_ADDRESS_STRUCT
{ {
@@ -118,7 +115,7 @@ typedef struct _nx_mnrs_network_driver_instance_type
/* In this example, there are four instances of the MNRS ETH driver. /* In this example, there are four instances of the MNRS ETH driver.
Therefore an array of four driver instances are created to keep track of Therefore an array of four driver instances are created to keep track of
the interface information of each driver. */ the interface information of each driver. */
static _nx_mnrs_network_driver_instance_type nx_mnrs_driver[NX_MAX_MNRS_INTERFACES]; static _nx_mnrs_network_driver_instance_type nx_mnrs_driver[NX_MAX_PHYSICAL_INTERFACES];
/**************************************************************************/ /**************************************************************************/
@@ -172,14 +169,14 @@ static _nx_mnrs_network_driver_instance_type nx_mnrs_driver[NX_MAX_MNRS_INTERFAC
/* resulting in version 6.4.0 */ /* resulting in version 6.4.0 */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
VOID _nx_mnrs_network_driver(NX_IP_DRIVER *driver_req_ptr) VOID _nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
{ {
UINT i = 0; UINT i = 0;
NX_IP *ip_ptr; NX_IP* ip_ptr;
NX_PACKET *packet_ptr; NX_PACKET* packet_ptr;
NX_INTERFACE *interface_ptr; NX_INTERFACE* interface_ptr;
UINT interface_index; UINT interface_index;
USHORT ether_type; USHORT ether_type;
#ifndef NX_ENABLE_VLAN #ifndef NX_ENABLE_VLAN
ULONG *ethernet_frame_ptr; ULONG *ethernet_frame_ptr;
#endif /* NX_ENABLE_VLAN */ #endif /* NX_ENABLE_VLAN */
@@ -201,9 +198,9 @@ ULONG *ethernet_frame_ptr;
/* Obtain the index number of the network interface. */ /* Obtain the index number of the network interface. */
interface_index = interface_ptr -> nx_interface_index; interface_index = interface_ptr -> nx_interface_index;
/* Find out the driver interface if the driver command is not ATTACH. */ /* Find out the driver interface if the driver command is not ATTACH. */
if (driver_req_ptr -> nx_ip_driver_command != NX_LINK_INTERFACE_ATTACH) if (driver_req_ptr->nx_ip_driver_command != NX_LINK_INTERFACE_ATTACH)
{ {
for (i = 0; i < NX_MAX_MNRS_INTERFACES; i++) for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
{ {
if (nx_mnrs_driver[i].nx_mnrs_network_driver_in_use == 0) if (nx_mnrs_driver[i].nx_mnrs_network_driver_in_use == 0)
{ {
@@ -218,20 +215,20 @@ ULONG *ethernet_frame_ptr;
break; break;
} }
} }
if (i == NX_MAX_MNRS_INTERFACES) if (i == NX_MAX_PHYSICAL_INTERFACES)
{ {
driver_req_ptr -> nx_ip_driver_status = NX_INVALID_INTERFACE; driver_req_ptr->nx_ip_driver_status = NX_INVALID_INTERFACE;
return; return;
} }
} }
/* Process according to the driver request type in the IP control /* Process according to the driver request type in the IP control
block. */ block. */
switch (driver_req_ptr -> nx_ip_driver_command) switch (driver_req_ptr->nx_ip_driver_command)
{ {
case NX_LINK_INTERFACE_ATTACH: case NX_LINK_INTERFACE_ATTACH:
{ {
/* Find an available driver instance to attach the interface. */ /* Find an available driver instance to attach the interface. */
for (i = 0; i < NX_MAX_MNRS_INTERFACES; i++) for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
{ {
if (nx_mnrs_driver[i].nx_mnrs_network_driver_in_use == 0) if (nx_mnrs_driver[i].nx_mnrs_network_driver_in_use == 0)
{ {
@@ -239,7 +236,7 @@ ULONG *ethernet_frame_ptr;
} }
} }
/* An available entry is found. */ /* An available entry is found. */
if (i < NX_MAX_MNRS_INTERFACES) if (i < NX_MAX_PHYSICAL_INTERFACES)
{ {
/* Set the IN USE flag.*/ /* Set the IN USE flag.*/
nx_mnrs_driver[i].nx_mnrs_network_driver_in_use = 1; nx_mnrs_driver[i].nx_mnrs_network_driver_in_use = 1;
@@ -252,7 +249,8 @@ ULONG *ethernet_frame_ptr;
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw = mnrs_mac_address_msw; nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw = mnrs_mac_address_msw;
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw = mnrs_mac_address_lsw + i; nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw = mnrs_mac_address_lsw + i;
/* Record the peripheral address */ /* Record the peripheral address */
switch(i) { switch (i)
{
case 0: case 0:
nx_mnrs_driver[i].ethmac = ethmac0; nx_mnrs_driver[i].ethmac = ethmac0;
break; break;
@@ -274,7 +272,7 @@ ULONG *ethernet_frame_ptr;
} }
else else
{ {
driver_req_ptr -> nx_ip_driver_status = NX_INVALID_INTERFACE; driver_req_ptr->nx_ip_driver_status = NX_INVALID_INTERFACE;
} }
break; break;
} }
@@ -288,15 +286,16 @@ ULONG *ethernet_frame_ptr;
{ {
/* Device driver shall initialize the Ethernet Controller here. */ /* Device driver shall initialize the Ethernet Controller here. */
#ifdef NX_DEBUG #ifdef NX_DEBUG
printf("NetX MNRS ETH Driver Initialization - %s\n", ip_ptr -> nx_ip_name); printf("NetX MNRS ETH Driver Initialization - %s\n", ip_ptr->nx_ip_name);
printf(" IP Address =%08X\n", ip_ptr -> nx_ip_address); printf(" IP Address =%08X\n", ip_ptr->nx_ip_address);
#endif #endif
// enable TX & RX path // enable TX & RX path
set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac, set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac,
get_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac) & ~(ETHMAC_MAC_CTRL_TX_FLUSH(1)| ETHMAC_MAC_CTRL_RX_FLUSH(1))); get_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac) &
~(ETHMAC_MAC_CTRL_TX_FLUSH(1) | ETHMAC_MAC_CTRL_RX_FLUSH(1)));
register_irq_handler(ETH0_IRQ, &_nx_mnrs_eth_recv_packet_eth0); register_irq_handler(ETH0_IRQ, &_nx_mnrs_eth_recv_packet_eth0);
register_irq_handler(ETH1_IRQ, &_nx_mnrs_eth_recv_packet_eth1); register_irq_handler(ETH1_IRQ, &_nx_mnrs_eth_recv_packet_eth1);
csr_read_set_bits_mie(1<<ETH0_IRQ | 1<<ETH1_IRQ); csr_read_set_bits_mie(1 << ETH0_IRQ | 1 << ETH1_IRQ);
set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 1); set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 1);
/* Once the Ethernet controller is initialized, the driver needs to /* Once the Ethernet controller is initialized, the driver needs to
configure the NetX Interface Control block, as outlined below. */ configure the NetX Interface Control block, as outlined below. */
@@ -308,9 +307,11 @@ ULONG *ethernet_frame_ptr;
/* For this MNRS ETH driver, the MAC address is constructed by /* For this MNRS ETH driver, the MAC address is constructed by
incrementing a base lsw value, to simulate multiple nodes on the incrementing a base lsw value, to simulate multiple nodes on the
ethernet. */ ethernet. */
nx_ip_interface_physical_address_set(ip_ptr, interface_index, nx_ip_interface_physical_address_set(ip_ptr,
interface_index,
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw, nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw,
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw, NX_FALSE); nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw,
NX_FALSE);
/* Indicate to the IP software that IP to physical mapping is required. */ /* Indicate to the IP software that IP to physical mapping is required. */
nx_ip_interface_address_mapping_configure(ip_ptr, interface_index, NX_TRUE); nx_ip_interface_address_mapping_configure(ip_ptr, interface_index, NX_TRUE);
break; break;
@@ -319,13 +320,14 @@ ULONG *ethernet_frame_ptr;
{ {
// disable TX & RX path // disable TX & RX path
set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 0); set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 0);
csr_read_clr_bits_mie(1<<ETH0_IRQ | 1<<ETH1_IRQ); csr_read_clr_bits_mie(1 << ETH0_IRQ | 1 << ETH1_IRQ);
register_irq_handler(ETH0_IRQ, NULL); register_irq_handler(ETH0_IRQ, NULL);
register_irq_handler(ETH1_IRQ, NULL); register_irq_handler(ETH1_IRQ, NULL);
// set_ethmac_mac_ctrl_tx_flush(nx_mnrs_driver[i].ethmac, 1); // set_ethmac_mac_ctrl_tx_flush(nx_mnrs_driver[i].ethmac, 1);
// set_ethmac_mac_ctrl_rx_flush(nx_mnrs_driver[i].ethmac, 1); // set_ethmac_mac_ctrl_rx_flush(nx_mnrs_driver[i].ethmac, 1);
set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac, set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac,
get_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac) | ETHMAC_MAC_CTRL_TX_FLUSH(1)| ETHMAC_MAC_CTRL_RX_FLUSH(1)); get_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac) | ETHMAC_MAC_CTRL_TX_FLUSH(1) |
ETHMAC_MAC_CTRL_RX_FLUSH(1));
/* Zero out the driver instance. */ /* Zero out the driver instance. */
memset(&(nx_mnrs_driver[i]), 0, sizeof(_nx_mnrs_network_driver_instance_type)); memset(&(nx_mnrs_driver[i]), 0, sizeof(_nx_mnrs_network_driver_instance_type));
break; break;
@@ -338,9 +340,9 @@ ULONG *ethernet_frame_ptr;
// set_ethmac_int_ctrl_reg_tx_free_intr_enable(nx_mnrs_driver[i].ethmac, 1); // set_ethmac_int_ctrl_reg_tx_free_intr_enable(nx_mnrs_driver[i].ethmac, 1);
set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 1); set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 1);
/* In the MNRS ETH driver, just set the enabled flag. */ /* In the MNRS ETH driver, just set the enabled flag. */
interface_ptr -> nx_interface_link_up = NX_TRUE; interface_ptr->nx_interface_link_up = NX_TRUE;
#ifdef NX_DEBUG #ifdef NX_DEBUG
printf("NetX MNRS ETH Driver Link Enabled - %s\n", ip_ptr -> nx_ip_name); printf("NetX MNRS ETH Driver Link Enabled - %s\n", ip_ptr->nx_ip_name);
#endif #endif
break; break;
} }
@@ -354,9 +356,9 @@ ULONG *ethernet_frame_ptr;
// set_ethmac_int_ctrl_reg_tx_free_intr_enable(nx_mnrs_driver[i].ethmac, 0); // set_ethmac_int_ctrl_reg_tx_free_intr_enable(nx_mnrs_driver[i].ethmac, 0);
set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 0); set_ethmac_mac_intr_rx_data_avail_intr_enable(nx_mnrs_driver[i].ethmac, 0);
/* In the MNRS ETH driver, just clear the enabled flag. */ /* In the MNRS ETH driver, just clear the enabled flag. */
interface_ptr -> nx_interface_link_up = NX_FALSE; interface_ptr->nx_interface_link_up = NX_FALSE;
#ifdef NX_DEBUG #ifdef NX_DEBUG
printf("NetX MNRS ETH Driver Link Disabled - %s\n", ip_ptr -> nx_ip_name); printf("NetX MNRS ETH Driver Link Disabled - %s\n", ip_ptr->nx_ip_name);
#endif #endif
break; break;
} }
@@ -375,21 +377,21 @@ ULONG *ethernet_frame_ptr;
The following sequence illustrates this process. The following sequence illustrates this process.
*/ */
/* Place the ethernet frame at the front of the packet. */ /* Place the ethernet frame at the front of the packet. */
packet_ptr = driver_req_ptr -> nx_ip_driver_packet; packet_ptr = driver_req_ptr->nx_ip_driver_packet;
/* Get Ethernet type. */ /* Get Ethernet type. */
if (driver_req_ptr -> nx_ip_driver_command == NX_LINK_ARP_SEND) if (driver_req_ptr->nx_ip_driver_command == NX_LINK_ARP_SEND)
{ {
ether_type = NX_ETHERNET_ARP; ether_type = NX_ETHERNET_ARP;
} }
else if (driver_req_ptr -> nx_ip_driver_command == NX_LINK_ARP_RESPONSE_SEND) else if (driver_req_ptr->nx_ip_driver_command == NX_LINK_ARP_RESPONSE_SEND)
{ {
ether_type = NX_ETHERNET_ARP; ether_type = NX_ETHERNET_ARP;
} }
else if (driver_req_ptr -> nx_ip_driver_command == NX_LINK_RARP_SEND) else if (driver_req_ptr->nx_ip_driver_command == NX_LINK_RARP_SEND)
{ {
ether_type = NX_ETHERNET_RARP; ether_type = NX_ETHERNET_RARP;
} }
else if (packet_ptr -> nx_packet_ip_version == 4) else if (packet_ptr->nx_packet_ip_version == 4)
{ {
ether_type = NX_ETHERNET_IP; ether_type = NX_ETHERNET_IP;
} }
@@ -400,9 +402,10 @@ ULONG *ethernet_frame_ptr;
#ifdef NX_ENABLE_VLAN #ifdef NX_ENABLE_VLAN
/* Add Ethernet header. */ /* Add Ethernet header. */
if (nx_link_ethernet_header_add(ip_ptr, if (nx_link_ethernet_header_add(ip_ptr,
driver_req_ptr -> nx_ip_driver_interface -> nx_interface_index, packet_ptr, driver_req_ptr->nx_ip_driver_interface->nx_interface_index,
driver_req_ptr -> nx_ip_driver_physical_address_msw, packet_ptr,
driver_req_ptr -> nx_ip_driver_physical_address_lsw, driver_req_ptr->nx_ip_driver_physical_address_msw,
driver_req_ptr->nx_ip_driver_physical_address_lsw,
(UINT)ether_type)) (UINT)ether_type))
{ {
/* Release the packet. */ /* Release the packet. */
@@ -411,19 +414,19 @@ ULONG *ethernet_frame_ptr;
} }
#else #else
/* Adjust the prepend pointer. */ /* Adjust the prepend pointer. */
packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_prepend_ptr - NX_ETHERNET_SIZE; packet_ptr->nx_packet_prepend_ptr = packet_ptr->nx_packet_prepend_ptr - NX_ETHERNET_SIZE;
/* Adjust the packet length. */ /* Adjust the packet length. */
packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length + NX_ETHERNET_SIZE; packet_ptr->nx_packet_length = packet_ptr->nx_packet_length + NX_ETHERNET_SIZE;
/* Setup the ethernet frame pointer to build the ethernet frame. Backup another 2 /* Setup the ethernet frame pointer to build the ethernet frame. Backup another 2
bytes to get 32-bit word alignment. */ bytes to get 32-bit word alignment. */
/*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
ethernet_frame_ptr = (ULONG *)(packet_ptr -> nx_packet_prepend_ptr - 2); ethernet_frame_ptr = (ULONG*)(packet_ptr->nx_packet_prepend_ptr - 2);
/* Build the ethernet frame. */ /* Build the ethernet frame. */
*ethernet_frame_ptr = driver_req_ptr -> nx_ip_driver_physical_address_msw; *ethernet_frame_ptr = driver_req_ptr->nx_ip_driver_physical_address_msw;
*(ethernet_frame_ptr + 1) = driver_req_ptr -> nx_ip_driver_physical_address_lsw; *(ethernet_frame_ptr + 1) = driver_req_ptr->nx_ip_driver_physical_address_lsw;
*(ethernet_frame_ptr + 2) = (interface_ptr -> nx_interface_physical_address_msw << 16) | *(ethernet_frame_ptr + 2) = (interface_ptr->nx_interface_physical_address_msw << 16) |
(interface_ptr -> nx_interface_physical_address_lsw >> 16); (interface_ptr->nx_interface_physical_address_lsw >> 16);
*(ethernet_frame_ptr + 3) = (interface_ptr -> nx_interface_physical_address_lsw << 16) | ether_type; *(ethernet_frame_ptr + 3) = (interface_ptr->nx_interface_physical_address_lsw << 16) | ether_type;
/* Endian swapping if NX_LITTLE_ENDIAN is defined. */ /* Endian swapping if NX_LITTLE_ENDIAN is defined. */
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr)); NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr));
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 1)); NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 1));
@@ -431,7 +434,7 @@ ULONG *ethernet_frame_ptr;
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 3)); NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 3));
#endif /* NX_ENABLE_VLAN */ #endif /* NX_ENABLE_VLAN */
#ifdef NX_DEBUG_PACKET #ifdef NX_DEBUG_PACKET
printf("NetX MNRS ETH Driver Packet Send - %s\n", ip_ptr -> nx_ip_name); printf("NetX MNRS ETH Driver Packet Send - %s\n", ip_ptr->nx_ip_name);
#endif #endif
/* At this point, the packet is a complete Ethernet frame, ready to be transmitted. /* At this point, the packet is a complete Ethernet frame, ready to be transmitted.
The driver shall call the actual Ethernet transmit routine and put the packet The driver shall call the actual Ethernet transmit routine and put the packet
@@ -445,7 +448,7 @@ ULONG *ethernet_frame_ptr;
case NX_LINK_RAW_PACKET_SEND: case NX_LINK_RAW_PACKET_SEND:
{ {
/* Send raw packet out directly. */ /* Send raw packet out directly. */
_nx_mnrs_network_driver_output(driver_req_ptr -> nx_ip_driver_packet, i); _nx_mnrs_network_driver_output(driver_req_ptr->nx_ip_driver_packet, i);
break; break;
} }
#endif /* NX_ENABLE_VLAN */ #endif /* NX_ENABLE_VLAN */
@@ -469,14 +472,16 @@ ULONG *ethernet_frame_ptr;
if (nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw == 0 && if (nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw == 0 &&
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw == 0) nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw == 0)
{ {
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw = driver_req_ptr -> nx_ip_driver_physical_address_msw; nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw =
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw = driver_req_ptr -> nx_ip_driver_physical_address_lsw; driver_req_ptr->nx_ip_driver_physical_address_msw;
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw =
driver_req_ptr->nx_ip_driver_physical_address_lsw;
break; break;
} }
} }
if (mcast_index == NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES) if (mcast_index == NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES)
{ {
driver_req_ptr -> nx_ip_driver_status = NX_NO_MORE_ENTRIES; driver_req_ptr->nx_ip_driver_status = NX_NO_MORE_ENTRIES;
} }
break; break;
} }
@@ -493,8 +498,10 @@ ULONG *ethernet_frame_ptr;
multicast MAC addresses by a simple look up table. */ multicast MAC addresses by a simple look up table. */
for (mcast_index = 0; mcast_index < NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES; mcast_index++) for (mcast_index = 0; mcast_index < NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES; mcast_index++)
{ {
if (nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw == driver_req_ptr -> nx_ip_driver_physical_address_msw && if (nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw ==
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw == driver_req_ptr -> nx_ip_driver_physical_address_lsw) driver_req_ptr->nx_ip_driver_physical_address_msw &&
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw ==
driver_req_ptr->nx_ip_driver_physical_address_lsw)
{ {
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw = 0; nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw = 0;
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw = 0; nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw = 0;
@@ -503,56 +510,56 @@ ULONG *ethernet_frame_ptr;
} }
if (mcast_index == NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES) if (mcast_index == NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES)
{ {
driver_req_ptr -> nx_ip_driver_status = NX_ENTRY_NOT_FOUND; driver_req_ptr->nx_ip_driver_status = NX_ENTRY_NOT_FOUND;
} }
break; break;
} }
case NX_LINK_GET_STATUS: case NX_LINK_GET_STATUS:
{ {
/* Return the link status in the supplied return pointer. */ /* Return the link status in the supplied return pointer. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = ip_ptr -> nx_ip_interface[0].nx_interface_link_up; *(driver_req_ptr->nx_ip_driver_return_ptr) = ip_ptr->nx_ip_interface[0].nx_interface_link_up;
break; break;
} }
case NX_LINK_GET_SPEED: case NX_LINK_GET_SPEED:
{ {
/* Return the link's line speed in the supplied return pointer. Unsupported feature. */ /* Return the link's line speed in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; *(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_LINK_GET_DUPLEX_TYPE: case NX_LINK_GET_DUPLEX_TYPE:
{ {
/* Return the link's line speed in the supplied return pointer. Unsupported feature. */ /* Return the link's line speed in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; *(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_LINK_GET_ERROR_COUNT: case NX_LINK_GET_ERROR_COUNT:
{ {
/* Return the link's line speed in the supplied return pointer. Unsupported feature. */ /* Return the link's line speed in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; *(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_LINK_GET_RX_COUNT: case NX_LINK_GET_RX_COUNT:
{ {
/* Return the link's line speed in the supplied return pointer. Unsupported feature. */ /* Return the link's line speed in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; *(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_LINK_GET_TX_COUNT: case NX_LINK_GET_TX_COUNT:
{ {
/* Return the link's line speed in the supplied return pointer. Unsupported feature. */ /* Return the link's line speed in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; *(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_LINK_GET_ALLOC_ERRORS: case NX_LINK_GET_ALLOC_ERRORS:
{ {
/* Return the link's line speed in the supplied return pointer. Unsupported feature. */ /* Return the link's line speed in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; *(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_LINK_GET_INTERFACE_TYPE: case NX_LINK_GET_INTERFACE_TYPE:
{ {
/* Return the link's interface type in the supplied return pointer. Unsupported feature. */ /* Return the link's interface type in the supplied return pointer. Unsupported feature. */
*(driver_req_ptr -> nx_ip_driver_return_ptr) = NX_INTERFACE_TYPE_UNKNOWN; *(driver_req_ptr->nx_ip_driver_return_ptr) = NX_INTERFACE_TYPE_UNKNOWN;
break; break;
} }
case NX_LINK_DEFERRED_PROCESSING: case NX_LINK_DEFERRED_PROCESSING:
@@ -577,7 +584,7 @@ ULONG *ethernet_frame_ptr;
case NX_LINK_SET_PHYSICAL_ADDRESS: case NX_LINK_SET_PHYSICAL_ADDRESS:
{ {
/* Find an driver instance to attach the interface. */ /* Find an driver instance to attach the interface. */
for (i = 0; i < NX_MAX_MNRS_INTERFACES; i++) for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
{ {
if (nx_mnrs_driver[i].nx_mnrs_driver_interface_ptr == interface_ptr) if (nx_mnrs_driver[i].nx_mnrs_driver_interface_ptr == interface_ptr)
{ {
@@ -585,23 +592,26 @@ ULONG *ethernet_frame_ptr;
} }
} }
/* An available entry is found. */ /* An available entry is found. */
if (i < NX_MAX_MNRS_INTERFACES) if (i < NX_MAX_PHYSICAL_INTERFACES)
{ {
/* Set the physical address. */ /* Set the physical address. */
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw = driver_req_ptr -> nx_ip_driver_physical_address_msw; nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw =
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw = driver_req_ptr -> nx_ip_driver_physical_address_lsw; driver_req_ptr->nx_ip_driver_physical_address_msw;
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw =
driver_req_ptr->nx_ip_driver_physical_address_lsw;
} }
else else
{ {
driver_req_ptr -> nx_ip_driver_status = NX_INVALID_INTERFACE; driver_req_ptr->nx_ip_driver_status = NX_INVALID_INTERFACE;
} }
break; break;
} }
#ifdef NX_ENABLE_INTERFACE_CAPABILITY #ifdef NX_ENABLE_INTERFACE_CAPABILITY
case NX_INTERFACE_CAPABILITY_GET: case NX_INTERFACE_CAPABILITY_GET:
{ {
/* Return the capability of the Ethernet controller speed in the supplied return pointer. Unsupported feature. */ /* Return the capability of the Ethernet controller speed in the supplied return pointer. Unsupported
*(driver_req_ptr -> nx_ip_driver_return_ptr) = 0; * feature. */
*(driver_req_ptr->nx_ip_driver_return_ptr) = 0;
break; break;
} }
case NX_INTERFACE_CAPABILITY_SET: case NX_INTERFACE_CAPABILITY_SET:
@@ -614,9 +624,9 @@ ULONG *ethernet_frame_ptr;
/* Invalid driver request. */ /* Invalid driver request. */
/* Return the unhandled command status. */ /* Return the unhandled command status. */
driver_req_ptr -> nx_ip_driver_status = NX_UNHANDLED_COMMAND; driver_req_ptr->nx_ip_driver_status = NX_UNHANDLED_COMMAND;
#ifdef NX_DEBUG #ifdef NX_DEBUG
printf("NetX MNRS ETH Driver Received invalid request - %s\n", ip_ptr -> nx_ip_name); printf("NetX MNRS ETH Driver Received invalid request - %s\n", ip_ptr->nx_ip_name);
#endif #endif
break; break;
} }
@@ -671,9 +681,9 @@ ULONG *ethernet_frame_ptr;
/* resulting in version 6.4.0 */ /* resulting in version 6.4.0 */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
void _nx_mnrs_network_driver_output(NX_PACKET *packet_ptr, UINT interface_instance_id) void _nx_mnrs_network_driver_output(NX_PACKET* packet_ptr, UINT interface_instance_id)
{ {
UINT old_threshold = 0; UINT old_threshold = 0;
#ifdef NX_DEBUG_PACKET #ifdef NX_DEBUG_PACKET
UCHAR *ptr; UCHAR *ptr;
@@ -694,7 +704,7 @@ UINT i, j;
printf("%02X ", *ptr++); printf("%02X ", *ptr++);
i = 0; i = 0;
for (j = 0; j < (packet_ptr -> nx_packet_length - NX_ETHERNET_SIZE); j++) for (j = 0; j < (packet_ptr->nx_packet_length - NX_ETHERNET_SIZE); j++)
{ {
printf("%02X", *ptr++); printf("%02X", *ptr++);
i++; i++;
@@ -713,8 +723,9 @@ UINT i, j;
#ifdef NX_ENABLE_VLAN #ifdef NX_ENABLE_VLAN
/* Release the packet. */ /* Release the packet. */
nx_link_packet_transmitted(nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_ip_ptr, nx_link_packet_transmitted(nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_ip_ptr,
nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_interface_ptr -> nx_interface_index, nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_interface_ptr->nx_interface_index,
packet_ptr, NX_NULL); packet_ptr,
NX_NULL);
#else #else
/* Remove the Ethernet header. In real hardware environments, this is typically /* Remove the Ethernet header. In real hardware environments, this is typically
done after a transmit complete interrupt. */ done after a transmit complete interrupt. */
@@ -781,21 +792,23 @@ UINT i, j;
/* resulting in version 6.4.0 */ /* resulting in version 6.4.0 */
/* */ /* */
/**************************************************************************/ /**************************************************************************/
void _nx_mnrs_network_driver_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT interface_instance_id) void _nx_mnrs_network_driver_receive(NX_IP* ip_ptr, NX_PACKET* packet_ptr, UINT interface_instance_id)
{ {
UINT packet_type; UINT packet_type;
#ifdef NX_ENABLE_VLAN #ifdef NX_ENABLE_VLAN
nx_link_ethernet_packet_received(ip_ptr, nx_link_ethernet_packet_received(ip_ptr,
nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_interface_ptr -> nx_interface_index, nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_interface_ptr->nx_interface_index,
packet_ptr, NX_NULL); packet_ptr,
NX_NULL);
#else #else
/* Pickup the packet header to determine where the packet needs to be /* Pickup the packet header to determine where the packet needs to be
sent. */ sent. */
packet_type = (((UINT)(*(packet_ptr -> nx_packet_prepend_ptr + 12))) << 8) | packet_type = (((UINT)(*(packet_ptr->nx_packet_prepend_ptr + 12))) << 8) |
((UINT)(*(packet_ptr -> nx_packet_prepend_ptr + 13))); ((UINT)(*(packet_ptr->nx_packet_prepend_ptr + 13)));
/* Setup interface pointer. */ /* Setup interface pointer. */
packet_ptr -> nx_packet_address.nx_packet_interface_ptr = nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_interface_ptr; packet_ptr->nx_packet_address.nx_packet_interface_ptr =
nx_mnrs_driver[interface_instance_id].nx_mnrs_driver_interface_ptr;
/* Route the incoming packet according to its ethernet type. */ /* Route the incoming packet according to its ethernet type. */
/* The MNRS ETH driver accepts both IPv4 and IPv6 frames. */ /* The MNRS ETH driver accepts both IPv4 and IPv6 frames. */
if ((packet_type == NX_ETHERNET_IP) || (packet_type == NX_ETHERNET_IPV6)) if ((packet_type == NX_ETHERNET_IP) || (packet_type == NX_ETHERNET_IPV6))
@@ -853,32 +866,37 @@ UINT packet_type;
#endif /* NX_ENABLE_VLAN */ #endif /* NX_ENABLE_VLAN */
} }
UINT _nx_mnrs_eth_send_packet(NX_PACKET *packet_ptr, volatile ethmac_t* ethmac){ UINT _nx_mnrs_eth_send_packet(NX_PACKET* packet_ptr, volatile ethmac_t* ethmac)
ULONG size = 0; {
UCHAR *data; ULONG size = 0;
UINT i; UCHAR* data;
ULONG buffer; UINT i;
ULONG words; ULONG buffer;
ULONG words;
/* Make sure the data length is less than MTU. */ /* Make sure the data length is less than MTU. */
if (packet_ptr -> nx_packet_length > NX_MAX_PACKET_SIZE) if (packet_ptr->nx_packet_length > NX_MAX_PACKET_SIZE)
{ {
return NX_NOT_SUCCESSFUL; return NX_NOT_SUCCESSFUL;
} }
/* get data pointer to be transmitted. */ /* get data pointer to be transmitted. */
data = packet_ptr -> nx_packet_prepend_ptr; data = packet_ptr->nx_packet_prepend_ptr;
size = packet_ptr -> nx_packet_length; size = packet_ptr->nx_packet_length;
words = (size+3)/4; words = (size + 3) / 4;
while(get_ethmac_mac_ctrl_tx_ready(ethmac) == 0) while (get_ethmac_mac_ctrl_tx_ready(ethmac) == 0)
; ;
set_ethmac_mac_tx(ethmac, size*8); set_ethmac_mac_tx(ethmac, size * 8);
for(i=0; i<size; i+=4) { for (i = 0; i < size; i += 4)
if(i<size-3) { {
memcpy(&buffer, data+i, 4); if (i < size - 3)
} else { {
memcpy(&buffer, data+i, size-i); memcpy(&buffer, data + i, 4);
} }
while(!get_ethmac_mac_ctrl_tx_ready(ethmac)) else
{
memcpy(&buffer, data + i, size - i);
}
while (!get_ethmac_mac_ctrl_tx_ready(ethmac))
; ;
set_ethmac_mac_tx(ethmac, buffer); set_ethmac_mac_tx(ethmac, buffer);
@@ -886,22 +904,26 @@ ULONG words;
return NX_SUCCESS; return NX_SUCCESS;
} }
UINT mac_addr_hit(UINT i, MAC_ADDRESS* mac_addr) { UINT mac_addr_hit(UINT i, MAC_ADDRESS* mac_addr)
{
UINT mcast_index; UINT mcast_index;
if (nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw == mac_addr->nx_mac_address_msw && if (nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_msw == mac_addr->nx_mac_address_msw &&
nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw == mac_addr -> nx_mac_address_lsw) nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw == mac_addr->nx_mac_address_lsw)
{ {
return 1; return 1;
} }
return 0; return 0;
} }
UINT mcast_mac_addr_hit_idx(UINT i, MAC_ADDRESS*mac_addr) { UINT mcast_mac_addr_hit_idx(UINT i, MAC_ADDRESS* mac_addr)
{
UINT mcast_index; UINT mcast_index;
for (mcast_index = 0; mcast_index < NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES; mcast_index++) for (mcast_index = 0; mcast_index < NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES; mcast_index++)
{ {
if (nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw == mac_addr->nx_mac_address_msw && if (nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_msw ==
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw == mac_addr -> nx_mac_address_lsw) mac_addr->nx_mac_address_msw &&
nx_mnrs_driver[i].nx_mnrs_driver_mcast_address[mcast_index].nx_mac_address_lsw ==
mac_addr->nx_mac_address_lsw)
{ {
return i; return i;
} }
@@ -910,15 +932,12 @@ UINT mcast_mac_addr_hit_idx(UINT i, MAC_ADDRESS*mac_addr) {
} }
static UCHAR nx_mnrs_receive_buffer[NX_MAX_PACKET_SIZE]; static UCHAR nx_mnrs_receive_buffer[NX_MAX_PACKET_SIZE];
VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac){ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac)
UINT bit_size; {
UINT word_size; UINT bits_received;
UINT byte_size; UINT words_to_read;
UINT i; UINT i, j;
UINT word; UINT word;
UCHAR buffer[16];
MAC_ADDRESS to_mac;
MAC_ADDRESS from_mac;
UINT status; UINT status;
NX_PACKET* packet_ptr; NX_PACKET* packet_ptr;
NX_IP* ip_ptr; NX_IP* ip_ptr;
@@ -928,56 +947,49 @@ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac){
UINT packet_type; UINT packet_type;
set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 0); set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 0);
bit_size = get_ethmac_mac_rx(ethmac); bits_received = get_ethmac_mac_rx(ethmac);
word_size = (bit_size+31)/32; words_to_read = (bits_received + 31) / 32;
byte_size = (bit_size+7)/8; if (words_to_read < 4)
if(word_size<4)
{ {
for (j = 0; j < words_to_read; j++)
{
while (!get_ethmac_mac_ctrl_rx_pending(ethmac))
;
// be carefull of unaligned accesses since data is 2byte aligned
word = get_ethmac_mac_rx(ethmac);
memcpy(data + j * sizeof(UINT), &word, sizeof(UINT));
}
set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 1); set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 1);
return; return;
} }
// read the first 14 bytes to get from and to mac address (6bytes each) and the frame type/length
for( i = 0;i < 4;i++)
{
while(!get_ethmac_mac_ctrl_rx_pending(ethmac))
;
// be carefull of unaligned accesses
word = get_ethmac_mac_rx(ethmac);
memcpy(buffer+i*sizeof(UINT), &word, sizeof(UINT));
}
to_mac.nx_mac_address_msw=(buffer[0]<<8) + buffer[1];
to_mac.nx_mac_address_lsw=(buffer[2]<<24) + (buffer[3]<<16) + (buffer[4]<<8) + buffer[5];
from_mac.nx_mac_address_msw=(buffer[6]<<8) + buffer[7];
from_mac.nx_mac_address_lsw=(buffer[8]<<24) + (buffer[9]<<16) + (buffer[10]<<8) + buffer[11];
// find the diver instance belonging to our ethmac // find the diver instance belonging to our ethmac
for(i=0; i<NX_MAX_MNRS_INTERFACES; ++i) { for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; ++i)
if(nx_mnrs_driver[i].ethmac == ethmac) {
if (nx_mnrs_driver[i].ethmac == ethmac)
{ {
ip_ptr = nx_mnrs_driver[i].nx_mnrs_driver_ip_ptr; ip_ptr = nx_mnrs_driver[i].nx_mnrs_driver_ip_ptr;
status = nx_packet_allocate(ip_ptr->nx_ip_default_packet_pool, status = nx_packet_allocate(ip_ptr->nx_ip_default_packet_pool, &packet_ptr, NX_RECEIVE_PACKET, NX_NO_WAIT);
&packet_ptr, NX_RECEIVE_PACKET, NX_NO_WAIT);
if (status) if (status)
{ {
packet_ptr = NX_NULL; packet_ptr = NX_NULL;
data = nx_mnrs_receive_buffer; data = nx_mnrs_receive_buffer;
} }
else if (ip_ptr -> nx_ip_default_packet_pool -> nx_packet_pool_payload_size >= (NX_LINK_MTU + 2)) else if (ip_ptr->nx_ip_default_packet_pool->nx_packet_pool_payload_size >= (NX_LINK_MTU + 2))
{ {
data = packet_ptr -> nx_packet_prepend_ptr + 2; data = packet_ptr->nx_packet_prepend_ptr + 2;
} }
else else
{ {
data = nx_mnrs_receive_buffer; data = nx_mnrs_receive_buffer;
} }
/* read the data from the rx buffer into the packet pointer or our frame buffer */
memcpy(data, buffer, 16);
/* now get the remaining bytes from the ethmac peripheral */ /* now get the remaining bytes from the ethmac peripheral */
for( i = 4;i < word_size;i++){ for (j = 0; j < words_to_read; j++)
while(!get_ethmac_mac_ctrl_rx_pending(ethmac)) {
while (!get_ethmac_mac_ctrl_rx_pending(ethmac))
; ;
// be carefull of unaligned accesses // be carefull of unaligned accesses since data is 2byte aligned
word = get_ethmac_mac_rx(ethmac); word = get_ethmac_mac_rx(ethmac);
memcpy(data+i*sizeof(UINT), &word, sizeof(UINT)); memcpy(data + j * sizeof(UINT), &word, sizeof(UINT));
} }
if (packet_ptr == NX_NULL) if (packet_ptr == NX_NULL)
{ {
@@ -985,13 +997,13 @@ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac){
return; return;
} }
/* Make sure IP header is 4-byte aligned. */ /* Make sure IP header is 4-byte aligned. */
packet_ptr -> nx_packet_prepend_ptr += 2; packet_ptr->nx_packet_prepend_ptr += 2;
packet_ptr -> nx_packet_append_ptr += 2; packet_ptr->nx_packet_append_ptr += 2;
if (data == nx_mnrs_receive_buffer) if (data == nx_mnrs_receive_buffer)
{ {
/* Copy data into packet. */ /* Copy data into packet. */
status = nx_packet_data_append(packet_ptr, (VOID *)data, bytes_received, status = nx_packet_data_append(
ip_ptr -> nx_ip_default_packet_pool, NX_NO_WAIT); packet_ptr, (VOID*)data, bytes_received, ip_ptr->nx_ip_default_packet_pool, NX_NO_WAIT);
if (status) if (status)
{ {
nx_packet_release(packet_ptr); nx_packet_release(packet_ptr);
@@ -1000,72 +1012,29 @@ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac){
} }
else else
{ {
packet_ptr -> nx_packet_length = (ULONG)bytes_received; packet_ptr->nx_packet_length = (ULONG)bytes_received;
packet_ptr -> nx_packet_append_ptr += (ULONG)bytes_received; packet_ptr->nx_packet_append_ptr += (ULONG)bytes_received;
} }
/* Pickup the packet header to determine where the packet needs to be sent. */
packet_type = (((UINT)(*(packet_ptr -> nx_packet_prepend_ptr + 12))) << 8) |
((UINT)(*(packet_ptr -> nx_packet_prepend_ptr + 13)));
/* Route the incoming packet according to its ethernet type. */
if ((packet_type == NX_ETHERNET_IP) || (packet_type == NX_ETHERNET_IPV6))
{
/* Note: The length reported by some Ethernet hardware includes bytes after the packet
as well as the Ethernet header. In some cases, the actual packet length after the
Ethernet header should be derived from the length in the IP header (lower 16 bits of
the first 32-bit word). */
/* Clean off the Ethernet header. */ _nx_mnrs_network_driver_receive(ip_ptr, packet_ptr, i);
packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_prepend_ptr + NX_ETHERNET_SIZE; break;
/* Adjust the packet length. */
packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length - NX_ETHERNET_SIZE;
_nx_ip_packet_deferred_receive(ip_ptr, packet_ptr);
}
else if (packet_type == NX_ETHERNET_ARP)
{
/* Clean off the Ethernet header. */
packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_prepend_ptr + NX_ETHERNET_SIZE;
/* Adjust the packet length. */
packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length - NX_ETHERNET_SIZE;
_nx_arp_packet_deferred_receive(ip_ptr, packet_ptr);
}
else if (packet_type == NX_ETHERNET_RARP)
{
/* Clean off the Ethernet header. */
packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_prepend_ptr + NX_ETHERNET_SIZE;
/* Adjust the packet length. */
packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length - NX_ETHERNET_SIZE;
_nx_rarp_packet_deferred_receive(ip_ptr, packet_ptr);
}
#ifdef NX_ENABLE_PPPOE
else if ((packet_type == NX_ETHERNET_PPPOE_DISCOVERY) ||
(packet_type == NX_ETHERNET_PPPOE_SESSION))
{
/* Clean off the Ethernet header. */
packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_prepend_ptr + NX_ETHERNET_SIZE;
/* Adjust the packet length. */
packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length - NX_ETHERNET_SIZE;
/* Route to the PPPoE receive function. */
_nx_pppoe_packet_deferred_receive(packet_ptr);
}
#endif
else
{
/* Invalid ethernet header... release the packet. */
nx_packet_release(packet_ptr);
}
} }
} }
set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 1); set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 1);
} }
VOID _nx_mnrs_eth_recv_packet_eth0(VOID){ VOID _nx_mnrs_eth_recv_packet_eth0(VOID)
if(get_ethmac_mac_ctrl_rx_pending(ethmac0)) { {
if (get_ethmac_mac_ctrl_rx_pending(ethmac0))
{
_nx_mnrs_eth_recv_packet(0, ethmac0); _nx_mnrs_eth_recv_packet(0, ethmac0);
} }
} }
VOID _nx_mnrs_eth_recv_packet_eth1(VOID){ VOID _nx_mnrs_eth_recv_packet_eth1(VOID)
if(get_ethmac_mac_ctrl_rx_pending(ethmac1)) { {
if (get_ethmac_mac_ctrl_rx_pending(ethmac1))
{
_nx_mnrs_eth_recv_packet(1, ethmac1); _nx_mnrs_eth_recv_packet(1, ethmac1);
} }
} }

View File

@@ -62,16 +62,6 @@
#define NX_LITTLE_ENDIAN #define NX_LITTLE_ENDIAN
/* Define various constants for the port. */
#ifndef NX_IP_PERIODIC_RATE
#ifdef TX_TIMER_TICKS_PER_SECOND
#define NX_IP_PERIODIC_RATE TX_TIMER_TICKS_PER_SECOND
#else
#define NX_IP_PERIODIC_RATE 10
#endif
#endif
/* Define macros that swap the endian for little endian ports. */ /* Define macros that swap the endian for little endian ports. */
#ifdef NX_LITTLE_ENDIAN #ifdef NX_LITTLE_ENDIAN
#define NX_CHANGE_ULONG_ENDIAN(arg) \ #define NX_CHANGE_ULONG_ENDIAN(arg) \

View File

@@ -61,11 +61,8 @@
/* Define the base exponent of 2 for huge number. /* Define the base exponent of 2 for huge number.
* Only 16 and 32 are supported. */ * Only 16 and 32 are supported. */
#if __riscv_xlen == 64
#define NX_CRYPTO_HUGE_NUMBER_BITS 16
#else
#define NX_CRYPTO_HUGE_NUMBER_BITS 32 #define NX_CRYPTO_HUGE_NUMBER_BITS 32
#endif #define NX_DIRECT_ISR_CALL 1
/* Define various build options for the NetX Duo port. The application should either make changes /* Define various build options for the NetX Duo port. The application should either make changes
here by commenting or un-commenting the conditional compilation defined OR supply the defines here by commenting or un-commenting the conditional compilation defined OR supply the defines
though the compiler's equivalent of the -D option. */ though the compiler's equivalent of the -D option. */
@@ -79,10 +76,8 @@
present to NetX Duo IP layer. Physical interface does not include present to NetX Duo IP layer. Physical interface does not include
loopback interface. By default there is at least one physical interface loopback interface. By default there is at least one physical interface
in the system. */ in the system. */
#define NX_MAX_PHYSICAL_INTERFACES 2 #define NX_MAX_PHYSICAL_INTERFACES 2
/* Defined, this option disables NetX Duo support on the 127.0.0.1 loopback interface. /* Defined, this option disables NetX Duo support on the 127.0.0.1 loopback interface.
127.0.0.1 loopback interface is enabled by default. Uncomment out the follow code to disable 127.0.0.1 loopback interface is enabled by default. Uncomment out the follow code to disable
the loopback interface. */ the loopback interface. */
@@ -99,13 +94,11 @@
/* This defines specifies the number of ThreadX timer ticks in one second. The default value is based /* This defines specifies the number of ThreadX timer ticks in one second. The default value is based
on ThreadX timer interrupt. */ on ThreadX timer interrupt. */
/*
#ifdef TX_TIMER_TICKS_PER_SECOND #ifdef TX_TIMER_TICKS_PER_SECOND
#define NX_IP_PERIODIC_RATE TX_TIMER_TICKS_PER_SECOND #define NX_IP_PERIODIC_RATE TX_TIMER_TICKS_PER_SECOND
#else #else
#define NX_IP_PERIODIC_RATE 100 #define NX_IP_PERIODIC_RATE 100
#endif #endif
*/
/* Defined, NX_ENABLE_IP_RAW_PACKET_FILTER allows an application to install a filter /* Defined, NX_ENABLE_IP_RAW_PACKET_FILTER allows an application to install a filter
for incoming raw packets. This feature is disabled by default. */ for incoming raw packets. This feature is disabled by default. */

View File

@@ -130,7 +130,7 @@
Note: the actual hardware timer value may need to be changed (usually in tx_initialize_low_level). */ Note: the actual hardware timer value may need to be changed (usually in tx_initialize_low_level). */
#define TX_TIMER_TICKS_PER_SECOND (33UL) // for moonlight with 32,7kHz Frequency (divided by 1000) #define TX_TIMER_TICKS_PER_SECOND (100) // for moonlight with 32,7kHz Frequency (divided by 1000)
/* Determine if there is a FileX pointer in the thread control block. /* Determine if there is a FileX pointer in the thread control block.

View File

@@ -134,7 +134,8 @@ void thread_0_entry(ULONG thread_input) {
NX_PARAMETER_NOT_USED(thread_input); NX_PARAMETER_NOT_USED(thread_input);
tx_thread_sleep(NX_IP_PERIODIC_RATE); /* Wait 1 second for the IP thread to finish its initilization. */
tx_thread_sleep(/* NX_IP_PERIODIC_RATE */ 10);
/* set the TCP server addresses. */ /* set the TCP server addresses. */
server_ipv4_address.nxd_ip_version = NX_IP_VERSION_V4; server_ipv4_address.nxd_ip_version = NX_IP_VERSION_V4;
@@ -234,7 +235,7 @@ void thread_1_entry(ULONG thread_input) {
NX_PARAMETER_NOT_USED(thread_input); NX_PARAMETER_NOT_USED(thread_input);
/* Wait 1 second for the IP thread to finish its initilization. */ /* Wait 1 second for the IP thread to finish its initilization. */
tx_thread_sleep(NX_IP_PERIODIC_RATE); tx_thread_sleep(/* NX_IP_PERIODIC_RATE */ 10);
/* Ensure the IP instance has been initialized. */ /* Ensure the IP instance has been initialized. */
status = nx_ip_status_check(&ip_1, NX_IP_INITIALIZE_DONE, &actual_status, NX_IP_PERIODIC_RATE); status = nx_ip_status_check(&ip_1, NX_IP_INITIALIZE_DONE, &actual_status, NX_IP_PERIODIC_RATE);