Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
363 johboh 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, PIC24F, PIC24H, dsPIC30F, dsPIC33F
10
 * Complier:        Microchip C18 v3.02 or higher
11
 *                  Microchip C30 v2.01 or higher
12
 * Company:         Microchip Technology, Inc.
13
 *
14
 * Software License Agreement
15
 *
16
 * This software is owned by Microchip Technology Inc. ("Microchip")
17
 * and is supplied to you for use exclusively as described in the
18
 * associated software agreement.  This software is protected by
19
 * software and other intellectual property laws.  Any use in
20
 * violation of the software license may subject the user to criminal
21
 * sanctions as well as civil liability.  Copyright 2006 Microchip
22
 * Technology Inc.  All rights reserved.
23
 *
24
 * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL
25
 * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED
26
 * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
27
 * INFRINGEMENT.  Microchip shall in no event be liable for special,
28
 * incidental, or consequential damages.
29
 *
30
 *
31
 * Author               Date    Comment
32
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
 * Nilesh Rajbharti     3/19/01  Original        (Rev 1.0)
34
 ********************************************************************/
35
 
36
#ifndef UDP_H
37
#define UDP_H
38
 
39
#include "..\Include\StackTsk.h"
40
#include "..\Include\IP.h"
41
#include "..\Include\MAC.h"
42
 
43
 
44
 
45
typedef WORD UDP_PORT;
46
typedef BYTE UDP_SOCKET;
47
 
48
typedef struct _UDP_SOCKET_INFO
49
{
50
    NODE_INFO   remoteNode;
51
    UDP_PORT    remotePort;
52
    UDP_PORT    localPort;
53
    WORD        TxCount;
54
    WORD        RxCount;
55
    BUFFER      TxBuffer;
56
    WORD        TxOffset;
57
 
58
    struct
59
    {
60
        unsigned char bFirstRead     : 1;
61
    } Flags;
62
 
63
} UDP_SOCKET_INFO;
64
 
65
 
66
#define INVALID_UDP_SOCKET      (0xff)
67
#define INVALID_UDP_PORT        (0L)
68
 
69
/*
70
 * All module utilizing UDP module will get extern definition of
71
 * activeUDPSocket.  While UDP module itself will define activeUDPSocket.
72
 */
73
#if !defined(THIS_IS_UDP_MODULE)
74
    extern UDP_SOCKET activeUDPSocket;
75
    extern UDP_SOCKET_INFO  UDPSocketInfo[MAX_UDP_SOCKETS];
76
#endif
77
 
78
 
79
typedef struct _UDP_HEADER
80
{
81
    UDP_PORT    SourcePort;
82
    UDP_PORT    DestinationPort;
83
    WORD        Length;
84
    WORD        Checksum;
85
} UDP_HEADER;
86
 
87
 
88
/*********************************************************************
89
 * Function:        void UDPInit(void)
90
 *
91
 * PreCondition:    None
92
 *
93
 * Input:           None
94
 *
95
 * Output:          None
96
 *
97
 * Side Effects:    None
98
 *
99
 * Overview:        Initializes internal variables.
100
 *
101
 * Note:
102
 ********************************************************************/
103
void        UDPInit(void);
104
 
105
 
106
/*********************************************************************
107
 * Function:        UDP_SOCKET UDPOpen(UDP_PORT localPort,
108
 *                                     NODE_INFO *remoteNode,
109
 *                                     UDP_PORT remotePort)
110
 *
111
 * PreCondition:    UDPInit() is already called
112
 *
113
 * Input:           remoteNode - Remote Node info such as MAC and IP
114
 *                               address
115
 *                               If NULL, localPort is opened for
116
 *                               Listen.
117
 *                  remotePort - Remote Port to which to talk to
118
 *                               If INVALID_UDP_SOCKET, localPort is
119
 *                               opened for Listen.
120
 *                  localPort  - A non-zero port number.
121
 *
122
 * Output:          A valid UDP socket that is to be used for
123
 *                  subsequent UDP communications.
124
 *
125
 * Side Effects:    None
126
 *
127
 * Overview:        A UDP packet header is assembled and loaded into
128
 *                  UDP transmit buffer.
129
 *
130
 * Note:            A localPort value of '0' is considered nonexistent
131
 *                  port.  This call must always have nonzero localPort
132
 *                  value.
133
 *                  This function sets returned socket as an active
134
 *                  UDP socket.
135
  ********************************************************************/
136
UDP_SOCKET UDPOpen(UDP_PORT localPort,
137
                   NODE_INFO *remoteNode,
138
                   UDP_PORT remotePort);
139
 
140
 
141
/*********************************************************************
142
 * Function:        void UDPClose(UDP_SOCKET s)
143
 *
144
 * PreCondition:    UDPOpen() is already called
145
 *
146
 * Input:           s       - Socket that is to be closed.
147
 *
148
 * Output:          None
149
 *
150
 * Side Effects:    None
151
 *
152
 * Overview:        Given socket is marked as available for future
153
 *                  new communcations.
154
 *
155
 * Note:            This function does not affect previous
156
 *                  active UDP socket designation.
157
  ********************************************************************/
158
void UDPClose(UDP_SOCKET s);
159
 
160
 
161
/*********************************************************************
162
 * Macro:           BOOL UDPIsPutReady(UDP_SOCKET s)
163
 *
164
 * PreCondition:
165
 *
166
 * Input:           s       - Socket that is to be loaded and made
167
 *                            an active UDP socket.
168
 *
169
 * Output:          TRUE if at least one UDP buffer is ready to transmit
170
 *                  FALSE if no UDP buffer is ready
171
 *
172
 * Side Effects:    None
173
 *
174
 * Overview:        None
175
 *
176
 * Note:            This call sets given socket as an active UDP socket.
177
 ********************************************************************/
178
#define UDPIsPutReady(s)        (activeUDPSocket = s, MACIsTxReady(TRUE))
179
 
180
 
181
/*********************************************************************
182
 * Function:        BOOL UDPPut(BYTE v)
183
 *
184
 * PreCondition:    UDPIsPutReady() == TRUE with desired UDP socket
185
 *                  that is to be loaded.
186
 *
187
 * Input:           v       - Data byte to loaded into transmit buffer
188
 *
189
 * Output:          TRUE if transmit buffer is still ready to accept
190
 *                  more data bytes
191
 *
192
 *                  FALSE if transmit buffer can no longer accept
193
 *                  any more data byte.
194
 *
195
 * Side Effects:    None
196
 *
197
 * Overview:        Given data byte is put into UDP transmit buffer
198
 *                  and active UDP socket buffer length is incremented
199
 *                  by one.
200
 *                  If buffer has become full, FALSE is returned.
201
 *                  Or else TRUE is returned.
202
 *
203
 * Note:            This function loads data into an active UDP socket
204
 *                  as determined by previous call to UDPIsPutReady()
205
 ********************************************************************/
206
BOOL UDPPut(BYTE v);
207
 
208
 
209
/*********************************************************************
210
 * Function:        BOOL UDPFlush(void)
211
 *
212
 * PreCondition:    UDPPut() is already called and desired UDP socket
213
 *                  is set as an active socket by calling
214
 *                  UDPIsPutReady().
215
 *
216
 * Input:           None
217
 *
218
 * Output:          All and any data associated with active UDP socket
219
 *                  buffer is marked as ready for transmission.
220
 *
221
 * Side Effects:    None
222
 *
223
 * Overview:        None
224
 *
225
 * Note:            This function transmit all data from
226
 *                  an active UDP socket.
227
 ********************************************************************/
228
void UDPFlush(void);
229
 
230
 
231
 
232
/*********************************************************************
233
 * Function:        BOOL UDPIsGetReady(UDP_SOCKET s)
234
 *
235
 * PreCondition:    UDPInit() is already called.
236
 *
237
 * Input:           A valid UDP socket that is already "Listen"ed on
238
 *                  or opened.
239
 *
240
 * Output:          TRUE if given port contains any data.
241
 *                  FALSE if given port does not contain any data.
242
 *
243
 * Side Effects:    Given socket is set as an active UDP Socket.
244
 *
245
 * Overview:        None
246
 *
247
 * Note:            This function automatically sets supplied socket
248
 *                  as an active socket.  Caller need not call
249
 *                  explicit function UDPSetActiveSocket().  All
250
 *                  subsequent calls will us this socket as an
251
 *                  active socket.
252
 ********************************************************************/
253
BOOL UDPIsGetReady(UDP_SOCKET s);
254
 
255
 
256
 
257
/*********************************************************************
258
 * Function:        BOOL UDPGet(BYTE *v)
259
 *
260
 * PreCondition:    UDPInit() is already called     AND
261
 *                  UDPIsGetReady(s) == TRUE
262
 *
263
 * Input:           v       - Buffer to receive UDP data byte
264
 *
265
 * Output:          TRUE    if a data byte was read
266
 *                  FALSE   if no data byte was read or available
267
 *
268
 * Side Effects:    None
269
 *
270
 * Overview:        None
271
 *
272
 * Note:            This function fetches data from an active UDP
273
 *                  socket as set by UDPIsGetReady() call.
274
 ********************************************************************/
275
BOOL UDPGet(BYTE *v);
276
 
277
 
278
/*********************************************************************
279
 * Function:        void UDPDiscard(void)
280
 *
281
 * PreCondition:    UDPInit() is already called    AND
282
 *                  UDPIsGetReady() == TRUE with desired UDP socket.
283
 *
284
 * Input:           None
285
 *
286
 * Output:          None
287
 *
288
 * Side Effects:    None
289
 *
290
 * Overview:        None
291
 *
292
 * Note:            This function discards an active UDP socket content.
293
 ********************************************************************/
294
void UDPDiscard(void);
295
 
296
 
297
 
298
/*********************************************************************
299
 * Function:        BOOL UDPProcess(NODE_INFO* remoteNode,
300
 *                                  IP_ADDR *localIP,
301
 *                                  WORD len)
302
 *
303
 * PreCondition:    UDPInit() is already called     AND
304
 *                  UDP segment is ready in MAC buffer
305
 *
306
 * Input:           remoteNode      - Remote node info
307
 *                  len             - Total length of UDP semgent.
308
 *
309
 * Output:          TRUE if this function has completed its task
310
 *                  FALSE otherwise
311
 *
312
 * Side Effects:    None
313
 *
314
 * Overview:        None
315
 *
316
 * Note:            None
317
 ********************************************************************/
318
BOOL        UDPProcess(NODE_INFO *remoteNode,
319
                       IP_ADDR *localIP,
320
                       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