Select one of the symbols to view example projects that use it.
 
Outline
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "SEGGER_SYSVIEW.h"
#include "SEGGER_SYSVIEW_FreeRTOS.h"
#include "string.h"
SYSVIEW_FREERTOS_TASK_STATUS
SYSVIEW_FREERTOS_TASK_STATUS
_aTasks
_NumTasks
_cbSendTaskList()
_cbGetTime()
SYSVIEW_AddTask(unsigned long, const char *, unsigned int, unsigned long, unsigned int)
SYSVIEW_UpdateTask(unsigned long, const char *, unsigned int, unsigned long, unsigned int)
SYSVIEW_DeleteTask(unsigned long)
SYSVIEW_SendTaskInfo(unsigned long, const char *, unsigned int, unsigned long, unsigned int)
SYSVIEW_X_OS_TraceAPI
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/app_trace/sys_view/Sample/FreeRTOSV10.4/SEGGER_SYSVIEW_FreeRTOS.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 1995-2021 SEGGER Microcontroller GmbH * * SPDX-License-Identifier: BSD-1-Clause * * SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD *//* ... */ /********************************************************************* * SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** * * * (c) 1995 - 2021 SEGGER Microcontroller GmbH * * * * www.segger.com Support: support@segger.com * * * ********************************************************************** * * * SEGGER SystemView * Real-time application analysis * * * ********************************************************************** * * * All rights reserved. * * * * SEGGER strongly recommends to not make any changes * * to or modify the source code of this software in order to stay * * compatible with the SystemView and RTT protocol, and J-Link. * * * * Redistribution and use in source and binary forms, with or * * without modification, are permitted provided that the following * * condition is met: * * * * o Redistributions of source code must retain the above copyright * * notice, this condition and the following disclaimer. * * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * * DAMAGE. * * * ********************************************************************** * * * SystemView version: 3.42 * * * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : SEGGER_SYSVIEW_FreeRTOS.c Purpose : Interface between FreeRTOS and SystemView. Revision: $Rev: 7947 $ *//* ... */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "SEGGER_SYSVIEW.h" #include "SEGGER_SYSVIEW_FreeRTOS.h" #include "string.h" // Required for memset5 includes typedef struct SYSVIEW_FREERTOS_TASK_STATUS SYSVIEW_FREERTOS_TASK_STATUS; struct SYSVIEW_FREERTOS_TASK_STATUS { U32 xHandle; const char* pcTaskName; unsigned uxCurrentPriority; U32 pxStack; unsigned uStackHighWaterMark; }{ ... }; static SYSVIEW_FREERTOS_TASK_STATUS _aTasks[SYSVIEW_FREERTOS_MAX_NOF_TASKS]; static unsigned _NumTasks; /********************************************************************* * * _cbSendTaskList() * * Function description * This function is part of the link between FreeRTOS and SYSVIEW. * Called from SystemView when asked by the host, it uses SYSVIEW * functions to send the entire task list to the host. *//* ... */ static void _cbSendTaskList(void) { unsigned n; for (n = 0; n < _NumTasks; n++) { #if INCLUDE_uxTaskGetStackHighWaterMark // Report Task Stack High Watermark _aTasks[n].uStackHighWaterMark = uxTaskGetStackHighWaterMark((TaskHandle_t)_aTasks[n].xHandle); #endif SYSVIEW_SendTaskInfo((U32)_aTasks[n].xHandle, _aTasks[n].pcTaskName, (unsigned)_aTasks[n].uxCurrentPriority, (U32)_aTasks[n].pxStack, (unsigned)_aTasks[n].uStackHighWaterMark); }{...} }{ ... } /********************************************************************* * * _cbGetTime() * * Function description * This function is part of the link between FreeRTOS and SYSVIEW. * Called from SystemView when asked by the host, returns the * current system time in micro seconds. *//* ... */ static U64 _cbGetTime(void) { U64 Time; Time = xTaskGetTickCountFromISR(); Time *= portTICK_PERIOD_MS; Time *= 1000; return Time; }{ ... } /********************************************************************* * * Global functions * ********************************************************************** *//* ... */ /********************************************************************* * * SYSVIEW_AddTask() * * Function description * Add a task to the internal list and record its information. *//* ... */ void SYSVIEW_AddTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { /* On multi-core we have several idle tasks with 'IDLEx' names Not best solution, because we can filter out user tasks starting with 'IDLE'. But we can not use 'xTaskGetIdleTaskHandle' because at the moment when this function is called array of idle tasks handles are not initialized yet. *//* ... */ if (memcmp(pcTaskName, "IDLE", 4) == 0) { return; }{...} if (_NumTasks >= SYSVIEW_FREERTOS_MAX_NOF_TASKS) { SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); return; }{...} _aTasks[_NumTasks].xHandle = xHandle; _aTasks[_NumTasks].pcTaskName = pcTaskName; _aTasks[_NumTasks].uxCurrentPriority = uxCurrentPriority; _aTasks[_NumTasks].pxStack = pxStack; _aTasks[_NumTasks].uStackHighWaterMark = uStackHighWaterMark; _NumTasks++; SYSVIEW_SendTaskInfo(xHandle, pcTaskName,uxCurrentPriority, pxStack, uStackHighWaterMark); }{ ... } /********************************************************************* * * SYSVIEW_UpdateTask() * * Function description * Update a task in the internal list and record its information. *//* ... */ void SYSVIEW_UpdateTask(U32 xHandle, const char* pcTaskName, unsigned uxCurrentPriority, U32 pxStack, unsigned uStackHighWaterMark) { unsigned n; /* On multi-core we have several idle tasks with 'IDLEx' names Not best solution, because we can filter out user tasks starting with 'IDLE'. But we can not use 'xTaskGetIdleTaskHandle' because at the moment when this function is called array of idle tasks handles are not initialized yet. *//* ... */ if (memcmp(pcTaskName, "IDLE", 4) == 0) { return; }{...} for (n = 0; n < _NumTasks; n++) { if (_aTasks[n].xHandle == xHandle) { break; }{...} }{...} if (n < _NumTasks) { _aTasks[n].pcTaskName = pcTaskName; _aTasks[n].uxCurrentPriority = uxCurrentPriority; _aTasks[n].pxStack = pxStack; _aTasks[n].uStackHighWaterMark = uStackHighWaterMark; SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); }{...} else { SYSVIEW_AddTask(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); }{...} }{ ... } /********************************************************************* * * SYSVIEW_DeleteTask() * * Function description * Delete a task from the internal list. *//* ... */ void SYSVIEW_DeleteTask(U32 xHandle) { unsigned n; if (_NumTasks == 0) { return; // Early out }{...} for (n = 0; n < _NumTasks; n++) { if (_aTasks[n].xHandle == xHandle) { break; }{...} }{...} if (n == (_NumTasks - 1)) { // // Task is last item in list. // Simply zero the item and decrement number of tasks. // memset(&_aTasks[n], 0, sizeof(_aTasks[n])); _NumTasks--; }{...} else if (n < _NumTasks) { // // Task is in the middle of the list. // Move last item to current position and decrement number of tasks. // Order of tasks does not really matter, so no need to move all following items. // _aTasks[n].xHandle = _aTasks[_NumTasks - 1].xHandle; _aTasks[n].pcTaskName = _aTasks[_NumTasks - 1].pcTaskName; _aTasks[n].uxCurrentPriority = _aTasks[_NumTasks - 1].uxCurrentPriority; _aTasks[n].pxStack = _aTasks[_NumTasks - 1].pxStack; _aTasks[n].uStackHighWaterMark = _aTasks[_NumTasks - 1].uStackHighWaterMark; memset(&_aTasks[_NumTasks - 1], 0, sizeof(_aTasks[_NumTasks - 1])); _NumTasks--; }{...} }{ ... } /********************************************************************* * * SYSVIEW_SendTaskInfo() * * Function description * Record task information. *//* ... */ void SYSVIEW_SendTaskInfo(U32 TaskID, const char* sName, unsigned Prio, U32 StackBase, unsigned StackSize) { SEGGER_SYSVIEW_TASKINFO TaskInfo; memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future version without breaking the code TaskInfo.TaskID = TaskID; TaskInfo.sName = sName; TaskInfo.Prio = Prio; TaskInfo.StackBase = StackBase; TaskInfo.StackSize = StackSize; SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); }{ ... } /********************************************************************* * * Public API structures * ********************************************************************** *//* ... */ // Callbacks provided to SYSTEMVIEW by FreeRTOS const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { _cbGetTime, _cbSendTaskList, }{...}; /*************************** End of file ****************************/
Details