1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** NetX Component */ 16 /** */ 17 /** Port Specific */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 /**************************************************************************/ 24 /* */ 25 /* PORT SPECIFIC C INFORMATION RELEASE */ 26 /* */ 27 /* nx_port.h Linux/GNU */ 28 /* 6.1 */ 29 /* */ 30 /* AUTHOR */ 31 /* */ 32 /* Yuxin Zhou, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file contains data type definitions that make the NetX */ 37 /* real-time TCP/IP function identically on a variety of different */ 38 /* processor architectures. */ 39 /* */ 40 /* RELEASE HISTORY */ 41 /* */ 42 /* DATE NAME DESCRIPTION */ 43 /* */ 44 /* 09-30-2020 Yuxin Zhou Initial Version 6.1 */ 45 /* */ 46 /**************************************************************************/ 47 48 #ifndef NX_PORT_H 49 #define NX_PORT_H 50 51 52 #ifdef NX_INCLUDE_USER_DEFINE_FILE 53 54 55 /* Yes, include the user defines in nx_user.h. The defines in this file may 56 alternately be defined on the command line. */ 57 58 #include "nx_user.h" 59 #endif 60 61 62 /* Default to little endian, since this is what most ARM targets are. */ 63 64 #define NX_LITTLE_ENDIAN 1 65 66 67 #include <stdio.h> 68 #include <string.h> 69 #include <stdlib.h> 70 71 72 /* Define various constants for the port. */ 73 74 #ifndef NX_IP_PERIODIC_RATE 75 #ifdef TX_TIMER_TICKS_PER_SECOND 76 #define NX_IP_PERIODIC_RATE TX_TIMER_TICKS_PER_SECOND 77 #else 78 #define NX_IP_PERIODIC_RATE 100 79 #endif 80 #endif 81 82 83 /* Define macros that swap the endian for little endian ports. */ 84 #ifdef NX_LITTLE_ENDIAN 85 #define NX_CHANGE_ULONG_ENDIAN(arg) \ 86 { \ 87 ULONG _i; \ 88 ULONG _tmp; \ 89 _i = (UINT)arg; \ 90 /* _i = A, B, C, D */ \ 91 _tmp = _i ^ (((_i) >> 16) | (_i << 16)); \ 92 /* tmp = _i ^ (_i ROR 16) = A^C, B^D, C^A, D^B*/ \ 93 _tmp &= 0xff00ffff; \ 94 /* tmp = A^C, 0, C^A, D^B */ \ 95 _i = ((_i) >> 8) | (_i<<24); \ 96 /* _i = D, A, B, C */ \ 97 _i = _i ^ ((_tmp) >> 8); \ 98 /* _i = D, C, B, A */ \ 99 arg = _i; \ 100 } 101 #define NX_CHANGE_USHORT_ENDIAN(a) a = ((USHORT)((a >> 8) | (a << 8)) & 0xFFFF) 102 103 104 #define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ 105 | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) 106 107 #define __SWAP16__(val) (USHORT)((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) 108 109 110 #ifndef htonl 111 #define htonl(val) __SWAP32__(val) 112 #endif /* htonl */ 113 #ifndef ntohl 114 #define ntohl(val) __SWAP32__(val) 115 #endif /* htonl */ 116 117 #ifndef htons 118 #define htons(val) __SWAP16__(val) 119 #endif /*htons */ 120 121 #ifndef ntohs 122 #define ntohs(val) __SWAP16__(val) 123 #endif /*htons */ 124 125 126 #else 127 #define NX_CHANGE_ULONG_ENDIAN(a) 128 #define NX_CHANGE_USHORT_ENDIAN(a) 129 130 #ifndef htons 131 #define htons(val) (val) 132 #endif /* htons */ 133 134 #ifndef ntohs 135 #define ntohs(val) (val) 136 #endif /* ntohs */ 137 138 #ifndef ntohl 139 #define ntohl(val) (val) 140 #endif 141 142 #ifndef htonl 143 #define htonl(val) (val) 144 #endif /* htonl */ 145 #endif 146 147 148 /* Define several macros for the error checking shell in NetX. */ 149 150 #ifndef TX_TIMER_PROCESS_IN_ISR 151 152 #define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ 153 extern TX_THREAD _tx_timer_thread; \ 154 extern volatile ULONG _tx_thread_system_state; 155 156 #define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ 157 (_tx_thread_current_ptr == TX_NULL) || \ 158 (_tx_thread_current_ptr == &_tx_timer_thread)) \ 159 return(NX_CALLER_ERROR); 160 161 #define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ 162 (_tx_thread_current_ptr == &_tx_timer_thread)) \ 163 return(NX_CALLER_ERROR); 164 165 166 #define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ 167 return(NX_CALLER_ERROR); 168 169 #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ 170 ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ 171 return(NX_CALLER_ERROR); 172 173 174 #else 175 176 177 178 #define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ 179 extern volatile ULONG _tx_thread_system_state; 180 181 #define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ 182 (_tx_thread_current_ptr == TX_NULL)) \ 183 return(NX_CALLER_ERROR); 184 185 #define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ 186 return(NX_CALLER_ERROR); 187 188 #define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ 189 return(NX_CALLER_ERROR); 190 191 #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ 192 ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ 193 return(NX_CALLER_ERROR); 194 195 #endif 196 197 198 /* Define the version ID of NetX. This may be utilized by the application. */ 199 200 #ifdef NX_SYSTEM_INIT 201 CHAR _nx_version_id[] = 202 "Copyright (c) 2024 Microsoft Corporation. * NetX Duo Linux/GNU Version 6.4.1 *"; 203 #else 204 extern CHAR _nx_version_id[]; 205 #endif 206 207 #endif 208 209