]> begriffs open source - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcHardwarePort.h
Update trace recorder to include heap tracing and new v8 features.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace / Include / trcHardwarePort.h
1 /******************************************************************************* \r
2  * Tracealyzer v2.6.0 Recorder Library\r
3  * Percepio AB, www.percepio.com\r
4  *\r
5  * trcHardwarePort.h\r
6  *\r
7  * Contains together with trcHardwarePort.c all hardware portability issues of \r
8  * the trace recorder library.\r
9  *\r
10  * Terms of Use\r
11  * This software is copyright Percepio AB. The recorder library is free for\r
12  * use together with Percepio products. You may distribute the recorder library\r
13  * in its original form, including modifications in trcPort.c and trcPort.h\r
14  * given that these modification are clearly marked as your own modifications\r
15  * and documented in the initial comment section of these source files. \r
16  * This software is the intellectual property of Percepio AB and may not be \r
17  * sold or in other ways commercially redistributed without explicit written \r
18  * permission by Percepio AB.\r
19  *\r
20  * Disclaimer \r
21  * The trace tool and recorder library is being delivered to you AS IS and \r
22  * Percepio AB makes no warranty as to its use or performance. Percepio AB does \r
23  * not and cannot warrant the performance or results you may obtain by using the \r
24  * software or documentation. Percepio AB make no warranties, express or \r
25  * implied, as to noninfringement of third party rights, merchantability, or \r
26  * fitness for any particular purpose. In no event will Percepio AB, its \r
27  * technology partners, or distributors be liable to you for any consequential, \r
28  * incidental or special damages, including any lost profits or lost savings, \r
29  * even if a representative of Percepio AB has been advised of the possibility \r
30  * of such damages, or for any claim by any third party. Some jurisdictions do \r
31  * not allow the exclusion or limitation of incidental, consequential or special \r
32  * damages, or the exclusion of implied warranties or limitations on how long an \r
33  * implied warranty may last, so the above limitations may not apply to you.\r
34  *\r
35  * Copyright Percepio AB, 2013.\r
36  * www.percepio.com\r
37  ******************************************************************************/\r
38 \r
39 #ifndef TRCPORT_H\r
40 #define TRCPORT_H\r
41 #include <stdint.h>\r
42 \r
43 /* If Win32 port */\r
44 #ifdef WIN32\r
45 \r
46    #undef _WIN32_WINNT\r
47    #define _WIN32_WINNT 0x0600\r
48 \r
49    /* Standard includes. */\r
50    #include <stdio.h>\r
51    #include <windows.h>\r
52    #include <direct.h>\r
53 \r
54 /*******************************************************************************\r
55  * The Win32 port by default saves the trace to file and then kills the\r
56  * program when the recorder is stopped, to facilitate quick, simple tests\r
57  * of the recorder.\r
58  ******************************************************************************/\r
59    #define WIN32_PORT_SAVE_WHEN_STOPPED 1\r
60    #define WIN32_PORT_EXIT_WHEN_STOPPED 1\r
61 \r
62 #endif\r
63 \r
64 #define DIRECTION_INCREMENTING 1\r
65 #define DIRECTION_DECREMENTING 2\r
66 \r
67 /******************************************************************************\r
68  * Supported ports\r
69  * \r
70  * PORT_HWIndependent\r
71  * A hardware independent fallback option for event timestamping. Provides low \r
72  * resolution timestamps based on the OS tick.\r
73  * This may be used on the Win32 port, but may also be used on embedded hardware \r
74  * platforms. All time durations will be truncated to the OS tick frequency, \r
75  * typically 1 KHz. This means that a task or ISR that executes in less than \r
76  * 1 ms get an execution time of zero.\r
77  *\r
78  * PORT_APPLICATION_DEFINED\r
79  * Allows for defining the port macros in other source code files.\r
80  *\r
81  * PORT_Win32\r
82  * "Accurate" timestamping based on the Windows performance counter for Win32 \r
83  * builds. Note that this gives the host machine time, not the kernel time.\r
84  *\r
85  * Hardware specific ports\r
86  * To get accurate timestamping, a hardware timer is necessary. Below are the \r
87  * available ports. Some of these are "unofficial", meaning that \r
88  * they have not yet been verified by Percepio but have been contributed by \r
89  * external developers. They should work, otherwise let us know by emailing \r
90  * support@percepio.com. Some work on any OS platform, while other are specific \r
91  * to a certain operating system.\r
92  *****************************************************************************/\r
93 \r
94 /****** Port Name ******************** Code ** Official ** OS Platform *******/\r
95 #define PORT_APPLICATION_DEFINED       -2   /* -           -                 */\r
96 #define PORT_NOT_SET                   -1   /* -           -                 */\r
97 #define PORT_HWIndependent             0    /* Yes         Any               */\r
98 #define PORT_Win32                     1    /* Yes         Windows (FreeRTOS)*/\r
99 #define PORT_Atmel_AT91SAM7            2    /* No          Any               */\r
100 #define PORT_Atmel_UC3A0               3    /* No          Any               */\r
101 #define PORT_ARM_CortexM               4    /* Yes         Any               */\r
102 #define PORT_Renesas_RX600             5    /* Yes         Any               */\r
103 #define PORT_Microchip_dsPIC_AND_PIC24 6    /* Yes         Any               */\r
104 #define PORT_TEXAS_INSTRUMENTS_TMS570  7    /* No          Any               */\r
105 #define PORT_TEXAS_INSTRUMENTS_MSP430  8    /* No          Any               */\r
106 #define PORT_MICROCHIP_PIC32           9    /* No          Any               */\r
107 #define PORT_XILINX_PPC405             10   /* No          FreeRTOS          */\r
108 #define PORT_XILINX_PPC440             11   /* No          FreeRTOS          */\r
109 #define PORT_XILINX_MICROBLAZE         12   /* No          Any               */\r
110 #define PORT_NXP_LPC210X               13   /* No          Any               */\r
111 \r
112 #include "trcConfig.h" // Where SELECTED_PORT is defined\r
113 \r
114 /*******************************************************************************\r
115  * IRQ_PRIORITY_ORDER\r
116  *\r
117  * Macro which should be defined as an integer of 0 or 1.\r
118  *\r
119  * This should be 0 if lower IRQ priority values implies higher priority \r
120  * levels, such as on ARM Cortex M. If the opposite scheme is used, i.e., \r
121  * if higher IRQ priority values means higher priority, this should be 1.\r
122  *\r
123  * This setting is not critical. It is used only to sort and colorize the \r
124  * interrupts in priority order, in case you record interrupts using\r
125  * the vTraceStoreISRBegin and vTraceStoreISREnd routines.\r
126  *\r
127  ******************************************************************************\r
128  *\r
129  * HWTC Macros \r
130  *\r
131  * These four HWTC macros provides a hardware isolation layer representing a \r
132  * generic hardware timer/counter used for driving the operating system tick, \r
133  * such as the SysTick feature of ARM Cortex M3/M4, or the PIT of the Atmel \r
134  * AT91SAM7X.\r
135  *\r
136  * HWTC_COUNT: The current value of the counter. This is expected to be reset \r
137  * a each tick interrupt. Thus, when the tick handler starts, the counter has \r
138  * already wrapped.\r
139  *\r
140  * HWTC_COUNT_DIRECTION: Should be one of:\r
141  * - DIRECTION_INCREMENTING - for hardware timer/counters of incrementing type\r
142  *   such as the PIT on Atmel AT91SAM7X.\r
143  *   When the counter value reach HWTC_PERIOD, it is reset to zero and the\r
144  *   interrupt is signaled.\r
145  * - DIRECTION_DECREMENTING - for hardware timer/counters of decrementing type\r
146  *   such as the SysTick on ARM Cortex M3/M4 chips.\r
147  *   When the counter value reach 0, it is reset to HWTC_PERIOD and the\r
148  *   interrupt is signaled.\r
149  *\r
150  * HWTC_PERIOD: The number of increments or decrements of HWTC_COUNT between\r
151  * two OS tick interrupts. This should preferably be mapped to the reload\r
152  * register of the hardware timer, to make it more portable between chips in the \r
153  * same family. The macro should in most cases be (reload register + 1).\r
154  * For FreeRTOS, this can in most cases be defined as \r
155  * #define HWTC_PERIOD (configCPU_CLOCK_HZ / configTICK_RATE_HZ)\r
156  *\r
157  * HWTC_DIVISOR: If the timer frequency is very high, like on the Cortex M chips\r
158  * (where the SysTick runs at the core clock frequency), the "differential \r
159  * timestamping" used in the recorder will more frequently insert extra XTS \r
160  * events to store the timestamps, which increases the event buffer usage. \r
161  * In such cases, to reduce the number of XTS events and thereby get longer \r
162  * traces, you use HWTC_DIVISOR to scale down the timestamps and frequency.\r
163  * Assuming a OS tick rate of 1 KHz, it is suggested to keep the effective timer\r
164  * frequency below 65 MHz to avoid an excessive amount of XTS events. Thus, a\r
165  * Cortex M chip running at 72 MHZ should use a HWTC_DIVISOR of 2, while a \r
166  * faster chip require a higher HWTC_DIVISOR value. \r
167  *\r
168  * The HWTC macros and vTracePortGetTimeStamp is the main porting issue\r
169  * or the trace recorder library. Typically you should not need to change\r
170  * the code of vTracePortGetTimeStamp if using the HWTC macros.\r
171  *\r
172  ******************************************************************************/\r
173 \r
174 #if (SELECTED_PORT == PORT_Win32)\r
175     // This can be used as a template for any free-running 32-bit counter\r
176     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
177     #define HWTC_COUNT (ulGetRunTimeCounterValue())\r
178     #define HWTC_PERIOD 0\r
179     #define HWTC_DIVISOR 1\r
180 \r
181     // Please update according to your system...\r
182     #define IRQ_PRIORITY_ORDER 1  \r
183     \r
184 #elif (SELECTED_PORT == PORT_HWIndependent) \r
185         // OS Tick only (typically 1 ms resolution)    \r
186     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
187     #define HWTC_COUNT 0\r
188     #define HWTC_PERIOD 1\r
189     #define HWTC_DIVISOR 1\r
190     \r
191         // Please update according to your system...\r
192     #define IRQ_PRIORITY_ORDER NOT_SET  \r
193 \r
194 \r
195 #elif (SELECTED_PORT == PORT_ARM_CortexM)\r
196 \r
197         void prvTraceSetIRQMask(uint32_t priMask);\r
198         uint32_t prvTraceGetIRQMask(void);\r
199         \r
200         void prvTraceEnableIRQ(void);\r
201         void prvTraceDisableIRQ(void);\r
202             \r
203         void prvTraceInitCortexM(void);\r
204                 \r
205         #define PORT_SPECIFIC_INIT() prvTraceInitCortexM()      \r
206                 \r
207         extern uint32_t DWT_CYCLES_ADDED;               \r
208         #define DWT_CTRL_REG (*((uint32_t*)0xE0001000))\r
209         #define DWT_CYCLE_COUNTER (*((uint32_t*)0xE0001004))\r
210         \r
211     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
212     #define HWTC_COUNT (DWT_CYCLE_COUNTER + DWT_CYCLES_ADDED)\r
213     #define HWTC_PERIOD 0\r
214     #define HWTC_DIVISOR 4\r
215 \r
216     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
217 \r
218 #elif (SELECTED_PORT == PORT_Renesas_RX600)    \r
219 \r
220     #include "iodefine.h"\r
221 \r
222     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
223     #define HWTC_COUNT (CMT0.CMCNT)\r
224     #define HWTC_PERIOD (CMT0.CMCOR + 1)\r
225     #define HWTC_DIVISOR 1\r
226     #define IRQ_PRIORITY_ORDER 1  // higher IRQ priority values are more significant\r
227 \r
228 #elif (SELECTED_PORT == PORT_Microchip_dsPIC_AND_PIC24)\r
229 \r
230     /* For Microchip PIC24 and dsPIC (16 bit) */\r
231 \r
232     /* Note: The trace library is designed for 32-bit MCUs and is slower than \r
233        intended on 16-bit MCUs. Storing an event on a PIC24 takes about 70 usec. \r
234        In comparison, 32-bit MCUs are often 10-20 times faster. If recording overhead \r
235        becomes a problem on PIC24, use the filters to exclude less interesting tasks \r
236        or system calls. */\r
237 \r
238     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
239     #define HWTC_COUNT (TMR1)\r
240     #define HWTC_PERIOD (PR1+1)\r
241     #define HWTC_DIVISOR 1\r
242     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
243 \r
244 #elif (SELECTED_PORT == PORT_Atmel_AT91SAM7)\r
245 \r
246     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
247         \r
248     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
249     #define HWTC_COUNT ((uint32_t)(AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF))\r
250     #define HWTC_PERIOD ((uint32_t)(AT91C_BASE_PITC->PITC_PIMR + 1))\r
251     #define HWTC_DIVISOR 1\r
252     #define IRQ_PRIORITY_ORDER 1  // higher IRQ priority values are more significant\r
253 \r
254 #elif (SELECTED_PORT == PORT_Atmel_UC3A0)\r
255 \r
256     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
257     /* For Atmel AVR32 (AT32UC3A).*/\r
258         \r
259     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
260     #define HWTC_COUNT ((uint32_t)sysreg_read(AVR32_COUNT))\r
261     #define HWTC_PERIOD ((uint32_t)(sysreg_read(AVR32_COMPARE) + 1))\r
262     #define HWTC_DIVISOR 1\r
263     #define IRQ_PRIORITY_ORDER 1  // higher IRQ priority values are more significant\r
264 \r
265 #elif (SELECTED_PORT == PORT_NXP_LPC210X)\r
266 \r
267     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */   \r
268     /* Tested with LPC2106, but should work with most LPC21XX chips. */\r
269         \r
270     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
271     #define HWTC_COUNT  *((uint32_t *)0xE0004008 )\r
272     #define HWTC_PERIOD *((uint32_t *)0xE0004018 )\r
273     #define HWTC_DIVISOR 1    \r
274     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
275 \r
276 #elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_TMS570)\r
277  \r
278     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
279 \r
280     #define RTIFRC0 *((uint32_t *)0xFFFFFC10)\r
281     #define RTICOMP0 *((uint32_t *)0xFFFFFC50)\r
282     #define RTIUDCP0 *((uint32_t *)0xFFFFFC54)\r
283     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
284     #define HWTC_COUNT (RTIFRC0 - (RTICOMP0 - RTIUDCP0))\r
285     #define HWTC_PERIOD (RTIUDCP0)\r
286     #define HWTC_DIVISOR 1\r
287 \r
288     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
289 \r
290 #elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_MSP430)\r
291 \r
292     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
293 \r
294     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
295     #define HWTC_COUNT (TA0R)\r
296     #define HWTC_PERIOD (((uint16_t)TACCR0)+1)\r
297     #define HWTC_DIVISOR 1\r
298     #define IRQ_PRIORITY_ORDER 1  // higher IRQ priority values are more significant\r
299 \r
300 #elif (SELECTED_PORT == PORT_MICROCHIP_PIC32)\r
301 \r
302     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
303 \r
304     #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
305     #define HWTC_COUNT (ReadTimer1())     /* Should be available in BSP */\r
306     #define HWTC_PERIOD (ReadPeriod1()+1) /* Should be available in BSP */\r
307     #define HWTC_DIVISOR 1\r
308     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
309 \r
310 #elif (SELECTED_PORT == PORT_XILINX_PPC405)\r
311     \r
312     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
313 \r
314     #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
315     #define HWTC_COUNT  mfspr(0x3db)    \r
316         #if (defined configCPU_CLOCK_HZ && defined configTICK_RATE_HZ) // Check if FreeRTOS\r
317             /* For FreeRTOS only - found no generic OS independent solution for the PPC405 architecture. */\r
318             #define HWTC_PERIOD ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) // Same as in port.c for PPC405\r
319         #else\r
320             /* Not defined for other operating systems yet */\r
321             #error HWTC_PERIOD must be defined to give the number of hardware timer ticks per OS tick.\r
322         #endif  \r
323     #define HWTC_DIVISOR 1\r
324     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
325 \r
326 #elif (SELECTED_PORT == PORT_XILINX_PPC440)\r
327     \r
328         /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
329     /* This should work with most PowerPC chips */    \r
330     \r
331         #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
332     #define HWTC_COUNT  mfspr(0x016)\r
333         #if (defined configCPU_CLOCK_HZ && defined configTICK_RATE_HZ) // Check if FreeRTOS\r
334                 /* For FreeRTOS only - found no generic OS independent solution for the PPC440 architecture. */\r
335                 #define HWTC_PERIOD ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) // Same as in port.c for PPC440\r
336         #else\r
337                 /* Not defined for other operating systems yet */\r
338                 #error HWTC_PERIOD must be defined to give the number of hardware timer ticks per OS tick.\r
339         #endif\r
340     #define HWTC_DIVISOR 1    \r
341     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
342     \r
343 #elif (SELECTED_PORT == PORT_XILINX_MICROBLAZE)\r
344 \r
345     /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
346 \r
347     /* This should work with most Microblaze configurations.\r
348      * It uses the AXI Timer 0 - the tick interrupt source.\r
349      * If an AXI Timer 0 peripheral is available on your hardware platform, no modifications are required.\r
350      */\r
351     #include "xtmrctr_l.h"\r
352 \r
353     #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
354     #define HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 )\r
355         #define HWTC_PERIOD (XTmrCtr_mGetLoadReg( XPAR_TMRCTR_0_BASEADDR,  0) + 1)\r
356     #define HWTC_DIVISOR 16\r
357     #define IRQ_PRIORITY_ORDER 0  // lower IRQ priority values are more significant\r
358 \r
359 #elif (SELECTED_PORT == PORT_APPLICATION_DEFINED)\r
360 \r
361         #if !( defined (HWTC_COUNT_DIRECTION) && defined (HWTC_COUNT) && defined (HWTC_PERIOD) && defined (HWTC_DIVISOR) && defined (IRQ_PRIORITY_ORDER) )\r
362                 #error SELECTED_PORT is PORT_APPLICATION_DEFINED but not all of the necessary constants have been defined.\r
363         #endif\r
364 \r
365 #elif (SELECTED_PORT != PORT_NOT_SET)\r
366 \r
367     #error "SELECTED_PORT had unsupported value!"\r
368     #define SELECTED_PORT PORT_NOT_SET\r
369 \r
370 #endif\r
371 \r
372 #if (SELECTED_PORT != PORT_NOT_SET)\r
373     \r
374     #ifndef HWTC_COUNT_DIRECTION\r
375     #error "HWTC_COUNT_DIRECTION is not set!"\r
376     #endif \r
377     \r
378     #ifndef HWTC_COUNT\r
379     #error "HWTC_COUNT is not set!"    \r
380     #endif \r
381     \r
382     #ifndef HWTC_PERIOD\r
383     #error "HWTC_PERIOD is not set!"\r
384     #endif \r
385     \r
386     #ifndef HWTC_DIVISOR\r
387     #error "HWTC_DIVISOR is not set!"    \r
388     #endif \r
389     \r
390     #ifndef IRQ_PRIORITY_ORDER\r
391     #error "IRQ_PRIORITY_ORDER is not set!"\r
392     #elif (IRQ_PRIORITY_ORDER != 0) && (IRQ_PRIORITY_ORDER != 1)\r
393     #error "IRQ_PRIORITY_ORDER has bad value!"\r
394     #endif \r
395     \r
396     #if (HWTC_DIVISOR < 1)\r
397     #error "HWTC_DIVISOR must be a non-zero positive value!"\r
398     #endif \r
399         \r
400 #endif\r
401 /*******************************************************************************\r
402  * vTraceConsoleMessage\r
403  *\r
404  * A wrapper for your system-specific console "printf" console output function.\r
405  * This needs to be correctly defined to see status reports from the trace \r
406  * status monitor task (this is defined in trcUser.c).\r
407  ******************************************************************************/         \r
408 #define vTraceConsoleMessage(x)\r
409 \r
410 /*******************************************************************************\r
411  * vTracePortGetTimeStamp\r
412  *\r
413  * Returns the current time based on the HWTC macros which provide a hardware\r
414  * isolation layer towards the hardware timer/counter.\r
415  *\r
416  * The HWTC macros and vTracePortGetTimeStamp is the main porting issue\r
417  * or the trace recorder library. Typically you should not need to change\r
418  * the code of vTracePortGetTimeStamp if using the HWTC macros.\r
419  *\r
420  ******************************************************************************/\r
421 void vTracePortGetTimeStamp(uint32_t *puiTimestamp);\r
422 \r
423 /*******************************************************************************\r
424  * vTracePortEnd\r
425  * \r
426  * This function is called when the recorder is stopped due to full buffer.\r
427  * Mainly intended to show a message in the console.\r
428  * This is used by the Win32 port to store the trace to a file. The file path is\r
429  * set using vTracePortSetFileName.\r
430  ******************************************************************************/\r
431 void vTracePortEnd(void);\r
432 \r
433 #endif\r