]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c
Update version number to V8.0.0 (without the release candidate number).
[freertos] / FreeRTOS-Plus / Demo / Common / FreeRTOS_Plus_UDP_Demos / TraceMacros / Example1 / DemoIPTrace.c
1 /*\r
2     FreeRTOS V8.0.0 - 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /* \r
67  * This file, along with DemoIPTrace.h, provides a basic example use of the\r
68  * FreeRTOS+UDP trace macros.  The statistics gathered here can be viewed in\r
69  * the command line interface.\r
70  * See http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/UDP_IP_Trace.shtml\r
71  */\r
72 \r
73 /* Standard includes. */\r
74 #include <stdint.h>\r
75 \r
76 /* FreeRTOS includes. */ \r
77 #include "FreeRTOS.h"\r
78 #include "task.h"\r
79 \r
80 /* FreeRTOS+UDP includes. */\r
81 #include "FreeRTOS_UDP_IP.h"\r
82 #include "DemoIPTrace.h"\r
83 \r
84 /* It is possible to remove the trace macros using the \r
85 configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */\r
86 #if configINCLUDE_DEMO_DEBUG_STATS == 1\r
87 \r
88 /*\r
89  * Each row in the xIPTraceValues[] table contains a pointer to a function that\r
90  * updates the value for that row.  Rows that latch the lowest value point to\r
91  * this function (for example, this function can be used to latch the lowest\r
92  * number of network buffers that were available during the execution of the\r
93  * stack).\r
94  */\r
95 static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount );\r
96 \r
97 /*\r
98  * Each row in the xIPTraceValues[] table contains a pointer to a function that\r
99  * updates the value for that row.  Rows that simply increment an event count\r
100  * point to this function.\r
101  */\r
102 static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount );\r
103 \r
104 \r
105 xExampleDebugStatEntry_t xIPTraceValues[] =\r
106 {\r
107         /* Comment out array entries to remove individual trace items. */\r
108 \r
109         { iptraceID_NETWORK_INTERFACE_RECEIVE,                  ( const uint8_t * const ) "Packets received by the network interface",                  prvIncrementEventCount, 0 },\r
110         { iptraceID_NETWORK_INTERFACE_TRANSMIT,                 ( const uint8_t * const ) "Count of transmitted packets",                                               prvIncrementEventCount, 0 },\r
111         { iptraceID_PACKET_DROPPED_TO_GENERATE_ARP,             ( const uint8_t * const ) "Count of packets dropped to generate ARP",                   prvIncrementEventCount, 0 },\r
112         { iptraceID_NETWORK_BUFFER_OBTAINED,                    ( const uint8_t * const ) "Lowest ever available network buffers",                              prvStoreLowest, 0xffffUL },\r
113         { iptraceID_NETWORK_EVENT_RECEIVED,                             ( const uint8_t * const ) "Lowest ever free space in network event queue",              prvStoreLowest, 0xffffUL },\r
114         { iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER,    ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 },\r
115         { iptraceID_ARP_TABLE_ENTRY_EXPIRED,                    ( const uint8_t * const ) "Count of expired ARP entries",                                               prvIncrementEventCount, 0 },\r
116         { iptraceID_FAILED_TO_CREATE_SOCKET,                    ( const uint8_t * const ) "Count of failures to create a socket",                               prvIncrementEventCount, 0 },\r
117         { iptraceID_RECVFROM_DISCARDING_BYTES,                  ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes",             prvIncrementEventCount, 0 },\r
118         { iptraceID_ETHERNET_RX_EVENT_LOST,                             ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 },\r
119         { iptraceID_STACK_TX_EVENT_LOST,                                ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)",  prvIncrementEventCount, 0 },\r
120         { ipconfigID_BIND_FAILED,                                               ( const uint8_t * const ) "Count of failed calls to bind()",                                    prvIncrementEventCount, 0 },\r
121         { iptraceID_RECVFROM_TIMEOUT,                                   ( const uint8_t * const ) "Count of receive timeouts",                                                  prvIncrementEventCount, 0 },\r
122         { iptraceID_SENDTO_DATA_TOO_LONG,                               ( const uint8_t * const ) "Count of failed sends due to oversized payload",             prvIncrementEventCount, 0 },\r
123         { iptraceID_SENDTO_SOCKET_NOT_BOUND,                    ( const uint8_t * const ) "Count of failed sends due to unbound socket",                prvIncrementEventCount, 0 },\r
124         { iptraceID_NO_BUFFER_FOR_SENDTO,                               ( const uint8_t * const ) "Count of failed transmits due to timeout",                   prvIncrementEventCount, 0 },\r
125         { 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
126         { iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP,              ( const uint8_t * const ) "Failed to notify select group",                                              prvIncrementEventCount, 0 }\r
127 };\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 portBASE_TYPE xExampleDebugStatEntries( void )\r
132 {\r
133         /* Return the number of entries in the xIPTraceValues[] table. */\r
134         return ( portBASE_TYPE ) ( sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ) );\r
135 }\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue )\r
139 {\r
140 portBASE_TYPE xIndex;\r
141 const portBASE_TYPE xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t );\r
142 \r
143         /* Update an entry in the xIPTraceValues[] table.  Each row in the table\r
144         includes a pointer to a function that performs the actual update.  This\r
145         function just executes the update function from that table row. */\r
146         for( xIndex = 0; xIndex < xEntries; xIndex++ )\r
147         {\r
148                 if( xIPTraceValues[ xIndex ].ucIdentifier == ucIdentifier )\r
149                 {\r
150                         xIPTraceValues[ xIndex ].vPerformAction( &( xIPTraceValues[ xIndex ].ulData ), ulValue );\r
151                         break;\r
152                 }\r
153         }\r
154 \r
155         configASSERT( xIndex != xEntries );\r
156 }\r
157 /*-----------------------------------------------------------*/\r
158 \r
159 static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount )\r
160 {\r
161         /* Each row in the xIPTraceValues[] table contains a pointer to a function\r
162         that updates the value for that row.  Rows that simply increment an event\r
163         count point to this function. */\r
164         ( void ) ulCount;\r
165         ( *pulCurrentValue )++;\r
166 }\r
167 /*-----------------------------------------------------------*/\r
168 \r
169 static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount )\r
170 {\r
171         /* Each row in the xIPTraceValues[] table contains a pointer to a function\r
172         that updates the value for that row.  Rows that latch the lowest value\r
173         point to this function (for example, this function can be used to latch\r
174         the lowest number of network buffers that were available during the\r
175         execution of the stack). */\r
176         if( ulCount < *pulCurrentValue )\r
177         {\r
178                 *pulCurrentValue = ulCount;\r
179         }\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 \r
184 #endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */\r
185 \r
186 \r
187 \r
188 \r