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
Showing only changes of commit 3e8fa257d5 - Show all commits

View File

@@ -82,7 +82,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 +117,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];
/**************************************************************************/ /**************************************************************************/
@@ -201,12 +200,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_PHYSICAL_INTERFACES; i++) {
for (i = 0; i < NX_MAX_MNRS_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)
{
continue; continue;
} }
if (nx_mnrs_driver[i].nx_mnrs_driver_ip_ptr != ip_ptr) if (nx_mnrs_driver[i].nx_mnrs_driver_ip_ptr != ip_ptr)
@@ -218,8 +214,7 @@ 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;
} }
@@ -231,16 +226,13 @@ ULONG *ethernet_frame_ptr;
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)
{
break; break;
} }
} }
/* 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;
nx_mnrs_driver[i].nx_mnrs_network_driver_id = i; nx_mnrs_driver[i].nx_mnrs_network_driver_id = i;
@@ -577,16 +569,13 @@ 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)
{
break; break;
} }
} }
/* 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 = 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; nx_mnrs_driver[i].nx_mnrs_driver_mac_address.nx_mac_address_lsw = driver_req_ptr -> nx_ip_driver_physical_address_lsw;
@@ -911,14 +900,10 @@ 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 bits_received;
UINT word_size; UINT words_to_read;
UINT byte_size; UINT i, j;
UINT i;
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,29 +913,23 @@ 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)
{ {
set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 1); for(j = 0;j < words_to_read;j++)
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)) 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(buffer+i*sizeof(UINT), &word, sizeof(UINT)); memcpy(data + j * sizeof(UINT), &word, sizeof(UINT));
}
set_ethmac_mac_intr_rx_data_avail_intr_enable(ethmac, 1);
return;
} }
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;
@@ -969,15 +948,14 @@ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac){
{ {
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)
{ {
@@ -1003,69 +981,24 @@ VOID _nx_mnrs_eth_recv_packet(UINT id, volatile ethmac_t* ethmac){
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);
} }
} }