Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /********************************************************************* |
2 | * |
||
3 | * UDP Performance Test |
||
4 | * Module for Microchip TCP/IP Stack |
||
5 | * -Sends out dummy packets from ROM memory |
||
6 | * -Reference: None. This is for testing only. |
||
7 | * |
||
8 | ********************************************************************* |
||
9 | * FileName: UDPPerformanceTest.c |
||
10 | * Dependencies: UDP, Ethernet (ENC28J60.c or ETH97J60.c) |
||
11 | * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32 |
||
12 | * Compiler: Microchip C32 v1.05 or higher |
||
13 | * Microchip C30 v3.12 or higher |
||
14 | * Microchip C18 v3.30 or higher |
||
15 | * HI-TECH PICC-18 PRO 9.63PL2 or higher |
||
16 | * Company: Microchip Technology, Inc. |
||
17 | * |
||
18 | * Software License Agreement |
||
19 | * |
||
20 | * Copyright (C) 2002-2009 Microchip Technology Inc. All rights |
||
21 | * reserved. |
||
22 | * |
||
23 | * Microchip licenses to you the right to use, modify, copy, and |
||
24 | * distribute: |
||
25 | * (i) the Software when embedded on a Microchip microcontroller or |
||
26 | * digital signal controller product ("Device") which is |
||
27 | * integrated into Licensee's product; or |
||
28 | * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, |
||
29 | * ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device |
||
30 | * used in conjunction with a Microchip ethernet controller for |
||
31 | * the sole purpose of interfacing with the ethernet controller. |
||
32 | * |
||
33 | * You should refer to the license agreement accompanying this |
||
34 | * Software for additional information regarding your rights and |
||
35 | * obligations. |
||
36 | * |
||
37 | * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT |
||
38 | * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT |
||
39 | * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
||
40 | * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
41 | * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR |
||
42 | * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF |
||
43 | * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS |
||
44 | * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE |
||
45 | * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER |
||
46 | * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT |
||
47 | * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. |
||
48 | * |
||
49 | * |
||
50 | * Author Date Comment |
||
51 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
52 | * Howard Schlunder 01/29/07 Original |
||
53 | ********************************************************************/ |
||
54 | #define __UDPPERFORMANCETEST_C |
||
55 | |||
56 | #include "TCPIPConfig.h" |
||
57 | |||
58 | #if defined(STACK_USE_UDP_PERFORMANCE_TEST) |
||
59 | |||
60 | #include "TCPIP Stack/TCPIP.h" |
||
61 | |||
62 | |||
63 | // Which UDP port to broadcast from for the UDP tests |
||
64 | #define PERFORMANCE_PORT 9 |
||
65 | |||
66 | |||
67 | /***************************************************************************** |
||
68 | Function: |
||
69 | void UDPPerformanceTask(void) |
||
70 | |||
71 | Summary: |
||
72 | Tests the transmit performance of the UDP module. |
||
73 | |||
74 | Description: |
||
75 | This function tests the transmit performance of the UDP module. At boot, |
||
76 | this module will transmit 1024 large UDP broadcast packets of 1024 bytes |
||
77 | each. Using a packet sniffer, one can determine how long this process |
||
78 | takes and calculate the transmit rate of the stack. This function tests |
||
79 | true UDP performance in that it will open a socket, transmit one packet, |
||
80 | and close the socket for each loop. After this initial transmission, the |
||
81 | module can be re-enabled by holding button 3. |
||
82 | |||
83 | This function is particularly useful after development to determine the |
||
84 | impact of your application code on the stack's performance. A before and |
||
85 | after comparison will indicate if your application is unacceptably |
||
86 | blocking the processor or taking too long to execute. |
||
87 | |||
88 | Precondition: |
||
89 | UDP is initialized. |
||
90 | |||
91 | Parameters: |
||
92 | None |
||
93 | |||
94 | Returns: |
||
95 | None |
||
96 | ***************************************************************************/ |
||
97 | void UDPPerformanceTask(void) |
||
98 | { |
||
99 | UDP_SOCKET MySocket; |
||
100 | NODE_INFO Remote; |
||
101 | WORD wTemp; |
||
102 | static DWORD dwCounter = 1; |
||
103 | |||
104 | if((BUTTON3_IO) && (dwCounter > 1024u)) |
||
105 | return; |
||
106 | |||
107 | // Suppress transmissions if we don't have an Ethernet link so our counter starts correctly at 0x00000001 |
||
108 | if(!MACIsLinked()) |
||
109 | return; |
||
110 | |||
111 | #if defined(STACK_USE_DHCP_CLIENT) && defined(DELAY_UDP_PERFORMANCE_TEST) |
||
112 | { |
||
113 | static DWORD dwTimer = 0; |
||
114 | |||
115 | // Wait until DHCP module is finished |
||
116 | if(!DHCPIsBound(0)) |
||
117 | { |
||
118 | dwTimer = TickGet(); |
||
119 | return; |
||
120 | } |
||
121 | |||
122 | // Wait an additional half second after DHCP is finished to let the announce module and any other stack state machines to reach normal operation |
||
123 | if(TickGet() - dwTimer < TICK_SECOND/2) |
||
124 | return; |
||
125 | } |
||
126 | #endif |
||
127 | |||
128 | // Set the socket's destination to be a broadcast over our IP |
||
129 | // subnet |
||
130 | // Set the MAC destination to be a broadcast |
||
131 | memset(&Remote, 0xFF, sizeof(Remote)); |
||
132 | |||
133 | // Open a UDP socket for outbound transmission |
||
134 | MySocket = UDPOpen(0, &Remote, PERFORMANCE_PORT); |
||
135 | |||
136 | // Abort operation if no UDP sockets are available |
||
137 | // If this ever happens, incrementing MAX_UDP_SOCKETS in |
||
138 | // StackTsk.h may help (at the expense of more global memory |
||
139 | // resources). |
||
140 | if(MySocket == INVALID_UDP_SOCKET) |
||
141 | return; |
||
142 | |||
143 | // Make certain the socket can be written to |
||
144 | if(!UDPIsPutReady(MySocket)) |
||
145 | { |
||
146 | UDPClose(MySocket); |
||
147 | return; |
||
148 | } |
||
149 | |||
150 | // Put counter value into first 4 bytes of the packet |
||
151 | UDPPutArray((BYTE*)&dwCounter, sizeof(dwCounter)); |
||
152 | dwCounter++; |
||
153 | |||
154 | wTemp = UDPPutROMArray((ROM BYTE*) |
||
155 | "The quick brown fox tried to jump over the yellow dog. Unfortunately, the yellow dog stood up while the fox was in mid-jump. As a result, the two collided. Then, the dog, being the omnivore that it is, ate the quick brown fox. This line is 256 bytes.\r\n" |
||
156 | "The quick brown fox tried to jump over the yellow dog. Unfortunately, the yellow dog stood up while the fox was in mid-jump. As a result, the two collided. Then, the dog, being the omnivore that it is, ate the quick brown fox. This line is 256 bytes.\r\n" |
||
157 | "The quick brown fox tried to jump over the yellow dog. Unfortunately, the yellow dog stood up while the fox was in mid-jump. As a result, the two collided. Then, the dog, being the omnivore that it is, ate the quick brown fox. This line is 256 bytes.\r\n" |
||
158 | "The quick brown fox tried to jump over the yellow dog. Unfortunately, the yellow dog stood up while the fox was in mid-jump. As a result, the two collided. Then, the dog, being the omnivore that it is, ate the quick brown fox. This line is 252b. \r\n", 1020); |
||
159 | |||
160 | // Send the packet |
||
161 | UDPFlush(); |
||
162 | |||
163 | // Close the socket so it can be used by other modules |
||
164 | UDPClose(MySocket); |
||
165 | } |
||
166 | |||
167 | #endif //#if defined(STACK_USE_UDP_PERFORMANCE_TEST) |
Powered by WebSVN v2.8.3