1 /* 2 * Percepio Trace Recorder for Tracealyzer v4.8.1 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 counter APIs. 13 */ 14 15 #ifndef TRC_COUNTER_H 16 #define TRC_COUNTER_H 17 18 #if (TRC_USE_TRACEALYZER_RECORDER == 1) 19 20 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) 21 22 #define TRC_COUNTER_VALUE_INDEX 0 23 #define TRC_COUNTER_LOWER_LIMIT_INDEX 1 24 #define TRC_COUNTER_UPPER_LIMIT_INDEX 2 25 26 #include <trcTypes.h> 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /** 33 * @defgroup trace_counter_apis Trace Counter APIs 34 * @ingroup trace_recorder_apis 35 * @{ 36 */ 37 38 typedef struct TraceCounterData /* Aligned */ 39 { 40 TraceCounterCallback_t xCallbackFunction; 41 } TraceCounterData_t; 42 43 /** 44 * @brief Initializes the Counter trace system 45 * 46 * @param[in] pxBuffer Pointer to memory that is used by the counter system 47 * 48 * @retval TRC_FAIL Failure 49 * @retval TRC_SUCCESS Success 50 */ 51 traceResult xTraceCounterInitialize(TraceCounterData_t *pxBuffer); 52 53 /** 54 * @brief Sets trace counter callback. 55 * 56 * @param[in] xCallback Callback 57 * 58 * @retval TRC_FAIL Failure 59 * @retval TRC_SUCCESS Success 60 */ 61 traceResult xTraceCounterSetCallback(TraceCounterCallback_t xCallback); 62 63 /** 64 * @brief Creates trace counter. 65 * 66 * @param[in] szName Name. 67 * @param[in] xInitialValue Initial value. 68 * @param[in] xLowerLimit Lower limit. 69 * @param[in] xUpperLimit Upper limit. 70 * @param[out] pxCounterHandle Uninitialized trace counter handle. 71 * 72 * @retval TRC_FAIL Failure 73 * @retval TRC_SUCCESS Success 74 */ 75 traceResult xTraceCounterCreate(const char* szName, TraceBaseType_t xInitialValue, TraceBaseType_t xLowerLimit, TraceBaseType_t xUpperLimit, TraceCounterHandle_t* pxCounterHandle); 76 77 /** 78 * @brief Adds value to trace counter. 79 * 80 * @param[in] xCounterHandle Initialized trace counter handle. 81 * @param[in] xValue Value. 82 * 83 * @retval TRC_FAIL Failure 84 * @retval TRC_SUCCESS Success 85 */ 86 #define xTraceCounterAdd(xCounterHandle, xValue) xTraceCounterSet(xCounterHandle, (TraceBaseType_t)(xTraceEntryGetStateReturn((TraceEntryHandle_t)(xCounterHandle), TRC_COUNTER_VALUE_INDEX)) + (xValue)) 87 88 /** 89 * @brief Sets trace counter value. 90 * 91 * @param[in] xCounterHandle Initialized trace counter handle. 92 * @param[in] xValue Value. 93 * 94 * @retval TRC_FAIL Failure 95 * @retval TRC_SUCCESS Success 96 */ 97 traceResult xTraceCounterSet(TraceCounterHandle_t xCounterHandle, TraceBaseType_t xValue); 98 99 /** 100 * @brief Gets trace counter value. 101 * 102 * @param[in] xCounterHandle Initialized trace counter handle. 103 * @param[out] pxValue Returned value. 104 * 105 * @retval TRC_FAIL Failure 106 * @retval TRC_SUCCESS Success 107 */ 108 #define xTraceCounterGet(xCounterHandle, pxValue) xTraceEntryGetState((TraceEntryHandle_t)(xCounterHandle), TRC_COUNTER_VALUE_INDEX, (TraceUnsignedBaseType_t*)(pxValue)) 109 110 /** 111 * @brief Increases trace counter value. 112 * 113 * @param[in] xCounterHandle Initialized trace counter handle 114 * 115 * @retval TRC_FAIL Failure 116 * @retval TRC_SUCCESS Success 117 */ 118 #define xTraceCounterIncrease(xCounterHandle) xTraceCounterAdd(xCounterHandle, 1) 119 120 /** 121 * @brief Decreases trace counter value. 122 * 123 * @param[in] xCounterHandle Initialized trace counter handle 124 * 125 * @retval TRC_FAIL Failure 126 * @retval TRC_SUCCESS Success 127 */ 128 #define xTraceCounterDecrease(xCounterHandle) xTraceCounterAdd(xCounterHandle, -1) 129 130 /** 131 * @brief Gets trace counter upper limit. 132 * 133 * @param[in] xCounterHandle Initialized trace counter handle 134 * @param[out] pxValue Returned value 135 * 136 * @retval TRC_FAIL Failure 137 * @retval TRC_SUCCESS Success 138 */ 139 #define xTraceCounterGetUpperLimit(xCounterHandle, pxValue) xTraceEntryGetState((TraceEntryHandle_t)(xCounterHandle), TRC_COUNTER_UPPER_LIMIT_INDEX, (TraceUnsignedBaseType_t*)(pxValue)) 140 141 /** 142 * @brief Gets trace counter lower limit. 143 * 144 * @param[in] xCounterHandle Initialized trace counter handle 145 * @param[out] pxValue Returned value 146 * 147 * @retval TRC_FAIL Failure 148 * @retval TRC_SUCCESS Success 149 */ 150 #define xTraceCounterGetLowerLimit(xCounterHandle, pxValue) xTraceEntryGetState((TraceEntryHandle_t)(xCounterHandle), TRC_COUNTER_LOWER_LIMIT_INDEX, (TraceUnsignedBaseType_t*)(pxValue)) 151 152 /** 153 * @brief Gets trace counter name. 154 * 155 * @param[in] xCounterHandle Initialized trace counter handle. 156 * @param[out] pszName Returned name. 157 * 158 * @retval TRC_FAIL Failure 159 * @retval TRC_SUCCESS Success 160 */ 161 #define xTraceCounterGetName(xCounterHandle, pszName) xTraceEntryGetSymbol((TraceEntryHandle_t)(xCounterHandle), pszName) 162 163 /** @} */ 164 165 #ifdef __cplusplus 166 } 167 #endif 168 169 #else 170 171 /** 172 * @brief Disabled by TRC_CFG_RECORDER_MODE 173 */ 174 #define xTraceCounterSetCallback(__xCallback) ((void)(__xCallback), TRC_SUCCESS) 175 176 /** 177 * @brief Disabled by TRC_CFG_RECORDER_MODE 178 */ 179 #define xTraceCounterCreate(__szName, __xInitialValue, __xLowerLimit, __xUpperLimit, __pxCounterHandle) ((void)(__szName), (void)(__xInitialValue), (void)(__xLowerLimit), (void)(__xUpperLimit), *(__pxCounterHandle) = 0, TRC_SUCCESS) 180 181 /** 182 * @brief Disabled by TRC_CFG_RECORDER_MODE 183 */ 184 #define xTraceCounterAdd(__xCounterHandle, __xValue) ((void)(__xCounterHandle), (void)(__xValue), TRC_SUCCESS) 185 186 /** 187 * @brief Disabled by TRC_CFG_RECORDER_MODE 188 */ 189 #define xTraceCounterSet(__xCounterHandle, __xValue) ((void)(__xCounterHandle), (void)(__xValue), TRC_SUCCESS) 190 191 /** 192 * @brief Disabled by TRC_CFG_RECORDER_MODE 193 */ 194 #define xTraceCounterGet(__xCounterHandle, __pxValue) ((void)(__xCounterHandle), *(__pxValue) = 0, TRC_SUCCESS) 195 196 /** 197 * @brief Disabled by TRC_CFG_RECORDER_MODE 198 */ 199 #define xTraceCounterIncrease(__xCounterHandle) ((void)(__xCounterHandle), TRC_SUCCESS) 200 201 /** 202 * @brief Disabled by TRC_CFG_RECORDER_MODE 203 */ 204 #define xTraceCounterDecrease(__xCounterHandle) ((void)(__xCounterHandle), TRC_SUCCESS) 205 206 /** 207 * @brief Disabled by TRC_CFG_RECORDER_MODE 208 */ 209 #define xTraceCounterGetUpperLimit(__xCounterHandle, __pxValue) ((void)(__xCounterHandle), *(__pxValue) = 0, TRC_SUCCESS) 210 211 /** 212 * @brief Disabled by TRC_CFG_RECORDER_MODE 213 */ 214 #define xTraceCounterGetLowerLimit(__xCounterHandle, __pxValue) ((void)(__xCounterHandle), *(__pxValue) = 0, TRC_SUCCESS) 215 216 /** 217 * @brief Disabled by TRC_CFG_RECORDER_MODE 218 */ 219 #define xTraceCounterGetName(__xCounterHandle, __pszName) ((void)(__xCounterHandle), *(__pszName) = "N/A", TRC_SUCCESS) 220 221 #endif 222 223 #endif 224 225 #endif 226