]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/Common/FreeRTOS_Plus_UDP_Demos/TraceMacros/Example1/DemoIPTrace.c
Update license information text files for the CLI, TCP and UDP products to be correct...
[freertos] / FreeRTOS-Plus / Demo / Common / FreeRTOS_Plus_UDP_Demos / TraceMacros / Example1 / DemoIPTrace.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* \r
30  * This file, along with DemoIPTrace.h, provides a basic example use of the\r
31  * FreeRTOS+UDP trace macros.  The statistics gathered here can be viewed in\r
32  * the command line interface.\r
33  * See http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/UDP_IP_Trace.shtml\r
34  */\r
35 \r
36 /* Standard includes. */\r
37 #include <stdint.h>\r
38 \r
39 /* FreeRTOS includes. */ \r
40 #include "FreeRTOS.h"\r
41 #include "task.h"\r
42 \r
43 /* FreeRTOS+UDP includes. */\r
44 #include "FreeRTOS_UDP_IP.h"\r
45 #include "DemoIPTrace.h"\r
46 \r
47 /* It is possible to remove the trace macros using the \r
48 configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */\r
49 #if configINCLUDE_DEMO_DEBUG_STATS == 1\r
50 \r
51 /*\r
52  * Each row in the xIPTraceValues[] table contains a pointer to a function that\r
53  * updates the value for that row.  Rows that latch the lowest value point to\r
54  * this function (for example, this function can be used to latch the lowest\r
55  * number of network buffers that were available during the execution of the\r
56  * stack).\r
57  */\r
58 static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount );\r
59 \r
60 /*\r
61  * Each row in the xIPTraceValues[] table contains a pointer to a function that\r
62  * updates the value for that row.  Rows that simply increment an event count\r
63  * point to this function.\r
64  */\r
65 static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount );\r
66 \r
67 \r
68 xExampleDebugStatEntry_t xIPTraceValues[] =\r
69 {\r
70         /* Comment out array entries to remove individual trace items. */\r
71 \r
72         { iptraceID_NETWORK_INTERFACE_RECEIVE,                  ( const uint8_t * const ) "Packets received by the network interface",                  prvIncrementEventCount, 0 },\r
73         { iptraceID_NETWORK_INTERFACE_TRANSMIT,                 ( const uint8_t * const ) "Count of transmitted packets",                                               prvIncrementEventCount, 0 },\r
74         { iptraceID_PACKET_DROPPED_TO_GENERATE_ARP,             ( const uint8_t * const ) "Count of packets dropped to generate ARP",                   prvIncrementEventCount, 0 },\r
75         { iptraceID_NETWORK_BUFFER_OBTAINED,                    ( const uint8_t * const ) "Lowest ever available network buffers",                              prvStoreLowest, 0xffffUL },\r
76         { iptraceID_NETWORK_EVENT_RECEIVED,                             ( const uint8_t * const ) "Lowest ever free space in network event queue",              prvStoreLowest, 0xffffUL },\r
77         { iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER,    ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 },\r
78         { iptraceID_ARP_TABLE_ENTRY_EXPIRED,                    ( const uint8_t * const ) "Count of expired ARP entries",                                               prvIncrementEventCount, 0 },\r
79         { iptraceID_FAILED_TO_CREATE_SOCKET,                    ( const uint8_t * const ) "Count of failures to create a socket",                               prvIncrementEventCount, 0 },\r
80         { iptraceID_RECVFROM_DISCARDING_BYTES,                  ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes",             prvIncrementEventCount, 0 },\r
81         { iptraceID_ETHERNET_RX_EVENT_LOST,                             ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 },\r
82         { iptraceID_STACK_TX_EVENT_LOST,                                ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)",  prvIncrementEventCount, 0 },\r
83         { ipconfigID_BIND_FAILED,                                               ( const uint8_t * const ) "Count of failed calls to bind()",                                    prvIncrementEventCount, 0 },\r
84         { iptraceID_RECVFROM_TIMEOUT,                                   ( const uint8_t * const ) "Count of receive timeouts",                                                  prvIncrementEventCount, 0 },\r
85         { iptraceID_SENDTO_DATA_TOO_LONG,                               ( const uint8_t * const ) "Count of failed sends due to oversized payload",             prvIncrementEventCount, 0 },\r
86         { iptraceID_SENDTO_SOCKET_NOT_BOUND,                    ( const uint8_t * const ) "Count of failed sends due to unbound socket",                prvIncrementEventCount, 0 },\r
87         { iptraceID_NO_BUFFER_FOR_SENDTO,                               ( const uint8_t * const ) "Count of failed transmits due to timeout",                   prvIncrementEventCount, 0 },\r
88         { 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
89         { iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP,              ( const uint8_t * const ) "Failed to notify select group",                                              prvIncrementEventCount, 0 }\r
90 };\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 BaseType_t xExampleDebugStatEntries( void )\r
95 {\r
96         /* Return the number of entries in the xIPTraceValues[] table. */\r
97         return ( BaseType_t ) ( sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ) );\r
98 }\r
99 /*-----------------------------------------------------------*/\r
100 \r
101 void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue )\r
102 {\r
103 BaseType_t xIndex;\r
104 const BaseType_t xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t );\r
105 \r
106         /* Update an entry in the xIPTraceValues[] table.  Each row in the table\r
107         includes a pointer to a function that performs the actual update.  This\r
108         function just executes the update function from that table row. */\r
109         for( xIndex = 0; xIndex < xEntries; xIndex++ )\r
110         {\r
111                 if( xIPTraceValues[ xIndex ].ucIdentifier == ucIdentifier )\r
112                 {\r
113                         xIPTraceValues[ xIndex ].vPerformAction( &( xIPTraceValues[ xIndex ].ulData ), ulValue );\r
114                         break;\r
115                 }\r
116         }\r
117 \r
118         configASSERT( xIndex != xEntries );\r
119 }\r
120 /*-----------------------------------------------------------*/\r
121 \r
122 static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount )\r
123 {\r
124         /* Each row in the xIPTraceValues[] table contains a pointer to a function\r
125         that updates the value for that row.  Rows that simply increment an event\r
126         count point to this function. */\r
127         ( void ) ulCount;\r
128         ( *pulCurrentValue )++;\r
129 }\r
130 /*-----------------------------------------------------------*/\r
131 \r
132 static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount )\r
133 {\r
134         /* Each row in the xIPTraceValues[] table contains a pointer to a function\r
135         that updates the value for that row.  Rows that latch the lowest value\r
136         point to this function (for example, this function can be used to latch\r
137         the lowest number of network buffers that were available during the\r
138         execution of the stack). */\r
139         if( ulCount < *pulCurrentValue )\r
140         {\r
141                 *pulCurrentValue = ulCount;\r
142         }\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 \r
147 #endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */\r
148 \r
149 \r
150 \r
151 \r