1 /* 2 * Percepio Trace Recorder for Tracealyzer v4.10.3 3 * Copyright 2023 Percepio AB 4 * www.percepio.com 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 /** 10 * @file 11 * 12 * @brief Public trace thread APIs. 13 */ 14 15 #ifndef TRC_THREAD_H 16 #define TRC_THREAD_H 17 18 #if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) 19 20 #include <trcTypes.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * @defgroup trace_thread_apis Trace Thread APIs 28 * @ingroup trace_recorder_apis 29 * @{ 30 */ 31 32 /** 33 * @brief Register trace thread in the trace. 34 * 35 * @param[in] szName Name. 36 * @param[in] uxPriority Priority. 37 * @param[in] uxProcess Process address or handle used when registering process. 38 * @param[out] pxThreadHandle Pointer to uninitialized trace thread. 39 * 40 * @retval TRC_FAIL Failure 41 * @retval TRC_SUCCESS Success 42 */ 43 #define xTraceThreadRegister(szName, uxPriority, uxProcess, pxThreadHandle) xTraceObjectRegister2(PSF_EVENT_THREAD_CREATE, (void*)0, szName, uxPriority, (TraceUnsignedBaseType_t)(uxProcess), (TraceObjectHandle_t*)(pxThreadHandle)) 44 45 /** 46 * @brief Registers trace thread without trace thread handle. 47 * 48 * @param[in] pvThread Thread. 49 * @param[in] szName Name. 50 * @param[in] uxPriority Priority. 51 * @param[in] uxProcess Process address or handle used when registering process. 52 * 53 * @retval TRC_FAIL Failure 54 * @retval TRC_SUCCESS Success 55 */ 56 #define xTraceThreadRegisterWithoutHandle(pvThread, szName, uxPriority, uxProcess) xTraceObjectRegisterWithoutHandle2(PSF_EVENT_THREAD_CREATE, (void*)(pvThread), szName, uxPriority, (TraceUnsignedBaseType_t)(uxProcess)) 57 58 /** 59 * @brief Unregister trace thread from trace. 60 * 61 * @param[in] xThreadHandle Pointer to initialized trace thread. 62 * @param[in] uxPriority Priority. 63 * 64 * @retval TRC_FAIL Failure 65 * @retval TRC_SUCCESS Success 66 */ 67 #define xTraceThreadUnregister(xThreadHandle, uxPriority) xTraceObjectUnregister((TraceObjectHandle_t)(xThreadHandle), PSF_EVENT_THREAD_DELETE, uxPriority) 68 69 /** 70 * @brief Unregisters trace thread without trace thread handle. 71 * 72 * @param[in] pvThread Thread. 73 * @param[in] uxPriority Priority. 74 * 75 * @retval TRC_FAIL Failure 76 * @retval TRC_SUCCESS Success 77 */ 78 #define xTraceThreadUnregisterWithoutHandle(pvThread, uxPriority) xTraceObjectUnregisterWithoutHandle(PSF_EVENT_THREAD_DELETE, (void*)(pvThread), uxPriority) 79 80 /** 81 * @brief Sets trace thread priority. 82 * 83 * @param[in] xThreadHandle Handle to initialized trace thread. 84 * @param[in] uxPriority Priority. 85 * 86 * @retval TRC_FAIL Failure 87 * @retval TRC_SUCCESS Success 88 */ 89 #define xTraceThreadSetPriority(xThreadHandle, uxPriority) xTraceTaskSetPriority((TraceTaskHandle_t)(xThreadHandle), uxPriority) 90 91 /** 92 * @brief Sets trace thread priority without trace thread handle. 93 * 94 * @param[in] pvThread Thread. 95 * @param[in] uxPriority Priority. 96 * 97 * @retval TRC_FAIL Failure 98 * @retval TRC_SUCCESS Success 99 */ 100 #define xTraceThreadSetPriorityWithoutHandle(pvThread, uxPriority) xTraceTaskSetPriorityWithoutHandle(pvThread, uxPriority) 101 102 /** 103 * @brief Registers trace thread switch event. 104 * 105 * @param[in] xThread Thread address or thread handle used when registering thread. 106 * @param[in] uxPriority Priority. 107 * 108 * @retval TRC_FAIL Failure 109 * @retval TRC_SUCCESS Success 110 */ 111 #define xTraceThreadSwitch(xThread, uxPriority) xTraceTaskSwitch((void*)(xThread), uxPriority) 112 113 #if (TRC_CFG_INCLUDE_READY_EVENTS == 1) 114 /** 115 * @brief Registers trace thread ready event. 116 * 117 * @param[in] xThread Thread address or thread handle used when registering thread. 118 * 119 * @retval TRC_FAIL Failure 120 * @retval TRC_SUCCESS Success 121 */ 122 #define xTraceThreadReady(xThread) xTraceTaskReady((void*)(xThread)) 123 #else 124 #define xTraceThreadReady(xThread) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2((void)(xThread), TRC_SUCCESS) 125 #endif 126 127 /** @} */ 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #else 134 135 #define xTraceThreadRegister(___szName, __uxPriority, __uxProcess, __pxThreadHandle) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_5((void)(__szName), (void)(__uxPriority), (void)(__uxProcess), (void)(__pxThreadHandle), TRC_SUCCESS) 136 137 #define xTraceThreadRegisterWithoutHandle(__pvThread, __szName, __uxPriority, __uxProcess) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_5((void)(__pvThread), (void)(__szName), (void)(__uxPriority), (void)(__uxProcess), TRC_SUCCESS) 138 139 #define xTraceThreadUnregister(__xThreadHandle, __uxPriority) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_3((void)(__xThreadHandle), (void)(__uxPriority), TRC_SUCCESS) 140 141 #define xTraceThreadUnregisterWithoutHandle(__pvThread, __uxPriority) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_3((void)(__pvThread), (void)(__uxPriority), TRC_SUCCESS) 142 143 #define xTraceThreadSetPriority(__xThreadHandle, __uxPriority) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_3((void)(__xThreadHandle), (void)(__uxPriority), TRC_SUCCESS) 144 145 #define xTraceThreadSetPriorityWithoutHandle(__pvThread, __uxPriority) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_3((void)(__pvThread), (void)(__uxPriority), TRC_SUCCESS) 146 147 #define xTraceThreadSwitch(__pvThread, __uxPriority) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_3((void)(__pvThread), (void)(__uxPriority), TRC_SUCCESS) 148 149 #define xTraceThreadReady(__pvThread) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2((void)(__pvThread), TRC_SUCCESS) 150 151 #endif 152 153 #endif 154