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