forked from zephyrproject-rtos/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcISR.c
248 lines (183 loc) · 7.01 KB
/
trcISR.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* Percepio Trace Recorder for Tracealyzer v4.8.0.hotfix2
* Copyright 2023 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation for ISR tagging.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1)
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
TraceISRData_t* pxTraceISRData TRC_CFG_RECORDER_DATA_ATTRIBUTE;
traceResult xTraceISRInitialize(TraceISRData_t *pxBuffer)
{
uint32_t uiCoreIndex;
uint32_t uiStackIndex;
/* This should never fail */
TRC_ASSERT(pxBuffer != (void*)0);
pxTraceISRData = pxBuffer;
for (uiCoreIndex = 0u; uiCoreIndex < (uint32_t)(TRC_CFG_CORE_COUNT); uiCoreIndex++)
{
TraceISRCoreData_t* pxCoreData = &pxTraceISRData->cores[uiCoreIndex];
/* Initialize ISR stack */
for (uiStackIndex = 0u; uiStackIndex < (uint32_t)(TRC_CFG_MAX_ISR_NESTING); uiStackIndex++)
{
pxCoreData->handleStack[uiStackIndex] = 0;
}
pxCoreData->stackIndex = -1;
pxCoreData->isPendingContextSwitch = 0u;
}
xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_ISR);
return TRC_SUCCESS;
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceISRRegister(const char* szName, uint32_t uiPriority, TraceISRHandle_t *pxISRHandle)
{
TraceEntryHandle_t xEntryHandle;
TraceEventHandle_t xEventHandle = 0;
uint32_t i, uiLength, uiValue = 0u;
/* We need to check this */
if (xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ISR) == 0U)
{
return TRC_FAIL;
}
/* This should never fail */
TRC_ASSERT(pxISRHandle != (void*)0);
if (szName == (void*)0)
{
szName = ""; /*cstat !MISRAC2012-Rule-17.8 Suppress modified function parameter check*/
}
/* Always save in symbol table, in case the recording has not yet started */
/* We need to check this */
if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
{
return TRC_FAIL;
}
for (i = 0u; (szName[i] != (char)0) && (i < 128u); i++) {} /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/ /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
uiLength = i;
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetSymbol(xEntryHandle, szName, uiLength) == TRC_SUCCESS);
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetState(xEntryHandle, 0u, (TraceUnsignedBaseType_t)uiPriority) == TRC_SUCCESS);
*pxISRHandle = (TraceISRHandle_t)xEntryHandle;
/* We need to check this */
if (xTraceEventBegin(PSF_EVENT_DEFINE_ISR, uiLength + sizeof(void*) + sizeof(uint32_t), &xEventHandle) == TRC_SUCCESS)
{
(void)xTraceEventAddPointer(xEventHandle, (void*)xEntryHandle);
(void)xTraceEventAdd32(xEventHandle, uiPriority);
(void)xTraceEventAddString(xEventHandle, szName, uiLength);
/* Check if we can truncate */
(void)xTraceEventPayloadRemaining(xEventHandle, &uiValue);
if (uiValue > 0u)
{
(void)xTraceEventAdd8(xEventHandle, 0u);
}
(void)xTraceEventEnd(xEventHandle); /*cstat !MISRAC2012-Rule-17.7*/
}
return TRC_SUCCESS;
}
traceResult xTraceISRBegin(TraceISRHandle_t xISRHandle)
{
TraceISRCoreData_t* pxCoreData;
TRACE_ALLOC_CRITICAL_SECTION();
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ISR));
TRACE_ENTER_CRITICAL_SECTION();
/* We are at the start of a possible ISR chain.
* No context switches should have been triggered now.
*/
pxCoreData = &pxTraceISRData->cores[TRC_CFG_GET_CURRENT_CORE()];
if (pxCoreData->stackIndex == -1)
{
pxCoreData->isPendingContextSwitch = 0u;
}
if (pxCoreData->stackIndex < ((TRC_CFG_MAX_ISR_NESTING) - 1))
{
pxCoreData->stackIndex++;
pxCoreData->handleStack[pxCoreData->stackIndex] = xISRHandle;
#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
(void)xTraceEventCreate1(PSF_EVENT_ISR_BEGIN, (TraceUnsignedBaseType_t)xISRHandle); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
#endif
}
else
{
TRACE_EXIT_CRITICAL_SECTION();
(void)xTraceError(TRC_ERROR_ISR_NESTING_OVERFLOW);
return TRC_FAIL;
}
TRACE_EXIT_CRITICAL_SECTION();
return TRC_SUCCESS;
}
traceResult xTraceISREnd(TraceBaseType_t xIsTaskSwitchRequired)
{
TraceISRCoreData_t* pxCoreData;
TRACE_ALLOC_CRITICAL_SECTION();
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ISR));
TRACE_ENTER_CRITICAL_SECTION();
pxCoreData = &pxTraceISRData->cores[TRC_CFG_GET_CURRENT_CORE()];
pxCoreData->stackIndex--;
#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
/* Is there a pending task-switch? (perhaps from an earlier ISR) */
pxCoreData->isPendingContextSwitch |= (uint32_t)xIsTaskSwitchRequired;
if (pxCoreData->stackIndex >= 0)
{
/* Store return to interrupted ISR (if nested ISRs)*/
(void)xTraceEventCreate1(PSF_EVENT_ISR_RESUME, (TraceUnsignedBaseType_t)pxCoreData->handleStack[pxCoreData->stackIndex]); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
}
else
{
/* Store return to interrupted task, if no context switch will occur in between. */
if ((pxCoreData->isPendingContextSwitch == 0U) || (xTraceKernelPortIsSchedulerSuspended() == 1U)) /*cstat !MISRAC2004-13.7_b For some kernel ports xTraceKernelPortIsSchedulerSuspended() will never return 1, and that is expected*/
{
(void)xTraceEventCreate1(PSF_EVENT_TASK_ACTIVATE, (TraceUnsignedBaseType_t)xTraceTaskGetCurrentReturn()); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 !MISRAC2012-Rule-11.6 Suppress conversion from pointer to integer check*/
}
}
#endif
TRACE_EXIT_CRITICAL_SECTION();
return TRC_SUCCESS;
}
#if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
traceResult xTraceISRGetCurrentNesting(int32_t* puiValue)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ISR));
/* This should never fail */
TRC_ASSERT(puiValue != (void*)0);
TraceISRCoreData_t* pxCoreData = &pxTraceISRData->cores[TRC_CFG_GET_CURRENT_CORE()];
*puiValue = pxCoreData->stackIndex;
return TRC_SUCCESS;
}
int32_t xTraceISRGetCurrentNestingReturned(void)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ISR));
return pxTraceISRData->cores[TRC_CFG_GET_CURRENT_CORE()].stackIndex;
}
traceResult xTraceISRGetCurrent(TraceISRHandle_t* pxISRHandle)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_ISR));
/* This should never fail */
TRC_ASSERT(pxISRHandle != (void*)0);
TraceISRCoreData_t* pxCoreData = &pxTraceISRData->cores[TRC_CFG_GET_CURRENT_CORE()];
if (pxCoreData->stackIndex < 0)
{
return TRC_FAIL;
}
*pxISRHandle = pxCoreData->handleStack[pxCoreData->stackIndex];
return TRC_SUCCESS;
}
#endif
/* DEPRECATED */
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
TraceISRHandle_t xTraceSetISRProperties(const char* szName, uint32_t uiPriority)
{
TraceISRHandle_t xISRHandle = 0;
(void)xTraceISRRegister(szName, uiPriority, &xISRHandle);
return xISRHandle;
}
#endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */