1 |
/*********************************************************************
|
2 |
*
|
3 |
* UDP Module Defs for Microchip TCP/IP Stack
|
4 |
*
|
5 |
*********************************************************************
|
6 |
* FileName: UDP.h
|
7 |
* Dependencies: StackTsk.h
|
8 |
* MAC.h
|
9 |
* Processor: PIC18
|
10 |
* Complier: MCC18 v1.00.50 or higher
|
11 |
* HITECH PICC-18 V8.10PL1 or higher
|
12 |
* Company: Microchip Technology, Inc.
|
13 |
*
|
14 |
* Software License Agreement
|
15 |
*
|
16 |
* The software supplied herewith by Microchip Technology Incorporated
|
17 |
* (the “Company”) for its PICmicro® Microcontroller is intended and
|
18 |
* supplied to you, the Company’s customer, for use solely and
|
19 |
* exclusively on Microchip PICmicro Microcontroller products. The
|
20 |
* software is owned by the Company and/or its supplier, and is
|
21 |
* protected under applicable copyright laws. All rights are reserved.
|
22 |
* Any use in violation of the foregoing restrictions may subject the
|
23 |
* user to criminal sanctions under applicable laws, as well as to
|
24 |
* civil liability for the breach of the terms and conditions of this
|
25 |
* license.
|
26 |
*
|
27 |
* THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
|
28 |
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
|
29 |
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
30 |
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
|
31 |
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
|
32 |
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
33 |
*
|
34 |
* Author Date Comment
|
35 |
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
36 |
* Nilesh Rajbharti 3/19/01 Original (Rev 1.0)
|
37 |
********************************************************************/
|
38 |
|
39 |
#ifndef UDP_H
|
40 |
#define UDP_H
|
41 |
|
42 |
#include "stacktsk.h"
|
43 |
#include "ip.h"
|
44 |
#include "mac.h"
|
45 |
|
46 |
|
47 |
|
48 |
typedef WORD UDP_PORT;
|
49 |
typedef BYTE UDP_SOCKET;
|
50 |
|
51 |
typedef struct _UDP_SOCKET_INFO
|
52 |
{
|
53 |
NODE_INFO remoteNode;
|
54 |
UDP_PORT remotePort;
|
55 |
UDP_PORT localPort;
|
56 |
WORD TxCount;
|
57 |
WORD RxCount;
|
58 |
BUFFER TxBuffer;
|
59 |
WORD TxOffset;
|
60 |
|
61 |
struct
|
62 |
{
|
63 |
unsigned int bFirstRead : 1;
|
64 |
} Flags;
|
65 |
|
66 |
} UDP_SOCKET_INFO;
|
67 |
|
68 |
|
69 |
#define INVALID_UDP_SOCKET (0xff)
|
70 |
#define INVALID_UDP_PORT (0L)
|
71 |
|
72 |
/*
|
73 |
* All module utilizing UDP module will get extern definition of
|
74 |
* activeUDPSocket. While UDP module itself will define activeUDPSocket.
|
75 |
*/
|
76 |
#if !defined(THIS_IS_UDP_MODULE)
|
77 |
extern UDP_SOCKET activeUDPSocket;
|
78 |
extern UDP_SOCKET_INFO UDPSocketInfo[MAX_UDP_SOCKETS];
|
79 |
#endif
|
80 |
|
81 |
|
82 |
typedef struct _UDP_HEADER
|
83 |
{
|
84 |
UDP_PORT SourcePort;
|
85 |
UDP_PORT DestinationPort;
|
86 |
WORD Length;
|
87 |
WORD Checksum;
|
88 |
} UDP_HEADER;
|
89 |
|
90 |
|
91 |
/*********************************************************************
|
92 |
* Function: void UDPInit(void)
|
93 |
*
|
94 |
* PreCondition: None
|
95 |
*
|
96 |
* Input: None
|
97 |
*
|
98 |
* Output: None
|
99 |
*
|
100 |
* Side Effects: None
|
101 |
*
|
102 |
* Overview: Initializes internal variables.
|
103 |
*
|
104 |
* Note:
|
105 |
********************************************************************/
|
106 |
void UDPInit(void);
|
107 |
|
108 |
|
109 |
/*********************************************************************
|
110 |
* Function: UDP_SOCKET UDPOpen(UDP_PORT localPort,
|
111 |
* NODE_INFO *remoteNode,
|
112 |
* UDP_PORT remotePort)
|
113 |
*
|
114 |
* PreCondition: UDPInit() is already called
|
115 |
*
|
116 |
* Input: remoteNode - Remote Node info such as MAC and IP
|
117 |
* address
|
118 |
* If NULL, localPort is opened for
|
119 |
* Listen.
|
120 |
* remotePort - Remote Port to which to talk to
|
121 |
* If INVALID_UDP_SOCKET, localPort is
|
122 |
* opened for Listen.
|
123 |
* localPort - A non-zero port number.
|
124 |
*
|
125 |
* Output: A valid UDP socket that is to be used for
|
126 |
* subsequent UDP communications.
|
127 |
*
|
128 |
* Side Effects: None
|
129 |
*
|
130 |
* Overview: A UDP packet header is assembled and loaded into
|
131 |
* UDP transmit buffer.
|
132 |
*
|
133 |
* Note: A localPort value of '0' is considered nonexistent
|
134 |
* port. This call must always have nonzero localPort
|
135 |
* value.
|
136 |
* This function sets returned socket as an active
|
137 |
* UDP socket.
|
138 |
********************************************************************/
|
139 |
UDP_SOCKET UDPOpen(UDP_PORT localPort,
|
140 |
NODE_INFO *remoteNode,
|
141 |
UDP_PORT remotePort);
|
142 |
|
143 |
|
144 |
/*********************************************************************
|
145 |
* Function: void UDPClose(UDP_SOCKET s)
|
146 |
*
|
147 |
* PreCondition: UDPOpen() is already called
|
148 |
*
|
149 |
* Input: s - Socket that is to be closed.
|
150 |
*
|
151 |
* Output: None
|
152 |
*
|
153 |
* Side Effects: None
|
154 |
*
|
155 |
* Overview: Given socket is marked as available for future
|
156 |
* new communcations.
|
157 |
*
|
158 |
* Note: This function does not affect previous
|
159 |
* active UDP socket designation.
|
160 |
********************************************************************/
|
161 |
void UDPClose(UDP_SOCKET s);
|
162 |
|
163 |
|
164 |
/*********************************************************************
|
165 |
* Macro: BOOL UDPIsPutReady(UDP_SOCKET s)
|
166 |
*
|
167 |
* PreCondition:
|
168 |
*
|
169 |
* Input: s - Socket that is to be loaded and made
|
170 |
* an active UDP socket.
|
171 |
*
|
172 |
* Output: TRUE if at least one UDP buffer is ready to transmit
|
173 |
* FALSE if no UDP buffer is ready
|
174 |
*
|
175 |
* Side Effects: None
|
176 |
*
|
177 |
* Overview: None
|
178 |
*
|
179 |
* Note: This call sets given socket as an active UDP socket.
|
180 |
********************************************************************/
|
181 |
#define UDPIsPutReady(s) (activeUDPSocket = s, MACIsTxReady())
|
182 |
|
183 |
|
184 |
/*********************************************************************
|
185 |
* Function: BOOL UDPPut(BYTE v)
|
186 |
*
|
187 |
* PreCondition: UDPIsPutReady() == TRUE with desired UDP socket
|
188 |
* that is to be loaded.
|
189 |
*
|
190 |
* Input: v - Data byte to loaded into transmit buffer
|
191 |
*
|
192 |
* Output: TRUE if transmit buffer is still ready to accept
|
193 |
* more data bytes
|
194 |
*
|
195 |
* FALSE if transmit buffer can no longer accept
|
196 |
* any more data byte.
|
197 |
*
|
198 |
* Side Effects: None
|
199 |
*
|
200 |
* Overview: Given data byte is put into UDP transmit buffer
|
201 |
* and active UDP socket buffer length is incremented
|
202 |
* by one.
|
203 |
* If buffer has become full, FALSE is returned.
|
204 |
* Or else TRUE is returned.
|
205 |
*
|
206 |
* Note: This function loads data into an active UDP socket
|
207 |
* as determined by previous call to UDPIsPutReady()
|
208 |
********************************************************************/
|
209 |
BOOL UDPPut(BYTE v);
|
210 |
|
211 |
|
212 |
/*********************************************************************
|
213 |
* Function: BOOL UDPFlush(void)
|
214 |
*
|
215 |
* PreCondition: UDPPut() is already called and desired UDP socket
|
216 |
* is set as an active socket by calling
|
217 |
* UDPIsPutReady().
|
218 |
*
|
219 |
* Input: None
|
220 |
*
|
221 |
* Output: All and any data associated with active UDP socket
|
222 |
* buffer is marked as ready for transmission.
|
223 |
*
|
224 |
* Side Effects: None
|
225 |
*
|
226 |
* Overview: None
|
227 |
*
|
228 |
* Note: This function transmit all data from
|
229 |
* an active UDP socket.
|
230 |
********************************************************************/
|
231 |
void UDPFlush(void);
|
232 |
|
233 |
|
234 |
|
235 |
/*********************************************************************
|
236 |
* Function: BOOL UDPIsGetReady(UDP_SOCKET s)
|
237 |
*
|
238 |
* PreCondition: UDPInit() is already called.
|
239 |
*
|
240 |
* Input: A valid UDP socket that is already "Listen"ed on
|
241 |
* or opened.
|
242 |
*
|
243 |
* Output: TRUE if given port contains any data.
|
244 |
* FALSE if given port does not contain any data.
|
245 |
*
|
246 |
* Side Effects: Given socket is set as an active UDP Socket.
|
247 |
*
|
248 |
* Overview: None
|
249 |
*
|
250 |
* Note: This function automatically sets supplied socket
|
251 |
* as an active socket. Caller need not call
|
252 |
* explicit function UDPSetActiveSocket(). All
|
253 |
* subsequent calls will us this socket as an
|
254 |
* active socket.
|
255 |
********************************************************************/
|
256 |
BOOL UDPIsGetReady(UDP_SOCKET s);
|
257 |
|
258 |
|
259 |
|
260 |
/*********************************************************************
|
261 |
* Function: BOOL UDPGet(BYTE *v)
|
262 |
*
|
263 |
* PreCondition: UDPInit() is already called AND
|
264 |
* UDPIsGetReady(s) == TRUE
|
265 |
*
|
266 |
* Input: v - Buffer to receive UDP data byte
|
267 |
*
|
268 |
* Output: TRUE if a data byte was read
|
269 |
* FALSE if no data byte was read or available
|
270 |
*
|
271 |
* Side Effects: None
|
272 |
*
|
273 |
* Overview: None
|
274 |
*
|
275 |
* Note: This function fetches data from an active UDP
|
276 |
* socket as set by UDPIsGetReady() call.
|
277 |
********************************************************************/
|
278 |
BOOL UDPGet(BYTE *v);
|
279 |
|
280 |
|
281 |
/*********************************************************************
|
282 |
* Function: void UDPDiscard(void)
|
283 |
*
|
284 |
* PreCondition: UDPInit() is already called AND
|
285 |
* UDPIsGetReady() == TRUE with desired UDP socket.
|
286 |
*
|
287 |
* Input: None
|
288 |
*
|
289 |
* Output: None
|
290 |
*
|
291 |
* Side Effects: None
|
292 |
*
|
293 |
* Overview: None
|
294 |
*
|
295 |
* Note: This function discards an active UDP socket content.
|
296 |
********************************************************************/
|
297 |
void UDPDiscard(void);
|
298 |
|
299 |
|
300 |
|
301 |
/*********************************************************************
|
302 |
* Function: BOOL UDPProcess(NODE_INFO* remoteNode,
|
303 |
* WORD len)
|
304 |
*
|
305 |
* PreCondition: UDPInit() is already called AND
|
306 |
* UDP segment is ready in MAC buffer
|
307 |
*
|
308 |
* Input: remoteNode - Remote node info
|
309 |
* len - Total length of UDP semgent.
|
310 |
*
|
311 |
* Output: TRUE if this function has completed its task
|
312 |
* FALSE otherwise
|
313 |
*
|
314 |
* Side Effects: None
|
315 |
*
|
316 |
* Overview: None
|
317 |
*
|
318 |
* Note: None
|
319 |
********************************************************************/
|
320 |
BOOL UDPProcess(NODE_INFO *remoteNode, WORD len);
|
321 |
|
322 |
|
323 |
/*********************************************************************
|
324 |
* Macro: UDPSetTxBuffer(a, b)
|
325 |
*
|
326 |
* PreCondition: None
|
327 |
*
|
328 |
* Input: a - Buffer identifier
|
329 |
* b - Offset
|
330 |
*
|
331 |
* Output: Next Read/Write access to transmit buffer 'a'
|
332 |
* set to offset 'b'
|
333 |
*
|
334 |
* Side Effects: None
|
335 |
*
|
336 |
* Note: None
|
337 |
*
|
338 |
********************************************************************/
|
339 |
#define UDPSetTxBuffer(a, b) (UDPSocketInfo[activeUDPSocket].TxOffset = b, IPSetTxBuffer(a, b+sizeof(UDP_HEADER)))
|
340 |
|
341 |
|
342 |
/*********************************************************************
|
343 |
* Macro: UDPSetRxBuffer(a)
|
344 |
*
|
345 |
* PreCondition: None
|
346 |
*
|
347 |
* Input: a - Offset
|
348 |
*
|
349 |
* Output: Next Read/Write access to receive buffer is
|
350 |
* set to offset 'b'
|
351 |
*
|
352 |
* Side Effects: None
|
353 |
*
|
354 |
* Note: None
|
355 |
*
|
356 |
********************************************************************/
|
357 |
#define UDPSetRxBuffer(a) IPSetRxBuffer(a+sizeof(UDP_HEADER))
|
358 |
|
359 |
|
360 |
#endif
|