1 /*******************************************************************************
\r
2 * FreeRTOS+Trace v2.2.3 Recorder Library
\r
3 * Percepio AB, www.percepio.se
\r
7 * Functions used by trcHooks.h, for the FreeRTOS kernel integration.
\r
10 * This software is copyright Percepio AB. The recorder library is free for
\r
11 * use together with Percepio products. You may distribute the recorder library
\r
12 * in its original form, including modifications in trcPort.c and trcPort.h
\r
13 * given that these modification are clearly marked as your own modifications
\r
14 * and documented in the initial comment section of these source files.
\r
15 * This software is the intellectual property of Percepio AB and may not be
\r
16 * sold or in other ways commercially redistributed without explicit written
\r
17 * permission by Percepio AB.
\r
20 * The trace tool and recorder library is being delivered to you AS IS and
\r
21 * Percepio AB makes no warranty as to its use or performance. Percepio AB does
\r
22 * not and cannot warrant the performance or results you may obtain by using the
\r
23 * software or documentation. Percepio AB make no warranties, express or
\r
24 * implied, as to noninfringement of third party rights, merchantability, or
\r
25 * fitness for any particular purpose. In no event will Percepio AB, its
\r
26 * technology partners, or distributors be liable to you for any consequential,
\r
27 * incidental or special damages, including any lost profits or lost savings,
\r
28 * even if a representative of Percepio AB has been advised of the possibility
\r
29 * of such damages, or for any claim by any third party. Some jurisdictions do
\r
30 * not allow the exclusion or limitation of incidental, consequential or special
\r
31 * damages, or the exclusion of implied warranties or limitations on how long an
\r
32 * implied warranty may last, so the above limitations may not apply to you.
\r
34 * FreeRTOS+Trace is available as Free Edition and in two premium editions.
\r
35 * You may use the premium features during 30 days for evaluation.
\r
36 * Download FreeRTOS+Trace at http://www.percepio.se/index.php?page=downloads
\r
38 * Copyright Percepio AB, 2012.
\r
40 ******************************************************************************/
\r
45 #include "trcTypes.h"
\r
47 #if (configUSE_TRACE_FACILITY == 1)
\r
49 #include "trcBase.h"
\r
51 /* Internal functions */
\r
53 void vTraceStoreTaskswitch(void);
\r
55 void vTraceStoreKernelCall(uint32_t eventcode, uint32_t byteParam);
\r
57 void vTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode,
\r
60 void vTraceStoreKernelCallWithParam(uint32_t evtcode, uint32_t objectNumber,
\r
63 void vTraceSetTaskInstanceFinished(objectHandleType handle);
\r
65 void vTraceSetPriorityProperty(uint8_t objectclass, uint8_t id, uint8_t value);
\r
67 uint8_t uiTraceGetPriorityProperty(uint8_t objectclass, uint8_t id);
\r
69 void vTraceSetObjectState(uint8_t objectclass, uint8_t id, uint8_t value);
\r
71 uint8_t uiTraceGetObjectState(uint8_t objectclass, uint8_t id);
\r
73 #if (INCLUDE_OBJECT_DELETE == 1)
\r
75 void vTraceStoreObjectNameOnCloseEvent(objectHandleType handle,
\r
76 traceObjectClass objectclass);
\r
78 void vTraceStoreObjectPropertiesOnCloseEvent(objectHandleType handle,
\r
79 traceObjectClass objectclass);
\r
82 /* Internal constants for task state */
\r
83 #define TASK_STATE_INSTANCE_NOT_ACTIVE 0
\r
84 #define TASK_STATE_INSTANCE_ACTIVE 1
\r
85 #define TASK_STATE_INSTANCE_MARKED_FINISHED 2
\r
87 /* This defines the mapping between FreeRTOS queue types and our internal
\r
89 extern traceObjectClass TraceObjectClassTable[5];
\r
91 /*******************************************************************************
\r
92 * The event codes - should match the offline config file.
\r
94 * Some sections below are encoded to allow for constructions like:
\r
96 * vTraceStoreKernelCall(EVENTGROUP_CREATE + objectclass, ...
\r
98 * The object class ID is given by the three LSB bits, in such cases. Since each
\r
99 * object class has a separate object property table, the class ID is needed to
\r
100 * know what section in the object table to use for getting an object name from
\r
101 * an object handle.
\r
102 ******************************************************************************/
\r
104 #define NULL_EVENT (0x00) /* Ignored in the analysis*/
\r
105 #define RECORDING_START (0x01) /* Not yet used */
\r
106 #define RECORDING_STOP (0x02) /* Not yet used */
\r
108 /*******************************************************************************
\r
111 * Events for storing task-switches and interrupts. The RESUME events are
\r
112 * generated if the task/interrupt is already marked active.
\r
113 ******************************************************************************/
\r
114 #define EVENTGROUP_TS (0x04)
\r
115 #define TS_ISR_BEGIN (EVENTGROUP_TS + 0) /* 4 */
\r
116 #define TS_ISR_RESUME (EVENTGROUP_TS + 1) /* 5 */
\r
117 #define TS_TASK_BEGIN (EVENTGROUP_TS + 2) /* 6 */
\r
118 #define TS_TASK_RESUME (EVENTGROUP_TS + 3) /* 7 */
\r
120 /*******************************************************************************
\r
121 * EVENTGROUP_OBJCLOSE_NAME
\r
123 * About Close Events
\r
124 * When an object is evicted from the object property table (object close), two
\r
125 * internal events are stored (EVENTGROUP_OBJCLOSE_NAME and
\r
126 * EVENTGROUP_OBJCLOSE_PROP), containg the handle-name mapping and object
\r
127 * properties valid up to this point.
\r
128 ******************************************************************************/
\r
129 #define EVENTGROUP_OBJCLOSE_NAME (0x08)
\r
131 /*******************************************************************************
\r
132 * EVENTGROUP_OBJCLOSE_PROP
\r
134 * The internal event carrying properties of deleted objects
\r
135 * The handle and object class of the closed object is not stored in this event,
\r
136 * but is assumed to be the same as in the preceeding CLOSE event. Thus, these
\r
137 * two events must be generated from within a critical section.
\r
138 * When queues are closed, arg1 is the "state" property (i.e., number of
\r
139 * buffered messages/signals).
\r
140 * When actors are closed, arg1 is priority, arg2 is handle of the "instance
\r
141 * finish" event, and arg3 is event code of the "instance finish" event.
\r
142 * In this case, the lower three bits is the object class of the instance finish
\r
143 * handle. The lower three bits are not used (always zero) when queues are
\r
144 * closed since the queue type is given in the previous OBJCLOSE_NAME event.
\r
145 ******************************************************************************/
\r
146 #define EVENTGROUP_OBJCLOSE_PROP (EVENTGROUP_OBJCLOSE_NAME + 8) /*0x10*/
\r
148 /*******************************************************************************
\r
149 * EVENTGROUP_CREATE
\r
151 * The events in this group are used to log Kernel object creations.
\r
152 * The lower three bits in the event code gives the object class, i.e., type of
\r
153 * create operation (task, queue, semaphore, etc).
\r
154 ******************************************************************************/
\r
155 #define EVENTGROUP_CREATE (EVENTGROUP_OBJCLOSE_PROP + 8) /*0x18*/
\r
157 /*******************************************************************************
\r
160 * The events in this group are used to log Send/Give events on queues,
\r
161 * semaphores and mutexeds The lower three bits in the event code gives the
\r
162 * object class, i.e., what type of object that is operated on (queue, semaphore
\r
164 ******************************************************************************/
\r
165 #define EVENTGROUP_SEND (EVENTGROUP_CREATE + 8) /*0x20*/
\r
167 /*******************************************************************************
\r
168 * EVENTGROUP_RECEIVE
\r
170 * The events in this group are used to log Receive/Take events on queues,
\r
171 * semaphores and mutexes. The lower three bits in the event code gives the
\r
172 * object class, i.e., what type of object that is operated on (queue, semaphore
\r
174 ******************************************************************************/
\r
175 #define EVENTGROUP_RECEIVE (EVENTGROUP_SEND + 8) /*0x28*/
\r
177 /* Send/Give operations, from ISR */
\r
178 #define EVENTGROUP_SEND_FROM_ISR (EVENTGROUP_RECEIVE + 8) /*0x30*/
\r
180 /* Receive/Take operations, from ISR */
\r
181 #define EVENTGROUP_RECEIVE_FROM_ISR (EVENTGROUP_SEND_FROM_ISR + 8) /*0x38*/
\r
183 /* "Failed" event type versions of above (timeout, failed allocation, etc) */
\r
184 #define EVENTGROUP_FAILED_KSE (EVENTGROUP_RECEIVE_FROM_ISR + 8) /*0x40*/
\r
186 /* Failed create calls - memory allocation failed */
\r
187 #define EVENTGROUP_FAILED_CREATE (EVENTGROUP_FAILED_KSE) /*0x40*/
\r
189 /* Failed send/give - timeout! */
\r
190 #define EVENTGROUP_FAILED_SEND (EVENTGROUP_FAILED_CREATE + 8) /*0x48*/
\r
192 /* Failed receive/take - timeout! */
\r
193 #define EVENTGROUP_FAILED_RECEIVE (EVENTGROUP_FAILED_SEND + 8) /*0x50*/
\r
195 /* Failed non-blocking send/give - queue full */
\r
196 #define EVENTGROUP_FAILED_SEND_FROM_ISR (EVENTGROUP_FAILED_RECEIVE + 8) /*0x58*/
\r
198 /* Failed non-blocking receive/take - queue empty */
\r
199 #define EVENTGROUP_FAILED_RECEIVE_FROM_ISR \
\r
200 (EVENTGROUP_FAILED_SEND_FROM_ISR + 8) /*0x60*/
\r
202 /* Events when blocking on receive/take */
\r
203 #define EVENTGROUP_BLOCK_ON_RECEIVE \
\r
204 (EVENTGROUP_FAILED_RECEIVE_FROM_ISR + 8) /*0x68*/
\r
206 /* Events when blocking on send/give */
\r
207 #define EVENTGROUP_BLOCK_ON_SEND (EVENTGROUP_BLOCK_ON_RECEIVE + 8) /*0x70*/
\r
209 /* Events on queue peek (receive) */
\r
210 #define EVENTGROUP_PEEK (EVENTGROUP_BLOCK_ON_SEND + 8) /*0x78*/
\r
212 /* Events on object delete (vTaskDelete or vQueueDelete) */
\r
213 #define EVENTGROUP_DELETE (EVENTGROUP_PEEK + 8) /*0x80*/
\r
215 /* Other events - object class is implied: TASK */
\r
216 #define EVENTGROUP_OTHERS (EVENTGROUP_DELETE + 8) /*0x88*/
\r
217 #define TASK_DELAY_UNTIL (EVENTGROUP_OTHERS + 0)
\r
218 #define TASK_DELAY (EVENTGROUP_OTHERS + 1)
\r
219 #define TASK_SUSPEND (EVENTGROUP_OTHERS + 2)
\r
220 #define TASK_RESUME (EVENTGROUP_OTHERS + 3)
\r
221 #define TASK_RESUME_FROM_ISR (EVENTGROUP_OTHERS + 4)
\r
222 #define TASK_PRIORITY_SET (EVENTGROUP_OTHERS + 5)
\r
223 #define TASK_PRIORITY_INHERIT (EVENTGROUP_OTHERS + 6)
\r
224 #define TASK_PRIORITY_DISINHERIT (EVENTGROUP_OTHERS + 7)
\r
227 #define EVENTGROUP_FTRACE_PLACEHOLDER (EVENTGROUP_OTHERS + 8) /*0x90*/
\r
230 #define EVENTGROUP_USEREVENT (EVENTGROUP_FTRACE_PLACEHOLDER + 8) /*0x98*/
\r
231 #define USER_EVENT (EVENTGROUP_USEREVENT + 0)
\r
233 /* Allow for 0-15 arguments (the number of args is added to event code) */
\r
234 #define USER_EVENT_LAST (EVENTGROUP_USEREVENT + 15)
\r
236 /******************************************************************************
\r
237 * XTS Event - eXtended TimeStamp events
\r
238 * The timestamps used in the recorder are "differential timestamps" (DTS), i.e.
\r
239 * the time since the last stored event. The DTS fields are either 1 or 2 bytes
\r
240 * in the other events, depending on the bytes available in the event struct.
\r
241 * If the time since the last event (the DTS) is larger than allowed for by
\r
242 * the DTS field of the current event, an XTS event is inserted immidiatly
\r
243 * before the original event. The XTS event contains up to 3 additional bytes
\r
244 * of the DTS value - the higher bytes of the true DTS value. The lower 1-2
\r
245 * bytes are stored in the normal DTS field.
\r
246 * There are two types of XTS events, XTS8 and XTS16. An XTS8 event is stored
\r
247 * when there is only room for 1 byte (8 bit) DTS data in the original event,
\r
248 * which means a limit of 0xFF (255). The XTS16 is used when the original event
\r
249 * has a 16 bit DTS field and thereby can handle values up to 0xFFFF (65535).
\r
251 * Using a very high frequency time base can result in many XTS events.
\r
252 * Preferably, the time between two OS ticks should fit in 16 bits, i.e.,
\r
253 * at most 65535. If your time base has a higher frequency, you can define
\r
255 ******************************************************************************/
\r
257 #define EVENTGROUP_SYS (EVENTGROUP_USEREVENT + 16) /*0xA8*/
\r
258 #define XTS8 (EVENTGROUP_SYS + 0) /*0xA8*/
\r
259 #define XTS16 (EVENTGROUP_SYS + 1) /*0xA9*/
\r
261 #define EVENT_BEING_WRITTEN (EVENTGROUP_SYS + 2) /*0xAA*/
\r
263 #define RESERVED_DUMMY_CODE (EVENTGROUP_SYS + 3) /*0xAB*/
\r