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
+63
-59
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
|
||||
Reference in new issue
Block a user