Percepio Trace Recorder v4.11.0
Loading...
Searching...
No Matches
trcAssert.h
Go to the documentation of this file.
1/*
2* Percepio Trace Recorder for Tracealyzer v4.11.0
3* Copyright 2025 Percepio AB
4* www.percepio.com
5*
6* SPDX-License-Identifier: Apache-2.0
7*/
8
14
15#ifndef TRC_ASSERT_H
16#define TRC_ASSERT_H
17
18#if (TRC_USE_TRACEALYZER_RECORDER == 1)
19
20#include <trcTypes.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
31
32#ifndef TRC_CFG_USE_TRACE_ASSERT
33#error "TRC_CFG_USE_TRACE_ASSERT is not defined. Please define it in trcConfig.h"
34#endif
35
36#if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
37
38/* Standard assert */
39#define TRC_ASSERT(__condition) if (!(__condition)) { prvTraceAssertCreate(__FILE__, __LINE__); return TRC_FAIL; }
40
41#define TRC_ASSERT_ALWAYS_EVALUATE TRC_ASSERT
42
43/* Standard assert with custom on fail actions */
44#define TRC_ASSERT_CUSTOM_ON_FAIL(__condition, __custom_on_fail) if (!(__condition)) { prvTraceAssertCreate(__FILE__, __LINE__); __custom_on_fail; }
45
46#define TRC_ASSERT_CUSTOM_ON_FAIL_ALWAYS_EVALUATE TRC_ASSERT_CUSTOM_ON_FAIL
47
48#if (defined(TRC_CFG_TEST_MODE) && (TRC_CFG_TEST_MODE) == 1)
49
50/* Asserts that two types have an equal size. Condition passed to function to avoid compilers warning about unreachable code due to constant value. */
51#define TRC_ASSERT_EQUAL_SIZE(x, y) if (!prvTraceAssertCheckCondition((TraceBaseType_t)(sizeof(x) == sizeof(y)))) { prvTraceAssertCreate(__FILE__, __LINE__); return TRC_FAIL; }
52
58inline TraceBaseType_t prvTraceAssertCheckCondition(TraceBaseType_t condition)
59{
60 return condition;
61}
62
63#else
64
65#define TRC_ASSERT_EQUAL_SIZE(x, y)
66
67#endif
68
69
70typedef struct TraceAssertData /* Aligned */
71{
72 TraceEntryHandle_t xEntry;
73} TraceAssertData_t;
74
83traceResult xTraceAssertInitialize(TraceAssertData_t *pxBuffer);
84
94void prvTraceAssertCreate(const char* szFilePath, TraceUnsignedBaseType_t uxLineNumber);
95
105traceResult xTraceAssertGet(TraceStringHandle_t* pxFileNameStringHandle, TraceUnsignedBaseType_t* puxLineNumber);
106
107#else /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
108
109#define TRC_ASSERT(__condition)
110
111#define TRC_ASSERT_ALWAYS_EVALUATE(__condition) (void)(__condition)
112
113#define TRC_ASSERT_CUSTOM_ON_FAIL(__condition, __custom_on_fail)
114
115#define TRC_ASSERT_CUSTOM_ON_FAIL_ALWAYS_EVALUATE(__condition, __custom_on_fail) (__condition)
116
117#define TRC_ASSERT_EQUAL_SIZE(x, y)
118
119typedef struct TraceAssertData
120{
121 TraceUnsignedBaseType_t buffer[1];
122} TraceAssertData_t;
123
124#define xTraceAssertInitialize(pxBuffer) ((void)pxBuffer, TRC_SUCCESS)
125
126#define xTraceAssertGet(pxFileNameStringHandle, puxLineNumber) ((void)pxFileNameStringHandle, (void)puxLineNumber, TRC_FAIL)
127
128#endif /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
129
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif
137
138#endif /* TRC_ASSERT_H */