/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2025-present Eclipse ThreadX Contributors * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Port Specific */ /** */ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /* */ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* nx_port.h PIC32x/Microchip */ /* 6.4.3 */ /* */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This file contains data type definitions that make the NetX */ /* real-time TCP/IP function identically on a variety of different */ /* processor architectures. */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 10-31-2022 Zhen Kong Initial PIC32x/Microchip */ /* Support Version 6.2.0 */ /* */ /**************************************************************************/ #ifndef NX_PORT_H #define NX_PORT_H /* Determine if the optional NetX user define file should be used. */ #ifdef NX_INCLUDE_USER_DEFINE_FILE /* Yes, include the user defines in nx_user.h. The defines in this file may alternately be defined on the command line. */ #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 #endif #include "tx_port.h" _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 /* Default to little endian, since this is what most RISC-V targets are. */ #define NX_LITTLE_ENDIAN /* Define macros that swap the endian for little endian ports. */ #ifdef NX_LITTLE_ENDIAN #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_ULONG_ENDIAN(val) #endif /* htonl */ #ifndef ntohl #define ntohl(val) NX_CHANGE_ULONG_ENDIAN(val) #endif /* ntohl */ #ifndef htons #define htons(val) NX_CHANGE_USHORT_ENDIAN(val) #endif /*htons */ #ifndef ntohs #define ntohs(val) NX_CHANGE_USHORT_ENDIAN(val) #endif /*ntohs */ #else #define NX_CHANGE_ULONG_ENDIAN(a) #define NX_CHANGE_USHORT_ENDIAN(a) #ifndef htons #define htons(val) (val) #endif /* htons */ #ifndef ntohs #define ntohs(val) (val) #endif /* ntohs */ #ifndef ntohl #define ntohl(val) (val) #endif #ifndef htonl #define htonl(val) (val) #endif /* htonl */ #endif /* Define several macros for the error checking shell in NetX. */ #ifndef TX_TIMER_PROCESS_IN_ISR #define NX_CALLER_CHECKING_EXTERNS \ extern TX_THREAD* _tx_thread_current_ptr; \ extern TX_THREAD _tx_timer_thread; \ extern volatile ULONG TX_THREAD_GET_SYSTEM_STATE(); #define NX_THREADS_ONLY_CALLER_CHECKING \ if ((TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == TX_NULL) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return (NX_CALLER_ERROR); #define NX_INIT_AND_THREADS_CALLER_CHECKING \ if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG)0xF0F0F0F0))) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return (NX_CALLER_ERROR); #define NX_NOT_ISR_CALLER_CHECKING \ if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG)0xF0F0F0F0))) \ return (NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING \ if ((wait_option) && ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == &_tx_timer_thread))) \ return (NX_CALLER_ERROR); #else #define NX_CALLER_CHECKING_EXTERNS \ extern TX_THREAD* _tx_thread_current_ptr; \ extern volatile ULONG TX_THREAD_GET_SYSTEM_STATE(); #define NX_THREADS_ONLY_CALLER_CHECKING \ if ((TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == TX_NULL)) \ return (NX_CALLER_ERROR); #define NX_INIT_AND_THREADS_CALLER_CHECKING \ if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG)0xF0F0F0F0)))) \ return (NX_CALLER_ERROR); #define NX_NOT_ISR_CALLER_CHECKING \ if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG)0xF0F0F0F0))) \ return (NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING \ if ((wait_option) && ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ return (NX_CALLER_ERROR); #endif /* Define the version ID of NetX. This may be utilized by the application. */ #ifdef NX_SYSTEM_INIT CHAR _nx_version_id[] = "Copyright (c) 2024 Microsoft Corporation. * NetX Duo PIC32x/MPLAB Version 6.4.1 *"; #else extern CHAR _nx_version_id[]; #endif #endif