1 /*
2  * Trace Recorder for Tracealyzer v4.5.1
3  * Copyright 2021 Percepio AB
4  * www.percepio.com
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  * uC/OS3 specific definitions needed by the trace recorder
9  */
10 
11 #ifndef TRC_KERNEL_PORT_H
12 #define TRC_KERNEL_PORT_H
13 
14 #include <stdint.h>
15 #include <os.h>
16 #include <os_cfg.h>	                                        /* Defines OS_CFG_TRACE_EN (1: Enabled).               */
17 #include <os_cfg_app.h>	                                    /* Defines OS_CFG_TICK_RATE_HZ.                        */
18 #if(TRC_BSP_CLK_SOURCE == 1)
19 #include <bsp.h>
20 #endif
21 #include "trcPortDefines.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #if (OS_VERSION >= 30600u)
28 #if (defined(OS_CFG_TRACE_EN) && (OS_CFG_TRACE_EN > 0u))
29   #define TRC_USE_TRACEALYZER_RECORDER   1
30 #else
31   #define TRC_USE_TRACEALYZER_RECORDER   0
32 #endif
33 #else /* (OS_VERSION >= 30600u) */
34 #if (defined(TRACE_CFG_EN) && (TRACE_CFG_EN > 0u))
35   #define TRC_USE_TRACEALYZER_RECORDER   1
36 #else
37   #define TRC_USE_TRACEALYZER_RECORDER   0
38 #endif
39 #endif /* (OS_VERSION >= 30600u) */
40 
41 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
42 
43 #define TRC_PLATFORM_CFG ""
44 #define TRC_PLATFORM_CFG_MAJOR 1
45 #define TRC_PLATFORM_CFG_MINOR 0
46 #define TRC_PLATFORM_CFG_PATCH 0
47 
48 #if defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)
49 	/* Required for this feature */
50 #undef OS_CFG_STAT_TASK_STK_CHK_EN
51 #define OS_CFG_STAT_TASK_STK_CHK_EN DEF_ENABLED
52 #endif /* defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0) */
53 
54 #define TRACE_KERNEL_VERSION 0x2AA2
55 #define TRACE_TICK_RATE_HZ  OS_CFG_TICK_RATE_HZ            /* OS tick rate in Hertz.           */
56 
57 #if(TRC_BSP_CLK_SOURCE == 1 && OS_VERSION >= 30700u)
58 #define TRACE_CPU_CLOCK_HZ BSP_ClkFreqGet(CLK_ID_SYSCLK)
59 #elif(TRC_BSP_CLK_SOURCE == 1 && OS_VERSION < 30700u)
60 #define TRACE_CPU_CLOCK_HZ  BSP_CPU_ClkFreq()              /* Peripheral clock speed in Hertz. */
61 #endif
62 
63 /* Gives the currently executing task (wrapper for RTOS-specific function) */
64 void* prvTraceGetCurrentTaskHandle(void);
65 uint32_t prvIsNewTCB(void* pNewTCB);
66 char* prvTraceAppend(const char* name, const char* suffix);
67 
68 #if defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1)
69 uint32_t prvTraceGetStackHighWaterMark(void* task);
70 #endif /* defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1)*/
71 
72 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))
73 void vTraceStartStackMonitor(void);
74 #else /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)) */
75 #define vTraceStartStackMonitor()
76 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (defined(TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)) */
77 
78 #if (((TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (TRC_CFG_INCLUDE_ISR_TRACING == 1)) || (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING))
79 /* Tells if the scheduler currently is suspended (task-switches can't occur) */
80 unsigned char prvTraceIsSchedulerSuspended(void);
81 
82 #endif /* (((TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (TRC_CFG_INCLUDE_ISR_TRACING == 1)) || (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)) */
83 
84 #define TRACE_GET_CURRENT_TASK() prvTraceGetCurrentTaskHandle()
85 
86 #define TRACE_GET_OS_TICKS() (uiTraceTickCount) /* Streaming only */
87 
88 /* If using dynamic allocation of snapshot trace buffer... */
89 #define TRACE_MALLOC(size) pvPortMalloc(size)
90 
91 /* Critical sections definition */
92 #define TRACE_ALLOC_CRITICAL_SECTION()    CPU_SR_ALLOC();
93 #define TRACE_ENTER_CRITICAL_SECTION()    CPU_CRITICAL_ENTER();
94 #define TRACE_EXIT_CRITICAL_SECTION()     CPU_CRITICAL_EXIT();
95 
96 extern uint16_t CurrentFilterMask;
97 
98 extern uint16_t CurrentFilterGroup;
99 
100 #if (OS_VERSION < 30700u)
101 extern void* prvTrcTickTask;
102 #endif /* (OS_VERSION < 30700u) */
103 
104 #if !defined(TRC_CFG_INCLUDE_TICK_TASK)
105 #define TRC_CFG_INCLUDE_TICK_TASK 0
106 #endif
107 
108 #if (TRC_CFG_INCLUDE_TICK_TASK == 0) && (OS_VERSION < 30700u)
109 #define TRACE_IF_NOT_TICK_TASK(p_tcb) if (prvTrcTickTask != (void*)p_tcb)
110 #else /* (TRC_CFG_INCLUDE_TICK_TASK == 0) && (OS_VERSION < 30700u) */
111 #define TRACE_IF_NOT_TICK_TASK(p_tcb)
112 #endif /* (TRC_CFG_INCLUDE_TICK_TASK == 0) && (OS_VERSION < 30700u) */
113 
114 /* Tasks */
115 uint16_t prvTraceGetTaskNumberLow16(void* handle);
116 uint16_t prvTraceGetTaskNumberHigh16(void* handle);
117 void prvTraceSetTaskNumberLow16(void* handle, uint16_t value);
118 void prvTraceSetTaskNumberHigh16(void* handle, uint16_t value);
119 
120 /* Task Queues */
121 #if (OS_CFG_TASK_Q_EN == DEF_ENABLED)
122 uint16_t prvTraceGetTaskQueueNumberLow16(void* handle);
123 uint16_t prvTraceGetTaskQueueNumberHigh16(void* handle);
124 void prvTraceSetTaskQueueNumberLow16(void* handle, uint16_t value);
125 void prvTraceSetTaskQueueNumberHigh16(void* handle, uint16_t value);
126 #endif /* (OS_CFG_TASK_Q_EN == DEF_ENABLED) */
127 
128 /* Task Semaphores */
129 uint16_t prvTraceGetTaskSemNumberLow16(void* handle);
130 uint16_t prvTraceGetTaskSemNumberHigh16(void* handle);
131 void prvTraceSetTaskSemNumberLow16(void* handle, uint16_t value);
132 void prvTraceSetTaskSemNumberHigh16(void* handle, uint16_t value);
133 
134 /* Queues */
135 uint16_t prvTraceGetQueueNumberLow16(void* handle);
136 uint16_t prvTraceGetQueueNumberHigh16(void* handle);
137 void prvTraceSetQueueNumberLow16(void* handle, uint16_t value);
138 void prvTraceSetQueueNumberHigh16(void* handle, uint16_t value);
139 
140 /* Semaphores */
141 uint16_t prvTraceGetSemaphoreNumberLow16(void* handle);
142 uint16_t prvTraceGetSemaphoreNumberHigh16(void* handle);
143 void prvTraceSetSemaphoreNumberLow16(void* handle, uint16_t value);
144 void prvTraceSetSemaphoreNumberHigh16(void* handle, uint16_t value);
145 
146 /* Mutexes */
147 uint16_t prvTraceGetMutexNumberLow16(void* handle);
148 uint16_t prvTraceGetMutexNumberHigh16(void* handle);
149 void prvTraceSetMutexNumberLow16(void* handle, uint16_t value);
150 void prvTraceSetMutexNumberHigh16(void* handle, uint16_t value);
151 
152 /* Flags */
153 uint16_t prvTraceGetFlagNumberLow16(void* handle);
154 uint16_t prvTraceGetFlagNumberHigh16(void* handle);
155 void prvTraceSetFlagNumberLow16(void* handle, uint16_t value);
156 void prvTraceSetFlagNumberHigh16(void* handle, uint16_t value);
157 
158 /* Mems */
159 uint16_t prvTraceGetMemNumberLow16(void* handle);
160 uint16_t prvTraceGetMemNumberHigh16(void* handle);
161 void prvTraceSetMemNumberLow16(void* handle, uint16_t value);
162 void prvTraceSetMemNumberHigh16(void* handle, uint16_t value);
163 
164 /* Task Suspend and Resume */
165 void prvTraceTaskSuspendEnter(void* p_tcb);
166 void prvTraceTaskSuspendExit(uint32_t p_err);
167 void prvTraceTaskResumeEnter(void* p_tcb);
168 void prvTraceTaskResumeExit(uint32_t p_err);
169 
170 /* Filters */
171 #define TRACE_GET_TASK_FILTER(pxTask) 1
172 #define TRACE_SET_TASK_FILTER(pxTask, group)
173 
174 #if (OS_CFG_TASK_Q_EN == DEF_ENABLED)
175 #define TRACE_GET_MICRIUM_TASK_MSG_Q_FILTER(pxObject) 1
176 #define TRACE_SET_MICRIUM_TASK_MSG_Q_FILTER(pxObject, group)
177 #endif /* (OS_CFG_TASK_Q_EN == DEF_ENABLED) */
178 
179 #define TRACE_GET_MICRIUM_TASK_SEM_FILTER(pxObject) 1
180 #define TRACE_SET_MICRIUM_TASK_SEM_FILTER(pxObject, group)
181 
182 #define TRACE_GET_MICRIUM_Q_FILTER(pxObject) 1
183 #define TRACE_SET_MICRIUM_Q_FILTER(pxObject, group)
184 
185 #define TRACE_GET_MICRIUM_SEM_FILTER(pxObject) 1
186 #define TRACE_SET_MICRIUM_SEM_FILTER(pxObject, group)
187 
188 #define TRACE_GET_MICRIUM_MUTEX_FILTER(pxObject) 1
189 #define TRACE_SET_MICRIUM_MUTEX_FILTER(pxObject, group)
190 
191 #define TRACE_GET_MICRIUM_FLAG_FILTER(pxObject) 1
192 #define TRACE_SET_MICRIUM_FLAG_FILTER(pxObject, group)
193 
194 #define TRACE_GET_MICRIUM_MEM_FILTER(pxObject) 1
195 #define TRACE_SET_MICRIUM_MEM_FILTER(pxObject, group)
196 
197 #define TRACE_GET_OBJECT_FILTER(CLASS, pxObject) TRACE_GET_##CLASS##_FILTER(pxObject)
198 #define TRACE_SET_OBJECT_FILTER(CLASS, pxObject, group) TRACE_SET_##CLASS##_FILTER(pxObject, group)
199 
200 /******************************************************************************/
201 /*** Definitions for Snapshot mode ********************************************/
202 /******************************************************************************/
203 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
204 
205 #define  OS_TRACE_INIT()                                      vTraceEnable(TRC_INIT)
206 #define  OS_TRACE_START()
207 #define  OS_TRACE_STOP()
208 #define  OS_TRACE_CLEAR()                                     vTraceClear()
209 
210 /*** The object classes *******************************************************/
211 #define TRACE_NCLASSES        9
212 #define TRACE_CLASS_QUEUE     ((traceObjectClass)0)
213 #define TRACE_CLASS_SEMAPHORE ((traceObjectClass)1)
214 #define TRACE_CLASS_MUTEX     ((traceObjectClass)2)
215 #define TRACE_CLASS_FLAG      ((traceObjectClass)3)
216 #define TRACE_CLASS_MEM       ((traceObjectClass)4)
217 #define TRACE_CLASS_TASK_SEM  ((traceObjectClass)5)
218 #define TRACE_CLASS_TASK_Q    ((traceObjectClass)6)
219 #define TRACE_CLASS_TASK      ((traceObjectClass)7)
220 #define TRACE_CLASS_ISR       ((traceObjectClass)8)
221 
222 #define TRACE_KERNEL_OBJECT_COUNT ((TRC_CFG_NQUEUE) + (TRC_CFG_NSEMAPHORE) + (TRC_CFG_NMUTEX) + (TRC_CFG_NFLAG) + (TRC_CFG_NMEM) + (TRC_CFG_NTASK_SEM) + (TRC_CFG_NTASK_Q) + (TRC_CFG_NTASK) + (TRC_CFG_NISR))
223 
224 /* The size of the Object Property Table entries, in bytes, per object */
225 
226 /* Queue properties (except name):     current number of message in queue */
227 #define PropertyTableSizeQueue         ((TRC_CFG_NAME_LEN_QUEUE) + 1)
228 
229 /* Semaphore properties (except name): state (signaled = 1, cleared = 0) */
230 #define PropertyTableSizeSemaphore     ((TRC_CFG_NAME_LEN_SEMAPHORE) + 1)
231 
232 /* Mutex properties (except name):     owner (task handle, 0 = free) */
233 #define PropertyTableSizeMutex         ((TRC_CFG_NAME_LEN_MUTEX) + 1)
234 
235 /* Flags properties (except name): state (signaled = 1, cleared = 0) */
236 #define PropertyTableSizeFlag          ((TRC_CFG_NAME_LEN_FLAG) + 1)
237 
238 /* Memory Partitions properties (except name): state (signaled = 1, cleared = 0) */
239 #define PropertyTableSizeMem           ((TRC_CFG_NAME_LEN_MEM) + 1)
240 
241 /* Task Semaphore properties (except name): state (signaled = 1, cleared = 0) */
242 #define PropertyTableSizeTaskSem       ((TRC_CFG_NAME_LEN_TASK_SEM) + 1)
243 
244 /* Task Q properties (except name): state (signaled = 1, cleared = 0) */
245 #define PropertyTableSizeTaskQ         ((TRC_CFG_NAME_LEN_TASK_Q) + 1)
246 
247 /* Task properties (except name):      Byte 0: Current priority
248                                        Byte 1: state (if already active)
249                                        Byte 2: InstanceFinishEvent_ServiceCode
250                                        Byte 3: InstanceFinishEvent_ObjHandle */
251 #define PropertyTableSizeTask         ((TRC_CFG_NAME_LEN_TASK) + 4)
252 
253 /* ISR properties:                     Byte 0: priority
254                                        Byte 1: state (if already active) */
255 #define PropertyTableSizeISR          ((TRC_CFG_NAME_LEN_ISR) + 2)
256 
257 
258 
259 /* The layout of the byte array representing the Object Property Table */
260 #define StartIndexQueue            (0)
261 #define StartIndexSemaphore        (StartIndexQueue     + (TRC_CFG_NQUEUE)     * PropertyTableSizeQueue)
262 #define StartIndexMutex            (StartIndexSemaphore + (TRC_CFG_NSEMAPHORE) * PropertyTableSizeSemaphore)
263 #define StartIndexFlag             (StartIndexMutex     + (TRC_CFG_NMUTEX)     * PropertyTableSizeMutex)
264 #define StartIndexMem              (StartIndexFlag      + (TRC_CFG_NFLAG)      * PropertyTableSizeFlag)
265 #define StartIndexTaskSem          (StartIndexMem       + (TRC_CFG_NMEM)       * PropertyTableSizeMem)
266 #define StartIndexTaskQ            (StartIndexTaskSem   + (TRC_CFG_NTASK_SEM)  * PropertyTableSizeTaskSem)
267 #define StartIndexTask             (StartIndexTaskQ     + (TRC_CFG_NTASK_Q)    * PropertyTableSizeTaskQ)
268 #define StartIndexISR              (StartIndexTask      + (TRC_CFG_NTASK)      * PropertyTableSizeTask)
269 
270 
271 /* Number of bytes used by the object table */
272 #define TRACE_OBJECT_TABLE_SIZE    (StartIndexISR       + (TRC_CFG_NISR)       * PropertyTableSizeISR)
273 
274 /* Initialization of the object property table */
275 void vTraceInitObjectPropertyTable(void);
276 
277 /* Initialization of the handle mechanism, see e.g, prvTraceGetObjectHandle */
278 void vTraceInitObjectHandleStack(void);
279 
280 /* Returns the "Not enough handles" error message for the specified object class */
281 const char* pszTraceGetErrorNotEnoughHandles(traceObjectClass objectclass);
282 
283 /*** Event codes for snapshot mode - must match Tracealyzer config files ******/
284 
285 #define NULL_EVENT                   (0x00)  /* Ignored in the analysis*/
286 
287 /*******************************************************************************
288  * EVENTGROUP_DIV
289  *
290  * Miscellaneous events.
291  ******************************************************************************/
292 #define EVENTGROUP_DIV                           (NULL_EVENT + 1)                                /*0x01*/
293 #define DIV_XPS                                  (EVENTGROUP_DIV + 0)                            /*0x01*/
294 #define DIV_TASK_READY                           (EVENTGROUP_DIV + 1)                            /*0x02*/
295 #define DIV_NEW_TIME                             (EVENTGROUP_DIV + 2)                            /*0x03*/
296 
297 /*******************************************************************************
298  * EVENTGROUP_TS
299  *
300  * Events for storing task-switches and interrupts. The RESUME events are
301  * generated if the task/interrupt is already marked active.
302  ******************************************************************************/
303 #define EVENTGROUP_TS                            (EVENTGROUP_DIV + 3)                            /*0x04*/
304 #define TS_ISR_BEGIN                             (EVENTGROUP_TS + 0)                             /*0x04*/
305 #define TS_ISR_RESUME                            (EVENTGROUP_TS + 1)                             /*0x05*/
306 #define TS_TASK_BEGIN                            (EVENTGROUP_TS + 2)                             /*0x06*/
307 #define TS_TASK_RESUME                           (EVENTGROUP_TS + 3)                             /*0x07*/
308 
309 /*******************************************************************************
310  * EVENTGROUP_OBJCLOSE_NAME
311  *
312  * About Close Events
313  * When an object is evicted from the object property table (object close), two
314  * internal events are stored (EVENTGROUP_OBJCLOSE_NAME and
315  * EVENTGROUP_OBJCLOSE_PROP), containing the handle-name mapping and object
316  * properties valid up to this point.
317  ******************************************************************************/
318 #define EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS      (EVENTGROUP_TS + 4)                             /*0x08*/
319 
320 /*******************************************************************************
321  * EVENTGROUP_OBJCLOSE_PROP
322  *
323  * The internal event carrying properties of deleted objects
324  * The handle and object class of the closed object is not stored in this event,
325  * but is assumed to be the same as in the preceding CLOSE event. Thus, these
326  * two events must be generated from within a critical section.
327  * When queues are closed, arg1 is the "state" property (i.e., number of
328  * buffered messages/signals).
329  * When actors are closed, arg1 is priority, arg2 is handle of the "instance
330  * finish" event, and arg3 is event code of the "instance finish" event.
331  * In this case, the lower three bits is the object class of the instance finish
332  * handle. The lower three bits are not used (always zero) when queues are
333  * closed since the queue type is given in the previous OBJCLOSE_NAME event.
334  ******************************************************************************/
335 #define EVENTGROUP_OBJCLOSE_PROP_TRCSUCCESS      (EVENTGROUP_OBJCLOSE_NAME_TRCSUCCESS + 10)      /*0x12*/
336 
337 /*******************************************************************************
338  * EVENTGROUP_CREATE
339  *
340  * The events in this group are used to log Kernel object creations.
341  * The lower three bits in the event code gives the object class, i.e., type of
342  * create operation (task, queue, semaphore, etc).
343  ******************************************************************************/
344 #define EVENTGROUP_CREATE_TRCSUCCESS             (EVENTGROUP_OBJCLOSE_PROP_TRCSUCCESS + 10)      /*0x1C*/
345 
346 /*******************************************************************************
347  * EVENTGROUP_SEND
348  *
349  * The events in this group are used to log Send/Give events on queues,
350  * semaphores and mutexes The lower three bits in the event code gives the
351  * object class, i.e., what type of object that is operated on (queue, semaphore
352  * or mutex).
353  ******************************************************************************/
354 #define EVENTGROUP_SEND_TRCSUCCESS               (EVENTGROUP_CREATE_TRCSUCCESS + 10)             /*0x26*/
355 
356 /*******************************************************************************
357  * EVENTGROUP_RECEIVE
358  *
359  * The events in this group are used to log Receive/Take events on queues,
360  * semaphores and mutexes. The lower three bits in the event code gives the
361  * object class, i.e., what type of object that is operated on (queue, semaphore
362  * or mutex).
363  ******************************************************************************/
364 #define EVENTGROUP_RECEIVE_TRCSUCCESS            (EVENTGROUP_SEND_TRCSUCCESS + 10)               /*0x30*/
365 
366 /* Send/Give operations, to a task */
367 #define EVENTGROUP_SEND_TO_TASK_TRCSUCCESS       (EVENTGROUP_RECEIVE_TRCSUCCESS + 10)            /*0x3A*/
368 
369 /* Receive/Take operations, from a task */
370 #define EVENTGROUP_RECEIVE_FROM_TASK_TRCSUCCESS  (EVENTGROUP_SEND_TO_TASK_TRCSUCCESS + 10)       /*0x44*/
371 
372 /* "Failed" event type versions of above (timeout, failed allocation, etc) */
373 #define EVENTGROUP_KSE_TRCFAILED                 (EVENTGROUP_RECEIVE_FROM_TASK_TRCSUCCESS + 10)  /*0x4E*/
374 
375 /* Failed create calls - memory allocation failed */
376 #define EVENTGROUP_CREATE_TRCFAILED              (EVENTGROUP_KSE_TRCFAILED)                      /*0x4E*/
377 
378 /* Failed send/give - timeout! */
379 #define EVENTGROUP_SEND_TRCFAILED                (EVENTGROUP_CREATE_TRCFAILED + 10)              /*0x58*/
380 
381 /* Failed receive/take - timeout! */
382 #define EVENTGROUP_RECEIVE_TRCFAILED             (EVENTGROUP_SEND_TRCFAILED + 10)                /*0x62*/
383 
384 /* Failed non-blocking send/give - queue full */
385 #define EVENTGROUP_SEND_TO_TASK_TRCFAILED        (EVENTGROUP_RECEIVE_TRCFAILED + 10)             /*0x6C*/
386 
387 /* Failed non-blocking receive/take - queue empty */
388 #define EVENTGROUP_RECEIVE_FROM_TASK_TRCFAILED   (EVENTGROUP_SEND_TO_TASK_TRCFAILED + 10)        /*0x76*/
389 
390 /* Events when blocking on receive/take */
391 #define EVENTGROUP_RECEIVE_TRCBLOCK              (EVENTGROUP_RECEIVE_FROM_TASK_TRCFAILED + 10)   /*0x80*/
392 
393 /* Events when blocking on send/give */
394 #define EVENTGROUP_SEND_TRCBLOCK                 (EVENTGROUP_RECEIVE_TRCBLOCK + 10)              /*0x8A*/
395 
396 /* Events on queue peek (receive) */
397 #define EVENTGROUP_PEEK_TRCSUCCESS               (EVENTGROUP_SEND_TRCBLOCK + 10)                 /*0x94*/
398 
399 /* Events on object delete (vTaskDelete or vQueueDelete) */
400 #define EVENTGROUP_DELETE_TRCSUCCESS             (EVENTGROUP_PEEK_TRCSUCCESS + 10)               /*0x9E*/
401 
402 /* Other events - object class is implied: TASK */
403 #define EVENTGROUP_OTHERS						 (EVENTGROUP_DELETE_TRCSUCCESS + 10)             /*0xA8*/
404 #define TASK_DELAY_UNTIL						 (EVENTGROUP_OTHERS + 0)                         /*0xA8*/
405 #define TASK_DELAY								 (EVENTGROUP_OTHERS + 1)                         /*0xA9*/
406 #define TASK_SUSPEND							 (EVENTGROUP_OTHERS + 2)                         /*0xAA*/
407 #define TASK_RESUME								 (EVENTGROUP_OTHERS + 3)                         /*0xAB*/
408 #define TASK_PRIORITY_SET						 (EVENTGROUP_OTHERS + 5)                         /*0xAD*/
409 #define TASK_PRIORITY_INHERIT					 (EVENTGROUP_OTHERS + 6)                         /*0xAE*/
410 #define TASK_PRIORITY_DISINHERIT				 (EVENTGROUP_OTHERS + 7)                         /*0xAF*/
411 #define TASK_SUSPEND_FAIL						 (EVENTGROUP_OTHERS + 9)                         /*0xB1*/
412 #define TASK_RESUME_FAIL						 (EVENTGROUP_OTHERS + 10)                        /*0xB2*/
413 
414 /* Not yet used */
415 #define EVENTGROUP_FTRACE_PLACEHOLDER            (EVENTGROUP_OTHERS + 8)                         /*0xB0*/
416 
417 /* User events */
418 #define EVENTGROUP_USEREVENT                     (EVENTGROUP_FTRACE_PLACEHOLDER + 10)            /*0xBA*/
419 #define USER_EVENT                               (EVENTGROUP_USEREVENT + 0)
420 
421 /* Allow for 0-15 arguments (the number of args is added to event code) */
422 #define USER_EVENT_LAST                          (EVENTGROUP_USEREVENT + 15)                     /*0xC9*/
423 
424 /*******************************************************************************
425  * XTS Event - eXtended TimeStamp events
426  * The timestamps used in the recorder are "differential timestamps" (DTS), i.e.
427  * the time since the last stored event. The DTS fields are either 1 or 2 bytes
428  * in the other events, depending on the bytes available in the event struct.
429  * If the time since the last event (the DTS) is larger than allowed for by
430  * the DTS field of the current event, an XTS event is inserted immediately
431  * before the original event. The XTS event contains up to 3 additional bytes
432  * of the DTS value - the higher bytes of the true DTS value. The lower 1-2
433  * bytes are stored in the normal DTS field.
434  * There are two types of XTS events, XTS8 and XTS16. An XTS8 event is stored
435  * when there is only room for 1 byte (8 bit) DTS data in the original event,
436  * which means a limit of 0xFF (255). The XTS16 is used when the original event
437  * has a 16 bit DTS field and thereby can handle values up to 0xFFFF (65535).
438  *
439  * Using a very high frequency time base can result in many XTS events.
440  * Preferably, the time between two OS ticks should fit in 16 bits, i.e.,
441  * at most 65535. If your time base has a higher frequency, you can define
442  * the TRACE
443  ******************************************************************************/
444 
445 #define EVENTGROUP_SYS                           (EVENTGROUP_USEREVENT + 16)                      /*0xCA*/
446 #define XTS8                                     (EVENTGROUP_SYS + 0)                             /*0xCA*/
447 #define XTS16                                    (EVENTGROUP_SYS + 1)                             /*0xCB*/
448 #define EVENT_BEING_WRITTEN                      (EVENTGROUP_SYS + 2)                             /*0xCC*/
449 #define RESERVED_DUMMY_CODE                      (EVENTGROUP_SYS + 3)                             /*0xCD*/
450 #define LOW_POWER_BEGIN                          (EVENTGROUP_SYS + 4)                             /*0xCE*/
451 #define LOW_POWER_END                            (EVENTGROUP_SYS + 5)                             /*0xCF*/
452 #define XID                                      (EVENTGROUP_SYS + 6)                             /*0xD0*/
453 #define XTS16L                                   (EVENTGROUP_SYS + 7)                             /*0xD1*/
454 #define TASK_INSTANCE_FINISHED_NEXT_KSE          (EVENTGROUP_SYS + 8)                             /*0xD2*/
455 #define TASK_INSTANCE_FINISHED_DIRECT            (EVENTGROUP_SYS + 9)                             /*0xD3*/
456 #define TRACE_UNUSED_STACK         			     (EVENTGROUP_SYS + 10)                            /*0xD4*/
457 
458 traceHandle prvTraceGetTaskNumber(void* handle);
459 unsigned char prvTraceIsSchedulerActive(void);
460 unsigned char prvTraceIsSchedulerSuspended(void);
461 unsigned char prvTraceIsSchedulerStarted(void);
462 
463 /************************************************************************/
464 /* KERNEL SPECIFIC MACROS USED BY THE TRACE RECORDER                    */
465 /************************************************************************/
466 
467 /****************************
468 * MACROS TO GET TRACE CLASS *
469 ****************************/
470 
471 #define TRACE_GET_TASK_TRACE_CLASS()          	   TRACE_CLASS_TASK
472 #define TRACE_GET_MICRIUM_TASK_SEM_TRACE_CLASS()   TRACE_CLASS_TASK_SEM
473 #define TRACE_GET_MICRIUM_TASK_MSG_Q_TRACE_CLASS() TRACE_CLASS_TASK_Q
474 #define TRACE_GET_MICRIUM_Q_TRACE_CLASS()          TRACE_CLASS_QUEUE
475 #define TRACE_GET_MICRIUM_SEM_TRACE_CLASS()        TRACE_CLASS_SEMAPHORE
476 #define TRACE_GET_MICRIUM_MUTEX_TRACE_CLASS()      TRACE_CLASS_MUTEX
477 #define TRACE_GET_MICRIUM_FLAG_TRACE_CLASS()       TRACE_CLASS_FLAG
478 #define TRACE_GET_MICRIUM_MEM_TRACE_CLASS()        TRACE_CLASS_MEM
479 
480 #define TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject) TRACE_GET_##CLASS##_TRACE_CLASS()
481 
482 /******************************
483 * MACROS TO GET OBJECT NUMBER *
484 ******************************/
485 #define TRACE_GET_TASK_NUMBER(pxTCB) ((traceHandle)prvTraceGetTaskNumberLow16(pxTCB))
486 #define TRACE_SET_TASK_NUMBER(pxTCB) prvTraceSetTaskNumberLow16(pxTCB, prvTraceGetObjectHandle(TRACE_CLASS_TASK))
487 
488 #define TRACE_GET_MICRIUM_TASK_MSG_Q_NUMBER(p_msg_q) ((traceHandle)prvTraceGetTaskQueueNumberLow16(p_msg_q))
489 #define TRACE_SET_MICRIUM_TASK_MSG_Q_NUMBER(p_msg_q) prvTraceSetTaskQueueNumberLow16(p_msg_q, prvTraceGetObjectHandle(TRACE_CLASS_TASK_Q))
490 
491 #define TRACE_GET_MICRIUM_TASK_SEM_NUMBER(p_tcb) ((traceHandle)prvTraceGetTaskSemNumberLow16(p_tcb))
492 #define TRACE_SET_MICRIUM_TASK_SEM_NUMBER(p_tcb) prvTraceSetTaskSemNumberLow16(p_tcb, prvTraceGetObjectHandle(TRACE_CLASS_TASK_SEM))
493 
494 #define TRACE_GET_MICRIUM_Q_NUMBER(p_q) ((traceHandle)prvTraceGetQueueNumberLow16(p_q))
495 #define TRACE_SET_MICRIUM_Q_NUMBER(p_q) prvTraceSetQueueNumberLow16(p_q, prvTraceGetObjectHandle(TRACE_CLASS_QUEUE))
496 
497 #define TRACE_GET_MICRIUM_SEM_NUMBER(p_sem) ((traceHandle)prvTraceGetSemaphoreNumberLow16(p_sem))
498 #define TRACE_SET_MICRIUM_SEM_NUMBER(p_sem) prvTraceSetSemaphoreNumberLow16(p_sem, prvTraceGetObjectHandle(TRACE_CLASS_SEMAPHORE))
499 
500 #define TRACE_GET_MICRIUM_MUTEX_NUMBER(p_mutex) ((traceHandle)prvTraceGetMutexNumberLow16(p_mutex))
501 #define TRACE_SET_MICRIUM_MUTEX_NUMBER(p_mutex) prvTraceSetMutexNumberLow16(p_mutex, prvTraceGetObjectHandle(TRACE_CLASS_MUTEX))
502 
503 #define TRACE_GET_MICRIUM_FLAG_NUMBER(p_grp) ((traceHandle)prvTraceGetFlagNumberLow16(p_grp))
504 #define TRACE_SET_MICRIUM_FLAG_NUMBER(p_grp) prvTraceSetFlagNumberLow16(p_grp, prvTraceGetObjectHandle(TRACE_CLASS_FLAG))
505 
506 #define TRACE_GET_MICRIUM_MEM_NUMBER(p_mem) ((traceHandle)prvTraceGetMemNumberLow16(p_mem))
507 #define TRACE_SET_MICRIUM_MEM_NUMBER(p_mem) prvTraceSetMemNumberLow16(p_mem, prvTraceGetObjectHandle(TRACE_CLASS_MEM))
508 
509 #define TRACE_GET_OBJECT_NUMBER(CLASS, pxObject) TRACE_GET_##CLASS##_NUMBER(pxObject)
510 #define TRACE_SET_OBJECT_NUMBER(CLASS, pxObject) TRACE_SET_##CLASS##_NUMBER(pxObject)
511 
512 /******************************
513 * MACROS FOR EVENT CODES      *
514 ******************************/
515 #define TRACE_GET_CLASS_EVENT_CODE(SERVICE, RESULT, CLASS, kernelClass) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_##CLASS##_TRACE_CLASS())
516 #define TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_##CLASS##_TRACE_CLASS())
517 #define TRACE_GET_TASK_EVENT_CODE(SERVICE, RESULT, CLASS, pxTCB) (EVENTGROUP_##SERVICE##_##RESULT + TRACE_CLASS_TASK)
518 
519 /******************************
520 * SPECIAL MACROS FOR TASKS    *
521 ******************************/
522 #define TRACE_GET_TASK_PRIORITY(pxTCB) ((uint8_t)pxTCB->Prio)              /* Prio is a field in OS_TCB (0: highest priority).     */
523 #define TRACE_GET_TASK_NAME(pxTCB) ((char*)pxTCB->NamePtr)                 /* NamePtr is a field in OS_TCB.                        */
524 
525 #define TRACE_MALLOC(size) pvPortMalloc(size)
526 
527 /*** The trace macros for snapshot mode **************************************/
528 
529 /* Called each time a task is created */
530 /* Critical section needed */
531 #undef OS_TRACE_TASK_CREATE
532 #if (OS_VERSION >= 30700u)
533 #define OS_TRACE_TASK_CREATE(p_tcb) \
534 	TRACE_ENTER_CRITICAL_SECTION(); \
535 	trcKERNEL_HOOKS_TASK_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, TASK, p_tcb), NOT_USED, p_tcb); \
536 	prvAddTaskToStackMonitor(p_tcb); \
537 	TRACE_EXIT_CRITICAL_SECTION();
538 #else /* (OS_VERSION >= 30700u) */
539 #define OS_TRACE_TASK_CREATE(p_tcb) \
540 	TRACE_ENTER_CRITICAL_SECTION(); \
541 	if (p_task == OS_TickTask) \
542 	{ \
543 		prvTrcTickTask = (void*)p_tcb; /* This is the Tick Task */ \
544 	} \
545 	trcKERNEL_HOOKS_TASK_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, TASK, p_tcb), NOT_USED, p_tcb); \
546 	prvAddTaskToStackMonitor(p_tcb); \
547 	TRACE_EXIT_CRITICAL_SECTION();
548 #endif /* (OS_VERSION >= 30700u) */
549 
550 /* Called each time a task gets deleted */
551 /* No critical section needed */
552 #undef OS_TRACE_TASK_DEL
553 #define OS_TRACE_TASK_DEL(p_tcb) \
554 	trcKERNEL_HOOKS_TASK_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, TASK, p_tcb), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, TASK, p_tcb), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, TASK, p_tcb), p_tcb); \
555 	prvRemoveTaskFromStackMonitor(p_tcb);
556 
557 /* Called on each task-switch-in */
558 /* No critical section needed */
559 #undef OS_TRACE_TASK_SWITCHED_IN
560 #define OS_TRACE_TASK_SWITCHED_IN(p_tcb) \
561 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
562 	{ \
563 		trcKERNEL_HOOKS_TASK_SWITCH(p_tcb); \
564 	}
565 
566 /* Called for each task that becomes ready */
567 /* No critical section needed */
568 #if (TRC_CFG_INCLUDE_READY_EVENTS == 1)
569 #undef OS_TRACE_TASK_READY
570 #define OS_TRACE_TASK_READY(p_tcb) \
571 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
572 	{ \
573 		trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(p_tcb); \
574 	}
575 #else /* (TRC_CFG_INCLUDE_READY_EVENTS == 1) */
576 #define OS_TRACE_TASK_READY(p_tcb)
577 #endif /* (TRC_CFG_INCLUDE_READY_EVENTS == 1) */
578 
579 /* Called on each OS tick. Will call uiPortGetTimestamp to make sure it is called at least once every OS tick. */
580 /* No critical section needed */
581 #if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)
582 #undef OS_TRACE_TICK_INCREMENT
583 #define OS_TRACE_TICK_INCREMENT(OSTickCtr) \
584 	if (OSRunning == 1) { trcKERNEL_HOOKS_NEW_TIME(DIV_NEW_TIME, OSTickCtr + 1); } \
585     else if (OSRunning == 0) { trcKERNEL_HOOKS_INCREMENT_TICK(); }
586 #else /* (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1) */
587 #define OS_TRACE_TICK_INCREMENT(OSTickCtr)
588 #endif /* (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1) */
589 
590 #if (TRC_CFG_SCHEDULING_ONLY == 0)
591 
592 #if (OS_VERSION < 30700u)
593 /* Called in OSTaskSuspend() */
594 /* Critical section needed. Also SR_ALLOC needed. */
595 #undef OS_TRACE_TASK_SUSPEND
596 #define OS_TRACE_TASK_SUSPEND(p_tcb) \
597 	{ \
598 		TRACE_ALLOC_CRITICAL_SECTION(); \
599 		TRACE_ENTER_CRITICAL_SECTION(); \
600 		if (p_tcb == 0) \
601 		{ \
602 			trcKERNEL_HOOKS_TASK_SUSPEND(TASK_SUSPEND, OSTCBCurPtr); \
603 		} \
604 		else \
605 		{ \
606 			trcKERNEL_HOOKS_TASK_SUSPEND(TASK_SUSPEND, p_tcb); \
607 		} \
608 		TRACE_EXIT_CRITICAL_SECTION(); \
609 	}
610 
611 #else /* (OS_VERSION < 30700u) */
612 /* Called in OSTaskSuspend() */
613 /* Critical section needed. Also SR_ALLOC needed. */
614 #undef OS_TRACE_TASK_SUSPEND_ENTER
615 #define OS_TRACE_TASK_SUSPEND_ENTER(p_tcb) \
616 	prvTraceTaskSuspendEnter(p_tcb);
617 
618 #undef OS_TRACE_TASK_SUSPEND_EXIT
619 #define OS_TRACE_TASK_SUSPEND_EXIT(p_err) \
620 	prvTraceTaskSuspendExit(p_err);
621 #endif /* (OS_VERSION < 30700u) */
622 
623 /* Called on any of the task delay functions */
624 /* No critical section needed */
625 #undef OS_TRACE_TASK_DLY
626 #define OS_TRACE_TASK_DLY(dly_ticks) \
627 	trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY, OSTCBCurPtr, dly_ticks); \
628 	trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
629 
630 /* Called each time a task gets deleted */
631 /* No critical section needed */
632 #undef OS_TRACE_TASK_SEM_DEL
633 #define OS_TRACE_TASK_SEM_DEL(p_tcb) \
634 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb);
635 
636 /* Called each time a task gets deleted */
637 /* No critical section needed */
638 #undef traceTASK_MSG_Q_DELETE
639 #define traceTASK_MSG_Q_DELETE(p_msg_q) \
640 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q);
641 
642 /* Called on OSSemDel */
643 /* No critical section needed */
644 #undef OS_TRACE_SEM_DEL
645 #define OS_TRACE_SEM_DEL(p_sem) \
646 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_SEM, p_sem), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_SEM, p_sem), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem);
647 
648 /* Called on OSQDel */
649 /* No critical section needed */
650 #undef OS_TRACE_Q_DEL
651 #define OS_TRACE_Q_DEL(p_q) \
652 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_Q, p_q), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_Q, p_q), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_Q, p_q), MICRIUM_Q, p_q);
653 
654 /* Called on OSMutexDel */
655 /* No critical section needed */
656 #undef OS_TRACE_MUTEX_DEL
657 #define OS_TRACE_MUTEX_DEL(p_mutex) \
658 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_MUTEX, p_mutex), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_MUTEX, p_mutex), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex);
659 
660 /* Called on OSFlagDel */
661 /* No critical section needed */
662 #undef OS_TRACE_FLAG_DEL
663 #define OS_TRACE_FLAG_DEL(p_grp) \
664 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_FLAG, p_grp), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_FLAG, p_grp), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp);
665 
666 /* Called on OSTaskDel */
667 /* No need to protect critical section. */
668 #undef OS_TRACE_TASK_SEM_DEL
669 #define OS_TRACE_TASK_SEM_DEL(p_tcb) \
670 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb);
671 
672 /* Called on OSTaskDel */
673 /* No need to protect critical section. */
674 #undef OS_TRACE_TASK_MSG_Q_DEL
675 #define OS_TRACE_TASK_MSG_Q_DEL(p_msg_q) \
676 	trcKERNEL_HOOKS_OBJECT_DELETE(TRACE_GET_OBJECT_EVENT_CODE(DELETE, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_NAME, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), TRACE_GET_OBJECT_EVENT_CODE(OBJCLOSE_PROP, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q);
677 
678 /* Called in OSTaskCreate, if it fails (typically if the stack can not be allocated) */
679 /* Need to protect critical section without reallocating the SR.                     */
680 #undef OS_TRACE_TASK_CREATE_FAILED
681 #define OS_TRACE_TASK_CREATE_FAILED(p_tcb) \
682 	TRACE_ENTER_CRITICAL_SECTION(); \
683 	trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(TRACE_GET_CLASS_EVENT_CODE(CREATE, TRCFAILED, TASK, NOT_USED), 0); \
684 	TRACE_EXIT_CRITICAL_SECTION();
685 
686 /* Called in OSTaskCreate, while it creates the built-in message queue */
687 /* Need to protect critical section without reallocating the SR.       */
688 #undef OS_TRACE_TASK_MSG_Q_CREATE
689 #define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name )\
690 	TRACE_ENTER_CRITICAL_SECTION(); \
691 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_TASK_MSG_Q, pxNewQueue), MICRIUM_TASK_MSG_Q, p_msg_q); \
692     prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_TASK_MSG_Q, p_msg_q), TRACE_GET_OBJECT_NUMBER(MICRIUM_TASK_MSG_Q, p_msg_q), prvTraceAppend(p_name, "Q")); \
693 	TRACE_EXIT_CRITICAL_SECTION();
694 
695 /* Called in OSTaskCreate, while it creates the built-in message queue */
696 /* Need to protect critical section without reallocating the SR.       */
697 #undef OS_TRACE_TASK_SEM_CREATE
698 #define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name )\
699 	TRACE_ENTER_CRITICAL_SECTION(); \
700 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb); \
701     prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_TASK_SEM, p_tcb), TRACE_GET_OBJECT_NUMBER(MICRIUM_TASK_SEM, p_tcb), prvTraceAppend(p_name, "Sem")); \
702 	TRACE_EXIT_CRITICAL_SECTION();
703 
704 /* No critical section needed */
705 #undef OS_TRACE_MUTEX_CREATE
706 #define OS_TRACE_MUTEX_CREATE(p_mutex, p_name )\
707 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex); \
708 	prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_MUTEX, p_mutex), TRACE_GET_OBJECT_NUMBER(MICRIUM_MUTEX, p_mutex), p_name);
709 
710 /* No critical section needed */
711 #undef OS_TRACE_SEM_CREATE
712 #define OS_TRACE_SEM_CREATE(p_sem, p_name )\
713 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem); \
714     prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_SEM, p_sem), TRACE_GET_OBJECT_NUMBER(MICRIUM_SEM, p_sem), p_name);
715 
716 /* No critical section needed */
717 #undef OS_TRACE_Q_CREATE
718 #define OS_TRACE_Q_CREATE(p_q, p_name )\
719 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_Q, p_q), MICRIUM_Q, p_q); \
720 	prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_Q, p_q), TRACE_GET_OBJECT_NUMBER(MICRIUM_Q, p_q), p_name);
721 
722 /* No critical section needed */
723 #undef OS_TRACE_FLAG_CREATE
724 #define OS_TRACE_FLAG_CREATE(p_grp, p_name )\
725 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp); \
726 	prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_FLAG, p_grp), TRACE_GET_OBJECT_NUMBER(MICRIUM_FLAG, p_grp), p_name);
727 
728 /* No critical section needed */
729 #undef OS_TRACE_MEM_CREATE
730 #define OS_TRACE_MEM_CREATE(p_mem, p_name )\
731 	trcKERNEL_HOOKS_OBJECT_CREATE(TRACE_GET_OBJECT_EVENT_CODE(CREATE, TRCSUCCESS, MICRIUM_MEM, p_mem), MICRIUM_MEM, p_mem); \
732 	prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(MICRIUM_MEM, p_mem), TRACE_GET_OBJECT_NUMBER(MICRIUM_MEM, p_mem), p_name);
733 
734 /* Called when a message is sent to a queue */
735 /* Critical section needed. Also SR_ALLOC needed. */
736 #undef OS_TRACE_TASK_MSG_Q_POST
737 #define OS_TRACE_TASK_MSG_Q_POST(p_msg_q) \
738 	{ \
739 		TRACE_ALLOC_CRITICAL_SECTION(); \
740 		TRACE_ENTER_CRITICAL_SECTION(); \
741 		if ((p_msg_q)->NbrEntries >= (p_msg_q)->NbrEntriesSize || OSMsgPool.NbrFree == 0u) \
742 		{ \
743 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q); \
744 		} \
745 		else \
746 		{ \
747 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q); \
748 			trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_TASK_MSG_Q, p_msg_q, (uint32_t)((p_msg_q)->NbrEntries)); \
749 		} \
750 		TRACE_EXIT_CRITICAL_SECTION(); \
751 	}
752 
753 /* No critical section needed */
754 #undef OS_TRACE_TASK_MSG_Q_POST_FAILED
755 #define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q) \
756 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q);
757 
758 /* Called when a signal is posted to a task semaphore (Post) */
759 /* Critical section needed. Also SR_ALLOC needed. */
760 #undef OS_TRACE_TASK_SEM_POST
761 #define OS_TRACE_TASK_SEM_POST(p_tcb) \
762 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
763 	{ \
764 		OS_TCB *trcPtr; \
765 		if (p_tcb == 0) \
766 		{ \
767 			trcPtr = OSTCBCurPtr; \
768 		} \
769 		else \
770 		{ \
771 			trcPtr = p_tcb; \
772 		} \
773 		TRACE_ALLOC_CRITICAL_SECTION(); \
774 		TRACE_ENTER_CRITICAL_SECTION(); \
775 		if (trcPtr->SemCtr == (OS_SEM_CTR)-1) \
776 		{ \
777 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_TASK_SEM, trcPtr), MICRIUM_TASK_SEM, trcPtr); \
778 		} \
779 		else \
780 		{ \
781 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_TASK_SEM, trcPtr), MICRIUM_TASK_SEM, trcPtr); \
782 			trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_TASK_SEM, trcPtr, (uint8_t)(trcPtr->SemCtr)); \
783 		} \
784 		TRACE_EXIT_CRITICAL_SECTION(); \
785 	}
786 
787 /* No critical section needed */
788 #undef OS_TRACE_TASK_SEM_POST_FAILED
789 #define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb) \
790 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
791 	{ \
792 		trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb); \
793 	}
794 
795 /* Called when a signal is posted to a semaphore (Post) */
796 /* Critical section needed. Also SR_ALLOC needed. */
797 #undef OS_TRACE_SEM_POST
798 #define OS_TRACE_SEM_POST(p_sem) \
799 	{ \
800 		TRACE_ALLOC_CRITICAL_SECTION(); \
801 		TRACE_ENTER_CRITICAL_SECTION(); \
802 		if (p_sem->Ctr == (OS_SEM_CTR)-1) \
803 		{ \
804 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem); \
805 		} \
806 		else \
807 		{ \
808 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem); \
809 			trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_SEM, p_sem, (uint8_t)(p_sem->Ctr)); \
810 		} \
811 		TRACE_EXIT_CRITICAL_SECTION(); \
812 	}
813 
814 /* No critical section needed */
815 #undef OS_TRACE_SEM_POST_FAILED
816 #define OS_TRACE_SEM_POST_FAILED(p_sem) \
817 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem);
818 
819 /* Called when a message is posted to a queue (Post) */
820 /* Critical section needed. Also SR_ALLOC needed. */
821 #undef OS_TRACE_Q_POST
822 #define OS_TRACE_Q_POST(p_q) \
823   { \
824 		TRACE_ALLOC_CRITICAL_SECTION(); \
825 		TRACE_ENTER_CRITICAL_SECTION(); \
826 		if (p_q->MsgQ.NbrEntries >= p_q->MsgQ.NbrEntriesSize || OSMsgPool.NbrFree == 0u) \
827 		{ \
828 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_Q, p_q), MICRIUM_Q, p_q); \
829 		} \
830 		else \
831 		{ \
832 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_Q, p_q), MICRIUM_Q, p_q); \
833 			trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_Q, p_q, (uint8_t)(p_q->PendList.NbrEntries)); \
834 		} \
835 		TRACE_EXIT_CRITICAL_SECTION(); \
836 	}
837 
838 /* No critical section needed */
839 #undef OS_TRACE_Q_POST_FAILED
840 #define OS_TRACE_Q_POST_FAILED(p_q) \
841 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_Q, p_q), MICRIUM_Q, p_q);
842 
843 /* Called when a signal is posted to a mutex (Post) */
844 /* No critical section needed */
845 #undef OS_TRACE_MUTEX_POST
846 #define OS_TRACE_MUTEX_POST(p_mutex) \
847 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex);
848 
849 /* No critical section needed */
850 #undef OS_TRACE_MUTEX_POST_FAILED
851 #define OS_TRACE_MUTEX_POST_FAILED(p_mutex) \
852 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex);
853 
854 /* Called when a signal is posted to a event flag group (Post) */
855 /* No critical section needed */
856 #undef OS_TRACE_FLAG_POST
857 #define OS_TRACE_FLAG_POST(p_grp) \
858 	switch (opt) \
859 	{ \
860 		case OS_OPT_POST_FLAG_SET: \
861 		case OS_OPT_POST_FLAG_SET | OS_OPT_POST_NO_SCHED: \
862 		case OS_OPT_POST_FLAG_CLR: \
863 		case OS_OPT_POST_FLAG_CLR | OS_OPT_POST_NO_SCHED: \
864 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp); \
865 			break; \
866 		default: \
867 			trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp); \
868 			break; \
869 	}
870 
871 /* No critical section needed */
872 #undef OS_TRACE_FLAG_POST_FAILED
873 #define OS_TRACE_FLAG_POST_FAILED(p_grp) \
874 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp);
875 
876 /* Called when a task or ISR returns a memory partition (put) */
877 /* Critical section needed */
878 #undef OS_TRACE_MEM_PUT
879 #define OS_TRACE_MEM_PUT(p_mem) \
880 	TRACE_ENTER_CRITICAL_SECTION(); \
881 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCSUCCESS, MICRIUM_MEM, p_mem), MICRIUM_MEM, p_mem); \
882 	trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_MEM, p_mem, (uint8_t)(p_mem->NbrFree)); \
883 	TRACE_EXIT_CRITICAL_SECTION();
884 
885 /* No critical section needed */
886 #undef OS_TRACE_MEM_PUT_FAILED
887 #define OS_TRACE_MEM_PUT_FAILED(p_mem) \
888 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(SEND, TRCFAILED, MICRIUM_MEM, p_mem), MICRIUM_MEM, p_mem);
889 
890 /* Called when a message is received from a task message queue */
891 /* Critical section needed */
892 #undef OS_TRACE_TASK_MSG_Q_PEND
893 #define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q) \
894 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q); \
895 	trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_TASK_MSG_Q, p_msg_q, (uint8_t)(p_msg_q->NbrEntries));
896 
897 /* No critical section needed */
898 #undef OS_TRACE_TASK_MSG_Q_PEND_FAILED
899 #define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q) \
900 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q);
901 
902 /* Called when a message is received from a task message queue */
903 /* No critical section needed */
904 #undef OS_TRACE_TASK_MSG_Q_PEND_BLOCK
905 #define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q) \
906 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, MICRIUM_TASK_MSG_Q, p_msg_q), MICRIUM_TASK_MSG_Q, p_msg_q); \
907 	trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
908 
909 /* Called when a task pends on a task semaphore (Pend)*/
910 /* No critical section needed */
911 #undef OS_TRACE_TASK_SEM_PEND
912 #define OS_TRACE_TASK_SEM_PEND(p_tcb) \
913 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
914 	{ \
915 		trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb); \
916 		trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_TASK_SEM, p_tcb, (uint8_t)(p_tcb->SemCtr)); \
917 	}
918 
919 /* No critical section needed */
920 #undef OS_TRACE_TASK_SEM_PEND_FAILED
921 #define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb) \
922 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
923 	{ \
924 		trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb); \
925 	}
926 
927 /* Called when a task pends and blocks on a task semaphore (Pend)*/
928 /* No critical section needed */
929 #undef OS_TRACE_TASK_SEM_PEND_BLOCK
930 #define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb) \
931 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
932 	{ \
933 		trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, MICRIUM_TASK_SEM, p_tcb), MICRIUM_TASK_SEM, p_tcb); \
934 		trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED(); \
935 	}
936 
937 /* Called when a task pends on a semaphore (Pend)*/
938 /* No critical section needed */
939 #undef OS_TRACE_SEM_PEND
940 #define OS_TRACE_SEM_PEND(p_sem) \
941 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem); \
942 	trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_SEM, p_sem, (uint8_t)(p_sem->Ctr));
943 
944 /* No critical section needed */
945 #undef OS_TRACE_SEM_PEND_FAILED
946 #define OS_TRACE_SEM_PEND_FAILED(p_sem) \
947 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem);
948 
949 /* Called when a task pends on a semaphore (Pend)*/
950 /* No critical section needed */
951 #undef OS_TRACE_SEM_PEND_BLOCK
952 #define OS_TRACE_SEM_PEND_BLOCK(p_sem) \
953 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, MICRIUM_SEM, p_sem), MICRIUM_SEM, p_sem); \
954 	trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
955 	//trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_SEM, p_sem, (uint8_t)(p_sem->Ctr)); \
956 
957 /* Called when a message is received from a message queue */
958 /* Critical section needed */
959 #undef OS_TRACE_Q_PEND
960 #define OS_TRACE_Q_PEND(p_q) \
961 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_Q, p_q), MICRIUM_Q, p_q); \
962 	trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_Q, p_q, (uint8_t)(p_q->PendList.NbrEntries));
963 
964 /* No critical section needed */
965 #undef OS_TRACE_Q_PEND_FAILED
966 #define OS_TRACE_Q_PEND_FAILED(p_q) \
967 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_Q, p_q), MICRIUM_Q, p_q);
968 
969 /* Called when a message is received from a message queue */
970 /* No critical section needed */
971 #undef OS_TRACE_Q_PEND_BLOCK
972 #define OS_TRACE_Q_PEND_BLOCK(p_q) \
973 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, MICRIUM_Q, p_q), MICRIUM_Q, p_q); \
974 	trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
975 //	trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_Q, p_q, (uint8_t)(p_q->PendList.NbrEntries)); \
976 
977 /* Called when a task pends on a mutex (Pend)*/
978 /* No critical section needed */
979 #undef OS_TRACE_MUTEX_PEND
980 #define OS_TRACE_MUTEX_PEND(p_mutex) \
981 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex);
982 
983 /* No critical section needed */
984 #undef OS_TRACE_MUTEX_PEND_FAILED
985 #define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) \
986 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex);
987 
988 /* Called when a task pends on a mutex (Pend)*/
989 /* No critical section needed */
990 #undef OS_TRACE_MUTEX_PEND_BLOCK
991 #define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) \
992 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, MICRIUM_MUTEX, p_mutex), MICRIUM_MUTEX, p_mutex);
993 
994 /* Called when a task pends on an event flag group (Pend)*/
995 /* No critical section needed */
996 #undef OS_TRACE_FLAG_PEND
997 #define OS_TRACE_FLAG_PEND(p_grp) \
998 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp);
999 
1000 /* No critical section needed */
1001 #undef OS_TRACE_FLAG_PEND_FAILED
1002 #define OS_TRACE_FLAG_PEND_FAILED(p_grp) \
1003 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp);
1004 
1005 /* Called when a task pends on an event flag group (Pend)*/
1006 /* No critical section needed */
1007 #undef OS_TRACE_FLAG_PEND_BLOCK
1008 #define OS_TRACE_FLAG_PEND_BLOCK(p_grp) \
1009 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCBLOCK, MICRIUM_FLAG, p_grp), MICRIUM_FLAG, p_grp); \
1010 	trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();
1011 
1012 /* Called when a task or ISR gets a memory partition */
1013 /* Critical section needed */
1014 #undef OS_TRACE_MEM_GET
1015 #define OS_TRACE_MEM_GET(p_mem) \
1016 	TRACE_ENTER_CRITICAL_SECTION(); \
1017 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCSUCCESS, MICRIUM_MEM, p_mem), MICRIUM_MEM, p_mem); \
1018 	trcKERNEL_HOOKS_SET_OBJECT_STATE(MICRIUM_MEM, p_mem, (uint8_t)(p_mem->NbrFree)); \
1019 	TRACE_EXIT_CRITICAL_SECTION();
1020 
1021 /* No critical section needed */
1022 #undef OS_TRACE_MEM_GET_FAILED
1023 #define OS_TRACE_MEM_GET_FAILED(p_mem) \
1024 	trcKERNEL_HOOKS_KERNEL_SERVICE(TRACE_GET_OBJECT_EVENT_CODE(RECEIVE, TRCFAILED, MICRIUM_MEM, p_mem), MICRIUM_MEM, p_mem);
1025 
1026 /* Called in OSTaskChangePrio */
1027 /* No critical section needed */
1028 #undef OS_TRACE_TASK_PRIO_CHANGE
1029 #define OS_TRACE_TASK_PRIO_CHANGE( pxTask, uxNewPriority ) \
1030 	trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(TASK_PRIORITY_SET, pxTask, uxNewPriority);
1031 
1032 /* Called in by mutex operations, when the task's priority is changed to the one from the mutex's owner */
1033 /* No critical section needed */
1034 #undef OS_TRACE_MUTEX_TASK_PRIO_INHERIT
1035 #define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio) \
1036 	trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(TASK_PRIORITY_INHERIT, p_tcb, prio);
1037 
1038 /* Called in by mutex operations, when the task's priority is changed back to its original */
1039 /* No critical section needed */
1040 #undef OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT
1041 #define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio) \
1042 	trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(TASK_PRIORITY_DISINHERIT, p_tcb, prio);
1043 
1044 #if (OS_VERSION < 30700u)
1045 /* Called in vTaskResume */
1046 /* No critical section needed */
1047 #undef OS_TRACE_TASK_RESUME
1048 #define OS_TRACE_TASK_RESUME(p_tcb) \
1049 	trcKERNEL_HOOKS_TASK_RESUME(TASK_RESUME, p_tcb);
1050 
1051 #else /* (OS_VERSION < 30700u) */
1052 /* Called in vTaskResume */
1053 /* Critical section needed */
1054 #undef OS_TRACE_TASK_RESUME_ENTER
1055 #define OS_TRACE_TASK_RESUME_ENTER(p_tcb) \
1056 	prvTraceTaskResumeEnter(p_tcb);
1057 
1058 #undef OS_TRACE_TASK_RESUME_EXIT
1059 #define OS_TRACE_TASK_RESUME_EXIT(p_err) \
1060 	prvTraceTaskResumeExit(p_err);
1061 #endif /* (OS_VERSION < 30700u) */
1062 
1063 #else /* (TRC_CFG_SCHEDULING_ONLY == 0) */
1064 
1065 /* SCHEDULING ONLY, DEFINE ALL AS EMPTY */
1066 
1067 #undef OS_TRACE_TASK_SUSPEND
1068 #define OS_TRACE_TASK_SUSPEND(p_tcb)
1069 
1070 #undef OS_TRACE_TASK_SUSPEND_ENTER
1071 #define OS_TRACE_TASK_SUSPEND_ENTER(p_tcb)
1072 
1073 #undef OS_TRACE_TASK_SUSPEND_EXIT
1074 #define OS_TRACE_TASK_SUSPEND_EXIT(p_err)
1075 
1076 #undef OS_TRACE_TASK_DLY
1077 #define OS_TRACE_TASK_DLY(dly_ticks)
1078 
1079 #undef OS_TRACE_TASK_SEM_DEL
1080 #define OS_TRACE_TASK_SEM_DEL(p_tcb)
1081 
1082 #undef traceTASK_MSG_Q_DELETE
1083 #define traceTASK_MSG_Q_DELETE(p_msg_q)
1084 
1085 #undef OS_TRACE_SEM_DEL
1086 #define OS_TRACE_SEM_DEL(p_sem)
1087 
1088 #undef OS_TRACE_Q_DEL
1089 #define OS_TRACE_Q_DEL(p_q)
1090 
1091 #undef OS_TRACE_MUTEX_DEL
1092 #define OS_TRACE_MUTEX_DEL(p_mutex)
1093 
1094 #undef OS_TRACE_FLAG_DEL
1095 #define OS_TRACE_FLAG_DEL(p_grp)
1096 
1097 #undef OS_TRACE_TASK_SEM_DEL
1098 #define OS_TRACE_TASK_SEM_DEL(p_tcb)
1099 
1100 #undef OS_TRACE_TASK_MSG_Q_DEL
1101 #define OS_TRACE_TASK_MSG_Q_DEL(p_msg_q)
1102 
1103 #undef OS_TRACE_TASK_CREATE_FAILED
1104 #define OS_TRACE_TASK_CREATE_FAILED(p_tcb)
1105 
1106 #undef OS_TRACE_TASK_MSG_Q_CREATE
1107 #define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name )
1108 
1109 #undef OS_TRACE_TASK_SEM_CREATE
1110 #define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name )
1111 
1112 #undef OS_TRACE_MUTEX_CREATE
1113 #define OS_TRACE_MUTEX_CREATE(p_mutex, p_name )
1114 
1115 #undef OS_TRACE_SEM_CREATE
1116 #define OS_TRACE_SEM_CREATE(p_sem, p_name )
1117 
1118 #undef OS_TRACE_Q_CREATE
1119 #define OS_TRACE_Q_CREATE(p_q, p_name )
1120 
1121 #undef OS_TRACE_FLAG_CREATE
1122 #define OS_TRACE_FLAG_CREATE(p_grp, p_name )
1123 
1124 #undef OS_TRACE_MEM_CREATE
1125 #define OS_TRACE_MEM_CREATE(p_mem, p_name )
1126 
1127 #undef OS_TRACE_TASK_MSG_Q_POST
1128 #define OS_TRACE_TASK_MSG_Q_POST(p_msg_q)
1129 
1130 #undef OS_TRACE_TASK_MSG_Q_POST_FAILED
1131 #define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q)
1132 
1133 #undef OS_TRACE_TASK_SEM_POST
1134 #define OS_TRACE_TASK_SEM_POST(p_tcb)
1135 
1136 #undef OS_TRACE_TASK_SEM_POST_FAILED
1137 #define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb)
1138 
1139 #undef OS_TRACE_SEM_POST
1140 #define OS_TRACE_SEM_POST(p_sem)
1141 
1142 #undef OS_TRACE_SEM_POST_FAILED
1143 #define OS_TRACE_SEM_POST_FAILED(p_sem)
1144 
1145 #undef OS_TRACE_Q_POST
1146 #define OS_TRACE_Q_POST(p_q)
1147 
1148 #undef OS_TRACE_Q_POST_FAILED
1149 #define OS_TRACE_Q_POST_FAILED(p_q)
1150 
1151 #undef OS_TRACE_MUTEX_POST
1152 #define OS_TRACE_MUTEX_POST(p_mutex)
1153 
1154 #undef OS_TRACE_MUTEX_POST_FAILED
1155 #define OS_TRACE_MUTEX_POST_FAILED(p_mutex)
1156 
1157 #undef OS_TRACE_FLAG_POST
1158 #define OS_TRACE_FLAG_POST(p_grp)
1159 
1160 #undef OS_TRACE_FLAG_POST_FAILED
1161 #define OS_TRACE_FLAG_POST_FAILED(p_grp)
1162 
1163 #undef OS_TRACE_MEM_PUT
1164 #define OS_TRACE_MEM_PUT(p_mem)
1165 
1166 #undef OS_TRACE_MEM_PUT_FAILED
1167 #define OS_TRACE_MEM_PUT_FAILED(p_mem)
1168 
1169 #undef OS_TRACE_TASK_MSG_Q_PEND
1170 #define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q)
1171 
1172 #undef OS_TRACE_TASK_MSG_Q_PEND_FAILED
1173 #define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q)
1174 
1175 #undef OS_TRACE_TASK_MSG_Q_PEND_BLOCK
1176 #define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q)
1177 
1178 #undef OS_TRACE_TASK_SEM_PEND
1179 #define OS_TRACE_TASK_SEM_PEND(p_tcb)
1180 
1181 #undef OS_TRACE_TASK_SEM_PEND_FAILED
1182 #define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb)
1183 
1184 #undef OS_TRACE_TASK_SEM_PEND_BLOCK
1185 #define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb)
1186 
1187 #undef OS_TRACE_SEM_PEND
1188 #define OS_TRACE_SEM_PEND(p_sem)
1189 
1190 #undef OS_TRACE_SEM_PEND_FAILED
1191 #define OS_TRACE_SEM_PEND_FAILED(p_sem)
1192 
1193 #undef OS_TRACE_SEM_PEND_BLOCK
1194 #define OS_TRACE_SEM_PEND_BLOCK(p_sem)
1195 
1196 #undef OS_TRACE_Q_PEND
1197 #define OS_TRACE_Q_PEND(p_q)
1198 
1199 #undef OS_TRACE_Q_PEND_FAILED
1200 #define OS_TRACE_Q_PEND_FAILED(p_q)
1201 
1202 #undef OS_TRACE_Q_PEND_BLOCK
1203 #define OS_TRACE_Q_PEND_BLOCK(p_q)
1204 
1205 #undef OS_TRACE_MUTEX_PEND
1206 #define OS_TRACE_MUTEX_PEND(p_mutex)
1207 
1208 #undef OS_TRACE_MUTEX_PEND_FAILED
1209 #define OS_TRACE_MUTEX_PEND_FAILED(p_mutex)
1210 
1211 #undef OS_TRACE_MUTEX_PEND_BLOCK
1212 #define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex)
1213 
1214 #undef OS_TRACE_FLAG_PEND
1215 #define OS_TRACE_FLAG_PEND(p_grp)
1216 
1217 #undef OS_TRACE_FLAG_PEND_FAILED
1218 #define OS_TRACE_FLAG_PEND_FAILED(p_grp)
1219 
1220 #undef OS_TRACE_FLAG_PEND_BLOCK
1221 #define OS_TRACE_FLAG_PEND_BLOCK(p_grp)
1222 
1223 #undef OS_TRACE_MEM_GET
1224 #define OS_TRACE_MEM_GET(p_mem)
1225 
1226 #undef OS_TRACE_MEM_GET_FAILED
1227 #define OS_TRACE_MEM_GET_FAILED(p_mem)
1228 
1229 #undef OS_TRACE_TASK_PRIO_CHANGE
1230 #define OS_TRACE_TASK_PRIO_CHANGE( pxTask, uxNewPriority )
1231 
1232 #undef OS_TRACE_MUTEX_TASK_PRIO_INHERIT
1233 #define OS_TRACE_MUTEX_TASK_PRIO_INHERIT(p_tcb, prio)
1234 
1235 #undef OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT
1236 #define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT(p_tcb, prio)
1237 
1238 #undef OS_TRACE_TASK_RESUME
1239 #define OS_TRACE_TASK_RESUME(p_tcb)
1240 
1241 #undef OS_TRACE_TASK_RESUME_ENTER
1242 #define OS_TRACE_TASK_RESUME_ENTER(p_tcb)
1243 
1244 #undef OS_TRACE_TASK_RESUME_EXIT
1245 #define OS_TRACE_TASK_RESUME_EXIT(p_err)
1246 
1247 #endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
1248 
1249 #undef OS_TRACE_ISR_REGISTER
1250 #define OS_TRACE_ISR_REGISTER(isr_id, isr_name, isr_prio) \
1251         vTraceSetISRProperties(isr_id, isr_name, isr_prio);
1252 
1253 #undef OS_TRACE_ISR_BEGIN
1254 #define OS_TRACE_ISR_BEGIN(isr_id) \
1255         vTraceStoreISRBegin(isr_id);
1256 
1257 #undef OS_TRACE_ISR_END
1258 #define OS_TRACE_ISR_END(flag) \
1259         vTraceStoreISREnd(flag);
1260 
1261 #define  OS_TRACE_ISR_ENTER()
1262 #define  OS_TRACE_ISR_EXIT()
1263 #define  OS_TRACE_ISR_EXIT_TO_SCHEDULER()
1264 
1265 #endif /*#if TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT */
1266 
1267 /******************************************************************************/
1268 /*** Definitions for Streaming mode *******************************************/
1269 /******************************************************************************/
1270 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
1271 
1272 #define  OS_TRACE_INIT()                                      vTraceEnable(TRC_INIT)
1273 #define  OS_TRACE_START()
1274 #define  OS_TRACE_STOP()
1275 #define  OS_TRACE_CLEAR()                                     vTraceClear()
1276 
1277 //#define  OS_TRACE_USR_EVT_CREATE(evt_name)                    Use xTraceRegisterString(evt_name) to create a traceString that can be used with vTracePrint() and vTracePrintF()
1278 //#define  OS_TRACE_USR_EVT_LOG(hnd)                            Use vTracePrint() instead
1279 //#define  OS_TRACE_PRINTF(hnd, format_str, ...)                Use vTracePrintF() instead
1280 
1281 /*******************************************************************************
1282 * vTraceStoreKernelObjectName
1283 *
1284 * Set the name for a kernel object (defined by its address).
1285 ******************************************************************************/
1286 void vTraceStoreKernelObjectName(void* object, const char* name);
1287 
1288 /*******************************************************************************
1289  * prvTraceOnBegin
1290  *
1291  * Called on trace begin.
1292  ******************************************************************************/
1293 void prvTraceOnBegin(void);
1294 
1295 /*******************************************************************************
1296  * prvTraceOnEnd
1297  *
1298  * Called on trace end.
1299  ******************************************************************************/
1300 void prvTraceOnEnd(void);
1301 
1302 /*************************************************************************/
1303 /* KERNEL SPECIFIC OBJECT CONFIGURATION									 */
1304 /*************************************************************************/
1305 
1306 /*******************************************************************************
1307  * The event codes - should match the offline config file.
1308  ******************************************************************************/
1309 
1310 #define PSF_EVENT_NULL_EVENT								0x00
1311 
1312 /* PSF event codes */
1313 #define PSF_EVENT_TRACE_START								0x01
1314 #define PSF_EVENT_TS_CONFIG									0x02
1315 #define PSF_EVENT_OBJ_NAME									0x03
1316 #define PSF_EVENT_TASK_PRIORITY								0x04
1317 #define PSF_EVENT_TASK_PRIO_INHERIT							0x05
1318 #define PSF_EVENT_TASK_PRIO_DISINHERIT						0x06
1319 #define PSF_EVENT_DEFINE_ISR								0x07
1320 #define PSF_EVENT_UNUSED_STACK								0x08
1321 
1322 #define PSF_EVENT_TASK_CREATE								0x10
1323 #define PSF_EVENT_TASK_SEM_CREATE							0x11
1324 #define PSF_EVENT_TASK_MSG_Q_CREATE							0x12
1325 #define PSF_EVENT_QUEUE_CREATE								0x13
1326 #define PSF_EVENT_SEMAPHORE_CREATE					        0x14
1327 #define PSF_EVENT_MUTEX_CREATE								0x15
1328 #define PSF_EVENT_FLAG_CREATE							    0x16
1329 #define PSF_EVENT_MEM_CREATE							    0x17
1330 #define PSF_EVENT_TMR_CREATE							    0x18
1331 
1332 #define PSF_EVENT_TASK_DELETE								0x20
1333 #define PSF_EVENT_QUEUE_DELETE								0x21
1334 #define PSF_EVENT_SEMAPHORE_DELETE							0x22
1335 #define PSF_EVENT_MUTEX_DELETE								0x23
1336 #define PSF_EVENT_FLAG_DELETE					   		    0x24
1337 #define PSF_EVENT_MEM_DELETE								0x25
1338 #define PSF_EVENT_TMR_DELETE								0x26
1339 #define PSF_EVENT_TASK_SEM_DELETE							0x27
1340 #define PSF_EVENT_TASK_MSG_Q_DELETE							0x28
1341 
1342 #define PSF_EVENT_TASK_READY								0x30
1343 #define PSF_EVENT_NEW_TIME									0x31
1344 #define PSF_EVENT_NEW_TIME_SCHEDULER_SUSPENDED				0x32
1345 #define PSF_EVENT_ISR_BEGIN									0x33
1346 #define PSF_EVENT_ISR_RESUME								0x34
1347 #define PSF_EVENT_TS_BEGIN									0x35
1348 #define PSF_EVENT_TS_RESUME									0x36
1349 #define PSF_EVENT_TASK_ACTIVATE								0x37
1350 
1351 #define PSF_EVENT_MALLOC									0x38
1352 #define PSF_EVENT_FREE										0x39
1353 
1354 #define PSF_EVENT_LOWPOWER_BEGIN							0x3A
1355 #define PSF_EVENT_LOWPOWER_END								0x3B
1356 
1357 #define PSF_EVENT_IFE_NEXT									0x3C
1358 #define PSF_EVENT_IFE_DIRECT								0x3D
1359 
1360 #define PSF_EVENT_TASK_CREATE_FAILED						0x40
1361 #define PSF_EVENT_QUEUE_CREATE_FAILED						0x41
1362 #define PSF_EVENT_SEMAPHORE_CREATE_FAILED			        0x42
1363 #define PSF_EVENT_MUTEX_CREATE_FAILED						0x43
1364 #define PSF_EVENT_FLAG_CREATE_FAILED						0x44
1365 #define PSF_EVENT_MEM_CREATE_FAILED					        0x45
1366 #define PSF_EVENT_TMR_CREATE_FAILED			                0x46
1367 
1368 #define PSF_EVENT_TASK_MSG_Q_SEND		    				0x50
1369 #define PSF_EVENT_TASK_SEM_SEND		    					0x51
1370 #define PSF_EVENT_SEM_SEND				        			0x52
1371 #define PSF_EVENT_Q_SEND		    						0x53
1372 #define PSF_EVENT_MUTEX_SEND								0x54
1373 #define PSF_EVENT_FLAG_SEND						    		0x55
1374 #define PSF_EVENT_MEM_SEND						    		0x56
1375 
1376 #define PSF_EVENT_TASK_MSG_Q_SEND_FAILED		    		0x57
1377 #define PSF_EVENT_TASK_SEM_SEND_FAILED		    			0x58
1378 #define PSF_EVENT_SEM_SEND_FAILED				        	0x59
1379 #define PSF_EVENT_Q_SEND_FAILED		    					0x5A
1380 #define PSF_EVENT_MUTEX_SEND_FAILED					    	0x5B
1381 #define PSF_EVENT_FLAG_SEND_FAILED					   		0x5C
1382 #define PSF_EVENT_MEM_SEND_FAILED					   		0x5D
1383 
1384 #define PSF_EVENT_TASK_MSG_Q_RECEIVE		   				0x60
1385 #define PSF_EVENT_TASK_SEM_RECEIVE		    				0x61
1386 #define PSF_EVENT_SEM_RECEIVE				       			0x62
1387 #define PSF_EVENT_Q_RECEIVE		    						0x63
1388 #define PSF_EVENT_MUTEX_RECEIVE								0x64
1389 #define PSF_EVENT_FLAG_RECEIVE					    		0x65
1390 #define PSF_EVENT_MEM_RECEIVE					    		0x66
1391 
1392 #define PSF_EVENT_TASK_MSG_Q_RECEIVE_FAILED		   			0x70
1393 #define PSF_EVENT_TASK_SEM_RECEIVE_FAILED		    		0x71
1394 #define PSF_EVENT_SEM_RECEIVE_FAILED		      			0x72
1395 #define PSF_EVENT_Q_RECEIVE_FAILED		    				0x73
1396 #define PSF_EVENT_MUTEX_RECEIVE_FAILED						0x74
1397 #define PSF_EVENT_FLAG_RECEIVE_FAILED			    		0x75
1398 #define PSF_EVENT_MEM_RECEIVE_FAILED			    		0x76
1399 
1400 #define PSF_EVENT_TASK_MSG_Q_RECEIVE_BLOCK		    		0x80
1401 #define PSF_EVENT_TASK_SEM_RECEIVE_BLOCK		    		0x81
1402 #define PSF_EVENT_SEM_RECEIVE_BLOCK				        	0x82
1403 #define PSF_EVENT_Q_RECEIVE_BLOCK		    				0x83
1404 #define PSF_EVENT_MUTEX_RECEIVE_BLOCK						0x84
1405 #define PSF_EVENT_FLAG_RECEIVE_BLOCK					  	0x85
1406 #define PSF_EVENT_MEM_RECEIVE_BLOCK				    		0x86
1407 
1408 #define PSF_EVENT_TASK_DELAY								0xAA
1409 #define PSF_EVENT_TASK_SUSPEND								0xAB
1410 #define PSF_EVENT_TASK_RESUME								0xAC
1411 #define PSF_EVENT_TASK_SUSPEND_FAILED						0xAD
1412 #define PSF_EVENT_TASK_RESUME_FAILED						0xAE
1413 
1414 #define PSF_EVENT_USER_EVENT								0xB4
1415 #define PSF_EVENT_USER_EVENT_2								0xB5
1416 #define PSF_EVENT_USER_EVENT_3								0xB6
1417 #define PSF_EVENT_USER_EVENT_4								0xB7
1418 #define PSF_EVENT_USER_EVENT_5								0xB8
1419 #define PSF_EVENT_USER_EVENT_6								0xB9
1420 #define PSF_EVENT_USER_EVENT_7								0xBA
1421 #define PSF_EVENT_USER_EVENT_8								0xBB
1422 
1423 /*** The trace macros for streaming ******************************************/
1424 
1425 /* Called in OSTaskCreate */
1426 /* Need to protect critical section without reallocating the SR.                     */
1427 #undef OS_TRACE_TASK_CREATE
1428 #if (OS_VERSION >= 30700u)
1429 #define OS_TRACE_TASK_CREATE(p_tcb) \
1430 	TRACE_ENTER_CRITICAL_SECTION(); \
1431     if (p_tcb != NULL) \
1432 	{ \
1433 		prvAddTaskToStackMonitor(p_tcb); \
1434 		prvTraceSaveObjectSymbol(p_tcb, (const char*)p_tcb->NamePtr); \
1435 		prvTraceSaveObjectData(p_tcb, p_tcb->Prio); \
1436 		prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, p_tcb->NamePtr, p_tcb); \
1437 		prvTraceStoreEvent2(PSF_EVENT_TASK_CREATE, (uint32_t)p_tcb, p_tcb->Prio); \
1438 	} \
1439 	TRACE_EXIT_CRITICAL_SECTION();
1440 #else /* (OS_VERSION >= 30700u) */
1441 #define OS_TRACE_TASK_CREATE(p_tcb) \
1442 	TRACE_ENTER_CRITICAL_SECTION(); \
1443     if (p_tcb != NULL) \
1444 	{ \
1445     	if (p_task == OS_TickTask) \
1446     	{ \
1447     		prvTrcTickTask = (void*)p_tcb; /* This is the Tick Task */ \
1448     	} \
1449 		prvAddTaskToStackMonitor(p_tcb); \
1450 		prvTraceSaveObjectSymbol(p_tcb, (const char*)p_tcb->NamePtr); \
1451 		prvTraceSaveObjectData(p_tcb, p_tcb->Prio); \
1452 		prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, p_tcb->NamePtr, p_tcb); \
1453 		prvTraceStoreEvent2(PSF_EVENT_TASK_CREATE, (uint32_t)p_tcb, p_tcb->Prio); \
1454 	} \
1455 	TRACE_EXIT_CRITICAL_SECTION();
1456 #endif /* (OS_VERSION >= 30700u) */
1457 
1458 /* Called in OSTaskCreate, if it fails (typically if the stack can not be allocated) */
1459 /* No need to protect critical section. */
1460 #undef OS_TRACE_TASK_CREATE_FAILED
1461 #define OS_TRACE_TASK_CREATE_FAILED(p_tcb) \
1462 	prvTraceStoreEvent0(PSF_EVENT_TASK_CREATE_FAILED);
1463 
1464 /* Called on OSTaskDel */
1465 /* No need to protect critical section. */
1466 /* If this macro give you problem try increase optimization. */
1467 #undef OS_TRACE_TASK_DEL
1468 #define OS_TRACE_TASK_DEL(p_tcb) \
1469 	prvTraceStoreEvent2(PSF_EVENT_TASK_DELETE, (uint32_t)p_tcb, p_tcb->Prio); \
1470 	prvTraceDeleteSymbol(p_tcb); \
1471 	prvTraceDeleteObjectData(p_tcb); \
1472 	prvRemoveTaskFromStackMonitor(p_tcb);
1473 
1474 /* Called for each task that becomes ready */
1475 /* No need to protect critical section. */
1476 #if (TRC_CFG_INCLUDE_READY_EVENTS == 1)
1477 #undef OS_TRACE_TASK_READY
1478 #define OS_TRACE_TASK_READY( p_tcb ) \
1479 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1480 	{ \
1481 		prvTraceStoreEvent1(PSF_EVENT_TASK_READY, (uint32_t)p_tcb); \
1482 	}
1483 #else /* (TRC_CFG_INCLUDE_READY_EVENTS == 1) */
1484 #define OS_TRACE_TASK_READY( p_tcb )
1485 #endif /* (TRC_CFG_INCLUDE_READY_EVENTS == 1) */
1486 
1487 /* Called on each OS tick. Will call uiPortGetTimestamp to make sure it is called at least once every OS tick. */
1488 /* No need to protect critical section. */
1489 #if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)
1490 #undef OS_TRACE_TICK_INCREMENT
1491 #define OS_TRACE_TICK_INCREMENT( OSTickCtr ) \
1492 	{ extern uint32_t uiTraceTickCount; uiTraceTickCount = OSTickCtr + 1; prvTraceStoreEvent1(PSF_EVENT_NEW_TIME, OSTickCtr + 1); }
1493 #else /* (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1) */
1494 #define OS_TRACE_TICK_INCREMENT( OSTickCtr )
1495 #endif /* (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1) */
1496 
1497 extern volatile uint32_t uiTraceSystemState;
1498 
1499 /* Called on each task-switch */
1500 /* No need to protect critical section. */
1501 #undef OS_TRACE_TASK_SWITCHED_IN
1502 #define OS_TRACE_TASK_SWITCHED_IN(p_tcb) \
1503 	uiTraceSystemState = TRC_STATE_IN_TASKSWITCH; \
1504 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1505 	{ \
1506 		if (prvIsNewTCB(p_tcb)) \
1507 		{ \
1508 			prvTraceStoreEvent2(PSF_EVENT_TASK_ACTIVATE, (uint32_t)p_tcb, p_tcb->Prio); \
1509 		} \
1510 	} \
1511 	uiTraceSystemState = TRC_STATE_IN_APPLICATION;
1512 
1513 #if (TRC_CFG_SCHEDULING_ONLY == 0)
1514 
1515 #if (OS_VERSION < 30700u)
1516 /* Called on OSTaskSuspend */
1517 /* No need to protect critical section. */
1518 #undef OS_TRACE_TASK_SUSPEND
1519 #define OS_TRACE_TASK_SUSPEND( p_tcb ) \
1520 	if (p_tcb == 0) \
1521 	{ \
1522 		prvTraceStoreEvent1(PSF_EVENT_TASK_SUSPEND, (uint32_t)OSTCBCurPtr); \
1523 	} \
1524 	else \
1525 	{ \
1526 		prvTraceStoreEvent1(PSF_EVENT_TASK_SUSPEND, (uint32_t)p_tcb); \
1527 	}
1528 #else /* (OS_VERSION < 30700u) */
1529 /* Called on OSTaskSuspend */
1530 /* Critical section needed to prevent variable to be overwritten. */
1531 #undef OS_TRACE_TASK_SUSPEND_ENTER
1532 #define OS_TRACE_TASK_SUSPEND_ENTER( p_tcb ) \
1533 	prvTraceTaskSuspendEnter(p_tcb);
1534 
1535 #undef OS_TRACE_TASK_SUSPEND_EXIT
1536 #define OS_TRACE_TASK_SUSPEND_EXIT(p_err) \
1537 	prvTraceTaskSuspendExit(p_err);
1538 #endif /* (OS_VERSION < 30700u) */
1539 
1540 #if (TRACE_CFG_USE_TICKLESS_IDLE != 0)
1541 
1542 /* NOT USED */
1543 /* No need to protect critical section. */
1544 #undef traceLOW_POWER_IDLE_BEGIN
1545 #define traceLOW_POWER_IDLE_BEGIN() \
1546 	prvTraceStoreEvent0(PSF_EVENT_LOWPOWER_BEGIN);
1547 
1548 /* NOT USED */
1549 /* No need to protect critical section. */
1550 #undef traceLOW_POWER_IDLE_END
1551 #define traceLOW_POWER_IDLE_END() \
1552 	prvTraceStoreEvent0(PSF_EVENT_LOWPOWER_END);
1553 
1554 #endif
1555 
1556 /* Called on OSTimeDly */
1557 /* No need to protect critical section. */
1558 #undef OS_TRACE_TASK_DLY
1559 #define OS_TRACE_TASK_DLY(dly_ticks) \
1560 	prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY, dly_ticks);
1561 
1562 /* Called on OSTaskDel */
1563 /* No need to protect critical section. */
1564 #undef OS_TRACE_TASK_MSG_Q_DEL
1565 #define OS_TRACE_TASK_MSG_Q_DEL(p_msg_q) \
1566 	prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_DELETE, (uint32_t)p_msg_q, (uint32_t)((p_msg_q)->NbrEntries)); \
1567 	prvTraceDeleteSymbol(p_msg_q);
1568 
1569 /* Called on OSTaskDel */
1570 /* No need to protect critical section. */
1571 #undef OS_TRACE_TASK_SEM_DEL
1572 #define OS_TRACE_TASK_SEM_DEL(p_tcb) \
1573 	prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_DELETE, (uint32_t)(&p_tcb->SemCtr), (uint32_t)(p_tcb->SemCtr)); \
1574 	prvTraceDeleteSymbol(&p_tcb->SemCtr);
1575 
1576 /* Called on OSQDel */
1577 /* No need to protect critical section. */
1578 #undef OS_TRACE_Q_DEL
1579 #define OS_TRACE_Q_DEL( p_q ) \
1580 	prvTraceStoreEvent2(PSF_EVENT_QUEUE_DELETE, (uint32_t)p_q, 0); \
1581 	prvTraceDeleteSymbol(p_q);
1582 
1583 /* Called on OSMutexDel */
1584 /* No need to protect critical section. */
1585 #undef OS_TRACE_MUTEX_DEL
1586 #define OS_TRACE_MUTEX_DEL( p_mutex ) \
1587 	prvTraceStoreEvent2(PSF_EVENT_MUTEX_DELETE, (uint32_t)p_mutex, 0); \
1588 	prvTraceDeleteSymbol(p_mutex);
1589 
1590 /* Called on OSSemDel */
1591 /* No need to protect critical section. */
1592 #undef OS_TRACE_SEM_DEL
1593 #define OS_TRACE_SEM_DEL( p_sem ) \
1594 	prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_DELETE, (uint32_t)p_sem, 0); \
1595 	prvTraceDeleteSymbol(p_sem);
1596 
1597 /* Called on OSFlagDel */
1598 /* No need to protect critical section. */
1599 #undef OS_TRACE_FLAG_DEL
1600 #define OS_TRACE_FLAG_DEL( p_grp ) \
1601 	prvTraceStoreEvent2(PSF_EVENT_FLAG_DELETE, (uint32_t)p_grp, 0); \
1602 	prvTraceDeleteSymbol(p_grp);
1603 
1604 /* Called in OSTaskCreate, while it creates the built-in message queue */
1605 /* Need to protect critical section without reallocating the SR.       */
1606 #undef OS_TRACE_TASK_MSG_Q_CREATE
1607 #define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name) \
1608 	TRACE_ENTER_CRITICAL_SECTION(); \
1609     if (p_msg_q != NULL) \
1610 	{ \
1611 		prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_CREATE, (uint32_t)p_msg_q, (uint32_t)(((OS_MSG_Q *)p_msg_q)->NbrEntries)); \
1612         vTraceStoreKernelObjectName(p_msg_q, prvTraceAppend((const char*)p_name, "Q")); \
1613 	} \
1614 	TRACE_EXIT_CRITICAL_SECTION();
1615 
1616 
1617 /* Called in OSTaskCreate, while it creates the built-in semaphore */
1618 /* Need to protect critical section without reallocating the SR.       */
1619 #undef OS_TRACE_TASK_SEM_CREATE
1620 #define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name) \
1621 	TRACE_ENTER_CRITICAL_SECTION(); \
1622     if (p_tcb) \
1623 	{ \
1624 		prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_CREATE, (uint32_t)(&p_tcb->SemCtr), p_tcb->SemCtr); \
1625         vTraceStoreKernelObjectName((void *)(&p_tcb->SemCtr), prvTraceAppend((const char*)p_name, "Sem")); \
1626 	} \
1627 	TRACE_EXIT_CRITICAL_SECTION();
1628 
1629 /* Called from os_q.c. */
1630 /* No need to protect critical section. */
1631 #undef OS_TRACE_Q_CREATE
1632 #define OS_TRACE_Q_CREATE(p_q, p_name ) \
1633 	prvTraceStoreEvent2(PSF_EVENT_QUEUE_CREATE, (uint32_t)p_q, p_q->MsgQ.NbrEntriesSize); \
1634 	vTraceStoreKernelObjectName(p_q, (const char*)p_name);
1635 
1636 /* Called from OSSemCreate. */
1637 /* No need to protect critical section. */
1638 #undef OS_TRACE_SEM_CREATE
1639 #define OS_TRACE_SEM_CREATE( p_sem, p_name) \
1640 	prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_CREATE, (uint32_t)p_sem, p_sem->Ctr); \
1641     vTraceStoreKernelObjectName(p_sem, (const char*)p_name);
1642 
1643 /* Called from OSMutexCreate. */
1644 /* No need to protect critical section. */
1645 #undef OS_TRACE_MUTEX_CREATE
1646 #define OS_TRACE_MUTEX_CREATE( p_mutex, p_name ) \
1647 	prvTraceStoreEvent1(PSF_EVENT_MUTEX_CREATE, (uint32_t)p_mutex); \
1648     vTraceStoreKernelObjectName(p_mutex, (const char*)p_name);
1649 
1650 /* Called from OSMemCreate. */
1651 /* No need to protect critical section. */
1652 #undef OS_TRACE_MEM_CREATE
1653 #define OS_TRACE_MEM_CREATE( p_mem, p_name ) \
1654 	prvTraceStoreEvent1(PSF_EVENT_MEM_CREATE, (uint32_t)p_mem); \
1655     vTraceStoreKernelObjectName(p_mem, (const char*)p_name);
1656 
1657 /* Called from OSFlagCreate. */
1658 /* No need to protect critical section. */
1659 #undef OS_TRACE_FLAG_CREATE
1660 #define OS_TRACE_FLAG_CREATE( p_grp, p_name ) \
1661 	prvTraceStoreEvent1(PSF_EVENT_FLAG_CREATE, (uint32_t)p_grp); \
1662     vTraceStoreKernelObjectName(p_grp, (const char*)p_name);
1663 
1664 /* Called when a message is sent to a task's queue */
1665 /* No need to protect critical section. */
1666 #undef OS_TRACE_TASK_MSG_Q_POST
1667 #define OS_TRACE_TASK_MSG_Q_POST(p_msg_q) \
1668 	if ((p_msg_q)->NbrEntries >= (p_msg_q)->NbrEntriesSize || OSMsgPool.NbrFree == 0u) \
1669 	{ \
1670 		prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_SEND_FAILED, (uint32_t)p_msg_q, (uint32_t)(((OS_MSG_Q *)p_msg_q)->NbrEntries)); \
1671 	} \
1672 	else \
1673 	{ \
1674 		prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_SEND, (uint32_t)p_msg_q, (uint32_t)(((OS_MSG_Q *)p_msg_q)->NbrEntries)); \
1675 	}
1676 
1677 /* Called when a message failed to be sent to a task's queue (timeout) */
1678 /* No need to protect critical section. */
1679 #undef OS_TRACE_TASK_MSG_Q_POST_FAILED
1680 #define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q) \
1681 	prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_SEND_FAILED, (uint32_t)p_msg_q, (uint32_t)(((OS_MSG_Q *)p_msg_q)->NbrEntries));
1682 
1683 /* Called when a message is sent to a task's semaphore */
1684 /* No need to protect critical section. */
1685 #undef OS_TRACE_TASK_SEM_POST
1686 #define OS_TRACE_TASK_SEM_POST(p_tcb) \
1687 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1688 	{ \
1689 		OS_TCB* trcPtr; \
1690 		if (p_tcb == 0) \
1691 		{ \
1692 			trcPtr = OSTCBCurPtr; \
1693 		} \
1694 		else \
1695 		{ \
1696 			trcPtr = p_tcb; \
1697 		} \
1698 		if (trcPtr->SemCtr == (OS_SEM_CTR)-1) \
1699 		{ \
1700 			prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_SEND_FAILED, (uint32_t)(&trcPtr->SemCtr), (uint8_t)(trcPtr->SemCtr)); \
1701 		} \
1702 		else \
1703 		{ \
1704 			prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_SEND, (uint32_t)(&trcPtr->SemCtr), (uint8_t)(trcPtr->SemCtr)); \
1705 		} \
1706 	}
1707 
1708 /* Called when a signal failed to be sent to a task's semaphore (timeout) */
1709 /* No need to protect critical section. */
1710 #undef OS_TRACE_TASK_SEM_POST_FAILED
1711 #define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb) \
1712 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1713 	{ \
1714 		prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_SEND_FAILED, (uint32_t)(&p_tcb->SemCtr), (uint8_t)(p_tcb->SemCtr)); \
1715 	}
1716 
1717 /* Called when a signal is sent to a queue */
1718 /* No need to protect critical section. */
1719 #undef OS_TRACE_Q_POST
1720 #define OS_TRACE_Q_POST(p_q) \
1721 	if (p_q->MsgQ.NbrEntries >= p_q->MsgQ.NbrEntriesSize || OSMsgPool.NbrFree == 0u) \
1722 	{ \
1723 		prvTraceStoreEvent2(PSF_EVENT_Q_SEND_FAILED, (uint32_t)p_q, (uint8_t)(p_q->PendList.NbrEntries)); \
1724 	} \
1725 	else \
1726 	{ \
1727 		prvTraceStoreEvent2(PSF_EVENT_Q_SEND, (uint32_t)p_q, (uint8_t)(p_q->PendList.NbrEntries)); \
1728 	}
1729 
1730 /* Called when a message failed to be sent to a queue (timeout) */
1731 /* No need to protect critical section. */
1732 #undef OS_TRACE_Q_POST_FAILED
1733 #define OS_TRACE_Q_POST_FAILED(p_q) \
1734 	prvTraceStoreEvent2(PSF_EVENT_Q_SEND_FAILED, (uint32_t)p_q, (uint8_t)(p_q->PendList.NbrEntries));
1735 
1736 /* Called when a signal is sent to a semaphore */
1737 /* No need to protect critical section. */
1738 #undef OS_TRACE_SEM_POST
1739 #define OS_TRACE_SEM_POST(p_sem) \
1740 	if (p_sem->Ctr == (OS_SEM_CTR)-1) \
1741 	{ \
1742 		prvTraceStoreEvent2(PSF_EVENT_SEM_SEND_FAILED, (uint32_t)p_sem, (uint8_t)(p_sem->Ctr)); \
1743 	} \
1744 	else \
1745 	{ \
1746 		prvTraceStoreEvent2(PSF_EVENT_SEM_SEND, (uint32_t)p_sem, (uint8_t)(p_sem->Ctr)); \
1747 	}
1748 
1749 /* Called when a signal failed to be sent to a semaphore (timeout) */
1750 /* No need to protect critical section. */
1751 #undef OS_TRACE_SEM_POST_FAILED
1752 #define OS_TRACE_SEM_POST_FAILED(p_tcb) \
1753 	prvTraceStoreEvent2(PSF_EVENT_SEM_SEND_FAILED, (uint32_t)p_sem, (uint8_t)(p_sem->Ctr));
1754 
1755 /* Called when a signal is sent to a mutex */
1756 /* No need to protect critical section. */
1757 #undef OS_TRACE_MUTEX_POST
1758 #define OS_TRACE_MUTEX_POST(p_mutex) \
1759 	prvTraceStoreEvent1(PSF_EVENT_MUTEX_SEND, (uint32_t)p_mutex);
1760 
1761 /* Called when a message failed to be sent to a mutex (timeout) */
1762 /* No need to protect critical section. */
1763 #undef OS_TRACE_MUTEX_POST_FAILED
1764 #define OS_TRACE_MUTEX_POST_FAILED(p_mutex) \
1765 	prvTraceStoreEvent1(PSF_EVENT_MUTEX_SEND_FAILED, (uint32_t)p_mutex);
1766 
1767 /* Called when a signal is sent to a flag group */
1768 /* No need to protect critical section. */
1769 #undef OS_TRACE_FLAG_POST
1770 #define OS_TRACE_FLAG_POST(p_grp) \
1771 	switch (opt) \
1772 	{ \
1773 		case OS_OPT_POST_FLAG_SET: \
1774 		case OS_OPT_POST_FLAG_SET | OS_OPT_POST_NO_SCHED: \
1775 		case OS_OPT_POST_FLAG_CLR: \
1776 		case OS_OPT_POST_FLAG_CLR | OS_OPT_POST_NO_SCHED: \
1777 			prvTraceStoreEvent1(PSF_EVENT_FLAG_SEND, (uint32_t)p_grp); \
1778 			break; \
1779 		default: \
1780 			prvTraceStoreEvent1(PSF_EVENT_FLAG_SEND_FAILED, (uint32_t)p_grp); \
1781 			break; \
1782 	}
1783 
1784 /* Called when a message failed to be sent to a flag group (timeout) */
1785 /* No need to protect critical section. */
1786 #undef OS_TRACE_FLAG_POST_FAILED
1787 #define OS_TRACE_FLAG_POST_FAILED(p_grp) \
1788 	prvTraceStoreEvent1(PSF_EVENT_FLAG_SEND_FAILED, (uint32_t)p_grp);
1789 
1790 /* Called when a signal is sent to a memory partition */
1791 /* No need to protect critical section. */
1792 #undef OS_TRACE_MEM_PUT
1793 #define OS_TRACE_MEM_PUT(p_mem) \
1794 	prvTraceStoreEvent2(PSF_EVENT_MEM_SEND, (uint32_t)p_mem, (uint8_t)(p_mem->NbrFree));
1795 
1796 /* Called when a message failed to be sent to a memory partition (timeout) */
1797 /* No need to protect critical section. */
1798 #undef OS_TRACE_MEM_PUT_FAILED
1799 #define OS_TRACE_MEM_PUT_FAILED(p_mem) \
1800 	prvTraceStoreEvent1(PSF_EVENT_MEM_SEND_FAILED, (uint32_t)p_mem);
1801 
1802 
1803 /* Called when a message is received from a task message queue */
1804 /* No need to protect critical section. */
1805 #undef OS_TRACE_TASK_MSG_Q_PEND
1806 #define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q) \
1807 	prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_RECEIVE, (uint32_t)p_msg_q, (uint8_t)(p_msg_q->NbrEntries));
1808 
1809 /* Called when a message is received from a task message queue */
1810 /* No need to protect critical section. */
1811 #undef OS_TRACE_TASK_MSG_Q_PEND_FAILED
1812 #define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q) \
1813 	prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_RECEIVE_FAILED, (uint32_t)p_msg_q, (uint8_t)(p_msg_q->NbrEntries));
1814 
1815 /* Called when a message is received from a task message queue */
1816 /* No need to protect critical section. */
1817 #undef OS_TRACE_TASK_MSG_Q_PEND_BLOCK
1818 #define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q) \
1819 	prvTraceStoreEvent2(PSF_EVENT_TASK_MSG_Q_RECEIVE_BLOCK, (uint32_t)p_msg_q, (uint8_t)(p_msg_q->NbrEntries));
1820 
1821 /* Called when a message is received from a task semaphore */
1822 /* No need to protect critical section. */
1823 #undef OS_TRACE_TASK_SEM_PEND
1824 #define OS_TRACE_TASK_SEM_PEND(p_tcb) \
1825 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1826 	{ \
1827 		prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_RECEIVE, (uint32_t)(&p_tcb->SemCtr), (uint8_t)(p_tcb->SemCtr)); \
1828 	}
1829 
1830 /* Called when a message is received from a task semaphore */
1831 /* No need to protect critical section. */
1832 #undef OS_TRACE_TASK_SEM_PEND_FAILED
1833 #define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb) \
1834 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1835 	{ \
1836 		prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_RECEIVE_FAILED, (uint32_t)(&p_tcb->SemCtr), (uint8_t)(p_tcb->SemCtr)); \
1837 	}
1838 
1839 /* Called when a message is received from a task semaphore */
1840 /* No need to protect critical section. */
1841 #undef OS_TRACE_TASK_SEM_PEND_BLOCK
1842 #define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb) \
1843 	TRACE_IF_NOT_TICK_TASK(p_tcb) \
1844 	{ \
1845 		prvTraceStoreEvent2(PSF_EVENT_TASK_SEM_RECEIVE_BLOCK, (uint32_t)(&p_tcb->SemCtr), (uint8_t)(p_tcb->SemCtr)); \
1846 	}
1847 
1848 /* Called when a message is received from a semaphore */
1849 /* No need to protect critical section. */
1850 #undef OS_TRACE_SEM_PEND
1851 #define OS_TRACE_SEM_PEND(p_sem) \
1852 	prvTraceStoreEvent2(PSF_EVENT_SEM_RECEIVE, (uint32_t)p_sem, (uint8_t)(p_sem->Ctr));
1853 
1854 /* Called when a message is received from a semaphore */
1855 /* No need to protect critical section. */
1856 #undef OS_TRACE_SEM_PEND_FAILED
1857 #define OS_TRACE_SEM_PEND_FAILED(p_sem) \
1858 	prvTraceStoreEvent2(PSF_EVENT_SEM_RECEIVE_FAILED, (uint32_t)p_sem, (uint8_t)(p_sem->Ctr));
1859 
1860 /* Called when a message is received from a semaphore */
1861 /* No need to protect critical section. */
1862 #undef OS_TRACE_SEM_PEND_BLOCK
1863 #define OS_TRACE_SEM_PEND_BLOCK(p_sem) \
1864 	prvTraceStoreEvent2(PSF_EVENT_SEM_RECEIVE_BLOCK, (uint32_t)p_sem, (uint8_t)(p_sem->Ctr));
1865 
1866 
1867 /* Called when a message is received from a queue */
1868 /* No need to protect critical section. */
1869 #undef OS_TRACE_Q_PEND
1870 #define OS_TRACE_Q_PEND(p_q) \
1871 	prvTraceStoreEvent2(PSF_EVENT_Q_RECEIVE, (uint32_t)p_q, (uint8_t)(p_q->PendList.NbrEntries));
1872 
1873 /* Called when a message is received from a queue */
1874 /* No need to protect critical section. */
1875 #undef OS_TRACE_Q_PEND_FAILED
1876 #define OS_TRACE_Q_PEND_FAILED(p_q) \
1877 	prvTraceStoreEvent2(PSF_EVENT_Q_RECEIVE_FAILED, (uint32_t)p_q, (uint8_t)(p_q->PendList.NbrEntries));
1878 
1879 /* Called when a message is received from a queue */
1880 /* No need to protect critical section. */
1881 #undef OS_TRACE_Q_PEND_BLOCK
1882 #define OS_TRACE_Q_PEND_BLOCK(p_q) \
1883 	prvTraceStoreEvent2(PSF_EVENT_Q_RECEIVE_BLOCK, (uint32_t)p_q, (uint8_t)(p_q->PendList.NbrEntries));
1884 
1885 
1886 /* Called when a signal is received from a mutex */
1887 /* No need to protect critical section. */
1888 #undef OS_TRACE_MUTEX_PEND
1889 #define OS_TRACE_MUTEX_PEND(p_mutex) \
1890 	prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECEIVE, (uint32_t)p_mutex);
1891 
1892 /* Called when a signal is received from a mutex */
1893 /* No need to protect critical section. */
1894 #undef OS_TRACE_MUTEX_PEND_FAILED
1895 #define OS_TRACE_MUTEX_PEND_FAILED(p_mutex) \
1896 	prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECEIVE_FAILED, (uint32_t)p_mutex);
1897 
1898 /* Called when a signal is received from a mutex */
1899 /* No need to protect critical section. */
1900 #undef OS_TRACE_MUTEX_PEND_BLOCK
1901 #define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex) \
1902 	prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECEIVE_BLOCK, (uint32_t)p_mutex);
1903 
1904 
1905 /* Called when a signal is received from a flag group */
1906 /* No need to protect critical section. */
1907 #undef OS_TRACE_FLAG_PEND
1908 #define OS_TRACE_FLAG_PEND(p_grp) \
1909 	prvTraceStoreEvent1(PSF_EVENT_FLAG_RECEIVE, (uint32_t)p_grp);
1910 
1911 /* Called when a signal is received from a flag group */
1912 /* No need to protect critical section. */
1913 #undef OS_TRACE_FLAG_PEND_FAILED
1914 #define OS_TRACE_FLAG_PEND_FAILED(p_grp) \
1915 	prvTraceStoreEvent1(PSF_EVENT_FLAG_RECEIVE_FAILED, (uint32_t)p_grp);
1916 
1917 /* Called when a signal is received from a flag group */
1918 /* No need to protect critical section. */
1919 #undef OS_TRACE_FLAG_PEND_BLOCK
1920 #define OS_TRACE_MEM_GET_FAILED(p_mem) \
1921 	prvTraceStoreEvent2(PSF_EVENT_MEM_RECEIVE_FAILED, (uint32_t)p_mem, (uint8_t)(p_mem->NbrFree));
1922 
1923 /* Called in OSTaskChangePrio */
1924 #undef OS_TRACE_TASK_PRIO_CHANGE
1925 #define OS_TRACE_TASK_PRIO_CHANGE( p_tcb, prio ) \
1926 	prvTraceStoreEvent2(PSF_EVENT_TASK_PRIORITY, (uint32_t)p_tcb, prio);
1927 
1928 /* Called in by mutex operations, when the task's priority is changed to the one from the mutex's owner */
1929 /* No need to protect critical section. */
1930 #undef OS_TRACE_MUTEX_TASK_PRIO_INHERIT
1931 #define OS_TRACE_MUTEX_TASK_PRIO_INHERIT( p_tcb, prio ) \
1932 	prvTraceStoreEvent2(PSF_EVENT_TASK_PRIO_INHERIT, (uint32_t)p_tcb, prio);
1933 
1934 /* Called in by mutex operations, when the task's priority is changed back to its original */
1935 /* No need to protect critical section. */
1936 #undef OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT
1937 #define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT( p_tcb, prio ) \
1938 	prvTraceStoreEvent2(PSF_EVENT_TASK_PRIO_DISINHERIT, (uint32_t)p_tcb, prio);
1939 
1940 #if (OS_VERSION < 30700u)
1941 /* Called in OSTaskResume */
1942 /* No need to protect critical section. */
1943 #undef OS_TRACE_TASK_RESUME
1944 #define OS_TRACE_TASK_RESUME( p_tcb ) \
1945 	prvTraceStoreEvent1(PSF_EVENT_TASK_RESUME, (uint32_t)p_tcb);
1946 
1947 #else /* (OS_VERSION < 30700u) */
1948 /* Called in OSTaskResume */
1949 /* Critical section needed to prevent variable to be overwritten. */
1950 #undef OS_TRACE_TASK_RESUME_ENTER
1951 #define OS_TRACE_TASK_RESUME_ENTER( p_tcb )\
1952 	prvTraceTaskResumeEnter(p_tcb);
1953 
1954 #undef OS_TRACE_TASK_RESUME_EXIT
1955 #define OS_TRACE_TASK_RESUME_EXIT( p_err )\
1956 	prvTraceTaskResumeExit(p_err);
1957 #endif /* (OS_VERSION < 30700u) */
1958 
1959 #else /* (TRC_CFG_SCHEDULING_ONLY == 0) */
1960 
1961 /* SCHEDULING ONLY, DEFINE ALL AS EMPTY */
1962 
1963 #undef OS_TRACE_TASK_SUSPEND
1964 #define OS_TRACE_TASK_SUSPEND( p_tcb )
1965 
1966 #undef OS_TRACE_TASK_SUSPEND_ENTER
1967 #define OS_TRACE_TASK_SUSPEND_ENTER( p_tcb )
1968 
1969 #undef OS_TRACE_TASK_SUSPEND_EXIT
1970 #define OS_TRACE_TASK_SUSPEND_EXIT(p_err)
1971 
1972 #undef traceLOW_POWER_IDLE_BEGIN
1973 #define traceLOW_POWER_IDLE_BEGIN()
1974 
1975 #undef traceLOW_POWER_IDLE_END
1976 #define traceLOW_POWER_IDLE_END()
1977 
1978 #undef OS_TRACE_TASK_DLY
1979 #define OS_TRACE_TASK_DLY(dly_ticks)
1980 
1981 #undef OS_TRACE_TASK_MSG_Q_DEL
1982 #define OS_TRACE_TASK_MSG_Q_DEL(p_msg_q)
1983 
1984 #undef OS_TRACE_TASK_SEM_DEL
1985 #define OS_TRACE_TASK_SEM_DEL(p_tcb)
1986 
1987 #undef OS_TRACE_Q_DEL
1988 #define OS_TRACE_Q_DEL( p_q )
1989 
1990 #undef OS_TRACE_MUTEX_DEL
1991 #define OS_TRACE_MUTEX_DEL( p_mutex )
1992 
1993 #undef OS_TRACE_SEM_DEL
1994 #define OS_TRACE_SEM_DEL( p_sem )
1995 
1996 #undef OS_TRACE_FLAG_DEL
1997 #define OS_TRACE_FLAG_DEL( p_grp )
1998 
1999 #undef OS_TRACE_TASK_MSG_Q_CREATE
2000 #define OS_TRACE_TASK_MSG_Q_CREATE(p_msg_q, p_name)
2001 
2002 #undef OS_TRACE_TASK_SEM_CREATE
2003 #define OS_TRACE_TASK_SEM_CREATE(p_tcb, p_name)
2004 
2005 #undef OS_TRACE_Q_CREATE
2006 #define OS_TRACE_Q_CREATE(p_q, p_name )
2007 
2008 #undef OS_TRACE_SEM_CREATE
2009 #define OS_TRACE_SEM_CREATE( p_sem, p_name)
2010 
2011 #undef OS_TRACE_MUTEX_CREATE
2012 #define OS_TRACE_MUTEX_CREATE( p_mutex, p_name )
2013 
2014 #undef OS_TRACE_MEM_CREATE
2015 #define OS_TRACE_MEM_CREATE( p_mem, p_name )
2016 
2017 #undef OS_TRACE_FLAG_CREATE
2018 #define OS_TRACE_FLAG_CREATE( p_grp, p_name )
2019 
2020 #undef OS_TRACE_TASK_MSG_Q_POST
2021 #define OS_TRACE_TASK_MSG_Q_POST(p_msg_q)
2022 
2023 #undef OS_TRACE_TASK_MSG_Q_POST_FAILED
2024 #define OS_TRACE_TASK_MSG_Q_POST_FAILED(p_msg_q)
2025 
2026 #undef OS_TRACE_TASK_SEM_POST
2027 #define OS_TRACE_TASK_SEM_POST(p_tcb)
2028 
2029 #undef OS_TRACE_TASK_SEM_POST_FAILED
2030 #define OS_TRACE_TASK_SEM_POST_FAILED(p_tcb)
2031 
2032 #undef OS_TRACE_Q_POST
2033 #define OS_TRACE_Q_POST(p_q)
2034 
2035 #undef OS_TRACE_Q_POST_FAILED
2036 #define OS_TRACE_Q_POST_FAILED(p_q)
2037 
2038 #undef OS_TRACE_SEM_POST
2039 #define OS_TRACE_SEM_POST(p_sem)
2040 
2041 #undef OS_TRACE_SEM_POST_FAILED
2042 #define OS_TRACE_SEM_POST_FAILED(p_tcb)
2043 
2044 #undef OS_TRACE_MUTEX_POST
2045 #define OS_TRACE_MUTEX_POST(p_mutex)
2046 
2047 #undef OS_TRACE_MUTEX_POST_FAILED
2048 #define OS_TRACE_MUTEX_POST_FAILED(p_mutex)
2049 
2050 #undef OS_TRACE_FLAG_POST
2051 #define OS_TRACE_FLAG_POST(p_grp)
2052 
2053 #undef OS_TRACE_FLAG_POST_FAILED
2054 #define OS_TRACE_FLAG_POST_FAILED(p_grp)
2055 
2056 #undef OS_TRACE_MEM_PUT
2057 #define OS_TRACE_MEM_PUT(p_mem)
2058 
2059 #undef OS_TRACE_MEM_PUT_FAILED
2060 #define OS_TRACE_MEM_PUT_FAILED(p_mem)
2061 
2062 #undef OS_TRACE_TASK_MSG_Q_PEND
2063 #define OS_TRACE_TASK_MSG_Q_PEND(p_msg_q)
2064 
2065 #undef OS_TRACE_TASK_MSG_Q_PEND_FAILED
2066 #define OS_TRACE_TASK_MSG_Q_PEND_FAILED(p_msg_q)
2067 
2068 #undef OS_TRACE_TASK_MSG_Q_PEND_BLOCK
2069 #define OS_TRACE_TASK_MSG_Q_PEND_BLOCK(p_msg_q)
2070 
2071 #undef OS_TRACE_TASK_SEM_PEND
2072 #define OS_TRACE_TASK_SEM_PEND(p_tcb)
2073 
2074 #undef OS_TRACE_TASK_SEM_PEND_FAILED
2075 #define OS_TRACE_TASK_SEM_PEND_FAILED(p_tcb)
2076 
2077 #undef OS_TRACE_TASK_SEM_PEND_BLOCK
2078 #define OS_TRACE_TASK_SEM_PEND_BLOCK(p_tcb)
2079 
2080 #undef OS_TRACE_SEM_PEND
2081 #define OS_TRACE_SEM_PEND(p_sem)
2082 
2083 #undef OS_TRACE_SEM_PEND_FAILED
2084 #define OS_TRACE_SEM_PEND_FAILED(p_sem)
2085 
2086 #undef OS_TRACE_SEM_PEND_BLOCK
2087 #define OS_TRACE_SEM_PEND_BLOCK(p_sem)
2088 
2089 #undef OS_TRACE_Q_PEND
2090 #define OS_TRACE_Q_PEND(p_q)
2091 
2092 #undef OS_TRACE_Q_PEND_FAILED
2093 #define OS_TRACE_Q_PEND_FAILED(p_q)
2094 
2095 #undef OS_TRACE_Q_PEND_BLOCK
2096 #define OS_TRACE_Q_PEND_BLOCK(p_q)
2097 
2098 #undef OS_TRACE_MUTEX_PEND
2099 #define OS_TRACE_MUTEX_PEND(p_mutex)
2100 
2101 #undef OS_TRACE_MUTEX_PEND_FAILED
2102 #define OS_TRACE_MUTEX_PEND_FAILED(p_mutex)
2103 
2104 #undef OS_TRACE_MUTEX_PEND_BLOCK
2105 #define OS_TRACE_MUTEX_PEND_BLOCK(p_mutex)
2106 
2107 #undef OS_TRACE_FLAG_PEND
2108 #define OS_TRACE_FLAG_PEND(p_grp)
2109 
2110 #undef OS_TRACE_FLAG_PEND_FAILED
2111 #define OS_TRACE_FLAG_PEND_FAILED(p_grp)
2112 
2113 #undef OS_TRACE_FLAG_PEND_BLOCK
2114 #define OS_TRACE_MEM_GET_FAILED(p_mem)
2115 
2116 #undef OS_TRACE_TASK_PRIO_CHANGE
2117 #define OS_TRACE_TASK_PRIO_CHANGE( p_tcb, prio )
2118 
2119 #undef OS_TRACE_MUTEX_TASK_PRIO_INHERIT
2120 #define OS_TRACE_MUTEX_TASK_PRIO_INHERIT( p_tcb, prio )
2121 
2122 #undef OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT
2123 #define OS_TRACE_MUTEX_TASK_PRIO_DISINHERIT( p_tcb, prio )
2124 
2125 #undef OS_TRACE_TASK_RESUME
2126 #define OS_TRACE_TASK_RESUME( p_tcb )
2127 
2128 #undef OS_TRACE_TASK_RESUME_ENTER
2129 #define OS_TRACE_TASK_RESUME_ENTER( p_tcb )
2130 
2131 #undef OS_TRACE_TASK_RESUME_EXIT
2132 #define OS_TRACE_TASK_RESUME_EXIT( p_err )
2133 
2134 #endif /* (TRC_CFG_SCHEDULING_ONLY == 0) */
2135 
2136 #undef OS_TRACE_ISR_REGISTER
2137 #define OS_TRACE_ISR_REGISTER(isr_name, isr_prio) \
2138 	vTraceSetISRProperties(isr_name, isr_prio);
2139 
2140 #undef OS_TRACE_ISR_BEGIN
2141 #define OS_TRACE_ISR_BEGIN(isr_name) \
2142 	vTraceStoreISRBegin(isr_name);
2143 
2144 #undef OS_TRACE_ISR_END
2145 #define OS_TRACE_ISR_END(flag) \
2146 	vTraceStoreISREnd(flag);
2147 
2148 #define  OS_TRACE_ISR_ENTER()
2149 #define  OS_TRACE_ISR_EXIT()
2150 #define  OS_TRACE_ISR_EXIT_TO_SCHEDULER()
2151 
2152 #endif /*TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING*/
2153 
2154 #else /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
2155 
2156 #define vTraceExcludeQueue(handle)
2157 #define vTraceExcludeSemaphore(handle)
2158 #define vTraceExcludeMutex(handle)
2159 #define vTraceExcludeTimer(handle)
2160 #define vTraceExcludeEventGroup(handle)
2161 #define vTraceExcludeDelays()
2162 
2163 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
2164 
2165 #ifdef __cplusplus
2166 }
2167 #endif
2168 
2169 #endif /* TRC_KERNEL_PORT_H */
2170