1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** ThreadX Component */ 16 /** */ 17 /** Trace */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define TX_SOURCE_CODE 23 24 25 /* Include necessary system files. */ 26 27 #include "tx_api.h" 28 #include "tx_trace.h" 29 #ifdef TX_ENABLE_EVENT_TRACE 30 31 32 /* Define the pointer to the start of the trace buffer control structure. */ 33 34 TX_TRACE_HEADER *_tx_trace_header_ptr; 35 36 37 /* Define the pointer to the start of the trace object registry area in the trace buffer. */ 38 39 TX_TRACE_OBJECT_ENTRY *_tx_trace_registry_start_ptr; 40 41 42 /* Define the pointer to the end of the trace object registry area in the trace buffer. */ 43 44 TX_TRACE_OBJECT_ENTRY *_tx_trace_registry_end_ptr; 45 46 47 /* Define the pointer to the starting entry of the actual trace event area of the trace buffer. */ 48 49 TX_TRACE_BUFFER_ENTRY *_tx_trace_buffer_start_ptr; 50 51 52 /* Define the pointer to the ending entry of the actual trace event area of the trace buffer. */ 53 54 TX_TRACE_BUFFER_ENTRY *_tx_trace_buffer_end_ptr; 55 56 57 /* Define the pointer to the current entry of the actual trace event area of the trace buffer. */ 58 59 TX_TRACE_BUFFER_ENTRY *_tx_trace_buffer_current_ptr; 60 61 62 /* Define the trace event enable bits, where each bit represents a type of event that can be enabled 63 or disabled dynamically by the application. */ 64 65 ULONG _tx_trace_event_enable_bits; 66 67 68 /* Define a counter that is used in environments that don't have a timer source. This counter 69 is incremented on each use giving each event a unique timestamp. */ 70 71 ULONG _tx_trace_simulated_time; 72 73 74 /* Define the function pointer used to call the application when the trace buffer wraps. If NULL, 75 the application has not registered a callback function. */ 76 77 VOID (*_tx_trace_full_notify_function)(VOID *buffer); 78 79 80 /* Define the total number of registry entries. */ 81 82 ULONG _tx_trace_total_registry_entries; 83 84 85 /* Define a counter that is used to track the number of available registry entries. */ 86 87 ULONG _tx_trace_available_registry_entries; 88 89 90 /* Define an index that represents the start of the registry search. */ 91 92 ULONG _tx_trace_registry_search_start; 93 94 #endif 95 96 97 /**************************************************************************/ 98 /* */ 99 /* FUNCTION RELEASE */ 100 /* */ 101 /* _tx_trace_initialize PORTABLE C */ 102 /* 6.1 */ 103 /* AUTHOR */ 104 /* */ 105 /* William E. Lamie, Microsoft Corporation */ 106 /* */ 107 /* DESCRIPTION */ 108 /* */ 109 /* This function initializes the various control data structures for */ 110 /* the trace component. */ 111 /* */ 112 /* INPUT */ 113 /* */ 114 /* None */ 115 /* */ 116 /* OUTPUT */ 117 /* */ 118 /* None */ 119 /* */ 120 /* CALLS */ 121 /* */ 122 /* None */ 123 /* */ 124 /* CALLED BY */ 125 /* */ 126 /* _tx_initialize_high_level High level initialization */ 127 /* */ 128 /* RELEASE HISTORY */ 129 /* */ 130 /* DATE NAME DESCRIPTION */ 131 /* */ 132 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 133 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 134 /* resulting in version 6.1 */ 135 /* */ 136 /**************************************************************************/ _tx_trace_initialize(VOID)137VOID _tx_trace_initialize(VOID) 138 { 139 140 #ifdef TX_ENABLE_EVENT_TRACE 141 #ifndef TX_DISABLE_REDUNDANT_CLEARING 142 143 /* Initialize all the pointers to the trace buffer to NULL. */ 144 _tx_trace_header_ptr = TX_NULL; 145 _tx_trace_registry_start_ptr = TX_NULL; 146 _tx_trace_registry_end_ptr = TX_NULL; 147 _tx_trace_buffer_start_ptr = TX_NULL; 148 _tx_trace_buffer_end_ptr = TX_NULL; 149 _tx_trace_buffer_current_ptr = TX_NULL; 150 #endif 151 #endif 152 } 153 154