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