User Datagram Protocol (UDP)
The UDP layer of the Microchip TCP/IP Stack is imple- mented by the file “UDP.c”. The header file
“UDP.h” defines the services provided by the layer. In this stack architecture, UDP is an active
layer. It fetches UDP packets and notifies corresponding UDP socket of data arrival or
transmission. The UDP module is imple- mented as a cooperative task, performing automatic
operations without the knowledge of the main application.
“UDP.h” provides UDP socket services and hides all UDP packet handling from the caller. The layer
allows up to 254 UDP sockets (the number limited only by available memory and compiler used). With
more than one socket, higher level applications can maintain mul- tiple simultaneous UDP
connections; more than one application could be using this layer. It is important to know that
each socket consumes approximately 19 bytes (check “UDP.h” file for actual consumption)
and increases overall UDP processing time.
Unlike other socket implementations, all sockets in the Microchip TCP/IP Stack share one or more
common transmit buffers. This approach reduces overall RAM requirements, but it may create a
potential problem, where a few sockets reserve all available transmit buffers and do not release
them on time for other sockets to use. Under these circumstances, remote
hosts and/or local applications would not be able to contact the stack. To avoid this, users must
make sure that there are enough transmit buffers for all sockets.
On the receive side, there is only one receive buffer. If a socket receives its data, the owner of
that socket must fetch and discard the receive buffer in one task time in order for the other
sockets to receive their data. This design mandates that once a task detects a packet it is
interested in, it must consume the complete packet in one task time. A task cannot fetch part of a
packet during one task time and expect to fetch the rest of the packet later.
The UDP specifications do not mandate that checksum calculation be performed on UDP packets. To
reduce overall program and data memory requirements, the Microchip TCP/IP Stack does not implement
UDP checksum calculation; instead, it sets the checksum fields to zero to indicate that no checksum
calculation is performed. This design decision requires that all modules utilizing the UDP module
ensure their data
integrity.