Updates NetX Duo to the upstream implementation
Uses the upstream ULONG APIs and passes RV64 callback pointers through ThreadX extension fields.
This commit is contained in:
1 parent
d404e17e5a
commit
608c4e0b0d
5 files changed
+61
-57
No files matched your search
+37
-24
@@ -56,13 +56,41 @@
|
||||
|
||||
#include "nx_user.h"
|
||||
#endif
|
||||
|
||||
/* The upstream RAM driver relies on the port for debug stdio declarations. */
|
||||
#if defined(NX_DEBUG) || defined(NX_DEBUG_PACKET)
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "tx_port.h"
|
||||
#if __riscv_xlen == 64
|
||||
typedef unsigned int UINT32;
|
||||
#else
|
||||
typedef unsigned long UINT32;
|
||||
_Static_assert(sizeof(ULONG) == 4, "NetX Duo requires a 32-bit ULONG");
|
||||
|
||||
#ifdef TX_TIMER_EXTENSION_PTR_DEFINED
|
||||
/* ThreadX callbacks take a 32-bit argument on RV64. Keep the NetX context
|
||||
pointers in the thread and timer control blocks. */
|
||||
#define NX_THREAD_EXTENSION_PTR_SET(thread, context) \
|
||||
{ (thread)->tx_thread_extension_ptr = (context); }
|
||||
|
||||
#define NX_THREAD_EXTENSION_PTR_GET(context, type, input) \
|
||||
{ \
|
||||
(void)(input); \
|
||||
TX_THREAD *current_thread = tx_thread_identify(); \
|
||||
while (current_thread->tx_thread_extension_ptr == TX_NULL) \
|
||||
tx_thread_sleep(1); \
|
||||
(context) = (type *)current_thread->tx_thread_extension_ptr; \
|
||||
}
|
||||
|
||||
#define NX_TIMER_EXTENSION_PTR_SET(timer, context) \
|
||||
{ (timer)->tx_timer_internal.tx_timer_internal_extension_ptr = (context); }
|
||||
|
||||
#define NX_TIMER_EXTENSION_PTR_GET(context, type, input) \
|
||||
{ \
|
||||
(void)(input); \
|
||||
if (_tx_timer_expired_timer_ptr->tx_timer_internal_extension_ptr == TX_NULL) \
|
||||
return; \
|
||||
(context) = (type *)_tx_timer_expired_timer_ptr->tx_timer_internal_extension_ptr; \
|
||||
}
|
||||
#endif
|
||||
_Static_assert(sizeof(UINT32) == 4, "UINT32 must be 4 bytes");
|
||||
|
||||
/* Default to little endian, since this is what most RISC-V targets are. */
|
||||
|
||||
@@ -70,30 +98,15 @@ _Static_assert(sizeof(UINT32) == 4, "UINT32 must be 4 bytes");
|
||||
|
||||
/* Define macros that swap the endian for little endian ports. */
|
||||
#ifdef NX_LITTLE_ENDIAN
|
||||
#define NX_CHANGE_UINT32_ENDIAN(arg) \
|
||||
{ \
|
||||
UINT32 _i; \
|
||||
UINT32 _tmp; \
|
||||
_i = (UINT)arg; \
|
||||
/* _i = A, B, C, D */ \
|
||||
_tmp = _i ^ (((_i) >> 16) | (_i << 16)); \
|
||||
/* _tmp = _i ^ (_i ROR 16) = A^C, B^D, C^A, D^B */ \
|
||||
_tmp &= 0xff00ffff; \
|
||||
/* _tmp = A^C, 0, C^A, D^B */ \
|
||||
_i = ((_i) >> 8) | (_i << 24); \
|
||||
/* _i = D, A, B, C */ \
|
||||
_i = _i ^ ((_tmp) >> 8); \
|
||||
/* _i = D, C, B, A */ \
|
||||
arg = _i; \
|
||||
}
|
||||
#define NX_CHANGE_ULONG_ENDIAN(arg) ((arg) = __builtin_bswap32((ULONG)(arg)))
|
||||
#define NX_CHANGE_USHORT_ENDIAN(a) (a = (((a >> 8) | (a << 8)) & 0xFFFF))
|
||||
|
||||
#ifndef htonl
|
||||
#define htonl(val) NX_CHANGE_UINT32_ENDIAN(val)
|
||||
#define htonl(val) NX_CHANGE_ULONG_ENDIAN(val)
|
||||
#endif /* htonl */
|
||||
|
||||
#ifndef ntohl
|
||||
#define ntohl(val) NX_CHANGE_UINT32_ENDIAN(val)
|
||||
#define ntohl(val) NX_CHANGE_ULONG_ENDIAN(val)
|
||||
#endif /* ntohl */
|
||||
|
||||
#ifndef htons
|
||||
@@ -106,7 +119,7 @@ _Static_assert(sizeof(UINT32) == 4, "UINT32 must be 4 bytes");
|
||||
|
||||
#else
|
||||
|
||||
#define NX_CHANGE_UINT32_ENDIAN(a)
|
||||
#define NX_CHANGE_ULONG_ENDIAN(a)
|
||||
#define NX_CHANGE_USHORT_ENDIAN(a)
|
||||
|
||||
#ifndef htons
|
||||
|
||||
@@ -761,21 +761,14 @@
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int rand(void);
|
||||
void srand(unsigned seed);
|
||||
int rand(void);
|
||||
void srand(unsigned int seed);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define NX_RAND rand
|
||||
#define NX_SRAND srand
|
||||
#endif
|
||||
// hacky workaround for missing include in netxduo/common/src/nx_ram_network_driver.c
|
||||
#ifdef NX_DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
@@ -66,8 +66,8 @@ extern int register_irq_handler(unsigned irq_num, void (*handler)());
|
||||
/* For the ethernet driver, physical addresses are allocated starting
|
||||
at the preset value and then incremented before the next allocation. */
|
||||
// Locally Administered Addresses that can be assigned by network, range is 02-00-00 to 02-00-5E
|
||||
const UINT32 mnrs_mac_address_msw = 0x0200;
|
||||
const UINT32 mnrs_mac_address_lsw = 0x00334450;
|
||||
const ULONG mnrs_mac_address_msw = 0x0200;
|
||||
const ULONG mnrs_mac_address_lsw = 0x00334450;
|
||||
|
||||
/* Define driver prototypes. */
|
||||
VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr);
|
||||
@@ -81,8 +81,8 @@ static VOID _nx_mnrs_eth_recv_packet_eth1(VOID);
|
||||
#define NX_MNRS_DRIVER_MAX_MCAST_ADDRESSES 3
|
||||
typedef struct MAC_ADDRESS_STRUCT
|
||||
{
|
||||
UINT32 nx_mac_address_msw;
|
||||
UINT32 nx_mac_address_lsw;
|
||||
ULONG nx_mac_address_msw;
|
||||
ULONG nx_mac_address_lsw;
|
||||
} MAC_ADDRESS;
|
||||
|
||||
/* Define an application-specific data structure that holds internal
|
||||
@@ -173,7 +173,7 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
||||
UINT interface_index;
|
||||
USHORT ether_type;
|
||||
#ifndef NX_ENABLE_VLAN
|
||||
UINT32* ethernet_frame_ptr;
|
||||
ULONG* ethernet_frame_ptr;
|
||||
#endif /* NX_ENABLE_VLAN */
|
||||
|
||||
/* Setup the IP pointer from the driver request. */
|
||||
@@ -275,7 +275,7 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
||||
/* Device driver shall initialize the Ethernet Controller here. */
|
||||
#ifdef NX_DEBUG
|
||||
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 =%08lX\n", (unsigned long)ip_ptr->nx_ip_address);
|
||||
#endif
|
||||
// enable TX & RX path
|
||||
set_ethmac_mac_ctrl(nx_mnrs_driver[i].ethmac,
|
||||
@@ -408,7 +408,7 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
||||
/* Setup the ethernet frame pointer to build the ethernet frame. Backup another 2
|
||||
bytes to get 32-bit word alignment. */
|
||||
/*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
|
||||
ethernet_frame_ptr = (UINT32*)(packet_ptr->nx_packet_prepend_ptr - 2);
|
||||
ethernet_frame_ptr = (ULONG*)(packet_ptr->nx_packet_prepend_ptr - 2);
|
||||
/* Build the ethernet frame. */
|
||||
*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;
|
||||
@@ -416,10 +416,10 @@ VOID nx_mnrs_network_driver(NX_IP_DRIVER* driver_req_ptr)
|
||||
(interface_ptr->nx_interface_physical_address_lsw >> 16);
|
||||
*(ethernet_frame_ptr + 3) = (interface_ptr->nx_interface_physical_address_lsw << 16) | ether_type;
|
||||
/* Endian swapping if NX_LITTLE_ENDIAN is defined. */
|
||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr));
|
||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr + 1));
|
||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr + 2));
|
||||
NX_CHANGE_UINT32_ENDIAN(*(ethernet_frame_ptr + 3));
|
||||
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr));
|
||||
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 1));
|
||||
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 2));
|
||||
NX_CHANGE_ULONG_ENDIAN(*(ethernet_frame_ptr + 3));
|
||||
#endif /* NX_ENABLE_VLAN */
|
||||
#ifdef NX_DEBUG_PACKET
|
||||
printf("NetX MNRS ETH Driver Packet Send - %s\n", ip_ptr->nx_ip_name);
|
||||
@@ -840,11 +840,10 @@ void _nx_mnrs_network_driver_receive(NX_IP* ip_ptr, NX_PACKET* packet_ptr, UINT
|
||||
|
||||
UINT _nx_mnrs_eth_send_packet(NX_PACKET* packet_ptr, volatile ethmac_t* ethmac)
|
||||
{
|
||||
UINT32 size = 0;
|
||||
ULONG size = 0;
|
||||
UCHAR* data;
|
||||
UINT i;
|
||||
UINT32 buffer;
|
||||
UINT32 words;
|
||||
ULONG buffer;
|
||||
|
||||
/* Make sure the data length is less than MTU. */
|
||||
if (packet_ptr->nx_packet_length > NX_MAX_PACKET_SIZE)
|
||||
@@ -854,7 +853,6 @@ UINT _nx_mnrs_eth_send_packet(NX_PACKET* packet_ptr, volatile ethmac_t* ethmac)
|
||||
/* get data pointer to be transmitted. */
|
||||
data = packet_ptr->nx_packet_prepend_ptr;
|
||||
size = packet_ptr->nx_packet_length;
|
||||
words = (size + 3) / 4;
|
||||
/* wait until ethmac is ready to receive packets */
|
||||
while (get_ethmac_mac_ctrl_tx_ready(ethmac) == 0)
|
||||
;
|
||||
@@ -967,7 +965,7 @@ VOID _nx_mnrs_eth_recv_packet(UINT i)
|
||||
|
||||
VOID _nx_mnrs_eth_recv_packet_eth0(VOID)
|
||||
{
|
||||
UINT32 old_threshold;
|
||||
UINT old_threshold;
|
||||
|
||||
if (get_ethmac_mac_ctrl_rx_pending(ethmac0))
|
||||
{
|
||||
@@ -986,7 +984,7 @@ VOID _nx_mnrs_eth_recv_packet_eth0(VOID)
|
||||
|
||||
VOID _nx_mnrs_eth_recv_packet_eth1(VOID)
|
||||
{
|
||||
UINT32 old_threshold;
|
||||
UINT old_threshold;
|
||||
|
||||
if (get_ethmac_mac_ctrl_rx_pending(ethmac1))
|
||||
{
|
||||
|
||||
+5
-5
@@ -137,11 +137,11 @@ void thread_0_entry(ULONG thread_input)
|
||||
|
||||
UINT status;
|
||||
NX_PACKET* my_packet;
|
||||
UINT32 length;
|
||||
ULONG length;
|
||||
|
||||
NXD_ADDRESS server_ipv4_address;
|
||||
NXD_ADDRESS peer_address;
|
||||
UINT32 peer_port;
|
||||
ULONG peer_port;
|
||||
|
||||
NX_PARAMETER_NOT_USED(thread_input);
|
||||
|
||||
@@ -259,7 +259,7 @@ void thread_1_entry(ULONG thread_input)
|
||||
|
||||
UINT status;
|
||||
NX_PACKET* packet_ptr;
|
||||
UINT32 actual_status;
|
||||
ULONG actual_status;
|
||||
|
||||
NX_PARAMETER_NOT_USED(thread_input);
|
||||
|
||||
@@ -331,10 +331,10 @@ void thread_1_entry(ULONG thread_input)
|
||||
else
|
||||
{
|
||||
char buffer[64];
|
||||
UINT32 size;
|
||||
ULONG size;
|
||||
nx_packet_data_extract_offset(packet_ptr, 0, buffer, 64, &size);
|
||||
buffer[size] = 0;
|
||||
printf("Received packet %lu with %s\n", thread_1_counter, buffer);
|
||||
printf("Received packet %lu with %s\n", (unsigned long)thread_1_counter, buffer);
|
||||
/* Release the packet. */
|
||||
nx_packet_release(packet_ptr);
|
||||
}
|
||||
|
||||
Vendored
+1
-1
Submodule third-party/netxduo updated: 949c0f235c...c690f59f9a.
Reference in new issue
Block a user