1 /* 2 * FreeRTOS V202212.00 3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 * this software and associated documentation files (the "Software"), to deal in 7 * the Software without restriction, including without limitation the rights to 8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 * the Software, and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in all 13 * copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * https://www.FreeRTOS.org 23 * https://github.com/FreeRTOS 24 * 25 */ 26 27 /* 28 * This file, along with DemoIPTrace.h, provides a basic example use of the 29 * FreeRTOS+UDP trace macros. The statistics gathered here can be viewed in 30 * the command line interface. 31 * See http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/UDP_IP_Trace.shtml 32 */ 33 34 #ifndef DEMO_IP_TRACE_MACROS_H 35 #define DEMO_IP_TRACE_MACROS_H 36 37 typedef void ( * vTraceAction_t )( uint32_t *, 38 uint32_t ); 39 40 /* Type that defines each statistic being gathered. */ 41 typedef struct ExampleDebugStatEntry 42 { 43 uint8_t ucIdentifier; /* Unique identifier for statistic. */ 44 const uint8_t * const pucDescription; /* Text description for the statistic. */ 45 vTraceAction_t vPerformAction; /* Action to perform when the statistic is updated (increment counter, store minimum value, store maximum value, etc. */ 46 uint32_t ulData; /* The meaning of this data is dependent on the trace macro ID. */ 47 } xExampleDebugStatEntry_t; 48 49 /* Unique identifiers used to locate the entry for each trace macro in the 50 * xIPTraceValues[] table defined in DemoIPTrace.c. */ 51 #define iptraceID_NETWORK_INTERFACE_RECEIVE 0 52 #define iptraceID_NETWORK_INTERFACE_TRANSMIT 1 53 #define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 2 54 55 /* Do not change IDs above this line as the ID is shared with a FreeRTOS+Nabto 56 * demo. */ 57 #define iptraceID_NETWORK_BUFFER_OBTAINED 3 58 #define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 4 59 #define iptraceID_NETWORK_EVENT_RECEIVED 5 60 #define iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER 6 61 #define iptraceID_ARP_TABLE_ENTRY_EXPIRED 7 62 #define iptraceID_FAILED_TO_CREATE_SOCKET 8 63 #define iptraceID_RECVFROM_DISCARDING_BYTES 9 64 #define iptraceID_ETHERNET_RX_EVENT_LOST 10 65 #define iptraceID_STACK_TX_EVENT_LOST 11 66 #define ipconfigID_BIND_FAILED 12 67 #define iptraceID_RECVFROM_TIMEOUT 13 68 #define iptraceID_SENDTO_DATA_TOO_LONG 14 69 #define iptraceID_SENDTO_SOCKET_NOT_BOUND 15 70 #define iptraceID_NO_BUFFER_FOR_SENDTO 16 71 #define iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR 17 72 #define iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP 18 73 74 /* It is possible to remove the trace macros using the 75 * configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */ 76 #if configINCLUDE_DEMO_DEBUG_STATS == 1 77 78 /* The trace macro definitions themselves. Any trace macros left undefined 79 * will default to be empty macros. */ 80 #define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) ) 81 #define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) ) 82 83 #define iptraceNETWORK_EVENT_RECEIVED( eEvent ) \ 84 { \ 85 uint16_t usSpace; \ 86 usSpace = ( uint16_t ) uxQueueMessagesWaiting( xNetworkEventQueue ); \ 87 /* Minus one as an event was removed before the space was queried. */ \ 88 usSpace = ( ipconfigEVENT_QUEUE_LENGTH - usSpace ) - 1; \ 89 vExampleDebugStatUpdate( iptraceID_NETWORK_EVENT_RECEIVED, usSpace ); \ 90 } 91 92 #define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER() vExampleDebugStatUpdate( iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, 0 ) 93 #define iptraceARP_TABLE_ENTRY_EXPIRED( ulIPAddress ) vExampleDebugStatUpdate( iptraceID_ARP_TABLE_ENTRY_EXPIRED, 0 ) 94 #define iptracePACKET_DROPPED_TO_GENERATE_ARP( ulIPAddress ) vExampleDebugStatUpdate( iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, 0 ) 95 #define iptraceFAILED_TO_CREATE_SOCKET() vExampleDebugStatUpdate( iptraceID_FAILED_TO_CREATE_SOCKET, 0 ) 96 #define iptraceRECVFROM_DISCARDING_BYTES( xNumberOfBytesDiscarded ) vExampleDebugStatUpdate( iptraceID_RECVFROM_DISCARDING_BYTES, 0 ) 97 #define iptraceETHERNET_RX_EVENT_LOST() vExampleDebugStatUpdate( iptraceID_ETHERNET_RX_EVENT_LOST, 0 ) 98 #define iptraceSTACK_TX_EVENT_LOST( xEvent ) vExampleDebugStatUpdate( iptraceID_STACK_TX_EVENT_LOST, 0 ) 99 #define iptraceBIND_FAILED( xSocket, usPort ) vExampleDebugStatUpdate( ipconfigID_BIND_FAILED, 0 ) 100 #define iptraceNETWORK_INTERFACE_TRANSMIT() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_TRANSMIT, 0 ) 101 #define iptraceRECVFROM_TIMEOUT() vExampleDebugStatUpdate( iptraceID_RECVFROM_TIMEOUT, 0 ) 102 #define iptraceSENDTO_DATA_TOO_LONG() vExampleDebugStatUpdate( iptraceID_SENDTO_DATA_TOO_LONG, 0 ) 103 #define iptraceSENDTO_SOCKET_NOT_BOUND() vExampleDebugStatUpdate( iptraceID_SENDTO_SOCKET_NOT_BOUND, 0 ) 104 #define iptraceNO_BUFFER_FOR_SENDTO() vExampleDebugStatUpdate( iptraceID_NO_BUFFER_FOR_SENDTO, 0 ) 105 #define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR() vExampleDebugStatUpdate( iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, 0 ) 106 #define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket ) vExampleDebugStatUpdate( iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, 0 ) 107 #define iptraceNETWORK_INTERFACE_RECEIVE() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_RECEIVE, 0 ) 108 109 /* 110 * The function that updates a line in the xIPTraceValues table. 111 */ 112 void vExampleDebugStatUpdate( uint8_t ucIdentifier, 113 uint32_t ulValue ); 114 115 /* 116 * Returns the number of entries in the xIPTraceValues table. 117 */ 118 BaseType_t xExampleDebugStatEntries( void ); 119 120 #endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */ 121 122 123 #endif /* DEMO_IP_TRACE_MACROS_H */ 124