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 extension APIs.
13  */
14 
15 #ifndef TRC_EXTENSION_H
16 #define TRC_EXTENSION_H
17 
18 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
19 
20 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
21 
22 #include <trcTypes.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define TRC_EXTENSION_STATE_INDEX_VERSION 0
29 #define TRC_EXTENSION_STATE_INDEX_BASE_EVENT_ID 1
30 #define TRC_EXTENSION_STATE_INDEX_EVENT_COUNT 2
31 
32 /**
33  * @defgroup trace_extension_apis Trace Extension APIs
34  * @ingroup trace_recorder_apis
35  * @{
36  */
37 
38 typedef struct TraceExtensionData	/* Aligned */
39 {
40 	TraceUnsignedBaseType_t uxNextFreeExtensionEventId;
41 } TraceExtensionData_t;
42 
43 /**
44  * @brief Initializes the Extension trace system
45  *
46  * @param[in] pxBuffer Pointer to memory that is used by the extension trace system
47  *
48  * @retval TRC_FAIL Failure
49  * @retval TRC_SUCCESS Success
50  */
51 traceResult xTraceExtensionInitialize(TraceExtensionData_t* const pxBuffer);
52 
53 /**
54  * @brief Creates trace extension.
55  *
56  * @param[in] szName Name.
57  * @param[in] uiMajor Major version.
58  * @param[in] uiMinor Minor version.
59  * @param[in] uiPatch Patch version.
60  * @param[in] uiEventCount Event count.
61  * @param[out] pxExtensionHandle Pointer to uninitialized extension handle.
62  *
63  * @retval TRC_FAIL Failure
64  * @retval TRC_SUCCESS Success
65  */
66 traceResult xTraceExtensionCreate(const char *szName, uint8_t uiMajor, uint8_t uiMinor, uint16_t uiPatch, uint32_t uiEventCount, TraceExtensionHandle_t *pxExtensionHandle);
67 
68 /**
69  * @brief Gets extension base event id.
70  *
71  * @param[in] xExtensionHandle Pointer to initialized extension handle.
72  * @param[out] puiBaseEventId Base event id.
73  *
74  * @retval TRC_FAIL Failure
75  * @retval TRC_SUCCESS Success
76  */
77 traceResult xTraceExtensionGetBaseEventId(TraceExtensionHandle_t xExtensionHandle, uint32_t *puiBaseEventId);
78 
79 /**
80  * @brief Gets extension configuration name.
81  *
82  * @param[in] xExtensionHandle Pointer to initialized extension handle.
83  * @param[out] pszName Name.
84  *
85  * @retval TRC_FAIL Failure
86  * @retval TRC_SUCCESS Success
87  */
88 traceResult xTraceExtensionGetConfigName(TraceExtensionHandle_t xExtensionHandle, const char** pszName);
89 
90 /**
91  * @brief Returns extension event id.
92  *
93  * @param[in] xExtensionHandle Pointer to initialized extension handle.
94  * @param[in] uiLocalEventId Local event id.
95  *
96  * @returns Extension event id
97  */
98 #define xTraceExtensionGetEventId(xExtensionHandle, uiLocalEventId) ((uint32_t)xTraceEntryGetStateReturn((TraceEntryHandle_t)(xExtensionHandle), TRC_EXTENSION_STATE_INDEX_BASE_EVENT_ID) + (uiLocalEventId))
99 
100 /** @} */
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
107 
108 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
109 
110 #endif /* TRC_EXTENSION_H */
111