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