]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcKernelHooks.h
a029124e4459fb6d82b1aedbd3447d69daed8b09
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace / Include / trcKernelHooks.h
1 /*******************************************************************************\r
2 * Tracealyzer v2.6.0 Recorder Library\r
3 * Percepio AB, www.percepio.com\r
4 *\r
5 * trcKernelHooks.h\r
6 *\r
7 * The kernel integration hooks.\r
8 *\r
9 * NOTE:\r
10 * For IAR Embedded Workbench for ARM, you need to have a preprocessor condition\r
11 * on the include, to except it from the assembler step which otherwise give\r
12 * compile-time errors.\r
13 *\r
14 * #ifdef __ICCARM__\r
15 *       #include "percepio/Include/trcKernelHooks.h"\r
16 * #endif\r
17 *\r
18 * Terms of Use\r
19 * This software is copyright Percepio AB. The recorder library is free for\r
20 * use together with Percepio products. You may distribute the recorder library\r
21 * in its original form, including modifications in trcPort.c and trcPort.h\r
22 * given that these modification are clearly marked as your own modifications\r
23 * and documented in the initial comment section of these source files.\r
24 * This software is the intellectual property of Percepio AB and may not be\r
25 * sold or in other ways commercially redistributed without explicit written\r
26 * permission by Percepio AB.\r
27 *\r
28 * Disclaimer\r
29 * The trace tool and recorder library is being delivered to you AS IS and\r
30 * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
31 * not and cannot warrant the performance or results you may obtain by using the\r
32 * software or documentation. Percepio AB make no warranties, express or\r
33 * implied, as to noninfringement of third party rights, merchantability, or\r
34 * fitness for any particular purpose. In no event will Percepio AB, its\r
35 * technology partners, or distributors be liable to you for any consequential,\r
36 * incidental or special damages, including any lost profits or lost savings,\r
37 * even if a representative of Percepio AB has been advised of the possibility\r
38 * of such damages, or for any claim by any third party. Some jurisdictions do\r
39 * not allow the exclusion or limitation of incidental, consequential or special\r
40 * damages, or the exclusion of implied warranties or limitations on how long an\r
41 * implied warranty may last, so the above limitations may not apply to you.\r
42 *\r
43 * Copyright Percepio AB, 2013.\r
44 * www.percepio.com\r
45 ******************************************************************************/\r
46 \r
47 #ifndef TRCKERNELHOOKS_H\r
48 #define TRCKERNELHOOKS_H\r
49 \r
50 #if (USE_TRACEALYZER_RECORDER == 1)\r
51 \r
52 #undef INCLUDE_xTaskGetSchedulerState\r
53 #define INCLUDE_xTaskGetSchedulerState 1\r
54 \r
55 #undef INCLUDE_xTaskGetCurrentTaskHandle\r
56 #define INCLUDE_xTaskGetCurrentTaskHandle 1\r
57 \r
58 #ifndef INCLUDE_OBJECT_DELETE\r
59 #define INCLUDE_OBJECT_DELETE 0\r
60 #endif\r
61 \r
62 #ifndef INCLUDE_READY_EVENTS\r
63 #define INCLUDE_READY_EVENTS 1\r
64 #endif\r
65 \r
66 #ifndef INCLUDE_NEW_TIME_EVENTS\r
67 #define INCLUDE_NEW_TIME_EVENTS 0\r
68 #endif\r
69 \r
70 #if (INCLUDE_OBJECT_DELETE == 1)\r
71 /* This macro will remove the task and store it in the event buffer */\r
72 #undef trcKERNEL_HOOKS_TASK_DELETE\r
73 #define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB) \\r
74         vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
75         vTraceStoreObjectNameOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
76         vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
77         vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
78         vTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \\r
79         vTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
80 #else\r
81 #undef trcKERNEL_HOOKS_TASK_DELETE\r
82 #define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB)\r
83 #endif\r
84 \r
85 #if (INCLUDE_OBJECT_DELETE == 1)\r
86 /* This macro will remove the object and store it in the event buffer */\r
87 #undef trcKERNEL_HOOKS_OBJECT_DELETE\r
88 #define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject) \\r
89         vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
90         vTraceStoreObjectNameOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
91         vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
92         vTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
93 #else\r
94 #undef trcKERNEL_HOOKS_OBJECT_DELETE\r
95 #define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject)\r
96 #endif\r
97 \r
98 /* This macro will create a task in the object table */\r
99 #undef trcKERNEL_HOOKS_TASK_CREATE\r
100 #define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \\r
101         TRACE_SET_TASK_NUMBER(pxTCB) \\r
102         vTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \\r
103         vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
104         vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
105 \r
106 /* This macro will create a failed create call to create a task */\r
107 #undef trcKERNEL_HOOKS_TASK_CREATE_FAILED\r
108 #define trcKERNEL_HOOKS_TASK_CREATE_FAILED(SERVICE, CLASS) \\r
109         vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, FAILED, CLASS, 0), TRACE_CLASS_TASK, 0);\r
110 \r
111 /* This macro will setup a task in the object table */\r
112 #undef trcKERNEL_HOOKS_OBJECT_CREATE\r
113 #define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\\r
114         TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\\r
115         vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
116         vTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);\r
117 \r
118 /* This macro will create a failed create call to create an object */\r
119 #undef trcKERNEL_HOOKS_OBJECT_CREATE_FAILED\r
120 #define trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(SERVICE, CLASS, kernelClass) \\r
121         vTraceStoreKernelCall(TRACE_GET_CLASS_EVENT_CODE(SERVICE, FAILED, CLASS, kernelClass), TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass), 0);\r
122 \r
123 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
124 #undef trcKERNEL_HOOKS_KERNEL_SERVICE\r
125 #define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, RESULT, CLASS, pxObject) \\r
126         vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
127 \r
128 /* This macro will set the state for an object */\r
129 #undef trcKERNEL_HOOKS_SET_OBJECT_STATE\r
130 #define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \\r
131         vTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), STATE);\r
132 \r
133 /* This macro will flag a certain task as a finished instance */\r
134 #undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED\r
135 #define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \\r
136         vTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));\r
137 \r
138 #if INCLUDE_READY_EVENTS == 1\r
139 /* This macro will create an event to indicate that a task became Ready */\r
140 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
141 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \\r
142         vTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));\r
143 #else\r
144 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
145 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)\r
146 #endif\r
147 \r
148 /* This macro will update the internal tick counter and call vTracePortGetTimeStamp(0) to update the internal counters */\r
149 #undef trcKERNEL_HOOKS_INCREMENT_TICK\r
150 #define trcKERNEL_HOOKS_INCREMENT_TICK() \\r
151         { extern uint32_t uiTraceTickCount; uiTraceTickCount++; vTracePortGetTimeStamp(0); }\r
152 \r
153 #if INCLUDE_NEW_TIME_EVENTS == 1\r
154 /* This macro will create an event indicating that the OS tick count has increased */\r
155 #undef trcKERNEL_HOOKS_NEW_TIME\r
156 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \\r
157         vTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);\r
158 #else\r
159 #undef trcKERNEL_HOOKS_NEW_TIME\r
160 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)\r
161 #endif\r
162 \r
163 /* This macro will create a task switch event to the currently executing task */\r
164 #undef trcKERNEL_HOOKS_TASK_SWITCH\r
165 #define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \\r
166         vTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));\r
167 \r
168 /* This macro will create an event to indicate that the task has been suspended */\r
169 #undef trcKERNEL_HOOKS_TASK_SUSPEND\r
170 #define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \\r
171         vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
172         vTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
173 \r
174 /* This macro will create an event to indicate that a task has called a wait/delay function */\r
175 #undef trcKERNEL_HOOKS_TASK_DELAY\r
176 #define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \\r
177         vTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \\r
178         vTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
179 \r
180 /* This macro will create an event to indicate that a task has gotten its priority changed */\r
181 #undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE\r
182 #define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \\r
183         vTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), uiTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\\r
184         vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority);\r
185 \r
186 /* This macro will create an event to indicate that the task has been resumed */\r
187 #undef trcKERNEL_HOOKS_TASK_RESUME\r
188 #define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \\r
189         vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
190         \r
191 #undef trcKERNEL_HOOKS_TIMER_EVENT\r
192 #define trcKERNEL_HOOKS_TIMER_EVENT(SERVICE, pxTimer) \\r
193         vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
194 \r
195 /* This macro will create a timer in the object table and assign the timer a trace handle (timer number).*/\r
196 #undef trcKERNEL_HOOKS_TIMER_CREATE\r
197 #define trcKERNEL_HOOKS_TIMER_CREATE(SERVICE, pxTimer) \\r
198 TRACE_SET_TIMER_NUMBER(pxTimer); \\r
199 vTraceSetObjectName(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_GET_TIMER_NAME(pxTimer)); \\r
200 vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
201 #endif\r
202 \r
203 #undef trcKERNEL_HOOKS_TIMER_DELETE\r
204 #define trcKERNEL_HOOKS_TIMER_DELETE(SERVICE, pxTimer) \\r
205 vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer)); \\r
206 vTraceStoreObjectNameOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
207 vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
208 vTraceFreeObjectHandle(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
209 \r
210 #endif /* TRCKERNELHOOKS_H */