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