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