1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** ThreadX Component */ 17 /** */ 18 /** Trace */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 /**************************************************************************/ 24 /* */ 25 /* COMPONENT DEFINITION RELEASE */ 26 /* */ 27 /* tx_trace.h PORTABLE C */ 28 /* 6.1 */ 29 /* AUTHOR */ 30 /* */ 31 /* William E. Lamie, Microsoft Corporation */ 32 /* */ 33 /* DESCRIPTION */ 34 /* */ 35 /* This file defines the ThreadX trace component, including constants */ 36 /* and structure definitions as well as external references. It is */ 37 /* assumed that tx_api.h and tx_port.h have already been included. */ 38 /* */ 39 /* RELEASE HISTORY */ 40 /* */ 41 /* DATE NAME DESCRIPTION */ 42 /* */ 43 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 44 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 45 /* resulting in version 6.1 */ 46 /* */ 47 /**************************************************************************/ 48 49 50 /* Include necessary system files. */ 51 52 #ifndef TX_TRACE_H 53 #define TX_TRACE_H 54 55 56 /* Determine if tracing is enabled. If not, simply define the in-line trace 57 macros to whitespace. */ 58 59 #ifndef TX_ENABLE_EVENT_TRACE 60 #define TX_TRACE_INITIALIZE 61 #define TX_TRACE_OBJECT_REGISTER(t,p,n,a,b) 62 #define TX_TRACE_OBJECT_UNREGISTER(o) 63 #define TX_TRACE_IN_LINE_INSERT(i,a,b,c,d,f) 64 #else 65 66 /* Event tracing is enabled. */ 67 68 /* Ensure that the thread component information is included. */ 69 70 #include "tx_thread.h" 71 72 73 /* Define trace port-specfic extension to white space if it isn't defined 74 already. */ 75 76 #ifndef TX_TRACE_PORT_EXTENSION 77 #define TX_TRACE_PORT_EXTENSION 78 #endif 79 80 81 /* Define the default clock source for trace event entry time stamp. The following two item are port specific. 82 For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock 83 source constants would be: 84 85 #define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024) 86 #define TX_TRACE_TIME_MASK 0x0000FFFFUL 87 88 */ 89 90 #ifndef TX_TRACE_TIME_SOURCE 91 #define TX_TRACE_TIME_SOURCE ++_tx_trace_simulated_time 92 #endif 93 #ifndef TX_TRACE_TIME_MASK 94 #define TX_TRACE_TIME_MASK 0xFFFFFFFFUL 95 #endif 96 97 98 /* Define the ID showing the event trace buffer is valid. */ 99 100 #define TX_TRACE_VALID 0x54585442UL 101 102 103 /* ThreadX Trace Description. The ThreadX Trace feature is designed to capture 104 events in real-time in a circular event buffer. This buffer may be analyzed by other 105 tools. The high-level format of the Trace structure is: 106 107 [Trace Control Header ] 108 [Trace Object Registry - Entry 0 ] 109 ... 110 [Trace Object Registry - Entry "n" ] 111 [Trace Buffer - Entry 0 ] 112 ... 113 [Trace Buffer - Entry "n" ] 114 115 */ 116 117 118 /* Trace Control Header. The Trace Control Header contains information that 119 defines the format of the Trace Object Registry as well as the location and 120 current entry of the Trace Buffer itself. The high-level format of the 121 Trace Control Header is: 122 123 Entry Size Description 124 125 [Trace ID] 4 This 4-byte field contains the ThreadX Trace 126 Identification. If the trace buffer is valid, the 127 contents are 0x54585442 (TXTB). Since it is written as 128 a 32-bit unsigned word, this value is also used to 129 determine if the event trace information is in 130 little or big endian format. 131 [Timer Valid Mask] 4 Mask of valid bits in the 32-bit time stamp. This 132 enables use of 32, 24, 16, or event 8-bit timers. 133 If the time source is 32-bits, the mask is 134 0xFFFFFFFF. If the time source is 16-bits, the 135 mask is 0x0000FFFF. 136 [Trace Base Address] 4 The base address for all trace pointer. Subtracting 137 the pointer and this address will yield the proper 138 offset into the trace buffer. 139 [Trace Object Registry Start Pointer] 4 Pointer to the start of Trace Object Registry 140 [Reserved] 2 Reserved two bytes - should be 0x0000 141 [Trace Object Object Name Size] 2 Number of bytes in object name 142 [Trace Object Registry End Pointer] 4 Pointer to the end of Trace Object Registry 143 [Trace Buffer Start Pointer] 4 Pointer to the start of the Trace Buffer Area 144 [Trace Buffer End Pointer] 4 Pointer to the end of the Trace Buffer Area 145 [Trace Buffer Current Pointer] 4 Pointer to the oldest entry in the Trace Buffer. 146 This entry will be overwritten on the next event and 147 incremented to the next event (wrapping to the top 148 if the buffer end pointer is exceeded). 149 [Reserved] 4 Reserved 4 bytes, should be 0xAAAAAAAA 150 [Reserved] 4 Reserved 4 bytes, should be 0xBBBBBBBB 151 [Reserved] 4 Reserved 4 bytes, should be 0xCCCCCCCC 152 */ 153 154 155 /* Define the Trace Control Header. */ 156 157 typedef struct TX_TRACE_HEADER_STRUCT 158 { 159 160 ULONG tx_trace_header_id; 161 ULONG tx_trace_header_timer_valid_mask; 162 ULONG tx_trace_header_trace_base_address; 163 ULONG tx_trace_header_registry_start_pointer; 164 USHORT tx_trace_header_reserved1; 165 USHORT tx_trace_header_object_name_size; 166 ULONG tx_trace_header_registry_end_pointer; 167 ULONG tx_trace_header_buffer_start_pointer; 168 ULONG tx_trace_header_buffer_end_pointer; 169 ULONG tx_trace_header_buffer_current_pointer; 170 ULONG tx_trace_header_reserved2; 171 ULONG tx_trace_header_reserved3; 172 ULONG tx_trace_header_reserved4; 173 } TX_TRACE_HEADER; 174 175 176 /* Trace Object Registry. The Trace Object Registry is used to map the object pointer in the trace buffer to 177 the application's name for the object (defined during object creation in ThreadX). */ 178 179 #ifndef TX_TRACE_OBJECT_REGISTRY_NAME 180 #define TX_TRACE_OBJECT_REGISTRY_NAME 32 181 #endif 182 183 184 /* Define the object name types as well as the contents of any additional parameters that might be useful in 185 trace analysis. */ 186 187 #define TX_TRACE_OBJECT_TYPE_NOT_VALID ((UCHAR) 0) /* Object is not valid */ 188 #define TX_TRACE_OBJECT_TYPE_THREAD ((UCHAR) 1) /* P1 = stack start address, P2 = stack size */ 189 #define TX_TRACE_OBJECT_TYPE_TIMER ((UCHAR) 2) /* P1 = initial ticks, P2 = reschedule ticks */ 190 #define TX_TRACE_OBJECT_TYPE_QUEUE ((UCHAR) 3) /* P1 = queue size, P2 = message size */ 191 #define TX_TRACE_OBJECT_TYPE_SEMAPHORE ((UCHAR) 4) /* P1 = initial instances */ 192 #define TX_TRACE_OBJECT_TYPE_MUTEX ((UCHAR) 5) /* P1 = priority inheritance flag */ 193 #define TX_TRACE_OBJECT_TYPE_EVENT_FLAGS ((UCHAR) 6) /* none */ 194 #define TX_TRACE_OBJECT_TYPE_BLOCK_POOL ((UCHAR) 7) /* P1 = total blocks, P2 = block size */ 195 #define TX_TRACE_OBJECT_TYPE_BYTE_POOL ((UCHAR) 8) /* P1 = total bytes */ 196 197 198 typedef struct TX_TRACE_OBJECT_ENTRY_STRUCT 199 { 200 201 UCHAR tx_trace_object_entry_available; /* TX_TRUE -> available */ 202 UCHAR tx_trace_object_entry_type; /* Types defined above */ 203 UCHAR tx_trace_object_entry_reserved1; /* Should be zero - except for thread */ 204 UCHAR tx_trace_object_entry_reserved2; /* Should be zero - except for thread */ 205 ULONG tx_trace_object_entry_thread_pointer; /* ThreadX object pointer */ 206 ULONG tx_trace_object_entry_param_1; /* Parameter value defined */ 207 ULONG tx_trace_object_entry_param_2; /* according to type above */ 208 UCHAR tx_trace_object_entry_name[TX_TRACE_OBJECT_REGISTRY_NAME]; /* Object name */ 209 } TX_TRACE_OBJECT_ENTRY; 210 211 212 /* Trace Buffer Entry. The Trace Buffer Entry contains information about a particular 213 event in the system. The high-level format of the Trace Buffer Entry is: 214 215 Entry Size Description 216 217 [Thread Pointer] 4 This 4-byte field contains the pointer to the 218 ThreadX thread running that caused the event. 219 If this field is NULL, the entry hasn't been used 220 yet. If this field is 0xFFFFFFFF, the event occurred 221 from within an ISR. If this entry is 0xF0F0F0F0, the 222 event occurred during initialization. 223 [Thread Priority or 4 This 4-byte field contains the current thread pointer for interrupt 224 Current Thread events or the thread preemption-threshold/priority for thread events. 225 Preemption-Threshold/ 226 Priority] 227 [Event ID] 4 This 4-byte field contains the Event ID of the event. A value of 228 0xFFFFFFFF indicates the event is invalid. All events are marked 229 as invalid during initialization. 230 [Time Stamp] 4 This 4-byte field contains the time stamp of the event. 231 [Information Field 1] 4 This 4-byte field contains the first 4-bytes of information 232 specific to the event. 233 [Information Field 2] 4 This 4-byte field contains the second 4-bytes of information 234 specific to the event. 235 [Information Field 3] 4 This 4-byte field contains the third 4-bytes of information 236 specific to the event. 237 [Information Field 4] 4 This 4-byte field contains the fourth 4-bytes of information 238 specific to the event. 239 */ 240 241 #define TX_TRACE_INVALID_EVENT 0xFFFFFFFFUL 242 243 244 /* Define ThreadX Trace Events, along with a brief description of the additional information fields, 245 where I1 -> Information Field 1, I2 -> Information Field 2, etc. */ 246 247 /* Event numbers 0 through 4095 are reserved by Azure RTOS. Specific event assignments are: 248 249 ThreadX events: 1-199 250 FileX events: 200-299 251 NetX events: 300-599 252 USBX events: 600-999 253 254 User-defined event numbers start at 4096 and continue through 65535, as defined by the constants 255 TX_TRACE_USER_EVENT_START and TX_TRACE_USER_EVENT_END, respectively. User events should be based 256 on these constants in case the user event number assignment is changed in future releases. */ 257 258 /* Define the basic ThreadX thread scheduling events first. */ 259 260 #define TX_TRACE_THREAD_RESUME 1 /* I1 = thread ptr, I2 = previous_state, I3 = stack ptr, I4 = next thread */ 261 #define TX_TRACE_THREAD_SUSPEND 2 /* I1 = thread ptr, I2 = new_state, I3 = stack ptr I4 = next thread */ 262 #define TX_TRACE_ISR_ENTER 3 /* I1 = stack_ptr, I2 = ISR number, I3 = system state, I4 = preempt disable */ 263 #define TX_TRACE_ISR_EXIT 4 /* I1 = stack_ptr, I2 = ISR number, I3 = system state, I4 = preempt disable */ 264 #define TX_TRACE_TIME_SLICE 5 /* I1 = next thread ptr, I2 = system state, I3 = preempt disable, I4 = stack*/ 265 #define TX_TRACE_RUNNING 6 /* None */ 266 267 268 /* Define the rest of the ThreadX system events. */ 269 270 #define TX_TRACE_BLOCK_ALLOCATE 10 /* I1 = pool ptr, I2 = memory ptr, I3 = wait option, I4 = remaining blocks */ 271 #define TX_TRACE_BLOCK_POOL_CREATE 11 /* I1 = pool ptr, I2 = pool_start, I3 = total blocks, I4 = block size */ 272 #define TX_TRACE_BLOCK_POOL_DELETE 12 /* I1 = pool ptr, I2 = stack ptr */ 273 #define TX_TRACE_BLOCK_POOL_INFO_GET 13 /* I1 = pool ptr */ 274 #define TX_TRACE_BLOCK_POOL_PERFORMANCE_INFO_GET 14 /* I1 = pool ptr */ 275 #define TX_TRACE_BLOCK_POOL__PERFORMANCE_SYSTEM_INFO_GET 15 /* None */ 276 #define TX_TRACE_BLOCK_POOL_PRIORITIZE 16 /* I1 = pool ptr, I2 = suspended count, I3 = stack ptr */ 277 #define TX_TRACE_BLOCK_RELEASE 17 /* I1 = pool ptr, I2 = memory ptr, I3 = suspended, I4 = stack ptr */ 278 #define TX_TRACE_BYTE_ALLOCATE 20 /* I1 = pool ptr, I2 = memory ptr, I3 = size requested, I4 = wait option */ 279 #define TX_TRACE_BYTE_POOL_CREATE 21 /* I1 = pool ptr, I2 = start ptr, I3 = pool size, I4 = stack ptr */ 280 #define TX_TRACE_BYTE_POOL_DELETE 22 /* I1 = pool ptr, I2 = stack ptr */ 281 #define TX_TRACE_BYTE_POOL_INFO_GET 23 /* I1 = pool ptr */ 282 #define TX_TRACE_BYTE_POOL_PERFORMANCE_INFO_GET 24 /* I1 = pool ptr */ 283 #define TX_TRACE_BYTE_POOL__PERFORMANCE_SYSTEM_INFO_GET 25 /* None */ 284 #define TX_TRACE_BYTE_POOL_PRIORITIZE 26 /* I1 = pool ptr, I2 = suspended count, I3 = stack ptr */ 285 #define TX_TRACE_BYTE_RELEASE 27 /* I1 = pool ptr, I2 = memory ptr, I3 = suspended, I4 = available bytes */ 286 #define TX_TRACE_EVENT_FLAGS_CREATE 30 /* I1 = group ptr, I2 = stack ptr */ 287 #define TX_TRACE_EVENT_FLAGS_DELETE 31 /* I1 = group ptr, I2 = stack ptr */ 288 #define TX_TRACE_EVENT_FLAGS_GET 32 /* I1 = group ptr, I2 = requested flags, I3 = current flags, I4 = get option*/ 289 #define TX_TRACE_EVENT_FLAGS_INFO_GET 33 /* I1 = group ptr */ 290 #define TX_TRACE_EVENT_FLAGS_PERFORMANCE_INFO_GET 34 /* I1 = group ptr */ 291 #define TX_TRACE_EVENT_FLAGS__PERFORMANCE_SYSTEM_INFO_GET 35 /* None */ 292 #define TX_TRACE_EVENT_FLAGS_SET 36 /* I1 = group ptr, I2 = flags to set, I3 = set option, I4= suspended count */ 293 #define TX_TRACE_EVENT_FLAGS_SET_NOTIFY 37 /* I1 = group ptr */ 294 #define TX_TRACE_INTERRUPT_CONTROL 40 /* I1 = new interrupt posture, I2 = stack ptr */ 295 #define TX_TRACE_MUTEX_CREATE 50 /* I1 = mutex ptr, I2 = inheritance, I3 = stack ptr */ 296 #define TX_TRACE_MUTEX_DELETE 51 /* I1 = mutex ptr, I2 = stack ptr */ 297 #define TX_TRACE_MUTEX_GET 52 /* I1 = mutex ptr, I2 = wait option, I3 = owning thread, I4 = own count */ 298 #define TX_TRACE_MUTEX_INFO_GET 53 /* I1 = mutex ptr */ 299 #define TX_TRACE_MUTEX_PERFORMANCE_INFO_GET 54 /* I1 = mutex ptr */ 300 #define TX_TRACE_MUTEX_PERFORMANCE_SYSTEM_INFO_GET 55 /* None */ 301 #define TX_TRACE_MUTEX_PRIORITIZE 56 /* I1 = mutex ptr, I2 = suspended count, I3 = stack ptr */ 302 #define TX_TRACE_MUTEX_PUT 57 /* I1 = mutex ptr, I2 = owning thread, I3 = own count, I4 = stack ptr */ 303 #define TX_TRACE_QUEUE_CREATE 60 /* I1 = queue ptr, I2 = message size, I3 = queue start, I4 = queue size */ 304 #define TX_TRACE_QUEUE_DELETE 61 /* I1 = queue ptr, I2 = stack ptr */ 305 #define TX_TRACE_QUEUE_FLUSH 62 /* I1 = queue ptr, I2 = stack ptr */ 306 #define TX_TRACE_QUEUE_FRONT_SEND 63 /* I1 = queue ptr, I2 = source ptr, I3 = wait option, I4 = enqueued */ 307 #define TX_TRACE_QUEUE_INFO_GET 64 /* I1 = queue ptr */ 308 #define TX_TRACE_QUEUE_PERFORMANCE_INFO_GET 65 /* I1 = queue ptr */ 309 #define TX_TRACE_QUEUE_PERFORMANCE_SYSTEM_INFO_GET 66 /* None */ 310 #define TX_TRACE_QUEUE_PRIORITIZE 67 /* I1 = queue ptr, I2 = suspended count, I3 = stack ptr */ 311 #define TX_TRACE_QUEUE_RECEIVE 68 /* I1 = queue ptr, I2 = destination ptr, I3 = wait option, I4 = enqueued */ 312 #define TX_TRACE_QUEUE_SEND 69 /* I1 = queue ptr, I2 = source ptr, I3 = wait option, I4 = enqueued */ 313 #define TX_TRACE_QUEUE_SEND_NOTIFY 70 /* I1 = queue ptr */ 314 #define TX_TRACE_SEMAPHORE_CEILING_PUT 80 /* I1 = semaphore ptr, I2 = current count, I3 = suspended count,I4 =ceiling */ 315 #define TX_TRACE_SEMAPHORE_CREATE 81 /* I1 = semaphore ptr, I2 = initial count, I3 = stack ptr */ 316 #define TX_TRACE_SEMAPHORE_DELETE 82 /* I1 = semaphore ptr, I2 = stack ptr */ 317 #define TX_TRACE_SEMAPHORE_GET 83 /* I1 = semaphore ptr, I2 = wait option, I3 = current count, I4 = stack ptr */ 318 #define TX_TRACE_SEMAPHORE_INFO_GET 84 /* I1 = semaphore ptr */ 319 #define TX_TRACE_SEMAPHORE_PERFORMANCE_INFO_GET 85 /* I1 = semaphore ptr */ 320 #define TX_TRACE_SEMAPHORE__PERFORMANCE_SYSTEM_INFO_GET 86 /* None */ 321 #define TX_TRACE_SEMAPHORE_PRIORITIZE 87 /* I1 = semaphore ptr, I2 = suspended count, I2 = stack ptr */ 322 #define TX_TRACE_SEMAPHORE_PUT 88 /* I1 = semaphore ptr, I2 = current count, I3 = suspended count,I4=stack ptr*/ 323 #define TX_TRACE_SEMAPHORE_PUT_NOTIFY 89 /* I1 = semaphore ptr */ 324 #define TX_TRACE_THREAD_CREATE 100 /* I1 = thread ptr, I2 = priority, I3 = stack ptr, I4 = stack_size */ 325 #define TX_TRACE_THREAD_DELETE 101 /* I1 = thread ptr, I2 = stack ptr */ 326 #define TX_TRACE_THREAD_ENTRY_EXIT_NOTIFY 102 /* I1 = thread ptr, I2 = thread state, I3 = stack ptr */ 327 #define TX_TRACE_THREAD_IDENTIFY 103 /* None */ 328 #define TX_TRACE_THREAD_INFO_GET 104 /* I1 = thread ptr, I2 = thread state */ 329 #define TX_TRACE_THREAD_PERFORMANCE_INFO_GET 105 /* I1 = thread ptr, I2 = thread state */ 330 #define TX_TRACE_THREAD_PERFORMANCE_SYSTEM_INFO_GET 106 /* None */ 331 #define TX_TRACE_THREAD_PREEMPTION_CHANGE 107 /* I1 = thread ptr, I2 = new threshold, I3 = old threshold, I4 =thread state*/ 332 #define TX_TRACE_THREAD_PRIORITY_CHANGE 108 /* I1 = thread ptr, I2 = new priority, I3 = old priority, I4 = thread state */ 333 #define TX_TRACE_THREAD_RELINQUISH 109 /* I1 = stack ptr, I2 = next thread ptr */ 334 #define TX_TRACE_THREAD_RESET 110 /* I1 = thread ptr, I2 = thread state */ 335 #define TX_TRACE_THREAD_RESUME_API 111 /* I1 = thread ptr, I2 = thread state, I3 = stack ptr */ 336 #define TX_TRACE_THREAD_SLEEP 112 /* I1 = sleep value, I2 = thread state, I3 = stack ptr */ 337 #define TX_TRACE_THREAD_STACK_ERROR_NOTIFY 113 /* None */ 338 #define TX_TRACE_THREAD_SUSPEND_API 114 /* I1 = thread ptr, I2 = thread state, I3 = stack ptr */ 339 #define TX_TRACE_THREAD_TERMINATE 115 /* I1 = thread ptr, I2 = thread state, I3 = stack ptr */ 340 #define TX_TRACE_THREAD_TIME_SLICE_CHANGE 116 /* I1 = thread ptr, I2 = new timeslice, I3 = old timeslice */ 341 #define TX_TRACE_THREAD_WAIT_ABORT 117 /* I1 = thread ptr, I2 = thread state, I3 = stack ptr */ 342 #define TX_TRACE_TIME_GET 120 /* I1 = current time, I2 = stack ptr */ 343 #define TX_TRACE_TIME_SET 121 /* I1 = new time */ 344 #define TX_TRACE_TIMER_ACTIVATE 122 /* I1 = timer ptr */ 345 #define TX_TRACE_TIMER_CHANGE 123 /* I1 = timer ptr, I2 = initial ticks, I3= reschedule ticks */ 346 #define TX_TRACE_TIMER_CREATE 124 /* I1 = timer ptr, I2 = initial ticks, I3= reschedule ticks, I4 = enable */ 347 #define TX_TRACE_TIMER_DEACTIVATE 125 /* I1 = timer ptr, I2 = stack ptr */ 348 #define TX_TRACE_TIMER_DELETE 126 /* I1 = timer ptr */ 349 #define TX_TRACE_TIMER_INFO_GET 127 /* I1 = timer ptr, I2 = stack ptr */ 350 #define TX_TRACE_TIMER_PERFORMANCE_INFO_GET 128 /* I1 = timer ptr */ 351 #define TX_TRACE_TIMER_PERFORMANCE_SYSTEM_INFO_GET 129 /* None */ 352 353 354 /* Define the an Trace Buffer Entry. */ 355 356 typedef struct TX_TRACE_BUFFER_ENTRY_STRUCT 357 { 358 359 ULONG tx_trace_buffer_entry_thread_pointer; 360 ULONG tx_trace_buffer_entry_thread_priority; 361 ULONG tx_trace_buffer_entry_event_id; 362 ULONG tx_trace_buffer_entry_time_stamp; 363 #ifdef TX_MISRA_ENABLE 364 ULONG tx_trace_buffer_entry_info_1; 365 ULONG tx_trace_buffer_entry_info_2; 366 ULONG tx_trace_buffer_entry_info_3; 367 ULONG tx_trace_buffer_entry_info_4; 368 #else 369 ULONG tx_trace_buffer_entry_information_field_1; 370 ULONG tx_trace_buffer_entry_information_field_2; 371 ULONG tx_trace_buffer_entry_information_field_3; 372 ULONG tx_trace_buffer_entry_information_field_4; 373 #endif 374 } TX_TRACE_BUFFER_ENTRY; 375 376 377 /* Trace management component data declarations follow. */ 378 379 /* Determine if the initialization function of this component is including 380 this file. If so, make the data definitions really happen. Otherwise, 381 make them extern so other functions in the component can access them. */ 382 383 #ifdef TX_TRACE_INIT 384 #define TRACE_DECLARE 385 #else 386 #define TRACE_DECLARE extern 387 #endif 388 389 390 /* Define the pointer to the start of the trace buffer control structure. */ 391 392 TRACE_DECLARE TX_TRACE_HEADER *_tx_trace_header_ptr; 393 394 395 /* Define the pointer to the start of the trace object registry area in the trace buffer. */ 396 397 TRACE_DECLARE TX_TRACE_OBJECT_ENTRY *_tx_trace_registry_start_ptr; 398 399 400 /* Define the pointer to the end of the trace object registry area in the trace buffer. */ 401 402 TRACE_DECLARE TX_TRACE_OBJECT_ENTRY *_tx_trace_registry_end_ptr; 403 404 405 /* Define the pointer to the starting entry of the actual trace event area of the trace buffer. */ 406 407 TRACE_DECLARE TX_TRACE_BUFFER_ENTRY *_tx_trace_buffer_start_ptr; 408 409 410 /* Define the pointer to the ending entry of the actual trace event area of the trace buffer. */ 411 412 TRACE_DECLARE TX_TRACE_BUFFER_ENTRY *_tx_trace_buffer_end_ptr; 413 414 415 /* Define the pointer to the current entry of the actual trace event area of the trace buffer. */ 416 417 TRACE_DECLARE TX_TRACE_BUFFER_ENTRY *_tx_trace_buffer_current_ptr; 418 419 420 /* Define the trace event enable bits, where each bit represents a type of event that can be enabled 421 or disabled dynamically by the application. */ 422 423 TRACE_DECLARE ULONG _tx_trace_event_enable_bits; 424 425 426 /* Define a counter that is used in environments that don't have a timer source. This counter 427 is incremented on each use giving each event a unique timestamp. */ 428 429 TRACE_DECLARE ULONG _tx_trace_simulated_time; 430 431 432 /* Define the function pointer used to call the application when the trace buffer wraps. If NULL, 433 the application has not registered a callback function. */ 434 435 TRACE_DECLARE VOID (*_tx_trace_full_notify_function)(VOID *buffer); 436 437 438 /* Define the total number of registry entries. */ 439 440 TRACE_DECLARE ULONG _tx_trace_total_registry_entries; 441 442 443 /* Define a counter that is used to track the number of available registry entries. */ 444 445 TRACE_DECLARE ULONG _tx_trace_available_registry_entries; 446 447 448 /* Define an index that represents the start of the registry search. */ 449 450 TRACE_DECLARE ULONG _tx_trace_registry_search_start; 451 452 453 /* Define the event trace macros that are expanded in-line when event tracing is enabled. */ 454 455 #ifdef TX_MISRA_ENABLE 456 #define TX_TRACE_INFO_FIELD_ASSIGNMENT(a,b,c,d) trace_event_ptr -> tx_trace_buffer_entry_info_1 = (ULONG) (a); trace_event_ptr -> tx_trace_buffer_entry_info_2 = (ULONG) (b); trace_event_ptr -> tx_trace_buffer_entry_info_3 = (ULONG) (c); trace_event_ptr -> tx_trace_buffer_entry_info_4 = (ULONG) (d); 457 #else 458 #define TX_TRACE_INFO_FIELD_ASSIGNMENT(a,b,c,d) trace_event_ptr -> tx_trace_buffer_entry_information_field_1 = (ULONG) (a); trace_event_ptr -> tx_trace_buffer_entry_information_field_2 = (ULONG) (b); trace_event_ptr -> tx_trace_buffer_entry_information_field_3 = (ULONG) (c); trace_event_ptr -> tx_trace_buffer_entry_information_field_4 = (ULONG) (d); 459 #endif 460 461 462 #define TX_TRACE_INITIALIZE _tx_trace_initialize(); 463 #define TX_TRACE_OBJECT_REGISTER(t,p,n,a,b) _tx_trace_object_register((UCHAR) (t), (VOID *) (p), (CHAR *) (n), (ULONG) (a), (ULONG) (b)); 464 #define TX_TRACE_OBJECT_UNREGISTER(o) _tx_trace_object_unregister((VOID *) (o)); 465 #ifndef TX_TRACE_IN_LINE_INSERT 466 #define TX_TRACE_IN_LINE_INSERT(i,a,b,c,d,e) \ 467 { \ 468 TX_TRACE_BUFFER_ENTRY *trace_event_ptr; \ 469 ULONG trace_system_state; \ 470 ULONG trace_priority; \ 471 TX_THREAD *trace_thread_ptr; \ 472 trace_event_ptr = _tx_trace_buffer_current_ptr; \ 473 if ((trace_event_ptr) && (_tx_trace_event_enable_bits & ((ULONG) (e)))) \ 474 { \ 475 TX_TRACE_PORT_EXTENSION \ 476 trace_system_state = (ULONG) TX_THREAD_GET_SYSTEM_STATE(); \ 477 TX_THREAD_GET_CURRENT(trace_thread_ptr) \ 478 \ 479 if (trace_system_state == 0) \ 480 { \ 481 trace_priority = trace_thread_ptr -> tx_thread_priority; \ 482 trace_priority = trace_priority | 0x80000000UL | (trace_thread_ptr -> tx_thread_preempt_threshold << 16); \ 483 } \ 484 else if (trace_system_state < 0xF0F0F0F0UL) \ 485 { \ 486 trace_priority = (ULONG) trace_thread_ptr; \ 487 trace_thread_ptr = (TX_THREAD *) 0xFFFFFFFFUL; \ 488 } \ 489 else \ 490 { \ 491 trace_thread_ptr = (TX_THREAD *) 0xF0F0F0F0UL; \ 492 trace_priority = 0; \ 493 } \ 494 trace_event_ptr -> tx_trace_buffer_entry_thread_pointer = (ULONG) trace_thread_ptr; \ 495 trace_event_ptr -> tx_trace_buffer_entry_thread_priority = (ULONG) trace_priority; \ 496 trace_event_ptr -> tx_trace_buffer_entry_event_id = (ULONG) (i); \ 497 trace_event_ptr -> tx_trace_buffer_entry_time_stamp = (ULONG) TX_TRACE_TIME_SOURCE; \ 498 TX_TRACE_INFO_FIELD_ASSIGNMENT((a),(b),(c),(d)) \ 499 trace_event_ptr++; \ 500 if (trace_event_ptr >= _tx_trace_buffer_end_ptr) \ 501 { \ 502 trace_event_ptr = _tx_trace_buffer_start_ptr; \ 503 _tx_trace_buffer_current_ptr = trace_event_ptr; \ 504 _tx_trace_header_ptr -> tx_trace_header_buffer_current_pointer = (ULONG) trace_event_ptr; \ 505 if (_tx_trace_full_notify_function) \ 506 (_tx_trace_full_notify_function)((VOID *) _tx_trace_header_ptr); \ 507 } \ 508 else \ 509 { \ 510 _tx_trace_buffer_current_ptr = trace_event_ptr; \ 511 _tx_trace_header_ptr -> tx_trace_header_buffer_current_pointer = (ULONG) trace_event_ptr; \ 512 } \ 513 } \ 514 } 515 #endif 516 #endif 517 518 519 #ifdef TX_SOURCE_CODE 520 521 /* Define internal function prototypes of the trace component, only if compiling ThreadX source code. */ 522 523 VOID _tx_trace_initialize(VOID); 524 VOID _tx_trace_object_register(UCHAR object_type, VOID *object_ptr, CHAR *object_name, ULONG parameter_1, ULONG parameter_2); 525 VOID _tx_trace_object_unregister(VOID *object_ptr); 526 527 528 #ifdef TX_ENABLE_EVENT_TRACE 529 530 /* Check for MISRA compliance requirements. */ 531 532 #ifdef TX_MISRA_ENABLE 533 534 /* Define MISRA-specific routines. */ 535 536 UCHAR *_tx_misra_object_to_uchar_pointer_convert(TX_TRACE_OBJECT_ENTRY *pointer); 537 TX_TRACE_OBJECT_ENTRY *_tx_misra_uchar_to_object_pointer_convert(UCHAR *pointer); 538 TX_TRACE_HEADER *_tx_misra_uchar_to_header_pointer_convert(UCHAR *pointer); 539 TX_TRACE_BUFFER_ENTRY *_tx_misra_uchar_to_entry_pointer_convert(UCHAR *pointer); 540 UCHAR *_tx_misra_entry_to_uchar_pointer_convert(TX_TRACE_BUFFER_ENTRY *pointer); 541 542 543 #define TX_OBJECT_TO_UCHAR_POINTER_CONVERT(a) _tx_misra_object_to_uchar_pointer_convert((a)) 544 #define TX_UCHAR_TO_OBJECT_POINTER_CONVERT(a) _tx_misra_uchar_to_object_pointer_convert((a)) 545 #define TX_UCHAR_TO_HEADER_POINTER_CONVERT(a) _tx_misra_uchar_to_header_pointer_convert((a)) 546 #define TX_UCHAR_TO_ENTRY_POINTER_CONVERT(a) _tx_misra_uchar_to_entry_pointer_convert((a)) 547 #define TX_ENTRY_TO_UCHAR_POINTER_CONVERT(a) _tx_misra_entry_to_uchar_pointer_convert((a)) 548 549 #else 550 551 #define TX_OBJECT_TO_UCHAR_POINTER_CONVERT(a) ((UCHAR *) ((VOID *) (a))) 552 #define TX_UCHAR_TO_OBJECT_POINTER_CONVERT(a) ((TX_TRACE_OBJECT_ENTRY *) ((VOID *) (a))) 553 #define TX_UCHAR_TO_HEADER_POINTER_CONVERT(a) ((TX_TRACE_HEADER *) ((VOID *) (a))) 554 #define TX_UCHAR_TO_ENTRY_POINTER_CONVERT(a) ((TX_TRACE_BUFFER_ENTRY *) ((VOID *) (a))) 555 #define TX_ENTRY_TO_UCHAR_POINTER_CONVERT(a) ((UCHAR *) ((VOID *) (a))) 556 557 #endif 558 #endif 559 #endif 560 #endif 561 562