forked from percepio/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcTask.c
193 lines (142 loc) · 4.72 KB
/
trcTask.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
/*
* Percepio Trace Recorder for Tracealyzer v4.6.3
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation for tasks.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1)
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
/* Code used for "task address" when no task has started, to indicate "(startup)".
* This value was used since NULL/0 was already reserved for the idle task. */
#define TRACE_HANDLE_NO_TASK ((void*)2)
#define TRC_TASK_STATE_INDEX_PRIORITY 0
#define TRC_TASK_STATE_INDEX_UNUSED_STACK 1
TraceTaskInfo_t* pxTraceTaskInfo;
traceResult xTraceTaskInitialize(TraceTaskInfoBuffer_t *pxBuffer)
{
uint32_t i;
TRC_ASSERT_EQUAL_SIZE(TraceTaskInfoBuffer_t, TraceTaskInfo_t);
/* This should never fail */
TRC_ASSERT(pxBuffer != 0);
pxTraceTaskInfo = (TraceTaskInfo_t*)pxBuffer;
for (i = 0; i < TRC_CFG_CORE_COUNT; i++)
{
pxTraceTaskInfo->coreTasks[i] = TRACE_HANDLE_NO_TASK;
}
xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_TASK);
return TRC_SUCCESS;
}
traceResult xTraceTaskUnregister(TraceTaskHandle_t xTaskHandle, TraceUnsignedBaseType_t uxPriority)
{
void* pvTask;
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress((TraceEntryHandle_t)xTaskHandle, &pvTask) == TRC_SUCCESS);
xTraceStackMonitorRemove(pvTask);
return xTraceObjectUnregister((TraceObjectHandle_t)xTaskHandle, PSF_EVENT_TASK_DELETE, uxPriority);
}
traceResult xTraceTaskSetPriority(TraceTaskHandle_t xTaskHandle, TraceUnsignedBaseType_t uxPriority)
{
TraceEventHandle_t xEventHandle = 0;
void *pvTask;
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceObjectSetState((TraceObjectHandle_t)xTaskHandle, uxPriority) == TRC_SUCCESS);
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress((TraceEntryHandle_t)xTaskHandle, &pvTask) == TRC_SUCCESS);
/* We need to check this */
if (xTraceEventBegin(PSF_EVENT_TASK_PRIORITY, sizeof(void*) + sizeof(uint32_t), &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvTask);
xTraceEventAdd32(xEventHandle, (uint32_t)uxPriority);
xTraceEventEnd(xEventHandle);
}
return TRC_SUCCESS;
}
traceResult xTraceTaskSetPriorityWithoutHandle(void* pvTask, TraceUnsignedBaseType_t uxPriority)
{
TraceEventHandle_t xEventHandle = 0;
TraceEntryHandle_t xEntryHandle;
if (xTraceEntryFind(pvTask, &xEntryHandle) == TRC_FAIL)
{
return TRC_FAIL;
}
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceObjectSetState((TraceObjectHandle_t)xEntryHandle, uxPriority) == TRC_SUCCESS);
/* We need to check this */
if (xTraceEventBegin(PSF_EVENT_TASK_PRIORITY, sizeof(void*) + sizeof(uint32_t), &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvTask);
xTraceEventAdd32(xEventHandle, (uint32_t)uxPriority);
xTraceEventEnd(xEventHandle);
}
return TRC_SUCCESS;
}
traceResult xTraceTaskSwitch(void *pvTask, TraceUnsignedBaseType_t uxPriority)
{
traceResult xResult = TRC_FAIL;
TraceEventHandle_t xEventHandle = 0;
void* pvCurrent = 0;
TRACE_ALLOC_CRITICAL_SECTION();
(void)pvTask;
(void)uxPriority;
if (xTraceIsRecorderEnabled() == 0)
{
return xResult;
}
TRACE_ENTER_CRITICAL_SECTION();
xTraceStateSet(TRC_STATE_IN_TASKSWITCH);
xTraceTaskGetCurrent(&pvCurrent);
if (pvCurrent != pvTask)
{
xTraceTaskSetCurrent(pvTask);
if (xTraceEventBegin(PSF_EVENT_TASK_ACTIVATE, sizeof(void*) + sizeof(uint32_t), &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvTask);
xTraceEventAdd32(xEventHandle, (uint32_t)uxPriority);
xTraceEventEnd(xEventHandle);
xResult = TRC_SUCCESS;
}
}
xTraceStateSet(TRC_STATE_IN_APPLICATION);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
#if (TRC_CFG_INCLUDE_READY_EVENTS == 1)
traceResult xTraceTaskReady(void *pvTask)
{
traceResult xResult = TRC_FAIL;
TraceEventHandle_t xEventHandle = 0;
if (xTraceEventBegin(PSF_EVENT_TASK_READY, sizeof(void*), &xEventHandle) == TRC_SUCCESS)
{
xTraceEventAddPointer(xEventHandle, pvTask);
xTraceEventEnd(xEventHandle);
xResult = TRC_SUCCESS;
}
return xResult;
}
#endif /* (TRC_CFG_INCLUDE_READY_EVENTS == 1) */
traceResult xTraceTaskInstanceFinishedNow(void)
{
TraceEventHandle_t xEventHandle = 0;
if (xTraceEventBegin(PSF_EVENT_IFE_DIRECT, 0, &xEventHandle) == TRC_FAIL)
{
return TRC_FAIL;
}
xTraceEventEnd(xEventHandle);
return TRC_SUCCESS;
}
traceResult xTraceTaskInstanceFinishedNext(void)
{
TraceEventHandle_t xEventHandle = 0;
if (xTraceEventBegin(PSF_EVENT_IFE_NEXT, 0, &xEventHandle) == TRC_FAIL)
{
return TRC_FAIL;
}
xTraceEventEnd(xEventHandle);
return TRC_SUCCESS;
}
#endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */