NetBurner 3.1
nbrtos/include/constants.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
10 #include <predef.h>
11 
12 #ifndef _CONSTANTS_H
13 #define _CONSTANTS_H
14 
15 #define TICK_IRQ_LEVEL (5) /* System clock IRQ level */
16 #define SERIAL_IRQ_LEVEL (3)
17 #define SERIAL_VECTOR_BASE (64)
18 
19 /*
20 
21 PLEASE READ THIS BEFORE MODIFYING TICKS_PER_SECOND
22 
23 Before you change this value understand what changing it does.
24 Making it faster only slows things down. It does not speed up task switches,
25 If only changes the granularity of time delays and timeouts.
26 Task switches happen much much faster than the tick interval. They happen as
27 soon as one task blocks or an interrupt /or task causes a higher priority task
28 to be unblocked. The Time tick has NOTHING to do with task switches.
29 
30 If you change it to the maximum 200 you have increased the RTOS overhead by a factor
31 of 10 and have actually slowed your system.
32 */
33 
34 #define TICKS_PER_SECOND (20) /* System clock tick */
35 
36 /*
37  *****************************************************************************
38  * OS Maximum Interrupt Level
39  *
40  * OS_MAX_IRQ_MASK - Optional, Maximum IRQ level that the RTOS is
41  * allowed to mask. RTOS objects may not be used
42  * in ISRs above this level.
43  *****************************************************************************
44  */
45 /* #define OS_MAX_IRQ (3) */
46 
47 /* Ethernet buffer defines */
48 #define ETHER_BUFFER_SIZE 1548
49 #define ETH_MAX_PAYLOAD (1500)
50 #define ETH_MAX_SIZE (1522)
51 #define ETH_MIN_SIZE (46)
52 #define IP_HEADER_SIZE (20)
53 #define UDP_HEADER_SIZE (8)
54 #define MAX_UDPDATA (ETH_MAX_PAYLOAD - (IP_HEADER_SIZE + UDP_HEADER_SIZE))
55 
56 #define SERIAL_TX_BUFFERS (2) /* ETHERN_BUFFER_SIZE = bytes of serial TX fifo */
57 #define SERIAL_RX_BUFFERS (2) /* ETHERN_BUFFER_SIZE = bytes of serial RX fifo */
58 #define stdin_buffer_size (200)
59 
60 #define OS_MAX_TASKS 32 /* Max number of system tasks */
61 
62 #define OS_MAX_PRIOS 64 /* Maximum number of system priorities */
63 
64 /*
65  ******************************************************************************
66  *
67  * System task priorities
68  *
69  * Restating the NBRTOS RTOS Library document (NBRtosLibrary.pdf)
70  * Lowest priority is OS_MAX_PRIOS-1, 1 is the highest.
71  * There can only be one task at each priority level.
72  * Idle task is created at priority 63.
73  *
74  * UserMain is created at priority 10. It is recommended and is supported by
75  * examples and default projects that a call to
76  * OSChangePrio( MAIN_PRIO );
77  * be made to lower the priority to the range recommended for the main
78  * application.
79  *
80  * Factory applications use priorities 46 through 56.
81  *
82  * Netburner Runtime library support and driver tasks use 36 through 45.
83  *
84  * Care should be taken in use of priorities it can affect reliability and
85  * performance.
86  *
87  ******************************************************************************
88  */
89 
90 /* Recommend UserMain priority */
91 #define MAIN_PRIO (50)
92 
93 /* Runtime library driver and support task priorities */
94 #define CONFIG_SERVER_PRIO (44)
95 #define HTTP_PRIO (45)
96 #define PPP_PRIO (46)
97 #define SECURITY_TASK_PRIO (43)
98 #define WIFI_STATION_TASK_PRIO (42)
99 #define WIFI_TASK_PRIO (41)
100 #define ENC_TASK_PRIORITY (41)
101 #define TCP_PRIO (40)
102 #define IP_PRIO (39)
103 #define ETHER_SEND_PRIO (38)
104 
105 /* Features */
106 /* SSH server must be lower than main for progress displays */
107 #define SSH_TASK_PRIORITY (56)
108 
109 /*
110  ******************************************************************************
111  *
112  * Stack size definitions
113  *
114  * SSH requires larger stacks for session key generation see predef.h
115  *
116  ******************************************************************************
117  */
118 #if defined NB_SSH_SUPPORTED || defined NB_SSL_SUPPORTED
119 #define MAIN_TASK_STK_SIZE (3072)
120 #define IP_STK_SIZE (2048)
121 #define TCP_STK_SIZE (3072)
122 #define HTTP_STK_SIZE (3072)
123 #define IDLE_STK_SIZE (2048)
124 #define ETHER_SEND_STK_SIZE (2048)
125 #define PPP_STK_SIZE (2048)
126 #define USER_TASK_STK_SIZE (3072)
127 #else /* #ifdef NB_SSH_SUPPORTED */
128 #define MAIN_TASK_STK_SIZE (2048)
129 #define IP_STK_SIZE (2048)
130 #define TCP_STK_SIZE (2048)
131 #define HTTP_STK_SIZE (2048)
132 #define IDLE_STK_SIZE (2048)
133 #define ETHER_SEND_STK_SIZE (2048)
134 #define PPP_STK_SIZE (2048)
135 #define USER_TASK_STK_SIZE (2048)
136 #endif /* #ifdef NB_SSH_SUPPORTED */
137 
138 /* TCP definitions */
139 #define DEFAULT_TCP4_MSS (512)
140 #define DEFAULT_TCP6_MSS (1200)
141 #define DEFAULT_TCP_RTTVAR \
142  ((TICKS_PER_SECOND * 3) / 4) /*See RFC 1122 for a 50msec tick 60 ticks=3 sec 4*15=60 (The 4 comes from stevens Vol1-300) */
143 #define TCP_CONN_TO (75 * TICKS_PER_SECOND) /* 75 seconds Min */
144 #define TCP_ACK_TICK_DLY (TICKS_PER_SECOND / 5) /* 200 msec delayed ACK timer */
145 #define DEFAULT_INITAL_RTO (TICKS_PER_SECOND * 3)
146 #define TCP_MAX_RTO (64 * TICKS_PER_SECOND)
147 #define TCP_MIN_RTO (TICKS_PER_SECOND / 2)
148 #define TCP_2MSL_WAIT (60 * TICKS_PER_SECOND)
149 #define MAX_TCP_RETRY (12)
150 #define TCP_WRITE_TIMEOUT (TICKS_PER_SECOND * 10)
151 #define TCP_BUFFER_SEGMENTS (3) /* Store 3 segments max in tx and rx buffers */
152 
153 #define MAX_MULTICAST_GROUPS (32)
154 
155 #define HTTP_TIMEOUT (TICKS_PER_SECOND * 10) /* 10 idle Seconds and a partially received request is abandoned */
156 #define HTTP_READ_TIME_LIMIT (30) /* Seconds to allow reading to avoid denial of service*/
157 #define HTTP_RX_BUFFERSIZE (10000)
158 #define MAX_HTTP_PENDING_SOCKETS (5) // Number of sockets allowed to be pending on listening socket, performance will degrade < 3
159 #define MAX_HTTP_CONNECTED_SOCKETS (5) // Number of sockets allowed to be connected to http server simultaneously
160 
161 // FDs are preallocated
162 // STDOUT
163 // STDIN
164 // STDERR
165 // <-SERIAL_SOCKET_OFFSET
166 // Serial 0
167 // Serial 1
168 // <-TCP_SOCKET_OFFSET
169 // TCP FD's
170 // <-EXTRA_IO_OFFSET
171 // Extra FDS
172 
173 #define SERIAL_SOCKET_OFFSET (3)
174 #define TCP_SOCKET_OFFSET (5)
175 #define TCP_SOCKET_STRUCTS (128)
176 #define EXTRA_IO_OFFSET (TCP_SOCKET_OFFSET + TCP_SOCKET_STRUCTS)
177 #define EXTRA_FDS (122)
178 #define TOTAL_FDS (TCP_SOCKET_OFFSET + TCP_SOCKET_STRUCTS + EXTRA_FDS)
179 #define FDSET_ELEMENTS ((TOTAL_FDS) / 32)
180 
181 #define TASK_TABLE_SIZE 2
182 
183 #define MAX_IP_ERRS 3
184 
185 #define BUFFER_POOL_SIZE (256) /* was 64 in last release, we increased buffer segments to handle higher throughput events*/
186 #define POOL_BUFFER_SIZE (sizeof(pool_buffer)) // Size of each buffer - 1712 bytes by default
187 #define UDP_DISPATCH_SIZE (10)
188 #define UDP_MIN_BUFFER_THRESHOLD (10)
189 #define ARP_ENTRY_SIZE (256)
190 
191 #define UDP_NETBURNERID_PORT (0x4E42) /* NB */
192 #define UDP_DHCP_SERVER_PORT (67)
193 #define UDP_DHCP_CLIENT_PORT (68)
194 
195 #define TFTP_RX_PORT (1414)
196 
197 #define LINK_STATUS_CHECK_INTERVAL (2 * TICKS_PER_SECOND)
198 
199 #define FTPD_SOCKET_TIMEOUT (5 * 60 * TICKS_PER_SECOND)
200 
201 #ifndef _DEBUG
202 #define ENABLE_SRAM_SYS
203 #endif
204 
205 /* If ENABLE _SRAM_SYS is TRUE, then the processor's on-chip SRAM will be
206  used for fast network buffering and OS tasks as defined below:
207 */
208 #ifdef ENABLE_SRAM_SYS
209 #define FAST_SYSTEM_VARIABLES
210 
211 // Uncommented system tasks will be stored in SRAM, otherwise SDRAM will be used.
212 //#define FAST_IDLE_STACK
213 #define FAST_MAIN_STACK
214 #define FAST_ETHERNET_VARIABLES
215 #define FAST_ETHERNET_STACK
216 #define FAST_BUFFERS_VARIABLES
217 #define FAST_BUFFERS
218 #define FAST_IP_VARIABLES
219 #define FAST_IP_STACK
220 #define FAST_TCP_VARIABLES
221 #define FAST_TCP_STACK
222 //#define FAST_HTTP_STACK
223 //#define FAST_FTP_STACK
224 //#define FAST_WIFI_STACK
225 //#define FAST_PPP_STACK
226 //#define FAST_COMMAND_STACK
227 
228 /* If these defines are enabled, any user variables or tasks declared with
229  FAST_USR_STK or FAST_USR_VAR will be stored in SRAM.
230 */
231 #define FAST_USER_VARIABLES
232 #define FAST_USER_STACK
233 
234 #define FAST_TLS_VARIABLES
235 
236 #endif
237 
238 #ifdef FAST_SYSTEM_VARIABLES
239 #define FAST_SYS_VAR __attribute__((section("SYS_VAR_SECT")))
240 #define FAST_SYS_VAR_REL __attribute__((section("SYS_VAR_SECT_REL")))
241 #define FAST_SYS_VAR_REL_STR __attribute__((section("SYS_VAR_SECT_REL_STR")))
242 #else
243 #define FAST_SYS_VAR
244 #define FAST_SYS_VAR_REL
245 #define FAST_SYS_VAR_REL_STR
246 #endif
247 #ifdef FAST_IDLE_STACK
248 #define FAST_IDLE_STK __attribute__((section("IDLE_STK_SECT")))
249 #else
250 #define FAST_IDLE_STK
251 #endif
252 #ifdef FAST_MAIN_STACK
253 #define FAST_MAIN_STK __attribute__((section("MAIN_STK_SECT")))
254 #else
255 #define FAST_MAIN_STK
256 #endif
257 #ifdef FAST_USER_STACK
258 #define FAST_USER_STK __attribute__((section("USER_STK_SECT")))
259 #else
260 #define FAST_USER_STK
261 #endif
262 #ifdef FAST_USER_VARIABLES
263 #define FAST_USER_VAR __attribute__((section("USER_VAR_SECT")))
264 #else
265 #define FAST_USER_VAR
266 #endif
267 #ifdef FAST_ETHERNET_VARIABLES
268 #define FAST_ETHER_VAR __attribute__((section("ETHER_VAR_SECT")))
269 #define FAST_ETHER_VAR_REL __attribute__((section("ETHER_VAR_SECT_REL")))
270 #else
271 #define FAST_ETHER_VAR
272 #define FAST_ETHER_VAR_REL
273 #endif
274 #ifdef FAST_ETHERNET_STACK
275 #define FAST_ETHER_STK __attribute__((section("ETHER_STK_SECT")))
276 #else
277 #define FAST_ETHER_STK
278 #endif
279 #ifdef FAST_IP_VARIABLES
280 #define FAST_IP_VAR __attribute__((section("IP_VAR_SECT")))
281 #define FAST_IP_VAR_REL __attribute__((section("IP_VAR_SECT_REL")))
282 #else
283 #define FAST_IP_VAR
284 #define FAST_IP_VAR_REL
285 #endif
286 #ifdef FAST_IP_STACK
287 #define FAST_IP_STK __attribute__((section("IP_STK_SECT")))
288 #else
289 #define FAST_IP_STK
290 #endif
291 #ifdef FAST_TCP_VARIABLES
292 #define FAST_TCP_VAR __attribute__((section("TCP_VAR_SECT")))
293 #define FAST_TCP_VAR_REL __attribute__((section("TCP_VAR_SECT_REL")))
294 #else
295 #define FAST_TCP_VAR
296 #define FAST_TCP_VAR_REL
297 #endif
298 #ifdef FAST_TCP_STACK
299 #define FAST_TCP_STK __attribute__((section("TCP_STK_SECT")))
300 #else
301 #define FAST_TCP_STK
302 #endif
303 #ifdef FAST_HTTP_STACK
304 #define FAST_HTTP_STK __attribute__((section("HTTP_STK_SECT")))
305 #else
306 #define FAST_HTTP_STK
307 #endif
308 #ifdef FAST_FTP_STACK
309 #define FAST_FTP_STK __attribute__((section("FTP_STK_SECT")))
310 #else
311 #define FAST_FTP_STK
312 #endif
313 #ifdef FAST_WIFI_STACK
314 #define FAST_WIFI_STK __attribute__((section("WIFI_STK_SECT")))
315 #else
316 #define FAST_WIFI_STK
317 #endif
318 #ifdef FAST_PPP_STACK
319 #define FAST_PPP_STK __attribute__((section("PPP_STK_SECT")))
320 #else
321 #define FAST_PPP_STK
322 #endif
323 #ifdef FAST_COMMAND_STACK
324 #define FAST_COMMAND_STK __attribute__((section("COMMAND_STK_SECT")))
325 #else
326 #define FAST_COMMAND_STK
327 #endif
328 #ifdef FAST_BUFFERS_VARIABLES
329 #define FAST_BUFF_VAR __attribute__((section("BUFFERS_VAR_SECT")))
330 #define FAST_BUFF_VAR_REL __attribute__((section("BUFFERS_VAR_SECT_REL")))
331 #else
332 #define FAST_BUFF_VAR
333 #define FAST_BUFF_VAR_REL
334 #endif
335 #ifdef FAST_TLS_VARIABLES
336 #define FAST_TLS_VAR __attribute__((section("TLS_VAR_SECT")))
337 #define FAST_TLS_VAR_REL __attribute__((section("TLS_VAR_SECT_REL")))
338 #else
339 #define FAST_TLS_VAR
340 #define FAST_TLS_VAR_REL
341 #endif
342 #define DO_NOT_CACHE __attribute__((section("NO_CACHE_SECT")))
343 
344 #endif /* #ifndef _CONSTANTS_H */