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 /** System Management (System) */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define NX_SOURCE_CODE
24
25
26 /* Locate NetX system data in this file. */
27
28 #define NX_SYSTEM_INIT
29
30
31 /* Include necessary system files. */
32
33 #include "nx_api.h"
34 #include "nx_system.h"
35 #include "nx_packet.h"
36 #include "nx_arp.h"
37 #include "nx_rarp.h"
38 #include "nx_ip.h"
39 #include "nx_udp.h"
40 #include "nx_icmp.h"
41 #include "nx_igmp.h"
42 #include "nx_tcp.h"
43
44 #ifdef FEATURE_NX_IPV6
45 #include "nx_nd_cache.h"
46 #endif /* FEATURE_NX_IPV6 */
47
48 /**************************************************************************/
49 /* */
50 /* FUNCTION RELEASE */
51 /* */
52 /* _nx_system_initialize PORTABLE C */
53 /* 6.1 */
54 /* AUTHOR */
55 /* */
56 /* Yuxin Zhou, Microsoft Corporation */
57 /* */
58 /* DESCRIPTION */
59 /* */
60 /* This function initializes the various components and system data */
61 /* structures. */
62 /* */
63 /* INPUT */
64 /* */
65 /* pool_start Packet pool starting address */
66 /* pool_size Packet pool size in bytes */
67 /* */
68 /* OUTPUT */
69 /* */
70 /* None */
71 /* */
72 /* CALLS */
73 /* */
74 /* _nx_packet_pool_initialize Initialize Packet Pool */
75 /* component */
76 /* _nx_ip_initialize Initialize IP component */
77 /* _nx_tcp_initialize Initialize TCP component */
78 /* */
79 /* CALLED BY */
80 /* */
81 /* Application */
82 /* */
83 /* RELEASE HISTORY */
84 /* */
85 /* DATE NAME DESCRIPTION */
86 /* */
87 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
88 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
89 /* resulting in version 6.1 */
90 /* */
91 /**************************************************************************/
_nx_system_initialize(VOID)92 VOID _nx_system_initialize(VOID)
93 {
94
95 /* Check whether or not system has been initialized? */
96 if (_nx_system_build_options_1 | _nx_system_build_options_2 |
97 _nx_system_build_options_3 | _nx_system_build_options_4 | _nx_system_build_options_5)
98 {
99
100 /* Yes it is. Just return. */
101 return;
102 }
103
104 /* If trace is enabled, insert this event into the trace buffer. */
105 NX_TRACE_IN_LINE_INSERT(NX_TRACE_SYSTEM_INITIALIZE, 0, 0, 0, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
106
107 /* Call the packet pool initialization component for NetX. */
108 _nx_packet_pool_initialize();
109
110 /* Call the IP component initialization. */
111 _nx_ip_initialize();
112
113 /* Call the TCP component initialization. */
114 /*lint -e{522} suppress lack of side-effects. */
115 _nx_tcp_initialize();
116
117 /* Setup the build options variables. */
118 _nx_system_build_options_1 = 0
119 #ifdef NX_LITTLE_ENDIAN
120 | (((ULONG)1) << 31)
121 #endif
122 #ifdef NX_DISABLE_ARP_AUTO_ENTRY
123 | (((ULONG)1) << 30)
124 #endif
125 #ifdef NX_ENABLE_TCP_KEEPALIVE
126 | (((ULONG)1) << 29)
127 #endif
128 #ifdef NX_TCP_IMMEDIATE_ACK
129 | (((ULONG)1) << 28)
130 #endif
131 #ifdef NX_DRIVER_DEFERRED_PROCESSING
132 | (((ULONG)1) << 27)
133 #endif
134 #ifdef NX_DISABLE_FRAGMENTATION
135 | (((ULONG)1) << 26)
136 #endif
137 #ifdef NX_DISABLE_IP_RX_CHECKSUM
138 | (((ULONG)1) << 25)
139 #endif
140 #ifdef NX_DISABLE_IP_TX_CHECKSUM
141 | (((ULONG)1) << 24)
142 #endif
143 #ifdef NX_DISABLE_TCP_RX_CHECKSUM
144 | (((ULONG)1) << 23)
145 #endif
146 #ifdef NX_DISABLE_TCP_TX_CHECKSUM
147 | (((ULONG)1) << 22)
148 #endif
149 #ifdef NX_DISABLE_RESET_DISCONNECT
150 | (((ULONG)1) << 21)
151 #endif
152 #ifdef NX_DISABLE_RX_SIZE_CHECKING
153 | (((ULONG)1) << 20)
154 #endif
155 #ifdef NX_DISABLE_ARP_INFO
156 | (((ULONG)1) << 19)
157 #endif
158 #ifdef NX_DISABLE_IP_INFO
159 | (((ULONG)1) << 18)
160 #endif
161 #ifdef NX_DISABLE_ICMP_INFO
162 | (((ULONG)1) << 17)
163 #endif
164 #ifdef NX_DISABLE_IGMP_INFO
165 | (((ULONG)1) << 16)
166 #endif
167 #ifdef NX_DISABLE_PACKET_INFO
168 | (((ULONG)1) << 15)
169 #endif
170 #ifdef NX_DISABLE_RARP_INFO
171 | (((ULONG)1) << 14)
172 #endif
173 #ifdef NX_DISABLE_TCP_INFO
174 | (((ULONG)1) << 13)
175 #endif
176 #ifdef NX_DISABLE_UDP_INFO
177 | (((ULONG)1) << 12)
178 #endif
179 ;
180
181
182 /* Add the retry shift value to the options. */
183 #if (NX_TCP_RETRY_SHIFT > 0xF)
184 _nx_system_build_options_1 |= 0xF;
185 #else
186 _nx_system_build_options_1 |= NX_TCP_RETRY_SHIFT;
187 #endif
188
189 #if (NX_IP_PERIODIC_RATE > 0xFFFFUL)
190 _nx_system_build_options_2 = ((ULONG)0xFFFF0000);
191 #else
192 _nx_system_build_options_2 = ((ULONG)NX_IP_PERIODIC_RATE) << 16;
193 #endif
194
195 #if (NX_ARP_EXPIRATION_RATE > 0xFF)
196 _nx_system_build_options_2 |= ((ULONG)0xFF) << 8;
197 #else
198 _nx_system_build_options_2 |= ((ULONG)NX_ARP_EXPIRATION_RATE) << 8;
199 #endif
200 #if (NX_ARP_UPDATE_RATE > 0xFF)
201 _nx_system_build_options_2 |= ((ULONG)0xFF);
202 #else
203 _nx_system_build_options_2 |= ((ULONG)NX_ARP_UPDATE_RATE);
204 #endif
205
206 /* Setup third option word. */
207 #if (NX_TCP_ACK_TIMER_RATE > 0xFF)
208 _nx_system_build_options_3 = ((ULONG)0xFF000000);
209 #else
210 _nx_system_build_options_3 = ((ULONG)NX_TCP_ACK_TIMER_RATE) << 24;
211 #endif
212 #if (NX_TCP_FAST_TIMER_RATE > 0xFF)
213 _nx_system_build_options_3 |= ((ULONG)0xFF) << 16;
214 #else
215 _nx_system_build_options_3 |= ((ULONG)NX_TCP_FAST_TIMER_RATE) << 16;
216 #endif
217 #if (NX_TCP_TRANSMIT_TIMER_RATE > 0xFF)
218 _nx_system_build_options_3 |= ((ULONG)0xFF) << 8;
219 #else
220 _nx_system_build_options_3 |= ((ULONG)NX_TCP_TRANSMIT_TIMER_RATE) << 8;
221 #endif
222 #if (NX_TCP_KEEPALIVE_RETRY > 0xFF)
223 _nx_system_build_options_3 |= ((ULONG)0xFF);
224 #else
225 _nx_system_build_options_3 |= ((ULONG)NX_TCP_KEEPALIVE_RETRY);
226 #endif
227
228 /* Setup the fourth option word. */
229 #if (NX_TCP_KEEPALIVE_INITIAL > 0xFFFFUL)
230 _nx_system_build_options_4 = ((ULONG)0xFFFF0000);
231 #else
232 _nx_system_build_options_4 = ((ULONG)NX_TCP_KEEPALIVE_INITIAL) << 16;
233 #endif
234 #if (NX_ARP_MAXIMUM_RETRIES > 0xFF)
235 _nx_system_build_options_4 |= ((ULONG)0xFF) << 8;
236 #else
237 _nx_system_build_options_4 |= ((ULONG)NX_ARP_MAXIMUM_RETRIES) << 8;
238 #endif
239 #if (NX_ARP_MAX_QUEUE_DEPTH > 0xF)
240 _nx_system_build_options_4 |= ((ULONG)0xF) << 4;
241 #else
242 _nx_system_build_options_4 |= ((ULONG)NX_ARP_MAX_QUEUE_DEPTH) << 4;
243 #endif
244 #if (NX_TCP_KEEPALIVE_RETRIES > 0xF)
245 _nx_system_build_options_4 |= ((ULONG)0xF);
246 #else
247 _nx_system_build_options_4 |= ((ULONG)NX_TCP_KEEPALIVE_RETRIES);
248 #endif
249
250 /* Setup the fifth option word. */
251 #if (NX_MAX_MULTICAST_GROUPS > 0xFF)
252 _nx_system_build_options_5 = ((ULONG)0xFF000000);
253 #else
254 _nx_system_build_options_5 = ((ULONG)NX_MAX_MULTICAST_GROUPS) << 24;
255 #endif
256 #if (NX_MAX_LISTEN_REQUESTS > 0xFF)
257 _nx_system_build_options_5 |= ((ULONG)0xFF) << 16;
258 #else
259 _nx_system_build_options_5 |= ((ULONG)NX_MAX_LISTEN_REQUESTS) << 16;
260 #endif
261 #if (NX_TCP_MAXIMUM_RETRIES > 0xFF)
262 _nx_system_build_options_5 |= ((ULONG)0xFF) << 8;
263 #else
264 _nx_system_build_options_5 |= ((ULONG)NX_TCP_MAXIMUM_RETRIES) << 8;
265 #endif
266 #if (NX_TCP_MAXIMUM_TX_QUEUE > 0xFF)
267 _nx_system_build_options_5 |= ((ULONG)0xFF);
268 #else
269 _nx_system_build_options_5 |= ((ULONG)NX_TCP_MAXIMUM_TX_QUEUE);
270 #endif
271 }
272
273