]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS-Plus / Demo / Common / FreeRTOS_Plus_UDP_Demos / TraceMacros / Example1 / DemoIPTrace.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /* \r
97  * This file, along with DemoIPTrace.h, provides a basic example use of the\r
98  * FreeRTOS+UDP trace macros.  The statistics gathered here can be viewed in\r
99  * the command line interface.\r
100  * See http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/UDP_IP_Trace.shtml\r
101  */\r
102 \r
103 /* Standard includes. */\r
104 #include <stdint.h>\r
105 \r
106 /* FreeRTOS includes. */ \r
107 #include "FreeRTOS.h"\r
108 #include "task.h"\r
109 \r
110 /* FreeRTOS+UDP includes. */\r
111 #include "FreeRTOS_UDP_IP.h"\r
112 #include "DemoIPTrace.h"\r
113 \r
114 /* It is possible to remove the trace macros using the \r
115 configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */\r
116 #if configINCLUDE_DEMO_DEBUG_STATS == 1\r
117 \r
118 /*\r
119  * Each row in the xIPTraceValues[] table contains a pointer to a function that\r
120  * updates the value for that row.  Rows that latch the lowest value point to\r
121  * this function (for example, this function can be used to latch the lowest\r
122  * number of network buffers that were available during the execution of the\r
123  * stack).\r
124  */\r
125 static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount );\r
126 \r
127 /*\r
128  * Each row in the xIPTraceValues[] table contains a pointer to a function that\r
129  * updates the value for that row.  Rows that simply increment an event count\r
130  * point to this function.\r
131  */\r
132 static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount );\r
133 \r
134 \r
135 xExampleDebugStatEntry_t xIPTraceValues[] =\r
136 {\r
137         /* Comment out array entries to remove individual trace items. */\r
138 \r
139         { iptraceID_NETWORK_INTERFACE_RECEIVE,                  ( const uint8_t * const ) "Packets received by the network interface",                  prvIncrementEventCount, 0 },\r
140         { iptraceID_NETWORK_INTERFACE_TRANSMIT,                 ( const uint8_t * const ) "Count of transmitted packets",                                               prvIncrementEventCount, 0 },\r
141         { iptraceID_PACKET_DROPPED_TO_GENERATE_ARP,             ( const uint8_t * const ) "Count of packets dropped to generate ARP",                   prvIncrementEventCount, 0 },\r
142         { iptraceID_NETWORK_BUFFER_OBTAINED,                    ( const uint8_t * const ) "Lowest ever available network buffers",                              prvStoreLowest, 0xffffUL },\r
143         { iptraceID_NETWORK_EVENT_RECEIVED,                             ( const uint8_t * const ) "Lowest ever free space in network event queue",              prvStoreLowest, 0xffffUL },\r
144         { iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER,    ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 },\r
145         { iptraceID_ARP_TABLE_ENTRY_EXPIRED,                    ( const uint8_t * const ) "Count of expired ARP entries",                                               prvIncrementEventCount, 0 },\r
146         { iptraceID_FAILED_TO_CREATE_SOCKET,                    ( const uint8_t * const ) "Count of failures to create a socket",                               prvIncrementEventCount, 0 },\r
147         { iptraceID_RECVFROM_DISCARDING_BYTES,                  ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes",             prvIncrementEventCount, 0 },\r
148         { iptraceID_ETHERNET_RX_EVENT_LOST,                             ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 },\r
149         { iptraceID_STACK_TX_EVENT_LOST,                                ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)",  prvIncrementEventCount, 0 },\r
150         { ipconfigID_BIND_FAILED,                                               ( const uint8_t * const ) "Count of failed calls to bind()",                                    prvIncrementEventCount, 0 },\r
151         { iptraceID_RECVFROM_TIMEOUT,                                   ( const uint8_t * const ) "Count of receive timeouts",                                                  prvIncrementEventCount, 0 },\r
152         { iptraceID_SENDTO_DATA_TOO_LONG,                               ( const uint8_t * const ) "Count of failed sends due to oversized payload",             prvIncrementEventCount, 0 },\r
153         { iptraceID_SENDTO_SOCKET_NOT_BOUND,                    ( const uint8_t * const ) "Count of failed sends due to unbound socket",                prvIncrementEventCount, 0 },\r
154         { iptraceID_NO_BUFFER_FOR_SENDTO,                               ( const uint8_t * const ) "Count of failed transmits due to timeout",                   prvIncrementEventCount, 0 },\r
155         { iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR,                 ( const uint8_t * const ) "Number of times task had to wait to obtain a DMA Tx descriptor", prvIncrementEventCount, 0 },\r
156         { iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP,              ( const uint8_t * const ) "Failed to notify select group",                                              prvIncrementEventCount, 0 }\r
157 };\r
158 \r
159 /*-----------------------------------------------------------*/\r
160 \r
161 BaseType_t xExampleDebugStatEntries( void )\r
162 {\r
163         /* Return the number of entries in the xIPTraceValues[] table. */\r
164         return ( BaseType_t ) ( sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ) );\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue )\r
169 {\r
170 BaseType_t xIndex;\r
171 const BaseType_t xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t );\r
172 \r
173         /* Update an entry in the xIPTraceValues[] table.  Each row in the table\r
174         includes a pointer to a function that performs the actual update.  This\r
175         function just executes the update function from that table row. */\r
176         for( xIndex = 0; xIndex < xEntries; xIndex++ )\r
177         {\r
178                 if( xIPTraceValues[ xIndex ].ucIdentifier == ucIdentifier )\r
179                 {\r
180                         xIPTraceValues[ xIndex ].vPerformAction( &( xIPTraceValues[ xIndex ].ulData ), ulValue );\r
181                         break;\r
182                 }\r
183         }\r
184 \r
185         configASSERT( xIndex != xEntries );\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount )\r
190 {\r
191         /* Each row in the xIPTraceValues[] table contains a pointer to a function\r
192         that updates the value for that row.  Rows that simply increment an event\r
193         count point to this function. */\r
194         ( void ) ulCount;\r
195         ( *pulCurrentValue )++;\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \r
199 static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount )\r
200 {\r
201         /* Each row in the xIPTraceValues[] table contains a pointer to a function\r
202         that updates the value for that row.  Rows that latch the lowest value\r
203         point to this function (for example, this function can be used to latch\r
204         the lowest number of network buffers that were available during the\r
205         execution of the stack). */\r
206         if( ulCount < *pulCurrentValue )\r
207         {\r
208                 *pulCurrentValue = ulCount;\r
209         }\r
210 }\r
211 /*-----------------------------------------------------------*/\r
212 \r
213 \r
214 #endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */\r
215 \r
216 \r
217 \r
218 \r