+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcConfig.h\r
- *\r
- * Configuration parameters for the trace recorder library. Before using the \r
- * trace recorder library, please check that the default settings are \r
- * appropriate for your system, and if necessary adjust these. Most likely, you \r
- * will need to adjust the NTask, NISR, NQueue, NMutex and NSemaphore values to \r
- * reflect the number of such objects in your system. These may be \r
- * over-approximated, although larger values values implies more RAM usage.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files. \r
- * This software is the intellectual property of Percepio AB and may not be \r
- * sold or in other ways commercially redistributed without explicit written \r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer \r
- * The trace tool and recorder library is being delivered to you AS IS and \r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does \r
- * not and cannot warrant the performance or results you may obtain by using the \r
- * software or documentation. Percepio AB make no warranties, express or \r
- * implied, as to noninfringement of third party rights, merchantability, or \r
- * fitness for any particular purpose. In no event will Percepio AB, its \r
- * technology partners, or distributors be liable to you for any consequential, \r
- * incidental or special damages, including any lost profits or lost savings, \r
- * even if a representative of Percepio AB has been advised of the possibility \r
- * of such damages, or for any claim by any third party. Some jurisdictions do \r
- * not allow the exclusion or limitation of incidental, consequential or special \r
- * damages, or the exclusion of implied warranties or limitations on how long an \r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#ifndef TRCCONFIG_H\r
-#define TRCCONFIG_H\r
-\r
-/******************************************************************************\r
- * SELECTED_PORT\r
- *\r
- * Macro that specifies what hardware port that should be used. \r
- * Available ports are:\r
- *\r
- * Port Name Code Official OS supported\r
- * PORT_APPLICATION_DEFINED -2 - - \r
- * PORT_NOT_SET -1 - - \r
- * PORT_HWIndependent 0 Yes Any\r
- * PORT_Win32 1 Yes FreeRTOS on Win32\r
- * PORT_Atmel_AT91SAM7 2 No Any \r
- * PORT_Atmel_UC3A0 3 No Any \r
- * PORT_ARM_CortexM 4 Yes Any \r
- * PORT_Renesas_RX600 5 Yes Any \r
- * PORT_Microchip_dsPIC_AND_PIC24 6 Yes Any \r
- * PORT_TEXAS_INSTRUMENTS_TMS570 7 No Any \r
- * PORT_TEXAS_INSTRUMENTS_MSP430 8 No Any \r
- * PORT_MICROCHIP_PIC32MX 9 Yes Any \r
- * PORT_XILINX_PPC405 10 No FreeRTOS \r
- * PORT_XILINX_PPC440 11 No FreeRTOS \r
- * PORT_XILINX_MICROBLAZE 12 No Any \r
- * PORT_NXP_LPC210X 13 No Any \r
- * PORT_MICROCHIP_PIC32MZ 14 Yes Any \r
- * PORT_ARM_CORTEX_A9 15 No Any\r
- * PORT_ARM_CORTEX_M0 16 Yes Any\r
- *****************************************************************************/\r
-\r
-// Set the port setting here!\r
-#define SELECTED_PORT PORT_NOT_SET\r
-\r
-#if (SELECTED_PORT == PORT_ARM_CortexM)\r
- /* For ARM Cortex-M: make sure ARM's CMSIS library is included here, which\r
- is used for accessing the PRIMASK register. e.g. #include "board.h" */\r
-#endif\r
-\r
-\r
-#if (SELECTED_PORT == PORT_NOT_SET)\r
- #error "You need to define SELECTED_PORT here!"\r
-#endif\r
-\r
-/******************************************************************************\r
- * FREERTOS_VERSION\r
- * \r
- * Specify what version of FreeRTOS that is used. This is necessary compensate \r
- * for renamed symbols in the FreeRTOS kernel (does not build if incorrect).\r
- * \r
- * FREERTOS_VERSION_7_3_OR_7_4 (= 1) If using FreeRTOS v7.3.0 - v7.4.2\r
- * FREERTOS_VERSION_7_5_OR_7_6 (= 2) If using FreeRTOS v7.5.0 - v7.6.0\r
- * FREERTOS_VERSION_8_0_OR_LATER (= 3) If using FreeRTOS v8.0.0 or later\r
- *****************************************************************************/\r
-#define FREERTOS_VERSION FREERTOS_VERSION_8_0_OR_LATER\r
-\r
-/******************************************************************************\r
- * TRACE_RECORDER_STORE_MODE\r
- *\r
- * Macro which should be defined as one of:\r
- * - TRACE_STORE_MODE_RING_BUFFER\r
- * - TRACE_STORE_MODE_STOP_WHEN_FULL\r
- * Default is TRACE_STORE_MODE_RING_BUFFER.\r
- *\r
- * With TRACE_RECORDER_STORE_MODE set to TRACE_STORE_MODE_RING_BUFFER, the \r
- * events are stored in a ring buffer, i.e., where the oldest events are \r
- * overwritten when the buffer becomes full. This allows you to get the last\r
- * events leading up to an interesting state, e.g., an error, without having \r
- * to store the whole run since startup.\r
- *\r
- * When TRACE_RECORDER_STORE_MODE is TRACE_STORE_MODE_STOP_WHEN_FULL, the \r
- * recording is stopped when the buffer becomes full. This is useful for\r
- * recording events following a specific state, e.g., the startup sequence.\r
- *****************************************************************************/\r
-#define TRACE_RECORDER_STORE_MODE TRACE_STORE_MODE_RING_BUFFER\r
-\r
-/*******************************************************************************\r
- * TRACE_SCHEDULING_ONLY\r
- *\r
- * Macro which should be defined as an integer value.\r
- *\r
- * If this setting is enabled (= 1), only scheduling events are recorded.\r
- * If disabled (= 0), all events are recorded.\r
- *\r
- * For users of "Free Edition", that only displays scheduling events, this\r
- * option can be used to avoid storing other events.\r
- *\r
- * Default value is 0 (store all enabled events).\r
- *\r
- ******************************************************************************/\r
-#define TRACE_SCHEDULING_ONLY 0\r
-\r
-/*******************************************************************************\r
- * EVENT_BUFFER_SIZE\r
- *\r
- * Macro which should be defined as an integer value.\r
- *\r
- * This defines the capacity of the event buffer, i.e., the number of records\r
- * it may store. Most events use one record (4 byte), although some events \r
- * require multiple 4-byte records. You should adjust this to the amount of RAM\r
- * available in the target system.\r
- * \r
- * Default value is 1000, which means that 4000 bytes is allocated for the\r
- * event buffer.\r
- ******************************************************************************/\r
-#define EVENT_BUFFER_SIZE 1000\r
-\r
-/*******************************************************************************\r
- * NTask, NISR, NQueue, NSemaphore, NMutex\r
- *\r
- * A group of macros which should be defined as integer values, zero or larger.\r
- *\r
- * These define the capacity of the Object Property Table, i.e., the maximum\r
- * number of objects active at any given point, within each object class (e.g., \r
- * task, queue, semaphore, ...).\r
- * \r
- * If tasks or other other objects are deleted in your system, this\r
- * setting does not limit the total amount of objects created, only the number\r
- * of objects that have been successfully created but not yet deleted.\r
- *\r
- * Using too small values will cause vTraceError to be called, which stores an \r
- * error message in the trace that is shown when opening the trace file.\r
- *\r
- * It can be wise to start with large values for these constants, \r
- * unless you are very confident on these numbers. Then do a recording and\r
- * check the actual usage by selecting View menu -> Trace Details -> \r
- * Resource Usage -> Object Table. \r
- ******************************************************************************/\r
-#define NTask 15\r
-#define NISR 5\r
-#define NQueue 10\r
-#define NSemaphore 10\r
-#define NMutex 10\r
-#define NTimer 2\r
-#define NEventGroup 2\r
-\r
-/******************************************************************************\r
- * INCLUDE_MEMMANG_EVENTS\r
- * \r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * This controls if malloc and free calls should be traced. Set this to zero to\r
- * exclude malloc/free calls, or one (1) to include such events in the trace.\r
- *\r
- * Default value is 1.\r
- *****************************************************************************/\r
-#define INCLUDE_MEMMANG_EVENTS 1\r
-\r
-/******************************************************************************\r
- * INCLUDE_USER_EVENTS\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * If this is zero (0) the code for creating User Events is excluded to\r
- * reduce code size. User Events are application-generated events, like \r
- * "printf" but for the trace log instead of console output. User Events are \r
- * much faster than a printf and can therefore be used in timing critical code.\r
- * See vTraceUserEvent() and vTracePrintF() in trcUser.h\r
- * \r
- * Default value is 1.\r
- *\r
- * Note that User Events are only displayed in Professional Edition.\r
- *****************************************************************************/\r
-#define INCLUDE_USER_EVENTS 1\r
-\r
-/*****************************************************************************\r
- * INCLUDE_ISR_TRACING\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * If this is zero (0), the code for recording Interrupt Service Routines is \r
- * excluded to reduce code size.\r
- *\r
- * Default value is 1.\r
- * \r
- * Note, if the kernel has no central interrupt dispatcher, recording ISRs \r
- * require that you insert calls to vTraceStoreISRBegin and vTraceStoreISREnd \r
- * in your interrupt handlers.\r
- *****************************************************************************/\r
-#define INCLUDE_ISR_TRACING 1\r
-\r
-/*****************************************************************************\r
- * INCLUDE_READY_EVENTS\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * If one (1), events are recorded when tasks enter scheduling state "ready". \r
- * This uses a lot of space in the event buffer, so excluding "ready events" \r
- * will allow for longer traces. Including ready events however allows for \r
- * showing the initial pending time before tasks enter the execution state, and \r
- * for presenting accurate response times.\r
- *\r
- * Default value is 1.\r
- *****************************************************************************/\r
-#define INCLUDE_READY_EVENTS 1\r
-\r
-/*****************************************************************************\r
- * INCLUDE_NEW_TIME_EVENTS\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * If this is zero (1), events will be generated whenever the OS clock is\r
- * increased.\r
- *\r
- * Default value is 0.\r
- *****************************************************************************/\r
-#define INCLUDE_NEW_TIME_EVENTS 0\r
-\r
-/******************************************************************************\r
- * INCLUDE_FLOAT_SUPPORT\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * If this is zero (0), all references to floating point values are removed,\r
- * in case floating point values are not supported by the platform used.\r
- * Floating point values are only used in vTracePrintF and its subroutines, to \r
- * store float (%f) or double (%lf) arguments. \r
- *\r
- * vTracePrintF can be used with integer and string arguments in either case.\r
- *\r
- * Default value is 1.\r
- *****************************************************************************/\r
-#define INCLUDE_FLOAT_SUPPORT 1\r
-\r
-/******************************************************************************\r
- * INCLUDE_OBJECT_DELETE\r
- * \r
- * Macro which should be defined as either zero (0) or one (1). \r
- *\r
- * This must be enabled (1) if tasks, queues or other \r
- * traced kernel objects are deleted at runtime. If no deletes are made, this \r
- * can be set to 0 in order to exclude the delete-handling code.\r
- *\r
- * Default value is 1.\r
- *****************************************************************************/\r
-#define INCLUDE_OBJECT_DELETE 1\r
-\r
-/*******************************************************************************\r
- * SYMBOL_TABLE_SIZE\r
- *\r
- * Macro which should be defined as an integer value.\r
- *\r
- * This defines the capacity of the symbol table, in bytes. This symbol table \r
- * stores User Events labels and names of deleted tasks, queues, or other kernel\r
- * objects. If you don't use User Events or delete any kernel \r
- * objects you set this to a very low value. The minimum recommended value is 4.\r
- * A size of zero (0) is not allowed since a zero-sized array may result in a \r
- * 32-bit pointer, i.e., using 4 bytes rather than 0.\r
- *\r
- * Default value is 800.\r
- ******************************************************************************/\r
-#define SYMBOL_TABLE_SIZE 800\r
-\r
-#if (SYMBOL_TABLE_SIZE == 0)\r
-#error "SYMBOL_TABLE_SIZE may not be zero!"\r
-#endif\r
-\r
-/******************************************************************************\r
- * NameLenTask, NameLenQueue, ...\r
- *\r
- * Macros that specify the maximum lengths (number of characters) for names of\r
- * kernel objects, such as tasks and queues. If longer names are used, they will\r
- * be truncated when stored in the recorder.\r
- *****************************************************************************/\r
-#define NameLenTask 15\r
-#define NameLenISR 15\r
-#define NameLenQueue 15\r
-#define NameLenSemaphore 15\r
-#define NameLenMutex 15\r
-#define NameLenTimer 15\r
-#define NameLenEventGroup 15\r
-\r
-/******************************************************************************\r
- * TRACE_DATA_ALLOCATION\r
- *\r
- * This defines how to allocate the recorder data structure, i.e., using a \r
- * static declaration or using a dynamic allocation in runtime (malloc).\r
- *\r
- * Should be one of these two options:\r
- * - TRACE_DATA_ALLOCATION_STATIC (default)\r
- * - TRACE_DATA_ALLOCATION_DYNAMIC\r
- *\r
- * Using static allocation has the benefits of compile-time errors if the buffer \r
- * is too large (too large constants in trcConfig.h) and no need to call the \r
- * initialization routine (xTraceInitTraceData).\r
- *\r
- * Using dynamic allocation may give more flexibility in some cases.\r
- *****************************************************************************/\r
-#define TRACE_DATA_ALLOCATION TRACE_DATA_ALLOCATION_STATIC\r
-\r
-\r
-\r
-/******************************************************************************\r
- *** ADVANCED SETTINGS ********************************************************\r
- ******************************************************************************\r
- * The remaining settings are not necessary to modify but allows for optimizing\r
- * the recorder setup for your specific needs, e.g., to exclude events that you\r
- * are not interested in, in order to get longer traces.\r
- *****************************************************************************/ \r
-\r
-/******************************************************************************\r
-* HEAP_SIZE_BELOW_16M\r
-*\r
-* An integer constant that can be used to reduce the buffer usage of memory\r
-* allocation events (malloc/free). This value should be 1 if the heap size is \r
-* below 16 MB (2^24 byte), and you can live with reported addresses showing the \r
-* lower 24 bits only. If 0, you get the full 32-bit addresses.\r
-*\r
-* Default value is 0.\r
-******************************************************************************/\r
-#define HEAP_SIZE_BELOW_16M 0\r
-\r
-/******************************************************************************\r
- * USE_LINKER_PRAGMA\r
- *\r
- * Macro which should be defined as an integer value, default is 0.\r
- *\r
- * If this is 1, the header file "recorderdata_linker_pragma.h" is included just\r
- * before the declaration of RecorderData (in trcBase.c), i.e., the trace data \r
- * structure. This allows the user to specify a pragma with linker options. \r
- *\r
- * Example (for IAR Embedded Workbench and NXP LPC17xx):\r
- * #pragma location="AHB_RAM_MEMORY"\r
- * \r
- * This example instructs the IAR linker to place RecorderData in another RAM \r
- * bank, the AHB RAM. This can also be used for other compilers with a similar\r
- * pragmas for linker options.\r
- * \r
- * Note that this only applies if using static allocation, see below.\r
- ******************************************************************************/\r
-#define USE_LINKER_PRAGMA 0\r
-\r
-/******************************************************************************\r
- * USE_IMPLICIT_IFE_RULES\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- * Default is 1.\r
- *\r
- * Tracealyzer groups the events into actor instances, based on context-switches\r
- * and a definition of "Instance Finish Events", or IFEs. These are kernel calls \r
- * considered to be the last event in a task instance. Some kernel calls are \r
- * considered IFEs by default (e.g., delay functions), but it is also possible\r
- * to specify this individually for each task (see vTraceTaskInstanceFinish).\r
- *\r
- * If USE_IMPLICIT_IFE_RULES is one (1), the default IFEs will be enabled, which\r
- * gives a "typical" grouping of events into instances. You can combine this \r
- * with calls to vTraceTaskInstanceFinish for specific tasks.\r
- *\r
- * If USE_IMPLICIT_IFE_RULES is zero (0), the implicit IFEs are disabled and all\r
- * events withing each task is then shown as a single instance, unless you call \r
- * vTraceTaskInstanceFinish() at suitable locations to mark the IFEs.\r
- *****************************************************************************/\r
-#define USE_IMPLICIT_IFE_RULES 1\r
-\r
-/******************************************************************************\r
- * USE_16BIT_OBJECT_HANDLES\r
- *\r
- * Macro which should be defined as either zero (0) or one (1).\r
- * \r
- * If set to 0 (zero), the recorder uses 8-bit handles to identify kernel \r
- * objects such as tasks and queues. This limits the supported number of\r
- * concurrently active objects to 255 of each type (object class).\r
- *\r
- * If set to 1 (one), the recorder uses 16-bit handles to identify kernel \r
- * objects such as tasks and queues. This limits the supported number of\r
- * concurrent objects to 65535 of each type (object class). However, since the\r
- * object property table is limited to 64 KB, the practical limit is about\r
- * 3000 objects in total. \r
- * \r
- * Default is 0.\r
- *\r
- * NOTE: An object with handle above 255 will use an extra 4-byte record in \r
- * the event buffer whenever referenced. Moreover, some internal tables in the \r
- * recorder gets larger when using 16-bit handles. The additional RAM usage is \r
- * 5-10 byte plus 1 byte per kernel object i.e., task, queue, mutex, etc.\r
- *****************************************************************************/\r
-#define USE_16BIT_OBJECT_HANDLES 0\r
-\r
-/******************************************************************************\r
- * USE_TRACE_ASSERT\r
- *\r
- * Macro which should be defined as either zero (0) or one (1). \r
- * Default is 1.\r
- *\r
- * If this is one (1), the TRACE_ASSERT macro will verify that a condition is \r
- * true. If the condition is false, vTraceError() will be called.\r
- * This is used on several places in the recorder code for sanity checks on\r
- * parameters. Can be switched off to reduce CPU usage of the tracing.\r
- *****************************************************************************/\r
-#define USE_TRACE_ASSERT 1\r
- \r
-/*******************************************************************************\r
- * USE_SEPARATE_USER_EVENT_BUFFER\r
- *\r
- * Macro which should be defined as an integer value.\r
- * Default is zero (0).\r
- *\r
- * This enables and disables the use of the separate user event buffer. Using \r
- * this separate buffer has the benefit of not overwriting the user events with \r
- * kernel events (usually generated at a much higher rate), i.e., when using \r
- * ring-buffer mode.\r
- *\r
- * Note: When using the separate user event buffer, you may get an artificial\r
- * task instance named "Unknown actor". This is added as a placeholder when the \r
- * user event history is longer than the task scheduling history.\r
- ******************************************************************************/\r
-#define USE_SEPARATE_USER_EVENT_BUFFER 0\r
-\r
-/*******************************************************************************\r
- * USER_EVENT_BUFFER_SIZE\r
- *\r
- * Macro which should be defined as an integer value.\r
- *\r
- * This defines the capacity of the user event buffer, in number of slots.\r
- * A single user event can use between 1 and X slots, depending on the data.\r
- *\r
- * Only in use if USE_SEPARATE_USER_EVENT_BUFFER is set to 1.\r
- ******************************************************************************/\r
-#define USER_EVENT_BUFFER_SIZE 10\r
-\r
-/*******************************************************************************\r
- * USER_EVENT_CHANNELS\r
- *\r
- * Macro which should be defined as an integer value.\r
- *\r
- * This defines the number of allowed user event channels.\r
- *\r
- * Only in use if USE_SEPARATE_USER_EVENT_BUFFER is set to 1.\r
- ******************************************************************************/\r
-#define CHANNEL_FORMAT_PAIRS 32\r
-\r
-#endif\r
-\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcBase.h\r
- *\r
- * Core functionality of the Tracealyzer recorder library.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#ifndef TRCBASE_H\r
-#define TRCBASE_H\r
-\r
-#define TRACE_MINOR_VERSION 4\r
-#define TRACE_STORE_MODE_STOP_WHEN_FULL 1\r
-#define TRACE_STORE_MODE_RING_BUFFER 2\r
-#define TRACE_DATA_ALLOCATION_STATIC 1\r
-#define TRACE_DATA_ALLOCATION_DYNAMIC 2\r
-#define TRACE_DATA_ALLOCATION_CUSTOM 3\r
-\r
-#include "trcKernelPort.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-#ifndef USE_SEPARATE_USER_EVENT_BUFFER\r
-#define USE_SEPARATE_USER_EVENT_BUFFER 0\r
-#endif\r
-\r
-#ifndef TRACE_SR_ALLOC_CRITICAL_SECTION\r
-#define TRACE_SR_ALLOC_CRITICAL_SECTION()\r
-#endif\r
-\r
-/* Max number of event codes supported */\r
-#define NEventCodes 0x100\r
-\r
-/* Keeps track of the recorder's critical sections */\r
-extern volatile int recorder_busy;\r
-\r
-/* Our local critical sections for the recorder */\r
-#define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}\r
-#define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}\r
-\r
-/* Structure to handle the exclude flags for all objects and tasks. We add some extra objects since index 0 is not used for each object class. */\r
-extern uint8_t excludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1];\r
-\r
-/* Structure to handle the exclude flags for all event codes */\r
-extern uint8_t excludedEventCodes[NEventCodes / 8 + 1];\r
-\r
-/******************************************************************************\r
- * ObjectHandleStack\r
- * This data-structure is used to provide a mechanism for 1-byte trace object\r
- * handles. This way, only 1 byte is necessary instead of 4 bytes (a pointer)\r
- * when storing a reference to an object. This allows for up to 255 objects of\r
- * each object class active at any given moment. There can be more "historic"\r
- * objects, that have been deleted - that number is only limited by the size of\r
- * the symbol table.\r
- * Note that handle zero (0) is not used, it is a code for an invalid handle.\r
- *\r
- * This data structure keeps track of the FREE handles, not the handles in use.\r
- * This data structure contains one stack per object class. When a handle is\r
- * allocated to an object, the next free handle is popped from the stack. When\r
- * a handle is released (on object delete), it is pushed back on the stack.\r
- * Note that there is no initialization code that pushed the free handles\r
- * initially, that is not necessary due to the following optimization:\r
- *\r
- * The stack of handles (objectHandles) is initially all zeros. Since zero\r
- * is not a valid handle, that is a signal of additional handles needed.\r
- * If a zero is received when popping a new handle, it is replaced by the\r
- * index of the popped handle instead.\r
- *\r
- *****************************************************************************/\r
-typedef struct\r
-{\r
- /* For each object class, the index of the next handle to allocate */\r
- uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];\r
-\r
- /* The lowest index of this class (constant) */\r
- uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];\r
-\r
- /* The highest index of this class (constant) */\r
- uint16_t highestIndexOfClass[ TRACE_NCLASSES ];\r
-\r
- /* The highest use count for this class (for statistics) */\r
- uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];\r
-\r
- /* The free object handles - a set of stacks within this array */\r
- objectHandleType objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];\r
-\r
-} objectHandleStackType;\r
-\r
-extern objectHandleStackType objectHandleStacks;\r
-\r
-/******************************************************************************\r
- * Object Property Table\r
- * The Object Table contains name and other properties of the objects (tasks,\r
- * queues, mutexes, etc). The below data structures defines the properties of\r
- * each object class and are used to cast the byte buffer into a cleaner format.\r
- *\r
- * The values in the object table are continuously overwritten and always\r
- * represent the current state. If a property is changed during runtime, the OLD\r
- * value should be stored in the trace buffer, not the new value (since the new\r
- * value is found in the Object Property Table).\r
- * For close events this mechanism is the old names are stored in the symbol\r
- * table), for "priority set" (the old priority is stored in the event data)\r
- * and for "isActive", where the value decides if the task switch event type\r
- * should be "new" or "resume".\r
- ******************************************************************************/\r
-\r
-typedef struct\r
-{\r
- /* = NCLASSES */\r
- uint32_t NumberOfObjectClasses;\r
-\r
- uint32_t ObjectPropertyTableSizeInBytes;\r
-\r
- /* This is used to calculate the index in the dynamic object table\r
- (handle - 1 - nofStaticObjects = index)*/\r
-#if (USE_16BIT_OBJECT_HANDLES == 1)\r
- objectHandleType NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];\r
-#else\r
- objectHandleType NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];\r
-#endif\r
-\r
- /* Allocation size rounded up to the closest multiple of 4 */\r
- uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
-\r
- uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
-\r
- /* Allocation size rounded up to the closest multiple of 2 */\r
- uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];\r
-\r
- /* The actual handles issued, should be Initiated to all zeros */\r
- uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];\r
-} ObjectPropertyTableType;\r
-\r
-/* Symbol table data structure */\r
-typedef struct\r
-{\r
- /* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */\r
- uint32_t symTableSize;\r
-\r
- /* Entry 0 is reserved. Any reference to entry 0 implies NULL*/\r
- uint32_t nextFreeSymbolIndex;\r
-\r
- /* Size rounded up to closest multiple of 4, to avoid alignment issues*/\r
- uint8_t symbytes[4*((SYMBOL_TABLE_SIZE+3)/4)];\r
-\r
- /* Used for lookups - Up to 64 linked lists within the symbol table\r
- connecting all entries with the same 6 bit checksum.\r
- This field holds the current list heads. Should be initiated to zeros */\r
- uint16_t latestEntryOfChecksum[64];\r
-} symbolTableType;\r
-\r
-\r
-/*******************************************************************************\r
- * The data structures of the different events, all 4 bytes long\r
- ******************************************************************************/\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t objHandle;\r
- uint16_t dts; /* differential timestamp - time since last event */\r
-} TSEvent, TREvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t dummy;\r
- uint16_t dts; /* differential timestamp - time since last event */\r
-} LPEvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t objHandle;\r
- uint16_t dts; /* differential timestamp - time since last event */\r
-} KernelCall;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t objHandle;\r
- uint8_t param;\r
- uint8_t dts; /* differential timestamp - time since last event */\r
-} KernelCallWithParamAndHandle;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t dts; /* differential timestamp - time since last event */\r
- uint16_t param;\r
-} KernelCallWithParam16;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t objHandle; /* the handle of the closed object */\r
- uint16_t symbolIndex; /* the name of the closed object */\r
-} ObjCloseNameEvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t arg1;\r
- uint8_t arg2;\r
- uint8_t arg3;\r
-} ObjClosePropEvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t unused1;\r
- uint8_t unused2;\r
- uint8_t dts;\r
-} TaskInstanceStatusEvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
- uint8_t dts;\r
- uint16_t payload; /* the name of the user event */\r
-} UserEvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
-\r
- /* 8 bits extra for storing DTS, if it does not fit in ordinary event\r
- (this one is always MSB if used) */\r
- uint8_t xts_8;\r
-\r
- /* 16 bits extra for storing DTS, if it does not fit in ordinary event. */\r
- uint16_t xts_16;\r
-} XTSEvent;\r
-\r
-typedef struct\r
-{\r
- uint8_t type;\r
-\r
- uint8_t xps_8;\r
- uint16_t xps_16;\r
-} XPSEvent;\r
-\r
-typedef struct{\r
- uint8_t type;\r
- uint8_t dts;\r
- uint16_t size;\r
-} MemEventSize;\r
-\r
-typedef struct{\r
- uint8_t type;\r
- uint8_t addr_high;\r
- uint16_t addr_low;\r
-} MemEventAddr;\r
-\r
-/*******************************************************************************\r
- * The separate user event buffer structure. Can be enabled in trcConfig.h.\r
- ******************************************************************************/\r
-\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
-typedef struct\r
-{\r
- traceLabel name;\r
- traceLabel defaultFormat;\r
-} ChannelFormatPair;\r
-\r
-typedef struct\r
-{\r
- uint16_t bufferID;\r
- uint16_t version;\r
- uint32_t wraparoundCounter;\r
- uint32_t numberOfSlots;\r
- uint32_t nextSlotToWrite;\r
- uint8_t numberOfChannels;\r
- uint8_t padding1;\r
- uint8_t padding2;\r
- uint8_t padding3;\r
- ChannelFormatPair channels[CHANNEL_FORMAT_PAIRS+1];\r
- uint8_t channelBuffer[(USER_EVENT_BUFFER_SIZE + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */\r
- uint8_t dataBuffer[USER_EVENT_BUFFER_SIZE * 4]; /* 4 bytes per slot */\r
-\r
-} UserEventBuffer;\r
-#endif\r
-\r
-/*******************************************************************************\r
- * The main data structure, read by Tracealyzer from the RAM dump\r
- ******************************************************************************/\r
-\r
-typedef struct\r
-{\r
- uint8_t startmarker0;\r
- uint8_t startmarker1;\r
- uint8_t startmarker2;\r
- uint8_t startmarker3;\r
- uint8_t startmarker4;\r
- uint8_t startmarker5;\r
- uint8_t startmarker6;\r
- uint8_t startmarker7;\r
- uint8_t startmarker8;\r
- uint8_t startmarker9;\r
- uint8_t startmarker10;\r
- uint8_t startmarker11;\r
-\r
- /* Used to determine Kernel and Endianess */\r
- uint16_t version;\r
-\r
- /* Currently 3 */\r
- uint8_t minor_version;\r
-\r
- /* This should be 0 if lower IRQ priority values implies higher priority\r
- levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,\r
- if higher IRQ priority values means higher priority, this should be 1. */\r
- uint8_t irq_priority_order;\r
-\r
- /* sizeof(RecorderDataType) - just for control */\r
- uint32_t filesize;\r
-\r
- /* Current number of events recorded */\r
- uint32_t numEvents;\r
-\r
- /* The buffer size, in number of event records */\r
- uint32_t maxEvents;\r
-\r
- /* The event buffer index, where to write the next event */\r
- uint32_t nextFreeIndex;\r
-\r
- /* 1 if the buffer is full, 0 otherwise */\r
- uint32_t bufferIsFull;\r
-\r
- /* The frequency of the clock/timer/counter used as time base */\r
- uint32_t frequency;\r
-\r
- /* The absolute timestamp of the last stored event, in the native\r
- timebase, modulo frequency! */\r
- uint32_t absTimeLastEvent;\r
-\r
- /* The number of seconds in total - lasts for 136 years */\r
- uint32_t absTimeLastEventSecond;\r
-\r
- /* 1 if the recorder has been started, 0 if not yet started or stopped.\r
- This is a 32 bit variable due to alignment issues. */\r
- uint32_t recorderActive;\r
-\r
- /* Not used, remains for compatibility and future use */\r
- uint8_t notused[28];\r
-\r
- /* The amount of heap memory remaining at the last malloc or free event */\r
- uint32_t heapMemUsage;\r
-\r
- /* 0xF0F0F0F0 - for control only */\r
- int32_t debugMarker0;\r
-\r
- /* Set to value of USE_16BIT_OBJECT_HANDLES */\r
- uint32_t isUsing16bitHandles;\r
-\r
- /* The Object Property Table holds information about currently active\r
- tasks, queues, and other recorded objects. This is updated on each\r
- create call and includes object name and other properties. */\r
- ObjectPropertyTableType ObjectPropertyTable;\r
-\r
- /* 0xF1F1F1F1 - for control only */\r
- int32_t debugMarker1;\r
-\r
- /* The Symbol Table stores strings for User Events and is also used to\r
- store names of deleted objects, which still may be in the trace but no\r
- longer are available. */\r
- symbolTableType SymbolTable;\r
-\r
- /* For inclusion of float support, and for endian detection of floats.\r
- The value should be (float)1 or (uint32_t)0 */\r
-#if (INCLUDE_FLOAT_SUPPORT == 1)\r
- float exampleFloatEncoding;\r
-#else\r
- uint32_t exampleFloatEncoding;\r
-#endif\r
- /* This is non-zero if an internal error occurred in the recorder, e.g., if\r
- one of the Nxxx constants was too small. The systemInfo string will then\r
- contain an error message that is displayed when attempting to view the\r
- trace file. */\r
- uint32_t internalErrorOccured;\r
-\r
- /* 0xF2F2F2F2 - for control only */\r
- int32_t debugMarker2;\r
-\r
- /* Error messages from the recorder. */\r
- char systemInfo[80];\r
-\r
- /* 0xF3F3F3F3 - for control only */\r
- int32_t debugMarker3;\r
-\r
- /* The event data, in 4-byte records */\r
- uint8_t eventData[ EVENT_BUFFER_SIZE * 4 ];\r
-\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
- UserEventBuffer userEventBuffer;\r
-#endif\r
-\r
- /* This should always be 0 */\r
- uint32_t endOfSecondaryBlocks;\r
-\r
- uint8_t endmarker0;\r
- uint8_t endmarker1;\r
- uint8_t endmarker2;\r
- uint8_t endmarker3;\r
- uint8_t endmarker4;\r
- uint8_t endmarker5;\r
- uint8_t endmarker6;\r
- uint8_t endmarker7;\r
- uint8_t endmarker8;\r
- uint8_t endmarker9;\r
- uint8_t endmarker10;\r
- uint8_t endmarker11;\r
-} RecorderDataType;\r
-\r
-extern RecorderDataType* RecorderDataPtr;\r
-\r
-/* Internal functions */\r
-\r
-uint16_t prvTraceGetDTS(uint16_t param_maxDTS);\r
-\r
-void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength);\r
-\r
-traceLabel prvTraceCreateSymbolTableEntry(const char* name,\r
- uint8_t crc6,\r
- uint8_t len,\r
- traceLabel channel);\r
-\r
-traceLabel prvTraceLookupSymbolTableEntry(const char* name,\r
- uint8_t crc6,\r
- uint8_t len,\r
- traceLabel channel);\r
-\r
-traceLabel prvTraceOpenSymbol(const char* name, traceLabel userEventChannel);\r
-\r
-void prvTraceUpdateCounters(void);\r
-\r
-void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nEntries);\r
-\r
-objectHandleType xTraceGetObjectHandle(traceObjectClass objectclass);\r
-\r
-void vTraceFreeObjectHandle(traceObjectClass objectclass,\r
- objectHandleType handle);\r
-\r
-void vTraceSetObjectName(traceObjectClass objectclass,\r
- objectHandleType handle,\r
- const char* name);\r
-\r
-void* xTraceNextFreeEventBufferSlot(void);\r
-\r
-#if (USE_16BIT_OBJECT_HANDLES == 1)\r
-unsigned char prvTraceGet8BitHandle(objectHandleType handle);\r
-#else\r
-#define prvTraceGet8BitHandle(x) ((unsigned char)x)\r
-#endif\r
-\r
-\r
-uint16_t uiIndexOfObject(objectHandleType objecthandle,\r
- uint8_t objectclass);\r
-\r
-/*******************************************************************************\r
- * vTraceError\r
- *\r
- * Called by various parts in the recorder. Stops the recorder and stores a\r
- * pointer to an error message, which is printed by the monitor task.\r
- ******************************************************************************/\r
-void vTraceError(const char* msg);\r
-\r
-/*******************************************************************************\r
- * prvTraceInitTraceData\r
- *\r
- * Allocates and initializes the recorder data structure, based on the constants\r
- * in trcConfig.h. This allows for allocating the data on the heap, instead of\r
- * using a static declaration.\r
- ******************************************************************************/\r
-void prvTraceInitTraceData(void);\r
-\r
-/* Internal macros */\r
-\r
-#define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \\r
-(const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \\r
-[uiIndexOfObject(objecthandle, objectclass)])\r
-\r
-#define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \\r
-RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
-+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]\r
-\r
-#define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \\r
-RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
-+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]\r
-\r
-#define TRACE_SET_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] |= (1 << ((bitIndex) & 7))\r
-#define TRACE_CLEAR_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] &= ~(1 << ((bitIndex) & 7))\r
-#define TRACE_GET_FLAG_ISEXCLUDED(flags, bitIndex) (flags[(bitIndex) >> 3] & (1 << ((bitIndex) & 7)))\r
-\r
-#define TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_SET_FLAG_ISEXCLUDED(excludedEventCodes, eventCode)\r
-#define TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedEventCodes, eventCode)\r
-#define TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_GET_FLAG_ISEXCLUDED(excludedEventCodes, eventCode)\r
-\r
-/* DEBUG ASSERTS */\r
-#if defined USE_TRACE_ASSERT && USE_TRACE_ASSERT != 0\r
-#define TRACE_ASSERT(eval, msg, defRetVal) \\r
-if (!(eval)) \\r
-{ \\r
- vTraceError("TRACE_ASSERT: " msg); \\r
- return defRetVal; \\r
-}\r
-#else\r
-#define TRACE_ASSERT(eval, msg, defRetVal)\r
-#endif\r
-\r
-#endif\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
* Percepio AB, www.percepio.com\r
*\r
* trcHardwarePort.h\r
*\r
- * Contains together with trcHardwarePort.c all hardware portability issues of\r
- * the trace recorder library.\r
+ * The hardware abstraction layer for the trace recorder.\r
*\r
* Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcPort.c and trcPort.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block.\r
*\r
* Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
*\r
* Tabs are used for indent in this file (1 tab = 4 spaces)\r
*\r
- * Copyright Percepio AB, 2014.\r
+ * Copyright Percepio AB, 2017.\r
* www.percepio.com\r
******************************************************************************/\r
\r
-#ifndef TRCPORT_H\r
-#define TRCPORT_H\r
-#include <stdint.h>\r
+#ifndef TRC_HARDWARE_PORT_H\r
+#define TRC_HARDWARE_PORT_H\r
\r
-/* If Win32 port */\r
-#ifdef WIN32\r
+#include "trcPortDefines.h"\r
\r
- /* Standard includes. */\r
- #include <stdio.h>\r
- #include <windows.h>\r
- #include <direct.h>\r
-\r
-/*******************************************************************************\r
- * The Win32 port by default saves the trace to file and then kills the\r
- * program when the recorder is stopped, to facilitate quick, simple tests\r
- * of the recorder.\r
- ******************************************************************************/\r
- #define WIN32_PORT_SAVE_WHEN_STOPPED 1\r
- #define WIN32_PORT_EXIT_WHEN_STOPPED 1\r
\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NOT_SET)\r
+ #error "TRC_CFG_HARDWARE_PORT not selected - see trcConfig.h"\r
#endif\r
\r
-#define DIRECTION_INCREMENTING 1\r
-#define DIRECTION_DECREMENTING 2\r
-\r
-/******************************************************************************\r
- * Supported ports\r
- *\r
- * PORT_HWIndependent\r
- * A hardware independent fallback option for event timestamping. Provides low\r
- * resolution timestamps based on the OS tick.\r
- * This may be used on the Win32 port, but may also be used on embedded hardware\r
- * platforms. All time durations will be truncated to the OS tick frequency,\r
- * typically 1 KHz. This means that a task or ISR that executes in less than\r
- * 1 ms get an execution time of zero.\r
- *\r
- * PORT_APPLICATION_DEFINED\r
- * Allows for defining the port macros in other source code files.\r
- *\r
- * PORT_Win32\r
- * "Accurate" timestamping based on the Windows performance counter for Win32\r
- * builds. Note that this gives the host machine time, not the kernel time.\r
- *\r
- * Hardware specific ports\r
- * To get accurate timestamping, a hardware timer is necessary. Below are the\r
- * available ports. Some of these are "unofficial", meaning that\r
- * they have not yet been verified by Percepio but have been contributed by\r
- * external developers. They should work, otherwise let us know by emailing\r
- * support@percepio.com. Some work on any OS platform, while other are specific\r
- * to a certain operating system.\r
- *****************************************************************************/\r
-\r
-/****** Port Name ********************** Code ***** Official ** OS Platform *********/\r
-#define PORT_APPLICATION_DEFINED -2 /* - - */\r
-#define PORT_NOT_SET -1 /* - - */\r
-#define PORT_HWIndependent 0 /* Yes Any */\r
-#define PORT_Win32 1 /* Yes FreeRTOS on Win32 */\r
-#define PORT_Atmel_AT91SAM7 2 /* No Any */\r
-#define PORT_Atmel_UC3A0 3 /* No Any */\r
-#define PORT_ARM_CortexM 4 /* Yes Any */\r
-#define PORT_Renesas_RX600 5 /* Yes Any */\r
-#define PORT_Microchip_dsPIC_AND_PIC24 6 /* Yes Any */\r
-#define PORT_TEXAS_INSTRUMENTS_TMS570 7 /* No Any */\r
-#define PORT_TEXAS_INSTRUMENTS_MSP430 8 /* No Any */\r
-#define PORT_MICROCHIP_PIC32MX 9 /* Yes Any */\r
-#define PORT_XILINX_PPC405 10 /* No FreeRTOS */\r
-#define PORT_XILINX_PPC440 11 /* No FreeRTOS */\r
-#define PORT_XILINX_MICROBLAZE 12 /* No Any */\r
-#define PORT_NXP_LPC210X 13 /* No Any */\r
-#define PORT_MICROCHIP_PIC32MZ 14 /* Yes Any */\r
-#define PORT_ARM_CORTEX_A9 15 /* No Any */\r
-#define PORT_ARM_CORTEX_M0 16 /* Yes Any */\r
-\r
-#include "trcConfig.h"\r
-\r
/*******************************************************************************\r
- * IRQ_PRIORITY_ORDER\r
+ * TRC_IRQ_PRIORITY_ORDER\r
*\r
* Macro which should be defined as an integer of 0 or 1.\r
*\r
*\r
* HWTC Macros\r
*\r
- * These four HWTC macros provides a hardware isolation layer representing a\r
- * generic hardware timer/counter used for driving the operating system tick,\r
- * such as the SysTick feature of ARM Cortex M3/M4, or the PIT of the Atmel\r
- * AT91SAM7X.\r
+ * These macros provides a hardware isolation layer representing the\r
+ * hardware timer/counter used for the event timestamping.\r
+ *\r
+ * TRC_HWTC_COUNT: How to read the current value of the timer/counter.\r
+ *\r
+ * TRC_HWTC_TYPE: Tells the type of timer/counter used for TRC_HWTC_COUNT:\r
*\r
- * HWTC_COUNT: The current value of the counter. This is expected to be reset\r
- * a each tick interrupt. Thus, when the tick handler starts, the counter has\r
- * already wrapped.\r
+ * - TRC_FREE_RUNNING_32BIT_INCR:\r
+ * Free-running 32-bit timer/counter, counting upwards from 0.\r
*\r
- * HWTC_COUNT_DIRECTION: Should be one of:\r
- * - DIRECTION_INCREMENTING - for hardware timer/counters of incrementing type\r
- * such as the PIT on Atmel AT91SAM7X.\r
- * When the counter value reach HWTC_PERIOD, it is reset to zero and the\r
- * interrupt is signaled.\r
- * - DIRECTION_DECREMENTING - for hardware timer/counters of decrementing type\r
- * such as the SysTick on ARM Cortex M3/M4 chips.\r
- * When the counter value reach 0, it is reset to HWTC_PERIOD and the\r
- * interrupt is signaled.\r
+ * - TRC_FREE_RUNNING_32BIT_DECR\r
+ * Free-running 32-bit timer/counter, counting downwards from 0xFFFFFFFF.\r
*\r
- * HWTC_PERIOD: The number of increments or decrements of HWTC_COUNT between\r
- * two OS tick interrupts. This should preferably be mapped to the reload\r
- * register of the hardware timer, to make it more portable between chips in the\r
- * same family. The macro should in most cases be (reload register + 1).\r
- * For FreeRTOS, this can in most cases be defined as\r
- * #define HWTC_PERIOD (configCPU_CLOCK_HZ / configTICK_RATE_HZ)\r
+ * - TRC_OS_TIMER_INCR\r
+ * Periodic timer that drives the OS tick interrupt, counting upwards\r
+ * from 0 until (TRC_HWTC_PERIOD-1).\r
*\r
- * HWTC_DIVISOR: If the timer frequency is very high, like on the Cortex M chips\r
- * (where the SysTick runs at the core clock frequency), the "differential\r
- * timestamping" used in the recorder will more frequently insert extra XTS\r
- * events to store the timestamps, which increases the event buffer usage.\r
- * In such cases, to reduce the number of XTS events and thereby get longer\r
- * traces, you use HWTC_DIVISOR to scale down the timestamps and frequency.\r
- * Assuming a OS tick rate of 1 KHz, it is suggested to keep the effective timer\r
- * frequency below 65 MHz to avoid an excessive amount of XTS events. Thus, a\r
- * Cortex M chip running at 72 MHZ should use a HWTC_DIVISOR of 2, while a\r
- * faster chip require a higher HWTC_DIVISOR value.\r
+ * - TRC_OS_TIMER_DECR\r
+ * Periodic timer that drives the OS tick interrupt, counting downwards\r
+ * from TRC_HWTC_PERIOD-1 until 0.\r
*\r
- * The HWTC macros and vTracePortGetTimeStamp is the main porting issue\r
- * or the trace recorder library. Typically you should not need to change\r
- * the code of vTracePortGetTimeStamp if using the HWTC macros.\r
+ * - TRC_CUSTOM_TIMER_INCR\r
+ * A custom timer or counter independent of the OS tick, counting\r
+ * downwards from TRC_HWTC_PERIOD-1 until 0. (Currently only supported\r
+ * in streaming mode).\r
*\r
+ * - TRC_CUSTOM_TIMER_DECR\r
+ * A custom timer independent of the OS tick, counting downwards\r
+ * from TRC_HWTC_PERIOD-1 until 0. (Currently only supported\r
+ * in streaming mode).\r
+ *\r
+ * TRC_HWTC_PERIOD: The number of HWTC_COUNT ticks until the timer wraps\r
+ * around. If using TRC_FREE_RUNNING_32BIT_INCR/DECR, this should be 0. \r
+ *\r
+ * TRC_HWTC_FREQ_HZ: The clock rate of the TRC_HWTC_COUNT counter in Hz. If using \r
+ * TRC_OS_TIMER_INCR/DECR, this is should be TRC_HWTC_PERIOD * TRACE_TICK_RATE_HZ.\r
+ * If using a free-running timer, this is often TRACE_CPU_CLOCK_HZ (if running at\r
+ * the core clock rate). If using TRC_CUSTOM_TIMER_INCR/DECR, this should match\r
+ * the clock rate of your custom timer (i.e., TRC_HWTC_COUNT). If the default value\r
+ * of TRC_HWTC_FREQ_HZ is incorrect for your setup, you can override it by calling\r
+ * vTraceSetFrequency before calling vTraceEnable.\r
+ *\r
+ * TRC_HWTC_DIVISOR (used in snapshot mode only):\r
+ * In snapshot mode, the timestamp resolution is TRC_HWTC_FREQ_HZ/TRC_HWTC_DIVISOR.\r
+ * If the timer frequency is very high (hundreds of MHz), we recommend increasing\r
+ * the TRC_HWTC_DIVISOR prescaler, to reduce the bandwidth needed to store\r
+ * timestamps. This since extra "XTS" events are inserted if the time since the\r
+ * previous event exceeds a certain limit (255 or 65535 depending on event type).\r
+ * It is advised to keep the time between most events below 65535 native ticks\r
+ * (after division by TRC_HWTC_DIVISOR) to avoid frequent XTS events.\r
******************************************************************************/\r
\r
-#if (SELECTED_PORT == PORT_Win32)\r
- // This can be used as a template for any free-running 32-bit counter\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (ulGetRunTimeCounterValue())\r
- #define HWTC_PERIOD 0\r
- #define HWTC_DIVISOR 1\r
-\r
- // Please update according to your system...\r
- #define IRQ_PRIORITY_ORDER 1\r
-\r
-#elif (SELECTED_PORT == PORT_HWIndependent)\r
- // OS Tick only (typically 1 ms resolution)\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT 0\r
- #define HWTC_PERIOD 1\r
- #define HWTC_DIVISOR 1\r
-\r
- // Please update according to your system...\r
- #define IRQ_PRIORITY_ORDER NOT_SET\r
-\r
-\r
-#elif (SELECTED_PORT == PORT_ARM_CortexM)\r
-\r
- void prvTraceInitCortexM(void);\r
-\r
- #define REG_DEMCR (*(volatile unsigned int*)0xE000EDFC)\r
- #define REG_DWT_CTRL (*(volatile unsigned int*)0xE0001000)\r
- #define REG_DWT_CYCCNT (*(volatile unsigned int*)0xE0001004)\r
- #define REG_DWT_EXCCNT (*(volatile unsigned int*)0xE000100C)\r
-\r
- /* Bit mask for TRCENA bit in DEMCR - Global enable for DWT and ITM */\r
- #define DEMCR_TRCENA (1 << 24)\r
-\r
- /* Bit mask for NOPRFCNT bit in DWT_CTRL. If 1, DWT_EXCCNT is not supported */\r
- #define DWT_CTRL_NOPRFCNT (1 << 24)\r
-\r
- /* Bit mask for NOCYCCNT bit in DWT_CTRL. If 1, DWT_CYCCNT is not supported */\r
- #define DWT_CTRL_NOCYCCNT (1 << 25)\r
-\r
- /* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_EXCCNT */\r
- #define DWT_CTRL_EXCEVTENA (1 << 18)\r
-\r
- /* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_CYCCNT */\r
- #define DWT_CTRL_CYCCNTENA (1)\r
-\r
- #define PORT_SPECIFIC_INIT() prvTraceInitCortexM()\r
-\r
- extern uint32_t DWT_CYCLES_ADDED;\r
-\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (REG_DWT_CYCCNT + DWT_CYCLES_ADDED)\r
- #define HWTC_PERIOD 0\r
- #define HWTC_DIVISOR 4\r
-\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NOT_SET)\r
+ #error "TRC_CFG_HARDWARE_PORT not selected - see trcConfig.h"\r
+#endif\r
\r
-#elif (SELECTED_PORT == PORT_ARM_CORTEX_M0)\r
- #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
- #define HWTC_COUNT (*((uint32_t*)0xE000E018))\r
- #define HWTC_PERIOD ((*(uint32_t*)0xE000E014) + 1)\r
- #define HWTC_DIVISOR 2\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)\r
+ /* This can be used as a template for any free-running 32-bit counter */\r
+ #define TRC_HWTC_TYPE TRC_FREE_RUNNING_32BIT_INCR\r
+ #define TRC_HWTC_COUNT (ulGetRunTimeCounterValue())\r
+ #define TRC_HWTC_PERIOD 0\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ 100000\r
+ \r
+ #define TRC_IRQ_PRIORITY_ORDER 1\r
+\r
+ #define TRC_PORT_SPECIFIC_INIT()\r
+\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_HWIndependent)\r
+ /* Timestamping by OS tick only (typically 1 ms resolution) */\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT 0\r
+ #define TRC_HWTC_PERIOD 1\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ TRACE_TICK_RATE_HZ\r
+\r
+ /* Set the meaning of IRQ priorities in ISR tracing - see above */\r
+ #define TRC_IRQ_PRIORITY_ORDER NOT_SET\r
+\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)\r
+ \r
+ #ifndef __CORTEX_M\r
+ #error "Can't find the CMSIS API. Please include your processor's header file in trcConfig.h" \r
+ #endif\r
\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+ /**************************************************************************\r
+ * For Cortex-M3, M4 and M7, the DWT cycle counter is used for timestamping.\r
+ * For Cortex-M0 and M0+, the SysTick timer is used since DWT is not\r
+ * available. Systick timestamping can also be forced on Cortex-M3, M4 and\r
+ * M7 by defining the preprocessor directive TRC_CFG_ARM_CM_USE_SYSTICK,\r
+ * either directly below or in trcConfig.h.\r
+ *\r
+ * #define TRC_CFG_ARM_CM_USE_SYSTICK\r
+ **************************************************************************/\r
+\r
+ #if ((__CORTEX_M >= 0x03) && (! defined TRC_CFG_ARM_CM_USE_SYSTICK))\r
+ \r
+ void prvTraceInitCortexM(void);\r
+\r
+ #define TRC_REG_DEMCR (*(volatile uint32_t*)0xE000EDFC)\r
+ #define TRC_REG_DWT_CTRL (*(volatile uint32_t*)0xE0001000)\r
+ #define TRC_REG_DWT_CYCCNT (*(volatile uint32_t*)0xE0001004)\r
+ #define TRC_REG_DWT_EXCCNT (*(volatile uint32_t*)0xE000100C)\r
+\r
+ #define TRC_REG_ITM_LOCKACCESS (*(volatile uint32_t*)0xE0001FB0) \r
+ #define TRC_ITM_LOCKACCESS_UNLOCK (0xC5ACCE55)\r
+ \r
+ /* Bit mask for TRCENA bit in DEMCR - Global enable for DWT and ITM */\r
+ #define TRC_DEMCR_TRCENA (1 << 24)\r
+\r
+ /* Bit mask for NOPRFCNT bit in DWT_CTRL. If 1, DWT_EXCCNT is not supported */\r
+ #define TRC_DWT_CTRL_NOPRFCNT (1 << 24)\r
+\r
+ /* Bit mask for NOCYCCNT bit in DWT_CTRL. If 1, DWT_CYCCNT is not supported */\r
+ #define TRC_DWT_CTRL_NOCYCCNT (1 << 25)\r
+\r
+ /* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_EXCCNT */\r
+ #define TRC_DWT_CTRL_EXCEVTENA (1 << 18)\r
+\r
+ /* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_CYCCNT */\r
+ #define TRC_DWT_CTRL_CYCCNTENA (1)\r
+\r
+ #define TRC_PORT_SPECIFIC_INIT() prvTraceInitCortexM()\r
+\r
+ #define TRC_HWTC_TYPE TRC_FREE_RUNNING_32BIT_INCR\r
+ #define TRC_HWTC_COUNT TRC_REG_DWT_CYCCNT\r
+ #define TRC_HWTC_PERIOD 0\r
+ #define TRC_HWTC_DIVISOR 4\r
+ #define TRC_HWTC_FREQ_HZ TRACE_CPU_CLOCK_HZ\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
+ \r
+ #else\r
+ \r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ #define TRC_HWTC_COUNT (*((volatile uint32_t*)0xE000E018))\r
+ #define TRC_HWTC_PERIOD ((*((volatile uint32_t*)0xE000E014)) + 1)\r
+ #define TRC_HWTC_DIVISOR 4\r
+ #define TRC_HWTC_FREQ_HZ TRACE_CPU_CLOCK_HZ\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
+ \r
+ #endif\r
\r
-#elif (SELECTED_PORT == PORT_Renesas_RX600)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Renesas_RX600)\r
\r
#include "iodefine.h"\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (CMT0.CMCNT)\r
- #define HWTC_PERIOD (CMT0.CMCOR + 1)\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant\r
-\r
-#elif ((SELECTED_PORT == PORT_MICROCHIP_PIC32MX) || (SELECTED_PORT == PORT_MICROCHIP_PIC32MZ))\r
-\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (TMR1)\r
- #define HWTC_PERIOD (PR1 + 1)\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
-\r
-#elif (SELECTED_PORT == PORT_Microchip_dsPIC_AND_PIC24)\r
-\r
- /* For Microchip PIC24 and dsPIC (16 bit) */\r
-\r
- /* Note: The trace library is designed for 32-bit MCUs and is slower than\r
- intended on 16-bit MCUs. Storing an event on a PIC24 takes about 70 usec.\r
- In comparison, this is 10-20 times faster on a 32-bit MCU... */\r
+ #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) \r
+ \r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT (CMT0.CMCNT)\r
+ \r
+ #elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+ \r
+ /* Decreasing counters better for Tickless Idle? */\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ #define TRC_HWTC_COUNT (CMT0.CMCOR - CMT0.CMCNT)\r
+ \r
+ #endif\r
+ \r
+ #define TRC_HWTC_PERIOD (CMT0.CMCOR + 1)\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 1 \r
+ \r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32)\r
+\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT (TMR1)\r
+ #define TRC_HWTC_PERIOD (PR1 + 1)\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
+\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48)\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (TMR1)\r
- #define HWTC_PERIOD (PR1+1)\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+ #define TRC_RTIFRC0 *((uint32_t *)0xFFFFFC10)\r
+ #define TRC_RTICOMP0 *((uint32_t *)0xFFFFFC50)\r
+ #define TRC_RTIUDCP0 *((uint32_t *)0xFFFFFC54)\r
+ \r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT (TRC_RTIFRC0 - (TRC_RTICOMP0 - TRC_RTIUDCP0))\r
+ #define TRC_HWTC_PERIOD (TRC_RTIUDCP0)\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
\r
-#elif (SELECTED_PORT == PORT_Atmel_AT91SAM7)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Atmel_AT91SAM7)\r
\r
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT ((uint32_t)(AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF))\r
- #define HWTC_PERIOD ((uint32_t)(AT91C_BASE_PITC->PITC_PIMR + 1))\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT ((uint32_t)(AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF))\r
+ #define TRC_HWTC_PERIOD ((uint32_t)(AT91C_BASE_PITC->PITC_PIMR + 1))\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 1\r
\r
-#elif (SELECTED_PORT == PORT_Atmel_UC3A0)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Atmel_UC3A0)\r
\r
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
- /* For Atmel AVR32 (AT32UC3A).*/\r
+ /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO*/\r
+ \r
+ /* For Atmel AVR32 (AT32UC3A) */\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT ((uint32_t)sysreg_read(AVR32_COUNT))\r
- #define HWTC_PERIOD ((uint32_t)(sysreg_read(AVR32_COMPARE) + 1))\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT ((uint32_t)sysreg_read(AVR32_COUNT))\r
+ #define TRC_HWTC_PERIOD ((uint32_t)(sysreg_read(AVR32_COMPARE) + 1))\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 1\r
\r
-#elif (SELECTED_PORT == PORT_NXP_LPC210X)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NXP_LPC210X)\r
\r
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
+ \r
/* Tested with LPC2106, but should work with most LPC21XX chips. */\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT *((uint32_t *)0xE0004008 )\r
- #define HWTC_PERIOD *((uint32_t *)0xE0004018 )\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT *((uint32_t *)0xE0004008 )\r
+ #define TRC_HWTC_PERIOD *((uint32_t *)0xE0004018 )\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
\r
-#elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_TMS570)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_MSP430)\r
\r
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
+ /* UNOFFICIAL PORT - NOT YET VERIFIED */\r
+ \r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_INCR\r
+ #define TRC_HWTC_COUNT (TA0R)\r
+ #define TRC_HWTC_PERIOD (((uint16_t)TACCR0)+1)\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 1\r
\r
- #define TRC_RTIFRC0 *((uint32_t *)0xFFFFFC10)\r
- #define TRC_RTICOMP0 *((uint32_t *)0xFFFFFC50)\r
- #define TRC_RTIUDCP0 *((uint32_t *)0xFFFFFC54)\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (TRC_RTIFRC0 - (TRC_RTICOMP0 - TRC_RTIUDCP0))\r
- #define HWTC_PERIOD (RTIUDCP0)\r
- #define HWTC_DIVISOR 1\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_PPC405)\r
\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+ /* UNOFFICIAL PORT - NOT YET VERIFIED */\r
+ \r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ #define TRC_HWTC_COUNT mfspr(0x3db)\r
+ #define TRC_HWTC_PERIOD (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
\r
-#elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_MSP430)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_PPC440)\r
\r
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
+ /* UNOFFICIAL PORT */\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING\r
- #define HWTC_COUNT (TA0R)\r
- #define HWTC_PERIOD (((uint16_t)TACCR0)+1)\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant\r
-\r
-#elif (SELECTED_PORT == PORT_XILINX_PPC405)\r
-\r
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
-\r
- #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
- #define HWTC_COUNT mfspr(0x3db)\r
- #if (defined configCPU_CLOCK_HZ && defined configTICK_RATE_HZ) // Check if FreeRTOS\r
- /* For FreeRTOS only - found no generic OS independent solution for the PPC405 architecture. */\r
- #define HWTC_PERIOD ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) // Same as in port.c for PPC405\r
- #else\r
- /* Not defined for other operating systems yet */\r
- #error HWTC_PERIOD must be defined to give the number of hardware timer ticks per OS tick.\r
- #endif\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
-\r
-#elif (SELECTED_PORT == PORT_XILINX_PPC440)\r
-\r
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
/* This should work with most PowerPC chips */\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
- #define HWTC_COUNT mfspr(0x016)\r
- #if (defined configCPU_CLOCK_HZ && defined configTICK_RATE_HZ) // Check if FreeRTOS\r
- /* For FreeRTOS only - found no generic OS independent solution for the PPC440 architecture. */\r
- #define HWTC_PERIOD ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) // Same as in port.c for PPC440\r
- #else\r
- /* Not defined for other operating systems yet */\r
- #error HWTC_PERIOD must be defined to give the number of hardware timer ticks per OS tick.\r
- #endif\r
- #define HWTC_DIVISOR 1\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ #define TRC_HWTC_COUNT mfspr(0x016)\r
+ #define TRC_HWTC_PERIOD (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
\r
-#elif (SELECTED_PORT == PORT_XILINX_MICROBLAZE)\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_MICROBLAZE)\r
\r
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
\r
* If an AXI Timer 0 peripheral is available on your hardware platform, no modifications are required.\r
*/\r
#include "xtmrctr_l.h"\r
+ \r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ #define TRC_HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 )\r
+ #define TRC_HWTC_PERIOD (XTmrCtr_mGetLoadReg( XPAR_TMRCTR_0_BASEADDR, 0) + 1)\r
+ #define TRC_HWTC_DIVISOR 16\r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
+\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_CORTEX_A9)\r
+ /* INPUT YOUR PERIPHERAL BASE ADDRESS HERE */\r
+ #define TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS 0xSOMETHING\r
+ \r
+ #define TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET 0x0600\r
+ #define TRC_CA9_MPCORE_PRIVCTR_PERIOD_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x00))\r
+ #define TRC_CA9_MPCORE_PRIVCTR_COUNTER_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x04))\r
+ #define TRC_CA9_MPCORE_PRIVCTR_CONTROL_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x08))\r
+ \r
+ #define TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK 0x0000FF00\r
+ #define TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT 8\r
+ #define TRC_CA9_MPCORE_PRIVCTR_PRESCALER (((TRC_CA9_MPCORE_PRIVCTR_CONTROL_REG & TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK) >> TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT) + 1)\r
+\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ #define TRC_HWTC_COUNT TRC_CA9_MPCORE_PRIVCTR_COUNTER_REG\r
+ #define TRC_HWTC_PERIOD (TRC_CA9_MPCORE_PRIVCTR_PERIOD_REG + 1)\r
+\r
+ /****************************************************************************************\r
+ NOTE: The private timer ticks with a very high frequency (half the core-clock usually), \r
+ depending on the prescaler used. If a low prescaler is used, the number of HW ticks between\r
+ the trace events gets large, and thereby inefficient to store (sometimes extra events are\r
+ needed). To improve efficiency, you may use the TRC_HWTC_DIVISOR as an additional prescaler.\r
+ *****************************************************************************************/ \r
+ #define TRC_HWTC_DIVISOR 1\r
+ \r
+ #define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)\r
+ #define TRC_IRQ_PRIORITY_ORDER 0\r
+\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_POWERPC_Z4)\r
+\r
+ /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
+\r
+ #define TRC_HWTC_TYPE TRC_OS_TIMER_DECR\r
+ //#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
+ #define TRC_HWTC_COUNT PIT.TIMER[configTICK_PIT_CHANNEL].CVAL.R // must be the PIT channel used for the systick\r
+ #define TRC_HWTC_PERIOD ((configPIT_CLOCK_HZ / configTICK_RATE_HZ) - 1U) // TODO FIXME or maybe not -1? what's the right "period" value?\r
+ #define TRC_HWTC_FREQ_HZ configPIT_CLOCK_HZ\r
+ #define TRC_HWTC_DIVISOR 1\r
+ #define TRC_IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant\r
+\r
+#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_APPLICATION_DEFINED)\r
+\r
+ #if !( defined (TRC_HWTC_TYPE) && defined (TRC_HWTC_COUNT) && defined (TRC_HWTC_PERIOD) && defined (TRC_HWTC_FREQ_HZ) && defined (TRC_IRQ_PRIORITY_ORDER) )\r
+ #error "The hardware port is not completely defined!"\r
+ #endif\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
- #define HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 )\r
- #define HWTC_PERIOD (XTmrCtr_mGetLoadReg( XPAR_TMRCTR_0_BASEADDR, 0) + 1)\r
- #define HWTC_DIVISOR 16\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
-\r
-#elif (SELECTED_PORT == PORT_ARM_CORTEX_A9)\r
-\r
- /* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */\r
-\r
- #define CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK 0x0000FF00\r
- #define CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT 8\r
-\r
- #define CA9_MPCORE_PRIVCTR_PERIOD_REG (*(volatile uint32_t*)(0xF8F00600 + 0))\r
- #define CA9_MPCORE_PRIVCTR_COUNTER_REG (*(volatile uint32_t*)(0xF8F00600 + 4))\r
- #define CA9_MPCORE_PRIVCTR_CONTROL_REG (*(volatile uint32_t*)(0xF8F00600 + 8))\r
-\r
- #define CA9_MPCORE_PRIVCTR_PRESCALER (((CA9_MPCORE_PRIVCTR_CONTROL_REG & CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK) >> CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT) + 1)\r
+#elif (TRC_CFG_HARDWARE_PORT != TRC_HARDWARE_PORT_NOT_SET)\r
\r
+ #error "TRC_CFG_HARDWARE_PORT had unsupported value!"\r
+ #define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET\r
\r
- #define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING\r
- #define HWTC_COUNT CA9_MPCORE_PRIVCTR_COUNTER_REG\r
- #define HWTC_PERIOD ((CA9_MPCORE_PRIVCTR_PERIOD_REG * CA9_MPCORE_PRIVCTR_PRESCALER) + 1)\r
+#endif\r
\r
- //NOTE: The private timer ticks with a very high frequency (half the core-clock usually),\r
- //but offers the possibility to apply a prescaler. Depending on the prescaler you set the\r
- //HWTC_DIVISOR may need to be raised. Refer to the notes at the beginning of this file\r
- //for more information.\r
- #define HWTC_DIVISOR 1\r
+#ifndef TRC_HWTC_DIVISOR\r
+ #define TRC_HWTC_DIVISOR 1\r
+#endif\r
\r
- #define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant\r
+#ifndef TRC_PORT_SPECIFIC_INIT\r
+ #define TRC_PORT_SPECIFIC_INIT() \r
+#endif\r
\r
-#elif (SELECTED_PORT == PORT_APPLICATION_DEFINED)\r
+/* If Win32 port */\r
+#ifdef WIN32\r
\r
- #if !( defined (HWTC_COUNT_DIRECTION) && defined (HWTC_COUNT) && defined (HWTC_PERIOD) && defined (HWTC_DIVISOR) && defined (IRQ_PRIORITY_ORDER) )\r
- #error SELECTED_PORT is PORT_APPLICATION_DEFINED but not all of the necessary constants have been defined.\r
- #endif\r
+ #undef _WIN32_WINNT\r
+ #define _WIN32_WINNT 0x0600\r
\r
-#elif (SELECTED_PORT != PORT_NOT_SET)\r
+ /* Standard includes. */\r
+ #include <stdio.h>\r
+ #include <windows.h>\r
+ #include <direct.h>\r
\r
- #error "SELECTED_PORT had unsupported value!"\r
- #define SELECTED_PORT PORT_NOT_SET\r
+ /***************************************************************************\r
+ * The Win32 port by default saves the trace to file and then kills the\r
+ * program when the recorder is stopped, to facilitate quick, simple tests\r
+ * of the recorder.\r
+ ***************************************************************************/\r
+ #define WIN32_PORT_SAVE_WHEN_STOPPED 1\r
+ #define WIN32_PORT_EXIT_WHEN_STOPPED 1\r
\r
#endif\r
\r
-#if (SELECTED_PORT != PORT_NOT_SET)\r
-\r
- #ifndef HWTC_COUNT_DIRECTION\r
- #error "HWTC_COUNT_DIRECTION is not set!"\r
+#if (TRC_CFG_HARDWARE_PORT != TRC_HARDWARE_PORT_NOT_SET)\r
+ \r
+ #ifndef TRC_HWTC_TYPE\r
+ #error "TRC_HWTC_TYPE is not set!"\r
#endif\r
\r
- #ifndef HWTC_COUNT\r
- #error "HWTC_COUNT is not set!"\r
+ #ifndef TRC_HWTC_COUNT\r
+ #error "TRC_HWTC_COUNT is not set!"\r
#endif\r
\r
- #ifndef HWTC_PERIOD\r
- #error "HWTC_PERIOD is not set!"\r
+ #ifndef TRC_HWTC_PERIOD\r
+ #error "TRC_HWTC_PERIOD is not set!"\r
#endif\r
\r
- #ifndef HWTC_DIVISOR\r
- #error "HWTC_DIVISOR is not set!"\r
+ #ifndef TRC_HWTC_DIVISOR\r
+ #error "TRC_HWTC_DIVISOR is not set!"\r
#endif\r
\r
- #ifndef IRQ_PRIORITY_ORDER\r
- #error "IRQ_PRIORITY_ORDER is not set!"\r
- #elif (IRQ_PRIORITY_ORDER != 0) && (IRQ_PRIORITY_ORDER != 1)\r
- #error "IRQ_PRIORITY_ORDER has bad value!"\r
+ #ifndef TRC_IRQ_PRIORITY_ORDER\r
+ #error "TRC_IRQ_PRIORITY_ORDER is not set!"\r
+ #elif (TRC_IRQ_PRIORITY_ORDER != 0) && (TRC_IRQ_PRIORITY_ORDER != 1)\r
+ #error "TRC_IRQ_PRIORITY_ORDER has bad value!"\r
#endif\r
\r
- #if (HWTC_DIVISOR < 1)\r
- #error "HWTC_DIVISOR must be a non-zero positive value!"\r
+ #if (TRC_HWTC_DIVISOR < 1)\r
+ #error "TRC_HWTC_DIVISOR must be a non-zero positive value!"\r
#endif\r
-\r
+ \r
+ #ifndef TRC_HWTC_FREQ_HZ \r
+ #error "TRC_HWTC_FREQ_HZ not defined!"\r
+ #endif\r
+ \r
#endif\r
-/*******************************************************************************\r
- * vTraceConsoleMessage\r
- *\r
- * A wrapper for your system-specific console "printf" console output function.\r
- * This needs to be correctly defined to see status reports from the trace\r
- * status monitor task (this is defined in trcUser.c).\r
- ******************************************************************************/\r
-#define vTraceConsoleMessage(x)\r
-\r
-/*******************************************************************************\r
- * vTracePortGetTimeStamp\r
- *\r
- * Returns the current time based on the HWTC macros which provide a hardware\r
- * isolation layer towards the hardware timer/counter.\r
- *\r
- * The HWTC macros and vTracePortGetTimeStamp is the main porting issue\r
- * or the trace recorder library. Typically you should not need to change\r
- * the code of vTracePortGetTimeStamp if using the HWTC macros.\r
- *\r
- ******************************************************************************/\r
-void vTracePortGetTimeStamp(uint32_t *puiTimestamp);\r
\r
-#endif\r
+#endif /*TRC_SNAPSHOT_HARDWARE_PORT_H*/\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcKernel.h\r
- *\r
- * Functions used by trcKernelHooks.h.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Copyright Percepio AB, 2013.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#ifndef TRCKERNEL_H\r
-#define TRCKERNEL_H\r
-\r
-#include "trcKernelPort.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-/* Internal functions */\r
-\r
-#if !defined INCLUDE_READY_EVENTS || INCLUDE_READY_EVENTS == 1\r
- void vTraceSetReadyEventsEnabled(int status);\r
- void vTraceStoreTaskReady(objectHandleType handle);\r
-#else\r
- #define vTraceSetReadyEventsEnabled(status)\r
-#endif\r
-\r
-void vTraceStoreLowPower(uint32_t flag);\r
-\r
-void vTraceStoreTaskswitch(objectHandleType task_handle);\r
-\r
-void vTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t byteParam);\r
-\r
-void vTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode,\r
- uint32_t param);\r
-\r
-void vTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,\r
- uint32_t objectNumber, uint32_t param);\r
-\r
-void vTraceSetTaskInstanceFinished(objectHandleType handle);\r
-\r
-void vTraceSetPriorityProperty(uint8_t objectclass, objectHandleType id, uint8_t value);\r
-\r
-uint8_t uiTraceGetPriorityProperty(uint8_t objectclass, objectHandleType id);\r
-\r
-void vTraceSetObjectState(uint8_t objectclass, objectHandleType id, uint8_t value);\r
-\r
-uint8_t uiTraceGetObjectState(uint8_t objectclass, objectHandleType id);\r
-\r
-#if (INCLUDE_OBJECT_DELETE == 1)\r
-\r
-void vTraceStoreObjectNameOnCloseEvent(objectHandleType handle,\r
- traceObjectClass objectclass);\r
-\r
-void vTraceStoreObjectPropertiesOnCloseEvent(objectHandleType handle,\r
- traceObjectClass objectclass);\r
-#endif\r
-\r
-/* Internal constants for task state */\r
-#define TASK_STATE_INSTANCE_NOT_ACTIVE 0\r
-#define TASK_STATE_INSTANCE_ACTIVE 1\r
-\r
-#endif\r
-\r
-#endif\r
-\r
-\r
-\r
+++ /dev/null
-/*******************************************************************************\r
-* Tracealyzer v3.0.2 Recorder Library\r
-* Percepio AB, www.percepio.com\r
-*\r
-* trcKernelHooks.h\r
-*\r
-* The kernel integration hooks.\r
-*\r
-* NOTE:\r
-* For IAR Embedded Workbench for ARM, you need to have a preprocessor condition\r
-* on the include, to except it from the assembler step which otherwise give\r
-* compile-time errors.\r
-*\r
-* #ifdef __ICCARM__\r
-* #include "trcKernelPort.h"\r
-* #endif\r
-*\r
-* Terms of Use\r
-* This software is copyright Percepio AB. The recorder library is free for\r
-* use together with Percepio products. You may distribute the recorder library\r
-* in its original form, including modifications in trcPort.c and trcPort.h\r
-* given that these modification are clearly marked as your own modifications\r
-* and documented in the initial comment section of these source files.\r
-* This software is the intellectual property of Percepio AB and may not be\r
-* sold or in other ways commercially redistributed without explicit written\r
-* permission by Percepio AB.\r
-*\r
-* Disclaimer\r
-* The trace tool and recorder library is being delivered to you AS IS and\r
-* Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
-* not and cannot warrant the performance or results you may obtain by using the\r
-* software or documentation. Percepio AB make no warranties, express or\r
-* implied, as to noninfringement of third party rights, merchantability, or\r
-* fitness for any particular purpose. In no event will Percepio AB, its\r
-* technology partners, or distributors be liable to you for any consequential,\r
-* incidental or special damages, including any lost profits or lost savings,\r
-* even if a representative of Percepio AB has been advised of the possibility\r
-* of such damages, or for any claim by any third party. Some jurisdictions do\r
-* not allow the exclusion or limitation of incidental, consequential or special\r
-* damages, or the exclusion of implied warranties or limitations on how long an\r
-* implied warranty may last, so the above limitations may not apply to you.\r
-*\r
-* Copyright Percepio AB, 2013.\r
-* www.percepio.com\r
-******************************************************************************/\r
-\r
-#ifndef TRCKERNELHOOKS_H\r
-#define TRCKERNELHOOKS_H\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#undef INCLUDE_xTaskGetSchedulerState\r
-#define INCLUDE_xTaskGetSchedulerState 1\r
-\r
-#undef INCLUDE_xTaskGetCurrentTaskHandle\r
-#define INCLUDE_xTaskGetCurrentTaskHandle 1\r
-\r
-#ifndef INCLUDE_OBJECT_DELETE\r
-#define INCLUDE_OBJECT_DELETE 0\r
-#endif\r
-\r
-#ifndef INCLUDE_READY_EVENTS\r
-#define INCLUDE_READY_EVENTS 1\r
-#endif\r
-\r
-#ifndef INCLUDE_NEW_TIME_EVENTS\r
-#define INCLUDE_NEW_TIME_EVENTS 0\r
-#endif\r
-\r
-#if (INCLUDE_OBJECT_DELETE == 1)\r
-/* This macro will remove the task and store it in the event buffer */\r
-#undef trcKERNEL_HOOKS_TASK_DELETE\r
-#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB) \\r
- vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
- vTraceStoreObjectNameOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
- vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
- vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
- vTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \\r
- vTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
-#else\r
-#undef trcKERNEL_HOOKS_TASK_DELETE\r
-#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB)\r
-#endif\r
-\r
-#if (INCLUDE_OBJECT_DELETE == 1)\r
-/* This macro will remove the object and store it in the event buffer */\r
-#undef trcKERNEL_HOOKS_OBJECT_DELETE\r
-#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject) \\r
- vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
- vTraceStoreObjectNameOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
- vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
- vTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
-#else\r
-#undef trcKERNEL_HOOKS_OBJECT_DELETE\r
-#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject)\r
-#endif\r
-\r
-/* This macro will create a task in the object table */\r
-#undef trcKERNEL_HOOKS_TASK_CREATE\r
-#define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \\r
- TRACE_SET_TASK_NUMBER(pxTCB) \\r
- vTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \\r
- vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
- vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
-\r
-/* This macro will create a failed create call to create a task */\r
-#undef trcKERNEL_HOOKS_TASK_CREATE_FAILED\r
-#define trcKERNEL_HOOKS_TASK_CREATE_FAILED(SERVICE, CLASS) \\r
- vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, FAILED, CLASS, 0), TRACE_CLASS_TASK, 0);\r
-\r
-/* This macro will setup a task in the object table */\r
-#undef trcKERNEL_HOOKS_OBJECT_CREATE\r
-#define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\\r
- TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\\r
- vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
- vTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);\r
-\r
-/* This macro will create a failed create call to create an object */\r
-#undef trcKERNEL_HOOKS_OBJECT_CREATE_FAILED\r
-#define trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(SERVICE, CLASS, kernelClass) \\r
- vTraceStoreKernelCall(TRACE_GET_CLASS_EVENT_CODE(SERVICE, FAILED, CLASS, kernelClass), TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass), 0);\r
-\r
-/* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
-#undef trcKERNEL_HOOKS_KERNEL_SERVICE\r
-#define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, RESULT, CLASS, pxObject) \\r
- vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
-\r
-/* This macro will set the state for an object */\r
-#undef trcKERNEL_HOOKS_SET_OBJECT_STATE\r
-#define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \\r
- vTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), STATE);\r
-\r
-/* This macro will flag a certain task as a finished instance */\r
-#undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED\r
-#define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \\r
- vTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));\r
-\r
-#if INCLUDE_READY_EVENTS == 1\r
-/* This macro will create an event to indicate that a task became Ready */\r
-#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
-#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \\r
- vTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));\r
-#else\r
-#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
-#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)\r
-#endif\r
-\r
-/* This macro will update the internal tick counter and call vTracePortGetTimeStamp(0) to update the internal counters */\r
-#undef trcKERNEL_HOOKS_INCREMENT_TICK\r
-#define trcKERNEL_HOOKS_INCREMENT_TICK() \\r
- { extern uint32_t uiTraceTickCount; uiTraceTickCount++; vTracePortGetTimeStamp(0); }\r
-\r
-#if INCLUDE_NEW_TIME_EVENTS == 1\r
-/* This macro will create an event indicating that the OS tick count has increased */\r
-#undef trcKERNEL_HOOKS_NEW_TIME\r
-#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \\r
- vTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);\r
-#else\r
-#undef trcKERNEL_HOOKS_NEW_TIME\r
-#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)\r
-#endif\r
-\r
-/* This macro will create a task switch event to the currently executing task */\r
-#undef trcKERNEL_HOOKS_TASK_SWITCH\r
-#define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \\r
- vTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));\r
-\r
-/* This macro will create an event to indicate that the task has been suspended */\r
-#undef trcKERNEL_HOOKS_TASK_SUSPEND\r
-#define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \\r
- vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
- vTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
-\r
-/* This macro will create an event to indicate that a task has called a wait/delay function */\r
-#undef trcKERNEL_HOOKS_TASK_DELAY\r
-#define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \\r
- vTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \\r
- vTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
-\r
-/* This macro will create an event to indicate that a task has gotten its priority changed */\r
-#undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE\r
-#define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \\r
- vTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), uiTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\\r
- vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority);\r
-\r
-/* This macro will create an event to indicate that the task has been resumed */\r
-#undef trcKERNEL_HOOKS_TASK_RESUME\r
-#define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \\r
- vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
-\r
-#undef trcKERNEL_HOOKS_TIMER_EVENT\r
-#define trcKERNEL_HOOKS_TIMER_EVENT(SERVICE, pxTimer) \\r
- vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
-\r
-/* This macro will create a timer in the object table and assign the timer a trace handle (timer number).*/\r
-#undef trcKERNEL_HOOKS_TIMER_CREATE\r
-#define trcKERNEL_HOOKS_TIMER_CREATE(SERVICE, pxTimer) \\r
-TRACE_SET_TIMER_NUMBER(pxTimer); \\r
-vTraceSetObjectName(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_GET_TIMER_NAME(pxTimer)); \\r
-vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
-#endif\r
-\r
-#undef trcKERNEL_HOOKS_TIMER_DELETE\r
-#define trcKERNEL_HOOKS_TIMER_DELETE(SERVICE, pxTimer) \\r
-vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer)); \\r
-vTraceStoreObjectNameOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
-vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
-vTraceFreeObjectHandle(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
-\r
-#endif /* TRCKERNELHOOKS_H */\r
-\r
-\r
-\r
/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
* Percepio AB, www.percepio.com\r
*\r
- * trcKernelPort.h\r
- *\r
- * Kernel-specific functionality for FreeRTOS, used by the recorder library.\r
- *\r
* Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
*\r
* Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * FreeRTOS-specific definitions needed by the trace recorder\r
+ *\r
+ * <LICENSE INFO>\r
*\r
* Tabs are used for indent in this file (1 tab = 4 spaces)\r
*\r
- * Copyright Percepio AB, 2014.\r
+ * Copyright Percepio AB, 2017.\r
* www.percepio.com\r
******************************************************************************/\r
\r
-\r
-#ifndef TRCKERNELPORTFREERTOS_H\r
-#define TRCKERNELPORTFREERTOS_H\r
+#ifndef TRC_KERNEL_PORT_H\r
+#define TRC_KERNEL_PORT_H\r
\r
#include "FreeRTOS.h" /* Defines configUSE_TRACE_FACILITY */\r
-#include "trcHardwarePort.h"\r
+#include "trcPortDefines.h"\r
\r
-extern int uiInEventGroupSetBitsFromISR;\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define TRC_USE_TRACEALYZER_RECORDER configUSE_TRACE_FACILITY\r
+\r
+/*** FreeRTOS version codes **************************************************/\r
+#define FREERTOS_VERSION_NOT_SET 0\r
+#define TRC_FREERTOS_VERSION_7_3_OR_7_4 1\r
+#define TRC_FREERTOS_VERSION_7_5_OR_7_6 2\r
+#define TRC_FREERTOS_VERSION_8_X 3\r
+#define TRC_FREERTOS_VERSION_9_X 4\r
+\r
+#if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
+\r
+/*******************************************************************************\r
+ * INCLUDE_xTaskGetCurrentTaskHandle must be set to 1 for tracing to work properly\r
+ ******************************************************************************/\r
+#undef INCLUDE_xTaskGetCurrentTaskHandle\r
+#define INCLUDE_xTaskGetCurrentTaskHandle 1\r
+\r
+/*******************************************************************************\r
+ * vTraceSetQueueName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Queue that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Queue objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetQueueName(void* object, const char* name);\r
+\r
+/*******************************************************************************\r
+ * vTraceSetSemaphoreName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Semaphore that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Semaphore objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetSemaphoreName(void* object, const char* name);\r
+\r
+/*******************************************************************************\r
+ * vTraceSetMutexName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Mutex that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Semaphore objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetMutexName(void* object, const char* name);\r
\r
-#define USE_TRACEALYZER_RECORDER configUSE_TRACE_FACILITY\r
+/*******************************************************************************\r
+ * Note: Setting names for event groups is difficult to support, this has been \r
+ * excluded intentionally. This since we don't know if event_groups.c is \r
+ * included in the build, so referencing it from the recorder may cause errors.\r
+ ******************************************************************************/\r
\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
+/* Gives the currently executing task (wrapper for RTOS-specific function) */\r
+void* prvTraceGetCurrentTaskHandle(void);\r
+\r
+#if (((TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (TRC_CFG_INCLUDE_ISR_TRACING == 1)) || (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING))\r
+/* Tells if the scheduler currently is suspended (task-switches can't occur) */\r
+unsigned char prvTraceIsSchedulerSuspended(void);\r
+\r
+/*******************************************************************************\r
+ * INCLUDE_xTaskGetSchedulerState must be set to 1 for tracing to work properly\r
+ ******************************************************************************/\r
+#undef INCLUDE_xTaskGetSchedulerState\r
+#define INCLUDE_xTaskGetSchedulerState 1\r
+\r
+#endif /* (((TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) && (TRC_CFG_INCLUDE_ISR_TRACING == 1)) || (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)) */\r
\r
-/* Defines that must be set for the recorder to work properly */\r
#define TRACE_KERNEL_VERSION 0x1AA1\r
#define TRACE_TICK_RATE_HZ configTICK_RATE_HZ /* Defined in "FreeRTOS.h" */\r
#define TRACE_CPU_CLOCK_HZ configCPU_CLOCK_HZ /* Defined in "FreeRTOSConfig.h" */\r
+#define TRACE_GET_CURRENT_TASK() prvTraceGetCurrentTaskHandle()\r
\r
-#if (SELECTED_PORT == PORT_ARM_CortexM)\r
-\r
- /* Uses CMSIS API */\r
+#define TRACE_GET_OS_TICKS() (uiTraceTickCount) /* Streaming only */\r
\r
- #define TRACE_SR_ALLOC_CRITICAL_SECTION() int __irq_status;\r
- #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = __get_PRIMASK(); __set_PRIMASK(1);}\r
- #define TRACE_EXIT_CRITICAL_SECTION() {__set_PRIMASK(__irq_status);}\r
+/* If using dynamic allocation of snapshot trace buffer... */\r
+#define TRACE_MALLOC(size) pvPortMalloc(size) \r
\r
-#endif\r
+#ifdef configUSE_TIMERS\r
+#if (configUSE_TIMERS == 1)\r
+#undef INCLUDE_xTimerGetTimerDaemonTaskHandle\r
+#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1\r
+#endif /* configUSE_TIMERS == 1*/\r
+#endif /* configUSE_TIMERS */\r
\r
-#if (SELECTED_PORT == PORT_ARM_CORTEX_M0)\r
- #define TRACE_SR_ALLOC_CRITICAL_SECTION() int __irq_status;\r
- #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}\r
- #define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}\r
+/* For ARM Cortex-M devices - assumes the ARM CMSIS API is available */\r
+#if (defined (__CORTEX_M)) \r
+ #define TRACE_ALLOC_CRITICAL_SECTION() uint32_t __irq_status;\r
+ #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = __get_PRIMASK(); __set_PRIMASK(1);} /* PRIMASK disables ALL interrupts - allows for tracing in any ISR */\r
+ #define TRACE_EXIT_CRITICAL_SECTION() {__set_PRIMASK(__irq_status);}\r
#endif\r
\r
-#if ((SELECTED_PORT == PORT_ARM_CORTEX_A9) || (SELECTED_PORT == PORT_Renesas_RX600) || (SELECTED_PORT == PORT_MICROCHIP_PIC32MX) || (SELECTED_PORT == PORT_MICROCHIP_PIC32MZ))\r
- #define TRACE_SR_ALLOC_CRITICAL_SECTION() int __irq_status;\r
+#if ((TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_CORTEX_A9) || (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Renesas_RX600) || (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32))\r
+ #define TRACE_ALLOC_CRITICAL_SECTION() int __irq_status;\r
#define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}\r
#define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}\r
#endif\r
\r
-#if (SELECTED_PORT == PORT_Win32)\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)\r
/* In the Win32 port, there are no real interrupts, so we can use the normal critical sections */\r
- #define TRACE_SR_ALLOC_CRITICAL_SECTION()\r
+ #define TRACE_ALLOC_CRITICAL_SECTION()\r
#define TRACE_ENTER_CRITICAL_SECTION() portENTER_CRITICAL()\r
#define TRACE_EXIT_CRITICAL_SECTION() portEXIT_CRITICAL()\r
#endif\r
\r
-#ifndef TRACE_ENTER_CRITICAL_SECTION\r
- #error "This port has no valid definition for critical sections! See http://percepio.com/2014/10/27/how-to-define-critical-sections-for-the-recorder/"\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_POWERPC_Z4)\r
+#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)\r
+ /* FreeRTOS v8.0 or later */ \r
+ #define TRACE_ALLOC_CRITICAL_SECTION() UBaseType_t __irq_status;\r
+ #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}\r
+ #define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}\r
+#else \r
+ /* FreeRTOS v7.x */\r
+ #define TRACE_ALLOC_CRITICAL_SECTION() unsigned portBASE_TYPE __irq_status;\r
+ #define TRACE_ENTER_CRITICAL_SECTION() {__irq_status = portSET_INTERRUPT_MASK_FROM_ISR();}\r
+ #define TRACE_EXIT_CRITICAL_SECTION() {portCLEAR_INTERRUPT_MASK_FROM_ISR(__irq_status);}\r
+#endif\r
#endif\r
\r
-#if (SELECTED_PORT == PORT_ARM_CortexM)\r
- #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_BEGIN\r
- #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_END\r
-#else\r
- #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY() recorder_busy++;\r
- #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY() recorder_busy--;\r
+#ifndef TRACE_ENTER_CRITICAL_SECTION\r
+ #error "This hardware port has no definition for critical sections! See http://percepio.com/2014/10/27/how-to-define-critical-sections-for-the-recorder/"\r
#endif\r
\r
-/*************************************************************************/\r
-/* KERNEL SPECIFIC OBJECT CONFIGURATION */\r
-/*************************************************************************/\r
+/******************************************************************************/\r
+/*** Definitions for Snapshot mode ********************************************/\r
+/******************************************************************************/\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+\r
+/*** The object classes *******************************************************/\r
+\r
#define TRACE_NCLASSES 7\r
#define TRACE_CLASS_QUEUE ((traceObjectClass)0)\r
#define TRACE_CLASS_SEMAPHORE ((traceObjectClass)1)\r
#define TRACE_CLASS_TIMER ((traceObjectClass)5)\r
#define TRACE_CLASS_EVENTGROUP ((traceObjectClass)6)\r
\r
-#define TRACE_KERNEL_OBJECT_COUNT (NQueue + NSemaphore + NMutex + NTask + NISR + NTimer + NEventGroup)\r
-\r
-/* The size of the Object Property Table entries, in bytes, per object */\r
+/*** Definitions for Object Table ********************************************/\r
+#define TRACE_KERNEL_OBJECT_COUNT (TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR + TRC_CFG_NTIMER + TRC_CFG_NEVENTGROUP)\r
\r
/* Queue properties (except name): current number of message in queue */\r
-#define PropertyTableSizeQueue (NameLenQueue + 1)\r
+#define PropertyTableSizeQueue (TRC_CFG_NAME_LEN_QUEUE + 1)\r
\r
/* Semaphore properties (except name): state (signaled = 1, cleared = 0) */\r
-#define PropertyTableSizeSemaphore (NameLenSemaphore + 1)\r
+#define PropertyTableSizeSemaphore (TRC_CFG_NAME_LEN_SEMAPHORE + 1)\r
\r
/* Mutex properties (except name): owner (task handle, 0 = free) */\r
-#define PropertyTableSizeMutex (NameLenMutex + 1)\r
+#define PropertyTableSizeMutex (TRC_CFG_NAME_LEN_MUTEX + 1)\r
\r
/* Task properties (except name): Byte 0: Current priority\r
Byte 1: state (if already active)\r
Byte 2: legacy, not used\r
Byte 3: legacy, not used */\r
-#define PropertyTableSizeTask (NameLenTask + 4)\r
+#define PropertyTableSizeTask (TRC_CFG_NAME_LEN_TASK + 4)\r
\r
/* ISR properties: Byte 0: priority\r
Byte 1: state (if already active) */\r
-#define PropertyTableSizeISR (NameLenISR + 2)\r
+#define PropertyTableSizeISR (TRC_CFG_NAME_LEN_ISR + 2)\r
\r
-/* NTimer properties: Byte 0: state (unused for now) */\r
-#define PropertyTableSizeTimer (NameLenTimer + 1)\r
+/* TRC_CFG_NTIMER properties: Byte 0: state (unused for now) */\r
+#define PropertyTableSizeTimer (TRC_CFG_NAME_LEN_TIMER + 1)\r
\r
-/* NEventGroup properties: Byte 0-3: state (unused for now)*/\r
-#define PropertyTableSizeEventGroup (NameLenEventGroup + 4)\r
+/* TRC_CFG_NEVENTGROUP properties: Byte 0-3: state (unused for now)*/\r
+#define PropertyTableSizeEventGroup (TRC_CFG_NAME_LEN_EVENTGROUP + 4)\r
\r
\r
/* The layout of the byte array representing the Object Property Table */\r
#define StartIndexQueue 0\r
-#define StartIndexSemaphore StartIndexQueue + NQueue * PropertyTableSizeQueue\r
-#define StartIndexMutex StartIndexSemaphore + NSemaphore * PropertyTableSizeSemaphore\r
-#define StartIndexTask StartIndexMutex + NMutex * PropertyTableSizeMutex\r
-#define StartIndexISR StartIndexTask + NTask * PropertyTableSizeTask\r
-#define StartIndexTimer StartIndexISR + NISR * PropertyTableSizeISR\r
-#define StartIndexEventGroup StartIndexTimer + NTimer * PropertyTableSizeTimer\r
+#define StartIndexSemaphore StartIndexQueue + TRC_CFG_NQUEUE * PropertyTableSizeQueue\r
+#define StartIndexMutex StartIndexSemaphore + TRC_CFG_NSEMAPHORE * PropertyTableSizeSemaphore\r
+#define StartIndexTask StartIndexMutex + TRC_CFG_NMUTEX * PropertyTableSizeMutex\r
+#define StartIndexISR StartIndexTask + TRC_CFG_NTASK * PropertyTableSizeTask\r
+#define StartIndexTimer StartIndexISR + TRC_CFG_NISR * PropertyTableSizeISR\r
+#define StartIndexEventGroup StartIndexTimer + TRC_CFG_NTIMER * PropertyTableSizeTimer\r
\r
/* Number of bytes used by the object table */\r
-#define TRACE_OBJECT_TABLE_SIZE StartIndexEventGroup + NEventGroup * PropertyTableSizeEventGroup\r
-\r
-#define FREERTOS_VERSION_NOT_SET 0\r
-#define FREERTOS_VERSION_7_3_OR_7_4 1\r
-#define FREERTOS_VERSION_7_5_OR_7_6 2\r
-#define FREERTOS_VERSION_8_0_OR_LATER 3\r
-\r
-/* Includes */\r
-#include "trcConfig.h" /* Must be first, even before trcTypes.h */\r
-#include "trcHardwarePort.h"\r
-#include "trcTypes.h"\r
-#include "trcKernelHooks.h"\r
-#include "trcBase.h"\r
-#include "trcKernel.h"\r
-#include "trcUser.h"\r
-\r
-#if (INCLUDE_NEW_TIME_EVENTS == 1 && configUSE_TICKLESS_IDLE != 0)\r
- #error "NewTime events can not be used in combination with tickless idle!"\r
-#endif\r
+#define TRACE_OBJECT_TABLE_SIZE StartIndexEventGroup + TRC_CFG_NEVENTGROUP * PropertyTableSizeEventGroup\r
+\r
+///*** FreeRTOS version codes **************************************************/\r
+//#define FREERTOS_VERSION_NOT_SET 0\r
+//#define TRC_FREERTOS_VERSION_7_3_OR_7_4 1\r
+//#define TRC_FREERTOS_VERSION_7_5_OR_7_6 2\r
+//#define TRC_FREERTOS_VERSION_8_X 3\r
+//#define TRC_FREERTOS_VERSION_9_X 4\r
+\r
+\r
+/* Flag to tell the context of tracePEND_FUNC_CALL_FROM_ISR */\r
+extern int uiInEventGroupSetBitsFromISR;\r
\r
/* Initialization of the object property table */\r
void vTraceInitObjectPropertyTable(void);\r
\r
-/* Initialization of the handle mechanism, see e.g, xTraceGetObjectHandle */\r
+/* Initialization of the handle mechanism, see e.g, prvTraceGetObjectHandle */\r
void vTraceInitObjectHandleStack(void);\r
\r
/* Returns the "Not enough handles" error message for the specified object class */\r
const char* pszTraceGetErrorNotEnoughHandles(traceObjectClass objectclass);\r
\r
-/*******************************************************************************\r
- * The event codes - should match the offline config file.\r
- *\r
- * Some sections below are encoded to allow for constructions like:\r
- *\r
- * vTraceStoreKernelCall(EVENTGROUP_CREATE + objectclass, ...\r
- *\r
- * The object class ID is given by the three LSB bits, in such cases. Since each\r
- * object class has a separate object property table, the class ID is needed to\r
- * know what section in the object table to use for getting an object name from\r
- * an object handle.\r
- ******************************************************************************/\r
+traceHandle prvTraceGetObjectNumber(void* handle);\r
+\r
+uint8_t prvTraceGetObjectType(void* handle);\r
+\r
+traceHandle prvTraceGetTaskNumber(void* handle);\r
+\r
+void* prvTraceGetCurrentTaskHandle(void);\r
+\r
+uint8_t uiTraceIsObjectExcluded(traceObjectClass objectclass, traceHandle handle);\r
+\r
+#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)\r
+traceHandle prvTraceGetEventGroupNumber(void* handle);\r
+#endif\r
+\r
+/******************************************************************************\r
+ * TraceObjectClassTable\r
+ * Translates a FreeRTOS QueueType into trace objects classes (TRACE_CLASS_).\r
+ * Has one entry for each QueueType, gives TRACE_CLASS ID.\r
+ ******************************************************************************/ \r
+extern traceObjectClass TraceObjectClassTable[5];\r
+\r
+\r
+/*** Event codes for snapshot mode - must match Tracealyzer config files ******/\r
\r
-#define NULL_EVENT (0x00) /* Ignored in the analysis*/\r
+#define NULL_EVENT (0x00UL)\r
\r
/*******************************************************************************\r
* EVENTGROUP_DIV\r
*\r
* Miscellaneous events.\r
******************************************************************************/\r
-#define EVENTGROUP_DIV (NULL_EVENT + 1) /*0x01*/\r
-#define DIV_XPS (EVENTGROUP_DIV + 0) /*0x01*/\r
-#define DIV_TASK_READY (EVENTGROUP_DIV + 1) /*0x02*/\r
-#define DIV_NEW_TIME (EVENTGROUP_DIV + 2) /*0x03*/\r
+#define EVENTGROUP_DIV (NULL_EVENT + 1UL) /*0x01*/\r
+#define DIV_XPS (EVENTGROUP_DIV + 0UL) /*0x01*/\r
+#define DIV_TASK_READY (EVENTGROUP_DIV + 1UL) /*0x02*/\r
+#define DIV_NEW_TIME (EVENTGROUP_DIV + 2UL) /*0x03*/\r
\r
/*******************************************************************************\r
* EVENTGROUP_TS\r
* Events for storing task-switches and interrupts. The RESUME events are\r
* generated if the task/interrupt is already marked active.\r
******************************************************************************/\r
-#define EVENTGROUP_TS (EVENTGROUP_DIV + 3) /*0x04*/\r
-#define TS_ISR_BEGIN (EVENTGROUP_TS + 0) /*0x04*/\r
-#define TS_ISR_RESUME (EVENTGROUP_TS + 1) /*0x05*/\r
-#define TS_TASK_BEGIN (EVENTGROUP_TS + 2) /*0x06*/\r
-#define TS_TASK_RESUME (EVENTGROUP_TS + 3) /*0x07*/\r
+#define EVENTGROUP_TS (EVENTGROUP_DIV + 3UL) /*0x04*/\r
+#define TS_ISR_BEGIN (EVENTGROUP_TS + 0UL) /*0x04*/\r
+#define TS_ISR_RESUME (EVENTGROUP_TS + 1UL) /*0x05*/\r
+#define TS_TASK_BEGIN (EVENTGROUP_TS + 2UL) /*0x06*/\r
+#define TS_TASK_RESUME (EVENTGROUP_TS + 3UL) /*0x07*/\r
\r
/*******************************************************************************\r
* EVENTGROUP_OBJCLOSE_NAME\r
* EVENTGROUP_OBJCLOSE_PROP), containing the handle-name mapping and object\r
* properties valid up to this point.\r
******************************************************************************/\r
-#define EVENTGROUP_OBJCLOSE_NAME (EVENTGROUP_TS + 4) /*0x08*/\r
+#define EVENTGROUP_OBJCLOSE_NAME (EVENTGROUP_TS + 4UL) /*0x08*/\r
\r
/*******************************************************************************\r
* EVENTGROUP_OBJCLOSE_PROP\r
* handle. The lower three bits are not used (always zero) when queues are\r
* closed since the queue type is given in the previous OBJCLOSE_NAME event.\r
******************************************************************************/\r
-#define EVENTGROUP_OBJCLOSE_PROP (EVENTGROUP_OBJCLOSE_NAME + 8) /*0x10*/\r
+#define EVENTGROUP_OBJCLOSE_PROP (EVENTGROUP_OBJCLOSE_NAME + 8UL) /*0x10*/\r
\r
/*******************************************************************************\r
* EVENTGROUP_CREATE\r
* The lower three bits in the event code gives the object class, i.e., type of\r
* create operation (task, queue, semaphore, etc).\r
******************************************************************************/\r
-#define EVENTGROUP_CREATE_OBJ_SUCCESS (EVENTGROUP_OBJCLOSE_PROP + 8) /*0x18*/\r
+#define EVENTGROUP_CREATE_OBJ_SUCCESS (EVENTGROUP_OBJCLOSE_PROP + 8UL) /*0x18*/\r
\r
/*******************************************************************************\r
* EVENTGROUP_SEND\r
* object class, i.e., what type of object that is operated on (queue, semaphore\r
* or mutex).\r
******************************************************************************/\r
-#define EVENTGROUP_SEND_SUCCESS (EVENTGROUP_CREATE_OBJ_SUCCESS + 8) /*0x20*/\r
+#define EVENTGROUP_SEND_SUCCESS (EVENTGROUP_CREATE_OBJ_SUCCESS + 8UL) /*0x20*/\r
\r
/*******************************************************************************\r
* EVENTGROUP_RECEIVE\r
* object class, i.e., what type of object that is operated on (queue, semaphore\r
* or mutex).\r
******************************************************************************/\r
-#define EVENTGROUP_RECEIVE_SUCCESS (EVENTGROUP_SEND_SUCCESS + 8) /*0x28*/\r
+#define EVENTGROUP_RECEIVE_SUCCESS (EVENTGROUP_SEND_SUCCESS + 8UL) /*0x28*/\r
\r
/* Send/Give operations, from ISR */\r
#define EVENTGROUP_SEND_FROM_ISR_SUCCESS \\r
- (EVENTGROUP_RECEIVE_SUCCESS + 8) /*0x30*/\r
+ (EVENTGROUP_RECEIVE_SUCCESS + 8UL) /*0x30*/\r
\r
/* Receive/Take operations, from ISR */\r
#define EVENTGROUP_RECEIVE_FROM_ISR_SUCCESS \\r
- (EVENTGROUP_SEND_FROM_ISR_SUCCESS + 8) /*0x38*/\r
+ (EVENTGROUP_SEND_FROM_ISR_SUCCESS + 8UL) /*0x38*/\r
\r
/* "Failed" event type versions of above (timeout, failed allocation, etc) */\r
#define EVENTGROUP_KSE_FAILED \\r
- (EVENTGROUP_RECEIVE_FROM_ISR_SUCCESS + 8) /*0x40*/\r
+ (EVENTGROUP_RECEIVE_FROM_ISR_SUCCESS + 8UL) /*0x40*/\r
\r
/* Failed create calls - memory allocation failed */\r
#define EVENTGROUP_CREATE_OBJ_FAILED (EVENTGROUP_KSE_FAILED) /*0x40*/\r
\r
/* Failed send/give - timeout! */\r
-#define EVENTGROUP_SEND_FAILED (EVENTGROUP_CREATE_OBJ_FAILED + 8) /*0x48*/\r
+#define EVENTGROUP_SEND_FAILED (EVENTGROUP_CREATE_OBJ_FAILED + 8UL) /*0x48*/\r
\r
/* Failed receive/take - timeout! */\r
-#define EVENTGROUP_RECEIVE_FAILED (EVENTGROUP_SEND_FAILED + 8) /*0x50*/\r
+#define EVENTGROUP_RECEIVE_FAILED (EVENTGROUP_SEND_FAILED + 8UL) /*0x50*/\r
\r
/* Failed non-blocking send/give - queue full */\r
-#define EVENTGROUP_SEND_FROM_ISR_FAILED (EVENTGROUP_RECEIVE_FAILED + 8) /*0x58*/\r
+#define EVENTGROUP_SEND_FROM_ISR_FAILED (EVENTGROUP_RECEIVE_FAILED + 8UL) /*0x58*/\r
\r
/* Failed non-blocking receive/take - queue empty */\r
#define EVENTGROUP_RECEIVE_FROM_ISR_FAILED \\r
- (EVENTGROUP_SEND_FROM_ISR_FAILED + 8) /*0x60*/\r
+ (EVENTGROUP_SEND_FROM_ISR_FAILED + 8UL) /*0x60*/\r
\r
/* Events when blocking on receive/take */\r
#define EVENTGROUP_RECEIVE_BLOCK \\r
- (EVENTGROUP_RECEIVE_FROM_ISR_FAILED + 8) /*0x68*/\r
+ (EVENTGROUP_RECEIVE_FROM_ISR_FAILED + 8UL) /*0x68*/\r
\r
/* Events when blocking on send/give */\r
-#define EVENTGROUP_SEND_BLOCK (EVENTGROUP_RECEIVE_BLOCK + 8) /*0x70*/\r
+#define EVENTGROUP_SEND_BLOCK (EVENTGROUP_RECEIVE_BLOCK + 8UL) /*0x70*/\r
\r
/* Events on queue peek (receive) */\r
-#define EVENTGROUP_PEEK_SUCCESS (EVENTGROUP_SEND_BLOCK + 8) /*0x78*/\r
+#define EVENTGROUP_PEEK_SUCCESS (EVENTGROUP_SEND_BLOCK + 8UL) /*0x78*/\r
\r
/* Events on object delete (vTaskDelete or vQueueDelete) */\r
-#define EVENTGROUP_DELETE_OBJ_SUCCESS (EVENTGROUP_PEEK_SUCCESS + 8) /*0x80*/\r
+#define EVENTGROUP_DELETE_OBJ_SUCCESS (EVENTGROUP_PEEK_SUCCESS + 8UL) /*0x80*/\r
\r
/* Other events - object class is implied: TASK */\r
-#define EVENTGROUP_OTHERS (EVENTGROUP_DELETE_OBJ_SUCCESS + 8) /*0x88*/\r
-#define TASK_DELAY_UNTIL (EVENTGROUP_OTHERS + 0) /*0x88*/\r
-#define TASK_DELAY (EVENTGROUP_OTHERS + 1) /*0x89*/\r
-#define TASK_SUSPEND (EVENTGROUP_OTHERS + 2) /*0x8A*/\r
-#define TASK_RESUME (EVENTGROUP_OTHERS + 3) /*0x8B*/\r
-#define TASK_RESUME_FROM_ISR (EVENTGROUP_OTHERS + 4) /*0x8C*/\r
-#define TASK_PRIORITY_SET (EVENTGROUP_OTHERS + 5) /*0x8D*/\r
-#define TASK_PRIORITY_INHERIT (EVENTGROUP_OTHERS + 6) /*0x8E*/\r
-#define TASK_PRIORITY_DISINHERIT (EVENTGROUP_OTHERS + 7) /*0x8F*/\r
-\r
-#define EVENTGROUP_MISC_PLACEHOLDER (EVENTGROUP_OTHERS + 8) /*0x90*/\r
-#define PEND_FUNC_CALL (EVENTGROUP_MISC_PLACEHOLDER+0) /*0x90*/\r
-#define PEND_FUNC_CALL_FROM_ISR (EVENTGROUP_MISC_PLACEHOLDER+1) /*0x91*/\r
-#define PEND_FUNC_CALL_FAILED (EVENTGROUP_MISC_PLACEHOLDER+2) /*0x92*/\r
-#define PEND_FUNC_CALL_FROM_ISR_FAILED (EVENTGROUP_MISC_PLACEHOLDER+3) /*0x93*/\r
-#define MEM_MALLOC_SIZE (EVENTGROUP_MISC_PLACEHOLDER+4) /*0x94*/\r
-#define MEM_MALLOC_ADDR (EVENTGROUP_MISC_PLACEHOLDER+5) /*0x95*/\r
-#define MEM_FREE_SIZE (EVENTGROUP_MISC_PLACEHOLDER+6) /*0x96*/\r
-#define MEM_FREE_ADDR (EVENTGROUP_MISC_PLACEHOLDER+7) /*0x97*/\r
+#define EVENTGROUP_OTHERS (EVENTGROUP_DELETE_OBJ_SUCCESS + 8UL) /*0x88*/\r
+#define TASK_DELAY_UNTIL (EVENTGROUP_OTHERS + 0UL) /*0x88*/\r
+#define TASK_DELAY (EVENTGROUP_OTHERS + 1UL) /*0x89*/\r
+#define TASK_SUSPEND (EVENTGROUP_OTHERS + 2UL) /*0x8A*/\r
+#define TASK_RESUME (EVENTGROUP_OTHERS + 3UL) /*0x8B*/\r
+#define TASK_RESUME_FROM_ISR (EVENTGROUP_OTHERS + 4UL) /*0x8C*/\r
+#define TASK_PRIORITY_SET (EVENTGROUP_OTHERS + 5UL) /*0x8D*/\r
+#define TASK_PRIORITY_INHERIT (EVENTGROUP_OTHERS + 6UL) /*0x8E*/\r
+#define TASK_PRIORITY_DISINHERIT (EVENTGROUP_OTHERS + 7UL) /*0x8F*/\r
+\r
+#define EVENTGROUP_MISC_PLACEHOLDER (EVENTGROUP_OTHERS + 8UL) /*0x90*/\r
+#define PEND_FUNC_CALL (EVENTGROUP_MISC_PLACEHOLDER+0UL) /*0x90*/\r
+#define PEND_FUNC_CALL_FROM_ISR (EVENTGROUP_MISC_PLACEHOLDER+1UL) /*0x91*/\r
+#define PEND_FUNC_CALL_FAILED (EVENTGROUP_MISC_PLACEHOLDER+2UL) /*0x92*/\r
+#define PEND_FUNC_CALL_FROM_ISR_FAILED (EVENTGROUP_MISC_PLACEHOLDER+3UL) /*0x93*/\r
+#define MEM_MALLOC_SIZE (EVENTGROUP_MISC_PLACEHOLDER+4UL) /*0x94*/\r
+#define MEM_MALLOC_ADDR (EVENTGROUP_MISC_PLACEHOLDER+5UL) /*0x95*/\r
+#define MEM_FREE_SIZE (EVENTGROUP_MISC_PLACEHOLDER+6UL) /*0x96*/\r
+#define MEM_FREE_ADDR (EVENTGROUP_MISC_PLACEHOLDER+7UL) /*0x97*/\r
\r
/* User events */\r
-#define EVENTGROUP_USEREVENT (EVENTGROUP_MISC_PLACEHOLDER + 8) /*0x98*/\r
-#define USER_EVENT (EVENTGROUP_USEREVENT + 0)\r
+#define EVENTGROUP_USEREVENT (EVENTGROUP_MISC_PLACEHOLDER + 8UL) /*0x98*/\r
+#define USER_EVENT (EVENTGROUP_USEREVENT + 0UL)\r
\r
/* Allow for 0-15 arguments (the number of args is added to event code) */\r
-#define USER_EVENT_LAST (EVENTGROUP_USEREVENT + 15) /*0xA7*/\r
+#define USER_EVENT_LAST (EVENTGROUP_USEREVENT + 15UL) /*0xA7*/\r
\r
/*******************************************************************************\r
* XTS Event - eXtended TimeStamp events\r
* bytes are stored in the normal DTS field.\r
* There are two types of XTS events, XTS8 and XTS16. An XTS8 event is stored\r
* when there is only room for 1 byte (8 bit) DTS data in the original event,\r
- * which means a limit of 0xFF (255). The XTS16 is used when the original event\r
- * has a 16 bit DTS field and thereby can handle values up to 0xFFFF (65535).\r
+ * which means a limit of 0xFF (255UL). The XTS16 is used when the original event\r
+ * has a 16 bit DTS field and thereby can handle values up to 0xFFFF (65535UL).\r
*\r
* Using a very high frequency time base can result in many XTS events.\r
* Preferably, the time between two OS ticks should fit in 16 bits, i.e.,\r
* the TRACE\r
******************************************************************************/\r
\r
-#define EVENTGROUP_SYS (EVENTGROUP_USEREVENT + 16) /*0xA8*/\r
-#define XTS8 (EVENTGROUP_SYS + 0) /*0xA8*/\r
-#define XTS16 (EVENTGROUP_SYS + 1) /*0xA9*/\r
-#define EVENT_BEING_WRITTEN (EVENTGROUP_SYS + 2) /*0xAA*/\r
-#define RESERVED_DUMMY_CODE (EVENTGROUP_SYS + 3) /*0xAB*/\r
-#define LOW_POWER_BEGIN (EVENTGROUP_SYS + 4) /*0xAC*/\r
-#define LOW_POWER_END (EVENTGROUP_SYS + 5) /*0xAD*/\r
-#define XID (EVENTGROUP_SYS + 6) /*0xAE*/\r
-#define XTS16L (EVENTGROUP_SYS + 7) /*0xAF*/\r
-\r
-#define EVENTGROUP_TIMER (EVENTGROUP_SYS + 8) /*0xB0*/\r
-#define TIMER_CREATE (EVENTGROUP_TIMER + 0) /*0xB0*/\r
-#define TIMER_START (EVENTGROUP_TIMER + 1) /*0xB1*/\r
-#define TIMER_RST (EVENTGROUP_TIMER + 2) /*0xB2*/\r
-#define TIMER_STOP (EVENTGROUP_TIMER + 3) /*0xB3*/\r
-#define TIMER_CHANGE_PERIOD (EVENTGROUP_TIMER + 4) /*0xB4*/\r
-#define TIMER_DELETE (EVENTGROUP_TIMER + 5) /*0xB5*/\r
-#define TIMER_START_FROM_ISR (EVENTGROUP_TIMER + 6) /*0xB6*/\r
-#define TIMER_RESET_FROM_ISR (EVENTGROUP_TIMER + 7) /*0xB7*/\r
-#define TIMER_STOP_FROM_ISR (EVENTGROUP_TIMER + 8) /*0xB8*/\r
-\r
-#define TIMER_CREATE_FAILED (EVENTGROUP_TIMER + 9) /*0xB9*/\r
-#define TIMER_START_FAILED (EVENTGROUP_TIMER + 10) /*0xBA*/\r
-#define TIMER_RESET_FAILED (EVENTGROUP_TIMER + 11) /*0xBB*/\r
-#define TIMER_STOP_FAILED (EVENTGROUP_TIMER + 12) /*0xBC*/\r
-#define TIMER_CHANGE_PERIOD_FAILED (EVENTGROUP_TIMER + 13) /*0xBD*/\r
-#define TIMER_DELETE_FAILED (EVENTGROUP_TIMER + 14) /*0xBE*/\r
-#define TIMER_START_FROM_ISR_FAILED (EVENTGROUP_TIMER + 15) /*0xBF*/\r
-#define TIMER_RESET_FROM_ISR_FAILED (EVENTGROUP_TIMER + 16) /*0xC0*/\r
-#define TIMER_STOP_FROM_ISR_FAILED (EVENTGROUP_TIMER + 17) /*0xC1*/\r
-\r
-#define EVENTGROUP_EG (EVENTGROUP_TIMER + 18) /*0xC2*/\r
-#define EVENT_GROUP_CREATE (EVENTGROUP_EG + 0) /*0xC2*/\r
-#define EVENT_GROUP_CREATE_FAILED (EVENTGROUP_EG + 1) /*0xC3*/\r
-#define EVENT_GROUP_SYNC_BLOCK (EVENTGROUP_EG + 2) /*0xC4*/\r
-#define EVENT_GROUP_SYNC_END (EVENTGROUP_EG + 3) /*0xC5*/\r
-#define EVENT_GROUP_WAIT_BITS_BLOCK (EVENTGROUP_EG + 4) /*0xC6*/\r
-#define EVENT_GROUP_WAIT_BITS_END (EVENTGROUP_EG + 5) /*0xC7*/\r
-#define EVENT_GROUP_CLEAR_BITS (EVENTGROUP_EG + 6) /*0xC8*/\r
-#define EVENT_GROUP_CLEAR_BITS_FROM_ISR (EVENTGROUP_EG + 7) /*0xC9*/\r
-#define EVENT_GROUP_SET_BITS (EVENTGROUP_EG + 8) /*0xCA*/\r
-#define EVENT_GROUP_DELETE (EVENTGROUP_EG + 9) /*0xCB*/\r
-#define EVENT_GROUP_SYNC_END_FAILED (EVENTGROUP_EG + 10) /*0xCC*/\r
-#define EVENT_GROUP_WAIT_BITS_END_FAILED (EVENTGROUP_EG + 11) /*0xCD*/\r
-#define EVENT_GROUP_SET_BITS_FROM_ISR (EVENTGROUP_EG + 12) /*0xCE*/\r
-#define EVENT_GROUP_SET_BITS_FROM_ISR_FAILED (EVENTGROUP_EG + 13) /*0xCF*/\r
-\r
-#define TASK_INSTANCE_FINISHED_NEXT_KSE (EVENTGROUP_EG + 14) /*0xD0*/\r
-#define TASK_INSTANCE_FINISHED_DIRECT (EVENTGROUP_EG + 15) /*0xD1*/\r
-\r
-#define TRACE_TASK_NOTIFY_GROUP (EVENTGROUP_EG + 16) /*0xD2*/\r
-#define TRACE_TASK_NOTIFY (TRACE_TASK_NOTIFY_GROUP + 0) /*0xD2*/\r
-#define TRACE_TASK_NOTIFY_TAKE (TRACE_TASK_NOTIFY_GROUP + 1) /*0xD3*/\r
-#define TRACE_TASK_NOTIFY_TAKE_BLOCK (TRACE_TASK_NOTIFY_GROUP + 2) /*0xD4*/\r
-#define TRACE_TASK_NOTIFY_TAKE_FAILED (TRACE_TASK_NOTIFY_GROUP + 3) /*0xD5*/\r
-#define TRACE_TASK_NOTIFY_WAIT (TRACE_TASK_NOTIFY_GROUP + 4) /*0xD6*/\r
-#define TRACE_TASK_NOTIFY_WAIT_BLOCK (TRACE_TASK_NOTIFY_GROUP + 5) /*0xD7*/\r
-#define TRACE_TASK_NOTIFY_WAIT_FAILED (TRACE_TASK_NOTIFY_GROUP + 6) /*0xD8*/\r
-#define TRACE_TASK_NOTIFY_FROM_ISR (TRACE_TASK_NOTIFY_GROUP + 7) /*0xD9*/\r
-#define TRACE_TASK_NOTIFY_GIVE_FROM_ISR (TRACE_TASK_NOTIFY_GROUP + 8) /*0xDA*/\r
-\r
-/************************************************************************/\r
-/* KERNEL SPECIFIC DATA AND FUNCTIONS NEEDED TO PROVIDE THE */\r
-/* FUNCTIONALITY REQUESTED BY THE TRACE RECORDER */\r
-/************************************************************************/\r
-\r
-/******************************************************************************\r
- * TraceObjectClassTable\r
- * Translates a FreeRTOS QueueType into trace objects classes (TRACE_CLASS_).\r
- * This was added since we want to map both types of Mutex and both types of\r
- * Semaphores on common classes for all Mutexes and all Semaphores respectively.\r
- *\r
- * FreeRTOS Queue types\r
- * #define queueQUEUE_TYPE_BASE (0U) => TRACE_CLASS_QUEUE\r
- * #define queueQUEUE_TYPE_MUTEX (1U) => TRACE_CLASS_MUTEX\r
- * #define queueQUEUE_TYPE_COUNTING_SEMAPHORE (2U) => TRACE_CLASS_SEMAPHORE\r
- * #define queueQUEUE_TYPE_BINARY_SEMAPHORE (3U) => TRACE_CLASS_SEMAPHORE\r
- * #define queueQUEUE_TYPE_RECURSIVE_MUTEX (4U) => TRACE_CLASS_MUTEX\r
- ******************************************************************************/\r
-\r
-extern traceObjectClass TraceObjectClassTable[5];\r
-\r
-/* These functions are implemented in the .c file since certain header files\r
-must not be included in this one */\r
-objectHandleType prvTraceGetObjectNumber(void* handle);\r
-unsigned char prvTraceGetObjectType(void* handle);\r
-objectHandleType prvTraceGetTaskNumber(void* handle);\r
-unsigned char prvTraceIsSchedulerActive(void);\r
-unsigned char prvTraceIsSchedulerSuspended(void);\r
-unsigned char prvTraceIsSchedulerStarted(void);\r
-void* prvTraceGetCurrentTaskHandle(void);\r
-\r
-#if (configUSE_TIMERS == 1)\r
-#undef INCLUDE_xTimerGetTimerDaemonTaskHandle\r
-#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1\r
-#endif\r
+#define EVENTGROUP_SYS (EVENTGROUP_USEREVENT + 16UL) /*0xA8*/\r
+#define XTS8 (EVENTGROUP_SYS + 0UL) /*0xA8*/\r
+#define XTS16 (EVENTGROUP_SYS + 1UL) /*0xA9*/\r
+#define EVENT_BEING_WRITTEN (EVENTGROUP_SYS + 2UL) /*0xAA*/\r
+#define RESERVED_DUMMY_CODE (EVENTGROUP_SYS + 3UL) /*0xAB*/\r
+#define LOW_POWER_BEGIN (EVENTGROUP_SYS + 4UL) /*0xAC*/\r
+#define LOW_POWER_END (EVENTGROUP_SYS + 5UL) /*0xAD*/\r
+#define XID (EVENTGROUP_SYS + 6UL) /*0xAE*/\r
+#define XTS16L (EVENTGROUP_SYS + 7UL) /*0xAF*/\r
+\r
+#define EVENTGROUP_TIMER (EVENTGROUP_SYS + 8UL) /*0xB0*/\r
+#define TIMER_CREATE (EVENTGROUP_TIMER + 0UL) /*0xB0*/\r
+#define TIMER_START (EVENTGROUP_TIMER + 1UL) /*0xB1*/\r
+#define TIMER_RST (EVENTGROUP_TIMER + 2UL) /*0xB2*/\r
+#define TIMER_STOP (EVENTGROUP_TIMER + 3UL) /*0xB3*/\r
+#define TIMER_CHANGE_PERIOD (EVENTGROUP_TIMER + 4UL) /*0xB4*/\r
+#define TIMER_DELETE (EVENTGROUP_TIMER + 5UL) /*0xB5*/\r
+#define TIMER_START_FROM_ISR (EVENTGROUP_TIMER + 6UL) /*0xB6*/\r
+#define TIMER_RESET_FROM_ISR (EVENTGROUP_TIMER + 7UL) /*0xB7*/\r
+#define TIMER_STOP_FROM_ISR (EVENTGROUP_TIMER + 8UL) /*0xB8*/\r
+\r
+#define TIMER_CREATE_FAILED (EVENTGROUP_TIMER + 9UL) /*0xB9*/\r
+#define TIMER_START_FAILED (EVENTGROUP_TIMER + 10UL) /*0xBA*/\r
+#define TIMER_RESET_FAILED (EVENTGROUP_TIMER + 11UL) /*0xBB*/\r
+#define TIMER_STOP_FAILED (EVENTGROUP_TIMER + 12UL) /*0xBC*/\r
+#define TIMER_CHANGE_PERIOD_FAILED (EVENTGROUP_TIMER + 13UL) /*0xBD*/\r
+#define TIMER_DELETE_FAILED (EVENTGROUP_TIMER + 14UL) /*0xBE*/\r
+#define TIMER_START_FROM_ISR_FAILED (EVENTGROUP_TIMER + 15UL) /*0xBF*/\r
+#define TIMER_RESET_FROM_ISR_FAILED (EVENTGROUP_TIMER + 16UL) /*0xC0*/\r
+#define TIMER_STOP_FROM_ISR_FAILED (EVENTGROUP_TIMER + 17UL) /*0xC1*/\r
+\r
+#define EVENTGROUP_EG (EVENTGROUP_TIMER + 18UL) /*0xC2*/\r
+#define EVENT_GROUP_CREATE (EVENTGROUP_EG + 0UL) /*0xC2*/\r
+#define EVENT_GROUP_CREATE_FAILED (EVENTGROUP_EG + 1UL) /*0xC3*/\r
+#define EVENT_GROUP_SYNC_BLOCK (EVENTGROUP_EG + 2UL) /*0xC4*/\r
+#define EVENT_GROUP_SYNC_END (EVENTGROUP_EG + 3UL) /*0xC5*/\r
+#define EVENT_GROUP_WAIT_BITS_BLOCK (EVENTGROUP_EG + 4UL) /*0xC6*/\r
+#define EVENT_GROUP_WAIT_BITS_END (EVENTGROUP_EG + 5UL) /*0xC7*/\r
+#define EVENT_GROUP_CLEAR_BITS (EVENTGROUP_EG + 6UL) /*0xC8*/\r
+#define EVENT_GROUP_CLEAR_BITS_FROM_ISR (EVENTGROUP_EG + 7UL) /*0xC9*/\r
+#define EVENT_GROUP_SET_BITS (EVENTGROUP_EG + 8UL) /*0xCA*/\r
+#define EVENT_GROUP_DELETE (EVENTGROUP_EG + 9UL) /*0xCB*/\r
+#define EVENT_GROUP_SYNC_END_FAILED (EVENTGROUP_EG + 10UL) /*0xCC*/\r
+#define EVENT_GROUP_WAIT_BITS_END_FAILED (EVENTGROUP_EG + 11UL) /*0xCD*/\r
+#define EVENT_GROUP_SET_BITS_FROM_ISR (EVENTGROUP_EG + 12UL) /*0xCE*/\r
+#define EVENT_GROUP_SET_BITS_FROM_ISR_FAILED (EVENTGROUP_EG + 13UL) /*0xCF*/\r
+\r
+#define TASK_INSTANCE_FINISHED_NEXT_KSE (EVENTGROUP_EG + 14UL) /*0xD0*/\r
+#define TASK_INSTANCE_FINISHED_DIRECT (EVENTGROUP_EG + 15UL) /*0xD1*/\r
+\r
+#define TRACE_TASK_NOTIFY_GROUP (EVENTGROUP_EG + 16UL) /*0xD2*/\r
+#define TRACE_TASK_NOTIFY (TRACE_TASK_NOTIFY_GROUP + 0UL) /*0xD2*/\r
+#define TRACE_TASK_NOTIFY_TAKE (TRACE_TASK_NOTIFY_GROUP + 1UL) /*0xD3*/\r
+#define TRACE_TASK_NOTIFY_TAKE_BLOCK (TRACE_TASK_NOTIFY_GROUP + 2UL) /*0xD4*/\r
+#define TRACE_TASK_NOTIFY_TAKE_FAILED (TRACE_TASK_NOTIFY_GROUP + 3UL) /*0xD5*/\r
+#define TRACE_TASK_NOTIFY_WAIT (TRACE_TASK_NOTIFY_GROUP + 4UL) /*0xD6*/\r
+#define TRACE_TASK_NOTIFY_WAIT_BLOCK (TRACE_TASK_NOTIFY_GROUP + 5UL) /*0xD7*/\r
+#define TRACE_TASK_NOTIFY_WAIT_FAILED (TRACE_TASK_NOTIFY_GROUP + 6UL) /*0xD8*/\r
+#define TRACE_TASK_NOTIFY_FROM_ISR (TRACE_TASK_NOTIFY_GROUP + 7UL) /*0xD9*/\r
+#define TRACE_TASK_NOTIFY_GIVE_FROM_ISR (TRACE_TASK_NOTIFY_GROUP + 8UL) /*0xDA*/\r
\r
-/************************************************************************/\r
-/* KERNEL SPECIFIC MACROS USED BY THE TRACE RECORDER */\r
-/************************************************************************/\r
-\r
-#define TRACE_MALLOC(size) pvPortMalloc(size)\r
-#define TRACE_IS_SCHEDULER_ACTIVE() prvTraceIsSchedulerActive()\r
-#define TRACE_IS_SCHEDULER_STARTED() prvTraceIsSchedulerStarted()\r
-#define TRACE_IS_SCHEDULER_SUSPENDED() prvTraceIsSchedulerSuspended()\r
-#define TRACE_GET_CURRENT_TASK() prvTraceGetCurrentTaskHandle()\r
\r
#define TRACE_GET_TASK_PRIORITY(pxTCB) ((uint8_t)pxTCB->uxPriority)\r
#define TRACE_GET_TASK_NAME(pxTCB) ((char*)pxTCB->pcTaskName)\r
#define TRACE_GET_TASK_NUMBER(pxTCB) (prvTraceGetTaskNumber(pxTCB))\r
-#define TRACE_SET_TASK_NUMBER(pxTCB) pxTCB->uxTaskNumber = xTraceGetObjectHandle(TRACE_CLASS_TASK);\r
+#define TRACE_SET_TASK_NUMBER(pxTCB) pxTCB->uxTaskNumber = prvTraceGetObjectHandle(TRACE_CLASS_TASK);\r
\r
#define TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass) TraceObjectClassTable[kernelClass]\r
#define TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject) TRACE_GET_CLASS_TRACE_CLASS(CLASS, prvTraceGetObjectType(pxObject))\r
\r
-#define TRACE_GET_TIMER_NUMBER(tmr) ( ( objectHandleType ) ((Timer_t*)tmr)->uxTimerNumber )\r
-#define TRACE_SET_TIMER_NUMBER(tmr) ((Timer_t*)tmr)->uxTimerNumber = xTraceGetObjectHandle(TRACE_CLASS_TIMER);\r
+#define TRACE_GET_TIMER_NUMBER(tmr) (((uint32_t)tmr) != 0 ? ( ( traceHandle ) ((Timer_t*)tmr)->uxTimerNumber ) : 0)\r
+#define TRACE_SET_TIMER_NUMBER(tmr) ((Timer_t*)tmr)->uxTimerNumber = prvTraceGetObjectHandle(TRACE_CLASS_TIMER);\r
#define TRACE_GET_TIMER_NAME(pxTimer) pxTimer->pcTimerName\r
#define TRACE_GET_TIMER_PERIOD(pxTimer) pxTimer->xTimerPeriodInTicks\r
\r
-#define TRACE_GET_EVENTGROUP_NUMBER(eg) ( ( objectHandleType ) uxEventGroupGetNumber(eg) )\r
-#define TRACE_SET_EVENTGROUP_NUMBER(eg) ((EventGroup_t*)eg)->uxEventGroupNumber = xTraceGetObjectHandle(TRACE_CLASS_EVENTGROUP);\r
+#define TRACE_GET_EVENTGROUP_NUMBER(eg) ( ( traceHandle ) uxEventGroupGetNumber(eg) )\r
+\r
+#define TRACE_SET_EVENTGROUP_NUMBER(eg) ((EventGroup_t*)eg)->uxEventGroupNumber = prvTraceGetObjectHandle(TRACE_CLASS_EVENTGROUP);\r
\r
#define TRACE_GET_OBJECT_NUMBER(CLASS, pxObject) (prvTraceGetObjectNumber(pxObject))\r
\r
-#if (FREERTOS_VERSION < FREERTOS_VERSION_8_0_OR_LATER)\r
- #define TRACE_SET_OBJECT_NUMBER(CLASS, pxObject) pxObject->ucQueueNumber = xTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject));\r
+#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_8_X)\r
+ #define TRACE_SET_OBJECT_NUMBER(CLASS, pxObject) pxObject->ucQueueNumber = prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject));\r
#else\r
- #define TRACE_SET_OBJECT_NUMBER(CLASS, pxObject) pxObject->uxQueueNumber = xTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject));\r
+ #define TRACE_SET_OBJECT_NUMBER(CLASS, pxObject) pxObject->uxQueueNumber = prvTraceGetObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject));\r
#endif\r
\r
#define TRACE_GET_CLASS_EVENT_CODE(SERVICE, RESULT, CLASS, kernelClass) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass))\r
#define TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject))\r
#define TRACE_GET_TASK_EVENT_CODE(SERVICE, RESULT, CLASS, pxTCB) (uint8_t)(EVENTGROUP_##SERVICE##_##RESULT + TRACE_CLASS_TASK)\r
\r
-/************************************************************************/\r
-/* KERNEL SPECIFIC WRAPPERS THAT SHOULD BE CALLED BY THE KERNEL */\r
-/************************************************************************/\r
+/*** The trace macros for snapshot mode **************************************/\r
\r
+#ifdef configUSE_TICKLESS_IDLE\r
#if (configUSE_TICKLESS_IDLE != 0)\r
\r
#undef traceLOW_POWER_IDLE_BEGIN\r
#define traceLOW_POWER_IDLE_BEGIN() \\r
{ \\r
extern uint32_t trace_disable_timestamp; \\r
- vTraceStoreLowPower(0); \\r
+ prvTraceStoreLowPower(0); \\r
trace_disable_timestamp = 1; \\r
}\r
\r
{ \\r
extern uint32_t trace_disable_timestamp; \\r
trace_disable_timestamp = 0; \\r
- vTraceStoreLowPower(1); \\r
+ prvTraceStoreLowPower(1); \\r
}\r
\r
-#endif\r
+#endif /* configUSE_TICKLESS_IDLE != 0 */\r
+#endif /* configUSE_TICKLESS_IDLE */ \r
\r
/* A macro that will update the tick count when returning from tickless idle */\r
#undef traceINCREASE_TICK_COUNT\r
-/* Note: This can handle time adjustments of max 2^32 ticks, i.e., 35 seconds at 120 MHz. Thus, tick-less idle periods longer than 2^32 ticks will appear "compressed" on the time line.*/\r
-#define traceINCREASE_TICK_COUNT( xCount ) { DWT_CYCLES_ADDED += (xCount * (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)); }\r
+#define traceINCREASE_TICK_COUNT( xCount ) \r
\r
/* Called for each task that becomes ready */\r
#undef traceMOVED_TASK_TO_READY_STATE\r
/* Called on each OS tick. Will call uiPortGetTimestamp to make sure it is called at least once every OS tick. */\r
#undef traceTASK_INCREMENT_TICK\r
\r
-#if (FREERTOS_VERSION == FREERTOS_VERSION_7_3_OR_7_4)\r
+#if (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_7_3_OR_7_4)\r
\r
#define traceTASK_INCREMENT_TICK( xTickCount ) \\r
if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxMissedTicks == 0) { trcKERNEL_HOOKS_INCREMENT_TICK(); } \\r
\r
/* Called on vTaskDelayUntil - note the use of FreeRTOS variable xTimeToWake */\r
#undef traceTASK_DELAY_UNTIL\r
-#define traceTASK_DELAY_UNTIL( xTickTimeToWake ) \\r
- trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY_UNTIL, pxCurrentTCB, ( xTickTimeToWake)); \\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X\r
+#define traceTASK_DELAY_UNTIL(xTimeToWake) \\r
+ trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY_UNTIL, pxCurrentTCB, xTimeToWake); \\r
+ trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_DELAY_UNTIL() \\r
+ trcKERNEL_HOOKS_TASK_DELAY(TASK_DELAY_UNTIL, pxCurrentTCB, xTimeToWake); \\r
trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
\r
-#if (INCLUDE_OBJECT_DELETE == 1)\r
+#if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
/* Called on vTaskDelete */\r
#undef traceTASK_DELETE\r
#define traceTASK_DELETE( pxTaskToDelete ) \\r
- { TRACE_SR_ALLOC_CRITICAL_SECTION(); \\r
+ { TRACE_ALLOC_CRITICAL_SECTION(); \\r
TRACE_ENTER_CRITICAL_SECTION(); \\r
trcKERNEL_HOOKS_TASK_DELETE(DELETE_OBJ, pxTaskToDelete); \\r
TRACE_EXIT_CRITICAL_SECTION(); }\r
-#endif\r
\r
-#if (INCLUDE_OBJECT_DELETE == 1)\r
/* Called on vQueueDelete */\r
#undef traceQUEUE_DELETE\r
#define traceQUEUE_DELETE( pxQueue ) \\r
- { TRACE_SR_ALLOC_CRITICAL_SECTION(); \\r
+ { TRACE_ALLOC_CRITICAL_SECTION(); \\r
TRACE_ENTER_CRITICAL_SECTION(); \\r
- trcKERNEL_HOOKS_OBJECT_DELETE(DELETE_OBJ, UNUSED, pxQueue); \\r
+ trcKERNEL_HOOKS_OBJECT_DELETE(DELETE_OBJ, TRC_UNUSED, pxQueue); \\r
TRACE_EXIT_CRITICAL_SECTION(); }\r
#endif\r
\r
#define traceTASK_CREATE(pxNewTCB) \\r
if (pxNewTCB != NULL) \\r
{ \\r
- trcKERNEL_HOOKS_TASK_CREATE(CREATE_OBJ, UNUSED, pxNewTCB); \\r
+ trcKERNEL_HOOKS_TASK_CREATE(CREATE_OBJ, TRC_UNUSED, pxNewTCB); \\r
}\r
\r
/* Called in vTaskCreate, if it fails (typically if the stack can not be allocated) */\r
#undef traceTASK_CREATE_FAILED\r
#define traceTASK_CREATE_FAILED() \\r
- trcKERNEL_HOOKS_TASK_CREATE_FAILED(CREATE_OBJ, UNUSED);\r
+ trcKERNEL_HOOKS_TASK_CREATE_FAILED(CREATE_OBJ, TRC_UNUSED);\r
\r
/* Called in xQueueCreate, and thereby for all other object based on queues, such as semaphores. */\r
#undef traceQUEUE_CREATE\r
#define traceQUEUE_CREATE( pxNewQueue )\\r
- trcKERNEL_HOOKS_OBJECT_CREATE(CREATE_OBJ, UNUSED, pxNewQueue);\r
+ trcKERNEL_HOOKS_OBJECT_CREATE(CREATE_OBJ, TRC_UNUSED, pxNewQueue);\r
\r
/* Called in xQueueCreate, if the queue creation fails */\r
#undef traceQUEUE_CREATE_FAILED\r
#define traceQUEUE_CREATE_FAILED( queueType ) \\r
- trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(CREATE_OBJ, UNUSED, queueType);\r
+ trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(CREATE_OBJ, TRC_UNUSED, queueType);\r
\r
+/* This macro is not necessary as of FreeRTOS v9.0.0 */\r
+#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X)\r
/* Called in xQueueCreateMutex, and thereby also from xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex */\r
#undef traceCREATE_MUTEX\r
#define traceCREATE_MUTEX( pxNewQueue ) \\r
- trcKERNEL_HOOKS_OBJECT_CREATE(CREATE_OBJ, UNUSED, pxNewQueue);\r
-\r
+ trcKERNEL_HOOKS_OBJECT_CREATE(CREATE_OBJ, TRC_UNUSED, pxNewQueue);\r
+ \r
/* Called in xQueueCreateMutex when the operation fails (when memory allocation fails) */\r
#undef traceCREATE_MUTEX_FAILED\r
#define traceCREATE_MUTEX_FAILED() \\r
- trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(CREATE_OBJ, UNUSED, queueQUEUE_TYPE_MUTEX);\r
+ trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(CREATE_OBJ, TRC_UNUSED, queueQUEUE_TYPE_MUTEX);\r
+#endif /* (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X) */\r
\r
/* Called when the Mutex can not be given, since not holder */\r
#undef traceGIVE_MUTEX_RECURSIVE_FAILED\r
#define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, FAILED, UNUSED, pxMutex);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, FAILED, TRC_UNUSED, pxMutex);\r
\r
/* Called when a message is sent to a queue */ /* CS IS NEW ! */\r
#undef traceQUEUE_SEND\r
#define traceQUEUE_SEND( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, SUCCESS, UNUSED, pxQueue); \\r
- trcKERNEL_HOOKS_SET_OBJECT_STATE(UNUSED, pxQueue, TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, pxQueue) == TRACE_CLASS_MUTEX ? (uint8_t)0 : (uint8_t)(pxQueue->uxMessagesWaiting + 1));\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, SUCCESS, TRC_UNUSED, pxQueue); \\r
+ trcKERNEL_HOOKS_SET_OBJECT_STATE(TRC_UNUSED, pxQueue, TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, pxQueue) == TRACE_CLASS_MUTEX ? (uint8_t)0 : (uint8_t)(pxQueue->uxMessagesWaiting + 1));\r
\r
/* Called when a message failed to be sent to a queue (timeout) */\r
#undef traceQUEUE_SEND_FAILED\r
#define traceQUEUE_SEND_FAILED( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, FAILED, UNUSED, pxQueue);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, FAILED, TRC_UNUSED, pxQueue);\r
\r
/* Called when the task is blocked due to a send operation on a full queue */\r
#undef traceBLOCKING_ON_QUEUE_SEND\r
#define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, BLOCK, UNUSED, pxQueue);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(SEND, BLOCK, TRC_UNUSED, pxQueue);\r
\r
/* Called when a message is received from a queue */\r
#undef traceQUEUE_RECEIVE\r
#define traceQUEUE_RECEIVE( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE, SUCCESS, UNUSED, pxQueue); \\r
- trcKERNEL_HOOKS_SET_OBJECT_STATE(UNUSED, pxQueue, TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, pxQueue) == TRACE_CLASS_MUTEX ? TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()) : (uint8_t)(pxQueue->uxMessagesWaiting - 1));\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE, SUCCESS, TRC_UNUSED, pxQueue); \\r
+ trcKERNEL_HOOKS_SET_OBJECT_STATE(TRC_UNUSED, pxQueue, TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, pxQueue) == TRACE_CLASS_MUTEX ? (uint8_t)TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()) : (uint8_t)(pxQueue->uxMessagesWaiting - 1));\r
\r
/* Called when a receive operation on a queue fails (timeout) */\r
#undef traceQUEUE_RECEIVE_FAILED\r
#define traceQUEUE_RECEIVE_FAILED( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE, FAILED, UNUSED, pxQueue);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE, FAILED, TRC_UNUSED, pxQueue);\r
\r
/* Called when the task is blocked due to a receive operation on an empty queue */\r
#undef traceBLOCKING_ON_QUEUE_RECEIVE\r
#define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE, BLOCK, UNUSED, pxQueue); \\r
- if (TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, pxQueue) != TRACE_CLASS_MUTEX) \\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE, BLOCK, TRC_UNUSED, pxQueue); \\r
+ if (TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, pxQueue) != TRACE_CLASS_MUTEX) \\r
{trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();}\r
\r
/* Called on xQueuePeek */\r
#undef traceQUEUE_PEEK\r
#define traceQUEUE_PEEK( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(PEEK, SUCCESS, UNUSED, pxQueue);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(PEEK, SUCCESS, TRC_UNUSED, pxQueue);\r
\r
/* Called when a message is sent from interrupt context, e.g., using xQueueSendFromISR */\r
#undef traceQUEUE_SEND_FROM_ISR\r
#define traceQUEUE_SEND_FROM_ISR( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(SEND_FROM_ISR, SUCCESS, UNUSED, pxQueue); \\r
- trcKERNEL_HOOKS_SET_OBJECT_STATE(UNUSED, pxQueue, (uint8_t)(pxQueue->uxMessagesWaiting + 1));\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(SEND_FROM_ISR, SUCCESS, TRC_UNUSED, pxQueue); \\r
+ trcKERNEL_HOOKS_SET_OBJECT_STATE(TRC_UNUSED, pxQueue, (uint8_t)(pxQueue->uxMessagesWaiting + 1));\r
\r
/* Called when a message send from interrupt context fails (since the queue was full) */\r
#undef traceQUEUE_SEND_FROM_ISR_FAILED\r
#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(SEND_FROM_ISR, FAILED, UNUSED, pxQueue);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(SEND_FROM_ISR, FAILED, TRC_UNUSED, pxQueue);\r
\r
/* Called when a message is received in interrupt context, e.g., using xQueueReceiveFromISR */\r
#undef traceQUEUE_RECEIVE_FROM_ISR\r
#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE_FROM_ISR, SUCCESS, UNUSED, pxQueue); \\r
- trcKERNEL_HOOKS_SET_OBJECT_STATE(UNUSED, pxQueue, (uint8_t)(pxQueue->uxMessagesWaiting - 1));\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE_FROM_ISR, SUCCESS, TRC_UNUSED, pxQueue); \\r
+ trcKERNEL_HOOKS_SET_OBJECT_STATE(TRC_UNUSED, pxQueue, (uint8_t)(pxQueue->uxMessagesWaiting - 1));\r
\r
/* Called when a message receive from interrupt context fails (since the queue was empty) */\r
#undef traceQUEUE_RECEIVE_FROM_ISR_FAILED\r
#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) \\r
- trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE_FROM_ISR, FAILED, UNUSED, pxQueue);\r
+ trcKERNEL_HOOKS_KERNEL_SERVICE(RECEIVE_FROM_ISR, FAILED, TRC_UNUSED, pxQueue);\r
\r
/* Called in vTaskPrioritySet */\r
#undef traceTASK_PRIORITY_SET\r
trcKERNEL_HOOKS_TASK_RESUME(TASK_RESUME_FROM_ISR, pxTaskToResume);\r
\r
\r
-#if (FREERTOS_VERSION >= FREERTOS_VERSION_8_0_OR_LATER)\r
+#if (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X)\r
\r
-#if (INCLUDE_MEMMANG_EVENTS == 1)\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1)\r
\r
extern void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t size);\r
\r
#undef traceFREE\r
#define traceFREE( pvAddress, uiSize ) {vTraceStoreMemMangEvent(MEM_FREE_SIZE, ( uint32_t ) pvAddress, (int32_t)(-uiSize)); }\r
\r
-#endif\r
+#endif /* (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1) */\r
\r
/* Called in timer.c - xTimerCreate */\r
#undef traceTIMER_CREATE\r
#undef traceTIMER_COMMAND_SEND\r
#define traceTIMER_COMMAND_SEND(tmr, xCommandID, xOptionalValue, xReturn) \\r
if (xCommandID > tmrCOMMAND_START_DONT_TRACE){\\r
- if (xCommandID == tmrCOMMAND_CHANGE_PERIOD) vTraceStoreKernelCallWithParam((xReturn == pdPASS) ? TIMER_CHANGE_PERIOD : TIMER_CHANGE_PERIOD_FAILED, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(tmr), xOptionalValue);\\r
+ if (xCommandID == tmrCOMMAND_CHANGE_PERIOD){ prvTraceStoreKernelCallWithParam((xReturn == pdPASS) ? TIMER_CHANGE_PERIOD : TIMER_CHANGE_PERIOD_FAILED, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(tmr), xOptionalValue);}\\r
else if ((xCommandID == tmrCOMMAND_DELETE) && (xReturn == pdPASS)){ trcKERNEL_HOOKS_TIMER_DELETE(TIMER_DELETE, tmr); } \\r
- else {trcKERNEL_HOOKS_TIMER_EVENT(EVENTGROUP_TIMER + xCommandID + ((xReturn == pdPASS)?0:(TIMER_CREATE_FAILED - TIMER_CREATE)), tmr); }\\r
+ else {trcKERNEL_HOOKS_TIMER_EVENT(EVENTGROUP_TIMER + (uint32_t)xCommandID + ((xReturn == pdPASS)?0:(TIMER_CREATE_FAILED - TIMER_CREATE)), tmr); }\\r
}\r
\r
#undef tracePEND_FUNC_CALL\r
#define tracePEND_FUNC_CALL(func, arg1, arg2, ret) \\r
-if (ret == pdPASS) \\r
- vTraceStoreKernelCall(PEND_FUNC_CALL, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTimerGetTimerDaemonTaskHandle()) ); \\r
-else \\r
- vTraceStoreKernelCall(PEND_FUNC_CALL_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTimerGetTimerDaemonTaskHandle()) );\r
+if (ret == pdPASS){ \\r
+ prvTraceStoreKernelCall(PEND_FUNC_CALL, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTimerGetTimerDaemonTaskHandle()) ); \\r
+}else{ \\r
+ prvTraceStoreKernelCall(PEND_FUNC_CALL_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTimerGetTimerDaemonTaskHandle()) );}\r
\r
#undef tracePEND_FUNC_CALL_FROM_ISR\r
#define tracePEND_FUNC_CALL_FROM_ISR(func, arg1, arg2, ret) \\r
- if (! uiInEventGroupSetBitsFromISR) vTraceStoreKernelCall(PEND_FUNC_CALL_FROM_ISR, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTimerGetTimerDaemonTaskHandle()) ); \\r
+ if (! uiInEventGroupSetBitsFromISR){ prvTraceStoreKernelCall(PEND_FUNC_CALL_FROM_ISR, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTimerGetTimerDaemonTaskHandle()) ); } \\r
uiInEventGroupSetBitsFromISR = 0;\r
-#endif\r
+\r
+#endif /* (TRC_CFG_FREERTOS_VERSION >= TRC_FREERTOS_VERSION_8_X) */\r
\r
#undef traceEVENT_GROUP_CREATE\r
#define traceEVENT_GROUP_CREATE(eg) \\r
TRACE_SET_EVENTGROUP_NUMBER(eg); \\r
- vTraceStoreKernelCall(EVENT_GROUP_CREATE, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg));\r
+ prvTraceStoreKernelCall(EVENT_GROUP_CREATE, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg));\r
\r
#undef traceEVENT_GROUP_DELETE\r
#define traceEVENT_GROUP_DELETE(eg) \\r
- vTraceStoreKernelCall(EVENT_GROUP_DELETE, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg)); \\r
- vTraceStoreObjectNameOnCloseEvent(TRACE_GET_EVENTGROUP_NUMBER(eg), TRACE_CLASS_EVENTGROUP); \\r
- vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_EVENTGROUP_NUMBER(eg), TRACE_CLASS_EVENTGROUP); \\r
- vTraceFreeObjectHandle(TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg));\r
+ prvTraceStoreKernelCall(EVENT_GROUP_DELETE, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg)); \\r
+ prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_EVENTGROUP_NUMBER(eg), TRACE_CLASS_EVENTGROUP); \\r
+ prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_EVENTGROUP_NUMBER(eg), TRACE_CLASS_EVENTGROUP); \\r
+ prvTraceFreeObjectHandle(TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg));\r
\r
#undef traceEVENT_GROUP_CREATE_FAILED\r
#define traceEVENT_GROUP_CREATE_FAILED() \\r
- vTraceStoreKernelCall(EVENT_GROUP_CREATE_FAILED, TRACE_CLASS_EVENTGROUP, 0);\r
+ prvTraceStoreKernelCall(EVENT_GROUP_CREATE_FAILED, TRACE_CLASS_EVENTGROUP, 0);\r
\r
#undef traceEVENT_GROUP_SYNC_BLOCK\r
#define traceEVENT_GROUP_SYNC_BLOCK(eg, bitsToSet, bitsToWaitFor) \\r
- vTraceStoreKernelCallWithParam(EVENT_GROUP_SYNC_BLOCK, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor);\r
+ prvTraceStoreKernelCallWithParam(EVENT_GROUP_SYNC_BLOCK, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor);\r
\r
#undef traceEVENT_GROUP_SYNC_END\r
#define traceEVENT_GROUP_SYNC_END(eg, bitsToSet, bitsToWaitFor, wasTimeout) \\r
- if (wasTimeout){ vTraceStoreKernelCallWithParam(EVENT_GROUP_SYNC_END_FAILED, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor);} \\r
- else{ vTraceStoreKernelCallWithParam(EVENT_GROUP_SYNC_END, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); }\r
+ if (wasTimeout){ prvTraceStoreKernelCallWithParam(EVENT_GROUP_SYNC_END_FAILED, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor);} \\r
+ else{ prvTraceStoreKernelCallWithParam(EVENT_GROUP_SYNC_END, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); }\r
\r
#undef traceEVENT_GROUP_WAIT_BITS_BLOCK\r
#define traceEVENT_GROUP_WAIT_BITS_BLOCK(eg, bitsToWaitFor) \\r
- vTraceStoreKernelCallWithParam(EVENT_GROUP_WAIT_BITS_BLOCK, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); \\r
+ prvTraceStoreKernelCallWithParam(EVENT_GROUP_WAIT_BITS_BLOCK, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); \\r
trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();\r
\r
#undef traceEVENT_GROUP_WAIT_BITS_END\r
#define traceEVENT_GROUP_WAIT_BITS_END(eg, bitsToWaitFor, wasTimeout) \\r
- if (wasTimeout){ vTraceStoreKernelCallWithParam(EVENT_GROUP_WAIT_BITS_END_FAILED, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); } \\r
- else{ vTraceStoreKernelCallWithParam(EVENT_GROUP_WAIT_BITS_END, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); }\r
+ if (wasTimeout){ prvTraceStoreKernelCallWithParam(EVENT_GROUP_WAIT_BITS_END_FAILED, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); } \\r
+ else{ prvTraceStoreKernelCallWithParam(EVENT_GROUP_WAIT_BITS_END, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToWaitFor); }\r
\r
#undef traceEVENT_GROUP_CLEAR_BITS\r
#define traceEVENT_GROUP_CLEAR_BITS(eg, bitsToClear) \\r
- if (bitsToClear) vTraceStoreKernelCallWithParam(EVENT_GROUP_CLEAR_BITS, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToClear);\r
+ if (bitsToClear) prvTraceStoreKernelCallWithParam(EVENT_GROUP_CLEAR_BITS, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToClear);\r
\r
#undef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR\r
#define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR(eg, bitsToClear) \\r
- if (bitsToClear) vTraceStoreKernelCallWithParam(EVENT_GROUP_CLEAR_BITS_FROM_ISR, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToClear);\r
+ if (bitsToClear) prvTraceStoreKernelCallWithParam(EVENT_GROUP_CLEAR_BITS_FROM_ISR, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToClear);\r
\r
#undef traceEVENT_GROUP_SET_BITS\r
#define traceEVENT_GROUP_SET_BITS(eg, bitsToSet) \\r
- vTraceStoreKernelCallWithParam(EVENT_GROUP_SET_BITS, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToSet);\r
+ prvTraceStoreKernelCallWithParam(EVENT_GROUP_SET_BITS, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToSet);\r
\r
#undef traceEVENT_GROUP_SET_BITS_FROM_ISR\r
#define traceEVENT_GROUP_SET_BITS_FROM_ISR(eg, bitsToSet) \\r
- vTraceStoreKernelCallWithParam(EVENT_GROUP_SET_BITS_FROM_ISR, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToSet); \\r
+ prvTraceStoreKernelCallWithParam(EVENT_GROUP_SET_BITS_FROM_ISR, TRACE_CLASS_EVENTGROUP, TRACE_GET_EVENTGROUP_NUMBER(eg), bitsToSet); \\r
uiInEventGroupSetBitsFromISR = 1;\r
\r
#undef traceTASK_NOTIFY_TAKE\r
+#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X)\r
#define traceTASK_NOTIFY_TAKE() \\r
- if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \\r
- vTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
- else \\r
- vTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait);\r
+ if (pxCurrentTCB->eNotifyState == eNotified){ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
+ }else{ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait);}\r
+#else /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_NOTIFY_TAKE() \\r
+ if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED){ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
+ }else{ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait);}\r
+#endif /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X */\r
\r
#undef traceTASK_NOTIFY_TAKE_BLOCK\r
#define traceTASK_NOTIFY_TAKE_BLOCK() \\r
- vTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE_BLOCK, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_TAKE_BLOCK, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();\r
\r
#undef traceTASK_NOTIFY_WAIT\r
+#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X)\r
#define traceTASK_NOTIFY_WAIT() \\r
- if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \\r
- vTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
- else \\r
- vTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait);\r
+ if (pxCurrentTCB->eNotifyState == eNotified){ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
+ }else{ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait);}\r
+#else /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_NOTIFY_WAIT() \\r
+ if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED){ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
+ }else{ \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_FAILED, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); }\r
+#endif /* TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_9_X */\r
\r
#undef traceTASK_NOTIFY_WAIT_BLOCK\r
#define traceTASK_NOTIFY_WAIT_BLOCK() \\r
- vTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_BLOCK, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
+ prvTraceStoreKernelCallWithParam(TRACE_TASK_NOTIFY_WAIT_BLOCK, TRACE_CLASS_TASK, uxTaskGetTaskNumber(pxCurrentTCB), xTicksToWait); \\r
trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED();\r
\r
#undef traceTASK_NOTIFY\r
#define traceTASK_NOTIFY() \\r
- vTraceStoreKernelCall(TRACE_TASK_NOTIFY, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTaskToNotify));\r
+ prvTraceStoreKernelCall(TRACE_TASK_NOTIFY, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTaskToNotify));\r
\r
#undef traceTASK_NOTIFY_FROM_ISR\r
#define traceTASK_NOTIFY_FROM_ISR() \\r
- vTraceStoreKernelCall(TRACE_TASK_NOTIFY_FROM_ISR, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTaskToNotify));\r
-\r
+ prvTraceStoreKernelCall(TRACE_TASK_NOTIFY_FROM_ISR, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTaskToNotify));\r
+ \r
#undef traceTASK_NOTIFY_GIVE_FROM_ISR\r
#define traceTASK_NOTIFY_GIVE_FROM_ISR() \\r
- vTraceStoreKernelCall(TRACE_TASK_NOTIFY_GIVE_FROM_ISR, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTaskToNotify));\r
+ prvTraceStoreKernelCall(TRACE_TASK_NOTIFY_GIVE_FROM_ISR, TRACE_CLASS_TASK, uxTaskGetTaskNumber(xTaskToNotify));\r
+\r
+#undef traceQUEUE_REGISTRY_ADD\r
+#define traceQUEUE_REGISTRY_ADD(object, name) prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);\r
+\r
+/*******************************************************************************\r
+ * (macro) vTraceExcludeQueue(object)\r
+ *\r
+ * Parameter object: pointer to the Queue object that shall be excluded.\r
+ *\r
+ * Excludes all operations on this object from the trace. Allows for capturing \r
+ * longer traces the snapshot RAM buffer by filtering out irrelevant events.\r
+ ******************************************************************************/\r
+#define vTraceExcludeQueue(object) \\r
+TRACE_SET_QUEUE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object));\r
+\r
+/*******************************************************************************\r
+ * (macro) vTraceExcludeSemaphore(object)\r
+ *\r
+ * Parameter object: pointer to the Semaphore object that shall be excluded.\r
+ *\r
+ * Excludes all operations on this object from the trace. Allows for capturing \r
+ * longer traces the snapshot RAM buffer by filtering out irrelevant events.\r
+ * \r
+ * Note: Only for snapshot mode. \r
+ ******************************************************************************/\r
+#define vTraceExcludeSemaphore(object) \\r
+TRACE_SET_SEMAPHORE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object));\r
+\r
+/*******************************************************************************\r
+ * (macro) vTraceExcludeMutex(object)\r
+ *\r
+ * Parameter object: pointer to the Mutex object that shall be excluded.\r
+ *\r
+ * Excludes all operations on this object from the trace. Allows for capturing \r
+ * longer traces the snapshot RAM buffer by filtering out irrelevant events.\r
+ * \r
+ * Note: Only for snapshot mode. \r
+ ******************************************************************************/\r
+#define vTraceExcludeMutex(object) \\r
+TRACE_SET_MUTEX_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object));\r
+\r
+/*******************************************************************************\r
+ * (macro) vTraceExcludeTimer(object)\r
+ *\r
+ * Parameter object: pointer to the Timer object that shall be excluded.\r
+ *\r
+ * Excludes all operations on this object from the trace. Allows for capturing \r
+ * longer traces the snapshot RAM buffer by filtering out irrelevant events.\r
+ * \r
+ * Note: Only for snapshot mode. \r
+ ******************************************************************************/\r
+#define vTraceExcludeTimer(object) \\r
+TRACE_SET_TIMER_FLAG_ISEXCLUDED(TRACE_GET_TIMER_NUMBER(object));\r
+\r
+/*******************************************************************************\r
+ * (macro) vTraceExcludeEventGroup(object)\r
+ *\r
+ * Parameter object: pointer to the Event Group object that shall be excluded.\r
+ *\r
+ * Excludes all operations on this object from the trace. Allows for capturing \r
+ * longer traces the snapshot RAM buffer by filtering out irrelevant events.\r
+ * \r
+ * Note: Only for snapshot mode. \r
+ ******************************************************************************/\r
+#define vTraceExcludeEventGroup(object) \\r
+TRACE_SET_EVENTGROUP_FLAG_ISEXCLUDED(TRACE_GET_EVENTGROUP_NUMBER(object));\r
\r
-/************************************************************************/\r
-/* KERNEL SPECIFIC MACROS TO EXCLUDE OR INCLUDE THINGS IN TRACE */\r
-/************************************************************************/\r
+/*******************************************************************************\r
+ * (macro) vTraceExcludeTask(object)\r
+ *\r
+ * Parameter object: pointer to the Task object that shall be excluded.\r
+ *\r
+ * Excludes all events from the specified task. Allows for capturing \r
+ * longer traces the snapshot RAM buffer by filtering out irrelevant events.\r
+ * \r
+ * Excluding tasks is problematic as the previous task will appear to continue\r
+ * executing while the excluded task is in fact executing. This therefore affects\r
+ * the timing statistics in an unpredictable way. \r
+ * Moreover, any operations on queues, semaphores, etc. made by an excluded task\r
+ * will also be excludes, so Tracealyzer will give an incorrect display regarding\r
+ * the states of these objects (number of messages in a queue, etc.).\r
+ *\r
+ * This should only be used on short tasks that don't affect other kernel objects\r
+ * of interest. \r
+ * \r
+ * Note: Only for snapshot mode. \r
+ ******************************************************************************/\r
+#define vTraceExcludeTask(object) \\r
+TRACE_SET_TASK_FLAG_ISEXCLUDED(TRACE_GET_TASK_NUMBER(object));\r
\r
-/* Returns the exclude state of the object */\r
-uint8_t uiTraceIsObjectExcluded(traceObjectClass objectclass, objectHandleType handle);\r
+/******************************************************************************\r
+ * (macro) vTraceExcludeDelays()\r
+ *\r
+ * Excludes all Delay operations from the trace. Allows for capturing \r
+ * longer traces the snapshot RAM buffer.\r
+ * \r
+ * Note: Only for snapshot mode. \r
+ *****************************************************************************/\r
+#define vTraceExcludeDelays() \\r
+TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY); \\r
+TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY_UNTIL);\r
+\r
+/*** Private helper macros for exclude functionality ************************/\r
\r
-#define TRACE_SET_QUEUE_FLAG_ISEXCLUDED(queueIndex) TRACE_SET_FLAG_ISEXCLUDED(excludedObjects, queueIndex)\r
-#define TRACE_CLEAR_QUEUE_FLAG_ISEXCLUDED(queueIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedObjects, queueIndex)\r
-#define TRACE_GET_QUEUE_FLAG_ISEXCLUDED(queueIndex) TRACE_GET_FLAG_ISEXCLUDED(excludedObjects, queueIndex)\r
+#define TRACE_SET_QUEUE_FLAG_ISEXCLUDED(queueIndex) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedObjects, queueIndex)\r
+#define TRACE_CLEAR_QUEUE_FLAG_ISEXCLUDED(queueIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedObjects, queueIndex)\r
+#define TRACE_GET_QUEUE_FLAG_ISEXCLUDED(queueIndex) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedObjects, queueIndex)\r
\r
-#define TRACE_SET_SEMAPHORE_FLAG_ISEXCLUDED(semaphoreIndex) TRACE_SET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+semaphoreIndex)\r
-#define TRACE_CLEAR_SEMAPHORE_FLAG_ISEXCLUDED(semaphoreIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+semaphoreIndex)\r
-#define TRACE_GET_SEMAPHORE_FLAG_ISEXCLUDED(semaphoreIndex) TRACE_GET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+semaphoreIndex)\r
+#define TRACE_SET_SEMAPHORE_FLAG_ISEXCLUDED(semaphoreIndex) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+semaphoreIndex)\r
+#define TRACE_CLEAR_SEMAPHORE_FLAG_ISEXCLUDED(semaphoreIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+semaphoreIndex)\r
+#define TRACE_GET_SEMAPHORE_FLAG_ISEXCLUDED(semaphoreIndex) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+semaphoreIndex)\r
\r
-#define TRACE_SET_MUTEX_FLAG_ISEXCLUDED(mutexIndex) TRACE_SET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+mutexIndex)\r
-#define TRACE_CLEAR_MUTEX_FLAG_ISEXCLUDED(mutexIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+mutexIndex)\r
-#define TRACE_GET_MUTEX_FLAG_ISEXCLUDED(mutexIndex) TRACE_GET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+mutexIndex)\r
+#define TRACE_SET_MUTEX_FLAG_ISEXCLUDED(mutexIndex) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+mutexIndex)\r
+#define TRACE_CLEAR_MUTEX_FLAG_ISEXCLUDED(mutexIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+mutexIndex)\r
+#define TRACE_GET_MUTEX_FLAG_ISEXCLUDED(mutexIndex) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+mutexIndex)\r
\r
-#define TRACE_SET_TASK_FLAG_ISEXCLUDED(taskIndex) TRACE_SET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+taskIndex)\r
-#define TRACE_CLEAR_TASK_FLAG_ISEXCLUDED(taskIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+taskIndex)\r
-#define TRACE_GET_TASK_FLAG_ISEXCLUDED(taskIndex) TRACE_GET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+taskIndex)\r
+#define TRACE_SET_TASK_FLAG_ISEXCLUDED(taskIndex) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+taskIndex)\r
+#define TRACE_CLEAR_TASK_FLAG_ISEXCLUDED(taskIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+taskIndex)\r
+#define TRACE_GET_TASK_FLAG_ISEXCLUDED(taskIndex) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+taskIndex)\r
\r
-#define TRACE_SET_TIMER_FLAG_ISEXCLUDED(timerIndex) TRACE_SET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+NTask+1+timerIndex)\r
-#define TRACE_CLEAR_TIMER_FLAG_ISEXCLUDED(timerIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+NTask+1+timerIndex)\r
-#define TRACE_GET_TIMER_FLAG_ISEXCLUDED(timerIndex) TRACE_GET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+NTask+1+timerIndex)\r
+#define TRACE_SET_TIMER_FLAG_ISEXCLUDED(timerIndex) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+TRC_CFG_NTASK+1+timerIndex)\r
+#define TRACE_CLEAR_TIMER_FLAG_ISEXCLUDED(timerIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+TRC_CFG_NTASK+1+timerIndex)\r
+#define TRACE_GET_TIMER_FLAG_ISEXCLUDED(timerIndex) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+TRC_CFG_NTASK+1+timerIndex)\r
\r
-#define TRACE_SET_EVENTGROUP_FLAG_ISEXCLUDED(egIndex) TRACE_SET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+NTask+1+NTimer+1+egIndex)\r
-#define TRACE_CLEAR_EVENTGROUP_FLAG_ISEXCLUDED(egIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+NTask+1+NTimer+1+egIndex)\r
-#define TRACE_GET_EVENTGROUP_FLAG_ISEXCLUDED(egIndex) TRACE_GET_FLAG_ISEXCLUDED(excludedObjects, NQueue+1+NSemaphore+1+NMutex+1+NTask+1+NTimer+1+egIndex)\r
+#define TRACE_SET_EVENTGROUP_FLAG_ISEXCLUDED(egIndex) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+TRC_CFG_NTASK+1+TRC_CFG_NTIMER+1+egIndex)\r
+#define TRACE_CLEAR_EVENTGROUP_FLAG_ISEXCLUDED(egIndex) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+TRC_CFG_NTASK+1+TRC_CFG_NTIMER+1+egIndex)\r
+#define TRACE_GET_EVENTGROUP_FLAG_ISEXCLUDED(egIndex) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedObjects, TRC_CFG_NQUEUE+1+TRC_CFG_NSEMAPHORE+1+TRC_CFG_NMUTEX+1+TRC_CFG_NTASK+1+TRC_CFG_NTIMER+1+egIndex)\r
\r
\r
#define TRACE_CLEAR_OBJECT_FLAG_ISEXCLUDED(objectclass, handle) \\r
break; \\r
}\r
\r
-/* Task */\r
-#define vTraceExcludeTaskFromTrace(handle) \\r
-TRACE_SET_TASK_FLAG_ISEXCLUDED(TRACE_GET_TASK_NUMBER(handle));\r
+#endif /*#if TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT */\r
+\r
+/******************************************************************************/\r
+/*** Definitions for Streaming mode *******************************************/\r
+/******************************************************************************/\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
+\r
+/*******************************************************************************\r
+* vTraceStoreKernelObjectName\r
+*\r
+* Set the name for a kernel object (defined by its address).\r
+******************************************************************************/ \r
+void vTraceStoreKernelObjectName(void* object, const char* name); \r
+\r
+/*******************************************************************************\r
+ * prvTraceOnBegin\r
+ *\r
+ * Called on trace begin.\r
+ ******************************************************************************/\r
+void prvTraceOnBegin(void);\r
\r
-#define vTraceIncludeTaskInTrace(handle) \\r
-TRACE_CLEAR_TASK_FLAG_ISEXCLUDED(TRACE_GET_TASK_NUMBER(handle));\r
+/*******************************************************************************\r
+ * prvTraceOnEnd\r
+ *\r
+ * Called on trace end.\r
+ ******************************************************************************/\r
+void prvTraceOnEnd(void);\r
\r
+/*******************************************************************************\r
+* prvIsNewTCB\r
+*\r
+* Tells if this task is already executing, or if there has been a task-switch.\r
+* Assumed to be called within a trace hook in kernel context.\r
+*******************************************************************************/\r
+uint32_t prvIsNewTCB(void* pNewTCB);\r
+\r
+#define TRACE_GET_CURRENT_TASK() prvTraceGetCurrentTaskHandle()\r
\r
-/* Queue */\r
-#define vTraceExcludeQueueFromTrace(handle) \\r
-TRACE_SET_QUEUE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(UNUSED, handle));\r
+/*************************************************************************/\r
+/* KERNEL SPECIFIC OBJECT CONFIGURATION */\r
+/*************************************************************************/\r
\r
-#define vTraceIncludeQueueInTrace(handle) \\r
-TRACE_CLEAR_QUEUE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(UNUSED, handle));\r
+/*******************************************************************************\r
+ * The event codes - should match the offline config file.\r
+ ******************************************************************************/\r
\r
+/*** Event codes for streaming - should match the Tracealyzer config file *****/\r
+#define PSF_EVENT_NULL_EVENT 0x00\r
+\r
+#define PSF_EVENT_TRACE_START 0x01\r
+#define PSF_EVENT_TS_CONFIG 0x02\r
+#define PSF_EVENT_OBJ_NAME 0x03\r
+#define PSF_EVENT_TASK_PRIORITY 0x04\r
+#define PSF_EVENT_TASK_PRIO_INHERIT 0x05\r
+#define PSF_EVENT_TASK_PRIO_DISINHERIT 0x06\r
+#define PSF_EVENT_DEFINE_ISR 0x07\r
+\r
+#define PSF_EVENT_TASK_CREATE 0x10\r
+#define PSF_EVENT_QUEUE_CREATE 0x11\r
+#define PSF_EVENT_SEMAPHORE_BINARY_CREATE 0x12\r
+#define PSF_EVENT_MUTEX_CREATE 0x13\r
+#define PSF_EVENT_TIMER_CREATE 0x14\r
+#define PSF_EVENT_EVENTGROUP_CREATE 0x15\r
+#define PSF_EVENT_SEMAPHORE_COUNTING_CREATE 0x16\r
+#define PSF_EVENT_MUTEX_RECURSIVE_CREATE 0x17\r
+\r
+#define PSF_EVENT_TASK_DELETE 0x20\r
+#define PSF_EVENT_QUEUE_DELETE 0x21\r
+#define PSF_EVENT_SEMAPHORE_DELETE 0x22\r
+#define PSF_EVENT_MUTEX_DELETE 0x23\r
+#define PSF_EVENT_TIMER_DELETE 0x24\r
+#define PSF_EVENT_EVENTGROUP_DELETE 0x25\r
+\r
+#define PSF_EVENT_TASK_READY 0x30\r
+#define PSF_EVENT_NEW_TIME 0x31\r
+#define PSF_EVENT_NEW_TIME_SCHEDULER_SUSPENDED 0x32\r
+#define PSF_EVENT_ISR_BEGIN 0x33\r
+#define PSF_EVENT_ISR_RESUME 0x34\r
+#define PSF_EVENT_TS_BEGIN 0x35\r
+#define PSF_EVENT_TS_RESUME 0x36\r
+#define PSF_EVENT_TASK_ACTIVATE 0x37\r
+\r
+#define PSF_EVENT_MALLOC 0x38\r
+#define PSF_EVENT_FREE 0x39\r
+\r
+#define PSF_EVENT_LOWPOWER_BEGIN 0x3A\r
+#define PSF_EVENT_LOWPOWER_END 0x3B\r
+\r
+#define PSF_EVENT_IFE_NEXT 0x3C\r
+#define PSF_EVENT_IFE_DIRECT 0x3D\r
+\r
+#define PSF_EVENT_TASK_CREATE_FAILED 0x40\r
+#define PSF_EVENT_QUEUE_CREATE_FAILED 0x41\r
+#define PSF_EVENT_SEMAPHORE_BINARY_CREATE_FAILED 0x42\r
+#define PSF_EVENT_MUTEX_CREATE_FAILED 0x43\r
+#define PSF_EVENT_TIMER_CREATE_FAILED 0x44\r
+#define PSF_EVENT_EVENTGROUP_CREATE_FAILED 0x45\r
+#define PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED 0x46\r
+#define PSF_EVENT_MUTEX_RECURSIVE_CREATE_FAILED 0x47\r
+\r
+#define PSF_EVENT_TIMER_DELETE_FAILED 0x48\r
+\r
+#define PSF_EVENT_QUEUE_SEND 0x50\r
+#define PSF_EVENT_SEMAPHORE_GIVE 0x51\r
+#define PSF_EVENT_MUTEX_GIVE 0x52\r
+\r
+#define PSF_EVENT_QUEUE_SEND_FAILED 0x53\r
+#define PSF_EVENT_SEMAPHORE_GIVE_FAILED 0x54\r
+#define PSF_EVENT_MUTEX_GIVE_FAILED 0x55\r
+\r
+#define PSF_EVENT_QUEUE_SEND_BLOCK 0x56\r
+#define PSF_EVENT_SEMAPHORE_GIVE_BLOCK 0x57\r
+#define PSF_EVENT_MUTEX_GIVE_BLOCK 0x58\r
+\r
+#define PSF_EVENT_QUEUE_SEND_FROMISR 0x59\r
+#define PSF_EVENT_SEMAPHORE_GIVE_FROMISR 0x5A\r
+\r
+#define PSF_EVENT_QUEUE_SEND_FROMISR_FAILED 0x5C\r
+#define PSF_EVENT_SEMAPHORE_GIVE_FROMISR_FAILED 0x5D\r
+\r
+#define PSF_EVENT_QUEUE_RECEIVE 0x60\r
+#define PSF_EVENT_SEMAPHORE_TAKE 0x61\r
+#define PSF_EVENT_MUTEX_TAKE 0x62\r
+\r
+#define PSF_EVENT_QUEUE_RECEIVE_FAILED 0x63\r
+#define PSF_EVENT_SEMAPHORE_TAKE_FAILED 0x64\r
+#define PSF_EVENT_MUTEX_TAKE_FAILED 0x65\r
+\r
+#define PSF_EVENT_QUEUE_RECEIVE_BLOCK 0x66\r
+#define PSF_EVENT_SEMAPHORE_TAKE_BLOCK 0x67\r
+#define PSF_EVENT_MUTEX_TAKE_BLOCK 0x68\r
+\r
+#define PSF_EVENT_QUEUE_RECEIVE_FROMISR 0x69\r
+#define PSF_EVENT_SEMAPHORE_TAKE_FROMISR 0x6A\r
+\r
+#define PSF_EVENT_QUEUE_RECEIVE_FROMISR_FAILED 0x6C\r
+#define PSF_EVENT_SEMAPHORE_TAKE_FROMISR_FAILED 0x6D\r
+\r
+#define PSF_EVENT_QUEUE_PEEK 0x70\r
+#define PSF_EVENT_SEMAPHORE_PEEK 0x71 /* Will never be used */\r
+#define PSF_EVENT_MUTEX_PEEK 0x72 /* Will never be used */\r
+\r
+#define PSF_EVENT_QUEUE_PEEK_FAILED 0x73\r
+#define PSF_EVENT_SEMAPHORE_PEEK_FAILED 0x74 /* Will never be used */\r
+#define PSF_EVENT_MUTEX_PEEK_FAILED 0x75 /* Will never be used */\r
+\r
+#define PSF_EVENT_QUEUE_PEEK_BLOCK 0x76\r
+#define PSF_EVENT_SEMAPHORE_PEEK_BLOCK 0x77 /* Will never be used */\r
+#define PSF_EVENT_MUTEX_PEEK_BLOCK 0x78 /* Will never be used */\r
+\r
+#define PSF_EVENT_TASK_DELAY_UNTIL 0x79\r
+#define PSF_EVENT_TASK_DELAY 0x7A\r
+#define PSF_EVENT_TASK_SUSPEND 0x7B\r
+#define PSF_EVENT_TASK_RESUME 0x7C\r
+#define PSF_EVENT_TASK_RESUME_FROMISR 0x7D\r
+\r
+#define PSF_EVENT_TIMER_PENDFUNCCALL 0x80\r
+#define PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR 0x81\r
+#define PSF_EVENT_TIMER_PENDFUNCCALL_FAILED 0x82\r
+#define PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR_FAILED 0x83\r
+\r
+#define PSF_EVENT_USER_EVENT 0x90\r
+\r
+#define PSF_EVENT_TIMER_START 0xA0\r
+#define PSF_EVENT_TIMER_RESET 0xA1\r
+#define PSF_EVENT_TIMER_STOP 0xA2\r
+#define PSF_EVENT_TIMER_CHANGEPERIOD 0xA3\r
+#define PSF_EVENT_TIMER_START_FROMISR 0xA4\r
+#define PSF_EVENT_TIMER_RESET_FROMISR 0xA5\r
+#define PSF_EVENT_TIMER_STOP_FROMISR 0xA6\r
+#define PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR 0xA7\r
+#define PSF_EVENT_TIMER_START_FAILED 0xA8\r
+#define PSF_EVENT_TIMER_RESET_FAILED 0xA9\r
+#define PSF_EVENT_TIMER_STOP_FAILED 0xAA\r
+#define PSF_EVENT_TIMER_CHANGEPERIOD_FAILED 0xAB\r
+#define PSF_EVENT_TIMER_START_FROMISR_FAILED 0xAC\r
+#define PSF_EVENT_TIMER_RESET_FROMISR_FAILED 0xAD\r
+#define PSF_EVENT_TIMER_STOP_FROMISR_FAILED 0xAE\r
+#define PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR_FAILED 0xAF\r
+\r
+#define PSF_EVENT_EVENTGROUP_SYNC 0xB0\r
+#define PSF_EVENT_EVENTGROUP_WAITBITS 0xB1\r
+#define PSF_EVENT_EVENTGROUP_CLEARBITS 0xB2\r
+#define PSF_EVENT_EVENTGROUP_CLEARBITS_FROMISR 0xB3\r
+#define PSF_EVENT_EVENTGROUP_SETBITS 0xB4\r
+#define PSF_EVENT_EVENTGROUP_SETBITS_FROMISR 0xB5\r
+#define PSF_EVENT_EVENTGROUP_SYNC_BLOCK 0xB6\r
+#define PSF_EVENT_EVENTGROUP_WAITBITS_BLOCK 0xB7\r
+#define PSF_EVENT_EVENTGROUP_SYNC_FAILED 0xB8\r
+#define PSF_EVENT_EVENTGROUP_WAITBITS_FAILED 0xB9\r
+\r
+#define PSF_EVENT_QUEUE_SEND_FRONT 0xC0\r
+#define PSF_EVENT_QUEUE_SEND_FRONT_FAILED 0xC1\r
+#define PSF_EVENT_QUEUE_SEND_FRONT_BLOCK 0xC2\r
+#define PSF_EVENT_QUEUE_SEND_FRONT_FROMISR 0xC3\r
+#define PSF_EVENT_QUEUE_SEND_FRONT_FROMISR_FAILED 0xC4\r
+#define PSF_EVENT_MUTEX_GIVE_RECURSIVE 0xC5\r
+#define PSF_EVENT_MUTEX_GIVE_RECURSIVE_FAILED 0xC6\r
+#define PSF_EVENT_MUTEX_TAKE_RECURSIVE 0xC7\r
+#define PSF_EVENT_MUTEX_TAKE_RECURSIVE_FAILED 0xC8\r
+\r
+#define PSF_EVENT_TASK_NOTIFY 0xC9\r
+#define PSF_EVENT_TASK_NOTIFY_TAKE 0xCA\r
+#define PSF_EVENT_TASK_NOTIFY_TAKE_BLOCK 0xCB\r
+#define PSF_EVENT_TASK_NOTIFY_TAKE_FAILED 0xCC\r
+#define PSF_EVENT_TASK_NOTIFY_WAIT 0xCD\r
+#define PSF_EVENT_TASK_NOTIFY_WAIT_BLOCK 0xCE\r
+#define PSF_EVENT_TASK_NOTIFY_WAIT_FAILED 0xCF\r
+#define PSF_EVENT_TASK_NOTIFY_FROM_ISR 0xD0\r
+#define PSF_EVENT_TASK_NOTIFY_GIVE_FROM_ISR 0xD1\r
+\r
+/*** The trace macros for streaming ******************************************/\r
+\r
+#if (defined(configUSE_TICKLESS_IDLE) && configUSE_TICKLESS_IDLE != 0)\r
\r
-/* Semaphore */\r
-#define vTraceExcludeSemaphoreFromTrace(handle) \\r
-TRACE_SET_SEMAPHORE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(UNUSED, handle));\r
+#undef traceLOW_POWER_IDLE_BEGIN\r
+#define traceLOW_POWER_IDLE_BEGIN() \\r
+ { \\r
+ prvTraceStoreEvent1(PSF_EVENT_LOWPOWER_BEGIN, xExpectedIdleTime); \\r
+ }\r
\r
-#define vTraceIncludeSemaphoreInTrace(handle) \\r
-TRACE_CLEAR_QUEUE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(UNUSED, handle));\r
+#undef traceLOW_POWER_IDLE_END\r
+#define traceLOW_POWER_IDLE_END() \\r
+ { \\r
+ prvTraceStoreEvent0(PSF_EVENT_LOWPOWER_END); \\r
+ }\r
\r
+#endif\r
\r
-/* Mutex */\r
-#define vTraceExcludeMutexFromTrace(handle) \\r
-TRACE_SET_MUTEX_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(UNUSED, handle));\r
+/* A macro that will update the tick count when returning from tickless idle */\r
+#undef traceINCREASE_TICK_COUNT\r
+/* Note: This can handle time adjustments of max 2^32 ticks, i.e., 35 seconds at 120 MHz. Thus, tick-less idle periods longer than 2^32 ticks will appear "compressed" on the time line.*/\r
+#define traceINCREASE_TICK_COUNT( xCount ) { extern uint32_t uiTraceTickCount; uiTraceTickCount += xCount; }\r
\r
-#define vTraceIncludeMutexInTrace(handle) \\r
-TRACE_CLEAR_QUEUE_FLAG_ISEXCLUDED(TRACE_GET_OBJECT_NUMBER(UNUSED, handle));\r
+/* Called for each task that becomes ready */\r
+#undef traceMOVED_TASK_TO_READY_STATE\r
+#define traceMOVED_TASK_TO_READY_STATE( pxTCB ) \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_READY, (uint32_t)pxTCB);\r
\r
-/* Timer */\r
-#define vTraceExcludeTimerFromTrace(handle) \\r
-TRACE_SET_TIMER_FLAG_ISEXCLUDED(TRACE_GET_TIMER_NUMBER(handle));\r
+/* Called on each OS tick. Will call uiPortGetTimestamp to make sure it is called at least once every OS tick. */\r
+#undef traceTASK_INCREMENT_TICK\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_7_3_OR_7_4\r
+#define traceTASK_INCREMENT_TICK( xTickCount ) \\r
+ if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxMissedTicks == 0) { extern uint32_t uiTraceTickCount; uiTraceTickCount++; } \\r
+ if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE) { prvTraceStoreEvent1(PSF_EVENT_NEW_TIME, (uint32_t)(xTickCount + 1)); }\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_7_3_OR_7_4 */\r
+#define traceTASK_INCREMENT_TICK( xTickCount ) \\r
+ if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdTRUE || uxPendedTicks == 0) { extern uint32_t uiTraceTickCount; uiTraceTickCount++; } \\r
+ if (uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE) { prvTraceStoreEvent1(PSF_EVENT_NEW_TIME, (uint32_t)(xTickCount + 1)); }\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_7_3_OR_7_4 */\r
\r
-#define vTraceIncludeTimerInTrace(handle) \\r
-TRACE_CLEAR_QUEUE_FLAG_ISEXCLUDED(TRACE_GET_TIMER_NUMBER(handle));\r
+/* Called on each task-switch */\r
+#undef traceTASK_SWITCHED_IN\r
+#define traceTASK_SWITCHED_IN() \\r
+ if (prvIsNewTCB(pxCurrentTCB)) \\r
+ { \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_ACTIVATE, (uint32_t)pxCurrentTCB, pxCurrentTCB->uxPriority); \\r
+ }\r
\r
-/* Event Group */\r
-#define vTraceExcludeEventGroupFromTrace(handle) \\r
-TRACE_SET_EVENTGROUP_FLAG_ISEXCLUDED(TRACE_GET_EVENTGROUP_NUMBER(handle));\r
+/* Called on vTaskSuspend */\r
+#undef traceTASK_SUSPEND\r
+#define traceTASK_SUSPEND( pxTaskToSuspend ) \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_SUSPEND, (uint32_t)pxTaskToSuspend);\r
\r
-#define vTraceIncludeEventGroupInTrace(handle) \\r
-TRACE_CLEAR_EVENTGROUP_FLAG_ISEXCLUDED(TRACE_GET_EVENTGROUP_NUMBER(handle));\r
+/* Called on vTaskDelay - note the use of FreeRTOS variable xTicksToDelay */\r
+#undef traceTASK_DELAY\r
+#define traceTASK_DELAY() \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY, xTicksToDelay);\r
\r
+/* Called on vTaskDelayUntil - note the use of FreeRTOS variable xTimeToWake */\r
+#undef traceTASK_DELAY_UNTIL\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X\r
+#define traceTASK_DELAY_UNTIL(xTimeToWake) \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY_UNTIL, (uint32_t)xTimeToWake);\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_DELAY_UNTIL() \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_DELAY_UNTIL, (uint32_t)xTimeToWake);\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
\r
-/* Kernel Services */\r
-#define vTraceExcludeKernelServiceDelayFromTrace() \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY_UNTIL);\r
+/* Called on vTaskDelete */\r
+#undef traceTASK_DELETE\r
+#define traceTASK_DELETE( pxTaskToDelete ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_DELETE, (uint32_t)pxTaskToDelete, (pxTaskToDelete != NULL) ? (pxTaskToDelete->uxPriority) : 0); \\r
+ prvTraceDeleteSymbol(pxTaskToDelete); \\r
+ prvTraceDeleteObjectData(pxTaskToDelete);\r
+\r
+/* Called on vQueueDelete */\r
+#undef traceQUEUE_DELETE\r
+#define traceQUEUE_DELETE( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_QUEUE_DELETE, (uint32_t)pxQueue, (pxQueue != NULL) ? (pxQueue->uxMessagesWaiting) : 0); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent2(PSF_EVENT_MUTEX_DELETE, (uint32_t)pxQueue, (pxQueue != NULL) ? (pxQueue->uxMessagesWaiting) : 0); \\r
+ break; \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_DELETE, (uint32_t)pxQueue, (pxQueue != NULL) ? (pxQueue->uxMessagesWaiting) : 0); \\r
+ break; \\r
+ } \\r
+ prvTraceDeleteSymbol(pxQueue);\r
+\r
+/* Called on vTaskCreate */\r
+#undef traceTASK_CREATE\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X\r
+#define traceTASK_CREATE(pxNewTCB) \\r
+ if (pxNewTCB != NULL) \\r
+ { \\r
+ prvTraceSaveSymbol(pxNewTCB, pxNewTCB->pcTaskName); \\r
+ prvTraceSaveObjectData(pxNewTCB, pxNewTCB->uxPriority); \\r
+ prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, pxNewTCB->pcTaskName, pxNewTCB); \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_CREATE, (uint32_t)pxNewTCB, pxNewTCB->uxPriority); \\r
+ }\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_CREATE(pxNewTCB) \\r
+ if (pxNewTCB != NULL) \\r
+ { \\r
+ prvTraceSaveSymbol(pxNewTCB, (const char*)pcName); \\r
+ prvTraceSaveObjectData(pxNewTCB, uxPriority); \\r
+ prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, pcName, pxNewTCB); \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_CREATE, (uint32_t)pxNewTCB, uxPriority); \\r
+ }\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+\r
+/* Called in vTaskCreate, if it fails (typically if the stack can not be allocated) */\r
+#undef traceTASK_CREATE_FAILED\r
+#define traceTASK_CREATE_FAILED() \\r
+ prvTraceStoreEvent0(PSF_EVENT_TASK_CREATE_FAILED);\r
+\r
+/* Called in xQueueCreate, and thereby for all other object based on queues, such as semaphores. */\r
+#undef traceQUEUE_CREATE\r
+#define traceQUEUE_CREATE( pxNewQueue )\\r
+ switch (pxNewQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_QUEUE_CREATE, (uint32_t)pxNewQueue, pxNewQueue->uxLength); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ prvTraceStoreEvent1(PSF_EVENT_SEMAPHORE_BINARY_CREATE, (uint32_t)pxNewQueue); \\r
+ break; \\r
+ }\r
+\r
+/* Called in xQueueCreate, if the queue creation fails */\r
+#undef traceQUEUE_CREATE_FAILED\r
+#define traceQUEUE_CREATE_FAILED( queueType ) \\r
+ switch (queueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent0(PSF_EVENT_QUEUE_CREATE_FAILED); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ prvTraceStoreEvent0(PSF_EVENT_SEMAPHORE_BINARY_CREATE_FAILED); \\r
+ break; \\r
+ }\r
+\r
+/* Called in xQueueCreateCountingSemaphore, if the queue creation fails */\r
+#undef traceCREATE_COUNTING_SEMAPHORE\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X\r
+#define traceCREATE_COUNTING_SEMAPHORE() \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE, (uint32_t)xHandle, ((Queue_t *) xHandle)->uxMessagesWaiting);\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceCREATE_COUNTING_SEMAPHORE() \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_COUNTING_CREATE, (uint32_t)pxHandle, pxHandle->uxMessagesWaiting);\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+\r
+#undef traceCREATE_COUNTING_SEMAPHORE_FAILED\r
+#define traceCREATE_COUNTING_SEMAPHORE_FAILED() \\r
+ prvTraceStoreEvent0(PSF_EVENT_SEMAPHORE_COUNTING_CREATE_FAILED);\r
+\r
+/* Called in xQueueCreateMutex, and thereby also from xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex */\r
+#undef traceCREATE_MUTEX\r
+#define traceCREATE_MUTEX( pxNewQueue ) \\r
+ switch (pxNewQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_CREATE, (uint32_t)pxNewQueue); \\r
+ break; \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_RECURSIVE_CREATE, (uint32_t)pxNewQueue); \\r
+ break; \\r
+ }\r
+\r
+/* Called in xQueueCreateMutex when the operation fails (when memory allocation fails) */\r
+#undef traceCREATE_MUTEX_FAILED\r
+#define traceCREATE_MUTEX_FAILED() \\r
+ prvTraceStoreEvent0(PSF_EVENT_MUTEX_CREATE_FAILED);\r
+\r
+/* Called when a message is sent to a queue */ /* CS IS NEW ! */\r
+#undef traceQUEUE_SEND\r
+#define traceQUEUE_SEND( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND : PSF_EVENT_QUEUE_SEND_FRONT, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE, (uint32_t)pxQueue); \\r
+ break; \\r
+ }\r
+\r
+/* Called when a message failed to be sent to a queue (timeout) */\r
+#undef traceQUEUE_SEND_FAILED\r
+#define traceQUEUE_SEND_FAILED( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_FAILED : PSF_EVENT_QUEUE_SEND_FRONT_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE_FAILED, (uint32_t)pxQueue); \\r
+ break; \\r
+ }\r
+\r
+/* Called when the task is blocked due to a send operation on a full queue */\r
+#undef traceBLOCKING_ON_QUEUE_SEND\r
+#define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_BLOCK : PSF_EVENT_QUEUE_SEND_FRONT_BLOCK, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_BLOCK, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE_BLOCK, (uint32_t)pxQueue); \\r
+ break; \\r
+ }\r
+\r
+/* Called for Recursive Mutex */\r
+#undef traceGIVE_MUTEX_RECURSIVE\r
+#define traceGIVE_MUTEX_RECURSIVE( pxMutex ) \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE_RECURSIVE, (uint32_t)pxMutex);\r
+\r
+/* Called for Recursive Mutex */\r
+#undef traceGIVE_MUTEX_RECURSIVE_FAILED\r
+#define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_GIVE_RECURSIVE_FAILED, (uint32_t)pxMutex);\r
+\r
+/**************************************************************************/\r
+/* Makes sure xQueueGiveFromISR also has a xCopyPosition parameter */\r
+/**************************************************************************/\r
+/* Helpers needed to correctly expand names */\r
+#define TZ__CAT2(a,b) a ## b\r
+#define TZ__CAT(a,b) TZ__CAT2(a, b)\r
+\r
+/* Expands name if this header is included... uxQueueType must be a macro that only exists in queue.c or whatever, and it must expand to nothing or to something that's valid in identifiers */\r
+#define xQueueGiveFromISR(a,b) TZ__CAT(xQueueGiveFromISR__, uxQueueType) (a,b)\r
+\r
+/* If in queue.c, the "uxQueueType" macro expands to "pcHead". queueSEND_TO_BACK is the value we need to send in */\r
+#define xQueueGiveFromISR__pcHead(__a, __b) MyWrapper(__a, __b, const BaseType_t xCopyPosition); \\r
+BaseType_t xQueueGiveFromISR(__a, __b) { return MyWrapper(xQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK); } \\r
+BaseType_t MyWrapper(__a, __b, const BaseType_t xCopyPosition)\r
+\r
+/* If not in queue.c, "uxQueueType" isn't expanded */\r
+#define xQueueGiveFromISR__uxQueueType(__a, __b) xQueueGiveFromISR(__a,__b)\r
+\r
+/**************************************************************************/\r
+/* End of xQueueGiveFromISR fix */\r
+/**************************************************************************/\r
+\r
+/* Called when a message is sent from interrupt context, e.g., using xQueueSendFromISR */\r
+#undef traceQUEUE_SEND_FROM_ISR\r
+#define traceQUEUE_SEND_FROM_ISR( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_FROMISR : PSF_EVENT_QUEUE_SEND_FRONT_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting + 1); \\r
+ break; \\r
+ }\r
+\r
+/* Called when a message send from interrupt context fails (since the queue was full) */\r
+#undef traceQUEUE_SEND_FROM_ISR_FAILED\r
+#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(xCopyPosition == queueSEND_TO_BACK ? PSF_EVENT_QUEUE_SEND_FROMISR_FAILED : PSF_EVENT_QUEUE_SEND_FRONT_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_GIVE_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ }\r
+\r
+/* Called when a message is received from a queue */\r
+#undef traceQUEUE_RECEIVE\r
+#define traceQUEUE_RECEIVE( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent3(PSF_EVENT_QUEUE_RECEIVE, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting - 1); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_TAKE, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting - 1); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent2(PSF_EVENT_MUTEX_TAKE, (uint32_t)pxQueue, xTicksToWait); \\r
+ break; \\r
+ }\r
+\r
+/* Called when a receive operation on a queue fails (timeout) */\r
+#undef traceQUEUE_RECEIVE_FAILED\r
+#define traceQUEUE_RECEIVE_FAILED( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent3(xJustPeeking == pdFALSE ? PSF_EVENT_QUEUE_RECEIVE_FAILED : PSF_EVENT_QUEUE_PEEK_FAILED, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent3(xJustPeeking == pdFALSE ? PSF_EVENT_SEMAPHORE_TAKE_FAILED : PSF_EVENT_SEMAPHORE_PEEK_FAILED, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent2(xJustPeeking == pdFALSE ? PSF_EVENT_MUTEX_TAKE_FAILED : PSF_EVENT_MUTEX_PEEK_FAILED, (uint32_t)pxQueue, xTicksToWait); \\r
+ break; \\r
+ }\r
+\r
+/* Called when the task is blocked due to a receive operation on an empty queue */\r
+#undef traceBLOCKING_ON_QUEUE_RECEIVE\r
+#define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent3(xJustPeeking == pdFALSE ? PSF_EVENT_QUEUE_RECEIVE_BLOCK : PSF_EVENT_QUEUE_PEEK_BLOCK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent3(xJustPeeking == pdFALSE ? PSF_EVENT_SEMAPHORE_TAKE_BLOCK : PSF_EVENT_SEMAPHORE_PEEK_BLOCK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent2(xJustPeeking == pdFALSE ? PSF_EVENT_MUTEX_TAKE_BLOCK : PSF_EVENT_MUTEX_PEEK_BLOCK, (uint32_t)pxQueue, xTicksToWait); \\r
+ break; \\r
+ }\r
+ \r
+#undef traceTAKE_MUTEX_RECURSIVE\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X\r
+#define traceTAKE_MUTEX_RECURSIVE( pxQueue ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_MUTEX_TAKE_RECURSIVE, (uint32_t)pxQueue, xTicksToWait);\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTAKE_MUTEX_RECURSIVE( pxQueue ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_MUTEX_TAKE_RECURSIVE, (uint32_t)pxQueue, xBlockTime);\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+\r
+#undef traceTAKE_MUTEX_RECURSIVE_FAILED\r
+#if TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X\r
+#define traceTAKE_MUTEX_RECURSIVE_FAILED( pxQueue ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_MUTEX_TAKE_RECURSIVE_FAILED, (uint32_t)pxQueue, xTicksToWait);\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTAKE_MUTEX_RECURSIVE_FAILED( pxQueue ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_MUTEX_TAKE_RECURSIVE_FAILED, (uint32_t)pxQueue, xBlockTime);\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+\r
+/* Called when a message is received in interrupt context, e.g., using xQueueReceiveFromISR */\r
+#undef traceQUEUE_RECEIVE_FROM_ISR\r
+#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) \\r
+switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_QUEUE_RECEIVE_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting - 1); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_TAKE_FROMISR, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting - 1); \\r
+ break; \\r
+ }\r
+\r
+/* Called when a message receive from interrupt context fails (since the queue was empty) */\r
+#undef traceQUEUE_RECEIVE_FROM_ISR_FAILED\r
+#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_QUEUE_RECEIVE_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent2(PSF_EVENT_SEMAPHORE_TAKE_FROMISR_FAILED, (uint32_t)pxQueue, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ }\r
+\r
+/* Called on xQueuePeek */\r
+#undef traceQUEUE_PEEK\r
+#define traceQUEUE_PEEK( pxQueue ) \\r
+ switch (pxQueue->ucQueueType) \\r
+ { \\r
+ case queueQUEUE_TYPE_BASE: \\r
+ prvTraceStoreEvent3(PSF_EVENT_QUEUE_PEEK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_BINARY_SEMAPHORE: \\r
+ case queueQUEUE_TYPE_COUNTING_SEMAPHORE: \\r
+ prvTraceStoreEvent3(PSF_EVENT_SEMAPHORE_PEEK, (uint32_t)pxQueue, xTicksToWait, pxQueue->uxMessagesWaiting); \\r
+ break; \\r
+ case queueQUEUE_TYPE_MUTEX: \\r
+ case queueQUEUE_TYPE_RECURSIVE_MUTEX: \\r
+ prvTraceStoreEvent1(PSF_EVENT_MUTEX_PEEK, (uint32_t)pxQueue); \\r
+ break; \\r
+ }\r
+\r
+/* Called in vTaskPrioritySet */\r
+#undef traceTASK_PRIORITY_SET\r
+#define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) \\r
+ prvTraceSaveObjectData(pxTask, uxNewPriority); \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_PRIORITY, (uint32_t)pxTask, uxNewPriority);\r
+ \r
+/* Called in vTaskPriorityInherit, which is called by Mutex operations */\r
+#undef traceTASK_PRIORITY_INHERIT\r
+#define traceTASK_PRIORITY_INHERIT( pxTask, uxNewPriority ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_PRIO_INHERIT, (uint32_t)pxTask, uxNewPriority);\r
+\r
+/* Called in vTaskPriorityDisinherit, which is called by Mutex operations */\r
+#undef traceTASK_PRIORITY_DISINHERIT\r
+#define traceTASK_PRIORITY_DISINHERIT( pxTask, uxNewPriority ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_PRIO_DISINHERIT, (uint32_t)pxTask, uxNewPriority);\r
+\r
+/* Called in vTaskResume */\r
+#undef traceTASK_RESUME\r
+#define traceTASK_RESUME( pxTaskToResume ) \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_RESUME, (uint32_t)pxTaskToResume);\r
+\r
+/* Called in vTaskResumeFromISR */\r
+#undef traceTASK_RESUME_FROM_ISR\r
+#define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_RESUME_FROMISR, (uint32_t)pxTaskToResume);\r
+\r
+#undef traceMALLOC\r
+#define traceMALLOC( pvAddress, uiSize ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_MALLOC, (uint32_t)pvAddress, uiSize);\r
+\r
+#undef traceFREE\r
+#define traceFREE( pvAddress, uiSize ) \\r
+ prvTraceStoreEvent2(PSF_EVENT_FREE, (uint32_t)pvAddress, (uint32_t)(-uiSize));\r
\r
-#define vTraceIncludeKernelServiceDelayInTrace() \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY_UNTIL);\r
+/* Called in timer.c - xTimerCreate */\r
+#undef traceTIMER_CREATE\r
+#define traceTIMER_CREATE(tmr) \\r
+ prvTraceSaveSymbol(tmr, tmr->pcTimerName); \\r
+ prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, tmr->pcTimerName, tmr); \\r
+ prvTraceStoreEvent2(PSF_EVENT_TIMER_CREATE, (uint32_t)tmr, tmr->xTimerPeriodInTicks);\r
\r
-/* HELPER MACROS FOR KERNEL SERVICES FOR OBJECTS */\r
-#define vTraceExcludeKernelServiceSendFromTrace_HELPER(class) \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_SUCCESS + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_BLOCK + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FAILED + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR_SUCCESS + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR_FAILED + class);\r
+#undef traceTIMER_CREATE_FAILED\r
+#define traceTIMER_CREATE_FAILED() \\r
+ prvTraceStoreEvent0(PSF_EVENT_TIMER_CREATE_FAILED);\r
+\r
+#if (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X)\r
+#define traceTIMER_COMMAND_SEND_8_0_CASES(tmr) \\r
+ case tmrCOMMAND_RESET: \\r
+ prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_RESET : PSF_EVENT_TIMER_RESET_FAILED, (uint32_t)tmr, xOptionalValue); \\r
+ break; \\r
+ case tmrCOMMAND_START_FROM_ISR: \\r
+ prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_START_FROMISR : PSF_EVENT_TIMER_START_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \\r
+ break; \\r
+ case tmrCOMMAND_RESET_FROM_ISR: \\r
+ prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_RESET_FROMISR : PSF_EVENT_TIMER_RESET_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \\r
+ break; \\r
+ case tmrCOMMAND_STOP_FROM_ISR: \\r
+ prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_STOP_FROMISR : PSF_EVENT_TIMER_STOP_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \\r
+ break; \\r
+ case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR: \\r
+ prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR : PSF_EVENT_TIMER_CHANGEPERIOD_FROMISR_FAILED, (uint32_t)tmr, xOptionalValue); \\r
+ break;\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTIMER_COMMAND_SEND_8_0_CASES(tmr) \r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_8_X || TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
\r
-#define vTraceIncludeKernelServiceSendInTrace_HELPER(class) \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_SUCCESS + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_BLOCK + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FAILED + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR_SUCCESS + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR_FAILED + class);\r
+/* Note that xCommandID can never be tmrCOMMAND_EXECUTE_CALLBACK (-1) since the trace macro is not called in that case */\r
+#undef traceTIMER_COMMAND_SEND\r
+#define traceTIMER_COMMAND_SEND(tmr, xCommandID, xOptionalValue, xReturn) \\r
+ switch(xCommandID) \\r
+ { \\r
+ case tmrCOMMAND_START: \\r
+ prvTraceStoreEvent1((xReturn == pdPASS) ? PSF_EVENT_TIMER_START : PSF_EVENT_TIMER_START_FAILED, (uint32_t)tmr); \\r
+ break; \\r
+ case tmrCOMMAND_STOP: \\r
+ prvTraceStoreEvent1((xReturn == pdPASS) ? PSF_EVENT_TIMER_STOP : PSF_EVENT_TIMER_STOP_FAILED, (uint32_t)tmr); \\r
+ break; \\r
+ case tmrCOMMAND_CHANGE_PERIOD: \\r
+ prvTraceStoreEvent2((xReturn == pdPASS) ? PSF_EVENT_TIMER_CHANGEPERIOD : PSF_EVENT_TIMER_CHANGEPERIOD_FAILED, (uint32_t)tmr, xOptionalValue); \\r
+ break; \\r
+ case tmrCOMMAND_DELETE: \\r
+ prvTraceStoreEvent1((xReturn == pdPASS) ? PSF_EVENT_TIMER_DELETE : PSF_EVENT_TIMER_DELETE_FAILED, (uint32_t)tmr); \\r
+ break; \\r
+ traceTIMER_COMMAND_SEND_8_0_CASES(tmr) \\r
+ }\r
+\r
+#undef tracePEND_FUNC_CALL\r
+#define tracePEND_FUNC_CALL(func, arg1, arg2, ret) \\r
+ prvTraceStoreEvent1((ret == pdPASS) ? PSF_EVENT_TIMER_PENDFUNCCALL : PSF_EVENT_TIMER_PENDFUNCCALL_FAILED, (uint32_t)func);\r
\r
-#define vTraceExcludeKernelServiceReceiveFromTrace_HELPER(class) \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_SUCCESS + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_BLOCK + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FAILED + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR_SUCCESS + class); \\r
-TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR_FAILED + class);\r
+#undef tracePEND_FUNC_CALL_FROM_ISR\r
+#define tracePEND_FUNC_CALL_FROM_ISR(func, arg1, arg2, ret) \\r
+ prvTraceStoreEvent1((ret == pdPASS) ? PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR : PSF_EVENT_TIMER_PENDFUNCCALL_FROMISR_FAILED, (uint32_t)func);\r
\r
-#define vTraceIncludeKernelServiceReceiveInTrace_HELPER(class) \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_SUCCESS + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_BLOCK + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FAILED + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR_SUCCESS + class); \\r
-TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR_FAILED + class);\r
+#undef traceEVENT_GROUP_CREATE\r
+#define traceEVENT_GROUP_CREATE(eg) \\r
+ prvTraceStoreEvent1(PSF_EVENT_EVENTGROUP_CREATE, (uint32_t)eg);\r
\r
-/* EXCLUDE AND INCLUDE FOR QUEUE */\r
-#define vTraceExcludeKernelServiceQueueSendFromTrace() \\r
-vTraceExcludeKernelServiceSendFromTrace_HELPER(TRACE_CLASS_QUEUE);\r
+#undef traceEVENT_GROUP_DELETE\r
+#define traceEVENT_GROUP_DELETE(eg) \\r
+ prvTraceStoreEvent1(PSF_EVENT_EVENTGROUP_DELETE, (uint32_t)eg); \\r
+ prvTraceDeleteSymbol(eg);\r
\r
-#define vTraceIncludeKernelServiceQueueSendInTrace() \\r
-vTraceIncludeKernelServiceSendInTrace_HELPER(TRACE_CLASS_QUEUE);\r
+#undef traceEVENT_GROUP_CREATE_FAILED\r
+#define traceEVENT_GROUP_CREATE_FAILED() \\r
+ prvTraceStoreEvent0(PSF_EVENT_EVENTGROUP_CREATE_FAILED);\r
\r
-#define vTraceExcludeKernelServiceQueueReceiveFromTrace() \\r
-vTraceExcludeKernelServiceReceiveFromTrace_HELPER(TRACE_CLASS_QUEUE);\r
+#undef traceEVENT_GROUP_SYNC_BLOCK\r
+#define traceEVENT_GROUP_SYNC_BLOCK(eg, bitsToSet, bitsToWaitFor) \\r
+ prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_SYNC_BLOCK, (uint32_t)eg, bitsToWaitFor);\r
\r
-#define vTraceIncludeKernelServiceQueueReceiveInTrace() \\r
-vTraceIncludeKernelServiceReceiveInTrace_HELPER(TRACE_CLASS_QUEUE);\r
+#undef traceEVENT_GROUP_SYNC_END\r
+#define traceEVENT_GROUP_SYNC_END(eg, bitsToSet, bitsToWaitFor, wasTimeout) \\r
+ prvTraceStoreEvent2((wasTimeout != pdTRUE) ? PSF_EVENT_EVENTGROUP_SYNC : PSF_EVENT_EVENTGROUP_SYNC_FAILED, (uint32_t)eg, bitsToWaitFor);\r
\r
-/* EXCLUDE AND INCLUDE FOR SEMAPHORE */\r
-#define vTraceExcludeKernelServiceSemaphoreSendFromTrace() \\r
-vTraceExcludeKernelServiceSendFromTrace_HELPER(TRACE_CLASS_SEMAPHORE);\r
+#undef traceEVENT_GROUP_WAIT_BITS_BLOCK\r
+#define traceEVENT_GROUP_WAIT_BITS_BLOCK(eg, bitsToWaitFor) \\r
+ prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_WAITBITS_BLOCK, (uint32_t)eg, bitsToWaitFor);\r
\r
-#define vTraceIncludeKernelServicSemaphoreSendInTrace() \\r
-vTraceIncludeKernelServiceSendInTrace_HELPER(TRACE_CLASS_SEMAPHORE);\r
+#undef traceEVENT_GROUP_WAIT_BITS_END\r
+#define traceEVENT_GROUP_WAIT_BITS_END(eg, bitsToWaitFor, wasTimeout) \\r
+ prvTraceStoreEvent2((wasTimeout != pdTRUE) ? PSF_EVENT_EVENTGROUP_WAITBITS : PSF_EVENT_EVENTGROUP_WAITBITS_FAILED, (uint32_t)eg, bitsToWaitFor);\r
\r
-#define vTraceExcludeKernelServiceSemaphoreReceiveFromTrace() \\r
-vTraceExcludeKernelServiceReceiveFromTrace_HELPER(TRACE_CLASS_SEMAPHORE);\r
+#undef traceEVENT_GROUP_CLEAR_BITS\r
+#define traceEVENT_GROUP_CLEAR_BITS(eg, bitsToClear) \\r
+ prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_CLEARBITS, (uint32_t)eg, bitsToClear);\r
\r
-#define vTraceIncludeKernelServiceSemaphoreReceiveInTrace() \\r
-vTraceIncludeKernelServiceReceiveInTrace_HELPER(TRACE_CLASS_SEMAPHORE);\r
+#undef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR\r
+#define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR(eg, bitsToClear) \\r
+ prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_CLEARBITS_FROMISR, (uint32_t)eg, bitsToClear);\r
\r
-/* EXCLUDE AND INCLUDE FOR MUTEX */\r
-#define vTraceExcludeKernelServiceMutexSendFromTrace() \\r
-vTraceExcludeKernelServiceSendFromTrace_HELPER(TRACE_CLASS_MUTEX);\r
+#undef traceEVENT_GROUP_SET_BITS\r
+#define traceEVENT_GROUP_SET_BITS(eg, bitsToSet) \\r
+ prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_SETBITS, (uint32_t)eg, bitsToSet);\r
\r
-#define vTraceIncludeKernelServiceMutexSendInTrace() \\r
-vTraceIncludeKernelServiceSendInTrace_HELPER(TRACE_CLASS_MUTEX);\r
+#undef traceEVENT_GROUP_SET_BITS_FROM_ISR\r
+#define traceEVENT_GROUP_SET_BITS_FROM_ISR(eg, bitsToSet) \\r
+ prvTraceStoreEvent2(PSF_EVENT_EVENTGROUP_SETBITS_FROMISR, (uint32_t)eg, bitsToSet);\r
\r
-#define vTraceExcludeKernelServiceMutexReceiveFromTrace() \\r
-vTraceExcludeKernelServiceReceiveFromTrace_HELPER(TRACE_CLASS_MUTEX);\r
+#undef traceTASK_NOTIFY_TAKE\r
+#if (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X)\r
+#define traceTASK_NOTIFY_TAKE() \\r
+ if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE, (uint32_t)pxCurrentTCB, xTicksToWait); \\r
+ else \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_NOTIFY_TAKE() \\r
+ if (pxCurrentTCB->eNotifyState == eNotified) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE, (uint32_t)pxCurrentTCB, xTicksToWait); \\r
+ else \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
\r
-#define vTraceIncludeKernelServiceMutexReceiveInTrace() \\r
-vTraceIncludeKernelServiceReceiveInTrace_HELPER(TRACE_CLASS_MUTEX);\r
+#undef traceTASK_NOTIFY_TAKE_BLOCK\r
+#define traceTASK_NOTIFY_TAKE_BLOCK() \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_TAKE_BLOCK, (uint32_t)pxCurrentTCB, xTicksToWait);\r
\r
-/************************************************************************/\r
-/* KERNEL SPECIFIC MACROS TO NAME OBJECTS, IF NECESSARY */\r
-/************************************************************************/\r
-#define vTraceSetQueueName(object, name) \\r
-vTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, object), TRACE_GET_OBJECT_NUMBER(UNUSED, object), name);\r
+#undef traceTASK_NOTIFY_WAIT\r
+#if (TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X)\r
+#define traceTASK_NOTIFY_WAIT() \\r
+ if (pxCurrentTCB->ucNotifyState == taskNOTIFICATION_RECEIVED) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT, (uint32_t)pxCurrentTCB, xTicksToWait); \\r
+ else \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);\r
+#else /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
+#define traceTASK_NOTIFY_WAIT() \\r
+ if (pxCurrentTCB->eNotifyState == eNotified) \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT, (uint32_t)pxCurrentTCB, xTicksToWait); \\r
+ else \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT_FAILED, (uint32_t)pxCurrentTCB, xTicksToWait);\r
+#endif /* TRC_CFG_FREERTOS_VERSION == TRC_FREERTOS_VERSION_9_X */\r
\r
-#define vTraceSetSemaphoreName(object, name) \\r
-vTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, object), TRACE_GET_OBJECT_NUMBER(UNUSED, object), name);\r
+#undef traceTASK_NOTIFY_WAIT_BLOCK\r
+#define traceTASK_NOTIFY_WAIT_BLOCK() \\r
+ prvTraceStoreEvent2(PSF_EVENT_TASK_NOTIFY_WAIT_BLOCK, (uint32_t)pxCurrentTCB, xTicksToWait);\r
\r
-#define vTraceSetMutexName(object, name) \\r
-vTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, object), TRACE_GET_OBJECT_NUMBER(UNUSED, object), name);\r
+#undef traceTASK_NOTIFY\r
+#define traceTASK_NOTIFY() \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_NOTIFY, (uint32_t)xTaskToNotify);\r
\r
-#define vTraceSetEventGroupName(object, name) \\r
-vTraceSetObjectName(TRACE_CLASS_EVENTGROUP, (objectHandleType)uxEventGroupGetNumber(object), name);\r
+#undef traceTASK_NOTIFY_FROM_ISR\r
+#define traceTASK_NOTIFY_FROM_ISR() \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_NOTIFY_FROM_ISR, (uint32_t)xTaskToNotify);\r
+ \r
+#undef traceTASK_NOTIFY_GIVE_FROM_ISR\r
+#define traceTASK_NOTIFY_GIVE_FROM_ISR() \\r
+ prvTraceStoreEvent1(PSF_EVENT_TASK_NOTIFY_GIVE_FROM_ISR, (uint32_t)xTaskToNotify);\r
\r
#undef traceQUEUE_REGISTRY_ADD\r
-#define traceQUEUE_REGISTRY_ADD(object, name) vTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(UNUSED, object), TRACE_GET_OBJECT_NUMBER(UNUSED, object), name);\r
+#define traceQUEUE_REGISTRY_ADD(object, name) \\r
+ prvTraceSaveSymbol(object, (const char*)name); \\r
+ prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, name, object);\r
+\r
+#endif /*#if TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING */\r
+\r
+#else /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+ \r
+ /* when recorder disabled */\r
+ #define vTraceSetQueueName(object, name)\r
+ #define vTraceSetSemaphoreName(object, name)\r
+ #define vTraceSetMutexName(object, name)\r
+\r
+ #define vTraceExcludeQueue(handle)\r
+ #define vTraceExcludeSemaphore(handle)\r
+ #define vTraceExcludeMutex(handle)\r
+ #define vTraceExcludeTimer(handle)\r
+ #define vTraceExcludeEventGroup(handle)\r
+ #define vTraceExcludeDelays()\r
+\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+\r
+#ifdef __cplusplus\r
+}\r
#endif\r
\r
-#endif /* TRCKERNELPORTFREERTOS_H_ */\r
+#endif /* TRC_KERNEL_PORT_H */\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcPortDefines.h\r
+ *\r
+ * Some common defines for the trace recorder.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_PORTDEFINES_H\r
+#define TRC_PORTDEFINES_H\r
+\r
+#define TRC_FREE_RUNNING_32BIT_INCR 1\r
+#define TRC_FREE_RUNNING_32BIT_DECR 2\r
+#define TRC_OS_TIMER_INCR 3\r
+#define TRC_OS_TIMER_DECR 4\r
+#define TRC_CUSTOM_TIMER_INCR 5\r
+#define TRC_CUSTOM_TIMER_DECR 6\r
+\r
+/* Start options for vTraceEnable. */\r
+#define TRC_INIT 0\r
+#define TRC_START 1\r
+#define TRC_START_AWAIT_HOST 2\r
+\r
+/* Command codes for TzCtrl task */\r
+#define CMD_SET_ACTIVE 1 /* Start (param1 = 1) or Stop (param1 = 0) */\r
+\r
+/* The final command code, used to validate commands. */\r
+#define CMD_LAST_COMMAND 1\r
+\r
+#define TRC_RECORDER_MODE_SNAPSHOT 0\r
+#define TRC_RECORDER_MODE_STREAMING 1\r
+\r
+#define TRC_RECORDER_BUFFER_ALLOCATION_STATIC (0x00)\r
+#define TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC (0x01)\r
+#define TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM (0x02)\r
+\r
+\r
+/******************************************************************************\r
+ * Supported ports\r
+ *\r
+ * TRC_HARDWARE_PORT_HWIndependent\r
+ * A hardware independent fallback option for event timestamping. Provides low\r
+ * resolution timestamps based on the OS tick.\r
+ * This may be used on the Win32 port, but may also be used on embedded hardware\r
+ * platforms. All time durations will be truncated to the OS tick frequency,\r
+ * typically 1 KHz. This means that a task or ISR that executes in less than\r
+ * 1 ms get an execution time of zero.\r
+ *\r
+ * TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
+ * Allows for defining the port macros in other source code files.\r
+ *\r
+ * TRC_HARDWARE_PORT_Win32\r
+ * "Accurate" timestamping based on the Windows performance counter for Win32\r
+ * builds. Note that this gives the host machine time, not the kernel time.\r
+ *\r
+ * Hardware specific ports\r
+ * To get accurate timestamping, a hardware timer is necessary. Below are the\r
+ * available ports. Some of these are "unofficial", meaning that\r
+ * they have not yet been verified by Percepio but have been contributed by\r
+ * external developers. They should work, otherwise let us know by emailing\r
+ * support@percepio.com. Some work on any OS platform, while other are specific\r
+ * to a certain operating system.\r
+ *****************************************************************************/\r
+\r
+/****** Port Name ************************************* Code ** Official ** OS Platform *********/\r
+#define TRC_HARDWARE_PORT_APPLICATION_DEFINED 98 /* - - */\r
+#define TRC_HARDWARE_PORT_NOT_SET 99 /* - - */\r
+#define TRC_HARDWARE_PORT_HWIndependent 0 /* Yes Any */\r
+#define TRC_HARDWARE_PORT_Win32 1 /* Yes FreeRTOS on Win32 */\r
+#define TRC_HARDWARE_PORT_Atmel_AT91SAM7 2 /* No Any */\r
+#define TRC_HARDWARE_PORT_Atmel_UC3A0 3 /* No Any */\r
+#define TRC_HARDWARE_PORT_ARM_Cortex_M 4 /* Yes Any */\r
+#define TRC_HARDWARE_PORT_Renesas_RX600 6 /* Yes Any */\r
+#define TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32 7 /* Yes Any */\r
+#define TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48 8 /* Yes Any */\r
+#define TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_MSP430 9 /* No Any */\r
+#define TRC_HARDWARE_PORT_XILINX_PPC405 11 /* No FreeRTOS */\r
+#define TRC_HARDWARE_PORT_XILINX_PPC440 12 /* No FreeRTOS */\r
+#define TRC_HARDWARE_PORT_XILINX_MICROBLAZE 13 /* No Any */\r
+#define TRC_HARDWARE_PORT_NXP_LPC210X 14 /* No Any */\r
+#define TRC_HARDWARE_PORT_ARM_CORTEX_A9 15 /* Yes Any */\r
+#define TRC_HARDWARE_PORT_POWERPC_Z4 16 /* No FreeRTOS */\r
+\r
+#endif /*TRC_PORTDEFINES_H*/\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcRecorder.h\r
+ *\r
+ * The public API of the trace recorder.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you. \r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_RECORDER_H\r
+#define TRC_RECORDER_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include <stdarg.h>\r
+#include <stdint.h>\r
+#include "trcConfig.h"\r
+#include "trcPortDefines.h"\r
+\r
+\r
+ \r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+typedef uint16_t traceString;\r
+typedef uint8_t traceUBChannel;\r
+typedef uint8_t traceObjectClass;\r
+\r
+#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
+typedef uint16_t traceHandle;\r
+#else\r
+typedef uint8_t traceHandle;\r
+#endif\r
+ \r
+#include "trcHardwarePort.h"\r
+#include "trcKernelPort.h"\r
+\r
+#endif\r
+ \r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
+\r
+typedef const char* traceString;\r
+typedef const void* traceHandle;\r
+\r
+#include "trcHardwarePort.h"\r
+#include "trcStreamingPort.h"\r
+#include "trcKernelPort.h"\r
+\r
+#endif\r
+\r
+#if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
+ \r
+/******************************************************************************/\r
+/*** Common API - both Snapshot and Streaming mode ****************************/\r
+/******************************************************************************/\r
+\r
+/******************************************************************************\r
+* vTraceEnable(int startOption);\r
+*\r
+* Initializes and optionally starts the trace, depending on the start option.\r
+* To use the trace recorder, the startup must call vTraceEnable before any RTOS\r
+* calls are made (including "create" calls). Three start options are provided:\r
+* \r
+* TRC_START: Starts the tracing directly. In snapshot mode this allows for \r
+* starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)\r
+* has been called in the startup.\r
+* Can also be used for streaming without Tracealyzer control, e.g. to a local\r
+* flash file system (assuming such a "stream port", see trcStreamingPort.h).\r
+* \r
+* TRC_START_AWAIT_HOST: For streaming mode only. Initializes the trace recorder\r
+* if necessary and waits for a Start command from Tracealyzer ("Start Recording"\r
+* button). This call is intentionally blocking! By calling vTraceEnable with\r
+* this option from the startup code, you start tracing at this point and capture\r
+* the early events.\r
+*\r
+* TRC_INIT: Initializes the trace recorder, but does not start the tracing.\r
+* In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime\r
+* later.\r
+*\r
+* Usage examples:\r
+* \r
+* Snapshot trace, from startup:\r
+* <board init>\r
+* vTraceEnable(TRC_START);\r
+* <RTOS init>\r
+*\r
+* Snapshot trace, from a later point:\r
+* <board init>\r
+* vTraceEnable(TRC_INIT);\r
+* <RTOS init>\r
+* ...\r
+* vTraceEnable(TRC_START); // e.g., in task context, at some relevant event\r
+* \r
+* Streaming trace, from startup:\r
+* <board init> \r
+* vTraceEnable(TRC_START_AWAIT_HOST); // Blocks!\r
+* <RTOS init>\r
+*\r
+* Streaming trace, from a later point:\r
+* <board startup>\r
+* vTraceEnable(TRC_INIT);\r
+* <RTOS startup>\r
+* \r
+******************************************************************************/\r
+void vTraceEnable(int startOption);\r
+\r
+/******************************************************************************\r
+ * vTracePrintF\r
+ *\r
+ * Generates "User Events", with formatted text and data, similar to a "printf".\r
+ * User Events can be used for very efficient logging from your application code.\r
+ * It is very fast since the actual string formatting is done on the host side, \r
+ * when the trace is displayed. The execution time is just some microseconds on\r
+ * a 32-bit MCU.\r
+ *\r
+ * User Events are shown as yellow labels in the main trace view of $PNAME.\r
+ *\r
+ * An advantage of User Events is that data can be plotted in the "User Event\r
+ * Signal Plot" view, visualizing any data you log as User Events, discrete\r
+ * states or control system signals (e.g. system inputs or outputs).\r
+ *\r
+ * You may group User Events into User Event Channels. The yellow User Event \r
+ * labels show the logged string, preceded by the channel name within brackets.\r
+ * \r
+ * Example:\r
+ *\r
+ * "[MyChannel] Hello World!"\r
+ *\r
+ * The User Event Channels are shown in the View Filter, which makes it easy to\r
+ * select what User Events you wish to display. User Event Channels are created\r
+ * using xTraceRegisterString().\r
+ *\r
+ * Example:\r
+ *\r
+ * traceString adc_uechannel = xTraceRegisterString("ADC User Events");\r
+ * ...\r
+ * vTracePrintF(adc_uechannel,\r
+ * "ADC channel %d: %d volts",\r
+ * ch, adc_reading);\r
+ *\r
+ * The following format specifiers are supported in both modes:\r
+ * %d - signed integer. \r
+ * %u - unsigned integer.\r
+ * %X - hexadecimal, uppercase. \r
+ * %x - hexadecimal, lowercase.\r
+ * %s - string (see comment below)\r
+ *\r
+ * For integer formats (%d, %u, %x, %X) you may also use width and padding.\r
+ * If using -42 as data argument, two examples are:\r
+ * "%05d" -> "-0042"\r
+ * "%5d" -> " -42".\r
+ *\r
+ * String arguments are supported in both snapshot and streaming, but in streaming\r
+ * mode you need to use xTraceRegisterString and use the returned traceString as\r
+ * the argument. In snapshot you simply provide a char* as argument.\r
+ *\r
+ * Snapshot: vTracePrintF(myChn, "my string: %s", str);\r
+ * Streaming: vTracePrintF(myChn, "my string: %s", xTraceRegisterString(str));\r
+ * \r
+ * In snapshot mode you can specify 8-bit or 16-bit arguments to reduce RAM usage:\r
+ * %hd -> 16 bit (h) signed integer (d).\r
+ * %bu -> 8 bit (b) unsigned integer (u).\r
+ *\r
+ * However, in streaming mode all data arguments are assumed to be 32 bit wide. \r
+ * Width specifiers (e.g. %hd) are accepted but ignored (%hd treated like %d).\r
+ *\r
+ * The maximum event size also differs between the modes. In streaming this is\r
+ * limited by a maximum payload size of 52 bytes, including format string and\r
+ * data arguments. So if using one data argument, the format string is limited\r
+ * to 48 byte, etc. If this is exceeded, the format string is truncated and you\r
+ * get a warning in Tracealyzer.\r
+ *\r
+ * In snapshot mode you are limited to maximum 15 arguments, that must not exceed\r
+ * 32 bytes in total (not counting the format string). If exceeded, the recorder\r
+ * logs an internal error (displayed when opening the trace) and stops recording. \r
+ *\r
+ ******************************************************************************/\r
+void vTracePrintF(traceString chn, const char* fmt, ...);\r
+\r
+/******************************************************************************\r
+* vTracePrint\r
+*\r
+* A faster version of vTracePrintF, that only allows for logging a string.\r
+*\r
+* Example:\r
+*\r
+* traceString chn = xTraceRegisterString("MyChannel");\r
+* ...\r
+* vTracePrint(chn, "Hello World!");\r
+*\r
+******************************************************************************/\r
+void vTracePrint(traceString chn, const char* str);\r
+\r
+/*******************************************************************************\r
+* xTraceRegisterString\r
+*\r
+* Register strings in the recorder, e.g. for names of user event channels.\r
+*\r
+* Example:\r
+* myEventHandle = xTraceRegisterString("MyUserEvent");\r
+* ...\r
+* vTracePrintF(myEventHandle, "My value is: %d", myValue);\r
+*\r
+******************************************************************************/\r
+traceString xTraceRegisterString(const char* name);\r
+\r
+/*******************************************************************************\r
+ * vTraceSet...Name(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the kernel object that shall be named\r
+ * Parameter name: the name to set\r
+ *\r
+ * Kernel-specific functions for setting names of kernel objects, for display in\r
+ * Tracealyzer.\r
+ *\r
+ * See trcKernelPort.h for details (since kernel-specific)\r
+ ******************************************************************************/\r
+\r
+/*******************************************************************************\r
+ * vTraceExclude... \r
+ *\r
+ * Kernel-specific macros for excluding specified events from the trace. Allows \r
+ * for capturing longer traces in snapshot mode by selective tracing.\r
+ *\r
+ * See trcKernelPort.h for details (kernel-specific)\r
+ ******************************************************************************/ \r
+\r
+/*******************************************************************************\r
+ * xTraceSetISRProperties\r
+ *\r
+ * Stores a name and priority level for an Interrupt Service Routine, to allow\r
+ * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin. \r
+ *\r
+ * Example:\r
+ * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * ...\r
+ * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(Timer1Handle);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+traceHandle xTraceSetISRProperties(const char* name, uint8_t priority);\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreISRBegin\r
+ *\r
+ * Registers the beginning of an Interrupt Service Routine, using a traceHandle\r
+ * provided by xTraceSetISRProperties.\r
+ *\r
+ * Example:\r
+ * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * ...\r
+ * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(Timer1Handle);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+void vTraceStoreISRBegin(traceHandle handle);\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreISREnd\r
+ *\r
+ * Registers the end of an Interrupt Service Routine.\r
+ *\r
+ * The parameter pendingISR indicates if the interrupt has requested a\r
+ * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the \r
+ * interrupt is assumed to return to the previous context.\r
+ *\r
+ * Example:\r
+ * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder\r
+ * ...\r
+ * traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(traceHandleIsrTimer1);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+void vTraceStoreISREnd(int isTaskSwitchRequired);\r
+\r
+/*******************************************************************************\r
+ * vTraceInstanceFinishNow\r
+ *\r
+ * Creates an event that ends the current task instance at this very instant.\r
+ * This makes the viewer to splits the current fragment at this point and begin\r
+ * a new actor instance, even if no task-switch has occurred.\r
+ *****************************************************************************/\r
+void vTraceInstanceFinishedNow(void);\r
+\r
+/*******************************************************************************\r
+ * vTraceInstanceFinishedNext\r
+ *\r
+ * Marks the current "task instance" as finished on the next kernel call.\r
+ *\r
+ * If that kernel call is blocking, the instance ends after the blocking event\r
+ * and the corresponding return event is then the start of the next instance.\r
+ * If the kernel call is not blocking, the viewer instead splits the current\r
+ * fragment right before the kernel call, which makes this call the first event\r
+ * of the next instance.\r
+ *****************************************************************************/\r
+void vTraceInstanceFinishedNext(void);\r
+\r
+/*******************************************************************************\r
+ * xTraceGetLastError\r
+ *\r
+ * Returns the last error, if any.\r
+ *****************************************************************************/\r
+const char* xTraceGetLastError(void);\r
+\r
+/*******************************************************************************\r
+ * vTraceClearError\r
+ *\r
+ * Clears any errors.\r
+ *****************************************************************************/\r
+void vTraceClearError(void);\r
+\r
+/*******************************************************************************\r
+* vTraceStop\r
+*\r
+* Stops the recording. Intended for snapshot mode or if streaming without \r
+* Tracealyzer control (e.g., to a device file system).\r
+******************************************************************************/\r
+void vTraceStop(void);\r
+\r
+/******************************************************************************\r
+* vTraceSetFrequency\r
+*\r
+* Registers the clock rate of the time source for the event timestamping.\r
+* This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)\r
+* should be incorrect for your setup, you can override it using this function.\r
+*\r
+* Must be called prior to vTraceEnable, and the time source is assumed to\r
+* have a fixed clock frequency after the startup.\r
+*\r
+* Note that, in snapshot mode, the value is divided by the TRC_HWTC_DIVISOR.\r
+* This is a software "prescaler" that is also applied on the timestamps.\r
+*****************************************************************************/\r
+void vTraceSetFrequency(uint32_t frequency);\r
+\r
+/*******************************************************************************\r
+* vTraceSetRecorderDataBuffer\r
+*\r
+* The trcConfig.h setting TRC_CFG_RECORDER_BUFFER_ALLOCATION allows for selecting\r
+* custom allocation (TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), which allows you to\r
+* control where the recorder trace buffer is allocated.\r
+*\r
+* When custom allocation is selected, use TRC_ALLOC_CUSTOM_BUFFER to make the\r
+* allocation (in global context) and then call vTraceSetRecorderDataBuffer to \r
+* register the allocated buffer. This supports both snapshot and streaming,\r
+* and has no effect if using other allocation modes than CUSTOM. \r
+*\r
+* NOTE: vTraceSetRecorderDataBuffer must be called before vTraceEnable.\r
+******************************************************************************/\r
+#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
+void vTraceSetRecorderDataBuffer(void* pRecorderData);\r
+#else\r
+#define vTraceSetRecorderDataBuffer(pRecorderData)\r
+#endif\r
+\r
+\r
+/*******************************************************************************\r
+* TRC_ALLOC_CUSTOM_BUFFER\r
+*\r
+* If using custom allocation of the trace buffer (i.e., your trcConfig.h has the\r
+* setting TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), this macro allows you to declare\r
+* the trace buffer in a portable way that works both in snapshot and streaming.\r
+*\r
+* This macro has no effect if using another allocation mode, so you can easily \r
+* switch between different recording modes and configurations, using the same \r
+* initialization code.\r
+*\r
+* This translates to a single static allocation, on which you can apply linker\r
+* directives to place it in a particular memory region.\r
+* - Snapshot mode: "RecorderDataType <name>"\r
+* - Streaming mode: "char <name> [<size>]", with <size> from trcStreamingPort.h.\r
+*\r
+* Example:\r
+*\r
+* // GCC example: place myTraceBuffer in section .tz, defined in the .ld file.\r
+* TRC_ALLOC_CUSTOM_BUFFER(myTraceBuffer) __attribute__((section(".tz")));\r
+* \r
+* int main(void)\r
+* {\r
+* ...\r
+* vTraceSetRecorderDataBuffer(&myTraceBuffer); // Note the "&"\r
+* ...\r
+* vTraceEnable(TRC_INIT); // Initialize the data structure\r
+*\r
+******************************************************************************/\r
+#ifndef TRC_ALLOC_CUSTOM_BUFFER\r
+/* Definition for snapshot mode only. Also defined in trcStreamingPort.h */\r
+#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname) RecorderDataType bufname;\r
+#else\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname)\r
+#endif\r
+#endif\r
+\r
+\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+\r
+/******************************************************************************/\r
+/*** Extended API for Snapshot mode *******************************************/\r
+/******************************************************************************/\r
+\r
+/******************************************************************************\r
+* TRACE_STOP_HOOK - Hook Pointer Data Type\r
+*\r
+* Declares a data type for a call back function that will be invoked whenever\r
+* the recorder is stopped.\r
+*\r
+* Snapshot mode only!\r
+******************************************************************************/\r
+typedef void(*TRACE_STOP_HOOK)(void);\r
+\r
+/*******************************************************************************\r
+* vTraceStopHookPtr\r
+*\r
+* Points to a call back function that is called from vTraceStop().\r
+*\r
+* Snapshot mode only!\r
+******************************************************************************/\r
+extern TRACE_STOP_HOOK vTraceStopHookPtr;\r
+\r
+/*******************************************************************************\r
+* vTraceSetStopHook\r
+*\r
+* Sets a function to be called when the recorder is stopped.\r
+*\r
+* Snapshot mode only!\r
+******************************************************************************/\r
+void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);\r
+\r
+/*******************************************************************************\r
+* uiTraceStart\r
+*\r
+* [DEPRECATED] Use vTraceEnable instead.\r
+*\r
+* Starts the recorder. The recorder will not be started if an error has been\r
+* indicated using prvTraceError, e.g. if any of the Nx constants in\r
+* trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
+*\r
+* Returns 1 if the recorder was started successfully.\r
+* Returns 0 if the recorder start was prevented due to a previous internal\r
+* error. In that case, check xTraceGetLastError to get the error message.\r
+* Any error message is also presented when opening a trace file.\r
+*\r
+*\r
+* Snapshot mode only!\r
+******************************************************************************/\r
+uint32_t uiTraceStart(void);\r
+\r
+/*******************************************************************************\r
+* vTraceStart\r
+*\r
+* [DEPRECATED] Use vTraceEnable instead.\r
+*\r
+* Starts the recorder. The recorder will not be started if an error has been\r
+* indicated using prvTraceError, e.g. if any of the Nx constants in\r
+* trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
+*\r
+* Snapshot mode only!\r
+******************************************************************************/\r
+void vTraceStart(void);\r
+\r
+/*******************************************************************************\r
+* vTraceClear\r
+*\r
+* Resets the recorder. Only necessary if a restart is desired - this is not\r
+* needed in the startup initialization.\r
+*\r
+* Snapshot mode only!\r
+******************************************************************************/\r
+void vTraceClear(void);\r
+\r
+\r
+/*****************************************************************************/\r
+/*** INTERNAL SNAPSHOT FUNCTIONS *********************************************/\r
+/*****************************************************************************/\r
+\r
+#undef INCLUDE_xTaskGetSchedulerState\r
+#define INCLUDE_xTaskGetSchedulerState 1\r
+\r
+#undef INCLUDE_xTaskGetCurrentTaskHandle\r
+#define INCLUDE_xTaskGetCurrentTaskHandle 1\r
+\r
+#ifndef TRC_CFG_INCLUDE_OBJECT_DELETE\r
+#define TRC_CFG_INCLUDE_OBJECT_DELETE 0\r
+#endif\r
+\r
+#ifndef TRC_CFG_INCLUDE_READY_EVENTS\r
+#define TRC_CFG_INCLUDE_READY_EVENTS 1\r
+#endif\r
+\r
+#ifndef TRC_CFG_INCLUDE_OSTICK_EVENTS\r
+#define TRC_CFG_INCLUDE_OSTICK_EVENTS 0\r
+#endif\r
+\r
+#define TRC_UNUSED\r
+\r
+#if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
+/* This macro will remove the task and store it in the event buffer */\r
+#undef trcKERNEL_HOOKS_TASK_DELETE\r
+#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB) \\r
+ prvTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
+ prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
+ prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
+ prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
+ prvTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \\r
+ prvTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
+#else /*(TRC_CFG_INCLUDE_OBJECT_DELETE == 1)*/\r
+#undef trcKERNEL_HOOKS_TASK_DELETE\r
+#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB)\r
+#endif /*(TRC_CFG_INCLUDE_OBJECT_DELETE == 1)*/\r
+\r
+#if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
+/* This macro will remove the object and store it in the event buffer */\r
+#undef trcKERNEL_HOOKS_OBJECT_DELETE\r
+#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject) \\r
+ prvTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
+ prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
+ prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
+ prvTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
+#else /*TRC_CFG_INCLUDE_OBJECT_DELETE*/\r
+#undef trcKERNEL_HOOKS_OBJECT_DELETE\r
+#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject)\r
+#endif /*TRC_CFG_INCLUDE_OBJECT_DELETE*/\r
+\r
+/* This macro will create a task in the object table */\r
+#undef trcKERNEL_HOOKS_TASK_CREATE\r
+#define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \\r
+ TRACE_SET_TASK_NUMBER(pxTCB) \\r
+ prvTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \\r
+ prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
+ prvTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
+\r
+/* This macro will create a failed create call to create a task */\r
+#undef trcKERNEL_HOOKS_TASK_CREATE_FAILED\r
+#define trcKERNEL_HOOKS_TASK_CREATE_FAILED(SERVICE, CLASS) \\r
+ prvTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, FAILED, CLASS, 0), TRACE_CLASS_TASK, 0);\r
+\r
+/* This macro will setup a task in the object table */\r
+#undef trcKERNEL_HOOKS_OBJECT_CREATE\r
+#define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\\r
+ TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\\r
+ prvMarkObjectAsUsed(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\\r
+ prvTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
+ prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);\r
+\r
+/* This macro will create a failed create call to create an object */\r
+#undef trcKERNEL_HOOKS_OBJECT_CREATE_FAILED\r
+#define trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(SERVICE, CLASS, kernelClass) \\r
+ prvTraceStoreKernelCall(TRACE_GET_CLASS_EVENT_CODE(SERVICE, FAILED, CLASS, kernelClass), TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass), 0);\r
+\r
+/* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
+#undef trcKERNEL_HOOKS_KERNEL_SERVICE\r
+#define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, RESULT, CLASS, pxObject) \\r
+ prvTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
+\r
+/* This macro will set the state for an object */\r
+#undef trcKERNEL_HOOKS_SET_OBJECT_STATE\r
+#define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \\r
+ prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), STATE);\r
+\r
+/* This macro will flag a certain task as a finished instance */\r
+#undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED\r
+#define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \\r
+ prvTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));\r
+\r
+#if (TRC_CFG_INCLUDE_READY_EVENTS == 1)\r
+/* This macro will create an event to indicate that a task became Ready */\r
+#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
+#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \\r
+ prvTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));\r
+#else /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/\r
+#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
+#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)\r
+#endif /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/\r
+\r
+/* This macro will update the internal tick counter and call prvTracePortGetTimeStamp(0) to update the internal counters */\r
+#undef trcKERNEL_HOOKS_INCREMENT_TICK\r
+#define trcKERNEL_HOOKS_INCREMENT_TICK() \\r
+ { extern uint32_t uiTraceTickCount; uiTraceTickCount++; prvTracePortGetTimeStamp(0); }\r
+\r
+#if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)\r
+/* This macro will create an event indicating that the OS tick count has increased */\r
+#undef trcKERNEL_HOOKS_NEW_TIME\r
+#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \\r
+ prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);\r
+#else /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/\r
+#undef trcKERNEL_HOOKS_NEW_TIME\r
+#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)\r
+#endif /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/\r
+\r
+/* This macro will create a task switch event to the currently executing task */\r
+#undef trcKERNEL_HOOKS_TASK_SWITCH\r
+#define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \\r
+ prvTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));\r
+\r
+/* This macro will create an event to indicate that the task has been suspended */\r
+#undef trcKERNEL_HOOKS_TASK_SUSPEND\r
+#define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \\r
+ prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
+ prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
+\r
+/* This macro will create an event to indicate that a task has called a wait/delay function */\r
+#undef trcKERNEL_HOOKS_TASK_DELAY\r
+#define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \\r
+ prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \\r
+ prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
+\r
+/* This macro will create an event to indicate that a task has gotten its priority changed */\r
+#undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE\r
+#define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \\r
+ prvTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), prvTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\\r
+ prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority);\r
+\r
+/* This macro will create an event to indicate that the task has been resumed */\r
+#undef trcKERNEL_HOOKS_TASK_RESUME\r
+#define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \\r
+ prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
+ \r
+#undef trcKERNEL_HOOKS_TIMER_EVENT\r
+#define trcKERNEL_HOOKS_TIMER_EVENT(SERVICE, pxTimer) \\r
+ prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
+\r
+/* This macro will create a timer in the object table and assign the timer a trace handle (timer number).*/\r
+#undef trcKERNEL_HOOKS_TIMER_CREATE\r
+#define trcKERNEL_HOOKS_TIMER_CREATE(SERVICE, pxTimer) \\r
+TRACE_SET_TIMER_NUMBER(pxTimer); \\r
+prvTraceSetObjectName(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_GET_TIMER_NAME(pxTimer)); \\r
+prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
+\r
+#undef trcKERNEL_HOOKS_TIMER_DELETE\r
+#define trcKERNEL_HOOKS_TIMER_DELETE(SERVICE, pxTimer) \\r
+prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer)); \\r
+prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
+prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
+prvTraceFreeObjectHandle(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
+\r
+#if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1\r
+ void prvTraceSetReadyEventsEnabled(int status);\r
+ void prvTraceStoreTaskReady(traceHandle handle);\r
+#else\r
+ #define prvTraceSetReadyEventsEnabled(status)\r
+#endif\r
+\r
+void prvTraceStoreLowPower(uint32_t flag);\r
+\r
+void prvTraceStoreTaskswitch(traceHandle task_handle);\r
+\r
+\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+\r
+void prvTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t byteParam);\r
+\r
+void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param);\r
+\r
+void prvTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,\r
+ uint32_t objectNumber, uint32_t param);\r
+#else\r
+\r
+#define prvTraceStoreKernelCall(eventcode, objectClass, byteParam) {}\r
+#define prvTraceStoreKernelCallWithNumericParamOnly(evtcode, param) {}\r
+#define prvTraceStoreKernelCallWithParam(evtcode, objectClass, objectNumber, param) {}\r
+\r
+#endif\r
+\r
+void prvTraceSetTaskInstanceFinished(traceHandle handle);\r
+\r
+void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value);\r
+\r
+uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id);\r
+\r
+void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value);\r
+\r
+void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle);\r
+\r
+\r
+#if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
+\r
+void prvTraceStoreObjectNameOnCloseEvent(traceHandle handle,\r
+ traceObjectClass objectclass);\r
+\r
+void prvTraceStoreObjectPropertiesOnCloseEvent(traceHandle handle,\r
+ traceObjectClass objectclass);\r
+#endif\r
+\r
+/* Internal constants for task state */\r
+#define TASK_STATE_INSTANCE_NOT_ACTIVE 0\r
+#define TASK_STATE_INSTANCE_ACTIVE 1\r
+\r
+\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 0)\r
+\r
+//void prvTraceIncreaseISRActive(void);\r
+\r
+//void prvTraceDecreaseISRActive(void);\r
+#undef vTraceSetISRProperties\r
+#define vTraceSetISRProperties(handle, name, priority)\r
+\r
+#undef vTraceStoreISRBegin\r
+#define vTraceStoreISRBegin(x) (void)x\r
+\r
+#undef vTraceStoreISREnd\r
+#define vTraceStoreISREnd(x) (void)x\r
+\r
+#undef xTraceSetISRProperties\r
+#define xTraceSetISRProperties(name, priority) 0\r
+\r
+#endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/\r
+\r
+/*******************************************************************************\r
+ * xTraceGetTraceBuffer\r
+ *\r
+ * Returns a pointer to the recorder data structure. Use this together with\r
+ * uiTraceGetTraceBufferSize if you wish to implement an own store/upload\r
+ * solution, e.g., in case a debugger connection is not available for uploading\r
+ * the data.\r
+ ******************************************************************************/\r
+void* xTraceGetTraceBuffer(void);\r
+\r
+/*******************************************************************************\r
+ * uiTraceGetTraceBufferSize\r
+ *\r
+ * Gets the size of the recorder data structure. For use together with\r
+ * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,\r
+ * e.g., in case a debugger connection is not available for uploading the data.\r
+ ******************************************************************************/\r
+uint32_t uiTraceGetTraceBufferSize(void);\r
+\r
+#if (TRC_CFG_SCHEDULING_ONLY == 1)\r
+#undef TRC_CFG_INCLUDE_USER_EVENTS\r
+#define TRC_CFG_INCLUDE_USER_EVENTS 0\r
+#endif /*(TRC_CFG_SCHEDULING_ONLY == 1)*/\r
+\r
+#if ((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))\r
+\r
+#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
+traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatStr);\r
+void vTraceUBData(traceUBChannel channel, ...);\r
+void vTraceUBEvent(traceUBChannel channel);\r
+#endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/\r
+\r
+#else /*((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))*/\r
+\r
+#undef vTracePrint\r
+#define vTracePrint(chn, ...) (void)chn\r
+#undef vTracePrintF\r
+#define vTracePrintF(chn, ...) (void)chn\r
+#undef xTraceRegisterString\r
+#define xTraceRegisterString(x) 0; (void)x;\r
+#undef xTraceRegisterChannelFormat\r
+#define xTraceRegisterChannelFormat(eventLabel, formatStr) 0\r
+#undef vTraceUBData\r
+#define vTraceUBData(label, ...) {}\r
+#undef vTraceChannelPrint\r
+#define vTraceChannelPrint(label) {}\r
+\r
+#endif /*(TRC_CFG_INCLUDE_USER_EVENTS == 1)*/\r
+\r
+#define NEventCodes 0x100\r
+\r
+/* Our local critical sections for the recorder */\r
+#define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}\r
+#define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}\r
+\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)\r
+ #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY TRACE_ALLOC_CRITICAL_SECTION\r
+ #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_BEGIN\r
+ #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_END\r
+#else\r
+ #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY() {}\r
+ #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY() recorder_busy++;\r
+ #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY() recorder_busy--;\r
+#endif\r
+\r
+/* Structure to handle the exclude flags for all objects and tasks. We add some extra objects since index 0 is not used for each object class. */\r
+extern uint8_t trcExcludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1];\r
+\r
+/* Structure to handle the exclude flags for all event codes */\r
+extern uint8_t trcExcludedEventCodes[NEventCodes / 8 + 1];\r
+\r
+/******************************************************************************\r
+ * ObjectHandleStack\r
+ * This data-structure is used to provide a mechanism for 1-byte trace object\r
+ * handles. This way, only 1 byte is necessary instead of 4 bytes (a pointer)\r
+ * when storing a reference to an object. This allows for up to 255 objects of\r
+ * each object class active at any given moment. There can be more "historic"\r
+ * objects, that have been deleted - that number is only limited by the size of\r
+ * the symbol table.\r
+ * Note that handle zero (0) is not used, it is a code for an invalid handle.\r
+ *\r
+ * This data structure keeps track of the FREE handles, not the handles in use.\r
+ * This data structure contains one stack per object class. When a handle is\r
+ * allocated to an object, the next free handle is popped from the stack. When\r
+ * a handle is released (on object delete), it is pushed back on the stack.\r
+ * Note that there is no initialization code that pushed the free handles\r
+ * initially, that is not necessary due to the following optimization:\r
+ *\r
+ * The stack of handles (objectHandles) is initially all zeros. Since zero\r
+ * is not a valid handle, that is a signal of additional handles needed.\r
+ * If a zero is received when popping a new handle, it is replaced by the\r
+ * index of the popped handle instead.\r
+ *\r
+ *****************************************************************************/\r
+typedef struct\r
+{\r
+ /* For each object class, the index of the next handle to allocate */\r
+ uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];\r
+\r
+ /* The lowest index of this class (constant) */\r
+ uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];\r
+\r
+ /* The highest index of this class (constant) */\r
+ uint16_t highestIndexOfClass[ TRACE_NCLASSES ];\r
+\r
+ /* The highest use count for this class (for statistics) */\r
+ uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];\r
+\r
+ /* The free object handles - a set of stacks within this array */\r
+ traceHandle objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];\r
+\r
+} objectHandleStackType;\r
+\r
+extern objectHandleStackType objectHandleStacks;\r
+\r
+/******************************************************************************\r
+ * Object Property Table\r
+ * The Object Table contains name and other properties of the objects (tasks,\r
+ * queues, mutexes, etc). The below data structures defines the properties of\r
+ * each object class and are used to cast the byte buffer into a cleaner format.\r
+ *\r
+ * The values in the object table are continuously overwritten and always\r
+ * represent the current state. If a property is changed during runtime, the OLD\r
+ * value should be stored in the trace buffer, not the new value (since the new\r
+ * value is found in the Object Property Table).\r
+ * For close events this mechanism is the old names are stored in the symbol\r
+ * table), for "priority set" (the old priority is stored in the event data)\r
+ * and for "isActive", where the value decides if the task switch event type\r
+ * should be "new" or "resume".\r
+ ******************************************************************************/\r
+\r
+typedef struct\r
+{\r
+ /* = NCLASSES */\r
+ uint32_t NumberOfObjectClasses;\r
+\r
+ uint32_t ObjectPropertyTableSizeInBytes;\r
+\r
+ /* This is used to calculate the index in the dynamic object table\r
+ (handle - 1 - nofStaticObjects = index)*/\r
+#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
+ traceHandle NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];\r
+#else\r
+ traceHandle NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];\r
+#endif\r
+\r
+ /* Allocation size rounded up to the closest multiple of 4 */\r
+ uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
+\r
+ uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
+\r
+ /* Allocation size rounded up to the closest multiple of 2 */\r
+ uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];\r
+\r
+ /* The actual handles issued, should be Initiated to all zeros */\r
+ uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];\r
+} ObjectPropertyTableType;\r
+\r
+/* Symbol table data structure */\r
+typedef struct\r
+{\r
+ /* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */\r
+ uint32_t symTableSize;\r
+\r
+ /* Entry 0 is reserved. Any reference to entry 0 implies NULL*/\r
+ uint32_t nextFreeSymbolIndex;\r
+\r
+ /* Size rounded up to closest multiple of 4, to avoid alignment issues*/\r
+ uint8_t symbytes[4*((TRC_CFG_SYMBOL_TABLE_SIZE+3)/4)];\r
+\r
+ /* Used for lookups - Up to 64 linked lists within the symbol table\r
+ connecting all entries with the same 6 bit checksum.\r
+ This field holds the current list heads. Should be initiated to zeros */\r
+ uint16_t latestEntryOfChecksum[64];\r
+} symbolTableType;\r
+\r
+\r
+/*******************************************************************************\r
+ * The data structures of the different events, all 4 bytes long\r
+ ******************************************************************************/\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t objHandle;\r
+ uint16_t dts; /* differential timestamp - time since last event */\r
+} TSEvent, TREvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t dummy;\r
+ uint16_t dts; /* differential timestamp - time since last event */\r
+} LPEvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t objHandle;\r
+ uint16_t dts; /* differential timestamp - time since last event */\r
+} KernelCall;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t objHandle;\r
+ uint8_t param;\r
+ uint8_t dts; /* differential timestamp - time since last event */\r
+} KernelCallWithParamAndHandle;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t dts; /* differential timestamp - time since last event */\r
+ uint16_t param;\r
+} KernelCallWithParam16;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t objHandle; /* the handle of the closed object */\r
+ uint16_t symbolIndex; /* the name of the closed object */\r
+} ObjCloseNameEvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t arg1;\r
+ uint8_t arg2;\r
+ uint8_t arg3;\r
+} ObjClosePropEvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t unused1;\r
+ uint8_t unused2;\r
+ uint8_t dts;\r
+} TaskInstanceStatusEvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+ uint8_t dts;\r
+ uint16_t payload; /* the name of the user event */\r
+} UserEvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+\r
+ /* 8 bits extra for storing DTS, if it does not fit in ordinary event\r
+ (this one is always MSB if used) */\r
+ uint8_t xts_8;\r
+\r
+ /* 16 bits extra for storing DTS, if it does not fit in ordinary event. */\r
+ uint16_t xts_16;\r
+} XTSEvent;\r
+\r
+typedef struct\r
+{\r
+ uint8_t type;\r
+\r
+ uint8_t xps_8;\r
+ uint16_t xps_16;\r
+} XPSEvent;\r
+\r
+typedef struct{\r
+ uint8_t type;\r
+ uint8_t dts;\r
+ uint16_t size;\r
+} MemEventSize;\r
+\r
+typedef struct{\r
+ uint8_t type;\r
+ uint8_t addr_high;\r
+ uint16_t addr_low;\r
+} MemEventAddr;\r
+\r
+/*******************************************************************************\r
+ * The separate user event buffer structure. Can be enabled in trcConfig.h.\r
+ ******************************************************************************/\r
+\r
+#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
+typedef struct\r
+{\r
+ traceString name;\r
+ traceString defaultFormat;\r
+} ChannelFormatPair;\r
+\r
+typedef struct\r
+{\r
+ uint16_t bufferID;\r
+ uint16_t version;\r
+ uint32_t wraparoundCounter;\r
+ uint32_t numberOfSlots;\r
+ uint32_t nextSlotToWrite;\r
+ uint8_t numberOfChannels;\r
+ uint8_t padding1;\r
+ uint8_t padding2;\r
+ uint8_t padding3;\r
+ ChannelFormatPair channels[TRC_CFG_UB_CHANNELS+1];\r
+ uint8_t channelBuffer[(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */\r
+ uint8_t dataBuffer[TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE * 4]; /* 4 bytes per slot */\r
+\r
+} UserEventBuffer;\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * The main data structure, read by Tracealyzer from the RAM dump\r
+ ******************************************************************************/\r
+\r
+typedef struct\r
+{\r
+ volatile uint8_t startmarker0; /* Volatile is important, see init code. */\r
+ volatile uint8_t startmarker1;\r
+ volatile uint8_t startmarker2;\r
+ volatile uint8_t startmarker3;\r
+ volatile uint8_t startmarker4;\r
+ volatile uint8_t startmarker5;\r
+ volatile uint8_t startmarker6;\r
+ volatile uint8_t startmarker7;\r
+ volatile uint8_t startmarker8;\r
+ volatile uint8_t startmarker9;\r
+ volatile uint8_t startmarker10;\r
+ volatile uint8_t startmarker11;\r
+\r
+ /* Used to determine Kernel and Endianess */\r
+ uint16_t version;\r
+\r
+ /* Currently 5 */\r
+ uint8_t minor_version;\r
+\r
+ /* This should be 0 if lower IRQ priority values implies higher priority\r
+ levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,\r
+ if higher IRQ priority values means higher priority, this should be 1. */\r
+ uint8_t irq_priority_order;\r
+\r
+ /* sizeof(RecorderDataType) - just for control */\r
+ uint32_t filesize;\r
+\r
+ /* Current number of events recorded */\r
+ uint32_t numEvents;\r
+\r
+ /* The buffer size, in number of event records */\r
+ uint32_t maxEvents;\r
+\r
+ /* The event buffer index, where to write the next event */\r
+ uint32_t nextFreeIndex;\r
+\r
+ /* 1 if the buffer is full, 0 otherwise */\r
+ uint32_t bufferIsFull;\r
+\r
+ /* The frequency of the clock/timer/counter used as time base */\r
+ uint32_t frequency;\r
+\r
+ /* The absolute timestamp of the last stored event, in the native\r
+ timebase, modulo frequency! */\r
+ uint32_t absTimeLastEvent;\r
+\r
+ /* The number of seconds in total - lasts for 136 years */\r
+ uint32_t absTimeLastEventSecond;\r
+\r
+ /* 1 if the recorder has been started, 0 if not yet started or stopped.\r
+ This is a 32 bit variable due to alignment issues. */\r
+ uint32_t recorderActive;\r
+\r
+ /* If > 0, tells the maximum time between two traced ISRs that execute\r
+ back-to-back. If the time between vTraceStoreISREnd and a directly\r
+ following vTraceISRBegin is above isrTailchainingThreshold, we assume a\r
+ return to the previous context in between the ISRs, otherwise we assume\r
+ the have executed back-to-back and don't show any fragment of the previous\r
+ context in between. */ \r
+ uint32_t isrTailchainingThreshold;\r
+\r
+ /* Not used, remains for compatibility and future use */\r
+ uint8_t notused[24];\r
+\r
+ /* The amount of heap memory remaining at the last malloc or free event */\r
+ uint32_t heapMemUsage;\r
+\r
+ /* 0xF0F0F0F0 - for control only */\r
+ int32_t debugMarker0;\r
+\r
+ /* Set to value of TRC_CFG_USE_16BIT_OBJECT_HANDLES */\r
+ uint32_t isUsing16bitHandles;\r
+\r
+ /* The Object Property Table holds information about currently active\r
+ tasks, queues, and other recorded objects. This is updated on each\r
+ create call and includes object name and other properties. */\r
+ ObjectPropertyTableType ObjectPropertyTable;\r
+\r
+ /* 0xF1F1F1F1 - for control only */\r
+ int32_t debugMarker1;\r
+\r
+ /* The Symbol Table stores strings for User Events and is also used to\r
+ store names of deleted objects, which still may be in the trace but no\r
+ longer are available. */\r
+ symbolTableType SymbolTable;\r
+\r
+ /* For inclusion of float support, and for endian detection of floats.\r
+ The value should be (float)1 or (uint32_t)0 */\r
+#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)\r
+ float exampleFloatEncoding;\r
+#else\r
+ uint32_t exampleFloatEncoding;\r
+#endif\r
+ /* This is non-zero if an internal error occurred in the recorder, e.g., if\r
+ one of the Nxxx constants was too small. The systemInfo string will then\r
+ contain an error message that is displayed when attempting to view the\r
+ trace file. */\r
+ uint32_t internalErrorOccured;\r
+\r
+ /* 0xF2F2F2F2 - for control only */\r
+ int32_t debugMarker2;\r
+\r
+ /* Error messages from the recorder. */\r
+ char systemInfo[80];\r
+\r
+ /* 0xF3F3F3F3 - for control only */\r
+ int32_t debugMarker3;\r
+\r
+ /* The event data, in 4-byte records */\r
+ uint8_t eventData[ TRC_CFG_EVENT_BUFFER_SIZE * 4 ];\r
+\r
+#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
+ UserEventBuffer userEventBuffer;\r
+#endif\r
+\r
+ /* This should always be 0 */\r
+ uint32_t endOfSecondaryBlocks;\r
+\r
+ uint8_t endmarker0;\r
+ uint8_t endmarker1;\r
+ uint8_t endmarker2;\r
+ uint8_t endmarker3;\r
+ uint8_t endmarker4;\r
+ uint8_t endmarker5;\r
+ uint8_t endmarker6;\r
+ uint8_t endmarker7;\r
+ uint8_t endmarker8;\r
+ uint8_t endmarker9;\r
+ uint8_t endmarker10;\r
+ uint8_t endmarker11;\r
+} RecorderDataType;\r
+\r
+extern RecorderDataType* RecorderDataPtr;\r
+\r
+/* Internal functions */\r
+\r
+/* Signal an error. */\r
+void prvTraceError(const char* msg);\r
+\r
+/*******************************************************************************\r
+ * prvTracePortGetTimeStamp\r
+ *\r
+ * Returns the current time based on the HWTC macros which provide a hardware\r
+ * isolation layer towards the hardware timer/counter.\r
+ *\r
+ * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue\r
+ * or the trace recorder library. Typically you should not need to change\r
+ * the code of prvTracePortGetTimeStamp if using the HWTC macros.\r
+ *\r
+ ******************************************************************************/\r
+void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);\r
+\r
+traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass);\r
+\r
+void prvTraceFreeObjectHandle(traceObjectClass objectclass,\r
+ traceHandle handle);\r
+\r
+/* Private function. Use the public functions in trcKernelPort.h */\r
+void prvTraceSetObjectName(traceObjectClass objectclass,\r
+ traceHandle handle,\r
+ const char* name);\r
+\r
+/* Internal macros */\r
+\r
+#define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \\r
+(const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \\r
+[uiIndexOfObject(objecthandle, objectclass)])\r
+\r
+#define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \\r
+RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
++ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]\r
+\r
+#define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \\r
+RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
++ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]\r
+\r
+#define TRACE_SET_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] |= (1 << ((bitIndex) & 7))\r
+#define TRACE_CLEAR_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] &= (uint8_t)(~(1 << ((bitIndex) & 7)))\r
+#define TRACE_GET_FLAG_ISEXCLUDED(flags, bitIndex) (flags[(bitIndex) >> 3] & (1 << ((bitIndex) & 7)))\r
+\r
+#define TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedEventCodes, eventCode)\r
+#define TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedEventCodes, eventCode)\r
+#define TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedEventCodes, eventCode)\r
+\r
+/* DEBUG ASSERTS */\r
+#if defined TRC_CFG_USE_TRACE_ASSERT && TRC_CFG_USE_TRACE_ASSERT != 0\r
+#define TRACE_ASSERT(eval, msg, defRetVal) \\r
+if (!(eval)) \\r
+{ \\r
+ prvTraceError("TRACE_ASSERT: " msg); \\r
+ return defRetVal; \\r
+}\r
+#else\r
+#define TRACE_ASSERT(eval, msg, defRetVal)\r
+#endif\r
+\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/\r
+\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
+\r
+/******************************************************************************/\r
+/*** INTERNAL STREAMING FUNCTIONS *********************************************/\r
+/******************************************************************************/\r
+\r
+/* Saves a symbol name (task name etc.) in symbol table */\r
+void prvTraceSaveSymbol(const void *address, const char *name);\r
+\r
+/* Deletes a symbol name (task name etc.) from symbol table */\r
+void prvTraceDeleteSymbol(void *address);\r
+\r
+/* Saves an object data entry (task base priority) in object data table */\r
+void prvTraceSaveObjectData(const void *address, uint32_t data);\r
+\r
+/* Removes an object data entry (task base priority) from object data table */\r
+void prvTraceDeleteObjectData(void *address);\r
+\r
+/* Store an event with zero parameters (event ID only) */\r
+void prvTraceStoreEvent0(uint16_t eventID);\r
+\r
+/* Store an event with one 32-bit parameter (pointer address or an int) */\r
+void prvTraceStoreEvent1(uint16_t eventID,\r
+ uint32_t param1);\r
+\r
+/* Store an event with two 32-bit parameters */\r
+void prvTraceStoreEvent2(uint16_t eventID,\r
+ uint32_t param1,\r
+ uint32_t param2);\r
+\r
+/* Store an event with three 32-bit parameters */\r
+void prvTraceStoreEvent3(uint16_t eventID,\r
+ uint32_t param1,\r
+ uint32_t param2,\r
+ uint32_t param3);\r
+\r
+/* Stores an event with <nParam> 32-bit integer parameters */\r
+void prvTraceStoreEvent(int nParam, uint16_t EventID, ...);\r
+\r
+/* Stories an event with a string and <nParam> 32-bit integer parameters */\r
+void prvTraceStoreStringEvent(int nArgs, uint16_t eventID, const char* str, ...);\r
+\r
+/* Initializes the paged event buffer used by certain stream ports */\r
+void prvPagedEventBufferInit(char* buffer);\r
+\r
+/* Retrieve a pointer to the paged event buffer */\r
+void* prvPagedEventBufferGetWritePointer(int sizeOfEvent);\r
+\r
+/* Transfer a full buffer page */\r
+int32_t prvPagedEventBufferTransfer(int32_t(*writeFunc)(void* data, uint32_t size, int32_t* ptrBytesWritten), int32_t* nofBytes);\r
+\r
+/* Resets the paged event buffer */\r
+void prvPagedEventBufferReset(void);\r
+\r
+/* The data structure for commands (a bit overkill) */\r
+typedef struct\r
+{\r
+ unsigned char cmdCode;\r
+ unsigned char param1;\r
+ unsigned char param2;\r
+ unsigned char param3;\r
+ unsigned char param4;\r
+ unsigned char param5;\r
+ unsigned char checksumLSB;\r
+ unsigned char checksumMSB;\r
+} TracealyzerCommandType;\r
+\r
+/* Checks if the provided command is a valid command */\r
+int prvIsValidCommand(TracealyzerCommandType* cmd);\r
+\r
+/* Executed the received command (Start or Stop) */\r
+void prvProcessCommand(TracealyzerCommandType* cmd);\r
+\r
+\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
+\r
+#else /* when TRC_USE_TRACEALYZER_RECORDER == 0 */\r
+\r
+#define vTraceEnable(x)\r
+#define xTraceRegisterString(x) 0; (void)x;\r
+#define vTracePrint(chn, ...) (void)chn\r
+#define vTracePrintF(chn, ...) (void)chn\r
+#define vTraceInstanceFinishedNow()\r
+#define vTraceInstanceFinishedNext()\r
+#define vTraceStoreISRBegin(x) (void)x\r
+#define vTraceStoreISREnd(x) (void)x\r
+#define xTraceSetISRProperties(a, b) 0\r
+#define vTraceStoreKernelObjectName(a, b)\r
+#define xTraceRegisterChannelFormat(eventLabel, formatStr) 0\r
+#define vTraceChannelPrint(label)\r
+#define vTraceUBData(label, ...)\r
+\r
+#define prvTraceSetReadyEventsEnabled(status)\r
+\r
+#define vTraceExcludeTask(handle)\r
+\r
+#define uiTraceStart() (1)\r
+#define vTraceStart()\r
+#define vTraceStop()\r
+\r
+#ifndef vTraceSetRecorderDataBuffer\r
+#define vTraceSetRecorderDataBuffer(pRecorderData)\r
+#endif\r
+\r
+#ifndef TRC_ALLOC_CUSTOM_BUFFER\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname)\r
+#endif\r
+\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* TRC_RECORDER_H */\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcTypes.h\r
- *\r
- * Data types used by the trace recorder library.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files. \r
- * This software is the intellectual property of Percepio AB and may not be \r
- * sold or in other ways commercially redistributed without explicit written \r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer \r
- * The trace tool and recorder library is being delivered to you AS IS and \r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does \r
- * not and cannot warrant the performance or results you may obtain by using the \r
- * software or documentation. Percepio AB make no warranties, express or \r
- * implied, as to noninfringement of third party rights, merchantability, or \r
- * fitness for any particular purpose. In no event will Percepio AB, its \r
- * technology partners, or distributors be liable to you for any consequential, \r
- * incidental or special damages, including any lost profits or lost savings, \r
- * even if a representative of Percepio AB has been advised of the possibility \r
- * of such damages, or for any claim by any third party. Some jurisdictions do \r
- * not allow the exclusion or limitation of incidental, consequential or special \r
- * damages, or the exclusion of implied warranties or limitations on how long an \r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#ifndef TRCTYPES_H\r
-#define TRCTYPES_H\r
-\r
-#include <stdint.h>\r
-#include <trcConfig.h>\r
-\r
-typedef uint16_t traceLabel;\r
-\r
-typedef uint8_t UserEventChannel;\r
-\r
-#if (USE_16BIT_OBJECT_HANDLES == 1)\r
-typedef uint16_t objectHandleType;\r
-#else\r
-typedef uint8_t objectHandleType;\r
-#endif\r
-\r
-typedef uint8_t traceObjectClass;\r
-\r
-#endif\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcUser.h\r
- * The public API of the trace recorder library.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#ifndef TRCUSER_H\r
-#define TRCUSER_H\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-#include "trcKernelPort.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#ifndef USE_SEPARATE_USER_EVENT_BUFFER\r
-#define USE_SEPARATE_USER_EVENT_BUFFER 0\r
-#endif\r
-\r
-/*******************************************************************************\r
- * TRACE_STOP_HOOK - Hook Pointer Data Type\r
- *\r
- * Declares a data type for a call back function that will be invoked whenever\r
- * the recorder is stopped.\r
- ******************************************************************************/\r
-typedef void (*TRACE_STOP_HOOK)(void);\r
-\r
-/*******************************************************************************\r
- * vTraceStopHookPtr\r
- *\r
- * Points to a call back function that is called from vTraceStop().\r
- ******************************************************************************/\r
-extern TRACE_STOP_HOOK vTraceStopHookPtr;\r
-\r
-/*******************************************************************************\r
- * vTraceInitTraceData\r
- *\r
- * Allocates, if necessary, and initializes the recorder data structure, based\r
- * on the constants in trcConfig.h.\r
- ******************************************************************************/\r
-void vTraceInitTraceData(void);\r
-\r
-/*******************************************************************************\r
- * vTraceSetRecorderData\r
- *\r
- * If custom allocation is used, this function must be called so the recorder\r
- * library knows where to save the trace data.\r
- ******************************************************************************/\r
-#if (TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_CUSTOM)\r
-void vTraceSetRecorderData(void* pRecorderData);\r
-#endif\r
-\r
-/*******************************************************************************\r
- * vTraceSetStopHook\r
- *\r
- * Sets a function to be called when the recorder is stopped.\r
- ******************************************************************************/\r
-void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);\r
-\r
-/*******************************************************************************\r
- * uiTraceStart\r
- *\r
- * Starts the recorder. The recorder will not be started if an error has been\r
- * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h\r
- * has a too small value (NTASK, NQUEUE, etc).\r
- *\r
- * Returns 1 if the recorder was started successfully.\r
- * Returns 0 if the recorder start was prevented due to a previous internal\r
- * error. In that case, check vTraceGetLastError to get the error message.\r
- * Any error message is also presented when opening a trace file.\r
- *\r
- ******************************************************************************/\r
-uint32_t uiTraceStart(void);\r
-\r
-/*******************************************************************************\r
- * vTraceStart\r
- *\r
- * Starts the recorder. The recorder will not be started if an error has been\r
- * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h\r
- * has a too small value (NTASK, NQUEUE, etc).\r
- *\r
- * This function is obsolete, but has been saved for backwards compatibility.\r
- * We recommend using uiTraceStart instead.\r
- ******************************************************************************/\r
-void vTraceStart(void);\r
-\r
-/*******************************************************************************\r
- * vTraceStop\r
- *\r
- * Stops the recorder. The recording can be resumed by calling vTraceStart.\r
- * This does not reset the recorder. Use vTraceClear is that is desired.\r
- ******************************************************************************/\r
-void vTraceStop(void);\r
-\r
-/*******************************************************************************\r
- * xTraceGetLastError\r
- *\r
- * Gives the last error message, if any. NULL if no error message is stored.\r
- * Any error message is also presented when opening a trace file.\r
- ******************************************************************************/\r
-char* xTraceGetLastError(void);\r
-\r
-/*******************************************************************************\r
- * vTraceClear\r
- *\r
- * Resets the recorder. Only necessary if a restart is desired - this is not\r
- * needed in the startup initialization.\r
- ******************************************************************************/\r
-void vTraceClear(void);\r
-\r
-/*******************************************************************************\r
-* vTraceClearError\r
-*\r
-* Removes any previous error message generated by recorder calling vTraceError.\r
-* By calling this function, it may be possible to start/restart the trace\r
-* despite errors in the recorder, but there is no guarantee that the trace\r
-* recorder will work correctly in that case, depending on the type of error.\r
-******************************************************************************/\r
-void vTraceClearError(int resetErrorMessage);\r
-\r
-#if (INCLUDE_ISR_TRACING == 1)\r
-\r
-/*******************************************************************************\r
- * vTraceSetISRProperties\r
- *\r
- * Registers an Interrupt Service Routine in the recorder library, This must be\r
- * called before using vTraceStoreISRBegin to store ISR events. This is\r
- * typically called in the startup of the system, before the scheduler is\r
- * started.\r
- *\r
- * Example:\r
- * #define ID_ISR_TIMER1 1 // lowest valid ID is 1\r
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
- * ...\r
- * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);\r
- * ...\r
- * void ISR_handler()\r
- * {\r
- * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);\r
- * ...\r
- * vTraceStoreISREnd(0);\r
- * }\r
- ******************************************************************************/\r
-void vTraceSetISRProperties(objectHandleType handle, const char* name, char priority);\r
-\r
-/*******************************************************************************\r
- * vTraceStoreISRBegin\r
- *\r
- * Registers the beginning of an Interrupt Service Routine.\r
- * If allowing nested ISRs, this must be called with interrupts disabled.\r
- *\r
- * Example:\r
- * #define ID_ISR_TIMER1 1 // lowest valid ID is 1\r
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
- * ...\r
- * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);\r
- * ...\r
- * void ISR_handler()\r
- * {\r
- * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);\r
- * ...\r
- * vTraceStoreISREnd(0);\r
- * }\r
- *\r
- ******************************************************************************/\r
-void vTraceStoreISRBegin(objectHandleType id);\r
-\r
-/*******************************************************************************\r
- * vTraceStoreISREnd\r
- *\r
- * Registers the end of an Interrupt Service Routine.\r
- *\r
- * The parameter pendingISR indicates if the interrupt has requested a\r
- * task-switch (= 1) or if the interrupt returns to the earlier context (= 0)\r
- *\r
- * Example:\r
- * #define ID_ISR_TIMER1 1 // lowest valid ID is 1\r
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
- * ...\r
- * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);\r
- * ...\r
- * void ISR_handler()\r
- * {\r
- * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);\r
- * ...\r
- * vTraceStoreISREnd(0);\r
- * }\r
- *\r
- ******************************************************************************/\r
-void vTraceStoreISREnd(int pendingISR);\r
-\r
-#else\r
- /* If not including the ISR recording */\r
-\r
-void vTraceIncreaseISRActive(void);\r
-\r
-void vTraceDecreaseISRActive(void);\r
-\r
-#define vTraceSetISRProperties(handle, name, priority)\r
-#define vTraceStoreISRBegin(id) vTraceIncreaseISRActive()\r
-#define vTraceStoreISREnd() vTraceDecreaseISRActive()\r
-\r
-#endif\r
-\r
-\r
-/******************************************************************************\r
- * vTraceTaskInstanceFinish(void)\r
- *\r
- * Marks the current task instance as finished on the next kernel call.\r
- *\r
- * If that kernel call is blocking, the instance ends after the blocking event\r
- * and the corresponding return event is then the start of the next instance.\r
- * If the kernel call is not blocking, the viewer instead splits the current\r
- * fragment right before the kernel call, which makes this call the first event\r
- * of the next instance.\r
- *\r
- * See also USE_IMPLICIT_IFE_RULES in trcConfig.h\r
- *\r
- * Example:\r
- *\r
- * while(1)\r
- * {\r
- * xQueueReceive(CommandQueue, &command, timeoutDuration);\r
- * processCommand(command);\r
- * vTraceInstanceFinish();\r
- * }\r
- *\r
- *****************************************************************************/\r
-void vTraceTaskInstanceFinish(void);\r
-\r
-/******************************************************************************\r
- * vTraceTaskInstanceFinishDirect(void)\r
- *\r
- * Marks the current task instance as finished at this very instant.\r
- * This makes the viewer to splits the current fragment at this point and begin\r
- * a new actor instance.\r
- *\r
- * See also USE_IMPLICIT_IFE_RULES in trcConfig.h\r
- *\r
- * Example:\r
- *\r
- * This example will generate two instances for each loop iteration.\r
- * The first instance ends at vTraceInstanceFinishDirect(), while the second\r
- * instance ends at the next xQueueReceive call.\r
- *\r
- * while (1)\r
- * {\r
- * xQueueReceive(CommandQueue, &command, timeoutDuration);\r
- * ProcessCommand(command);\r
- * vTraceInstanceFinishDirect();\r
- * DoSometingElse();\r
- * vTraceInstanceFinish();\r
- * }\r
- *\r
- *\r
- *****************************************************************************/\r
-void vTraceTaskInstanceFinishDirect(void);\r
-\r
-/*******************************************************************************\r
- * vTraceGetTraceBuffer\r
- *\r
- * Returns a pointer to the recorder data structure. Use this together with\r
- * uiTraceGetTraceBufferSize if you wish to implement an own store/upload\r
- * solution, e.g., in case a debugger connection is not available for uploading\r
- * the data.\r
- ******************************************************************************/\r
-void* vTraceGetTraceBuffer(void);\r
-\r
-/*******************************************************************************\r
- * uiTraceGetTraceBufferSize\r
- *\r
- * Gets the size of the recorder data structure. For use together with\r
- * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,\r
- * e.g., in case a debugger connection is not available for uploading the data.\r
- ******************************************************************************/\r
-uint32_t uiTraceGetTraceBufferSize(void);\r
-\r
-#if (INCLUDE_USER_EVENTS == 1)\r
-\r
-/*******************************************************************************\r
- * xTraceOpenLabel\r
- *\r
- * Creates user event labels for user event channels or for individual events.\r
- * User events can be used to log application events and data for display in\r
- * the visualization tool. A user event is identified by a label, i.e., a string,\r
- * which is stored in the recorder's symbol table.\r
- * When logging a user event, a numeric handle (reference) to this string is\r
- * used to identify the event. This is obtained by calling\r
- *\r
- * xTraceOpenLabel()\r
- *\r
- * whihc adds the string to the symbol table (if not already present)\r
- * and returns the corresponding handle.\r
- *\r
- * This can be used in two ways:\r
- *\r
- * 1. The handle is looked up every time, when storing the user event.\r
- *\r
- * Example:\r
- * vTraceUserEvent(xTraceOpenLabel("MyUserEvent"));\r
- *\r
- * 2. The label is registered just once, with the handle stored in an\r
- * application variable - much like using a file handle.\r
- *\r
- * Example:\r
- * myEventHandle = xTraceOpenLabel("MyUserEvent");\r
- * ...\r
- * vTraceUserEvent(myEventHandle);\r
- *\r
- * The second option is faster since no lookup is required on each event, and\r
- * therefore recommended for user events that are frequently\r
- * executed and/or located in time-critical code. The lookup operation is\r
- * however fairly fast due to the design of the symbol table.\r
- ******************************************************************************/\r
-traceLabel xTraceOpenLabel(const char* label);\r
-\r
- /******************************************************************************\r
- * vTraceUserEvent\r
- *\r
- * Basic user event (Standard and Professional Edition only)\r
- *\r
- * Generates a User Event with a text label. The label is created/looked up\r
- * in the symbol table using xTraceOpenLabel.\r
- ******************************************************************************/\r
-void vTraceUserEvent(traceLabel eventLabel);\r
-\r
- /******************************************************************************\r
- * vTracePrintF\r
- *\r
- * Advanced user events (Professional Edition only)\r
- *\r
- * Generates User Event with formatted text and data, similar to a "printf".\r
- * It is very fast compared to a normal "printf" since this function only\r
- * stores the arguments. The actual formatting is done\r
- * on the host PC when the trace is displayed in the viewer tool.\r
- *\r
- * User Event labels are created using xTraceOpenLabel.\r
- * Example:\r
- *\r
- * traceLabel adc_uechannel = xTraceOpenLabel("ADC User Events");\r
- * ...\r
- * vTracePrint(adc_uechannel,\r
- * "ADC channel %d: %lf volts",\r
- * ch, (double)adc_reading/(double)scale);\r
- *\r
- * This can be combined into one line, if desired, but this is slower:\r
- *\r
- * vTracePrint(xTraceOpenLabel("ADC User Events"),\r
- * "ADC channel %d: %lf volts",\r
- * ch, (double)adc_reading/(double)scale);\r
- *\r
- * Calling xTraceOpenLabel multiple times will not create duplicate entries, but\r
- * it is of course faster to just do it once, and then keep the handle for later\r
- * use. If you don�t have any data arguments, only a text label/string, it is\r
- * better to use vTraceUserEvent - it is faster.\r
- *\r
- * Format specifiers supported:\r
- * %d - 32 bit signed integer\r
- * %u - 32 bit unsigned integer\r
- * %f - 32 bit float\r
- * %s - string (is copied to the recorder symbol table)\r
- * %hd - 16 bit signed integer\r
- * %hu - 16 bit unsigned integer\r
- * %bd - 8 bit signed integer\r
- * %bu - 8 bit unsigned integer\r
- * %lf - double-precision float (Note! See below...)\r
- *\r
- * Up to 15 data arguments are allowed, with a total size of maximum 32 byte.\r
- * In case this is exceeded, the user event is changed into an error message.\r
- *\r
- * The data is stored in trace buffer, and is packed to allow storing multiple\r
- * smaller data entries in the same 4-byte record, e.g., four 8-bit values.\r
- * A string requires two bytes, as the symbol table is limited to 64K. Storing\r
- * a double (%lf) uses two records, so this is quite costly. Use float (%f)\r
- * unless the higher precision is really necessary.\r
- *\r
- * Note that the double-precision float (%lf) assumes a 64 bit double\r
- * representation. This does not seem to be the case on e.g. PIC24 and PIC32.\r
- * Before using a %lf argument on a 16-bit MCU, please verify that\r
- * "sizeof(double)" actually gives 8 as expected. If not, use %f instead.\r
- ******************************************************************************/\r
-void vTracePrintF(traceLabel eventLabel, const char* formatStr, ...);\r
-\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
-UserEventChannel xTraceRegisterChannelFormat(traceLabel channel, traceLabel formatStr);\r
-void vTraceChannelPrintF(UserEventChannel channel, ...);\r
-void vTraceChannelUserEvent(UserEventChannel channel);\r
-#endif\r
-\r
-#else\r
-\r
-#define vTracePrintF(eventLabel, formatStr, ...);\r
-#define xTraceOpenLabel(label) 0\r
-#define vTraceUserEvent(eventLabel)\r
-\r
-#endif\r
-\r
-#else\r
-\r
-/* Empty defines for user functions to avoid compiler errors if trace is not to be used */\r
-\r
-#define vTraceInitTraceData()\r
-#define uiTraceStart() (1) // Fake "success", if used when recorder is excluded from build\r
-#define vTraceStart()\r
-#define vTraceStop()\r
-#define vTraceClear()\r
-#define vTraceStartStatusMonitor()\r
-#define vTraceGetTraceBuffer() ((void*)0)\r
-#define uiTraceGetTraceBufferSize() 0\r
-#define xTraceOpenLabel(label) 0\r
-#define vTraceUserEvent(eventLabel)\r
-#define vTracePrintF(eventLabel,formatStr,...)\r
-#define vTraceExcludeTaskFromSchedulingTrace(name)\r
-\r
-#define vTraceSetISRProperties(handle, name, priority)\r
-#define vTraceStoreISRBegin(id)\r
-#define vTraceStoreISREnd(flag)\r
-#define vTraceExcludeTaskFromTrace(handle)\r
-#define vTraceSetQueueName(a, b)\r
-#define vTraceSetMutexName(a, b)\r
-#define vTraceSetSemaphoreName(a, b)\r
-#define vTraceSetEventGroupName(a, b)\r
-\r
-#define vTraceSetStopHook(a)\r
-#endif\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcConfig.h\r
+ *\r
+ * Main configuration parameters for the trace recorder library.\r
+ * More settings can be found in trcStreamingConfig.h and trcSnapshotConfig.h.\r
+ *\r
+ * Read more at http://percepio.com/2016/10/05/rtos-tracing/\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2016.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+ \r
+#ifndef TRC_CONFIG_H\r
+#define TRC_CONFIG_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "trcPortDefines.h"\r
+\r
+/******************************************************************************\r
+ * Include of processor header file\r
+ * \r
+ * Here you may need to include the header file for your processor. This is \r
+ * required at least for the ARM Cortex-M port, that uses the ARM CMSIS API.\r
+ * Try that in case of build problems. Otherwise, remove the #error line below.\r
+ *****************************************************************************/\r
+#error "Trace Recorder: Please include your processor's header file here and remove this line."\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_HARDWARE_PORT\r
+ *\r
+ * Specify what hardware port to use (i.e., the "timestamping driver").\r
+ *\r
+ * All ARM Cortex-M MCUs are supported by "TRC_HARDWARE_PORT_ARM_Cortex_M".\r
+ * This port uses the DWT cycle counter for Cortex-M3/M4/M7 devices, which is\r
+ * available on most such devices. In case your device don't have DWT support,\r
+ * you will get an error message opening the trace. In that case, you may \r
+ * force the recorder to use SysTick timestamping instead, using this define:\r
+ *\r
+ * #define TRC_CFG_ARM_CM_USE_SYSTICK\r
+ *\r
+ * For ARM Cortex-M0/M0+ devices, SysTick mode is used automatically.\r
+ *\r
+ * See trcHardwarePort.h for available ports and information on how to \r
+ * define your own port, if not already present.\r
+ ******************************************************************************/\r
+#define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_RECORDER_MODE\r
+ *\r
+ * Specify what recording mode to use. Snapshot means that the data is saved in\r
+ * an internal RAM buffer, for later upload. Streaming means that the data is\r
+ * transferred continuously to the host PC. \r
+ *\r
+ * For more information, see http://percepio.com/2016/10/05/rtos-tracing/\r
+ * and the Tracealyzer User Manual.\r
+ *\r
+ * Values:\r
+ * TRC_RECORDER_MODE_SNAPSHOT\r
+ * TRC_RECORDER_MODE_STREAMING\r
+ ******************************************************************************/\r
+#define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_RECORDER_BUFFER_ALLOCATION\r
+ *\r
+ * Specifies how the recorder buffer is allocated (also in case of streaming, in\r
+ * port using the recorder's internal temporary buffer)\r
+ *\r
+ * Values:\r
+ * TRC_RECORDER_BUFFER_ALLOCATION_STATIC - Static allocation (internal)\r
+ * TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC - Malloc in vTraceEnable\r
+ * TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM - Use vTraceSetRecorderDataBuffer\r
+ *\r
+ * Static and dynamic mode does the allocation for you, either in compile time \r
+ * (static) or in runtime (malloc). \r
+ * The custom mode allows you to control how and where the allocation is made, \r
+ * for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer().\r
+ ******************************************************************************/\r
+#define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_FREERTOS_VERSION\r
+ * \r
+ * Specify what version of FreeRTOS that is used (don't change unless using the\r
+ * trace recorder library with an older version of FreeRTOS).\r
+ * \r
+ * TRC_FREERTOS_VERSION_7_3_OR_7_4 If using FreeRTOS v7.3.0 - v7.4.2\r
+ * TRC_FREERTOS_VERSION_7_5_OR_7_6 If using FreeRTOS v7.5.0 - v7.6.0\r
+ * TRC_FREERTOS_VERSION_8_X If using FreeRTOS v8.X.X\r
+ * TRC_FREERTOS_VERSION_9_X If using FreeRTOS v9.X.X\r
+ *****************************************************************************/\r
+#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_9_X\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_MAX_ISR_NESTING\r
+ * \r
+ * Defines how many levels of interrupt nesting the recorder can handle, in\r
+ * case multiple ISRs are traced and ISR nesting is possible. If this\r
+ * is exceeded, the particular ISR will not be traced and the recorder then \r
+ * logs an error message. This setting is used to allocate an internal stack\r
+ * for keeping track of the previous execution context (4 byte per entry). \r
+ *\r
+ * This value must be a non-zero positive constant, at least 1.\r
+ * \r
+ * Default value: 8\r
+ *****************************************************************************/\r
+#define TRC_CFG_MAX_ISR_NESTING 8\r
+\r
+/* Specific configuration, depending on Streaming/Snapshot mode */\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+#include "trcSnapshotConfig.h"\r
+#elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
+#include "trcStreamingConfig.h"\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _TRC_CONFIG_H */\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcSnapshotConfig.h\r
+ *\r
+ * Configuration parameters for trace recorder library in snapshot mode. \r
+ * Read more at http://percepio.com/2016/10/05/rtos-tracing/\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_SNAPSHOT_CONFIG_H\r
+#define TRC_SNAPSHOT_CONFIG_H\r
+\r
+#define TRC_SNAPSHOT_MODE_RING_BUFFER (0x01)\r
+#define TRC_SNAPSHOT_MODE_STOP_WHEN_FULL (0x02)\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_SNAPSHOT_MODE\r
+ *\r
+ * Macro which should be defined as one of:\r
+ * - TRC_SNAPSHOT_MODE_RING_BUFFER\r
+ * - TRC_SNAPSHOT_MODE_STOP_WHEN_FULL\r
+ * Default is TRC_SNAPSHOT_MODE_RING_BUFFER.\r
+ *\r
+ * With TRC_CFG_SNAPSHOT_MODE set to TRC_SNAPSHOT_MODE_RING_BUFFER, the \r
+ * events are stored in a ring buffer, i.e., where the oldest events are \r
+ * overwritten when the buffer becomes full. This allows you to get the last\r
+ * events leading up to an interesting state, e.g., an error, without having \r
+ * to store the whole run since startup.\r
+ *\r
+ * When TRC_CFG_SNAPSHOT_MODE is TRC_SNAPSHOT_MODE_STOP_WHEN_FULL, the \r
+ * recording is stopped when the buffer becomes full. This is useful for\r
+ * recording events following a specific state, e.g., the startup sequence.\r
+ *****************************************************************************/\r
+#define TRC_CFG_SNAPSHOT_MODE TRC_SNAPSHOT_MODE_RING_BUFFER\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_SCHEDULING_ONLY\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * If this setting is enabled (= 1), only scheduling events are recorded.\r
+ * If disabled (= 0), all events are recorded.\r
+ *\r
+ * For users of Tracealyzer Free Edition, that only displays scheduling events, this\r
+ * option can be used to avoid storing other events.\r
+ *\r
+ * Default value is 0 (store all enabled events).\r
+ *\r
+ ******************************************************************************/\r
+#define TRC_CFG_SCHEDULING_ONLY 0\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_EVENT_BUFFER_SIZE\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * This defines the capacity of the event buffer, i.e., the number of records\r
+ * it may store. Most events use one record (4 byte), although some events \r
+ * require multiple 4-byte records. You should adjust this to the amount of RAM\r
+ * available in the target system.\r
+ * \r
+ * Default value is 1000, which means that 4000 bytes is allocated for the\r
+ * event buffer.\r
+ ******************************************************************************/\r
+#define TRC_CFG_EVENT_BUFFER_SIZE 1000\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE...\r
+ *\r
+ * A group of macros which should be defined as integer values, zero or larger.\r
+ *\r
+ * These define the capacity of the Object Property Table, i.e., the maximum\r
+ * number of objects active at any given point, within each object class (e.g., \r
+ * task, queue, semaphore, ...).\r
+ * \r
+ * If tasks or other objects are deleted in your system, this\r
+ * setting does not limit the total amount of objects created, only the number\r
+ * of objects that have been successfully created but not yet deleted.\r
+ *\r
+ * Using too small values will cause vTraceError to be called, which stores an \r
+ * error message in the trace that is shown when opening the trace file. The\r
+ * error message can also be retrieved using xTraceGetLastError.\r
+ *\r
+ * It can be wise to start with large values for these constants, \r
+ * unless you are very confident on these numbers. Then do a recording and\r
+ * check the actual usage by selecting View menu -> Trace Details -> \r
+ * Resource Usage -> Object Table. \r
+ ******************************************************************************/\r
+#define TRC_CFG_NTASK 10\r
+#define TRC_CFG_NISR 5\r
+#define TRC_CFG_NQUEUE 10\r
+#define TRC_CFG_NSEMAPHORE 10\r
+#define TRC_CFG_NMUTEX 10\r
+#define TRC_CFG_NTIMER 5\r
+#define TRC_CFG_NEVENTGROUP 5\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_INCLUDE_MEMMANG_EVENTS\r
+ * \r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * This controls if malloc and free calls should be traced. Set this to zero (0)\r
+ * to exclude malloc/free calls, or one (1) to include such events in the trace.\r
+ *\r
+ * Default value is 1.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_MEMMANG_EVENTS 1\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_INCLUDE_USER_EVENTS\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * If this is zero (0) the code for creating User Events is excluded to\r
+ * reduce code size. User Events are application-generated events, like \r
+ * "printf" but for the trace log and the formatting is done offline, by the\r
+ * Tracealyzer visualization tool. User Events are much faster than a printf\r
+ * and can therefore be used in timing critical code.\r
+ * \r
+ * Default value is 1.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_USER_EVENTS 1\r
+\r
+/*****************************************************************************\r
+ * TRC_CFG_INCLUDE_ISR_TRACING\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * If this is zero (0), the code for recording Interrupt Service Routines is \r
+ * excluded, in order to reduce code size.\r
+ *\r
+ * Default value is 1.\r
+ * \r
+ * Note: tracing ISRs requires that you insert calls to vTraceStoreISRBegin\r
+ * and vTraceStoreISREnd in your interrupt handlers.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_ISR_TRACING 1\r
+\r
+/*****************************************************************************\r
+ * TRC_CFG_INCLUDE_READY_EVENTS\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * If one (1), events are recorded when tasks enter scheduling state "ready". \r
+ * This allows Tracealyzer to show the initial pending time before tasks enter\r
+ * the execution state, and present accurate response times.\r
+ * If zero (0), "ready events" are not created, which allows for recording\r
+ * longer traces in the same amount of RAM. \r
+ *\r
+ * Default value is 1.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_READY_EVENTS 1\r
+\r
+/*****************************************************************************\r
+ * TRC_CFG_INCLUDE_OSTICK_EVENTS\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * If this is one (1), events will be generated whenever the OS clock is\r
+ * increased. If zero (0), OS tick events are not generated, which allows for\r
+ * recording longer traces in the same amount of RAM. \r
+ *\r
+ * Default value is 0.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_OSTICK_EVENTS 0\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_INCLUDE_FLOAT_SUPPORT\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * If this is zero (0), the support for logging floating point values in \r
+ * vTracePrintF is stripped out, in case floating point values are not used or\r
+ * supported by the platform used.\r
+ *\r
+ * Floating point values are only used in vTracePrintF and its subroutines, to \r
+ * allow for storing float (%f) or double (%lf) arguments. \r
+ *\r
+ * vTracePrintF can be used with integer and string arguments in either case.\r
+ *\r
+ * Default value is 0.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_FLOAT_SUPPORT 0\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_INCLUDE_OBJECT_DELETE\r
+ * \r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ *\r
+ * This must be enabled (1) if tasks, queues or other \r
+ * traced kernel objects are deleted at runtime. If no deletes are made, this \r
+ * can be set to 0 in order to exclude the delete-handling code.\r
+ *\r
+ * Default value is 1.\r
+ *****************************************************************************/\r
+#define TRC_CFG_INCLUDE_OBJECT_DELETE 1\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_SYMBOL_TABLE_SIZE\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * This defines the capacity of the symbol table, in bytes. This symbol table \r
+ * stores User Events labels and names of deleted tasks, queues, or other kernel\r
+ * objects. If you don't use User Events or delete any kernel \r
+ * objects you set this to a very low value. The minimum recommended value is 4.\r
+ * A size of zero (0) is not allowed since a zero-sized array may result in a \r
+ * 32-bit pointer, i.e., using 4 bytes rather than 0.\r
+ *\r
+ * Default value is 800.\r
+ ******************************************************************************/\r
+#define TRC_CFG_SYMBOL_TABLE_SIZE 800\r
+\r
+#if (TRC_CFG_SYMBOL_TABLE_SIZE == 0)\r
+#error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!"\r
+#endif\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ...\r
+ *\r
+ * Macros that specify the maximum lengths (number of characters) for names of\r
+ * kernel objects, such as tasks and queues. If longer names are used, they will\r
+ * be truncated when stored in the recorder.\r
+ *****************************************************************************/\r
+#define TRC_CFG_NAME_LEN_TASK 15\r
+#define TRC_CFG_NAME_LEN_ISR 15\r
+#define TRC_CFG_NAME_LEN_QUEUE 15\r
+#define TRC_CFG_NAME_LEN_SEMAPHORE 15\r
+#define TRC_CFG_NAME_LEN_MUTEX 15\r
+#define TRC_CFG_NAME_LEN_TIMER 15\r
+#define TRC_CFG_NAME_LEN_EVENTGROUP 15\r
+\r
+/******************************************************************************\r
+ *** ADVANCED SETTINGS ********************************************************\r
+ ******************************************************************************\r
+ * The remaining settings are not necessary to modify but allows for optimizing\r
+ * the recorder setup for your specific needs, e.g., to exclude events that you\r
+ * are not interested in, in order to get longer traces.\r
+ *****************************************************************************/ \r
+\r
+/******************************************************************************\r
+* TRC_CFG_HEAP_SIZE_BELOW_16M\r
+*\r
+* An integer constant that can be used to reduce the buffer usage of memory\r
+* allocation events (malloc/free). This value should be 1 if the heap size is \r
+* below 16 MB (2^24 byte), and you can live with reported addresses showing the \r
+* lower 24 bits only. If 0, you get the full 32-bit addresses.\r
+*\r
+* Default value is 0.\r
+******************************************************************************/\r
+#define TRC_CFG_HEAP_SIZE_BELOW_16M 0\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_USE_IMPLICIT_IFE_RULES\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ * Default is 1.\r
+ *\r
+ * Tracealyzer groups the events into "instances" based on Instance Finish\r
+ * Events (IFEs), produced either by default rules or calls to the recorder\r
+ * functions vTraceInstanceFinishedNow and vTraceInstanceFinishedNext. \r
+ *\r
+ * If TRC_CFG_USE_IMPLICIT_IFE_RULES is one (1), the default IFE rules is\r
+ * used, resulting in a "typical" grouping of events into instances.\r
+ * If these rules don't give appropriate instances in your case, you can \r
+ * override the default rules using vTraceInstanceFinishedNow/Next for one\r
+ * or several tasks. The default IFE rules are then disabled for those tasks.\r
+ *\r
+ * If TRC_CFG_USE_IMPLICIT_IFE_RULES is zero (0), the implicit IFE rules are\r
+ * disabled globally. You must then call vTraceInstanceFinishedNow or\r
+ * vTraceInstanceFinishedNext to manually group the events into instances,\r
+ * otherwise the tasks will appear a single long instance.\r
+ * \r
+ * The default IFE rules count the following events as "instance finished":\r
+ * - Task delay, delay until\r
+ * - Task suspend\r
+ * - Blocking on "input" operations, i.e., when the task is waiting for the \r
+ * next a message/signal/event. But only if this event is blocking.\r
+ *\r
+ * For details, see trcSnapshotKernelPort.h and look for references to the \r
+ * macro trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED. \r
+ *****************************************************************************/\r
+#define TRC_CFG_USE_IMPLICIT_IFE_RULES 1\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_USE_16BIT_OBJECT_HANDLES\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1).\r
+ * \r
+ * If set to 0 (zero), the recorder uses 8-bit handles to identify kernel \r
+ * objects such as tasks and queues. This limits the supported number of\r
+ * concurrently active objects to 255 of each type (tasks, queues, mutexes,\r
+ * etc.) Note: 255, not 256, since handle 0 is reserved.\r
+ *\r
+ * If set to 1 (one), the recorder uses 16-bit handles to identify kernel \r
+ * objects such as tasks and queues. This limits the supported number of\r
+ * concurrent objects to 65535 of each type (object class). However, since the\r
+ * object property table is limited to 64 KB, the practical limit is about\r
+ * 3000 objects in total. \r
+ * \r
+ * Default is 0 (8-bit handles)\r
+ *\r
+ * NOTE: An object with handle above 255 will use an extra 4-byte record in \r
+ * the event buffer whenever the object is referenced. Moreover, some internal\r
+ * tables in the recorder gets slightly larger when using 16-bit handles.\r
+ *****************************************************************************/\r
+#define TRC_CFG_USE_16BIT_OBJECT_HANDLES 0\r
+\r
+/******************************************************************************\r
+ * TRC_CFG_USE_TRACE_ASSERT\r
+ *\r
+ * Macro which should be defined as either zero (0) or one (1). \r
+ * Default is 1.\r
+ *\r
+ * If this is one (1), the TRACE_ASSERT macro (used at various locations in the \r
+ * trace recorder) will verify that a relevant condition is true. \r
+ * If the condition is false, prvTraceError() will be called, which stops the\r
+ * recording and stores an error message that is displayed when opening the\r
+ * trace in Tracealyzer.\r
+ *\r
+ * This is used on several places in the recorder code for sanity checks on\r
+ * parameters. Can be switched off to reduce the footprint of the tracing, but\r
+ * we recommend to have it enabled initially.\r
+ *****************************************************************************/\r
+#define TRC_CFG_USE_TRACE_ASSERT 1\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * Set TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER to 1 to enable the \r
+ * separate user event buffer (UB).\r
+ * In this mode, user events are stored separately from other events, \r
+ * e.g., RTOS events. Thereby you can get a much longer history of \r
+ * user events as they don't need to share the buffer space with more \r
+ * frequent events. \r
+ *\r
+ * The UB is typically used with the snapshot ring-buffer mode, so the\r
+ * recording can continue when the main buffer gets full. And since the \r
+ * main buffer then overwrites the earliest events, Tracealyzer displays\r
+ * "Unknown Actor" instead of task scheduling for periods with UB data only.\r
+ * \r
+ * In UB mode, user events are structured as UB channels, which contains\r
+ * a channel name and a default format string. Register a UB channel using\r
+ * xTraceRegisterUBChannel.\r
+ *\r
+ * Events and data arguments are written using vTraceUBEvent and\r
+ * vTraceUBData. They are designed to provide efficient logging of\r
+ * repeating events, using the same format string within each channel.\r
+ *\r
+ * Examples:\r
+ *\r
+ * traceString chn1 = xTraceRegisterString("Channel 1");\r
+ * traceString fmt1 = xTraceRegisterString("Event!");\r
+ * traceUBChannel UBCh1 = xTraceRegisterUBChannel(chn1, fmt1);\r
+ * \r
+ * traceString chn2 = xTraceRegisterString("Channel 2");\r
+ * traceString fmt2 = xTraceRegisterString("X: %d, Y: %d");\r
+ * traceUBChannel UBCh2 = xTraceRegisterUBChannel(chn2, fmt2);\r
+ * \r
+ * // Result in "[Channel 1] Event!"\r
+ * vTraceUBEvent(UBCh1); \r
+ *\r
+ * // Result in "[Channel 2] X: 23, Y: 19"\r
+ * vTraceUBData(UBCh2, 23, 19);\r
+ *\r
+ * You can also use the other user event functions, like vTracePrintF.\r
+ * as they are then rerouted to the UB instead of the main event buffer.\r
+ * vTracePrintF then looks up the correct UB channel based on the \r
+ * provided channel name and format string, or creates a new UB channel\r
+ * if no match is found. The format string should therefore not contain \r
+ * "random" messages but mainly format specifiers. Random strings should\r
+ * be stored using %s and with the string as an argument.\r
+ *\r
+ * // Creates a new UB channel ("Channel 2", "%Z: %d")\r
+ * vTracePrintF(chn2, "%Z: %d", value1);\r
+ * \r
+ * // Finds the existing UB channel\r
+ * vTracePrintF(chn2, "%Z: %d", value2);\r
+ \r
+ ******************************************************************************/\r
+#define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 0\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * This defines the capacity of the user event buffer (UB), in number of slots.\r
+ * A single user event can use multiple slots, depending on the arguments.\r
+ *\r
+ * Only applicable if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is 1.\r
+ ******************************************************************************/\r
+#define TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE 200\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_UB_CHANNELS\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * This defines the number of User Event Buffer Channels (UB channels).\r
+ * These are used to structure the events when using the separate user\r
+ * event buffer, and contains both a User Event Channel (the name) and\r
+ * a default format string for the channel.\r
+ *\r
+ * Only applicable if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is 1.\r
+ ******************************************************************************/\r
+#define TRC_CFG_UB_CHANNELS 32\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_ISR_TAILCHAINING_THRESHOLD\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * If tracing multiple ISRs, this setting allows for accurate display of the \r
+ * context-switching also in cases when the ISRs execute in direct sequence.\r
+ * \r
+ * vTraceStoreISREnd normally assumes that the ISR returns to the previous\r
+ * context, i.e., a task or a preempted ISR. But if another traced ISR \r
+ * executes in direct sequence, Tracealyzer may incorrectly display a minimal\r
+ * fragment of the previous context in between the ISRs.\r
+ *\r
+ * By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is \r
+ * however a threshold value that must be measured for your specific setup.\r
+ * See http://percepio.com/2014/03/21/isr_tailchaining_threshold/\r
+ *\r
+ * The default setting is 0, meaning "disabled" and that you may get an \r
+ * extra fragments of the previous context in between tail-chained ISRs.\r
+ *\r
+ * Note: This setting has separate definitions in trcSnapshotConfig.h and \r
+ * trcStreamingConfig.h, since it is affected by the recorder mode.\r
+ ******************************************************************************/\r
+#define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0\r
+\r
+#endif /*TRC_SNAPSHOT_CONFIG_H*/\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcStreamingConfig.h\r
+ *\r
+ * Configuration parameters for the trace recorder library in streaming mode.\r
+ * Read more at http://percepio.com/2016/10/05/rtos-tracing/\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_STREAMING_CONFIG_H\r
+#define TRC_STREAMING_CONFIG_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_SYMBOL_TABLE_SLOTS\r
+ *\r
+ * The maximum number of symbols names that can be stored. This includes:\r
+ * - Task names\r
+ * - Named ISRs (vTraceSetISRProperties)\r
+ * - Named kernel objects (vTraceStoreKernelObjectName)\r
+ * - User event channels (vTraceStoreUserEventChannelName)\r
+ *\r
+ * If this value is too small, not all symbol names will be stored and the\r
+ * trace display will be affected. In that case, there will be warnings\r
+ * (as User Events) from TzCtrl task, that monitors this.\r
+ ******************************************************************************/\r
+#define TRC_CFG_SYMBOL_TABLE_SLOTS 40\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_SYMBOL_MAX_LENGTH\r
+ *\r
+ * The maximum length of symbol names, including:\r
+ * - Task names\r
+ * - Named ISRs (vTraceSetISRProperties)\r
+ * - Named kernel objects (vTraceStoreKernelObjectName)\r
+ * - User event channel names (vTraceStoreUserEventChannelName)\r
+ *\r
+ * If longer symbol names are used, they will be truncated by the recorder,\r
+ * which will affect the trace display. In that case, there will be warnings\r
+ * (as User Events) from TzCtrl task, that monitors this.\r
+ ******************************************************************************/\r
+#define TRC_CFG_SYMBOL_MAX_LENGTH 25\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_OBJECT_DATA_SLOTS\r
+ *\r
+ * The maximum number of object data entries (used for task priorities) that can\r
+ * be stored at the same time. Must be sufficient for all tasks, otherwise there\r
+ * will be warnings (as User Events) from TzCtrl task, that monitors this.\r
+ ******************************************************************************/\r
+#define TRC_CFG_OBJECT_DATA_SLOTS 40\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_CTRL_TASK_STACK_SIZE\r
+ *\r
+ * The stack size of the TzCtrl task, that receive commands.\r
+ * We are aiming to remove this extra task in future versions.\r
+ ******************************************************************************/\r
+#define TRC_CFG_CTRL_TASK_STACK_SIZE (configMINIMAL_STACK_SIZE * 2)\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_CTRL_TASK_PRIORITY\r
+ *\r
+ * The priority of the TzCtrl task, that receive commands from Tracealyzer.\r
+ * Most stream ports also rely on the TzCtrl task to transmit the data from the\r
+ * internal buffer to the stream interface (all except for the J-Link port).\r
+ * For such ports, make sure the TzCtrl priority is high enough to ensure\r
+ * reliable periodic execution and transfer of the data.\r
+ ******************************************************************************/\r
+#define TRC_CFG_CTRL_TASK_PRIORITY 1\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_CTRL_TASK_DELAY\r
+ *\r
+ * The delay between every loop of the TzCtrl task. A high delay will reduce the\r
+ * CPU load, but may cause missed events if the TzCtrl task is performing the \r
+ * trace transfer.\r
+ ******************************************************************************/\r
+#define TRC_CFG_CTRL_TASK_DELAY ((10 * configTICK_RATE_HZ) / 1000)\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT\r
+ *\r
+ * Specifies the number of pages used by the paged event buffer.\r
+ * This may need to be increased if there are a lot of missed events.\r
+ *\r
+ * Note: not used by the J-Link RTT stream port (see SEGGER_RTT_Conf.h instead)\r
+ ******************************************************************************/\r
+#define TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT 2\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE\r
+ *\r
+ * Specifies the size of each page in the paged event buffer. This can be tuned \r
+ * to match any internal low-level buffers used by the streaming interface, like\r
+ * the Ethernet MTU (Maximum Transmission Unit).\r
+ *\r
+ * Note: not used by the J-Link RTT stream port (see SEGGER_RTT_Conf.h instead)\r
+ ******************************************************************************/\r
+#define TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE 2500\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_ISR_TAILCHAINING_THRESHOLD\r
+ *\r
+ * Macro which should be defined as an integer value.\r
+ *\r
+ * If tracing multiple ISRs, this setting allows for accurate display of the \r
+ * context-switching also in cases when the ISRs execute in direct sequence.\r
+ * \r
+ * vTraceStoreISREnd normally assumes that the ISR returns to the previous\r
+ * context, i.e., a task or a preempted ISR. But if another traced ISR \r
+ * executes in direct sequence, Tracealyzer may incorrectly display a minimal\r
+ * fragment of the previous context in between the ISRs.\r
+ *\r
+ * By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is \r
+ * however a threshold value that must be measured for your specific setup.\r
+ * See http://percepio.com/2014/03/21/isr_tailchaining_threshold/\r
+ *\r
+ * The default setting is 0, meaning "disabled" and that you may get an \r
+ * extra fragments of the previous context in between tail-chained ISRs.\r
+ *\r
+ * Note: This setting has separate definitions in trcSnapshotConfig.h and \r
+ * trcStreamingConfig.h, since it is affected by the recorder mode.\r
+ ******************************************************************************/\r
+#define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* TRC_STREAMING_CONFIG_H */\r
+++ /dev/null
-\r
-Tracealyzer - Uploading the trace data\r
------------------------------------------\r
-Percepio AB, Jan. 23, 2014\r
-\r
-This document decribes how to upload the trace data from the target system to\r
-Tracealyzer. \r
-\r
-Tracealyzer uses your existing debugger to upload the trace data from the \r
-chip RAM. This is a plain RAM dump, that is done whenever you want to look at \r
-the trace buffer contents. This means it works with essentially with any debug \r
-probe on the market.\r
-\r
-Built-in support for Segger J-Link/J-Trace and Atmel SAM-ICE\r
-------------------------------------------------------------\r
-Tracealyzer v2.3 supports Segger J-Link and J-Link compatible debuggers \r
-directly, without any debugger IDE involved. Using other debug probes is \r
-also possible, but requires some extra steps, described below.\r
-\r
-If you have a Segger J-Link/J-Trace debug probe or another J-Link compatible \r
-debug probe, just select "Read Trace" in the "J-Link" menu. Note that this \r
-menu is only available if a compatible debug probe is found.\r
-\r
-This opens a dialog where you get to enter the memory region where\r
-the recorder data structure is located. Normally you select the entire \r
-internal RAM according to the datasheet of your MCU, but the exact address\r
-can be found can by inspecting the "RecorderData" struct or the \r
-"RecorderDataPtr" pointer with your debugger.\r
-\r
-J-Link compatible debug probes also include Atmel SAM-ICE and many built-in \r
-debug interfaces on demonstration/evaluation boards (where there is a USB \r
-connection directly to the board). Look for a Segger J-Link label on the board.\r
-\r
-MemoryLogger extension in Atmel Studio 6\r
-----------------------------------------\r
-Atmel's MemoryLogger extension provides a superb integration with FreeRTOS+Trace. \r
-Look for "MemoryLogger" in Atmel Gallery, available in Atmel Studio and at the \r
-Atmel website (http://gallery.atmel.com).\r
-\r
-This extension automatically detects the path to FreeRTOS+Trace, if \r
-installed, and gives you a single-click upload/refresh. You can use it \r
-while debugging and optionally get an automatic refresh eash time the \r
-MCU is halted, e.g., on each breakpoint.\r
-\r
-Using other development environments and debug probes\r
------------------------------------------------------\r
-Most debuggers are able to save the RAM contents to a file. Tracealyzer \r
-supports the following common formats:\r
-- Binary (.bin), supporting gdb, J-Link and Renesas HEW.\r
-- Intel Hex (.hex), supporting IAR Embedded Workbench and Atmel Studio (atprogram.exe)\r
-- MCH (.mch), supporting Microchip MPLAB.\r
-\r
-When you store the RAM dump, you must also make sure to select the right region, \r
-i.e., start address and size. The recorder data is stored in a single data \r
-block, identified by the pointer RecorderDataPtr. \r
-It is not necessary to match the begin and end of the recorder data, as long as \r
-it is fully included by the dumped memory region. Tracealyzer automatically \r
-finds the trace data in the RAM dump, thanks to special signatures. For chips \r
-with on-chip RAM only, we therefore recommend to dump the entire RAM. This is \r
-usually very fast.\r
-For chips with larger amounts of (external) RAM, it is typically possible to \r
-dump a limited region where the data is typically found.\r
-\r
-Using IAR Embedded Workbench for ARM, version 6.3\r
--------------------------------------------------\r
-In the debugger view, when stopped on a breakpoint:\r
-- Select "Debug" menu, "Memory" submenu, "Save..." (keyboard shortcut: ALT,d,y,s)\r
-- In the Save dialog\r
- - Zone: Memory\r
- - Start Adress: 10000000 (for NXP LPC1766 in the demo project)\r
- - End Adress: 1000FFFF (for NXP LPC1766 in the demo project)\r
- - File format: Intel Extended\r
- - Filename: <name>.hex\r
- - Press "Save" button\r
-You can now open <name>.hex in Tracealyzer.\r
-\r
-To find the right Start and End addresses, check the address of the symbol \r
-"RecorderData". The addresses does not need to match this symbol exactly, as \r
-long as the whole data is included.\r
-\r
-Using Renesas High-performance Embedded Workshop v4.09\r
-------------------------------------------------------\r
-In the debugger view, when stopped on a breakpoint:\r
-- Select "Debug" menu, "Save Memory..." (keyboard shortcut: ALT,d,a)\r
-- In the Save dialog\r
- - Format: Binary\r
- - Filename: <name>.bin\r
- - Start Address: 00000000 (For RX62N in the demo project)\r
- - End Address: 0000FFFF (For RX62N in the demo project)\r
- - Access size: 1\r
- - Press "Save" button and open <name>.bin in Tracealyzer.\r
- \r
-Using Microchip MPLAB v8.86\r
-------------------------------------------------------\r
-- Select "View" -> "File Registers". This shows you the memory contents.\r
-- Make sure "Hex" is selected in the bottom left (instead of "Symbolic"). Hex mode seems to be default.\r
-- Right click in the view and select "Export Table...".\r
-- In the dialog ("Export As"), make sure "Single Column Output" is selected (seems to be default).\r
-- Select start address 0x0000 and make sure the end address is beyond the RecorderData structure. \r
- The default values seems to be the whole RAM, so you probably don't need to change this.\r
-- Save as a .mch file and open this file in Tracealyzer v2.2.4 or later (support for the .mch format was added in v2.2.4).\r
-\r
-Using STM32 ST-Link\r
-------------------------------------------------------\r
-- Start "ST-Link Utility"\r
-- Connect to the device and view the device memory.\r
-- Set the view to display the entire RAM, or at least the section containing the RecorderData structure.\r
-- Select "Save as" and choose binary (.bin) or Intel Hex (.hex) format.\r
-- Open the resulting file in Tracealyzer.\r
-\r
-In case you have any question, contact support@percepio.com\r
-\r
-Percepio AB\r
-www.percepio.com\r
+-------------------------------------------------------------------------------\r
+ Tracealyzer for FreeRTOS - Trace Recorder Library v3.1.1 \r
+-------------------------------------------------------------------------------\r
\r
-Tracealyzer Trace Recorder Library\r
--------------------------------------\r
-Percepio AB\r
-www.percepio.com\r
-\r
-This directory contains the a generic trace recorder library for Tracealyzer v3.0.2.\r
-\r
-For information on how to upload the trace data from your target system RAM to \r
-Tracealyzer, see the User Manual.\r
-\r
-Files included\r
---------------\r
-- trcConfig.h - The recorder's configuration file, set your recorder configuration here!\r
-- trcUser.c/.h - The main API towards the application (trcUser.h in the only include necessary).\r
-- trcKernel.c/.h - Internal routines for storing kernel events.\r
-- trcBase.c/.h - Internal routines for manipulating the data structures and calculating timestamps.\r
-- trcHardwarePort.c/.h - The hardware interface, especially for timestamping.\r
-- trcKernelPort.h - Wrapper for trcKernelPortFreeRTOS.h (for portability).\r
-- trcKernelPortFreeRTOS.c/.h - FreeRTOS-specific trace macros and helper functions.\r
-- trcKernelHooks.h - Generic trace macros (OS independent), used by trcKernelPortFreeRTOS.\r
-- trcTypes.h - Type definitions used.\r
-\r
-Hardware Timer Ports\r
---------------------\r
-This release contains hardware timer ports for the following hardware architectures:\r
-\r
-- ARM Cortex M3/M4/M0/M0+ (all brands, such as Atmel SAM3x/SAM4x/SAM D20, NXP 17xx, 18xx, 43xx, STM32, Freescale Kinetis, ...)\r
-- Atmel AT91SAM7x\r
-- Atmel AT32UC3 (AVR32)\r
-- Renesas RX600 (e.g., RX62N)\r
-- Microchip dsPIC/PIC24\r
-- Microchip PIC32MX\r
-- Microchip PIC32MZ\r
-- NXP LPC2106\r
-- Texas Instruments TMS570 (Cortex-R4)\r
-- Texas Instruments MSP430\r
-- Xilinx PowerPC 405\r
-- Xilinx PowerPC 440\r
-- Xilinx Microblaze\r
-- ARM Cortex-A9\r
-\r
-These are defined in trcHardwarePort.h. Some of these are "unofficial" ports, provided by external contributors.\r
-By unofficial, it means that they are not yet verified by Percepio AB. Please refer to trcHardwarePort.h for detailed information. \r
-If you use an unofficial port and believe it is incorrect, please let us know! (support@percepio.com)\r
-\r
-In case your MCU is not yet supported directly, developing a new port is quite easy, just a matter of defining a few macros\r
-according to your specific MCU. See trcHardwarePort.h for further information.\r
-\r
-In case you have any questions, do not hesitate to contact support@percepio.com\r
-\r
-Percepio AB\r
-Köpmangatan 1A\r
-72215 Västerås\r
-Sweden\r
-\r
-www.percepio.com
\ No newline at end of file
+Tracealyzer for FreeRTOS is a sophisticated tool for tracing and visualization\r
+of FreeRTOS-based systems. Tracealyzer gives an unprecedented insight into the\r
+runtime behavior, which speeds up debugging, validation and optimization. \r
+\r
+To learn more about this, see\r
+\r
+ - Getting Started (videos etc): http://percepio.com/gettingstarted/tz-freertos/\r
+\r
+ - User Manual (incl. Recorder API): http://percepio.com/docs/FreeRTOS/manual\r
+\r
+ - FAQ: http://percepio.com/category/faq/\r
+\r
+In case you have any questions, don't hesitate to contact support@percepio.com\r
+\r
+-------------------------------------------------------------------------------\r
+\r
+Changes, v3.1.1 -> v3.1.2\r
+\r
+- Fixed two bugs related to User Events, one in vTracePrintF and other in vTracePrint.\r
+\r
+- Fixed a build problem related to a single reference of the old FreeRTOS type "xTaskHandle", in trcKernelPort.c.\r
+ Changed to "TaskHandle_t", unless if using an older FreeRTOS kernel or the "compatibility mode".\r
+\r
+- Removed traceCREATE_MUTEX hook for FreeRTOS v9 or later (no longer required)\r
+\r
+- Updated the User Manual regarding snapshot trace via IAR Embedded Workbench.\r
+\r
+- Renamed vTraceGetTraceBuffer to xTraceGetTraceBuffer, since returning a pointer.\r
+\r
+-------------------------------------------------------------------------------\r
+\r
+Changes, v3.1.0 -> v3.1.1\r
+\r
+After the major changes in the v3.1.0 trace recorder library, this update \r
+corrects a number of minor issues. Only minor functional improvements.\r
+\r
+- You can now use TRC_ALLOC_CUSTOM_BUFFER to declare a trace buffer on a custom\r
+ location (using linker directives). \r
+ The related function vTraceSetRecorderDataBuffer has been promoted to the\r
+ Common API (previously only supported in snapshot mode, but custom allocation\r
+ is now generally supported also in streaming mode).\r
+ \r
+- Removed TRC_CFG_USE_LINKER_PRAGMA. No longer necessary thanks to the custom\r
+ allocation mode.\r
+ \r
+- Added support for timestamping from custom periodic timers, required for\r
+ accurate timestamping on Cortex-M0/M0+ devices when using tickless idle.\r
+ Only for streaming mode so far. See TRC_CUSTOM_TIMER_INCR / DECR.\r
+\r
+- ARM Cortex-M port: Made sure the DWT unit is initialized properly, in case\r
+ the debugger doesn't handle this.\r
+\r
+- ARM Cortex-M port: Added possibility to use Systick timestamping also on\r
+ Cortex-M3/M4/M7 devices (that otherwise use DWT timestamping by default).\r
+ To use this option, define the macro TRC_CFG_ARM_CM_USE_SYSTICK.\r
+\r
+- J-Link streaming: The default RTT buffer has been changed from 0 to 1.\r
+\r
+- J-Link streaming: The RTT buffer settings for buffer 1 and higher, are now\r
+ found in trcStreamingPort.h. Note: These settings don't apply to buffer 0.\r
+\r
+- vTracePrint has been optimized for better performance in string logging.\r
+\r
+- Minor performance improvement related to symbol table transfer in streaming mode.\r
+\r
+- Timer names now registered also in streaming mode.\r
+\r
+- Timer start and stop event are now traced.\r
+\r
+- Implemented support for queue registry (traceQUEUE_REGISTRY_ADD) also for streaming.\r
+\r
+- Fixed a bug related to repeated calls of vTraceEnable.\r
+\r
+- Fixed a bug where task-switches seemed to occur even though the scheduler was disabled.\r
+\r
+- Renamed HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48, added prefix TRC.\r
+\r
+- Fixed several language issues in the comments and documentation.\r
+\r
+- Fixed several minor issues and warnings from different compilers\r
+ (including PowerPC/gcc) and configurations.\r
+\r
+-------------------------------------------------------------------------------\r
+ \r
+Changes, v3.0.9 -> v3.1.0\r
+\r
+- Merge of previously separated snapshot and streaming recorders into a single\r
+ recorder supporting both streaming and snapshot as different modes.\r
+ \r
+- New common API for supporting both streaming and snapshot modes.\r
+ \r
+- New integration guide, see the User Manual.\r
+\r
+- Major improvement of API documentation in source files and User Manual.\r
+ \r
+- New concept of "stream ports", giving a better structure defining streaming\r
+ interfaces, and restructured the J-Link and TCP/IP streaming as stream ports.\r
+ \r
+- Added a stream port for USB CDC connections, with STM32 as example.\r
+ Since Tracealyzer now can receive serial data on Windows COM ports, this is\r
+ really easy to use.\r
+\r
+- Added a warning (#error) for cases where FreeRTOS tickless idle mode is used\r
+ together with timestamping using SysTick or other periodic interrupt timers,\r
+ Tracing with tickless idle requires an independent time source to correctly\r
+ capture the length of the idle periods.\r
+ \r
+- Major changes in the recorder API. Important examples are:\r
+\r
+ * Some configuration macros have changed names, e.g. for "hardware port".\r
+ Make sure to remove any old "trcConfig.h" files if upgrading from an\r
+ earlier version!\r
+\r
+ * Recorder configuration in trcConfig.h has been minimized and now only \r
+ includes the important settings that are independent of recorder mode.\r
+ Advanced settings for each mode are found in trcSnapshotConfig.h and\r
+ trcStreamingConfig.h.\r
+ \r
+ * vTraceEnable replaces Trace_Init and vTraceInitTraceData, as well as\r
+ vTraceStart and uiTraceStart.\r
+ \r
+ * vTraceStop now part of the common API and thereby available also in\r
+ streaming. And since vTraceEnable can start the streaming directly\r
+ you have the option control the tracing from target, e.g., for\r
+ streaming to a device file system.\r
+ \r
+ * vTraceStoreKernelObjectName from old streaming recorder has been replaced\r
+ by vTraceSetQueueName, vTraceSetSemaphoreName, etc.\r
+ \r
+ * vTraceSetISRProperties now returns a "traceHandle" that should be passed as\r
+ parameter to vTraceStoreISRBegin and vTraceStoreISREnd.\r
+ \r
+ * xTraceRegisterString has replaced the old functions xTraceOpenLabel and \r
+ vTraceStoreUserEventChannelName. This now returns a "traceString" for use\r
+ as "channel" parameter in vTracePrintF, and in other places where strings\r
+ are stored.\r
+ \r
+ * Removed vTraceStoreISREndManual and vTraceStoreISREndAuto, use\r
+ vTraceStoreISREnd instead.\r
+ \r
+ * Renamed the functions for saving User Events in a separate buffer:\r
+ - xTraceRegisterChannelFormat -> xTraceRegisterUBChannel\r
+ - vTraceChannelPrintF -> vTraceUBData\r
+ - vTraceChannelUserEvent -> vTraceUBEvent\r
+ \r
+ \r
+-------------------------------------------------------------------------------\r
+Copyright Percepio AB, 2017.
\ No newline at end of file
--- /dev/null
+Tracealyzer Stream Port for SEGGER J-Link\r
+-----------------------------------------\r
+\r
+This directory contains a "stream port" for the Tracealyzer recorder library,\r
+i.e., the specific code needed to use a particular interface for streaming a\r
+Tracealyzer RTOS trace. The stream port is defined by a set of macros in\r
+trcStreamingPort.h, found in the "include" directory.\r
+\r
+This particular stream port targets SEGGER J-Link debug probes, using the RTT\r
+interface provided by SEGGER.\r
+\r
+To use this stream port, make sure that include/trcStreamingPort.h is found\r
+by the compiler (i.e., add this folder to your project's include paths) and\r
+add all included source files to your build. Make sure no other versions of\r
+trcStreamingPort.h are included by mistake!\r
+\r
+Note that this stream port also contains SEGGER's RTT driver.\r
+\r
+See also http://percepio.com/2016/10/05/rtos-tracing.\r
+\r
+Percepio AB\r
+www.percepio.com
\ No newline at end of file
--- /dev/null
+/*********************************************************************\r
+* SEGGER MICROCONTROLLER GmbH & Co. KG *\r
+* Solutions for real time microcontroller applications *\r
+**********************************************************************\r
+* *\r
+* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *\r
+* *\r
+* www.segger.com Support: support@segger.com *\r
+* *\r
+**********************************************************************\r
+* *\r
+* SEGGER RTT * Real Time Transfer for embedded targets *\r
+* *\r
+**********************************************************************\r
+* *\r
+* All rights reserved. *\r
+* *\r
+* * This software may in its unmodified form be freely redistributed *\r
+* in source, linkable, or executable form. *\r
+* * The source code may be modified, provided the source code *\r
+* retains the above copyright notice, this list of conditions and *\r
+* the following disclaimer. *\r
+* * Modified versions of this software in source, executable, or *\r
+* linkable form may not be distributed without prior consent of *\r
+* SEGGER. *\r
+* * This software may only be used for communication with SEGGER *\r
+* J-Link debug probes. *\r
+* *\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *\r
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *\r
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *\r
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *\r
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *\r
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *\r
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *\r
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *\r
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *\r
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *\r
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *\r
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *\r
+* DAMAGE. *\r
+* *\r
+**********************************************************************\r
+* *\r
+* RTT version: 6.00e *\r
+* *\r
+**********************************************************************\r
+---------------------------END-OF-HEADER------------------------------\r
+File : SEGGER_RTT.c\r
+Purpose : Implementation of SEGGER real-time transfer (RTT) which\r
+ allows real-time communication on targets which support\r
+ debugger memory accesses while the CPU is running.\r
+Revision: $Rev: 4079 $\r
+\r
+Additional information:\r
+ Type "int" is assumed to be 32-bits in size\r
+ H->T Host to target communication\r
+ T->H Target to host communication\r
+\r
+ RTT channel 0 is always present and reserved for Terminal usage.\r
+ Name is fixed to "Terminal"\r
+\r
+ Effective buffer size: SizeOfBuffer - 1\r
+\r
+ WrOff == RdOff: Buffer is empty\r
+ WrOff == (RdOff - 1): Buffer is full\r
+ WrOff > RdOff: Free space includes wrap-around\r
+ WrOff < RdOff: Used space includes wrap-around\r
+ (WrOff == (SizeOfBuffer - 1)) && (RdOff == 0): \r
+ Buffer full and wrap-around after next byte\r
+\r
+\r
+----------------------------------------------------------------------\r
+*/\r
+\r
+#include "SEGGER_RTT.h"\r
+\r
+#include <string.h> // for memcpy\r
+\r
+/*********************************************************************\r
+*\r
+* Configuration, default values\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+#ifndef BUFFER_SIZE_UP\r
+ #define BUFFER_SIZE_UP 1024 // Size of the buffer for terminal output of target, up to host\r
+#endif\r
+\r
+#ifndef BUFFER_SIZE_DOWN\r
+ #define BUFFER_SIZE_DOWN 16 // Size of the buffer for terminal input to target from host (Usually keyboard input)\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_MAX_NUM_UP_BUFFERS\r
+ #define SEGGER_RTT_MAX_NUM_UP_BUFFERS 2 // Number of up-buffers (T->H) available on this target\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_MAX_NUM_DOWN_BUFFERS\r
+ #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS 2 // Number of down-buffers (H->T) available on this target\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_BUFFER_SECTION\r
+ #if defined(SEGGER_RTT_SECTION)\r
+ #define SEGGER_RTT_BUFFER_SECTION SEGGER_RTT_SECTION\r
+ #endif\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_ALIGNMENT\r
+ #define SEGGER_RTT_ALIGNMENT 0\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_BUFFER_ALIGNMENT\r
+ #define SEGGER_RTT_BUFFER_ALIGNMENT 0\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_MODE_DEFAULT\r
+ #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_LOCK\r
+ #define SEGGER_RTT_LOCK()\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_UNLOCK\r
+ #define SEGGER_RTT_UNLOCK()\r
+#endif\r
+\r
+#ifndef STRLEN\r
+ #define STRLEN(a) strlen((a))\r
+#endif\r
+\r
+#ifndef MEMCPY\r
+ #define MEMCPY(pDest, pSrc, NumBytes) memcpy((pDest), (pSrc), (NumBytes))\r
+#endif\r
+\r
+#ifndef MIN\r
+ #define MIN(a, b) (((a) < (b)) ? (a) : (b))\r
+#endif\r
+\r
+#ifndef MAX\r
+ #define MAX(a, b) (((a) > (b)) ? (a) : (b))\r
+#endif\r
+//\r
+// For some environments, NULL may not be defined until certain headers are included\r
+//\r
+#ifndef NULL\r
+ #define NULL 0\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* Defines, fixed\r
+*\r
+**********************************************************************\r
+*/\r
+#if (defined __ICCARM__) || (defined __ICCRX__)\r
+ #define RTT_PRAGMA(P) _Pragma(#P)\r
+#endif\r
+\r
+#if SEGGER_RTT_ALIGNMENT || SEGGER_RTT_BUFFER_ALIGNMENT\r
+ #if (defined __GNUC__)\r
+ #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment)))\r
+ #elif (defined __ICCARM__) || (defined __ICCRX__)\r
+ #define PRAGMA(A) _Pragma(#A)\r
+#define SEGGER_RTT_ALIGN(Var, Alignment) RTT_PRAGMA(data_alignment=Alignment) \\r
+ Var\r
+ #elif (defined __CC_ARM__)\r
+ #define SEGGER_RTT_ALIGN(Var, Alignment) Var __attribute__ ((aligned (Alignment)))\r
+ #else\r
+ #error "Alignment not supported for this compiler."\r
+ #endif\r
+#else\r
+ #define SEGGER_RTT_ALIGN(Var, Alignment) Var\r
+#endif\r
+\r
+#if defined(SEGGER_RTT_SECTION) || defined (SEGGER_RTT_BUFFER_SECTION)\r
+ #if (defined __GNUC__)\r
+ #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section))) Var\r
+ #elif (defined __ICCARM__) || (defined __ICCRX__)\r
+#define SEGGER_RTT_PUT_SECTION(Var, Section) RTT_PRAGMA(location=Section) \\r
+ Var\r
+ #elif (defined __CC_ARM__)\r
+ #define SEGGER_RTT_PUT_SECTION(Var, Section) __attribute__ ((section (Section), zero_init)) Var\r
+ #else\r
+ #error "Section placement not supported for this compiler."\r
+ #endif\r
+#else\r
+ #define SEGGER_RTT_PUT_SECTION(Var, Section) Var\r
+#endif\r
+\r
+\r
+#if SEGGER_RTT_ALIGNMENT\r
+ #define SEGGER_RTT_CB_ALIGN(Var) SEGGER_RTT_ALIGN(Var, SEGGER_RTT_ALIGNMENT)\r
+#else\r
+ #define SEGGER_RTT_CB_ALIGN(Var) Var\r
+#endif\r
+\r
+#if SEGGER_RTT_BUFFER_ALIGNMENT\r
+ #define SEGGER_RTT_BUFFER_ALIGN(Var) SEGGER_RTT_ALIGN(Var, SEGGER_RTT_BUFFER_ALIGNMENT)\r
+#else\r
+ #define SEGGER_RTT_BUFFER_ALIGN(Var) Var\r
+#endif\r
+\r
+\r
+#if defined(SEGGER_RTT_SECTION)\r
+ #define SEGGER_RTT_PUT_CB_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_SECTION)\r
+#else\r
+ #define SEGGER_RTT_PUT_CB_SECTION(Var) Var\r
+#endif\r
+\r
+#if defined(SEGGER_RTT_BUFFER_SECTION)\r
+ #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) SEGGER_RTT_PUT_SECTION(Var, SEGGER_RTT_BUFFER_SECTION)\r
+#else\r
+ #define SEGGER_RTT_PUT_BUFFER_SECTION(Var) Var\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* Static const data\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+static unsigned char _aTerminalId[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\r
+\r
+/*********************************************************************\r
+*\r
+* Static data\r
+*\r
+**********************************************************************\r
+*/\r
+//\r
+// RTT Control Block and allocate buffers for channel 0\r
+//\r
+SEGGER_RTT_PUT_CB_SECTION(SEGGER_RTT_CB_ALIGN(SEGGER_RTT_CB _SEGGER_RTT));\r
+\r
+SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBuffer [BUFFER_SIZE_UP]));\r
+SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[BUFFER_SIZE_DOWN]));\r
+\r
+static char _ActiveTerminal;\r
+\r
+/*********************************************************************\r
+*\r
+* Static functions\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+/*********************************************************************\r
+*\r
+* _DoInit()\r
+*\r
+* Function description\r
+* Initializes the control block an buffers.\r
+* May only be called via INIT() to avoid overriding settings.\r
+*\r
+*/\r
+#define INIT() do { \\r
+ if (_SEGGER_RTT.acID[0] == '\0') { _DoInit(); } \\r
+ } while (0)\r
+static void _DoInit(void) {\r
+ SEGGER_RTT_CB* p;\r
+ //\r
+ // Initialize control block\r
+ //\r
+ p = &_SEGGER_RTT;\r
+ p->MaxNumUpBuffers = SEGGER_RTT_MAX_NUM_UP_BUFFERS;\r
+ p->MaxNumDownBuffers = SEGGER_RTT_MAX_NUM_DOWN_BUFFERS;\r
+ //\r
+ // Initialize up buffer 0\r
+ //\r
+ p->aUp[0].sName = "Terminal";\r
+ p->aUp[0].pBuffer = _acUpBuffer;\r
+ p->aUp[0].SizeOfBuffer = sizeof(_acUpBuffer);\r
+ p->aUp[0].RdOff = 0u;\r
+ p->aUp[0].WrOff = 0u;\r
+ p->aUp[0].Flags = SEGGER_RTT_MODE_DEFAULT;\r
+ //\r
+ // Initialize down buffer 0\r
+ //\r
+ p->aDown[0].sName = "Terminal";\r
+ p->aDown[0].pBuffer = _acDownBuffer;\r
+ p->aDown[0].SizeOfBuffer = sizeof(_acDownBuffer);\r
+ p->aDown[0].RdOff = 0u;\r
+ p->aDown[0].WrOff = 0u;\r
+ p->aDown[0].Flags = SEGGER_RTT_MODE_DEFAULT;\r
+ //\r
+ // Finish initialization of the control block.\r
+ // Copy Id string in three steps to make sure "SEGGER RTT" is not found\r
+ // in initializer memory (usually flash) by J-Link\r
+ //\r
+ strcpy(&p->acID[7], "RTT");\r
+ strcpy(&p->acID[0], "SEGGER");\r
+ p->acID[6] = ' ';\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* _WriteBlocking()\r
+*\r
+* Function description\r
+* Stores a specified number of characters in SEGGER RTT ring buffer\r
+* and updates the associated write pointer which is periodically\r
+* read by the host.\r
+* The caller is responsible for managing the write chunk sizes as\r
+* _WriteBlocking() will block until all data has been posted successfully.\r
+*\r
+* Parameters\r
+* pRing Ring buffer to post to.\r
+* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.\r
+* NumBytes Number of bytes to be stored in the SEGGER RTT control block.\r
+*\r
+* Return value\r
+* >= 0 - Number of bytes written into buffer.\r
+*/\r
+static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer, unsigned NumBytes) {\r
+ unsigned NumBytesToWrite;\r
+ unsigned NumBytesWritten;\r
+ unsigned RdOff;\r
+ unsigned WrOff;\r
+ //\r
+ // Write data to buffer and handle wrap-around if necessary\r
+ //\r
+ NumBytesWritten = 0u;\r
+ WrOff = pRing->WrOff;\r
+ do {\r
+ RdOff = pRing->RdOff; // May be changed by host (debug probe) in the meantime\r
+ if (RdOff > WrOff) {\r
+ NumBytesToWrite = RdOff - WrOff - 1u;\r
+ } else {\r
+ NumBytesToWrite = pRing->SizeOfBuffer - (WrOff - RdOff + 1u);\r
+ }\r
+ NumBytesToWrite = MIN(NumBytesToWrite, (pRing->SizeOfBuffer - WrOff)); // Number of bytes that can be written until buffer wrap-around\r
+ NumBytesToWrite = MIN(NumBytesToWrite, NumBytes);\r
+ memcpy(pRing->pBuffer + WrOff, pBuffer, NumBytesToWrite);\r
+ NumBytesWritten += NumBytesToWrite;\r
+ pBuffer += NumBytesToWrite;\r
+ NumBytes -= NumBytesToWrite;\r
+ WrOff += NumBytesToWrite;\r
+ if (WrOff == pRing->SizeOfBuffer) {\r
+ WrOff = 0u;\r
+ }\r
+ pRing->WrOff = WrOff;\r
+ } while (NumBytes);\r
+ //\r
+ return NumBytesWritten;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* _WriteNoCheck()\r
+*\r
+* Function description\r
+* Stores a specified number of characters in SEGGER RTT ring buffer\r
+* and updates the associated write pointer which is periodically\r
+* read by the host.\r
+* It is callers responsibility to make sure data actually fits in buffer.\r
+*\r
+* Parameters\r
+* pRing Ring buffer to post to.\r
+* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.\r
+* NumBytes Number of bytes to be stored in the SEGGER RTT control block.\r
+*\r
+* Notes\r
+* (1) If there might not be enough space in the "Up"-buffer, call _WriteBlocking\r
+*/\r
+static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsigned NumBytes) {\r
+ unsigned NumBytesAtOnce;\r
+ unsigned WrOff;\r
+ unsigned Rem;\r
+\r
+ WrOff = pRing->WrOff;\r
+ Rem = pRing->SizeOfBuffer - WrOff;\r
+ if (Rem > NumBytes) {\r
+ //\r
+ // All data fits before wrap around\r
+ //\r
+ memcpy(pRing->pBuffer + WrOff, pData, NumBytes);\r
+ pRing->WrOff = WrOff + NumBytes;\r
+ } else {\r
+ //\r
+ // We reach the end of the buffer, so need to wrap around\r
+ //\r
+ NumBytesAtOnce = Rem;\r
+ memcpy(pRing->pBuffer + WrOff, pData, NumBytesAtOnce);\r
+ NumBytesAtOnce = NumBytes - Rem;\r
+ memcpy(pRing->pBuffer, pData + Rem, NumBytesAtOnce);\r
+ pRing->WrOff = NumBytesAtOnce;\r
+ }\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* _PostTerminalSwitch()\r
+*\r
+* Function description\r
+* Switch terminal to the given terminal ID. It is the caller's\r
+* responsibility to ensure the terminal ID is correct and there is\r
+* enough space in the buffer for this to complete successfully.\r
+*\r
+* Parameters\r
+* pRing Ring buffer to post to.\r
+* TerminalId Terminal ID to switch to.\r
+*/\r
+static void _PostTerminalSwitch(SEGGER_RTT_BUFFER_UP* pRing, unsigned char TerminalId) {\r
+ char ac[2];\r
+\r
+ ac[0] = 0xFFu;\r
+ ac[1] = _aTerminalId[TerminalId]; // Caller made already sure that TerminalId does not exceed our terminal limit\r
+ _WriteBlocking(pRing, ac, 2u);\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* _GetAvailWriteSpace()\r
+*\r
+* Function description\r
+* Returns the number of bytes that can be written to the ring\r
+* buffer without blocking.\r
+*\r
+* Parameters\r
+* pRing Ring buffer to check.\r
+*\r
+* Return value\r
+* Number of bytes that are free in the buffer.\r
+*/\r
+static unsigned _GetAvailWriteSpace(SEGGER_RTT_BUFFER_UP* pRing) {\r
+ unsigned RdOff;\r
+ unsigned WrOff;\r
+ unsigned r;\r
+ //\r
+ // Avoid warnings regarding volatile access order. It's not a problem\r
+ // in this case, but dampen compiler enthusiasm.\r
+ //\r
+ RdOff = pRing->RdOff;\r
+ WrOff = pRing->WrOff;\r
+ if (RdOff <= WrOff) {\r
+ r = pRing->SizeOfBuffer - 1u - WrOff + RdOff;\r
+ } else {\r
+ r = RdOff - WrOff - 1u;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* Public code\r
+*\r
+**********************************************************************\r
+*/\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_ReadNoLock()\r
+*\r
+* Function description\r
+* Reads characters from SEGGER real-time-terminal control block\r
+* which have been previously stored by the host.\r
+* Do not lock against interrupts and multiple access.\r
+*\r
+* Parameters\r
+* BufferIndex Index of Down-buffer to be used (e.g. 0 for "Terminal").\r
+* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.\r
+* BufferSize Size of the target application buffer.\r
+*\r
+* Return value\r
+* Number of bytes that have been read.\r
+*/\r
+unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize) {\r
+ unsigned NumBytesRem;\r
+ unsigned NumBytesRead;\r
+ unsigned RdOff;\r
+ unsigned WrOff;\r
+ unsigned char* pBuffer;\r
+ SEGGER_RTT_BUFFER_DOWN* pRing;\r
+ //\r
+ INIT();\r
+ pRing = &_SEGGER_RTT.aDown[BufferIndex];\r
+ pBuffer = (unsigned char*)pData;\r
+ RdOff = pRing->RdOff;\r
+ WrOff = pRing->WrOff;\r
+ NumBytesRead = 0u;\r
+ //\r
+ // Read from current read position to wrap-around of buffer, first\r
+ //\r
+ if (RdOff > WrOff) {\r
+ NumBytesRem = pRing->SizeOfBuffer - RdOff;\r
+ NumBytesRem = MIN(NumBytesRem, BufferSize);\r
+ memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);\r
+ NumBytesRead += NumBytesRem;\r
+ pBuffer += NumBytesRem;\r
+ BufferSize -= NumBytesRem;\r
+ RdOff += NumBytesRem;\r
+ //\r
+ // Handle wrap-around of buffer\r
+ //\r
+ if (RdOff == pRing->SizeOfBuffer) {\r
+ RdOff = 0u;\r
+ }\r
+ }\r
+ //\r
+ // Read remaining items of buffer\r
+ //\r
+ NumBytesRem = WrOff - RdOff;\r
+ NumBytesRem = MIN(NumBytesRem, BufferSize);\r
+ if (NumBytesRem > 0u) {\r
+ memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);\r
+ NumBytesRead += NumBytesRem;\r
+ pBuffer += NumBytesRem;\r
+ BufferSize -= NumBytesRem;\r
+ RdOff += NumBytesRem;\r
+ }\r
+ if (NumBytesRead) {\r
+ pRing->RdOff = RdOff;\r
+ }\r
+ //\r
+ return NumBytesRead;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_Read\r
+*\r
+* Function description\r
+* Reads characters from SEGGER real-time-terminal control block\r
+* which have been previously stored by the host.\r
+*\r
+* Parameters\r
+* BufferIndex Index of Down-buffer to be used (e.g. 0 for "Terminal").\r
+* pBuffer Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.\r
+* BufferSize Size of the target application buffer.\r
+*\r
+* Return value\r
+* Number of bytes that have been read.\r
+*/\r
+unsigned SEGGER_RTT_Read(unsigned BufferIndex, void* pBuffer, unsigned BufferSize) {\r
+ unsigned NumBytesRead;\r
+ //\r
+ SEGGER_RTT_LOCK();\r
+ //\r
+ // Call the non-locking read function\r
+ //\r
+ NumBytesRead = SEGGER_RTT_ReadNoLock(BufferIndex, pBuffer, BufferSize);\r
+ //\r
+ // Finish up.\r
+ //\r
+ SEGGER_RTT_UNLOCK();\r
+ //\r
+ return NumBytesRead;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_WriteWithOverwriteNoLock\r
+*\r
+* Function description\r
+* Stores a specified number of characters in SEGGER RTT\r
+* control block.\r
+* SEGGER_RTT_WriteWithOverwriteNoLock does not lock the application \r
+* and overwrites data if the data does not fit into the buffer.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").\r
+* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.\r
+* NumBytes Number of bytes to be stored in the SEGGER RTT control block.\r
+*\r
+* Notes\r
+* (1) If there is not enough space in the "Up"-buffer, data is overwritten.\r
+* (2) For performance reasons this function does not call Init()\r
+* and may only be called after RTT has been initialized.\r
+* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.\r
+* (3) Do not use SEGGER_RTT_WriteWithOverwriteNoLock if a J-Link \r
+* connection reads RTT data.\r
+*/\r
+void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {\r
+ const char* pData;\r
+ SEGGER_RTT_BUFFER_UP* pRing;\r
+ unsigned Avail;\r
+\r
+ pData = (const char *)pBuffer;\r
+ //\r
+ // Get "to-host" ring buffer and copy some elements into local variables.\r
+ //\r
+ pRing = &_SEGGER_RTT.aUp[BufferIndex];\r
+ //\r
+ // Check if we will overwrite data and need to adjust the RdOff.\r
+ //\r
+ if (pRing->WrOff == pRing->RdOff) {\r
+ Avail = pRing->SizeOfBuffer - 1u;\r
+ } else if ( pRing->WrOff < pRing->RdOff) {\r
+ Avail = pRing->RdOff - pRing->WrOff - 1u;\r
+ } else {\r
+ Avail = pRing->RdOff - pRing->WrOff - 1u + pRing->SizeOfBuffer;\r
+ }\r
+ if (NumBytes > Avail) {\r
+ pRing->RdOff += (NumBytes - Avail);\r
+ while (pRing->RdOff >= pRing->SizeOfBuffer) {\r
+ pRing->RdOff -= pRing->SizeOfBuffer;\r
+ }\r
+ }\r
+ //\r
+ // Write all data, no need to check the RdOff, but possibly handle multiple wrap-arounds\r
+ //\r
+ Avail = pRing->SizeOfBuffer - pRing->WrOff;\r
+ do {\r
+ if (Avail > NumBytes) {\r
+ //\r
+ // Last round\r
+ //\r
+#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.\r
+ char* pDst;\r
+ pDst = pRing->pBuffer + pRing->WrOff;\r
+ pRing->WrOff += NumBytes;\r
+ do {\r
+ *pDst++ = *pData++;\r
+ } while (--NumBytes);\r
+#else\r
+ memcpy(pRing->pBuffer + WrOff, pData, NumBytes);\r
+ pRing->WrOff += NumBytes;\r
+#endif\r
+ break; //Alternatively: NumBytes = 0;\r
+ } else {\r
+ //\r
+ // Wrap-around necessary, write until wrap-around and reset WrOff\r
+ //\r
+ memcpy(pRing->pBuffer + pRing->WrOff, pData, Avail);\r
+ pData += Avail;\r
+ pRing->WrOff = 0;\r
+ NumBytes -= Avail;\r
+ Avail = (pRing->SizeOfBuffer - 1);\r
+ }\r
+ } while (NumBytes);\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_WriteSkipNoLock\r
+*\r
+* Function description\r
+* Stores a specified number of characters in SEGGER RTT\r
+* control block which is then read by the host.\r
+* SEGGER_RTT_WriteSkipNoLock does not lock the application and\r
+* skips all data, if the data does not fit into the buffer.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").\r
+* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.\r
+* NumBytes Number of bytes to be stored in the SEGGER RTT control block.\r
+*\r
+* Return value\r
+* Number of bytes which have been stored in the "Up"-buffer.\r
+*\r
+* Notes\r
+* (1) If there is not enough space in the "Up"-buffer, all data is dropped.\r
+* (2) For performance reasons this function does not call Init()\r
+* and may only be called after RTT has been initialized.\r
+* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.\r
+*/\r
+unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {\r
+ const char* pData;\r
+ SEGGER_RTT_BUFFER_UP* pRing;\r
+ unsigned Avail;\r
+ unsigned RdOff;\r
+ unsigned WrOff;\r
+ unsigned Rem;\r
+\r
+ pData = (const char *)pBuffer;\r
+ //\r
+ // Get "to-host" ring buffer and copy some elements into local variables.\r
+ //\r
+ pRing = &_SEGGER_RTT.aUp[BufferIndex];\r
+ RdOff = pRing->RdOff;\r
+ WrOff = pRing->WrOff;\r
+ //\r
+ // Handle the most common cases fastest.\r
+ // Which is:\r
+ // RdOff <= WrOff -> Space until wrap around is free.\r
+ // AND\r
+ // WrOff + NumBytes < SizeOfBuffer -> No Wrap around necessary.\r
+ //\r
+ // OR\r
+ //\r
+ // RdOff > WrOff -> Space until RdOff - 1 is free.\r
+ // AND\r
+ // WrOff + NumBytes < RdOff -> Data fits into buffer\r
+ //\r
+ if (RdOff <= WrOff) {\r
+ //\r
+ // Get space until WrOff will be at wrap around.\r
+ //\r
+ Avail = pRing->SizeOfBuffer - 1u - WrOff ;\r
+ if (Avail >= NumBytes) {\r
+#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.\r
+ char* pDst;\r
+ pDst = pRing->pBuffer + WrOff;\r
+ WrOff += NumBytes;\r
+ do {\r
+ *pDst++ = *pData++;\r
+ } while (--NumBytes);\r
+ pRing->WrOff = WrOff + NumBytes;\r
+#else\r
+ memcpy(pRing->pBuffer + WrOff, pData, NumBytes);\r
+ pRing->WrOff = WrOff + NumBytes;\r
+#endif\r
+ return 1;\r
+ }\r
+ //\r
+ // If data did not fit into space until wrap around calculate complete space in buffer.\r
+ //\r
+ Avail += RdOff;\r
+ //\r
+ // If there is still no space for the whole of this output, don't bother.\r
+ //\r
+ if (Avail >= NumBytes) {\r
+ //\r
+ // OK, we have enough space in buffer. Copy in one or 2 chunks\r
+ //\r
+ Rem = pRing->SizeOfBuffer - WrOff; // Space until end of buffer\r
+ if (Rem > NumBytes) {\r
+ memcpy(pRing->pBuffer + WrOff, pData, NumBytes);\r
+ pRing->WrOff = WrOff + NumBytes;\r
+ } else {\r
+ //\r
+ // We reach the end of the buffer, so need to wrap around\r
+ //\r
+ memcpy(pRing->pBuffer + WrOff, pData, Rem);\r
+ memcpy(pRing->pBuffer, pData + Rem, NumBytes - Rem);\r
+ pRing->WrOff = NumBytes - Rem;\r
+ }\r
+ return 1;\r
+ }\r
+ } else {\r
+ Avail = RdOff - WrOff - 1u;\r
+ if (Avail >= NumBytes) {\r
+ memcpy(pRing->pBuffer + WrOff, pData, NumBytes);\r
+ pRing->WrOff = WrOff + NumBytes;\r
+ return 1;\r
+ }\r
+ }\r
+ //\r
+ // If we reach this point no data has been written\r
+ //\r
+ return 0;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_WriteNoLock\r
+*\r
+* Function description\r
+* Stores a specified number of characters in SEGGER RTT\r
+* control block which is then read by the host.\r
+* SEGGER_RTT_WriteNoLock does not lock the application.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").\r
+* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.\r
+* NumBytes Number of bytes to be stored in the SEGGER RTT control block.\r
+*\r
+* Return value\r
+* Number of bytes which have been stored in the "Up"-buffer.\r
+*\r
+* Notes\r
+* (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.\r
+* (2) For performance reasons this function does not call Init()\r
+* and may only be called after RTT has been initialized.\r
+* Either by calling SEGGER_RTT_Init() or calling another RTT API function first.\r
+*/\r
+unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {\r
+ unsigned Status;\r
+ unsigned Avail;\r
+ const char* pData;\r
+ SEGGER_RTT_BUFFER_UP* pRing;\r
+\r
+ pData = (const char *)pBuffer;\r
+ //\r
+ // Get "to-host" ring buffer.\r
+ //\r
+ pRing = &_SEGGER_RTT.aUp[BufferIndex];\r
+ //\r
+ // How we output depends upon the mode...\r
+ //\r
+ switch (pRing->Flags) {\r
+ case SEGGER_RTT_MODE_NO_BLOCK_SKIP:\r
+ //\r
+ // If we are in skip mode and there is no space for the whole\r
+ // of this output, don't bother.\r
+ //\r
+ Avail = _GetAvailWriteSpace(pRing);\r
+ if (Avail < NumBytes) {\r
+ Status = 0u;\r
+ } else {\r
+ Status = NumBytes;\r
+ _WriteNoCheck(pRing, pData, NumBytes);\r
+ }\r
+ break;\r
+ case SEGGER_RTT_MODE_NO_BLOCK_TRIM:\r
+ //\r
+ // If we are in trim mode, trim to what we can output without blocking.\r
+ //\r
+ Avail = _GetAvailWriteSpace(pRing);\r
+ Status = Avail < NumBytes ? Avail : NumBytes;\r
+ _WriteNoCheck(pRing, pData, Status);\r
+ break;\r
+ case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:\r
+ //\r
+ // If we are in blocking mode, output everything.\r
+ //\r
+ Status = _WriteBlocking(pRing, pData, NumBytes);\r
+ break;\r
+ default:\r
+ Status = 0u;\r
+ break;\r
+ }\r
+ //\r
+ // Finish up.\r
+ //\r
+ return Status;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_Write\r
+*\r
+* Function description\r
+* Stores a specified number of characters in SEGGER RTT\r
+* control block which is then read by the host.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").\r
+* pBuffer Pointer to character array. Does not need to point to a \0 terminated string.\r
+* NumBytes Number of bytes to be stored in the SEGGER RTT control block.\r
+*\r
+* Return value\r
+* Number of bytes which have been stored in the "Up"-buffer.\r
+*\r
+* Notes\r
+* (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.\r
+*/\r
+unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {\r
+ unsigned Status;\r
+ //\r
+ INIT();\r
+ SEGGER_RTT_LOCK();\r
+ //\r
+ // Call the non-locking write function\r
+ //\r
+ Status = SEGGER_RTT_WriteNoLock(BufferIndex, pBuffer, NumBytes);\r
+ //\r
+ // Finish up.\r
+ //\r
+ SEGGER_RTT_UNLOCK();\r
+ //\r
+ return Status;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_WriteString\r
+*\r
+* Function description\r
+* Stores string in SEGGER RTT control block.\r
+* This data is read by the host.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal").\r
+* s Pointer to string.\r
+*\r
+* Return value\r
+* Number of bytes which have been stored in the "Up"-buffer.\r
+*\r
+* Notes\r
+* (1) If there is not enough space in the "Up"-buffer, depending on configuration,\r
+* remaining characters may be dropped or RTT module waits until there is more space in the buffer.\r
+* (2) String passed to this function has to be \0 terminated\r
+* (3) \0 termination character is *not* stored in RTT buffer\r
+*/\r
+unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) {\r
+ unsigned Len;\r
+\r
+ Len = STRLEN(s);\r
+ return SEGGER_RTT_Write(BufferIndex, s, Len);\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_GetKey\r
+*\r
+* Function description\r
+* Reads one character from the SEGGER RTT buffer.\r
+* Host has previously stored data there.\r
+*\r
+* Return value\r
+* < 0 - No character available (buffer empty).\r
+* >= 0 - Character which has been read. (Possible values: 0 - 255)\r
+*\r
+* Notes\r
+* (1) This function is only specified for accesses to RTT buffer 0.\r
+*/\r
+int SEGGER_RTT_GetKey(void) {\r
+ char c;\r
+ int r;\r
+\r
+ r = (int)SEGGER_RTT_Read(0u, &c, 1u);\r
+ if (r == 1) {\r
+ r = (int)(unsigned char)c;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_WaitKey\r
+*\r
+* Function description\r
+* Waits until at least one character is avaible in the SEGGER RTT buffer.\r
+* Once a character is available, it is read and this function returns.\r
+*\r
+* Return value\r
+* >=0 - Character which has been read.\r
+*\r
+* Notes\r
+* (1) This function is only specified for accesses to RTT buffer 0\r
+* (2) This function is blocking if no character is present in RTT buffer\r
+*/\r
+int SEGGER_RTT_WaitKey(void) {\r
+ int r;\r
+\r
+ do {\r
+ r = SEGGER_RTT_GetKey();\r
+ } while (r < 0);\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_HasKey\r
+*\r
+* Function description\r
+* Checks if at least one character for reading is available in the SEGGER RTT buffer.\r
+*\r
+* Return value\r
+* == 0 - No characters are available to read.\r
+* == 1 - At least one character is available.\r
+*\r
+* Notes\r
+* (1) This function is only specified for accesses to RTT buffer 0\r
+*/\r
+int SEGGER_RTT_HasKey(void) {\r
+ unsigned RdOff;\r
+ int r;\r
+\r
+ INIT();\r
+ RdOff = _SEGGER_RTT.aDown[0].RdOff;\r
+ if (RdOff != _SEGGER_RTT.aDown[0].WrOff) {\r
+ r = 1;\r
+ } else {\r
+ r = 0;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_HasData\r
+*\r
+* Function description\r
+* Check if there is data from the host in the given buffer.\r
+*\r
+* Return value:\r
+* ==0: No data\r
+* !=0: Data in buffer\r
+*\r
+*/\r
+unsigned SEGGER_RTT_HasData(unsigned BufferIndex) {\r
+ SEGGER_RTT_BUFFER_DOWN* pRing;\r
+ unsigned v;\r
+\r
+ pRing = &_SEGGER_RTT.aDown[BufferIndex];\r
+ v = pRing->WrOff;\r
+ return v - pRing->RdOff;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_AllocDownBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of the next down-buffer (H->T).\r
+* The next buffer, which is not used yet is configured.\r
+* This includes: Buffer address, size, name, flags, ...\r
+*\r
+* Parameters\r
+* sName Pointer to a constant name string.\r
+* pBuffer Pointer to a buffer to be used.\r
+* BufferSize Size of the buffer.\r
+* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).\r
+*\r
+* Return value\r
+* >= 0 - O.K. Buffer Index\r
+* < 0 - Error\r
+*/\r
+int SEGGER_RTT_AllocDownBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {\r
+ int BufferIndex;\r
+\r
+ INIT();\r
+ SEGGER_RTT_LOCK();\r
+ BufferIndex = 0;\r
+ do {\r
+ if (_SEGGER_RTT.aDown[BufferIndex].pBuffer == NULL) {\r
+ break;\r
+ }\r
+ BufferIndex++;\r
+ } while (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers);\r
+ if (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers) {\r
+ _SEGGER_RTT.aDown[BufferIndex].sName = sName;\r
+ _SEGGER_RTT.aDown[BufferIndex].pBuffer = (char*)pBuffer;\r
+ _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;\r
+ _SEGGER_RTT.aDown[BufferIndex].RdOff = 0u;\r
+ _SEGGER_RTT.aDown[BufferIndex].WrOff = 0u;\r
+ _SEGGER_RTT.aDown[BufferIndex].Flags = Flags;\r
+ } else {\r
+ BufferIndex = -1;\r
+ }\r
+ SEGGER_RTT_UNLOCK();\r
+ return BufferIndex;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_AllocUpBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of the next up-buffer (T->H).\r
+* The next buffer, which is not used yet is configured.\r
+* This includes: Buffer address, size, name, flags, ...\r
+*\r
+* Parameters\r
+* sName Pointer to a constant name string.\r
+* pBuffer Pointer to a buffer to be used.\r
+* BufferSize Size of the buffer.\r
+* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).\r
+*\r
+* Return value\r
+* >= 0 - O.K. Buffer Index\r
+* < 0 - Error\r
+*/\r
+int SEGGER_RTT_AllocUpBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {\r
+ int BufferIndex;\r
+\r
+ INIT();\r
+ SEGGER_RTT_LOCK();\r
+ BufferIndex = 0;\r
+ do {\r
+ if (_SEGGER_RTT.aUp[BufferIndex].pBuffer == NULL) {\r
+ break;\r
+ }\r
+ BufferIndex++;\r
+ } while (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers);\r
+ if (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers) {\r
+ _SEGGER_RTT.aUp[BufferIndex].sName = sName;\r
+ _SEGGER_RTT.aUp[BufferIndex].pBuffer = (char*)pBuffer;\r
+ _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;\r
+ _SEGGER_RTT.aUp[BufferIndex].RdOff = 0u;\r
+ _SEGGER_RTT.aUp[BufferIndex].WrOff = 0u;\r
+ _SEGGER_RTT.aUp[BufferIndex].Flags = Flags;\r
+ } else {\r
+ BufferIndex = -1;\r
+ }\r
+ SEGGER_RTT_UNLOCK();\r
+ return BufferIndex;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_ConfigUpBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of a specific up-buffer (T->H).\r
+* Buffer to be configured is specified by index.\r
+* This includes: Buffer address, size, name, flags, ...\r
+*\r
+* Parameters\r
+* BufferIndex Index of the buffer to configure.\r
+* sName Pointer to a constant name string.\r
+* pBuffer Pointer to a buffer to be used.\r
+* BufferSize Size of the buffer.\r
+* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).\r
+*\r
+* Return value\r
+* >= 0 - O.K.\r
+* < 0 - Error\r
+*\r
+* Additional information\r
+* Buffer 0 is configured on compile-time.\r
+* May only be called once per buffer.\r
+* Buffer name and flags can be reconfigured using the appropriate functions.\r
+*/\r
+int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {\r
+ int r;\r
+\r
+ INIT();\r
+ if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {\r
+ SEGGER_RTT_LOCK();\r
+ if (BufferIndex > 0u) {\r
+ _SEGGER_RTT.aUp[BufferIndex].sName = sName;\r
+ _SEGGER_RTT.aUp[BufferIndex].pBuffer = (char*)pBuffer;\r
+ _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;\r
+ _SEGGER_RTT.aUp[BufferIndex].RdOff = 0u;\r
+ _SEGGER_RTT.aUp[BufferIndex].WrOff = 0u;\r
+ }\r
+ _SEGGER_RTT.aUp[BufferIndex].Flags = Flags;\r
+ SEGGER_RTT_UNLOCK();\r
+ r = 0;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_ConfigDownBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of a specific down-buffer (H->T).\r
+* Buffer to be configured is specified by index.\r
+* This includes: Buffer address, size, name, flags, ...\r
+*\r
+* Parameters\r
+* BufferIndex Index of the buffer to configure.\r
+* sName Pointer to a constant name string.\r
+* pBuffer Pointer to a buffer to be used.\r
+* BufferSize Size of the buffer.\r
+* Flags Operating modes. Define behavior if buffer is full (not enough space for entire message).\r
+*\r
+* Return value\r
+* >= 0 O.K.\r
+* < 0 Error\r
+*\r
+* Additional information\r
+* Buffer 0 is configured on compile-time.\r
+* May only be called once per buffer.\r
+* Buffer name and flags can be reconfigured using the appropriate functions.\r
+*/\r
+int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {\r
+ int r;\r
+\r
+ INIT();\r
+ if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {\r
+ SEGGER_RTT_LOCK();\r
+ if (BufferIndex > 0u) {\r
+ _SEGGER_RTT.aDown[BufferIndex].sName = sName;\r
+ _SEGGER_RTT.aDown[BufferIndex].pBuffer = (char*)pBuffer;\r
+ _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;\r
+ _SEGGER_RTT.aDown[BufferIndex].RdOff = 0u;\r
+ _SEGGER_RTT.aDown[BufferIndex].WrOff = 0u;\r
+ }\r
+ _SEGGER_RTT.aDown[BufferIndex].Flags = Flags;\r
+ SEGGER_RTT_UNLOCK();\r
+ r = 0;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_SetNameUpBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of a specific up-buffer name (T->H).\r
+* Buffer to be configured is specified by index.\r
+*\r
+* Parameters\r
+* BufferIndex Index of the buffer to renamed.\r
+* sName Pointer to a constant name string.\r
+*\r
+* Return value\r
+* >= 0 O.K.\r
+* < 0 Error\r
+*/\r
+int SEGGER_RTT_SetNameUpBuffer(unsigned BufferIndex, const char* sName) {\r
+ int r;\r
+\r
+ INIT();\r
+ if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {\r
+ SEGGER_RTT_LOCK();\r
+ _SEGGER_RTT.aUp[BufferIndex].sName = sName;\r
+ SEGGER_RTT_UNLOCK();\r
+ r = 0;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_SetNameDownBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of a specific Down-buffer name (T->H).\r
+* Buffer to be configured is specified by index.\r
+*\r
+* Parameters\r
+* BufferIndex Index of the buffer to renamed.\r
+* sName Pointer to a constant name string.\r
+*\r
+* Return value\r
+* >= 0 O.K.\r
+* < 0 Error\r
+*/\r
+int SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName) {\r
+ int r;\r
+\r
+ INIT();\r
+ if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {\r
+ SEGGER_RTT_LOCK();\r
+ _SEGGER_RTT.aDown[BufferIndex].sName = sName;\r
+ SEGGER_RTT_UNLOCK();\r
+ r = 0;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_SetFlagsUpBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of specific up-buffer flags (T->H).\r
+* Buffer to be configured is specified by index.\r
+*\r
+* Parameters\r
+* BufferIndex Index of the buffer.\r
+* Flags Flags to set for the buffer.\r
+*\r
+* Return value\r
+* >= 0 O.K.\r
+* < 0 Error\r
+*/\r
+int SEGGER_RTT_SetFlagsUpBuffer(unsigned BufferIndex, unsigned Flags) {\r
+ int r;\r
+\r
+ INIT();\r
+ if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {\r
+ SEGGER_RTT_LOCK();\r
+ _SEGGER_RTT.aUp[BufferIndex].Flags = Flags;\r
+ SEGGER_RTT_UNLOCK();\r
+ r = 0;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_SetFlagsDownBuffer\r
+*\r
+* Function description\r
+* Run-time configuration of specific Down-buffer flags (T->H).\r
+* Buffer to be configured is specified by index.\r
+*\r
+* Parameters\r
+* BufferIndex Index of the buffer to renamed.\r
+* Flags Flags to set for the buffer.\r
+*\r
+* Return value\r
+* >= 0 O.K.\r
+* < 0 Error\r
+*/\r
+int SEGGER_RTT_SetFlagsDownBuffer(unsigned BufferIndex, unsigned Flags) {\r
+ int r;\r
+\r
+ INIT();\r
+ if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {\r
+ SEGGER_RTT_LOCK();\r
+ _SEGGER_RTT.aDown[BufferIndex].Flags = Flags;\r
+ SEGGER_RTT_UNLOCK();\r
+ r = 0;\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_Init\r
+*\r
+* Function description\r
+* Initializes the RTT Control Block.\r
+* Should be used in RAM targets, at start of the application.\r
+*\r
+*/\r
+void SEGGER_RTT_Init (void) {\r
+ _DoInit();\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_SetTerminal\r
+*\r
+* Function description\r
+* Sets the terminal to be used for output on channel 0.\r
+*\r
+* Parameters\r
+* TerminalId Index of the terminal.\r
+*\r
+* Return value\r
+* >= 0 O.K.\r
+* < 0 Error (e.g. if RTT is configured for non-blocking mode and there was no space in the buffer to set the new terminal Id)\r
+*/\r
+int SEGGER_RTT_SetTerminal (char TerminalId) {\r
+ char ac[2];\r
+ SEGGER_RTT_BUFFER_UP* pRing;\r
+ unsigned Avail;\r
+ int r;\r
+ //\r
+ INIT();\r
+ //\r
+ r = 0;\r
+ ac[0] = 0xFFU;\r
+ if ((unsigned char)TerminalId < (unsigned char)sizeof(_aTerminalId)) { // We only support a certain number of channels\r
+ ac[1] = _aTerminalId[(unsigned char)TerminalId];\r
+ pRing = &_SEGGER_RTT.aUp[0]; // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed\r
+ SEGGER_RTT_LOCK(); // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing\r
+ if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {\r
+ _ActiveTerminal = TerminalId;\r
+ _WriteBlocking(pRing, ac, 2u);\r
+ } else { // Skipping mode or trim mode? => We cannot trim this command so handling is the same for both modes\r
+ Avail = _GetAvailWriteSpace(pRing);\r
+ if (Avail >= 2) {\r
+ _ActiveTerminal = TerminalId; // Only change active terminal in case of success\r
+ _WriteNoCheck(pRing, ac, 2u);\r
+ } else {\r
+ r = -1;\r
+ }\r
+ }\r
+ SEGGER_RTT_UNLOCK();\r
+ } else {\r
+ r = -1;\r
+ }\r
+ return r;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_TerminalOut\r
+*\r
+* Function description\r
+* Writes a string to the given terminal\r
+* without changing the terminal for channel 0.\r
+*\r
+* Parameters\r
+* TerminalId Index of the terminal.\r
+* s String to be printed on the terminal.\r
+*\r
+* Return value\r
+* >= 0 - Number of bytes written.\r
+* < 0 - Error.\r
+*\r
+*/\r
+int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {\r
+ int Status;\r
+ unsigned FragLen;\r
+ unsigned Avail;\r
+ SEGGER_RTT_BUFFER_UP* pRing;\r
+ //\r
+ INIT();\r
+ //\r
+ // Validate terminal ID.\r
+ //\r
+ if (TerminalId < (char)sizeof(_aTerminalId)) { // We only support a certain number of channels\r
+ //\r
+ // Get "to-host" ring buffer.\r
+ //\r
+ pRing = &_SEGGER_RTT.aUp[0];\r
+ //\r
+ // Need to be able to change terminal, write data, change back.\r
+ // Compute the fixed and variable sizes.\r
+ //\r
+ FragLen = strlen(s);\r
+ //\r
+ // How we output depends upon the mode...\r
+ //\r
+ SEGGER_RTT_LOCK();\r
+ Avail = _GetAvailWriteSpace(pRing);\r
+ switch (pRing->Flags & SEGGER_RTT_MODE_MASK) {\r
+ case SEGGER_RTT_MODE_NO_BLOCK_SKIP:\r
+ //\r
+ // If we are in skip mode and there is no space for the whole\r
+ // of this output, don't bother switching terminals at all.\r
+ //\r
+ if (Avail < (FragLen + 4u)) {\r
+ Status = 0;\r
+ } else {\r
+ _PostTerminalSwitch(pRing, TerminalId);\r
+ Status = (int)_WriteBlocking(pRing, s, FragLen);\r
+ _PostTerminalSwitch(pRing, _ActiveTerminal);\r
+ }\r
+ break;\r
+ case SEGGER_RTT_MODE_NO_BLOCK_TRIM:\r
+ //\r
+ // If we are in trim mode and there is not enough space for everything,\r
+ // trim the output but always include the terminal switch. If no room\r
+ // for terminal switch, skip that totally.\r
+ //\r
+ if (Avail < 4u) {\r
+ Status = -1;\r
+ } else {\r
+ _PostTerminalSwitch(pRing, TerminalId);\r
+ Status = (int)_WriteBlocking(pRing, s, (FragLen < (Avail - 4u)) ? FragLen : (Avail - 4u));\r
+ _PostTerminalSwitch(pRing, _ActiveTerminal);\r
+ }\r
+ break;\r
+ case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:\r
+ //\r
+ // If we are in blocking mode, output everything.\r
+ //\r
+ _PostTerminalSwitch(pRing, TerminalId);\r
+ Status = (int)_WriteBlocking(pRing, s, FragLen);\r
+ _PostTerminalSwitch(pRing, _ActiveTerminal);\r
+ break;\r
+ default:\r
+ Status = -1;\r
+ break;\r
+ }\r
+ //\r
+ // Finish up.\r
+ //\r
+ SEGGER_RTT_UNLOCK();\r
+ } else {\r
+ Status = -1;\r
+ }\r
+ return Status;\r
+}\r
+\r
+\r
+/*************************** End of file ****************************/\r
--- /dev/null
+/*********************************************************************\r
+* SEGGER MICROCONTROLLER GmbH & Co. KG *\r
+* Solutions for real time microcontroller applications *\r
+**********************************************************************\r
+* *\r
+* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *\r
+* *\r
+* www.segger.com Support: support@segger.com *\r
+* *\r
+**********************************************************************\r
+* *\r
+* SEGGER RTT * Real Time Transfer for embedded targets *\r
+* *\r
+**********************************************************************\r
+* *\r
+* All rights reserved. *\r
+* *\r
+* * This software may in its unmodified form be freely redistributed *\r
+* in source, linkable, or executable form. *\r
+* * The source code may be modified, provided the source code *\r
+* retains the above copyright notice, this list of conditions and *\r
+* the following disclaimer. *\r
+* * Modified versions of this software in source, executable, or *\r
+* linkable form may not be distributed without prior consent of *\r
+* SEGGER. *\r
+* * This software may only be used for communication with SEGGER *\r
+* J-Link debug probes. *\r
+* *\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *\r
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *\r
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *\r
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *\r
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *\r
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *\r
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *\r
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *\r
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *\r
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *\r
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *\r
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *\r
+* DAMAGE. *\r
+* *\r
+**********************************************************************\r
+* *\r
+* RTT version: 6.00e *\r
+* *\r
+**********************************************************************\r
+---------------------------END-OF-HEADER------------------------------\r
+File : SEGGER_RTT_printf.c\r
+Purpose : Replacement for printf to write formatted data via RTT\r
+Revision: $Rev: 3667 $\r
+----------------------------------------------------------------------\r
+*/\r
+#include "SEGGER_RTT.h"\r
+#include "SEGGER_RTT_Conf.h"\r
+\r
+/*********************************************************************\r
+*\r
+* Defines, configurable\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE\r
+ #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64)\r
+#endif\r
+\r
+#include <stdlib.h>\r
+#include <stdarg.h>\r
+\r
+\r
+#define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0)\r
+#define FORMAT_FLAG_PAD_ZERO (1u << 1)\r
+#define FORMAT_FLAG_PRINT_SIGN (1u << 2)\r
+#define FORMAT_FLAG_ALTERNATE (1u << 3)\r
+\r
+/*********************************************************************\r
+*\r
+* Types\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+typedef struct {\r
+ char* pBuffer;\r
+ unsigned BufferSize;\r
+ unsigned Cnt;\r
+\r
+ int ReturnValue;\r
+\r
+ unsigned RTTBufferIndex;\r
+} SEGGER_RTT_PRINTF_DESC;\r
+\r
+/*********************************************************************\r
+*\r
+* Function prototypes\r
+*\r
+**********************************************************************\r
+*/\r
+int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);\r
+\r
+/*********************************************************************\r
+*\r
+* Static code\r
+*\r
+**********************************************************************\r
+*/\r
+/*********************************************************************\r
+*\r
+* _StoreChar\r
+*/\r
+static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) {\r
+ unsigned Cnt;\r
+\r
+ Cnt = p->Cnt;\r
+ if ((Cnt + 1u) <= p->BufferSize) {\r
+ *(p->pBuffer + Cnt) = c;\r
+ p->Cnt = Cnt + 1u;\r
+ p->ReturnValue++;\r
+ }\r
+ //\r
+ // Write part of string, when the buffer is full\r
+ //\r
+ if (p->Cnt == p->BufferSize) {\r
+ if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) {\r
+ p->ReturnValue = -1;\r
+ } else {\r
+ p->Cnt = 0u;\r
+ }\r
+ }\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* _PrintUnsigned\r
+*/\r
+static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {\r
+ static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\r
+ unsigned Div;\r
+ unsigned Digit;\r
+ unsigned Number;\r
+ unsigned Width;\r
+ char c;\r
+\r
+ Number = v;\r
+ Digit = 1u;\r
+ //\r
+ // Get actual field width\r
+ //\r
+ Width = 1u;\r
+ while (Number >= Base) {\r
+ Number = (Number / Base);\r
+ Width++;\r
+ }\r
+ if (NumDigits > Width) {\r
+ Width = NumDigits;\r
+ }\r
+ //\r
+ // Print leading chars if necessary\r
+ //\r
+ if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {\r
+ if (FieldWidth != 0u) {\r
+ if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {\r
+ c = '0';\r
+ } else {\r
+ c = ' ';\r
+ }\r
+ while ((FieldWidth != 0u) && (Width < FieldWidth)) {\r
+ FieldWidth--;\r
+ _StoreChar(pBufferDesc, c);\r
+ if (pBufferDesc->ReturnValue < 0) {\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (pBufferDesc->ReturnValue >= 0) {\r
+ //\r
+ // Compute Digit.\r
+ // Loop until Digit has the value of the highest digit required.\r
+ // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.\r
+ //\r
+ while (1) {\r
+ if (NumDigits > 1u) { // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned)\r
+ NumDigits--;\r
+ } else {\r
+ Div = v / Digit;\r
+ if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done\r
+ break;\r
+ }\r
+ }\r
+ Digit *= Base;\r
+ }\r
+ //\r
+ // Output digits\r
+ //\r
+ do {\r
+ Div = v / Digit;\r
+ v -= Div * Digit;\r
+ _StoreChar(pBufferDesc, _aV2C[Div]);\r
+ if (pBufferDesc->ReturnValue < 0) {\r
+ break;\r
+ }\r
+ Digit /= Base;\r
+ } while (Digit);\r
+ //\r
+ // Print trailing spaces if necessary\r
+ //\r
+ if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {\r
+ if (FieldWidth != 0u) {\r
+ while ((FieldWidth != 0u) && (Width < FieldWidth)) {\r
+ FieldWidth--;\r
+ _StoreChar(pBufferDesc, ' ');\r
+ if (pBufferDesc->ReturnValue < 0) {\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* _PrintInt\r
+*/\r
+static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {\r
+ unsigned Width;\r
+ int Number;\r
+\r
+ Number = (v < 0) ? -v : v;\r
+\r
+ //\r
+ // Get actual field width\r
+ //\r
+ Width = 1u;\r
+ while (Number >= (int)Base) {\r
+ Number = (Number / (int)Base);\r
+ Width++;\r
+ }\r
+ if (NumDigits > Width) {\r
+ Width = NumDigits;\r
+ }\r
+ if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {\r
+ FieldWidth--;\r
+ }\r
+\r
+ //\r
+ // Print leading spaces if necessary\r
+ //\r
+ if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {\r
+ if (FieldWidth != 0u) {\r
+ while ((FieldWidth != 0u) && (Width < FieldWidth)) {\r
+ FieldWidth--;\r
+ _StoreChar(pBufferDesc, ' ');\r
+ if (pBufferDesc->ReturnValue < 0) {\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ //\r
+ // Print sign if necessary\r
+ //\r
+ if (pBufferDesc->ReturnValue >= 0) {\r
+ if (v < 0) {\r
+ v = -v;\r
+ _StoreChar(pBufferDesc, '-');\r
+ } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {\r
+ _StoreChar(pBufferDesc, '+');\r
+ } else {\r
+\r
+ }\r
+ if (pBufferDesc->ReturnValue >= 0) {\r
+ //\r
+ // Print leading zeros if necessary\r
+ //\r
+ if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {\r
+ if (FieldWidth != 0u) {\r
+ while ((FieldWidth != 0u) && (Width < FieldWidth)) {\r
+ FieldWidth--;\r
+ _StoreChar(pBufferDesc, '0');\r
+ if (pBufferDesc->ReturnValue < 0) {\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if (pBufferDesc->ReturnValue >= 0) {\r
+ //\r
+ // Print number without sign\r
+ //\r
+ _PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* Public code\r
+*\r
+**********************************************************************\r
+*/\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_vprintf\r
+*\r
+* Function description\r
+* Stores a formatted string in SEGGER RTT control block.\r
+* This data is read by the host.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")\r
+* sFormat Pointer to format string\r
+* pParamList Pointer to the list of arguments for the format string\r
+*\r
+* Return values\r
+* >= 0: Number of bytes which have been stored in the "Up"-buffer.\r
+* < 0: Error\r
+*/\r
+int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) {\r
+ char c;\r
+ SEGGER_RTT_PRINTF_DESC BufferDesc;\r
+ int v;\r
+ unsigned NumDigits;\r
+ unsigned FormatFlags;\r
+ unsigned FieldWidth;\r
+ char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE];\r
+\r
+ BufferDesc.pBuffer = acBuffer;\r
+ BufferDesc.BufferSize = SEGGER_RTT_PRINTF_BUFFER_SIZE;\r
+ BufferDesc.Cnt = 0u;\r
+ BufferDesc.RTTBufferIndex = BufferIndex;\r
+ BufferDesc.ReturnValue = 0;\r
+\r
+ do {\r
+ c = *sFormat;\r
+ sFormat++;\r
+ if (c == 0u) {\r
+ break;\r
+ }\r
+ if (c == '%') {\r
+ //\r
+ // Filter out flags\r
+ //\r
+ FormatFlags = 0u;\r
+ v = 1;\r
+ do {\r
+ c = *sFormat;\r
+ switch (c) {\r
+ case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;\r
+ case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break;\r
+ case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break;\r
+ case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break;\r
+ default: v = 0; break;\r
+ }\r
+ } while (v);\r
+ //\r
+ // filter out field with\r
+ //\r
+ FieldWidth = 0u;\r
+ do {\r
+ c = *sFormat;\r
+ if ((c < '0') || (c > '9')) {\r
+ break;\r
+ }\r
+ sFormat++;\r
+ FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0');\r
+ } while (1);\r
+\r
+ //\r
+ // Filter out precision (number of digits to display)\r
+ //\r
+ NumDigits = 0u;\r
+ c = *sFormat;\r
+ if (c == '.') {\r
+ sFormat++;\r
+ do {\r
+ c = *sFormat;\r
+ if ((c < '0') || (c > '9')) {\r
+ break;\r
+ }\r
+ sFormat++;\r
+ NumDigits = NumDigits * 10u + ((unsigned)c - '0');\r
+ } while (1);\r
+ }\r
+ //\r
+ // Filter out length modifier\r
+ //\r
+ c = *sFormat;\r
+ do {\r
+ if ((c == 'l') || (c == 'h')) {\r
+ sFormat++;\r
+ c = *sFormat;\r
+ } else {\r
+ break;\r
+ }\r
+ } while (1);\r
+ //\r
+ // Handle specifiers\r
+ //\r
+ switch (c) {\r
+ case 'c': {\r
+ char c0;\r
+ v = va_arg(*pParamList, int);\r
+ c0 = (char)v;\r
+ _StoreChar(&BufferDesc, c0);\r
+ break;\r
+ }\r
+ case 'd':\r
+ v = va_arg(*pParamList, int);\r
+ _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);\r
+ break;\r
+ case 'u':\r
+ v = va_arg(*pParamList, int);\r
+ _PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags);\r
+ break;\r
+ case 'x':\r
+ case 'X':\r
+ v = va_arg(*pParamList, int);\r
+ _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags);\r
+ break;\r
+ case 's':\r
+ {\r
+ const char * s = va_arg(*pParamList, const char *);\r
+ do {\r
+ c = *s;\r
+ s++;\r
+ if (c == '\0') {\r
+ break;\r
+ }\r
+ _StoreChar(&BufferDesc, c);\r
+ } while (BufferDesc.ReturnValue >= 0);\r
+ }\r
+ break;\r
+ case 'p':\r
+ v = va_arg(*pParamList, int);\r
+ _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u);\r
+ break;\r
+ case '%':\r
+ _StoreChar(&BufferDesc, '%');\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ sFormat++;\r
+ } else {\r
+ _StoreChar(&BufferDesc, c);\r
+ }\r
+ } while (BufferDesc.ReturnValue >= 0);\r
+\r
+ if (BufferDesc.ReturnValue > 0) {\r
+ //\r
+ // Write remaining data, if any\r
+ //\r
+ if (BufferDesc.Cnt != 0u) {\r
+ SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt);\r
+ }\r
+ BufferDesc.ReturnValue += (int)BufferDesc.Cnt;\r
+ }\r
+ return BufferDesc.ReturnValue;\r
+}\r
+\r
+/*********************************************************************\r
+*\r
+* SEGGER_RTT_printf\r
+*\r
+* Function description\r
+* Stores a formatted string in SEGGER RTT control block.\r
+* This data is read by the host.\r
+*\r
+* Parameters\r
+* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")\r
+* sFormat Pointer to format string, followed by the arguments for conversion\r
+*\r
+* Return values\r
+* >= 0: Number of bytes which have been stored in the "Up"-buffer.\r
+* < 0: Error\r
+*\r
+* Notes\r
+* (1) Conversion specifications have following syntax:\r
+* %[flags][FieldWidth][.Precision]ConversionSpecifier\r
+* (2) Supported flags:\r
+* -: Left justify within the field width\r
+* +: Always print sign extension for signed conversions\r
+* 0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision\r
+* Supported conversion specifiers:\r
+* c: Print the argument as one char\r
+* d: Print the argument as a signed integer\r
+* u: Print the argument as an unsigned integer\r
+* x: Print the argument as an hexadecimal integer\r
+* s: Print the string pointed to by the argument\r
+* p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.)\r
+*/\r
+int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) {\r
+ int r;\r
+ va_list ParamList;\r
+\r
+ va_start(ParamList, sFormat);\r
+ r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList);\r
+ va_end(ParamList);\r
+ return r;\r
+}\r
+/*************************** End of file ****************************/\r
--- /dev/null
+/*********************************************************************\r
+* SEGGER MICROCONTROLLER GmbH & Co. KG *\r
+* Solutions for real time microcontroller applications *\r
+**********************************************************************\r
+* *\r
+* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *\r
+* *\r
+* www.segger.com Support: support@segger.com *\r
+* *\r
+**********************************************************************\r
+* *\r
+* SEGGER RTT * Real Time Transfer for embedded targets *\r
+* *\r
+**********************************************************************\r
+* *\r
+* All rights reserved. *\r
+* *\r
+* * This software may in its unmodified form be freely redistributed *\r
+* in source, linkable, or executable form. *\r
+* * The source code may be modified, provided the source code *\r
+* retains the above copyright notice, this list of conditions and *\r
+* the following disclaimer. *\r
+* * Modified versions of this software in source, executable, or *\r
+* linkable form may not be distributed without prior consent of *\r
+* SEGGER. *\r
+* * This software may only be used for communication with SEGGER *\r
+* J-Link debug probes. *\r
+* *\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *\r
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *\r
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *\r
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *\r
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *\r
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *\r
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *\r
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *\r
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *\r
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *\r
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *\r
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *\r
+* DAMAGE. *\r
+* *\r
+**********************************************************************\r
+* *\r
+* RTT version: 6.00e *\r
+* *\r
+**********************************************************************\r
+---------------------------END-OF-HEADER------------------------------\r
+File : SEGGER_RTT.h\r
+Purpose : Implementation of SEGGER real-time transfer which allows\r
+ real-time communication on targets which support debugger \r
+ memory accesses while the CPU is running.\r
+Revision: $Rev: 4079 $\r
+----------------------------------------------------------------------\r
+*/\r
+\r
+#ifndef SEGGER_RTT_H\r
+#define SEGGER_RTT_H\r
+\r
+#include "SEGGER_RTT_Conf.h"\r
+\r
+/*********************************************************************\r
+*\r
+* Defines, fixed\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+/*********************************************************************\r
+*\r
+* Types\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+//\r
+// Description for a circular buffer (also called "ring buffer")\r
+// which is used as up-buffer (T->H)\r
+//\r
+typedef struct {\r
+ const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"\r
+ char* pBuffer; // Pointer to start of buffer\r
+ unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.\r
+ unsigned WrOff; // Position of next item to be written by either target.\r
+ volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.\r
+ unsigned Flags; // Contains configuration flags\r
+} SEGGER_RTT_BUFFER_UP;\r
+\r
+//\r
+// Description for a circular buffer (also called "ring buffer")\r
+// which is used as down-buffer (H->T)\r
+//\r
+typedef struct {\r
+ const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"\r
+ char* pBuffer; // Pointer to start of buffer\r
+ unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.\r
+ volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.\r
+ unsigned RdOff; // Position of next item to be read by target (down-buffer).\r
+ unsigned Flags; // Contains configuration flags\r
+} SEGGER_RTT_BUFFER_DOWN;\r
+\r
+//\r
+// RTT control block which describes the number of buffers available\r
+// as well as the configuration for each buffer\r
+//\r
+//\r
+typedef struct {\r
+ char acID[16]; // Initialized to "SEGGER RTT"\r
+ int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)\r
+ int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)\r
+ SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host\r
+ SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target\r
+} SEGGER_RTT_CB;\r
+\r
+/*********************************************************************\r
+*\r
+* Global data\r
+*\r
+**********************************************************************\r
+*/\r
+extern SEGGER_RTT_CB _SEGGER_RTT;\r
+\r
+/*********************************************************************\r
+*\r
+* RTT API functions\r
+*\r
+**********************************************************************\r
+*/\r
+#ifdef __cplusplus\r
+ extern "C" {\r
+#endif\r
+int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);\r
+int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);\r
+int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);\r
+int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);\r
+int SEGGER_RTT_GetKey (void);\r
+unsigned SEGGER_RTT_HasData (unsigned BufferIndex);\r
+int SEGGER_RTT_HasKey (void);\r
+void SEGGER_RTT_Init (void);\r
+unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);\r
+unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);\r
+int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);\r
+int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);\r
+int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);\r
+int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);\r
+int SEGGER_RTT_WaitKey (void);\r
+unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);\r
+unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);\r
+unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);\r
+unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);\r
+void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);\r
+//\r
+// Function macro for performance optimization\r
+//\r
+#define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)\r
+\r
+/*********************************************************************\r
+*\r
+* RTT "Terminal" API functions\r
+*\r
+**********************************************************************\r
+*/\r
+int SEGGER_RTT_SetTerminal (char TerminalId);\r
+int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);\r
+\r
+/*********************************************************************\r
+*\r
+* RTT printf functions (require SEGGER_RTT_printf.c)\r
+*\r
+**********************************************************************\r
+*/\r
+int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);\r
+#ifdef __cplusplus\r
+ }\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* Defines\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+//\r
+// Operating modes. Define behavior if buffer is full (not enough space for entire message)\r
+//\r
+#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default)\r
+#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits.\r
+#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer.\r
+#define SEGGER_RTT_MODE_MASK (3U)\r
+\r
+//\r
+// Control sequences, based on ANSI.\r
+// Can be used to control color, and clear the screen\r
+//\r
+#define RTT_CTRL_RESET "\e[0m" // Reset to default colors\r
+#define RTT_CTRL_CLEAR "\e[2J" // Clear screen, reposition cursor to top left\r
+\r
+#define RTT_CTRL_TEXT_BLACK "\e[2;30m"\r
+#define RTT_CTRL_TEXT_RED "\e[2;31m"\r
+#define RTT_CTRL_TEXT_GREEN "\e[2;32m"\r
+#define RTT_CTRL_TEXT_YELLOW "\e[2;33m"\r
+#define RTT_CTRL_TEXT_BLUE "\e[2;34m"\r
+#define RTT_CTRL_TEXT_MAGENTA "\e[2;35m"\r
+#define RTT_CTRL_TEXT_CYAN "\e[2;36m"\r
+#define RTT_CTRL_TEXT_WHITE "\e[2;37m"\r
+\r
+#define RTT_CTRL_TEXT_BRIGHT_BLACK "\e[1;30m"\r
+#define RTT_CTRL_TEXT_BRIGHT_RED "\e[1;31m"\r
+#define RTT_CTRL_TEXT_BRIGHT_GREEN "\e[1;32m"\r
+#define RTT_CTRL_TEXT_BRIGHT_YELLOW "\e[1;33m"\r
+#define RTT_CTRL_TEXT_BRIGHT_BLUE "\e[1;34m"\r
+#define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\e[1;35m"\r
+#define RTT_CTRL_TEXT_BRIGHT_CYAN "\e[1;36m"\r
+#define RTT_CTRL_TEXT_BRIGHT_WHITE "\e[1;37m"\r
+\r
+#define RTT_CTRL_BG_BLACK "\e[24;40m"\r
+#define RTT_CTRL_BG_RED "\e[24;41m"\r
+#define RTT_CTRL_BG_GREEN "\e[24;42m"\r
+#define RTT_CTRL_BG_YELLOW "\e[24;43m"\r
+#define RTT_CTRL_BG_BLUE "\e[24;44m"\r
+#define RTT_CTRL_BG_MAGENTA "\e[24;45m"\r
+#define RTT_CTRL_BG_CYAN "\e[24;46m"\r
+#define RTT_CTRL_BG_WHITE "\e[24;47m"\r
+\r
+#define RTT_CTRL_BG_BRIGHT_BLACK "\e[4;40m"\r
+#define RTT_CTRL_BG_BRIGHT_RED "\e[4;41m"\r
+#define RTT_CTRL_BG_BRIGHT_GREEN "\e[4;42m"\r
+#define RTT_CTRL_BG_BRIGHT_YELLOW "\e[4;43m"\r
+#define RTT_CTRL_BG_BRIGHT_BLUE "\e[4;44m"\r
+#define RTT_CTRL_BG_BRIGHT_MAGENTA "\e[4;45m"\r
+#define RTT_CTRL_BG_BRIGHT_CYAN "\e[4;46m"\r
+#define RTT_CTRL_BG_BRIGHT_WHITE "\e[4;47m"\r
+\r
+\r
+#endif\r
+\r
+/*************************** End of file ****************************/\r
--- /dev/null
+/*********************************************************************\r
+* SEGGER MICROCONTROLLER GmbH & Co. KG *\r
+* Solutions for real time microcontroller applications *\r
+**********************************************************************\r
+* *\r
+* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *\r
+* *\r
+* www.segger.com Support: support@segger.com *\r
+* *\r
+**********************************************************************\r
+* *\r
+* SEGGER RTT * Real Time Transfer for embedded targets *\r
+* *\r
+**********************************************************************\r
+* *\r
+* All rights reserved. *\r
+* *\r
+* * This software may in its unmodified form be freely redistributed *\r
+* in source, linkable, or executable form. *\r
+* * The source code may be modified, provided the source code *\r
+* retains the above copyright notice, this list of conditions and *\r
+* the following disclaimer. *\r
+* * Modified versions of this software in source, executable, or *\r
+* linkable form may not be distributed without prior consent of *\r
+* SEGGER. *\r
+* * This software may only be used for communication with SEGGER *\r
+* J-Link debug probes. *\r
+* *\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *\r
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *\r
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *\r
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *\r
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *\r
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *\r
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *\r
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *\r
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *\r
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *\r
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *\r
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *\r
+* DAMAGE. *\r
+* *\r
+**********************************************************************\r
+* *\r
+* RTT version: 6.00e *\r
+* *\r
+**********************************************************************\r
+----------------------------------------------------------------------\r
+File : SEGGER_RTT_Conf.h\r
+Purpose : Implementation of SEGGER real-time transfer (RTT) which \r
+ allows real-time communication on targets which support \r
+ debugger memory accesses while the CPU is running.\r
+Revision: $Rev: 3892 $\r
+---------------------------END-OF-HEADER------------------------------\r
+*/\r
+\r
+#ifndef SEGGER_RTT_CONF_H\r
+#define SEGGER_RTT_CONF_H\r
+\r
+#ifdef __IAR_SYSTEMS_ICC__\r
+ #include <intrinsics.h>\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* Defines, configurable\r
+*\r
+**********************************************************************\r
+*/\r
+\r
+#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)\r
+#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)\r
+\r
+#define BUFFER_SIZE_UP (64) // Size of the buffer for terminal output of target, up to host (Default: 1k)\r
+#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)\r
+\r
+#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)\r
+\r
+#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)\r
+\r
+//\r
+// Target is not allowed to perform other RTT operations while string still has not been stored completely.\r
+// Otherwise we would probably end up with a mixed string in the buffer.\r
+// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.\r
+// \r
+// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.\r
+// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.\r
+// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.\r
+// (Higher priority = lower priority number)\r
+// Default value for embOS: 128u\r
+// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )\r
+// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC\r
+// or define SEGGER_RTT_LOCK() to completely disable interrupts.\r
+// \r
+\r
+#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)\r
+\r
+/*********************************************************************\r
+*\r
+* RTT lock configuration for SEGGER Embedded Studio, \r
+* Rowley CrossStudio and GCC\r
+*/\r
+#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)\r
+ #ifdef __ARM_ARCH_6M__\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ __asm volatile ("mrs %0, primask \n\t" \\r
+ "mov r1, $1 \n\t" \\r
+ "msr primask, r1 \n\t" \\r
+ : "=r" (LockState) \\r
+ : \\r
+ : "r1" \\r
+ ); \r
+ \r
+ #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \\r
+ : \\r
+ : "r" (LockState) \\r
+ : \\r
+ ); \\r
+ } \r
+ \r
+ #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))\r
+ #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY\r
+ #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)\r
+ #endif\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ __asm volatile ("mrs %0, basepri \n\t" \\r
+ "mov r1, %1 \n\t" \\r
+ "msr basepri, r1 \n\t" \\r
+ : "=r" (LockState) \\r
+ : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \\r
+ : "r1" \\r
+ ); \r
+ \r
+ #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \\r
+ : \\r
+ : "r" (LockState) \\r
+ : \\r
+ ); \\r
+ }\r
+ \r
+ #elif defined(__ARM_ARCH_7A__)\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ __asm volatile ("mrs r1, CPSR \n\t" \\r
+ "mov %0, r1 \n\t" \\r
+ "orr r1, r1, #0xC0 \n\t" \\r
+ "msr CPSR_c, r1 \n\t" \\r
+ : "=r" (LockState) \\r
+ : \\r
+ : "r1" \\r
+ );\r
+\r
+ #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \\r
+ "mrs r1, CPSR \n\t" \\r
+ "bic r1, r1, #0xC0 \n\t" \\r
+ "and r0, r0, #0xC0 \n\t" \\r
+ "orr r1, r1, r0 \n\t" \\r
+ "msr CPSR_c, r1 \n\t" \\r
+ : \\r
+ : "r" (LockState) \\r
+ : "r0", "r1" \\r
+ ); \\r
+ }\r
+#else\r
+ #define SEGGER_RTT_LOCK() \r
+ #define SEGGER_RTT_UNLOCK()\r
+ #endif\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* RTT lock configuration for IAR EWARM\r
+*/\r
+#ifdef __ICCARM__\r
+ #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ LockState = __get_PRIMASK(); \\r
+ __set_PRIMASK(1); \r
+ \r
+ #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \\r
+ }\r
+ #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))\r
+ #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY\r
+ #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)\r
+ #endif\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ LockState = __get_BASEPRI(); \\r
+ __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); \r
+ \r
+ #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \\r
+ } \r
+ #endif\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* RTT lock configuration for IAR RX\r
+*/\r
+#ifdef __ICCRX__\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned long LockState; \\r
+ LockState = __get_interrupt_state(); \\r
+ __disable_interrupt(); \r
+ \r
+ #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \\r
+ }\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* RTT lock configuration for KEIL ARM\r
+*/\r
+#ifdef __CC_ARM\r
+ #if (defined __TARGET_ARCH_6S_M)\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ register unsigned char PRIMASK __asm( "primask"); \\r
+ LockState = PRIMASK; \\r
+ PRIMASK = 1u; \\r
+ __schedule_barrier();\r
+\r
+ #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \\r
+ __schedule_barrier(); \\r
+ }\r
+ #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))\r
+ #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY\r
+ #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)\r
+ #endif\r
+ #define SEGGER_RTT_LOCK() { \\r
+ unsigned int LockState; \\r
+ register unsigned char BASEPRI __asm( "basepri"); \\r
+ LockState = BASEPRI; \\r
+ BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \\r
+ __schedule_barrier();\r
+\r
+ #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \\r
+ __schedule_barrier(); \\r
+ }\r
+ #endif\r
+#endif\r
+\r
+/*********************************************************************\r
+*\r
+* RTT lock configuration fallback\r
+*/\r
+#ifndef SEGGER_RTT_LOCK\r
+ #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)\r
+#endif\r
+\r
+#ifndef SEGGER_RTT_UNLOCK\r
+ #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)\r
+#endif\r
+\r
+#endif\r
+/*************************** End of file ****************************/\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcStreamingPort.h\r
+ *\r
+ * The interface definitions for trace streaming ("stream ports").\r
+ * This "stream port" sets up the recorder to use SEGGER RTT as streaming channel.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_STREAMING_PORT_H\r
+#define TRC_STREAMING_PORT_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_RTT_BUFFER_SIZE_UP\r
+ *\r
+ * Defines the size of the "up" RTT buffer (target -> host) to use for writing\r
+ * the trace data, for RTT buffer 1 or higher.\r
+ *\r
+ * This setting is ignored for RTT buffer 0, which can't be reconfigured\r
+ * in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.\r
+ *\r
+ * Default buffer size for Tracealyzer is 5000 bytes. \r
+ *\r
+ * If you have a stand-alone J-Link probe, the can be decreased to around 1 KB.\r
+ * But integrated J-Link OB interfaces are slower and needs about 5-10 KB, \r
+ * depending on the amount of data produced.\r
+ ******************************************************************************/\r
+#define TRC_CFG_RTT_BUFFER_SIZE_UP 5000\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_RTT_BUFFER_SIZE_DOWN\r
+ *\r
+ * Defines the size of the "down" RTT buffer (host -> target) to use for reading\r
+ * commands from Tracealyzer, for RTT buffer 1 or higher.\r
+ *\r
+ * Default buffer size for Tracealyzer is 32 bytes.\r
+ *\r
+ * This setting is ignored for RTT buffer 0, which can't be reconfigured\r
+ * in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.\r
+ ******************************************************************************/\r
+#define TRC_CFG_RTT_BUFFER_SIZE_DOWN 32\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_RTT_UP_BUFFER_INDEX\r
+ *\r
+ * Defines the RTT buffer to use for writing the trace data. Make sure that\r
+ * the PC application has the same setting (File->Settings).\r
+ *\r
+ * Default: 1\r
+ *\r
+ * We don't recommend using RTT buffer 0, since mainly intended for terminals.\r
+ * If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h. \r
+ ******************************************************************************/\r
+#define TRC_CFG_RTT_UP_BUFFER_INDEX 1\r
+\r
+/*******************************************************************************\r
+ * Configuration Macro: TRC_CFG_RTT_DOWN_BUFFER_INDEX\r
+ *\r
+ * Defines the RTT buffer to use for reading the trace data. Make sure that\r
+ * the PC application has the same setting (File->Settings).\r
+ *\r
+ * Default: 1\r
+ *\r
+ * We don't recommend using RTT buffer 0, since mainly intended for terminals.\r
+ * If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h. \r
+ ******************************************************************************/\r
+#define TRC_CFG_RTT_DOWN_BUFFER_INDEX 1\r
+\r
+/*******************************************************************************\r
+ * TRC_CFG_RTT_MODE\r
+ * This stream port for J-Link streaming relies on SEGGER RTT, that contains an\r
+ * internal RAM buffer read by the J-Link probes during execution.\r
+ *\r
+ * Possible values:\r
+ * - SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (default)\r
+ * - SEGGER_RTT_MODE_NO_BLOCK_SKIP\r
+ *\r
+ * We recommend using SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL, to ensure you get a\r
+ * complete and valid trace. This may however cause blocking if your streaming\r
+ * interface isn't fast enough, which may disturb the real-time behavior.\r
+ * We therefore recommend to try SEGGER_RTT_MODE_NO_BLOCK_SKIP as well. \r
+ * In this mode, Tracealyzer will report lost events if the transfer is not\r
+ * fast enough. In that case, try increasing the size of the "up buffer".\r
+ ******************************************************************************/\r
+#define TRC_CFG_RTT_MODE SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL\r
+\r
+#include "SEGGER_RTT_Conf.h"\r
+#include "SEGGER_RTT.h"\r
+\r
+#if (TRC_CFG_RTT_UP_BUFFER_INDEX >= SEGGER_RTT_MAX_NUM_UP_BUFFERS)\r
+#error "TRC_CFG_RTT_UP_BUFFER_INDEX must be smaller than SEGGER_RTT_MAX_NUM_UP_BUFFERS"\r
+#endif\r
+\r
+#if (TRC_CFG_RTT_DOWN_BUFFER_INDEX >= SEGGER_RTT_MAX_NUM_DOWN_BUFFERS)\r
+#error "TRC_CFG_RTT_DOWN_BUFFER_INDEX must be smaller than SEGGER_RTT_MAX_NUM_DOWN_BUFFERS"\r
+#endif\r
+\r
+/* If index is defined as 0, the internal RTT buffers will be used instead of this. */\r
+#if TRC_CFG_RTT_UP_BUFFER_INDEX == 0\r
+#define TRC_RTT_ALLOC_UP() static char* _TzTraceData = NULL; /* Not actually used. Ignore allocation method. */\r
+#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname) /* Only for custom allocation */\r
+#else\r
+#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC\r
+#define TRC_RTT_ALLOC_UP() char _TzTraceData[TRC_CFG_RTT_BUFFER_SIZE_UP]; /* Static allocation */\r
+#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname) /* Only for custom allocation */\r
+#endif\r
+#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC\r
+#define TRC_RTT_ALLOC_UP() char* _TzTraceData = NULL; /* Dynamic allocation */\r
+#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_CFG_RTT_BUFFER_SIZE_UP);\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname) /* Only for custom allocation */\r
+#endif\r
+#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM\r
+#define TRC_RTT_ALLOC_UP() char* _TzTraceData = NULL; /* Custom allocation, user needs to call vTraceSetRecorderDataBuffer before vTraceEnable, to assign this */ \r
+#define TRC_STREAM_PORT_MALLOC() /* Not used in custom mode */\r
+#define TRC_ALLOC_CUSTOM_BUFFER(bufname) char bufname [TRC_CFG_RTT_BUFFER_SIZE_UP]; /* Not static in this case, since declared in user code */\r
+#endif\r
+#endif\r
+\r
+/* Down-buffer. If index is defined as 0, the internal RTT buffers will be used instead of this. */ \\r
+#if TRC_CFG_RTT_DOWN_BUFFER_INDEX == 0\r
+#define TRC_RTT_ALLOC_DOWN() static char* _TzCtrlData = NULL; /* Not actually used. Ignore allocation method. */\r
+#else\r
+#define TRC_RTT_ALLOC_DOWN() static char _TzCtrlData[TRC_CFG_RTT_BUFFER_SIZE_DOWN]; /* Always static allocation, since usually small. */\r
+#endif\r
+ \r
+#define TRC_STREAM_PORT_ALLOCATE_FIELDS() \\r
+ TRC_RTT_ALLOC_UP() /* Macro that will result in proper UP buffer allocation */ \\r
+ TRC_RTT_ALLOC_DOWN() /* Macro that will result in proper DOWN buffer allocation */\r
+\r
+#define TRC_STREAM_PORT_INIT() \\r
+ TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \\r
+ SEGGER_RTT_ConfigUpBuffer(TRC_CFG_RTT_UP_BUFFER_INDEX, "TzData", _TzTraceData, TRC_CFG_RTT_BUFFER_SIZE_UP, TRC_CFG_RTT_MODE ); \\r
+ SEGGER_RTT_ConfigDownBuffer(TRC_CFG_RTT_DOWN_BUFFER_INDEX, "TzCtrl", _TzCtrlData, TRC_CFG_RTT_BUFFER_SIZE_DOWN, TRC_CFG_RTT_MODE);\r
+\r
+#define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type _tmpArray[_size / sizeof(_type)]; _type* _ptrData = _tmpArray;\r
+#define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) _type _tmpArray[sizeof(largestEventType) / sizeof(_type)]; _type* _ptrData = _tmpArray;\r
+#define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) SEGGER_RTT_Write(TRC_CFG_RTT_UP_BUFFER_INDEX, (const char*)_ptrData, _size);\r
+#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) if (SEGGER_RTT_HASDATA(TRC_CFG_RTT_DOWN_BUFFER_INDEX)) *_ptrBytesRead = (int)SEGGER_RTT_Read(TRC_CFG_RTT_DOWN_BUFFER_INDEX, (char*)_ptrData, _size);\r
+#define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent)\r
+\r
+#define TRC_STREAM_PORT_ON_TRACE_BEGIN() /* Do nothing */\r
+#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */\r
+ \r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* TRC_STREAMING_PORT_H */\r
--- /dev/null
+Tracealyzer Stream Port for TCP/IP (lwIP example)\r
+-------------------------------------------------\r
+\r
+This directory contains a "stream port" for the Tracealyzer recorder library,\r
+i.e., the specific code needed to use a particular interface for streaming a\r
+Tracealyzer RTOS trace. The stream port is defined by a set of macros in\r
+trcStreamingPort.h, found in the "include" directory.\r
+\r
+This particular stream port targets TCP/IP. This example assumes lwIP but is\r
+easy to modify for other TCP/IP stacks.\r
+\r
+To use this stream port, make sure that include/trcStreamingPort.h is found\r
+by the compiler (i.e., add this folder to your project's include paths) and\r
+add all included source files to your build. Make sure no other versions of\r
+trcStreamingPort.h are included by mistake!\r
+\r
+Note that lwIP is not included, but assumed to exist in the project already.\r
+\r
+See also http://percepio.com/2016/10/05/rtos-tracing.\r
+\r
+Percepio AB\r
+www.percepio.com
\ No newline at end of file
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcStreamingPort.h\r
+ *\r
+ * The interface definitions for trace streaming ("stream ports").\r
+ * This "stream port" sets up the recorder to use TCP/IP as streaming channel.\r
+ * The example is for lwIP.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_STREAMING_PORT_H\r
+#define TRC_STREAMING_PORT_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * TRC_RECORDER_TRANSFER_METHOD_TCPIP\r
+ * \r
+ * This stream port for TCP/IP uses a temporary buffer consisting of multiple \r
+ * pages, that are transmitted periodically by the TzCtrl task. You can modify \r
+ * the supporting functions to match your system. See trcStreamingPort.c\r
+ ******************************************************************************/\r
+\r
+int32_t trcTcpWrite(void* data, uint32_t size, int32_t *ptrBytesWritten);\r
+int32_t trcTcpRead(void* data, uint32_t size, int32_t *ptrBytesRead);\r
+\r
+#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC\r
+#define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char _TzTraceData[TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE]; /* Static allocation. */\r
+#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
+#else\r
+#define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char* _TzTraceData = NULL; /* Dynamic allocation. */\r
+#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);\r
+#endif\r
+\r
+#define TRC_STREAM_PORT_INIT() \\r
+ TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \\r
+ prvPagedEventBufferInit(_TzTraceData);\r
+\r
+#define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)prvPagedEventBufferGetWritePointer(_size);\r
+#define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) /* We do the same thing as for non-dynamic event sizes */\r
+#define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) /* Not needed since we write immediately into the buffer received above by TRC_STREAM_PORT_ALLOCATE_EVENT, and the TRC_STREAM_PORT_PERIODIC_SEND_DATA defined below will take care of the actual trace transfer. */\r
+#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcTcpRead(_ptrData, _size, _ptrBytesRead);\r
+#define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent) prvPagedEventBufferTransfer(trcTcpWrite, _ptrBytesSent);\r
+\r
+#define TRC_STREAM_PORT_ON_TRACE_BEGIN() prvPagedEventBufferInit(_TzTraceData);\r
+#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* TRC_STREAMING_PORT_H */\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcStreamingPort.c\r
+ *\r
+ * Supporting functions for trace streaming, used by the "stream ports" \r
+ * for reading and writing data to the interface.\r
+ * Existing ports can easily be modified to fit another setup, e.g., a \r
+ * different TCP/IP stack, or to define your own stream port.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#include "trcRecorder.h"\r
+\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) \r
+#if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
+ \r
+/* TCP/IP includes */\r
+#include "lwip/tcpip.h"\r
+#include "lwip/sockets.h"\r
+\r
+int errno;\r
+\r
+#define TRC_TCPIP_PORT 12000\r
+\r
+int sock = -1, new_sd = -1;\r
+int flags = 0;\r
+int remoteSize;\r
+struct sockaddr_in address, remote;\r
+\r
+int32_t trcSocketSend( void* data, int32_t size, int32_t* bytesWritten )\r
+{\r
+ if (new_sd < 0)\r
+ return -1;\r
+ \r
+ *bytesWritten = send( new_sd, data, size, 0 );\r
+ if (*bytesWritten < 0)\r
+ {\r
+ /* EWOULDBLOCK may be expected when buffers are full */\r
+ if (errno != EWOULDBLOCK)\r
+ {\r
+ closesocket(new_sd);\r
+ new_sd = -1;\r
+ return -1;\r
+ }\r
+ else\r
+ *bytesWritten = 0;\r
+ }\r
+ \r
+ return 0;\r
+}\r
+\r
+int32_t trcSocketReceive( void* data, int32_t size, int32_t* bytesRead )\r
+{\r
+ if (new_sd < 0)\r
+ return -1;\r
+ \r
+ *bytesRead = recv( new_sd, data, size, 0 );\r
+ if ( *bytesRead < 0 )\r
+ {\r
+ /* EWOULDBLOCK may be expected when there is no data to receive */\r
+ if (errno != EWOULDBLOCK)\r
+ {\r
+ closesocket(new_sd);\r
+ new_sd = -1;\r
+ return -1;\r
+ }\r
+ else\r
+ *bytesRead = 0;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int32_t trcSocketInitializeListener()\r
+{\r
+ if (sock >= 0)\r
+ return 0;\r
+ \r
+ sock = lwip_socket(AF_INET, SOCK_STREAM, 0);\r
+\r
+ if (sock < 0)\r
+ return -1;\r
+\r
+ address.sin_family = AF_INET;\r
+ address.sin_port = htons( TRC_TCPIP_PORT );\r
+ address.sin_addr.s_addr = INADDR_ANY;\r
+\r
+ if (bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0)\r
+ {\r
+ closesocket(sock);\r
+ sock = -1;\r
+ return -1;\r
+ }\r
+\r
+ if (lwip_listen(sock, 5) < 0)\r
+ {\r
+ closesocket(sock);\r
+ sock = -1;\r
+ return -1;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int32_t trcSocketAccept()\r
+{\r
+ if (sock < 0)\r
+ return -1;\r
+ \r
+ if (new_sd >= 0)\r
+ return 0;\r
+ \r
+ remoteSize = sizeof( remote );\r
+ new_sd = accept( sock, (struct sockaddr *)&remote, (socklen_t*)&remoteSize );\r
+\r
+ flags = fcntl( new_sd, F_GETFL, 0 );\r
+ fcntl( new_sd, F_SETFL, flags | O_NONBLOCK );\r
+\r
+ if( new_sd < 0 )\r
+ {\r
+ closesocket(new_sd);\r
+ new_sd = -1;\r
+ closesocket(sock);\r
+ sock = -1;\r
+ return -1;\r
+ }\r
+\r
+ return 0;\r
+}\r
+/************** MODIFY THE ABOVE PART TO USE YOUR TPC/IP STACK ****************/\r
+\r
+int32_t trcTcpWrite(void* data, uint32_t size, int32_t *ptrBytesWritten)\r
+{\r
+ return trcSocketSend(data, size, ptrBytesWritten);\r
+}\r
+\r
+int32_t trcTcpRead(void* data, uint32_t size, int32_t *ptrBytesRead)\r
+{\r
+ trcSocketInitializeListener();\r
+ \r
+ trcSocketAccept();\r
+ \r
+ return trcSocketReceive(data, size, ptrBytesRead);\r
+}\r
+\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
--- /dev/null
+Tracealyzer Stream Port for USB CDC (STM32 example)\r
+---------------------------------------------------\r
+\r
+This directory contains a "stream port" for the Tracealyzer recorder library,\r
+i.e., the specific code needed to use a particular interface for streaming a\r
+Tracealyzer RTOS trace. The stream port is defined by a set of macros in\r
+trcStreamingPort.h, found in the "include" directory.\r
+\r
+This particular stream port targets USB CDC. This is an example for the STM32 USB\r
+stack (from the STM32CubeMX code generation tool, v1.4.1) and has been tested on\r
+a STM32F767ZI device on a Nucleo board. See this blog post:\r
+\r
+http://percepio.com/2017/02/03/usb-trace-streaming-st-nucleo-f767zi-board/\r
+\r
+However, it should be straight-forward to modify this for other USB stacks.\r
+\r
+To use this stream port, make sure that include/trcStreamingPort.h is found\r
+by the compiler (i.e., add this folder to your project's include paths) and\r
+add all included source files to your build. Make sure no other versions of\r
+trcStreamingPort.h are included by mistake!\r
+\r
+Note that the USB stack not included, but assumed to exist in the project already.\r
+\r
+See also http://percepio.com/2016/10/05/rtos-tracing.\r
+\r
+Percepio AB\r
+www.percepio.com
\ No newline at end of file
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcStreamingPort.h\r
+ *\r
+ * The interface definitions for trace streaming ("stream ports").\r
+ * This "stream port" sets up the recorder to use USB CDC as streaming channel.\r
+ * The example is for STM32 using STM32Cube.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#ifndef TRC_STREAMING_PORT_H\r
+#define TRC_STREAMING_PORT_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * Implement the below macros to define your own stream port. If your transfer \r
+ * method uses RTOS functions, you should not send the data directly but use \r
+ * the recorder's internal buffer to store the trace data, for later transfer by\r
+ * the TzCtrl task. Check the predefined stream ports for examples on how to use \r
+ * the internal buffer (e.g., TCP/IP, UART or USB CDC).\r
+ *\r
+ * Read more at http://percepio.com/2016/10/05/rtos-tracing/ \r
+ ******************************************************************************/\r
+\r
+/* Include files as needed, in this case it is files from STM32Cube FW_F7 V1.4.1 */\r
+#include "usb_device.h"\r
+#include "usbd_cdc.h"\r
+#include "usbd_CDC_if.h"\r
+#include "usb_device.h"\r
+\r
+/* Tested on STM32 devices using Keil/CMSIS USB stack */\r
+\r
+extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;\r
+uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);\r
+\r
+int32_t trcCDCReceive(void *data, uint32_t size, int32_t* NumBytes);\r
+int32_t trcCDCTransmit(void* data, uint32_t size, int32_t * noOfBytesSent );\r
+\r
+#if TRC_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC\r
+#define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char _TzTraceData[TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE]; /* Static allocation. */\r
+#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
+#else\r
+#define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char* _TzTraceData = NULL; /* Dynamic allocation. */\r
+#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_PAGED_EVENT_BUFFER_PAGE_SIZE);\r
+#endif\r
+\r
+#define TRC_STREAM_PORT_INIT() \\r
+ MX_USB_DEVICE_Init(); \\r
+ TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */\r
+\r
+#define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)prvPagedEventBufferGetWritePointer(_size);\r
+\r
+#define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) /* We do the same thing as for non-dynamic event sizes */\r
+#define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) /* Not needed since we write immediately into the buffer received above by TRC_STREAM_PORT_ALLOCATE_EVENT, and the TRC_STREAM_PORT_PERIODIC_SEND_DATA defined below will take care of the actual trace transfer. */\r
+#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcCDCReceive(_ptrData, _size, _ptrBytesRead);\r
+#define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent) prvPagedEventBufferTransfer(trcCDCTransmit, _ptrBytesSent);\r
+\r
+#define TRC_STREAM_PORT_ON_TRACE_BEGIN() { prvPagedEventBufferInit(_TzTraceData); }\r
+#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* TRC_STREAMING_PORT_H */\r
--- /dev/null
+#include "trcRecorder.h"\r
+\r
+#if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
+#if(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
+\r
+#include "stdint.h"\r
+\r
+/* Include files as needed, in this case it is files from STM32Cube FW_F7 V1.4.1 */\r
+#include "usb_device.h"\r
+#include "usbd_cdc.h"\r
+#include "usbd_CDC_if.h"\r
+#include "usb_device.h"\r
+\r
+#define BUFSIZE 64\r
+ \r
+typedef struct{\r
+ uint32_t idx;\r
+ uint8_t data[BUFSIZE];\r
+}recBuf;\r
+\r
+/* Define size for the receive and transmit buffer over CDC */\r
+#define APP_RX_DATA_SIZE 8\r
+#define APP_TX_DATA_SIZE 64\r
+\r
+/* Received Data over USB are stored in this buffer */\r
+uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];\r
+\r
+/* Send Data over USB CDC are stored in this buffer */\r
+uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];\r
+\r
+extern USBD_HandleTypeDef hUsbDeviceFS;\r
+extern PCD_HandleTypeDef hpcd_USB_OTG_FS;\r
+\r
+\r
+recBuf commandBuffer;\r
+\r
+static int8_t CDC_Init_FS (void);\r
+static int8_t CDC_DeInit_FS (void);\r
+static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length);\r
+static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len);\r
+ \r
+USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = \r
+{\r
+ CDC_Init_FS,\r
+ CDC_DeInit_FS,\r
+ CDC_Control_FS, \r
+ CDC_Receive_FS\r
+};\r
+\r
+/* Private functions ---------------------------------------------------------*/\r
+/**\r
+ * @brief CDC_Init_FS\r
+ * Initializes the CDC media low layer over the FS USB IP\r
+ * @param None\r
+ * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL\r
+ */\r
+static int8_t CDC_Init_FS(void)\r
+{ \r
+ /* Set Application Buffers */\r
+ USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);\r
+ USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);\r
+ return (USBD_OK);\r
+}\r
+\r
+/**\r
+ * @brief CDC_DeInit_FS\r
+ * DeInitializes the CDC media low layer\r
+ * @param None\r
+ * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL\r
+ */\r
+static int8_t CDC_DeInit_FS(void)\r
+{ \r
+ return (USBD_OK);\r
+}\r
+\r
+/**\r
+ * @brief CDC_Control_FS\r
+ * Manage the CDC class requests\r
+ * @param cmd: Command code \r
+ * @param pbuf: Buffer containing command data (request parameters)\r
+ * @param length: Number of data to be sent (in bytes)\r
+ * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL\r
+ */\r
+static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)\r
+{ \r
+ switch (cmd)\r
+ {\r
+ case CDC_SEND_ENCAPSULATED_COMMAND:\r
+ break;\r
+\r
+ case CDC_GET_ENCAPSULATED_RESPONSE:\r
+ break;\r
+\r
+ case CDC_SET_COMM_FEATURE:\r
+ break;\r
+\r
+ case CDC_GET_COMM_FEATURE:\r
+ break;\r
+\r
+ case CDC_CLEAR_COMM_FEATURE:\r
+ break;\r
+\r
+ /*******************************************************************************/\r
+ /* Line Coding Structure */\r
+ /*-----------------------------------------------------------------------------*/\r
+ /* Offset | Field | Size | Value | Description */\r
+ /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/\r
+ /* 4 | bCharFormat | 1 | Number | Stop bits */\r
+ /* 0 - 1 Stop bit */\r
+ /* 1 - 1.5 Stop bits */\r
+ /* 2 - 2 Stop bits */\r
+ /* 5 | bParityType | 1 | Number | Parity */\r
+ /* 0 - None */\r
+ /* 1 - Odd */ \r
+ /* 2 - Even */\r
+ /* 3 - Mark */\r
+ /* 4 - Space */\r
+ /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */\r
+ /*******************************************************************************/\r
+ case CDC_SET_LINE_CODING:\r
+ break;\r
+\r
+ case CDC_GET_LINE_CODING:\r
+ break;\r
+\r
+ case CDC_SET_CONTROL_LINE_STATE:\r
+ break;\r
+\r
+ case CDC_SEND_BREAK:\r
+ break; \r
+ \r
+ default:\r
+ break;\r
+ }\r
+ return (USBD_OK);\r
+}\r
+\r
+/**\r
+ * @brief CDC_Receive_FS\r
+ * Data received over USB OUT endpoint are sent over CDC interface \r
+ * through this function.\r
+ * \r
+ * @note\r
+ * This function will block any OUT packet reception on USB endpoint \r
+ * until exiting this function. If you exit this function before transfer\r
+ * is complete on CDC interface (i.e. using DMA controller) it will result \r
+ * in receiving more data while previous ones are still not sent.\r
+ * \r
+ * @param Buf: Buffer of data to be received\r
+ * @param Len: Number of data received (in bytes)\r
+ * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL\r
+ */\r
+static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)\r
+{\r
+ for( uint32_t i=0;i<* Len;i++)\r
+ { \r
+ commandBuffer.data[commandBuffer.idx]=Buf[i];\r
+ commandBuffer.idx++;\r
+ } \r
+ USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);\r
+ USBD_CDC_ReceivePacket(&hUsbDeviceFS); \r
+\r
+ return (USBD_OK);\r
+}\r
+\r
+/**\r
+ * @brief CDC_Transmit_FS\r
+ * Data send over USB IN endpoint are sent over CDC interface \r
+ * through this function. \r
+ * @note\r
+ * \r
+ * \r
+ * @param Buf: Buffer of data to be send\r
+ * @param Len: Number of data to be send (in bytes)\r
+ * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY\r
+ */\r
+uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)\r
+{\r
+ uint8_t result = USBD_OK;\r
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;\r
+ if (hcdc->TxState != 0){\r
+ return USBD_BUSY;\r
+ }\r
+ USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);\r
+ result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);\r
+ return result;\r
+}\r
+\r
+int32_t trcCDCReceive(void *data, uint32_t size, int32_t* NumBytes)\r
+{\r
+ uint32_t i,diff;\r
+\r
+ if(commandBuffer.idx>0)\r
+ {\r
+ if (size >= commandBuffer.idx) // more than what is stored, number of bytes will be .idx\r
+ {\r
+ memcpy(data,commandBuffer.data, commandBuffer.idx);\r
+ *NumBytes=commandBuffer.idx;\r
+ commandBuffer.idx=0; // Make the buffer ready for a new command\r
+ }\r
+ else //If some data in the buffer is not read\r
+ {\r
+ diff = commandBuffer.idx-size;\r
+ memcpy(data,commandBuffer.data, size);\r
+ for(i=0;i<diff;i++)\r
+ {\r
+ commandBuffer.data[i]=commandBuffer.data[i+size];\r
+ }\r
+ *NumBytes=size;\r
+ commandBuffer.idx=diff;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ *NumBytes=0;\r
+ }\r
+ return 0;\r
+}\r
+\r
+int32_t trcCDCTransmit(void* data, uint32_t size, int32_t * noOfBytesSent )\r
+{\r
+ int32_t result;\r
+ result=CDC_Transmit_FS(data,size);\r
+ *noOfBytesSent=size;\r
+\r
+ return result;\r
+}\r
+\r
+/**\r
+* @brief This function handles USB On The Go FS global interrupt.\r
+*/\r
+void OTG_FS_IRQHandler(void)\r
+{\r
+ HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);\r
+}\r
+\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcBase.c\r
- *\r
- * Core functionality of the trace recorder library.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#include "trcBase.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#include <stdint.h>\r
-\r
-/*******************************************************************************\r
- * Static data initializations\r
- ******************************************************************************/\r
-\r
-/* Tasks and kernel objects can be explicitly excluded from the trace to reduce\r
-buffer usage. This structure handles the exclude flags for all objects and tasks.\r
-Note that slot 0 is not used, since not a valid handle. */\r
-uint8_t excludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1] = { 0 };\r
-\r
-/* Specific events can also be excluded, i.e., by the event code. This can be\r
-used to exclude kernel calls that don't refer to a kernel object, like a delay.\r
-This structure handle the exclude flags for all event codes */\r
-uint8_t excludedEventCodes[NEventCodes / 8 + 1] = { 0 };\r
-\r
-/* A set of stacks that keeps track of available object handles for each class.\r
-The stacks are empty initially, meaning that allocation of new handles will be\r
-based on a counter (for each object class). Any delete operation will\r
-return the handle to the corresponding stack, for reuse on the next allocate.*/\r
-objectHandleStackType objectHandleStacks = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };\r
-\r
-/* Initial HWTC_COUNT value, for detecting if the time-stamping source is\r
-enabled. If using the OS periodic timer for time-stamping, this might not\r
-have been configured on the earliest events during the startup. */\r
-uint32_t init_hwtc_count;\r
-\r
-/*******************************************************************************\r
- * RecorderData\r
- *\r
- * The main data structure. This is the data read by the Tracealyzer tools,\r
- * typically through a debugger RAM dump. The recorder uses the pointer\r
- * RecorderDataPtr for accessing this, to allow for dynamic allocation.\r
- *\r
- * On the NXP LPC17xx you may use the secondary RAM bank (AHB RAM) for this\r
- * purpose. For instance, the LPC1766 has 32 KB AHB RAM which allows for\r
- * allocating a buffer size of at least 7500 events without affecting the main\r
- * RAM. To place RecorderData in this RAM bank using IAR Embedded Workbench\r
- * for ARM, use this pragma right before the declaration:\r
- *\r
- * #pragma location="AHB_RAM_MEMORY"\r
- *\r
- * This of course works for other hardware architectures with additional RAM\r
- * banks as well, just replace "AHB_RAM_MEMORY" with the section name from the\r
- * linker .map file, or simply the desired address.\r
- *\r
- * For portability reasons, we don't add the pragma directly in trcBase.c, but\r
- * in a header file included below. To include this header, you need to enable\r
- * USE_LINKER_PRAGMA, defined in trcConfig.h.\r
- *\r
- * If using GCC, you need to modify the declaration as follows:\r
- *\r
- * RecorderDataType RecorderData __attribute__ ((section ("name"))) = ...\r
- *\r
- * Remember to replace "name" with the correct section name.\r
- ******************************************************************************/\r
-\r
-static void vInitStartMarkers(void);\r
-\r
-#if (TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_STATIC)\r
-#if (USE_LINKER_PRAGMA == 1)\r
-#include "recorderdata_linker_pragma.h"\r
-#endif\r
-\r
-RecorderDataType RecorderData;\r
-\r
-#endif\r
-\r
-RecorderDataType* RecorderDataPtr = NULL;\r
-\r
-/* This version of the function dynamically allocates the trace data */\r
-void prvTraceInitTraceData()\r
-{\r
- init_hwtc_count = HWTC_COUNT;\r
-\r
-#if TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_STATIC\r
- RecorderDataPtr = &RecorderData;\r
-#elif TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_DYNAMIC\r
- RecorderDataPtr = (RecorderDataType*)TRACE_MALLOC(sizeof(RecorderDataType));\r
-#elif TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_CUSTOM\r
- /* DO NOTHING */\r
-#endif\r
-\r
-\r
- TRACE_ASSERT(RecorderDataPtr != NULL, "prvTraceInitTraceData, RecorderDataPtr == NULL", );\r
-\r
- if (! RecorderDataPtr)\r
- {\r
- vTraceError("No recorder data structure allocated!");\r
- return;\r
- }\r
-\r
- (void)memset(RecorderDataPtr, 0, sizeof(RecorderDataType));\r
-\r
- RecorderDataPtr->startmarker0 = 0x00;\r
- RecorderDataPtr->startmarker1 = 0x01;\r
- RecorderDataPtr->startmarker2 = 0x02;\r
- RecorderDataPtr->startmarker3 = 0x03;\r
- RecorderDataPtr->startmarker4 = 0x70;\r
- RecorderDataPtr->startmarker5 = 0x71;\r
- RecorderDataPtr->startmarker6 = 0x72;\r
- RecorderDataPtr->startmarker7 = 0x73;\r
- RecorderDataPtr->startmarker8 = 0xF0;\r
- RecorderDataPtr->startmarker9 = 0xF1;\r
- RecorderDataPtr->startmarker10 = 0xF2;\r
- RecorderDataPtr->startmarker11 = 0xF3;\r
-\r
- RecorderDataPtr->version = TRACE_KERNEL_VERSION;\r
- RecorderDataPtr->minor_version = TRACE_MINOR_VERSION;\r
- RecorderDataPtr->irq_priority_order = IRQ_PRIORITY_ORDER;\r
- RecorderDataPtr->filesize = sizeof(RecorderDataType);\r
-\r
- RecorderDataPtr->maxEvents = EVENT_BUFFER_SIZE;\r
-\r
- RecorderDataPtr->debugMarker0 = 0xF0F0F0F0;\r
-\r
- RecorderDataPtr->isUsing16bitHandles = USE_16BIT_OBJECT_HANDLES;\r
-\r
- /* This function is kernel specific */\r
- vTraceInitObjectPropertyTable();\r
-\r
- RecorderDataPtr->debugMarker1 = 0xF1F1F1F1;\r
- RecorderDataPtr->SymbolTable.symTableSize = SYMBOL_TABLE_SIZE;\r
- RecorderDataPtr->SymbolTable.nextFreeSymbolIndex = 1;\r
-#if (INCLUDE_FLOAT_SUPPORT == 1)\r
- RecorderDataPtr->exampleFloatEncoding = 1.0f; /* otherwise already zero */\r
-#endif\r
- RecorderDataPtr->debugMarker2 = 0xF2F2F2F2;\r
- (void)strncpy(RecorderDataPtr->systemInfo, "Trace Recorder Demo", 80);\r
- RecorderDataPtr->debugMarker3 = 0xF3F3F3F3;\r
- RecorderDataPtr->endmarker0 = 0x0A;\r
- RecorderDataPtr->endmarker1 = 0x0B;\r
- RecorderDataPtr->endmarker2 = 0x0C;\r
- RecorderDataPtr->endmarker3 = 0x0D;\r
- RecorderDataPtr->endmarker4 = 0x71;\r
- RecorderDataPtr->endmarker5 = 0x72;\r
- RecorderDataPtr->endmarker6 = 0x73;\r
- RecorderDataPtr->endmarker7 = 0x74;\r
- RecorderDataPtr->endmarker8 = 0xF1;\r
- RecorderDataPtr->endmarker9 = 0xF2;\r
- RecorderDataPtr->endmarker10 = 0xF3;\r
- RecorderDataPtr->endmarker11 = 0xF4;\r
-\r
-#if USE_SEPARATE_USER_EVENT_BUFFER\r
- RecorderDataPtr->userEventBuffer.bufferID = 1;\r
- RecorderDataPtr->userEventBuffer.version = 0;\r
- RecorderDataPtr->userEventBuffer.numberOfSlots = USER_EVENT_BUFFER_SIZE;\r
- RecorderDataPtr->userEventBuffer.numberOfChannels = CHANNEL_FORMAT_PAIRS + 1;\r
-#endif\r
-\r
- /* Kernel specific initialization of the objectHandleStacks variable */\r
- vTraceInitObjectHandleStack();\r
-\r
- /* Fix the start markers of the trace data structure */\r
- vInitStartMarkers();\r
-\r
- #ifdef PORT_SPECIFIC_INIT\r
- PORT_SPECIFIC_INIT();\r
- #endif\r
-}\r
-\r
-static void vInitStartMarkers()\r
-{\r
- uint32_t i;\r
- uint8_t *ptr = (uint8_t*)&(RecorderDataPtr->startmarker0);\r
- if ((*ptr) == 0)\r
- {\r
- for (i = 0; i < 12; i++)\r
- {\r
- ptr[i] += 1;\r
- }\r
- }\r
- else\r
- {\r
- vTraceError("Trace start markers already initialized!");\r
- }\r
-}\r
-\r
-volatile int recorder_busy = 0;\r
-\r
-/* Gives the last error message of the recorder. NULL if no error message. */\r
-const char* traceErrorMessage = NULL;\r
-\r
-void* xTraceNextFreeEventBufferSlot(void)\r
-{\r
- if (! RecorderDataPtr->recorderActive)\r
- {\r
- // If the associated XTS or XPS event prio to the main event has filled the buffer and store mode "stop when full".\r
- return NULL;\r
- }\r
-\r
- if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)\r
- {\r
- vTraceError("Attempt to index outside event buffer!");\r
- return NULL;\r
- }\r
- return (void*)(&RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex*4]);\r
-}\r
-\r
-uint16_t uiIndexOfObject(objectHandleType objecthandle, uint8_t objectclass)\r
-{\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "uiIndexOfObject: Invalid value for objectclass", 0);\r
- TRACE_ASSERT(objecthandle > 0 && objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "uiIndexOfObject: Invalid value for objecthandle", 0);\r
-\r
- if ((objectclass < TRACE_NCLASSES) && (objecthandle > 0) &&\r
- (objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass]))\r
- {\r
- return (uint16_t)(RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[objectclass] +\r
- (RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[objectclass] * (objecthandle-1)));\r
- }\r
-\r
- vTraceError("Object table lookup with invalid object handle or object class!");\r
- return 0;\r
-}\r
-\r
-/*******************************************************************************\r
- * Object handle system\r
- * This provides a mechanism to assign each kernel object (tasks, queues, etc)\r
- * with a 1-byte handle, that is used to identify the object in the trace.\r
- * This way, only one byte instead of four is necessary to identify the object.\r
- * This allows for maximum 255 objects, of each object class, active at any\r
- * moment.\r
- * Note that zero is reserved as an error code and is not a valid handle.\r
- *\r
- * In order to allow for fast dynamic allocation and release of object handles,\r
- * the handles of each object class (e.g., TASK) are stored in a stack. When a\r
- * handle is needed, e.g., on task creation, the next free handle is popped from\r
- * the stack. When an object (e.g., task) is deleted, its handle is pushed back\r
- * on the stack and can thereby be reused for other objects.\r
- *\r
- * Since this allows for reuse of object handles, a specific handle (e.g, "8")\r
- * may refer to TASK_X at one point, and later mean "TASK_Y". To resolve this,\r
- * the recorder uses "Close events", which are stored in the main event buffer\r
- * when objects are deleted and their handles are released. The close event\r
- * contains the mapping between object handle and object name which was valid up\r
- * to this point in time. The object name is stored as a symbol table entry.\r
- ******************************************************************************/\r
-\r
-objectHandleType xTraceGetObjectHandle(traceObjectClass objectclass)\r
-{\r
- objectHandleType handle;\r
- static int indexOfHandle;\r
-\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "xTraceGetObjectHandle: Invalid value for objectclass", (objectHandleType)0);\r
-\r
- indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];\r
- if (objectHandleStacks.objectHandles[indexOfHandle] == 0)\r
- {\r
- /* Zero is used to indicate a never before used handle, i.e.,\r
- new slots in the handle stack. The handle slot needs to\r
- be initialized here (starts at 1). */\r
- objectHandleStacks.objectHandles[indexOfHandle] =\r
- (objectHandleType)(1 + indexOfHandle -\r
- objectHandleStacks.lowestIndexOfClass[objectclass]);\r
- }\r
-\r
- handle = objectHandleStacks.objectHandles[indexOfHandle];\r
-\r
- if (objectHandleStacks.indexOfNextAvailableHandle[objectclass]\r
- > objectHandleStacks.highestIndexOfClass[objectclass])\r
- {\r
- /* ERROR */\r
- vTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));\r
-\r
- handle = 0; /* an invalid/anonymous handle - but the recorder is stopped now... */\r
- }\r
- else\r
- {\r
- int hndCount;\r
- objectHandleStacks.indexOfNextAvailableHandle[objectclass]++;\r
-\r
- hndCount = objectHandleStacks.indexOfNextAvailableHandle[objectclass] -\r
- objectHandleStacks.lowestIndexOfClass[objectclass];\r
-\r
- if (hndCount >\r
- objectHandleStacks.handleCountWaterMarksOfClass[objectclass])\r
- {\r
- objectHandleStacks.handleCountWaterMarksOfClass[objectclass] =\r
- (objectHandleType)hndCount;\r
- }\r
-\r
- TRACE_CLEAR_OBJECT_FLAG_ISEXCLUDED(objectclass, handle);\r
- }\r
-\r
- return handle;\r
-}\r
-\r
-void vTraceFreeObjectHandle(traceObjectClass objectclass, objectHandleType handle)\r
-{\r
- int indexOfHandle;\r
-\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "vTraceFreeObjectHandle: Invalid value for objectclass", );\r
- TRACE_ASSERT(handle > 0 && handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "vTraceFreeObjectHandle: Invalid value for handle", );\r
-\r
- /* Check that there is room to push the handle on the stack */\r
- if ((objectHandleStacks.indexOfNextAvailableHandle[objectclass] - 1) <\r
- objectHandleStacks.lowestIndexOfClass[objectclass])\r
- {\r
- /* Error */\r
- vTraceError("Attempt to free more handles than allocated!");\r
- }\r
- else\r
- {\r
- objectHandleStacks.indexOfNextAvailableHandle[objectclass]--;\r
- indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];\r
- objectHandleStacks.objectHandles[indexOfHandle] = handle;\r
- }\r
-\r
-}\r
-\r
-/*******************************************************************************\r
- * Objects Property Table\r
- *\r
- * This holds the names and properties of the currently active objects, such as\r
- * tasks and queues. This is developed to support "dynamic" objects which might\r
- * be deleted during runtime. Their handles are only valid during their\r
- * lifetime, i.e., from create to delete, as they might be reused on later\r
- * create operations. When an object is deleted from the OPT, its data is moved\r
- * to the trace buffer and/or the symbol table.\r
- * When an object (task, queue, etc.) is created, it receives a handle, which\r
- * together with the object class specifies its location in the OPT. Thus,\r
- * objects of different types may share the same name and/or handle, but still\r
- * be independent objects.\r
- ******************************************************************************/\r
-\r
-/*******************************************************************************\r
- * vTraceSetObjectName\r
- *\r
- * Registers the names of queues, semaphores and other kernel objects in the\r
- * recorder's Object Property Table, at the given handle and object class.\r
- ******************************************************************************/\r
-void vTraceSetObjectName(traceObjectClass objectclass,\r
- objectHandleType handle,\r
- const char* name)\r
-{\r
- static uint16_t idx;\r
-\r
- TRACE_ASSERT(name != NULL, "vTraceSetObjectName: name == NULL", );\r
-\r
- if (objectclass >= TRACE_NCLASSES)\r
- {\r
- vTraceError("Illegal object class in vTraceSetObjectName");\r
- return;\r
- }\r
-\r
- if (handle == 0)\r
- {\r
- vTraceError("Illegal handle (0) in vTraceSetObjectName.");\r
- return;\r
- }\r
-\r
- if (handle > RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass])\r
- {\r
- /* ERROR */\r
- vTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));\r
- }\r
- else\r
- {\r
- idx = uiIndexOfObject(handle, objectclass);\r
-\r
- if (traceErrorMessage == NULL)\r
- {\r
- (void)strncpy((char*)&(RecorderDataPtr->ObjectPropertyTable.objbytes[idx]),\r
- name,\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[ objectclass ]);\r
- }\r
- }\r
-}\r
-\r
-traceLabel prvTraceOpenSymbol(const char* name, traceLabel userEventChannel)\r
-{\r
- uint16_t result;\r
- uint8_t len;\r
- uint8_t crc;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- len = 0;\r
- crc = 0;\r
-\r
- TRACE_ASSERT(name != NULL, "prvTraceOpenSymbol: name == NULL", (traceLabel)0);\r
-\r
- prvTraceGetChecksum(name, &crc, &len);\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- result = prvTraceLookupSymbolTableEntry(name, crc, len, userEventChannel);\r
- if (!result)\r
- {\r
- result = prvTraceCreateSymbolTableEntry(name, crc, len, userEventChannel);\r
- }\r
- trcCRITICAL_SECTION_END();\r
-\r
- return result;\r
-}\r
-\r
-/*******************************************************************************\r
- * Supporting functions\r
- ******************************************************************************/\r
-\r
-/*******************************************************************************\r
- * vTraceError\r
- *\r
- * Called by various parts in the recorder. Stops the recorder and stores a\r
- * pointer to an error message, which is printed by the monitor task.\r
- * If you are not using the monitor task, you may use xTraceGetLastError()\r
- * from your application to check if the recorder is OK.\r
- *\r
- * Note: If a recorder error is registered before vTraceStart is called, the\r
- * trace start will be aborted. This can occur if any of the Nxxxx constants\r
- * (e.g., NTask) in trcConfig.h is too small.\r
- ******************************************************************************/\r
-void vTraceError(const char* msg)\r
-{\r
- TRACE_ASSERT(msg != NULL, "vTraceError: msg == NULL", );\r
- TRACE_ASSERT(RecorderDataPtr != NULL, "vTraceError: RecorderDataPtr == NULL", );\r
-\r
- /* Stop the recorder. Note: We do not call vTraceStop, since that adds a weird\r
- and unnecessary dependency to trcUser.c */\r
-\r
- RecorderDataPtr->recorderActive = 0;\r
-\r
- if (traceErrorMessage == NULL)\r
- {\r
- traceErrorMessage = msg;\r
- (void)strncpy(RecorderDataPtr->systemInfo, traceErrorMessage, 80);\r
- RecorderDataPtr->internalErrorOccured = 1;\r
- }\r
-\r
-}\r
-\r
-/******************************************************************************\r
- * prvCheckDataToBeOverwrittenForMultiEntryEvents\r
- *\r
- * This checks if the next event to be overwritten is a multi-entry user event,\r
- * i.e., a USER_EVENT followed by data entries.\r
- * Such data entries do not have an event code at byte 0, as other events.\r
- * All 4 bytes are user data, so the first byte of such data events must\r
- * not be interpreted as type field. The number of data entries following\r
- * a USER_EVENT is given in the event code of the USER_EVENT.\r
- * Therefore, when overwriting a USER_EVENT (when using in ringbuffer mode)\r
- * any data entries following must be replaced with NULL events (code 0).\r
- *\r
- * This is assumed to execute within a critical section...\r
- *****************************************************************************/\r
-\r
-void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nofEntriesToCheck)\r
-{\r
- /* Generic "int" type is desired - should be 16 bit variable on 16 bit HW */\r
- unsigned int i = 0;\r
- unsigned int e = 0;\r
-\r
- TRACE_ASSERT(nofEntriesToCheck != 0,\r
- "prvCheckDataToBeOverwrittenForMultiEntryEvents: nofEntriesToCheck == 0", );\r
-\r
- while (i < nofEntriesToCheck)\r
- {\r
- e = RecorderDataPtr->nextFreeIndex + i;\r
- if ((RecorderDataPtr->eventData[e*4] > USER_EVENT) &&\r
- (RecorderDataPtr->eventData[e*4] < USER_EVENT + 16))\r
- {\r
- uint8_t nDataEvents = (uint8_t)(RecorderDataPtr->eventData[e*4] - USER_EVENT);\r
- if ((e + nDataEvents) < RecorderDataPtr->maxEvents)\r
- {\r
- (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4 + 4 * nDataEvents);\r
- }\r
- }\r
- else if (RecorderDataPtr->eventData[e*4] == DIV_XPS)\r
- {\r
- if ((e + 1) < RecorderDataPtr->maxEvents)\r
- {\r
- /* Clear 8 bytes */\r
- (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4 + 4);\r
- }\r
- else\r
- {\r
- /* Clear 8 bytes, 4 first and 4 last */\r
- (void)memset(& RecorderDataPtr->eventData[0], 0, 4);\r
- (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4);\r
- }\r
- }\r
- i++;\r
- }\r
-}\r
-\r
-/*******************************************************************************\r
- * prvTraceUpdateCounters\r
- *\r
- * Updates the index of the event buffer.\r
- ******************************************************************************/\r
-void prvTraceUpdateCounters(void)\r
-{\r
- if (RecorderDataPtr->recorderActive == 0)\r
- {\r
- return;\r
- }\r
-\r
- RecorderDataPtr->numEvents++;\r
-\r
- RecorderDataPtr->nextFreeIndex++;\r
-\r
- if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)\r
- {\r
-#if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)\r
- RecorderDataPtr->bufferIsFull = 1;\r
- RecorderDataPtr->nextFreeIndex = 0;\r
-#else\r
- vTraceStop();\r
-#endif\r
- }\r
-\r
-#if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)\r
- prvCheckDataToBeOverwrittenForMultiEntryEvents(1);\r
-#endif\r
-}\r
-\r
-/******************************************************************************\r
- * prvTraceGetDTS\r
- *\r
- * Returns a differential timestamp (DTS), i.e., the time since\r
- * last event, and creates an XTS event if the DTS does not fit in the\r
- * number of bits given. The XTS event holds the MSB bytes of the DTS.\r
- *\r
- * The parameter param_maxDTS should be 0xFF for 8-bit dts or 0xFFFF for\r
- * events with 16-bit dts fields.\r
- *****************************************************************************/\r
-uint16_t prvTraceGetDTS(uint16_t param_maxDTS)\r
-{\r
- static uint32_t old_timestamp = 0;\r
- XTSEvent* xts = 0;\r
- uint32_t dts = 0;\r
- uint32_t timestamp = 0;\r
-\r
- TRACE_ASSERT(param_maxDTS == 0xFF || param_maxDTS == 0xFFFF, "prvTraceGetDTS: Invalid value for param_maxDTS", 0);\r
-\r
-#if (SELECTED_PORT != PORT_ARM_CortexM)\r
-\r
- if (RecorderDataPtr->frequency == 0 && init_hwtc_count != HWTC_COUNT)\r
- {\r
- /* If HWTC_PERIOD is mapped to the timer reload register,\r
- it might not be initialized before the scheduler has been started.\r
- We therefore store the frequency of the timer when the counter\r
- register has changed from its initial value.\r
- (Note that this function is called also by vTraceStart and\r
- uiTraceStart, which might be called before the scheduler\r
- has been started.) */\r
-\r
-#if (SELECTED_PORT == PORT_Win32)\r
- RecorderDataPtr->frequency = 100000;\r
-#elif (SELECTED_PORT == PORT_HWIndependent)\r
- RecorderDataPtr->frequency = TRACE_TICK_RATE_HZ;\r
-#else\r
- RecorderDataPtr->frequency = (HWTC_PERIOD * TRACE_TICK_RATE_HZ) / (uint32_t)HWTC_DIVISOR;\r
-#endif\r
- }\r
-#endif\r
- /**************************************************************************\r
- * The below statements read the timestamp from the timer port module.\r
- * If necessary, whole seconds are extracted using division while the rest\r
- * comes from the modulo operation.\r
- **************************************************************************/\r
-\r
- vTracePortGetTimeStamp(×tamp);\r
-\r
- /***************************************************************************\r
- * Since dts is unsigned the result will be correct even if timestamp has\r
- * wrapped around.\r
- ***************************************************************************/\r
- dts = timestamp - old_timestamp;\r
- old_timestamp = timestamp;\r
-\r
- if (RecorderDataPtr->frequency > 0)\r
- {\r
- /* Check if dts > 1 second */\r
- if (dts > RecorderDataPtr->frequency)\r
- {\r
- /* More than 1 second has passed */\r
- RecorderDataPtr->absTimeLastEventSecond += dts / RecorderDataPtr->frequency;\r
- /* The part that is not an entire second is added to absTimeLastEvent */\r
- RecorderDataPtr->absTimeLastEvent += dts % RecorderDataPtr->frequency;\r
- }\r
- else\r
- {\r
- RecorderDataPtr->absTimeLastEvent += dts;\r
- }\r
-\r
- /* Check if absTimeLastEvent >= 1 second */\r
- if (RecorderDataPtr->absTimeLastEvent >= RecorderDataPtr->frequency)\r
- {\r
- /* RecorderDataPtr->absTimeLastEvent is more than or equal to 1 second, but always less than 2 seconds */\r
- RecorderDataPtr->absTimeLastEventSecond++;\r
- RecorderDataPtr->absTimeLastEvent -= RecorderDataPtr->frequency;\r
- /* RecorderDataPtr->absTimeLastEvent is now less than 1 second */\r
- }\r
- }\r
- else\r
- {\r
- /* Special case if the recorder has not yet started (frequency may be uninitialized, i.e., zero) */\r
- RecorderDataPtr->absTimeLastEvent = timestamp;\r
- }\r
-\r
- /* If the dts (time since last event) does not fit in event->dts (only 8 or 16 bits) */\r
- if (dts > param_maxDTS)\r
- {\r
- /* Create an XTS event (eXtended TimeStamp) containing the higher dts bits*/\r
- xts = (XTSEvent*) xTraceNextFreeEventBufferSlot();\r
-\r
- if (xts != NULL)\r
- {\r
- if (param_maxDTS == 0xFFFF)\r
- {\r
- xts->type = XTS16;\r
- xts->xts_16 = (uint16_t)((dts / 0x10000) & 0xFFFF);\r
- xts->xts_8 = 0;\r
- }\r
- else if (param_maxDTS == 0xFF)\r
- {\r
- xts->type = XTS8;\r
- xts->xts_16 = (uint16_t)((dts / 0x100) & 0xFFFF);\r
- xts->xts_8 = (uint8_t)((dts / 0x1000000) & 0xFF);\r
- }\r
- else\r
- {\r
- vTraceError("Bad param_maxDTS in prvTraceGetDTS");\r
- }\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
-\r
- return (uint16_t)dts & param_maxDTS;\r
-}\r
-\r
-/*******************************************************************************\r
- * prvTraceLookupSymbolTableEntry\r
- *\r
- * Find an entry in the symbol table, return 0 if not present.\r
- *\r
- * The strings are stored in a byte pool, with four bytes of "meta-data" for\r
- * every string.\r
- * byte 0-1: index of next entry with same checksum (for fast lookup).\r
- * byte 2-3: reference to a symbol table entry, a label for vTracePrintF\r
- * format strings only (the handle of the destination channel).\r
- * byte 4..(4 + length): the string (object name or user event label), with\r
- * zero-termination\r
- ******************************************************************************/\r
-traceLabel prvTraceLookupSymbolTableEntry(const char* name,\r
- uint8_t crc6,\r
- uint8_t len,\r
- traceLabel chn)\r
-{\r
- uint16_t i = RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ];\r
-\r
- TRACE_ASSERT(name != NULL, "prvTraceLookupSymbolTableEntry: name == NULL", (traceLabel)0);\r
- TRACE_ASSERT(len != 0, "prvTraceLookupSymbolTableEntry: len == 0", (traceLabel)0);\r
-\r
- while (i != 0)\r
- {\r
- if (RecorderDataPtr->SymbolTable.symbytes[i + 2] == (chn & 0x00FF))\r
- {\r
- if (RecorderDataPtr->SymbolTable.symbytes[i + 3] == (chn / 0x100))\r
- {\r
- if (RecorderDataPtr->SymbolTable.symbytes[i + 4 + len] == '\0')\r
- {\r
- if (strncmp((char*)(& RecorderDataPtr->SymbolTable.symbytes[i + 4]), name, len) == 0)\r
- {\r
- break; /* found */\r
- }\r
- }\r
- }\r
- }\r
- i = (uint16_t)(RecorderDataPtr->SymbolTable.symbytes[i] + (RecorderDataPtr->SymbolTable.symbytes[i + 1] * 0x100));\r
- }\r
- return i;\r
-}\r
-\r
-/*******************************************************************************\r
- * prvTraceCreateSymbolTableEntry\r
- *\r
- * Creates an entry in the symbol table, independent if it exists already.\r
- *\r
- * The strings are stored in a byte pool, with four bytes of "meta-data" for\r
- * every string.\r
- * byte 0-1: index of next entry with same checksum (for fast lookup).\r
- * byte 2-3: reference to a symbol table entry, a label for vTracePrintF\r
- * format strings only (the handle of the destination channel).\r
- * byte 4..(4 + length): the string (object name or user event label), with\r
- * zero-termination\r
- ******************************************************************************/\r
-uint16_t prvTraceCreateSymbolTableEntry(const char* name,\r
- uint8_t crc6,\r
- uint8_t len,\r
- traceLabel channel)\r
-{\r
- uint16_t ret = 0;\r
-\r
- TRACE_ASSERT(name != NULL, "prvTraceCreateSymbolTableEntry: name == NULL", 0);\r
- TRACE_ASSERT(len != 0, "prvTraceCreateSymbolTableEntry: len == 0", 0);\r
-\r
- if (RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + len + 4 >= SYMBOL_TABLE_SIZE)\r
- {\r
- vTraceError("Symbol table full. Increase SYMBOL_TABLE_SIZE in trcConfig.h");\r
- ret = 0;\r
- }\r
- else\r
- {\r
-\r
- RecorderDataPtr->SymbolTable.symbytes\r
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex] =\r
- (uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] & 0x00FF);\r
-\r
- RecorderDataPtr->SymbolTable.symbytes\r
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 1] =\r
- (uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] / 0x100);\r
-\r
- RecorderDataPtr->SymbolTable.symbytes\r
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 2] =\r
- (uint8_t)(channel & 0x00FF);\r
-\r
- RecorderDataPtr->SymbolTable.symbytes\r
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 3] =\r
- (uint8_t)(channel / 0x100);\r
-\r
- /* set name (bytes 4...4+len-1) */\r
- (void)strncpy((char*)&(RecorderDataPtr->SymbolTable.symbytes\r
- [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4]), name, len);\r
-\r
- /* Set zero termination (at offset 4+len) */\r
- RecorderDataPtr->SymbolTable.symbytes\r
- [RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4 + len] = '\0';\r
-\r
- /* store index of entry (for return value, and as head of LL[crc6]) */\r
- RecorderDataPtr->SymbolTable.latestEntryOfChecksum\r
- [ crc6 ] = (uint16_t)RecorderDataPtr->SymbolTable.nextFreeSymbolIndex;\r
-\r
- RecorderDataPtr->SymbolTable.nextFreeSymbolIndex += (len + 5);\r
-\r
- ret = (uint16_t)(RecorderDataPtr->SymbolTable.nextFreeSymbolIndex -\r
- (len + 5));\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-\r
-/*******************************************************************************\r
- * prvTraceGetChecksum\r
- *\r
- * Calculates a simple 6-bit checksum from a string, used to index the string\r
- * for fast symbol table lookup.\r
- ******************************************************************************/\r
-void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength)\r
-{\r
- unsigned char c;\r
- int length = 1; /* Should be 1 to account for '\0' */\r
- int crc = 0;\r
-\r
- TRACE_ASSERT(pname != NULL, "prvTraceGetChecksum: pname == NULL", );\r
- TRACE_ASSERT(pcrc != NULL, "prvTraceGetChecksum: pcrc == NULL", );\r
- TRACE_ASSERT(plength != NULL, "prvTraceGetChecksum: plength == NULL", );\r
-\r
- if (pname != (const char *) 0)\r
- {\r
- for (; (c = *pname++) != '\0';)\r
- {\r
- crc += c;\r
- length++;\r
- }\r
- }\r
- *pcrc = (uint8_t)(crc & 0x3F);\r
- *plength = (uint8_t)length;\r
-}\r
-\r
-#if (USE_16BIT_OBJECT_HANDLES == 1)\r
-\r
-void prvTraceStoreXID(objectHandleType handle);\r
-\r
-/******************************************************************************\r
- * prvTraceStoreXID\r
- *\r
- * Stores an XID (eXtended IDentifier) event.\r
- * This is used if an object/task handle is larger than 255.\r
- * The parameter "handle" is the full (16 bit) handle, assumed to be 256 or\r
- * larger. Handles below 256 should not use this function.\r
- *\r
- * NOTE: this function MUST be called from within a critical section.\r
- *****************************************************************************/\r
-\r
-void prvTraceStoreXID(objectHandleType handle)\r
-{\r
- XPSEvent* xid;\r
-\r
- TRACE_ASSERT(handle >= 256, "prvTraceStoreXID: Handle < 256", );\r
-\r
- xid = (XPSEvent*)xTraceNextFreeEventBufferSlot();\r
-\r
- if (xid != NULL)\r
- {\r
- xid->type = XID;\r
-\r
- /* This function is (only) used when objectHandleType is 16 bit... */\r
- xid->xps_16 = handle;\r
-\r
- prvTraceUpdateCounters();\r
- }\r
-}\r
-\r
-unsigned char prvTraceGet8BitHandle(objectHandleType handle)\r
-{\r
- if (handle > 255)\r
- {\r
- prvTraceStoreXID(handle);\r
- /* The full handle (16 bit) is stored in the XID event.\r
- This code (255) is used instead of zero (which is an error code).*/\r
- return 255;\r
- }\r
- return (unsigned char)(handle & 0xFF);\r
-}\r
-\r
-#endif\r
-\r
-#endif\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcHardwarePort.c\r
- *\r
- * Contains together with trcHardwarePort.h all hardware portability issues of\r
- * the trace recorder library.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcPort.c and trcPort.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#include "trcHardwarePort.h"\r
-#include "trcKernelPort.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#include <stdint.h>\r
-\r
-uint32_t trace_disable_timestamp = 0;\r
-uint32_t last_timestamp = 0;\r
-\r
-/*******************************************************************************\r
- * uiTraceTickCount\r
- *\r
- * This variable is should be updated by the Kernel tick interrupt. This does\r
- * not need to be modified when developing a new timer port. It is preferred to\r
- * keep any timer port changes in the HWTC macro definitions, which typically\r
- * give sufficient flexibility.\r
- ******************************************************************************/\r
-uint32_t uiTraceTickCount = 0;\r
-\r
-uint32_t DWT_CYCLES_ADDED = 0; /* Used on ARM Cortex-M only */\r
-\r
-#if (SELECTED_PORT == PORT_ARM_CortexM)\r
-\r
-void prvTraceInitCortexM()\r
-{\r
- /* Make sure DWT is enabled is enabled, if supported */\r
- REG_DEMCR |= DEMCR_TRCENA;\r
-\r
- do{\r
- /* Verify that DWT is supported */\r
- if (REG_DEMCR == 0)\r
- {\r
- vTraceError("DWT not supported by this chip!");\r
- break;\r
- }\r
-\r
- /* Verify that DWT_CYCCNT is supported */\r
- if (REG_DWT_CTRL & DWT_CTRL_NOCYCCNT)\r
- {\r
- vTraceError("DWT_CYCCNT not supported by this chip!");\r
- break;\r
- }\r
-\r
- /* Reset the cycle counter */\r
- REG_DWT_CYCCNT = 0;\r
-\r
- /* Enable the cycle counter */\r
- REG_DWT_CTRL |= DWT_CTRL_CYCCNTENA;\r
-\r
- }while(0); /* breaks above jump here */\r
-\r
- if (RecorderDataPtr->frequency == 0)\r
- {\r
- RecorderDataPtr->frequency = TRACE_CPU_CLOCK_HZ / HWTC_DIVISOR;\r
- }\r
-}\r
-\r
-#endif\r
-\r
-/******************************************************************************\r
- * vTracePortGetTimeStamp\r
- *\r
- * Returns the current time based on the HWTC macros which provide a hardware\r
- * isolation layer towards the hardware timer/counter.\r
- *\r
- * The HWTC macros and vTracePortGetTimeStamp is the main porting issue\r
- * or the trace recorder library. Typically you should not need to change\r
- * the code of vTracePortGetTimeStamp if using the HWTC macros.\r
- *\r
- ******************************************************************************/\r
-void vTracePortGetTimeStamp(uint32_t *pTimestamp)\r
-{\r
- static uint32_t last_traceTickCount = 0;\r
- static uint32_t last_hwtc_count = 0;\r
- uint32_t traceTickCount = 0;\r
- uint32_t hwtc_count = 0;\r
-\r
- if (trace_disable_timestamp == 1)\r
- {\r
- if (pTimestamp)\r
- *pTimestamp = last_timestamp;\r
- return;\r
- }\r
-\r
- /* Retrieve HWTC_COUNT only once since the same value should be used all throughout this function. */\r
-#if (HWTC_COUNT_DIRECTION == DIRECTION_INCREMENTING)\r
- hwtc_count = HWTC_COUNT;\r
-#elif (HWTC_COUNT_DIRECTION == DIRECTION_DECREMENTING)\r
- hwtc_count = HWTC_PERIOD - HWTC_COUNT;\r
-#else\r
- Junk text to cause compiler error - HWTC_COUNT_DIRECTION is not set correctly!\r
- Should be DIRECTION_INCREMENTING or DIRECTION_DECREMENTING\r
-#endif\r
-\r
-#if (SELECTED_PORT == PORT_Win32)\r
- /* The Win32 port uses ulGetRunTimeCounterValue for timestamping, which in turn\r
- uses QueryPerformanceCounter. That function is not always reliable when used over\r
- multiple threads. We must therefore handle rare cases where the timestamp is less\r
- than the previous. In practice, the Win32 should "never" roll over since the\r
- performance counter is 64 bit wide. */\r
-\r
- if (last_hwtc_count > hwtc_count)\r
- {\r
- hwtc_count = last_hwtc_count;\r
- }\r
-#endif\r
-\r
- if (last_traceTickCount - uiTraceTickCount - 1 < 0x80000000)\r
- {\r
- /* This means last_traceTickCount is higher than uiTraceTickCount,\r
- so we have previously compensated for a missed tick.\r
- Therefore we use the last stored value because that is more accurate. */\r
- traceTickCount = last_traceTickCount;\r
- }\r
- else\r
- {\r
- /* Business as usual */\r
- traceTickCount = uiTraceTickCount;\r
- }\r
-\r
- /* Check for overflow. May occur if the update of uiTraceTickCount has been\r
- delayed due to disabled interrupts. */\r
- if (traceTickCount == last_traceTickCount && hwtc_count < last_hwtc_count)\r
- {\r
- /* A trace tick has occurred but not been executed by the kernel, so we compensate manually. */\r
- traceTickCount++;\r
- }\r
-\r
- /* Check if the return address is OK, then we perform the calculation. */\r
- if (pTimestamp)\r
- {\r
- /* Get timestamp from trace ticks. Scale down the period to avoid unwanted overflows. */\r
- *pTimestamp = traceTickCount * (HWTC_PERIOD / HWTC_DIVISOR);\r
- /* Increase timestamp by (hwtc_count + "lost hardware ticks from scaling down period") / HWTC_DIVISOR. */\r
- *pTimestamp += (hwtc_count + traceTickCount * (HWTC_PERIOD % HWTC_DIVISOR)) / HWTC_DIVISOR;\r
-\r
- last_timestamp = *pTimestamp;\r
- }\r
-\r
- /* Store the previous values. */\r
- last_traceTickCount = traceTickCount;\r
- last_hwtc_count = hwtc_count;\r
-}\r
-\r
-#endif\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcKernel.c\r
- *\r
- * Functions used by trcKernelHooks.h for storing various kernel events.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-\r
-#include "trcKernel.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#include <stdint.h>\r
-\r
-/* Internal variables */\r
-int8_t nISRactive = 0;\r
-objectHandleType handle_of_last_logged_task = 0;\r
-uint8_t inExcludedTask = 0;\r
-\r
-#if (INCLUDE_MEMMANG_EVENTS == 1) && (TRACE_SCHEDULING_ONLY == 0)\r
- /* Current heap usage. Always updated. */\r
- static uint32_t heapMemUsage = 0;\r
-#endif\r
-\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
-static uint32_t prvTraceGetParam(uint32_t, uint32_t);\r
-#endif\r
-\r
-#if !defined INCLUDE_READY_EVENTS || INCLUDE_READY_EVENTS == 1\r
-\r
-static int readyEventsEnabled = 1;\r
-\r
-void vTraceSetReadyEventsEnabled(int status)\r
-{\r
- readyEventsEnabled = status;\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStoreTaskReady\r
- *\r
- * This function stores a ready state for the task handle sent in as parameter.\r
- ******************************************************************************/\r
-void vTraceStoreTaskReady(objectHandleType handle)\r
-{\r
- uint16_t dts3;\r
- TREvent* tr;\r
- uint8_t hnd8;\r
-\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- if (handle == 0)\r
- {\r
- /* On FreeRTOS v7.3.0, this occurs when creating tasks due to a bad\r
- placement of the trace macro. In that case, the events are ignored. */\r
- return;\r
- }\r
- \r
- if (! readyEventsEnabled)\r
- {\r
- /* When creating tasks, ready events are also created. If creating \r
- a "hidden" (not traced) task, we must therefore disable recording \r
- of ready events to avoid an undesired ready event... */\r
- return;\r
- }\r
-\r
- TRACE_ASSERT(handle <= NTask, "vTraceStoreTaskReady: Invalid value for handle", );\r
-\r
- if (recorder_busy)\r
- {\r
- /***********************************************************************\r
- * This should never occur, as the tick- and kernel call ISR is on lowest\r
- * interrupt priority and always are disabled during the critical sections\r
- * of the recorder.\r
- ***********************************************************************/\r
-\r
- vTraceError("Recorder busy - high priority ISR using syscall? (1)");\r
- return;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */\r
- {\r
- if (!TRACE_GET_TASK_FLAG_ISEXCLUDED(handle))\r
- {\r
- dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
- hnd8 = prvTraceGet8BitHandle(handle);\r
- tr = (TREvent*)xTraceNextFreeEventBufferSlot();\r
- if (tr != NULL)\r
- {\r
- tr->type = DIV_TASK_READY;\r
- tr->dts = dts3;\r
- tr->objHandle = hnd8;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-}\r
-#endif\r
-\r
-/*******************************************************************************\r
- * vTraceStoreLowPower\r
- *\r
- * This function stores a low power state.\r
- ******************************************************************************/\r
-void vTraceStoreLowPower(uint32_t flag)\r
-{\r
- uint16_t dts;\r
- LPEvent* lp;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- TRACE_ASSERT(flag <= 1, "vTraceStoreLowPower: Invalid flag value", );\r
-\r
- if (recorder_busy)\r
- {\r
- /***********************************************************************\r
- * This should never occur, as the tick- and kernel call ISR is on lowest\r
- * interrupt priority and always are disabled during the critical sections\r
- * of the recorder.\r
- ***********************************************************************/\r
-\r
- vTraceError("Recorder busy - high priority ISR using syscall? (1)");\r
- return;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive)\r
- {\r
- dts = (uint16_t)prvTraceGetDTS(0xFFFF);\r
- lp = (LPEvent*)xTraceNextFreeEventBufferSlot();\r
- if (lp != NULL)\r
- {\r
- lp->type = LOW_POWER_BEGIN + ( uint8_t ) flag; /* BEGIN or END depending on flag */\r
- lp->dts = dts;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStoreMemMangEvent\r
- *\r
- * This function stores malloc and free events. Each call requires two records,\r
- * for size and address respectively. The event code parameter (ecode) is applied\r
- * to the first record (size) and the following address record gets event\r
- * code "ecode + 1", so make sure this is respected in the event code table.\r
- * Note: On "free" calls, the signed_size parameter should be negative.\r
- ******************************************************************************/\r
-#if (INCLUDE_MEMMANG_EVENTS == 1)\r
-void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_size)\r
-{ \r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- uint8_t dts1;\r
- MemEventSize * ms;\r
- MemEventAddr * ma;\r
- uint16_t size_low;\r
- uint16_t addr_low;\r
- uint8_t addr_high;\r
- uint32_t size;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- if (RecorderDataPtr == NULL) // This happens in vTraceInitTraceData, if using dynamic allocation...\r
- return;\r
- \r
- if (signed_size < 0)\r
- size = (uint32_t)(- signed_size);\r
- else\r
- size = (uint32_t)(signed_size);\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- \r
- heapMemUsage += signed_size;\r
- \r
- if (RecorderDataPtr->recorderActive)\r
- {\r
- /* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */\r
- if (nISRactive || !inExcludedTask)\r
- {\r
- dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
- size_low = (uint16_t)prvTraceGetParam(0xFFFF, size);\r
- ms = (MemEventSize *)xTraceNextFreeEventBufferSlot();\r
-\r
- if (ms != NULL)\r
- {\r
- ms->dts = dts1;\r
- ms->type = NULL_EVENT; /* Updated when all events are written */\r
- ms->size = size_low;\r
- prvTraceUpdateCounters();\r
-\r
- /* Storing a second record with address (signals "failed" if null) */\r
- #if (HEAP_SIZE_BELOW_16M)\r
- /* If the heap address range is within 16 MB, i.e., the upper 8 bits\r
- of addresses are constant, this optimization avoids storing an extra\r
- event record by ignoring the upper 8 bit of the address */\r
- addr_low = address & 0xFFFF; \r
- addr_high = (address >> 16) & 0xFF;\r
- #else\r
- /* The whole 32 bit address is stored using a second event record\r
- for the upper 16 bit */\r
- addr_low = (uint16_t)prvTraceGetParam(0xFFFF, address);\r
- addr_high = 0;\r
- #endif\r
-\r
- ma = (MemEventAddr *) xTraceNextFreeEventBufferSlot();\r
- if (ma != NULL)\r
- {\r
- ma->addr_low = addr_low;\r
- ma->addr_high = addr_high;\r
- ma->type = ( ( uint8_t) ecode ) + 1; /* Note this! */\r
- ms->type = (uint8_t)ecode;\r
- prvTraceUpdateCounters(); \r
- RecorderDataPtr->heapMemUsage = heapMemUsage;\r
- }\r
- }\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-#endif\r
-\r
-/*******************************************************************************\r
- * vTraceStoreKernelCall\r
- *\r
- * This is the main integration point for storing kernel calls, and\r
- * is called by the hooks in trcKernelHooks.h (see trcKernelPort.h for event codes).\r
- ******************************************************************************/\r
-void vTraceStoreKernelCall(uint32_t ecode, traceObjectClass objectClass, uint32_t objectNumber)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- KernelCall * kse;\r
- uint16_t dts1;\r
- uint8_t hnd8;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- TRACE_ASSERT(ecode < 0xFF, "vTraceStoreKernelCall: ecode >= 0xFF", );\r
- TRACE_ASSERT(objectClass < TRACE_NCLASSES, "vTraceStoreKernelCall: objectClass >= TRACE_NCLASSES", );\r
- TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "vTraceStoreKernelCall: Invalid value for objectNumber", );\r
-\r
- if (recorder_busy)\r
- {\r
- /*************************************************************************\r
- * This may occur if a high-priority ISR is illegally using a system call,\r
- * or creates a user event.\r
- * Only ISRs that are disabled by TRACE_ENTER_CRITICAL_SECTION may use system calls\r
- * or user events (see TRACE_MAX_SYSCALL_INTERRUPT_PRIORITY).\r
- *************************************************************************/\r
-\r
- vTraceError("Recorder busy - high priority ISR using syscall? (2)");\r
- return;\r
- }\r
-\r
- if (handle_of_last_logged_task == 0)\r
- {\r
- return;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive)\r
- {\r
- /* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */\r
- if (nISRactive || !inExcludedTask)\r
- {\r
- /* Check if the referenced object or the event code is excluded */\r
- if (!uiTraceIsObjectExcluded(objectClass, (objectHandleType)objectNumber) && !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(ecode))\r
- {\r
- dts1 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
- hnd8 = prvTraceGet8BitHandle(objectNumber);\r
- kse = (KernelCall*) xTraceNextFreeEventBufferSlot();\r
- if (kse != NULL)\r
- {\r
- kse->dts = dts1;\r
- kse->type = (uint8_t)ecode;\r
- kse->objHandle = hnd8;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStoreKernelCallWithParam\r
- *\r
- * Used for storing kernel calls with a handle and a numeric parameter. If the\r
- * numeric parameter does not fit in one byte, and extra XPS event is inserted\r
- * before the kernel call event containing the three upper bytes.\r
- ******************************************************************************/\r
-void vTraceStoreKernelCallWithParam(uint32_t evtcode,\r
- traceObjectClass objectClass,\r
- uint32_t objectNumber,\r
- uint32_t param)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- KernelCallWithParamAndHandle * kse;\r
- uint8_t dts2;\r
- uint8_t hnd8;\r
- uint8_t p8;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- TRACE_ASSERT(evtcode < 0xFF, "vTraceStoreKernelCall: evtcode >= 0xFF", );\r
- TRACE_ASSERT(objectClass < TRACE_NCLASSES, "vTraceStoreKernelCallWithParam: objectClass >= TRACE_NCLASSES", );\r
- TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "vTraceStoreKernelCallWithParam: Invalid value for objectNumber", );\r
-\r
- if (recorder_busy)\r
- {\r
- /*************************************************************************\r
- * This may occur if a high-priority ISR is illegally using a system call,\r
- * or creates a user event.\r
- * Only ISRs that are disabled by TRACE_ENTER_CRITICAL_SECTION may use system calls\r
- * or user events (see TRACE_MAX_SYSCALL_INTERRUPT_PRIORITY).\r
- *************************************************************************/\r
-\r
- vTraceError("Recorder busy - high priority ISR using syscall? (3)");\r
- return;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task && (! inExcludedTask || nISRactive))\r
- {\r
- /* Check if the referenced object or the event code is excluded */\r
- if (!uiTraceIsObjectExcluded(objectClass, (objectHandleType)objectNumber) &&\r
- !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))\r
- {\r
- dts2 = (uint8_t)prvTraceGetDTS(0xFF);\r
- p8 = (uint8_t) prvTraceGetParam(0xFF, param);\r
- hnd8 = prvTraceGet8BitHandle((objectHandleType)objectNumber);\r
- kse = (KernelCallWithParamAndHandle*) xTraceNextFreeEventBufferSlot();\r
- if (kse != NULL)\r
- {\r
- kse->dts = dts2;\r
- kse->type = (uint8_t)evtcode;\r
- kse->objHandle = hnd8;\r
- kse->param = p8;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
-\r
-/*******************************************************************************\r
- * prvTraceGetParam\r
- *\r
- * Used for storing extra bytes for kernel calls with numeric parameters.\r
- *\r
- * May only be called within a critical section!\r
- ******************************************************************************/\r
-static uint32_t prvTraceGetParam(uint32_t param_max, uint32_t param)\r
-{\r
- XPSEvent* xps;\r
-\r
- TRACE_ASSERT(param_max == 0xFF || param_max == 0xFFFF,\r
- "prvTraceGetParam: Invalid value for param_max", param);\r
-\r
- if (param <= param_max)\r
- {\r
- return param;\r
- }\r
- else\r
- {\r
- xps = (XPSEvent*) xTraceNextFreeEventBufferSlot();\r
- if (xps != NULL)\r
- {\r
- xps->type = DIV_XPS;\r
- xps->xps_8 = (param & (0xFF00 & ~param_max)) >> 8;\r
- xps->xps_16 = (param & (0xFFFF0000 & ~param_max)) >> 16;\r
- prvTraceUpdateCounters();\r
- }\r
-\r
- return param & param_max;\r
- }\r
-}\r
-#endif\r
-\r
-/*******************************************************************************\r
- * vTraceStoreKernelCallWithNumericParamOnly\r
- *\r
- * Used for storing kernel calls with numeric parameters only. This is\r
- * only used for traceTASK_DELAY and traceDELAY_UNTIL at the moment.\r
- ******************************************************************************/\r
-void vTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- KernelCallWithParam16 * kse;\r
- uint8_t dts6;\r
- uint16_t restParam;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- restParam = 0;\r
-\r
- TRACE_ASSERT(evtcode < 0xFF,\r
- "vTraceStoreKernelCallWithNumericParamOnly: Invalid value for evtcode", );\r
-\r
- if (recorder_busy)\r
- {\r
- /*************************************************************************\r
- * This may occur if a high-priority ISR is illegally using a system call,\r
- * or creates a user event.\r
- * Only ISRs that are disabled by TRACE_ENTER_CRITICAL_SECTION may use system calls\r
- * or user events (see TRACE_MAX_SYSCALL_INTERRUPT_PRIORITY).\r
- *************************************************************************/\r
-\r
- vTraceError("Recorder busy - high priority ISR using syscall? (4)");\r
- return;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task\r
- && (! inExcludedTask || nISRactive))\r
- {\r
- /* Check if the event code is excluded */\r
- if (!TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))\r
- {\r
- dts6 = (uint8_t)prvTraceGetDTS(0xFF);\r
- restParam = (uint16_t)prvTraceGetParam(0xFFFF, param);\r
- kse = (KernelCallWithParam16*) xTraceNextFreeEventBufferSlot();\r
- if (kse != NULL)\r
- {\r
- kse->dts = dts6;\r
- kse->type = (uint8_t)evtcode;\r
- kse->param = restParam;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStoreTaskswitch\r
- * Called by the scheduler from the SWITCHED_OUT hook, and by uiTraceStart.\r
- * At this point interrupts are assumed to be disabled!\r
- ******************************************************************************/\r
-void vTraceStoreTaskswitch(objectHandleType task_handle)\r
-{\r
- uint16_t dts3;\r
- TSEvent* ts;\r
- int8_t skipEvent;\r
- uint8_t hnd8;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- skipEvent = 0;\r
-\r
- TRACE_ASSERT(task_handle <= NTask,\r
- "vTraceStoreTaskswitch: Invalid value for task_handle", );\r
-\r
- /***************************************************************************\r
- This is used to detect if a high-priority ISRs is illegally using the\r
- recorder ISR trace functions (vTraceStoreISRBegin and ...End) while the\r
- recorder is busy with a task-level event or lower priority ISR event.\r
-\r
- If this is detected, it triggers a call to vTraceError with the error\r
- "Illegal call to vTraceStoreISRBegin/End". If you get this error, it means\r
- that the macro trcCRITICAL_SECTION_BEGIN does not disable this ISR, as required.\r
-\r
- Note: Setting recorder_busy is normally handled in our macros\r
- trcCRITICAL_SECTION_BEGIN and _END, but is needed explicitly in this\r
- function since critical sections should not be used in the context switch\r
- event...)\r
- ***************************************************************************/\r
-\r
- /* Skip the event if the task has been excluded, using vTraceExcludeTask */\r
- if (TRACE_GET_TASK_FLAG_ISEXCLUDED(task_handle))\r
- {\r
- skipEvent = 1;\r
- inExcludedTask = 1;\r
- }\r
- else\r
- {\r
- inExcludedTask = 0;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY();\r
-\r
- /* Skip the event if the same task is scheduled */\r
- if (task_handle == handle_of_last_logged_task)\r
- {\r
- skipEvent = 1;\r
- }\r
-\r
- if (!RecorderDataPtr->recorderActive)\r
- {\r
- skipEvent = 1;\r
- }\r
-\r
- /* If this event should be logged, log it! */\r
- if (skipEvent == 0)\r
- {\r
- dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
- handle_of_last_logged_task = task_handle;\r
- hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);\r
- ts = (TSEvent*)xTraceNextFreeEventBufferSlot();\r
-\r
- if (ts != NULL)\r
- {\r
- if (uiTraceGetObjectState(TRACE_CLASS_TASK,\r
- handle_of_last_logged_task) == TASK_STATE_INSTANCE_ACTIVE)\r
- {\r
- ts->type = TS_TASK_RESUME;\r
- }\r
- else\r
- {\r
- ts->type = TS_TASK_BEGIN;\r
- }\r
-\r
- ts->dts = dts3;\r
- ts->objHandle = hnd8;\r
-\r
- vTraceSetObjectState(TRACE_CLASS_TASK,\r
- handle_of_last_logged_task,\r
- TASK_STATE_INSTANCE_ACTIVE);\r
-\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
-\r
- trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY();\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStoreNameCloseEvent\r
- *\r
- * Updates the symbol table with the name of this object from the dynamic\r
- * objects table and stores a "close" event, holding the mapping between handle\r
- * and name (a symbol table handle). The stored name-handle mapping is thus the\r
- * "old" one, valid up until this point.\r
- ******************************************************************************/\r
-#if (INCLUDE_OBJECT_DELETE == 1)\r
-void vTraceStoreObjectNameOnCloseEvent(objectHandleType handle,\r
- traceObjectClass objectclass)\r
-{\r
- ObjCloseNameEvent * ce;\r
- const char * name;\r
- traceLabel idx;\r
-\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "vTraceStoreObjectNameOnCloseEvent: objectclass >= TRACE_NCLASSES", );\r
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "vTraceStoreObjectNameOnCloseEvent: Invalid value for handle", );\r
-\r
- if (RecorderDataPtr->recorderActive)\r
- {\r
- uint8_t hnd8 = prvTraceGet8BitHandle(handle);\r
- name = TRACE_PROPERTY_NAME_GET(objectclass, handle);\r
- idx = prvTraceOpenSymbol(name, 0);\r
-\r
- // Interrupt disable not necessary, already done in trcHooks.h macro\r
- ce = (ObjCloseNameEvent*) xTraceNextFreeEventBufferSlot();\r
- if (ce != NULL)\r
- {\r
- ce->type = EVENTGROUP_OBJCLOSE_NAME + objectclass;\r
- ce->objHandle = hnd8;\r
- ce->symbolIndex = idx;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
-}\r
-\r
-void vTraceStoreObjectPropertiesOnCloseEvent(objectHandleType handle,\r
- traceObjectClass objectclass)\r
-{\r
- ObjClosePropEvent * pe;\r
-\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "vTraceStoreObjectPropertiesOnCloseEvent: objectclass >= TRACE_NCLASSES", );\r
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "vTraceStoreObjectPropertiesOnCloseEvent: Invalid value for handle", );\r
-\r
- if (RecorderDataPtr->recorderActive)\r
- {\r
- // Interrupt disable not necessary, already done in trcHooks.h macro\r
- pe = (ObjClosePropEvent*) xTraceNextFreeEventBufferSlot();\r
- if (pe != NULL)\r
- {\r
- if (objectclass == TRACE_CLASS_TASK)\r
- {\r
- pe->arg1 = TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle);\r
- }\r
- else\r
- {\r
- pe->arg1 = TRACE_PROPERTY_OBJECT_STATE(objectclass, handle);\r
- }\r
- pe->type = EVENTGROUP_OBJCLOSE_PROP + objectclass;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
-}\r
-#endif\r
-\r
-void vTraceSetPriorityProperty(uint8_t objectclass, objectHandleType id, uint8_t value)\r
-{\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "vTraceSetPriorityProperty: objectclass >= TRACE_NCLASSES", );\r
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "vTraceSetPriorityProperty: Invalid value for id", );\r
-\r
- TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id) = value;\r
-}\r
-\r
-uint8_t uiTraceGetPriorityProperty(uint8_t objectclass, objectHandleType id)\r
-{\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "uiTraceGetPriorityProperty: objectclass >= TRACE_NCLASSES", 0);\r
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "uiTraceGetPriorityProperty: Invalid value for id", 0);\r
-\r
- return TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id);\r
-}\r
-\r
-void vTraceSetObjectState(uint8_t objectclass, objectHandleType id, uint8_t value)\r
-{\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "vTraceSetObjectState: objectclass >= TRACE_NCLASSES", );\r
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "vTraceSetObjectState: Invalid value for id", );\r
-\r
- TRACE_PROPERTY_OBJECT_STATE(objectclass, id) = value;\r
-}\r
-\r
-uint8_t uiTraceGetObjectState(uint8_t objectclass, objectHandleType id)\r
-{\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
- "uiTraceGetObjectState: objectclass >= TRACE_NCLASSES", 0);\r
- TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
- "uiTraceGetObjectState: Invalid value for id", 0);\r
-\r
- return TRACE_PROPERTY_OBJECT_STATE(objectclass, id);\r
-}\r
-\r
-void vTraceSetTaskInstanceFinished(objectHandleType handle)\r
-{\r
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_TASK],\r
- "vTraceSetTaskInstanceFinished: Invalid value for handle", );\r
-\r
-#if (USE_IMPLICIT_IFE_RULES == 1)\r
- TRACE_PROPERTY_OBJECT_STATE(TRACE_CLASS_TASK, handle) = 0;\r
-#endif\r
-}\r
-\r
-#endif\r
/*******************************************************************************\r
- * Tracealyzer v2.7.7 Recorder Library\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
* Percepio AB, www.percepio.com\r
*\r
* trcKernelPort.c\r
*\r
- * Kernel-specific functionality for FreeRTOS, used by the recorder library.\r
+ * The FreeRTOS-specific parts of the trace recorder\r
*\r
* Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
+ * This file is part of the trace recorder library (RECORDER), which is the\r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a\r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block.\r
*\r
* Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the\r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
*\r
* Tabs are used for indent in this file (1 tab = 4 spaces)\r
*\r
- * Copyright Percepio AB, 2012-2015.\r
+ * Copyright Percepio AB, 2017.\r
* www.percepio.com\r
******************************************************************************/\r
\r
-#include "trcKernelPort.h"\r
+#include "FreeRTOS.h"\r
\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
+#if (!defined(TRC_USE_TRACEALYZER_RECORDER) && configUSE_TRACE_FACILITY == 1)\r
+#error Trace Recorder: You need to include trcRecorder.h at the end of your FreeRTOSConfig.h!\r
+#endif\r
+\r
+#if (defined(TRC_USE_TRACEALYZER_RECORDER) && TRC_USE_TRACEALYZER_RECORDER == 1)\r
+\r
+#if (configUSE_TICKLESS_IDLE != 0 && (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR))\r
+ /*\r
+ The below error message is to alert you on the following issue:\r
+\r
+ The hardware port selected in trcConfig.h uses the operating system timer for the\r
+ timestamping, i.e., the periodic interrupt timer that drives the OS tick interrupt.\r
+\r
+ When using tickless idle, the recorder needs an independent time source in order to\r
+ correctly record the durations of the idle times. Otherwise, the trace may appear\r
+ to have a different length than in reality, and the reported CPU load is also affected.\r
+\r
+ You may override this warning by defining the TRC_CFG_ACKNOWLEDGE_TICKLESS_IDLE_WARNING\r
+ macro in your trcConfig.h file. But then the time scale may be incorrect during\r
+ tickless idle periods.\r
\r
-#include <stdint.h>\r
+ To get this correct, override the default timestamping by setting TRC_CFG_HARDWARE_PORT\r
+ in trcConfig.h to TRC_HARDWARE_PORT_APPLICATION_DEFINED and define the HWTC macros\r
+ accordingly, using a free running counter or an independent periodic interrupt timer.\r
+ See trcHardwarePort.h for details.\r
+\r
+ For ARM Cortex-M3, M4 and M7 MCUs this is not an issue, since the recorder uses the\r
+ DWT cycle counter for timestamping in these cases.\r
+ */\r
+\r
+ #ifndef TRC_CFG_ACKNOWLEDGE_TICKLESS_IDLE_WARNING\r
+ #error Trace Recorder: This timestamping mode is not recommended with Tickless Idle.\r
+ #endif\r
+#endif\r
\r
#include "task.h"\r
+#include "queue.h"\r
\r
-/* For classes implemented as FreeRTOS Queues:\r
-This translates queue.type to the corresponding trace object class. */\r
-traceObjectClass TraceObjectClassTable[5] = {\r
- TRACE_CLASS_QUEUE,\r
- TRACE_CLASS_MUTEX,\r
- TRACE_CLASS_SEMAPHORE,\r
- TRACE_CLASS_SEMAPHORE,\r
- TRACE_CLASS_MUTEX\r
-};\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
\r
-int uiInEventGroupSetBitsFromISR = 0;\r
+static void* pCurrentTCB = NULL;\r
+#if (defined(configENABLE_BACKWARD_COMPATIBILITY) && configENABLE_BACKWARD_COMPATIBILITY == 0)\r
+/* We're explicitly not using compatibility mode */\r
+static TaskHandle_t HandleTzCtrl = NULL; /* TzCtrl task TCB */\r
+#else\r
+/* We're using compatibility mode, or we're running an old kernel */\r
+static xTaskHandle HandleTzCtrl = NULL; /* TzCtrl task TCB */\r
+#endif\r
+\r
+#if (configSUPPORT_STATIC_ALLOCATION == 1)\r
+static StackType_t stackTzCtrl[TRC_CFG_CTRL_TASK_STACK_SIZE];\r
+static StaticTask_t tcbTzCtrl;\r
+#endif\r
+\r
+/* Monitored by TzCtrl task, that give warnings as User Events */\r
+extern volatile uint32_t NoRoomForSymbol;\r
+extern volatile uint32_t NoRoomForObjectData;\r
+extern volatile uint32_t LongestSymbolName;\r
+extern volatile uint32_t MaxBytesTruncated;\r
+\r
+/* Keeps track of previous values, to only react on changes. */\r
+static uint32_t NoRoomForSymbol_last = 0;\r
+static uint32_t NoRoomForObjectData_last = 0;\r
+static uint32_t LongestSymbolName_last = 0;\r
+static uint32_t MaxBytesTruncated_last = 0;\r
\r
-extern unsigned char ucQueueGetQueueType(void*);\r
+/* User Event Channel for giving warnings regarding NoRoomForSymbol etc. */\r
+traceString trcWarningChannel;\r
\r
-#if (FREERTOS_VERSION < FREERTOS_VERSION_8_0_OR_LATER)\r
+#define TRC_PORT_MALLOC(size) pvPortMalloc(size)\r
\r
-extern portBASE_TYPE ucQueueGetQueueNumber(void*);\r
+TRC_STREAM_PORT_ALLOCATE_FIELDS()\r
\r
-objectHandleType prvTraceGetObjectNumber(void* handle)\r
+/* Called by TzCtrl task periodically (Normally every 100 ms) */\r
+static void prvCheckRecorderStatus(void);\r
+\r
+/* The TzCtrl task - receives commands from Tracealyzer (start/stop) */\r
+static portTASK_FUNCTION( TzCtrl, pvParameters );\r
+\r
+/*******************************************************************************\r
+ * vTraceEnable\r
+ *\r
+ * Function that enables the tracing and creates the control task. It will halt\r
+ * execution until a Start command has been received if haltUntilStart is true.\r
+ *\r
+ ******************************************************************************/\r
+void vTraceEnable(int startOption)\r
{\r
- return (objectHandleType) ucQueueGetQueueNumber(handle);\r
-}\r
+ int bytes = 0;\r
+ extern uint32_t RecorderEnabled;\r
+ TracealyzerCommandType msg;\r
+\r
+ if (HandleTzCtrl != NULL)\r
+ return; /* Seems we already initiated */\r
+\r
+ TRC_STREAM_PORT_INIT();\r
+\r
+ if (startOption == TRC_START_AWAIT_HOST)\r
+ {\r
+ /* We keep trying to read commands until the recorder has been started */\r
+ do\r
+ {\r
+ bytes = 0;\r
+ TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), &bytes);\r
\r
+ if (bytes == sizeof(TracealyzerCommandType))\r
+ {\r
+ if (prvIsValidCommand(&msg))\r
+ {\r
+ if (msg.cmdCode == CMD_SET_ACTIVE && msg.param1 == 1)\r
+ {\r
+ /* On start, init and reset the timestamping */\r
+ TRC_PORT_SPECIFIC_INIT();\r
+ }\r
+\r
+ prvProcessCommand(&msg);\r
+ }\r
+ }\r
+ }\r
+ while (RecorderEnabled == 0);\r
+ }\r
+ else if (startOption == TRC_START)\r
+ {\r
+ /* We start streaming directly - this assumes that the interface is ready! */\r
+ TRC_PORT_SPECIFIC_INIT();\r
+\r
+ msg.cmdCode = CMD_SET_ACTIVE;\r
+ msg.param1 = 1;\r
+ prvProcessCommand(&msg);\r
+ }\r
+ else\r
+ {\r
+ /* On TRC_INIT */\r
+ TRC_PORT_SPECIFIC_INIT();\r
+ }\r
+\r
+ trcWarningChannel = xTraceRegisterString("Warnings from Recorder");\r
+\r
+ /* Creates the TzCtrl task - receives trace commands (start, stop, ...) */\r
+#if (configSUPPORT_STATIC_ALLOCATION == 1)\r
+ HandleTzCtrl = xTaskCreateStatic(TzCtrl, "TzCtrl", TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, stackTzCtrl, &tcbTzCtrl);\r
+ (void)HandleTzCtrl;\r
#else\r
+ xTaskCreate( TzCtrl, "TzCtrl", TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, &HandleTzCtrl );\r
+#endif\r
+}\r
\r
-extern portBASE_TYPE uxQueueGetQueueNumber(void*);\r
+/*******************************************************************************\r
+ * prvTraceOnBegin\r
+ *\r
+ * Called on trace begin.\r
+ ******************************************************************************/\r
+void prvTraceOnBegin()\r
+{\r
+ TRC_STREAM_PORT_ON_TRACE_BEGIN();\r
+}\r
\r
-objectHandleType prvTraceGetObjectNumber(void* handle)\r
+/*******************************************************************************\r
+ * prvTraceOnEnd\r
+ *\r
+ * Called on trace end.\r
+ ******************************************************************************/\r
+void prvTraceOnEnd()\r
{\r
- return (objectHandleType) uxQueueGetQueueNumber(handle);\r
+ TRC_STREAM_PORT_ON_TRACE_END();\r
}\r
\r
-#endif\r
+/*******************************************************************************\r
+ * vTraceSetQueueName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Queue that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Queue objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetQueueName(void* object, const char* name)\r
+{\r
+ vTraceStoreKernelObjectName(object, name);\r
+}\r
\r
-unsigned char prvTraceGetObjectType(void* handle)\r
+/*******************************************************************************\r
+ * vTraceSetSemaphoreName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Semaphore that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Semaphore objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetSemaphoreName(void* object, const char* name)\r
{\r
- return ucQueueGetQueueType(handle);\r
+ vTraceStoreKernelObjectName(object, name);\r
}\r
\r
-objectHandleType prvTraceGetTaskNumber(void* handle)\r
+/*******************************************************************************\r
+ * vTraceSetMutexName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Mutex that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Semaphore objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetMutexName(void* object, const char* name)\r
{\r
- return (objectHandleType)uxTaskGetTaskNumber(handle);\r
+ vTraceStoreKernelObjectName(object, name);\r
}\r
\r
-unsigned char prvTraceIsSchedulerActive()\r
+/*******************************************************************************\r
+ * prvGetCurrentTaskHandle\r
+ *\r
+ * Function that returns the handle to the currently executing task.\r
+ *\r
+ ******************************************************************************/\r
+void* prvTraceGetCurrentTaskHandle(void)\r
+{\r
+ return xTaskGetCurrentTaskHandle();\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvIsNewTCB\r
+ *\r
+ * Tells if this task is already executing, or if there has been a task-switch.\r
+ * Assumed to be called within a trace hook in kernel context.\r
+ ******************************************************************************/\r
+uint32_t prvIsNewTCB(void* pNewTCB)\r
{\r
- return xTaskGetSchedulerState() == taskSCHEDULER_RUNNING;\r
+ if (pCurrentTCB != pNewTCB)\r
+ {\r
+ pCurrentTCB = pNewTCB;\r
+ return 1;\r
+ }\r
+ return 0;\r
}\r
\r
+/*******************************************************************************\r
+ * prvTraceIsSchedulerSuspended\r
+ *\r
+ * Returns true if the RTOS scheduler currently is disabled, thus preventing any\r
+ * task-switches from occurring. Only called from vTraceStoreISREnd.\r
+ ******************************************************************************/\r
unsigned char prvTraceIsSchedulerSuspended()\r
{\r
+ /* Assumed to be available in FreeRTOS. According to the FreeRTOS docs,\r
+ INCLUDE_xTaskGetSchedulerState or configUSE_TIMERS must be set to 1 in\r
+ FreeRTOSConfig.h for this function to be available. */\r
+\r
return xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED;\r
}\r
\r
-unsigned char prvTraceIsSchedulerStarted()\r
+\r
+/*******************************************************************************\r
+ * prvCheckRecorderStatus\r
+ *\r
+ * Called by TzCtrl task periodically (every 100 ms - seems reasonable).\r
+ * Checks a number of diagnostic variables and give warnings as user events,\r
+ * in most cases including a suggested solution.\r
+ ******************************************************************************/\r
+static void prvCheckRecorderStatus(void)\r
{\r
- return xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED;\r
+ if (NoRoomForSymbol > NoRoomForSymbol_last)\r
+ {\r
+ vTracePrintF(trcWarningChannel, "TRC_CFG_SYMBOL_TABLE_SLOTS too small. Add %d slots.",\r
+ NoRoomForSymbol);\r
+\r
+ NoRoomForSymbol_last = NoRoomForSymbol;\r
+ }\r
+\r
+ if (NoRoomForObjectData > NoRoomForObjectData_last)\r
+ {\r
+ vTracePrintF(trcWarningChannel, "TRC_CFG_OBJECT_DATA_SLOTS too small. Add %d slots.",\r
+ NoRoomForObjectData);\r
+\r
+ NoRoomForObjectData_last = NoRoomForObjectData;\r
+ }\r
+\r
+ if (LongestSymbolName > LongestSymbolName_last)\r
+ {\r
+ if (LongestSymbolName > TRC_CFG_SYMBOL_MAX_LENGTH)\r
+ {\r
+ vTracePrintF(trcWarningChannel, "TRC_CFG_SYMBOL_MAX_LENGTH too small. Add %d chars.",\r
+ LongestSymbolName);\r
+ }\r
+ LongestSymbolName_last = LongestSymbolName;\r
+ }\r
+\r
+ if (MaxBytesTruncated > MaxBytesTruncated_last)\r
+ {\r
+ /* Some string event generated a too long string that was truncated.\r
+ This may happen for the following functions:\r
+ - vTracePrintF\r
+ - vTracePrintF\r
+ - vTraceStoreKernelObjectName\r
+ - vTraceStoreUserEventChannelName\r
+ - vTraceSetISRProperties\r
+\r
+ A PSF event may store maximum 60 bytes payload, including data arguments\r
+ and string characters. For User Events, also the User Event Channel ptr\r
+ must be squeezed in, if a channel is specified. */\r
+\r
+ vTracePrintF(trcWarningChannel, "String event too long, up to %d bytes truncated.",\r
+ MaxBytesTruncated);\r
+\r
+ MaxBytesTruncated_last = MaxBytesTruncated;\r
+ }\r
+}\r
+\r
+/*******************************************************************************\r
+ * TzCtrl\r
+ *\r
+ * Task for receiving commands from Tracealyzer and for recorder diagnostics.\r
+ *\r
+ ******************************************************************************/\r
+static portTASK_FUNCTION( TzCtrl, pvParameters )\r
+{\r
+ TracealyzerCommandType msg;\r
+ int bytes = 0;\r
+\r
+ (void)pvParameters;\r
+\r
+ while (1)\r
+ {\r
+ do\r
+ {\r
+ /* Listen for new commands */\r
+ bytes = 0;\r
+ TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), &bytes);\r
+ if (bytes == sizeof(TracealyzerCommandType))\r
+ {\r
+ if (prvIsValidCommand(&msg))\r
+ {\r
+ prvProcessCommand(&msg); /* Start or Stop currently... */\r
+ }\r
+ }\r
+\r
+ /* Send periodic data */\r
+ bytes = 0;\r
+ TRC_STREAM_PORT_PERIODIC_SEND_DATA(&bytes);\r
+ /* If there was data sent (bytes != 0), immediately loop around and do all this again. Otherwise, step out of this loop and sleep for a while. */\r
+ }\r
+ while (bytes != 0);\r
+\r
+ prvCheckRecorderStatus();\r
+ vTaskDelay(TRC_CFG_CTRL_TASK_DELAY); /* 10ms */\r
+ }\r
+}\r
+\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
+\r
+\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+\r
+/* Internal flag to tell the context of tracePEND_FUNC_CALL_FROM_ISR */\r
+int uiInEventGroupSetBitsFromISR = 0;\r
+\r
+/******************************************************************************\r
+ * TraceObjectClassTable\r
+ * Translates a FreeRTOS QueueType into trace objects classes (TRACE_CLASS_).\r
+ * Has one entry for each QueueType, gives TRACE_CLASS ID.\r
+ ******************************************************************************/\r
+traceObjectClass TraceObjectClassTable[5] = {\r
+ TRACE_CLASS_QUEUE,\r
+ TRACE_CLASS_MUTEX,\r
+ TRACE_CLASS_SEMAPHORE,\r
+ TRACE_CLASS_SEMAPHORE,\r
+ TRACE_CLASS_MUTEX\r
+};\r
+\r
+/*******************************************************************************\r
+ * vTraceSetQueueName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Queue that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Queue objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetQueueName(void* object, const char* name)\r
+{\r
+ prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceSetSemaphoreName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Semaphore that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Semaphore objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetSemaphoreName(void* object, const char* name)\r
+{\r
+ prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceSetMutexName(void* object, const char* name)\r
+ *\r
+ * Parameter object: pointer to the Mutex that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for Semaphore objects for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceSetMutexName(void* object, const char* name)\r
+{\r
+ prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);\r
}\r
\r
void* prvTraceGetCurrentTaskHandle()\r
return xTaskGetCurrentTaskHandle();\r
}\r
\r
+#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_8_X)\r
+traceHandle prvTraceGetObjectNumber(void* handle)\r
+{\r
+ return (traceHandle) ucQueueGetQueueNumber(handle);\r
+}\r
+#else /* For FreeRTOS v8 and later */\r
+traceHandle prvTraceGetObjectNumber(void* handle)\r
+{\r
+ return (traceHandle) uxQueueGetQueueNumber(handle);\r
+}\r
+#endif\r
+\r
+uint8_t prvTraceGetObjectType(void* handle)\r
+{\r
+ return ucQueueGetQueueType(handle);\r
+}\r
+\r
+traceHandle prvTraceGetTaskNumber(void* handle)\r
+{\r
+ return (traceHandle)uxTaskGetTaskNumber(handle);\r
+}\r
+\r
/* Initialization of the object property table */\r
void vTraceInitObjectPropertyTable()\r
{\r
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectClasses = TRACE_NCLASSES;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[0] = NQueue;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[1] = NSemaphore;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[2] = NMutex;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[3] = NTask;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[4] = NISR;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[5] = NTimer;\r
- RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[6] = NEventGroup;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[0] = NameLenQueue;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[1] = NameLenSemaphore;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[2] = NameLenMutex;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[3] = NameLenTask;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[4] = NameLenISR;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[5] = NameLenTimer;\r
- RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[6] = NameLenEventGroup;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[0] = TRC_CFG_NQUEUE;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[1] = TRC_CFG_NSEMAPHORE;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[2] = TRC_CFG_NMUTEX;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[3] = TRC_CFG_NTASK;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[4] = TRC_CFG_NISR;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[5] = TRC_CFG_NTIMER;\r
+ RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[6] = TRC_CFG_NEVENTGROUP;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[0] = TRC_CFG_NAME_LEN_QUEUE;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[1] = TRC_CFG_NAME_LEN_SEMAPHORE;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[2] = TRC_CFG_NAME_LEN_MUTEX;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[3] = TRC_CFG_NAME_LEN_TASK;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[4] = TRC_CFG_NAME_LEN_ISR;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[5] = TRC_CFG_NAME_LEN_TIMER;\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[6] = TRC_CFG_NAME_LEN_EVENTGROUP;\r
RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[0] = PropertyTableSizeQueue;\r
RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[1] = PropertyTableSizeSemaphore;\r
RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[2] = PropertyTableSizeMutex;\r
RecorderDataPtr->ObjectPropertyTable.ObjectPropertyTableSizeInBytes = TRACE_OBJECT_TABLE_SIZE;\r
}\r
\r
-/* Initialization of the handle mechanism, see e.g, xTraceGetObjectHandle */\r
+/* Initialization of the handle mechanism, see e.g, prvTraceGetObjectHandle */\r
void vTraceInitObjectHandleStack()\r
{\r
objectHandleStacks.indexOfNextAvailableHandle[0] = objectHandleStacks.lowestIndexOfClass[0] = 0;\r
- objectHandleStacks.indexOfNextAvailableHandle[1] = objectHandleStacks.lowestIndexOfClass[1] = NQueue;\r
- objectHandleStacks.indexOfNextAvailableHandle[2] = objectHandleStacks.lowestIndexOfClass[2] = NQueue + NSemaphore;\r
- objectHandleStacks.indexOfNextAvailableHandle[3] = objectHandleStacks.lowestIndexOfClass[3] = NQueue + NSemaphore + NMutex;\r
- objectHandleStacks.indexOfNextAvailableHandle[4] = objectHandleStacks.lowestIndexOfClass[4] = NQueue + NSemaphore + NMutex + NTask;\r
- objectHandleStacks.indexOfNextAvailableHandle[5] = objectHandleStacks.lowestIndexOfClass[5] = NQueue + NSemaphore + NMutex + NTask + NISR;\r
- objectHandleStacks.indexOfNextAvailableHandle[6] = objectHandleStacks.lowestIndexOfClass[6] = NQueue + NSemaphore + NMutex + NTask + NISR + NTimer;\r
-\r
- objectHandleStacks.highestIndexOfClass[0] = NQueue - 1;\r
- objectHandleStacks.highestIndexOfClass[1] = NQueue + NSemaphore - 1;\r
- objectHandleStacks.highestIndexOfClass[2] = NQueue + NSemaphore + NMutex - 1;\r
- objectHandleStacks.highestIndexOfClass[3] = NQueue + NSemaphore + NMutex + NTask - 1;\r
- objectHandleStacks.highestIndexOfClass[4] = NQueue + NSemaphore + NMutex + NTask + NISR - 1;\r
- objectHandleStacks.highestIndexOfClass[5] = NQueue + NSemaphore + NMutex + NTask + NISR + NTimer - 1;\r
- objectHandleStacks.highestIndexOfClass[6] = NQueue + NSemaphore + NMutex + NTask + NISR + NTimer + NEventGroup - 1;\r
+ objectHandleStacks.indexOfNextAvailableHandle[1] = objectHandleStacks.lowestIndexOfClass[1] = TRC_CFG_NQUEUE;\r
+ objectHandleStacks.indexOfNextAvailableHandle[2] = objectHandleStacks.lowestIndexOfClass[2] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE;\r
+ objectHandleStacks.indexOfNextAvailableHandle[3] = objectHandleStacks.lowestIndexOfClass[3] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX;\r
+ objectHandleStacks.indexOfNextAvailableHandle[4] = objectHandleStacks.lowestIndexOfClass[4] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK;\r
+ objectHandleStacks.indexOfNextAvailableHandle[5] = objectHandleStacks.lowestIndexOfClass[5] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR;\r
+ objectHandleStacks.indexOfNextAvailableHandle[6] = objectHandleStacks.lowestIndexOfClass[6] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR + TRC_CFG_NTIMER;\r
+\r
+ objectHandleStacks.highestIndexOfClass[0] = TRC_CFG_NQUEUE - 1;\r
+ objectHandleStacks.highestIndexOfClass[1] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE - 1;\r
+ objectHandleStacks.highestIndexOfClass[2] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX - 1;\r
+ objectHandleStacks.highestIndexOfClass[3] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK - 1;\r
+ objectHandleStacks.highestIndexOfClass[4] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR - 1;\r
+ objectHandleStacks.highestIndexOfClass[5] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR + TRC_CFG_NTIMER - 1;\r
+ objectHandleStacks.highestIndexOfClass[6] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR + TRC_CFG_NTIMER + TRC_CFG_NEVENTGROUP - 1;\r
}\r
\r
/* Returns the "Not enough handles" error message for this object class */\r
switch(objectclass)\r
{\r
case TRACE_CLASS_TASK:\r
- return "Not enough TASK handles - increase NTask in trcConfig.h";\r
+ return "Not enough TASK handles - increase TRC_CFG_NTASK in trcSnapshotConfig.h";\r
case TRACE_CLASS_ISR:\r
- return "Not enough ISR handles - increase NISR in trcConfig.h";\r
+ return "Not enough ISR handles - increase TRC_CFG_NISR in trcSnapshotConfig.h";\r
case TRACE_CLASS_SEMAPHORE:\r
- return "Not enough SEMAPHORE handles - increase NSemaphore in trcConfig.h";\r
+ return "Not enough SEMAPHORE handles - increase TRC_CFG_NSEMAPHORE in trcSnapshotConfig.h";\r
case TRACE_CLASS_MUTEX:\r
- return "Not enough MUTEX handles - increase NMutex in trcConfig.h";\r
+ return "Not enough MUTEX handles - increase TRC_CFG_NMUTEX in trcSnapshotConfig.h";\r
case TRACE_CLASS_QUEUE:\r
- return "Not enough QUEUE handles - increase NQueue in trcConfig.h";\r
+ return "Not enough QUEUE handles - increase TRC_CFG_NQUEUE in trcSnapshotConfig.h";\r
case TRACE_CLASS_TIMER:\r
- return "Not enough TIMER handles - increase NTimer in trcConfig.h";\r
+ return "Not enough TIMER handles - increase TRC_CFG_NTIMER in trcSnapshotConfig.h";\r
case TRACE_CLASS_EVENTGROUP:\r
- return "Not enough EVENTGROUP handles - increase NEventGroup in trcConfig.h";\r
+ return "Not enough EVENTGROUP handles - increase TRC_CFG_NEVENTGROUP in trcSnapshotConfig.h";\r
default:\r
return "pszTraceGetErrorHandles: Invalid objectclass!";\r
}\r
}\r
\r
/* Returns the exclude state of the object */\r
-uint8_t uiTraceIsObjectExcluded(traceObjectClass objectclass, objectHandleType handle)\r
+uint8_t uiTraceIsObjectExcluded(traceObjectClass objectclass, traceHandle handle)\r
{\r
- TRACE_ASSERT(objectclass < TRACE_NCLASSES, "prvTraceIsObjectExcluded: objectclass >= TRACE_NCLASSES", 1);\r
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], "uiTraceIsObjectExcluded: Invalid value for handle", 1);\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES, "prvIsObjectExcluded: objectclass >= TRACE_NCLASSES", 1);\r
+ TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], "prvIsObjectExcluded: Invalid value for handle", 1);\r
\r
switch(objectclass)\r
{\r
case TRACE_CLASS_TASK:\r
- return TRACE_GET_TASK_FLAG_ISEXCLUDED(handle);\r
+ return (uint8_t) TRACE_GET_TASK_FLAG_ISEXCLUDED(handle);\r
case TRACE_CLASS_SEMAPHORE:\r
- return TRACE_GET_SEMAPHORE_FLAG_ISEXCLUDED(handle);\r
+ return (uint8_t) TRACE_GET_SEMAPHORE_FLAG_ISEXCLUDED(handle);\r
case TRACE_CLASS_MUTEX:\r
- return TRACE_GET_MUTEX_FLAG_ISEXCLUDED(handle);\r
+ return (uint8_t) TRACE_GET_MUTEX_FLAG_ISEXCLUDED(handle);\r
case TRACE_CLASS_QUEUE:\r
- return TRACE_GET_QUEUE_FLAG_ISEXCLUDED(handle);\r
+ return (uint8_t) TRACE_GET_QUEUE_FLAG_ISEXCLUDED(handle);\r
case TRACE_CLASS_TIMER:\r
- return TRACE_GET_TIMER_FLAG_ISEXCLUDED(handle);\r
+ return (uint8_t) TRACE_GET_TIMER_FLAG_ISEXCLUDED(handle);\r
case TRACE_CLASS_EVENTGROUP:\r
- return TRACE_GET_EVENTGROUP_FLAG_ISEXCLUDED(handle);\r
+ return (uint8_t) TRACE_GET_EVENTGROUP_FLAG_ISEXCLUDED(handle);\r
}\r
\r
- vTraceError("Invalid object class ID in uiTraceIsObjectExcluded!");\r
+ prvTraceError("Invalid object class ID in prvIsObjectExcluded!");\r
\r
/* Must never reach */\r
return 1;\r
}\r
\r
-#endif
\ No newline at end of file
+/*******************************************************************************\r
+ * prvTraceIsSchedulerSuspended\r
+ *\r
+ * Returns true if the RTOS scheduler currently is disabled, thus preventing any\r
+ * task-switches from occurring. Only called from vTraceStoreISREnd.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
+unsigned char prvTraceIsSchedulerSuspended()\r
+{\r
+ /* Assumed to be available in FreeRTOS. According to the FreeRTOS docs,\r
+ INCLUDE_xTaskGetSchedulerState or configUSE_TIMERS must be set to 1 in\r
+ FreeRTOSConfig.h for this function to be available. */\r
+\r
+ return xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED;\r
+}\r
+#endif\r
+\r
+#endif /* Snapshot mode */\r
+\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcSnapshotRecorder.c\r
+ *\r
+ * The generic core of the trace recorder's snapshot mode.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#include "trcRecorder.h"\r
+\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
+\r
+#if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
+\r
+#include <string.h>\r
+#include <stdarg.h>\r
+#include <stdint.h>\r
+\r
+#if ((TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR))\r
+ #error "CUSTOM timestamping mode is not (yet) supported in snapshot mode!"\r
+#endif\r
+\r
+/* DO NOT CHANGE */\r
+#define TRACE_MINOR_VERSION 5\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
+static traceHandle isrstack[TRC_CFG_MAX_ISR_NESTING];\r
+int32_t isPendingContextSwitch = 0;\r
+#endif /* (TRC_CFG_INCLUDE_ISR_TRACING == 1) */\r
+\r
+#if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1\r
+static int readyEventsEnabled = 1;\r
+#endif /*!defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1*/\r
+/*******************************************************************************\r
+ * uiTraceTickCount\r
+ *\r
+ * This variable is should be updated by the Kernel tick interrupt. This does\r
+ * not need to be modified when developing a new timer port. It is preferred to\r
+ * keep any timer port changes in the HWTC macro definitions, which typically\r
+ * give sufficient flexibility.\r
+ ******************************************************************************/\r
+uint32_t uiTraceTickCount = 0;\r
+\r
+uint32_t trace_disable_timestamp = 0;\r
+static uint32_t last_timestamp = 0;\r
+/* Flag that shows if inside a critical section of the recorder */\r
+volatile int recorder_busy = 0;\r
+\r
+/* Holds the value set by vTraceSetFrequency */\r
+uint32_t timestampFrequency = 0;\r
+\r
+/* The last error message of the recorder. NULL if no error message. */\r
+const char* traceErrorMessage = NULL;\r
+\r
+\r
+int8_t nISRactive = 0;\r
+traceHandle handle_of_last_logged_task = 0;\r
+uint8_t inExcludedTask = 0;\r
+\r
+extern uint8_t inExcludedTask;\r
+extern int8_t nISRactive;\r
+extern traceHandle handle_of_last_logged_task;\r
+\r
+/* Called when the recorder is stopped, set by vTraceSetStopHook. */\r
+TRACE_STOP_HOOK vTraceStopHookPtr = (TRACE_STOP_HOOK)0;\r
+\r
+/*************** Private Functions *******************************************/\r
+static void prvStrncpy(char* dst, const char* src, uint32_t maxLength);\r
+static uint8_t prvTraceGetObjectState(uint8_t objectclass, traceHandle id); \r
+static void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength); \r
+static void* prvTraceNextFreeEventBufferSlot(void); \r
+static uint16_t prvTraceGetDTS(uint16_t param_maxDTS);\r
+static traceString prvTraceOpenSymbol(const char* name, traceString userEventChannel);\r
+static void prvTraceUpdateCounters(void);\r
+\r
+#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+static void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nEntries);\r
+#endif\r
+\r
+static traceString prvTraceCreateSymbolTableEntry(const char* name,\r
+ uint8_t crc6,\r
+ uint8_t len,\r
+ traceString channel);\r
+\r
+static traceString prvTraceLookupSymbolTableEntry(const char* name,\r
+ uint8_t crc6,\r
+ uint8_t len,\r
+ traceString channel);\r
+\r
+\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 0)\r
+/* ISR tracing is turned off */\r
+void prvTraceIncreaseISRActive(void);\r
+void prvTraceDecreaseISRActive(void);\r
+#endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/\r
+ \r
+#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
+static uint8_t prvTraceGet8BitHandle(traceHandle handle);\r
+#else\r
+#define prvTraceGet8BitHandle(x) ((uint8_t)x)\r
+#endif\r
+\r
+\r
+#if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)\r
+ /* Current heap usage. Always updated. */\r
+ static uint32_t heapMemUsage = 0;\r
+#endif\r
+\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+static uint32_t prvTraceGetParam(uint32_t, uint32_t);\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceInitTraceData\r
+ *\r
+ * Allocates and initializes the recorder data structure, based on the constants\r
+ * in trcConfig.h. This allows for allocating the data on the heap, instead of\r
+ * using a static declaration.\r
+ ******************************************************************************/\r
+static void prvTraceInitTraceData(void);\r
+\r
+/*******************************************************************************\r
+ * prvTracePortGetTimeStamp\r
+ *\r
+ * Returns the current time based on the HWTC macros which provide a hardware\r
+ * isolation layer towards the hardware timer/counter.\r
+ *\r
+ * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue\r
+ * or the trace recorder library. Typically you should not need to change\r
+ * the code of prvTracePortGetTimeStamp if using the HWTC macros.\r
+ *\r
+ ******************************************************************************/\r
+void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);\r
+\r
+static void prvTraceTaskInstanceFinish(int8_t direct);\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+static void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list vl);\r
+\r
+#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
+static void vTraceUBData_Helper(traceUBChannel channelPair, va_list vl);\r
+static void prvTraceUBHelper1(traceUBChannel channel, traceString eventLabel, traceString formatLabel, va_list vl);\r
+static void prvTraceUBHelper2(traceUBChannel channel, uint32_t* data, uint32_t noOfSlots);\r
+#endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/\r
+#endif /* ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)) */\r
+\r
+/********* Public Functions **************************************************/\r
+\r
+uint16_t uiIndexOfObject(traceHandle objecthandle, uint8_t objectclass);\r
+\r
+/*******************************************************************************\r
+ * prvTraceError\r
+ *\r
+ * Called by various parts in the recorder. Stops the recorder and stores a\r
+ * pointer to an error message, which is printed by the monitor task.\r
+ ******************************************************************************/\r
+void prvTraceError(const char* msg);\r
+\r
+/******************************************************************************\r
+* vTraceEnable(int startOption) - snapshot mode\r
+*\r
+* Initializes and optionally starts the trace, depending on the start option.\r
+* To use the trace recorder, the startup must call vTraceEnable before any RTOS\r
+* calls are made (including "create" calls). Three start options are provided:\r
+* \r
+* TRC_START: Starts the tracing directly. In snapshot mode this allows for \r
+* starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)\r
+* has been called in the startup.\r
+* Can also be used for streaming without Tracealyzer control, e.g. to a local\r
+* flash file system (assuming such a "stream port", see trcStreamingPort.h).\r
+* \r
+* TRC_INIT: Initializes the trace recorder, but does not start the tracing.\r
+* In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime\r
+* later.\r
+*\r
+* Usage examples, in snapshot mode:\r
+* \r
+* Snapshot trace, from startup:\r
+* <board init>\r
+* vTraceEnable(TRC_START);\r
+* <RTOS init>\r
+*\r
+* Snapshot trace, from a later point:\r
+* <board init>\r
+* vTraceEnable(TRC_INIT);\r
+* <RTOS init>\r
+* ...\r
+* vTraceEnable(TRC_START); // e.g., in task context, at some relevant event\r
+* \r
+*\r
+* Note: See other implementation of vTraceEnable in trcStreamingRecorder.c\r
+******************************************************************************/\r
+void vTraceEnable(int startOption)\r
+{\r
+ prvTraceInitTraceData();\r
+ \r
+ if (startOption == TRC_START)\r
+ {\r
+ vTraceStart();\r
+ }\r
+ else if (startOption == TRC_START_AWAIT_HOST)\r
+ {\r
+ prvTraceError("vTraceEnable(TRC_START_AWAIT_HOST) not allowed in Snapshot mode");\r
+ }\r
+ else if (startOption != TRC_INIT)\r
+ {\r
+ prvTraceError("Unexpected argument to vTraceEnable (snapshot mode)");\r
+ } \r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceSetRecorderDataBuffer\r
+ *\r
+ * If custom allocation is used, this function must be called so the recorder\r
+ * library knows where to save the trace data.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
+void vTraceSetRecorderDataBuffer(void* pRecorderData)\r
+{\r
+ TRACE_ASSERT(pRecorderData != NULL, "vTraceSetRecorderDataBuffer, pRecorderData == NULL", TRC_UNUSED);\r
+ RecorderDataPtr = pRecorderData;\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * vTraceSetStopHook\r
+ *\r
+ * Sets a function to be called when the recorder is stopped. This can be used\r
+ * to save the trace to a file system, if available. \r
+ ******************************************************************************/\r
+void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction)\r
+{\r
+ vTraceStopHookPtr = stopHookFunction;\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceClear\r
+ *\r
+ * Resets the recorder. Only necessary if a restart is desired - this is not\r
+ * needed in the startup initialization.\r
+ ******************************************************************************/\r
+void vTraceClear(void)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ RecorderDataPtr->absTimeLastEventSecond = 0;\r
+ RecorderDataPtr->absTimeLastEvent = 0;\r
+ RecorderDataPtr->nextFreeIndex = 0;\r
+ RecorderDataPtr->numEvents = 0;\r
+ RecorderDataPtr->bufferIsFull = 0;\r
+ traceErrorMessage = NULL;\r
+ RecorderDataPtr->internalErrorOccured = 0;\r
+ (void)memset(RecorderDataPtr->eventData, 0, RecorderDataPtr->maxEvents * 4);\r
+ handle_of_last_logged_task = 0;\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+\r
+/*******************************************************************************\r
+ * uiTraceStart\r
+ *\r
+ * Starts the recorder. The recorder will not be started if an error has been\r
+ * indicated using prvTraceError, e.g. if any of the Nx constants in trcConfig.h\r
+ * has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
+ *\r
+ * Returns 1 if the recorder was started successfully.\r
+ * Returns 0 if the recorder start was prevented due to a previous internal\r
+ * error. In that case, check xTraceGetLastError to get the error message.\r
+ * Any error message is also presented when opening a trace file.\r
+ *\r
+ * This function is obsolete, but has been saved for backwards compatibility.\r
+ * We recommend using vTraceEnable instead.\r
+ ******************************************************************************/\r
+uint32_t uiTraceStart(void)\r
+{\r
+ traceHandle handle;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ handle = 0;\r
+\r
+ if (RecorderDataPtr == NULL)\r
+ {\r
+ prvTraceError("RecorderDataPtr is NULL. Call vTraceInitTraceData() before starting trace.");\r
+ return 0;\r
+ }\r
+ \r
+ if (RecorderDataPtr->recorderActive == 1)\r
+ return 1; /* Already running */\r
+\r
+ if (traceErrorMessage == NULL)\r
+ {\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ RecorderDataPtr->recorderActive = 1;\r
+\r
+ handle = TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK());\r
+ if (handle == 0)\r
+ {\r
+ /* This occurs if the scheduler is not yet started.\r
+ This creates a dummy "(startup)" task entry internally in the\r
+ recorder */\r
+ handle = prvTraceGetObjectHandle(TRACE_CLASS_TASK);\r
+ prvTraceSetObjectName(TRACE_CLASS_TASK, handle, "(startup)");\r
+\r
+ prvTraceSetPriorityProperty(TRACE_CLASS_TASK, handle, 0);\r
+ }\r
+\r
+ prvTraceStoreTaskswitch(handle); /* Register the currently running task */\r
+ trcCRITICAL_SECTION_END();\r
+ }\r
+\r
+ return RecorderDataPtr->recorderActive;\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStart\r
+ *\r
+ * Starts the recorder. The recorder will not be started if an error has been\r
+ * indicated using prvTraceError, e.g. if any of the Nx constants in trcConfig.h\r
+ * has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
+ *\r
+ * This function is obsolete, but has been saved for backwards compatibility.\r
+ * We recommend using vTraceEnable instead.\r
+ ******************************************************************************/\r
+void vTraceStart(void)\r
+{\r
+ (void)uiTraceStart();\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStop\r
+ *\r
+ * Stops the recorder. The recording can be resumed by calling vTraceStart.\r
+ * This does not reset the recorder. Use vTraceClear if that is desired.\r
+ ******************************************************************************/\r
+void vTraceStop(void)\r
+{\r
+ RecorderDataPtr->recorderActive = 0;\r
+\r
+ if (vTraceStopHookPtr != (TRACE_STOP_HOOK)0)\r
+ {\r
+ (*vTraceStopHookPtr)(); /* An application call-back function. */\r
+ }\r
+}\r
+\r
+/*******************************************************************************\r
+ * xTraceGetLastError\r
+ *\r
+ * Gives the last error message, if any. NULL if no error message is stored.\r
+ * Any error message is also presented when opening a trace file.\r
+ ******************************************************************************/\r
+const char* xTraceGetLastError(void)\r
+{\r
+ return traceErrorMessage;\r
+}\r
+\r
+/*******************************************************************************\r
+* vTraceClearError\r
+*\r
+* Removes any previous error message generated by recorder calling prvTraceError.\r
+* By calling this function, it may be possible to start/restart the trace\r
+* despite errors in the recorder, but there is no guarantee that the trace\r
+* recorder will work correctly in that case, depending on the type of error.\r
+******************************************************************************/\r
+void vTraceClearError(void)\r
+{\r
+ traceErrorMessage = NULL;\r
+ if (RecorderDataPtr != NULL)\r
+ {\r
+ RecorderDataPtr->internalErrorOccured = 0;\r
+ }\r
+}\r
+\r
+/*******************************************************************************\r
+ * xTraceGetTraceBuffer\r
+ *\r
+ * Returns a pointer to the recorder data structure. Use this together with\r
+ * uiTraceGetTraceBufferSize if you wish to implement an own store/upload\r
+ * solution, e.g., in case a debugger connection is not available for uploading\r
+ * the data.\r
+ ******************************************************************************/\r
+void* xTraceGetTraceBuffer(void)\r
+{\r
+ return RecorderDataPtr;\r
+}\r
+\r
+/*******************************************************************************\r
+ * uiTraceGetTraceBufferSize\r
+ *\r
+ * Gets the size of the recorder data structure. For use together with\r
+ * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,\r
+ * e.g., in case a debugger connection is not available for uploading the data.\r
+ ******************************************************************************/\r
+uint32_t uiTraceGetTraceBufferSize(void)\r
+{\r
+ return sizeof(RecorderDataType);\r
+}\r
+\r
+/******************************************************************************\r
+ * prvTraceTaskInstanceFinish\r
+ *\r
+ * Private common function for the vTraceTaskInstanceFinishXXX functions.\r
+ * \r
+ *****************************************************************************/\r
+static void prvTraceTaskInstanceFinish(int8_t direct)\r
+{\r
+ TaskInstanceStatusEvent* tis;\r
+ uint8_t dts45;\r
+\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+ {\r
+ dts45 = (uint8_t)prvTraceGetDTS(0xFF);\r
+ tis = (TaskInstanceStatusEvent*) prvTraceNextFreeEventBufferSlot();\r
+ if (tis != NULL)\r
+ {\r
+ if (direct == 0)\r
+ tis->type = TASK_INSTANCE_FINISHED_NEXT_KSE;\r
+ else\r
+ tis->type = TASK_INSTANCE_FINISHED_DIRECT;\r
+\r
+ tis->dts = dts45;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+\r
+/******************************************************************************\r
+ * vTraceInstanceFinishedNext(void)\r
+ *\r
+ * Marks the current task instance as finished on the next kernel call.\r
+ *\r
+ * If that kernel call is blocking, the instance ends after the blocking event\r
+ * and the corresponding return event is then the start of the next instance.\r
+ * If the kernel call is not blocking, the viewer instead splits the current\r
+ * fragment right before the kernel call, which makes this call the first event\r
+ * of the next instance.\r
+ *\r
+ * See also TRC_CFG_USE_IMPLICIT_IFE_RULES in trcConfig.h\r
+ *\r
+ * Example:\r
+ *\r
+ * while(1)\r
+ * {\r
+ * xQueueReceive(CommandQueue, &command, timeoutDuration);\r
+ * processCommand(command);\r
+ * vTraceInstanceFinishedNext();\r
+ * }\r
+ *\r
+ * Note: This is only supported in Tracealyzer tools v2.7 or later\r
+ *\r
+ *****************************************************************************/\r
+void vTraceInstanceFinishedNext(void)\r
+{\r
+ prvTraceTaskInstanceFinish(0);\r
+}\r
+\r
+/******************************************************************************\r
+ * vTraceInstanceFinishedNow(void)\r
+ *\r
+ * Marks the current task instance as finished at this very instant.\r
+ * This makes the viewer to splits the current fragment at this point and begin\r
+ * a new actor instance.\r
+ *\r
+ * See also TRC_CFG_USE_IMPLICIT_IFE_RULES in trcConfig.h\r
+ *\r
+ * Example:\r
+ *\r
+ * This example will generate two instances for each loop iteration.\r
+ * The first instance ends at vTraceInstanceFinishedNow(), while the second\r
+ * instance ends at the next xQueueReceive call.\r
+ *\r
+ * while (1)\r
+ * {\r
+ * xQueueReceive(CommandQueue, &command, timeoutDuration);\r
+ * ProcessCommand(command);\r
+ * vTraceInstanceFinishedNow();\r
+ * DoSometingElse();\r
+ * vTraceInstanceFinishedNext();\r
+ * }\r
+ *\r
+ * Note: This is only supported in Tracealyzer tools v2.7 or later\r
+ *\r
+ *****************************************************************************/\r
+void vTraceInstanceFinishedNow(void)\r
+{\r
+ prvTraceTaskInstanceFinish(1);\r
+}\r
+\r
+/*******************************************************************************\r
+ * Interrupt recording functions\r
+ ******************************************************************************/\r
+\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
+\r
+/*******************************************************************************\r
+ * xTraceSetISRProperties\r
+ *\r
+ * Stores a name and priority level for an Interrupt Service Routine, to allow\r
+ * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin. \r
+ *\r
+ * Example:\r
+ * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * ...\r
+ * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(Timer1Handle);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+ traceHandle xTraceSetISRProperties(const char* name, uint8_t priority)\r
+{\r
+ static traceHandle handle = 0;\r
+ handle++;\r
+ TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "xTraceSetISRProperties: Invalid value for handle", 0);\r
+ TRACE_ASSERT(name != NULL, "xTraceSetISRProperties: name == NULL", 0);\r
+\r
+ prvTraceSetObjectName(TRACE_CLASS_ISR, handle, name);\r
+ prvTraceSetPriorityProperty(TRACE_CLASS_ISR, handle, priority);\r
+ \r
+ return handle;\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreISRBegin\r
+ *\r
+ * Registers the beginning of an Interrupt Service Routine, using a traceHandle\r
+ * provided by xTraceSetISRProperties.\r
+ *\r
+ * Example:\r
+ * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * ...\r
+ * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(Timer1Handle);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+void vTraceStoreISRBegin(traceHandle handle)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("vTraceStoreISRBegin - recorder busy! See code comment.");\r
+ return;\r
+ }\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ \r
+ if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
+ {\r
+ uint16_t dts4;\r
+ \r
+ TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceStoreISRBegin: Invalid value for handle", TRC_UNUSED);\r
+ \r
+ dts4 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+\r
+ if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */\r
+ {\r
+ if (nISRactive < TRC_CFG_MAX_ISR_NESTING)\r
+ {\r
+ TSEvent* ts;\r
+ uint8_t hnd8 = prvTraceGet8BitHandle(handle);\r
+ isrstack[nISRactive] = handle;\r
+ nISRactive++;\r
+ ts = (TSEvent*)prvTraceNextFreeEventBufferSlot();\r
+ if (ts != NULL)\r
+ {\r
+ ts->type = TS_ISR_BEGIN;\r
+ ts->dts = dts4;\r
+ ts->objHandle = hnd8;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* This should not occur unless something is very wrong */\r
+ prvTraceError("Too many nested interrupts!");\r
+ }\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreISREnd\r
+ *\r
+ * Registers the end of an Interrupt Service Routine.\r
+ *\r
+ * The parameter pendingISR indicates if the interrupt has requested a\r
+ * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the \r
+ * interrupt is assumed to return to the previous context.\r
+ *\r
+ * Example:\r
+ * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder\r
+ * ...\r
+ * traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(traceHandleIsrTimer1);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+void vTraceStoreISREnd(int pendingISR)\r
+{\r
+ TSEvent* ts;\r
+ uint16_t dts5;\r
+ uint8_t hnd8 = 0, type = 0;\r
+ \r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ if (! RecorderDataPtr->recorderActive || ! handle_of_last_logged_task)\r
+ {\r
+ return;\r
+ }\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("vTraceStoreISREnd - recorder busy! See code comment.");\r
+ return;\r
+ }\r
+ \r
+ if (nISRactive == 0)\r
+ {\r
+ prvTraceError("Unmatched call to vTraceStoreISREnd (nISRactive == 0, expected > 0)");\r
+ return;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ isPendingContextSwitch |= pendingISR; /* Is there a pending context switch right now? */\r
+ nISRactive--;\r
+ if (nISRactive > 0)\r
+ {\r
+ /* Return to another ISR */\r
+ type = TS_ISR_RESUME;\r
+ hnd8 = prvTraceGet8BitHandle(isrstack[nISRactive - 1]); /* isrstack[nISRactive] is the handle of the ISR we're currently exiting. isrstack[nISRactive - 1] is the handle of the ISR that was executing previously. */\r
+ }\r
+ else if ((isPendingContextSwitch == 0) || (prvTraceIsSchedulerSuspended())) \r
+ {\r
+ /* Return to interrupted task, if no context switch will occur in between. */\r
+ type = TS_TASK_RESUME;\r
+ hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);\r
+ }\r
+\r
+ if (type != 0)\r
+ {\r
+ dts5 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+ ts = (TSEvent*)prvTraceNextFreeEventBufferSlot();\r
+ if (ts != NULL)\r
+ {\r
+ ts->type = type;\r
+ ts->objHandle = hnd8;\r
+ ts->dts = dts5;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+\r
+#else\r
+\r
+/* ISR tracing is turned off */\r
+void prvTraceIncreaseISRActive(void)\r
+{\r
+ if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
+ nISRactive++;\r
+}\r
+\r
+void prvTraceDecreaseISRActive(void)\r
+{\r
+ if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
+ nISRactive--;\r
+}\r
+#endif /* (TRC_CFG_INCLUDE_ISR_TRACING == 1)*/\r
+\r
+/********************************************************************************/\r
+/* User Event functions */\r
+/********************************************************************************/\r
+\r
+#define MAX_ARG_SIZE (4+32)\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+static uint8_t writeInt8(void * buffer, uint8_t i, uint8_t value)\r
+{\r
+ TRACE_ASSERT(buffer != NULL, "writeInt8: buffer == NULL", 0);\r
+\r
+ if (i >= MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint8_t*)buffer)[i] = value;\r
+\r
+ if (i + 1 > MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ return ((uint8_t) (i + 1));\r
+}\r
+#endif\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+static uint8_t writeInt16(void * buffer, uint8_t i, uint16_t value)\r
+{\r
+ TRACE_ASSERT(buffer != NULL, "writeInt16: buffer == NULL", 0);\r
+\r
+ /* Align to multiple of 2 */\r
+ while ((i % 2) != 0)\r
+ {\r
+ if (i >= MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint8_t*)buffer)[i] = 0;\r
+ i++;\r
+ }\r
+\r
+ if (i + 2 > MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint16_t*)buffer)[i/2] = value;\r
+\r
+ return ((uint8_t) (i + 2));\r
+}\r
+#endif\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+static uint8_t writeInt32(void * buffer, uint8_t i, uint32_t value)\r
+{\r
+ TRACE_ASSERT(buffer != NULL, "writeInt32: buffer == NULL", 0);\r
+\r
+ /* A 32 bit value should begin at an even 4-byte address */\r
+ while ((i % 4) != 0)\r
+ {\r
+ if (i >= MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint8_t*)buffer)[i] = 0;\r
+ i++;\r
+ }\r
+\r
+ if (i + 4 > MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint32_t*)buffer)[i/4] = value;\r
+\r
+ return ((uint8_t) (i + 4));\r
+}\r
+#endif\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_INCLUDE_FLOAT_SUPPORT))\r
+static uint8_t writeFloat(void * buffer, uint8_t i, float value)\r
+{\r
+ TRACE_ASSERT(buffer != NULL, "writeFloat: buffer == NULL", 0);\r
+\r
+ /* A 32 bit value should begin at an even 4-byte address */\r
+ while ((i % 4) != 0)\r
+ {\r
+ if (i >= MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint8_t*)buffer)[i] = 0;\r
+ i++;\r
+ }\r
+\r
+ if (i + 4 > MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((float*)buffer)[i/4] = value;\r
+\r
+ return i + 4;\r
+}\r
+#endif\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_INCLUDE_FLOAT_SUPPORT))\r
+static uint8_t writeDouble(void * buffer, uint8_t i, double value)\r
+{\r
+ uint32_t * dest;\r
+ uint32_t * src = (uint32_t*)&value;\r
+\r
+ TRACE_ASSERT(buffer != NULL, "writeDouble: buffer == NULL", 0);\r
+\r
+ /* The double is written as two 32 bit values, and should begin at an even\r
+ 4-byte address (to avoid having to align with 8 byte) */\r
+ while (i % 4 != 0)\r
+ {\r
+ if (i >= MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ ((uint8_t*)buffer)[i] = 0;\r
+ i++;\r
+ }\r
+\r
+ if (i + 8 > MAX_ARG_SIZE)\r
+ {\r
+ return 255;\r
+ }\r
+\r
+ dest = &(((uint32_t *)buffer)[i/4]);\r
+\r
+ dest[0] = src[0];\r
+ dest[1] = src[1];\r
+\r
+ return i + 8;\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceUserEventFormat\r
+ *\r
+ * Parses the format string and stores the arguments in the buffer.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+static uint8_t prvTraceUserEventFormat(const char* formatStr, va_list vl, uint8_t* buffer, uint8_t byteOffset)\r
+{\r
+ uint16_t formatStrIndex = 0;\r
+ uint8_t argCounter = 0;\r
+ uint8_t i = byteOffset;\r
+\r
+ while (formatStr[formatStrIndex] != '\0')\r
+ {\r
+ if (formatStr[formatStrIndex] == '%')\r
+ {\r
+ argCounter++;\r
+\r
+ if (argCounter > 15)\r
+ {\r
+ prvTraceError("vTracePrintF - Too many arguments, max 15 allowed!");\r
+ return 0;\r
+ }\r
+\r
+ formatStrIndex++;\r
+\r
+ while ((formatStr[formatStrIndex] >= '0' && formatStr[formatStrIndex] <= '9') || formatStr[formatStrIndex] == '#' || formatStr[formatStrIndex] == '.')\r
+ formatStrIndex++;\r
+\r
+ if (formatStr[formatStrIndex] != '\0')\r
+ {\r
+ switch (formatStr[formatStrIndex])\r
+ {\r
+ case 'd': i = writeInt32( buffer,\r
+ i,\r
+ (uint32_t)va_arg(vl, uint32_t));\r
+ break;\r
+ case 'x':\r
+ case 'X':\r
+ case 'u': i = writeInt32( buffer,\r
+ i,\r
+ (uint32_t)va_arg(vl, uint32_t));\r
+ break;\r
+ case 's': i = writeInt16( buffer,\r
+ i,\r
+ xTraceRegisterString((char*)va_arg(vl, char*)));\r
+ break;\r
+\r
+#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT)\r
+ /* Yes, "double" as type also in the float\r
+ case. This since "float" is promoted into "double"\r
+ by the va_arg stuff. */\r
+ case 'f': i = writeFloat( buffer,\r
+ i,\r
+ (float)va_arg(vl, double));\r
+ break;\r
+#else\r
+ /* No support for floats, but attempt to store a float user event\r
+ avoid a possible crash due to float reference. Instead store the\r
+ data on uint_32 format (will not be displayed anyway). This is just\r
+ to keep va_arg and i consistent. */\r
+\r
+ case 'f': i = writeInt32( buffer,\r
+ i,\r
+ (uint32_t)va_arg(vl, double));\r
+ break;\r
+#endif\r
+ case 'l':\r
+ formatStrIndex++;\r
+ switch (formatStr[formatStrIndex])\r
+ {\r
+#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT)\r
+ case 'f': i = writeDouble(buffer,\r
+ i,\r
+ (double)va_arg(vl, double));\r
+ break;\r
+#else\r
+ /* No support for floats, but attempt to store a float user event\r
+ avoid a possible crash due to float reference. Instead store the\r
+ data on uint_32 format (will not be displayed anyway). This is just\r
+ to keep va_arg and i consistent. */\r
+ case 'f': i = writeInt32( buffer, /* In this case, the value will not be shown anyway */\r
+ i,\r
+ (uint32_t)va_arg(vl, double));\r
+\r
+ i = writeInt32( buffer, /* Do it twice, to write in total 8 bytes */\r
+ i,\r
+ (uint32_t)va_arg(vl, double));\r
+ break;\r
+#endif\r
+\r
+ }\r
+ break;\r
+ case 'h':\r
+ formatStrIndex++;\r
+ switch (formatStr[formatStrIndex])\r
+ {\r
+ case 'd': i = writeInt16( buffer,\r
+ i,\r
+ (uint16_t)va_arg(vl, uint32_t));\r
+ break;\r
+ case 'u': i = writeInt16( buffer,\r
+ i,\r
+ (uint16_t)va_arg(vl, uint32_t));\r
+ break;\r
+ }\r
+ break;\r
+ case 'b':\r
+ formatStrIndex++;\r
+ switch (formatStr[formatStrIndex])\r
+ {\r
+ case 'd': i = writeInt8( buffer,\r
+ i,\r
+ (uint8_t)va_arg(vl, uint32_t));\r
+ break;\r
+\r
+ case 'u': i = writeInt8( buffer,\r
+ i,\r
+ (uint8_t)va_arg(vl, uint32_t));\r
+ break;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ break;\r
+ }\r
+ formatStrIndex++;\r
+ if (i == 255)\r
+ {\r
+ prvTraceError("vTracePrintF - Too large arguments, max 32 byte allowed!");\r
+ return 0;\r
+ }\r
+ }\r
+ return (uint8_t)(i+3)/4;\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceClearChannelBuffer\r
+ *\r
+ * Clears a number of items in the channel buffer, starting from nextSlotToWrite.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+static void prvTraceClearChannelBuffer(uint32_t count)\r
+{\r
+ uint32_t slots;\r
+\r
+ TRACE_ASSERT(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE >= count,\r
+ "prvTraceClearChannelBuffer: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
+\r
+ /* Check if we're close to the end of the buffer */\r
+ if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE)\r
+ {\r
+ slots = TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
+ (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, slots);\r
+ (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[0], 0, (count - slots));\r
+ }\r
+ else\r
+ (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, count);\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceCopyToDataBuffer\r
+ *\r
+ * Copies a number of items to the data buffer, starting from nextSlotToWrite.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+static void prvTraceCopyToDataBuffer(uint32_t* data, uint32_t count)\r
+{\r
+ uint32_t slots;\r
+ \r
+ TRACE_ASSERT(data != NULL,\r
+ "prvTraceCopyToDataBuffer: data == NULL.", TRC_UNUSED);\r
+ TRACE_ASSERT(count <= TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE,\r
+ "prvTraceCopyToDataBuffer: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
+ /* Check if we're close to the end of the buffer */\r
+ if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE)\r
+ {\r
+ slots = TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
+ (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, slots * 4);\r
+ (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[0], data + slots, (count - slots) * 4);\r
+ }\r
+ else\r
+ {\r
+ (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, count * 4);\r
+ }\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceUBHelper1\r
+ *\r
+ * Calls on prvTraceUserEventFormat() to do the actual formatting, then goes on\r
+ * to the next helper function.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+static void prvTraceUBHelper1(traceUBChannel channel, traceString eventLabel, traceString formatLabel, va_list vl)\r
+{\r
+ uint32_t data[(3 + MAX_ARG_SIZE) / 4];\r
+ uint8_t byteOffset = 4; /* Need room for timestamp */\r
+ uint8_t noOfSlots;\r
+\r
+ if (channel == 0)\r
+ {\r
+ /* We are dealing with an unknown channel format pair */\r
+ byteOffset = (uint8_t)(byteOffset + 4); /* Also need room for channel and format */\r
+ ((uint16_t*)data)[2] = eventLabel;\r
+ ((uint16_t*)data)[3] = formatLabel;\r
+ }\r
+\r
+ noOfSlots = prvTraceUserEventFormat((char*)&(RecorderDataPtr->SymbolTable.symbytes[formatLabel+4]), vl, (uint8_t*)data, byteOffset);\r
+\r
+ prvTraceUBHelper2(channel, data, noOfSlots);\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceUBHelper2\r
+ *\r
+ * This function simply copies the data buffer to the actual user event buffer.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+static void prvTraceUBHelper2(traceUBChannel channel, uint32_t* data, uint32_t noOfSlots)\r
+{\r
+ static uint32_t old_timestamp = 0;\r
+ uint32_t old_nextSlotToWrite = 0;\r
+ \r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ASSERT(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE >= noOfSlots, "prvTraceUBHelper2: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ /* Store the timestamp */\r
+ prvTracePortGetTimeStamp(data);\r
+\r
+ if (*data < old_timestamp)\r
+ {\r
+ RecorderDataPtr->userEventBuffer.wraparoundCounter++;\r
+ }\r
+\r
+ old_timestamp = *data;\r
+\r
+ /* Start by erasing any information in the channel buffer */\r
+ prvTraceClearChannelBuffer(noOfSlots);\r
+\r
+ prvTraceCopyToDataBuffer(data, noOfSlots); /* Will wrap around the data if necessary */\r
+\r
+ old_nextSlotToWrite = RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Save the index that we want to write the channel data at when we're done */\r
+ RecorderDataPtr->userEventBuffer.nextSlotToWrite = (RecorderDataPtr->userEventBuffer.nextSlotToWrite + noOfSlots) % TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE; /* Make sure we never end up outside the buffer */\r
+\r
+ /* Write to the channel buffer to indicate that this user event is ready to be used */\r
+ if (channel != 0)\r
+ {\r
+ RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = channel;\r
+ }\r
+ else\r
+ {\r
+ /* 0xFF indicates that this is not a normal channel id */\r
+ RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = (traceUBChannel)0xFF;\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * xTraceRegisterUBChannel\r
+ *\r
+ * Registers a channel for Separated User Events, i.e., those stored in the\r
+ * separate user event buffer.\r
+ *\r
+ * Note: Only available if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is enabled in\r
+ * trcSnapshotConfig.h\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatStr)\r
+{\r
+ uint8_t i;\r
+ traceUBChannel retVal = 0;\r
+ \r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ASSERT(formatStr != 0, "xTraceRegisterChannelFormat: formatStr == 0", (traceUBChannel)0);\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ for (i = 1; i <= TRC_CFG_UB_CHANNELS; i++) /* Size of the channels buffer is TRC_CFG_UB_CHANNELS + 1. Index 0 is unused. */\r
+ {\r
+ if(RecorderDataPtr->userEventBuffer.channels[i].name == 0 && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == 0)\r
+ {\r
+ /* Found empty slot */\r
+ RecorderDataPtr->userEventBuffer.channels[i].name = channel;\r
+ RecorderDataPtr->userEventBuffer.channels[i].defaultFormat = formatStr;\r
+ retVal = (traceUBChannel)i;\r
+ break;\r
+ }\r
+\r
+ if (RecorderDataPtr->userEventBuffer.channels[i].name == channel && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == formatStr)\r
+ {\r
+ /* Found a match */\r
+ retVal = (traceUBChannel)i;\r
+ break;\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+\r
+ return retVal;\r
+}\r
+#endif\r
+\r
+/******************************************************************************\r
+ * vTraceUBData\r
+ *\r
+ * Slightly faster version of vTracePrintF() due to no lookups.\r
+ *\r
+ * Note: This is only available if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is enabled in\r
+ * trcConfig.h\r
+ *\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+void vTraceUBData(traceUBChannel channelPair, ...)\r
+{\r
+ va_list vl;\r
+ \r
+ TRACE_ASSERT(channelPair != 0, "vTraceUBData: Not a valid traceUBChannel!", TRC_UNUSED);\r
+\r
+ va_start(vl, channelPair);\r
+ vTraceUBData_Helper(channelPair, vl);\r
+ va_end(vl);\r
+}\r
+#endif\r
+\r
+/* Extracts the channel name and format string from the traceUBChannel, then calls prvTraceUBHelper1. */\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+void vTraceUBData_Helper(traceUBChannel channelPair, va_list vl)\r
+{\r
+ traceString channel;\r
+ traceString formatStr;\r
+\r
+ TRACE_ASSERT(channelPair != 0, "vTraceUBData_Helper: channelPair == 0", TRC_UNUSED);\r
+ TRACE_ASSERT(channelPair <= TRC_CFG_UB_CHANNELS, "vTraceUBData_Helper: ", TRC_UNUSED);\r
+\r
+ channel = RecorderDataPtr->userEventBuffer.channels[channelPair].name;\r
+ formatStr = RecorderDataPtr->userEventBuffer.channels[channelPair].defaultFormat;\r
+\r
+ prvTraceUBHelper1(channelPair, channel, formatStr, vl);\r
+}\r
+#endif\r
+\r
+/******************************************************************************\r
+ * vTraceUBEvent\r
+ *\r
+ * Slightly faster version of ... due to no lookups.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
+void vTraceUBEvent(traceUBChannel channelPair)\r
+{\r
+ uint32_t data[(3 + MAX_ARG_SIZE) / 4];\r
+\r
+ TRACE_ASSERT(channelPair != 0, "vTraceUBEvent: channelPair == 0", TRC_UNUSED);\r
+ TRACE_ASSERT(channelPair <= TRC_CFG_UB_CHANNELS, "vTraceUBEvent: ", TRC_UNUSED);\r
+\r
+ prvTraceUBHelper2(channelPair, data, 1); /* Only need one slot for timestamp */\r
+}\r
+#endif\r
+\r
+/******************************************************************************\r
+ * vTracePrintF\r
+ *\r
+ * Generates User Event with formatted text and data, similar to a "printf".\r
+ * It is very fast compared to a normal "printf" since this function only\r
+ * stores the arguments. The actual formatting is done\r
+ * on the host PC when the trace is displayed in the viewer tool.\r
+ *\r
+ * User Event labels are created using xTraceRegisterString.\r
+ * Example:\r
+ *\r
+ * traceString adc_uechannel = xTraceRegisterString("ADC User Events");\r
+ * ...\r
+ * vTracePrintF(adc_uechannel,\r
+ * "ADC channel %d: %lf volts",\r
+ * ch, (double)adc_reading/(double)scale);\r
+ *\r
+ * This can be combined into one line, if desired, but this is slower:\r
+ *\r
+ * vTracePrintF(xTraceRegisterString("ADC User Events"),\r
+ * "ADC channel %d: %lf volts",\r
+ * ch, (double)adc_reading/(double)scale);\r
+ *\r
+ * Calling xTraceRegisterString multiple times will not create duplicate entries, but\r
+ * it is of course faster to just do it once, and then keep the handle for later\r
+ * use. If you don't have any data arguments, only a text label/string, it is\r
+ * better to use vTracePrint - it is faster.\r
+ *\r
+ * Format specifiers supported:\r
+ * %d - 32 bit signed integer\r
+ * %u - 32 bit unsigned integer\r
+ * %f - 32 bit float\r
+ * %s - string (is copied to the recorder symbol table)\r
+ * %hd - 16 bit signed integer\r
+ * %hu - 16 bit unsigned integer\r
+ * %bd - 8 bit signed integer\r
+ * %bu - 8 bit unsigned integer\r
+ * %lf - double-precision float (Note! See below...)\r
+ *\r
+ * Up to 15 data arguments are allowed, with a total size of maximum 32 byte.\r
+ * In case this is exceeded, the user event is changed into an error message.\r
+ *\r
+ * The data is stored in trace buffer, and is packed to allow storing multiple\r
+ * smaller data entries in the same 4-byte record, e.g., four 8-bit values.\r
+ * A string requires two bytes, as the symbol table is limited to 64K. Storing\r
+ * a double (%lf) uses two records, so this is quite costly. Use float (%f)\r
+ * unless the higher precision is really necessary.\r
+ *\r
+ * Note that the double-precision float (%lf) assumes a 64 bit double\r
+ * representation. This does not seem to be the case on e.g. PIC24 and PIC32.\r
+ * Before using a %lf argument on a 16-bit MCU, please verify that\r
+ * "sizeof(double)" actually gives 8 as expected. If not, use %f instead.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+void vTracePrintF(traceString eventLabel, const char* formatStr, ...)\r
+{\r
+ va_list vl;\r
+\r
+ va_start(vl, formatStr);\r
+ vTracePrintF_Helper(eventLabel, formatStr, vl);\r
+ va_end(vl);\r
+}\r
+#endif\r
+\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list vl)\r
+{\r
+#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 0)\r
+ uint32_t noOfSlots;\r
+ UserEvent* ue1;\r
+ uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ASSERT(formatStr != NULL, "vTracePrintF_Helper: formatStr == NULL", TRC_UNUSED);\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+\r
+ if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+ {\r
+ /* First, write the "primary" user event entry in the local buffer, but\r
+ let the event type be "EVENT_BEING_WRITTEN" for now...*/\r
+\r
+ ue1 = (UserEvent*)(&tempDataBuffer[0]);\r
+\r
+ ue1->type = EVENT_BEING_WRITTEN; /* Update this as the last step */\r
+\r
+ noOfSlots = prvTraceUserEventFormat(formatStr, vl, (uint8_t*)tempDataBuffer, 4);\r
+\r
+ /* Store the format string, with a reference to the channel symbol */\r
+ ue1->payload = prvTraceOpenSymbol(formatStr, eventLabel);\r
+\r
+ ue1->dts = (uint8_t)prvTraceGetDTS(0xFF);\r
+\r
+ /* prvTraceGetDTS might stop the recorder in some cases... */\r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+\r
+ /* If the data does not fit in the remaining main buffer, wrap around to\r
+ 0 if allowed, otherwise stop the recorder and quit). */\r
+ if (RecorderDataPtr->nextFreeIndex + noOfSlots > RecorderDataPtr->maxEvents)\r
+ {\r
+ #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+ (void)memset(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],\r
+ 0,\r
+ (RecorderDataPtr->maxEvents - RecorderDataPtr->nextFreeIndex)*4);\r
+ RecorderDataPtr->nextFreeIndex = 0;\r
+ RecorderDataPtr->bufferIsFull = 1;\r
+ #else\r
+\r
+ /* Stop recorder, since the event data will not fit in the\r
+ buffer and not circular buffer in this case... */\r
+ vTraceStop();\r
+ #endif\r
+ }\r
+\r
+ /* Check if recorder has been stopped (i.e., vTraceStop above) */\r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+ /* Check that the buffer to be overwritten does not contain any user\r
+ events that would be partially overwritten. If so, they must be "killed"\r
+ by replacing the user event and following data with NULL events (i.e.,\r
+ using a memset to zero).*/\r
+ #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+ prvCheckDataToBeOverwrittenForMultiEntryEvents((uint8_t)noOfSlots);\r
+ #endif\r
+ /* Copy the local buffer to the main buffer */\r
+ (void)memcpy(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],\r
+ tempDataBuffer,\r
+ noOfSlots * 4);\r
+\r
+ /* Update the event type, i.e., number of data entries following the\r
+ main USER_EVENT entry (Note: important that this is after the memcpy,\r
+ but within the critical section!)*/\r
+ RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4] =\r
+ (uint8_t) ( USER_EVENT + noOfSlots - 1 );\r
+\r
+ /* Update the main buffer event index (already checked that it fits in\r
+ the buffer, so no need to check for wrapping)*/\r
+\r
+ RecorderDataPtr->nextFreeIndex += noOfSlots;\r
+ RecorderDataPtr->numEvents += noOfSlots;\r
+\r
+ if (RecorderDataPtr->nextFreeIndex >= TRC_CFG_EVENT_BUFFER_SIZE)\r
+ {\r
+ #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+ /* We have reached the end, but this is a ring buffer. Start from the beginning again. */\r
+ RecorderDataPtr->bufferIsFull = 1;\r
+ RecorderDataPtr->nextFreeIndex = 0;\r
+ #else\r
+ /* We have reached the end so we stop. */\r
+ vTraceStop();\r
+ #endif\r
+ }\r
+ }\r
+\r
+ #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+ /* Make sure the next entry is cleared correctly */\r
+ prvCheckDataToBeOverwrittenForMultiEntryEvents(1);\r
+ #endif\r
+\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+\r
+#elif (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
+ /* Use the separate user event buffer */\r
+ traceString formatLabel;\r
+ traceUBChannel channel;\r
+\r
+ if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+ {\r
+ formatLabel = xTraceRegisterString(formatStr);\r
+\r
+ channel = xTraceRegisterUBChannel(eventLabel, formatLabel);\r
+\r
+ prvTraceUBHelper1(channel, eventLabel, formatLabel, vl);\r
+ }\r
+#endif\r
+}\r
+#endif\r
+\r
+/******************************************************************************\r
+ * vTracePrint\r
+ *\r
+ * Basic user event\r
+ *\r
+ * Generates a User Event with a text label. The label is created/looked up\r
+ * in the symbol table using xTraceRegisterString.\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+void vTracePrint(traceString chn, const char* str)\r
+{\r
+#if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 0)\r
+ UserEvent* ue;\r
+ uint8_t dts1;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+ {\r
+ dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
+ ue = (UserEvent*) prvTraceNextFreeEventBufferSlot();\r
+ if (ue != NULL)\r
+ {\r
+ ue->dts = dts1;\r
+ ue->type = USER_EVENT;\r
+ ue->payload = prvTraceOpenSymbol(str, chn);\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+\r
+#elif (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
+ traceUBChannel channel;\r
+ uint32_t noOfSlots = 1;\r
+ uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];\r
+ if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+ {\r
+ traceString trcStr = prvTraceOpenSymbol(str, chn);\r
+ channel = xTraceRegisterUBChannel(chn, trcStr);\r
+\r
+ if (channel == 0)\r
+ {\r
+ /* We are dealing with an unknown channel format pair */\r
+ noOfSlots++; /* Also need room for channel and format */\r
+ ((uint16_t*)tempDataBuffer)[2] = chn;\r
+ ((uint16_t*)tempDataBuffer)[3] = trcStr;\r
+ }\r
+\r
+ prvTraceUBHelper2(channel, tempDataBuffer, noOfSlots);\r
+ }\r
+#endif\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * xTraceRegisterString\r
+ *\r
+ * Register strings in the recorder, e.g. for names of user event channels.\r
+ *\r
+ * Example:\r
+ * myEventHandle = xTraceRegisterString("MyUserEvent");\r
+ * ...\r
+ * vTracePrintF(myEventHandle, "My value is: %d", myValue);\r
+ *\r
+ ******************************************************************************/\r
+#if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
+traceString xTraceRegisterString(const char* label)\r
+{\r
+ TRACE_ASSERT(label != NULL, "xTraceRegisterString: label == NULL", (traceString)0);\r
+\r
+ return prvTraceOpenSymbol(label, 0);\r
+}\r
+#endif\r
+\r
+\r
+#if ((!defined TRC_CFG_INCLUDE_READY_EVENTS) || (TRC_CFG_INCLUDE_READY_EVENTS == 1))\r
+\r
+void prvTraceSetReadyEventsEnabled(int status) \r
+{\r
+ readyEventsEnabled = status;\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreTaskReady\r
+ *\r
+ * This function stores a ready state for the task handle sent in as parameter.\r
+ ******************************************************************************/\r
+void prvTraceStoreTaskReady(traceHandle handle) \r
+{\r
+ uint16_t dts3;\r
+ TREvent* tr;\r
+ uint8_t hnd8;\r
+\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ if (handle == 0)\r
+ {\r
+ /* On FreeRTOS v7.3.0, this occurs when creating tasks due to a bad\r
+ placement of the trace macro. In that case, the events are ignored. */\r
+ return;\r
+ }\r
+ \r
+ if (! readyEventsEnabled)\r
+ {\r
+ /* When creating tasks, ready events are also created. If creating \r
+ a "hidden" (not traced) task, we must therefore disable recording \r
+ of ready events to avoid an undesired ready event... */\r
+ return;\r
+ }\r
+\r
+ TRACE_ASSERT(handle <= TRC_CFG_NTASK, "prvTraceStoreTaskReady: Invalid value for handle", TRC_UNUSED);\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("Recorder busy - high priority ISR using syscall? (1)");\r
+ return;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */\r
+ {\r
+ if (!TRACE_GET_TASK_FLAG_ISEXCLUDED(handle))\r
+ {\r
+ dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+ hnd8 = prvTraceGet8BitHandle(handle);\r
+ tr = (TREvent*)prvTraceNextFreeEventBufferSlot();\r
+ if (tr != NULL)\r
+ {\r
+ tr->type = DIV_TASK_READY;\r
+ tr->dts = dts3;\r
+ tr->objHandle = hnd8;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreLowPower\r
+ *\r
+ * This function stores a low power state.\r
+ ******************************************************************************/\r
+void prvTraceStoreLowPower(uint32_t flag) \r
+{\r
+ uint16_t dts;\r
+ LPEvent* lp;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ASSERT(flag <= 1, "prvTraceStoreLowPower: Invalid flag value", TRC_UNUSED);\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("Recorder busy - high priority ISR using syscall? (1)");\r
+ return;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+ dts = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+ lp = (LPEvent*)prvTraceNextFreeEventBufferSlot();\r
+ if (lp != NULL)\r
+ {\r
+ lp->type = (uint8_t) (LOW_POWER_BEGIN + ( uint8_t ) flag); /* BEGIN or END depending on flag */\r
+ lp->dts = dts;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreMemMangEvent\r
+ *\r
+ * This function stores malloc and free events. Each call requires two records,\r
+ * for size and address respectively. The event code parameter (ecode) is applied\r
+ * to the first record (size) and the following address record gets event\r
+ * code "ecode + 1", so make sure this is respected in the event code table.\r
+ * Note: On "free" calls, the signed_size parameter should be negative.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1)\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_size)\r
+{\r
+ uint8_t dts1;\r
+ MemEventSize * ms;\r
+ MemEventAddr * ma;\r
+ uint16_t size_low;\r
+ uint16_t addr_low;\r
+ uint8_t addr_high;\r
+ uint32_t size;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ if (RecorderDataPtr == NULL)\r
+ {\r
+ /* Occurs in vTraceInitTraceData, if using dynamic allocation. */\r
+ return;\r
+ }\r
+ \r
+ if (signed_size < 0)\r
+ size = (uint32_t)(- signed_size);\r
+ else\r
+ size = (uint32_t)(signed_size);\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ \r
+ heapMemUsage = heapMemUsage + (uint32_t)signed_size;\r
+ \r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+ /* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */\r
+ if (nISRactive || !inExcludedTask)\r
+ {\r
+ dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
+ size_low = (uint16_t)prvTraceGetParam(0xFFFF, size);\r
+ ms = (MemEventSize *)prvTraceNextFreeEventBufferSlot();\r
+\r
+ if (ms != NULL)\r
+ {\r
+ ms->dts = dts1;\r
+ ms->type = NULL_EVENT; /* Updated when all events are written */\r
+ ms->size = size_low;\r
+ prvTraceUpdateCounters();\r
+\r
+ /* Storing a second record with address (signals "failed" if null) */\r
+ #if (TRC_CFG_HEAP_SIZE_BELOW_16M)\r
+ /* If the heap address range is within 16 MB, i.e., the upper 8 bits\r
+ of addresses are constant, this optimization avoids storing an extra\r
+ event record by ignoring the upper 8 bit of the address */\r
+ addr_low = address & 0xFFFF; \r
+ addr_high = (address >> 16) & 0xFF;\r
+ #else\r
+ /* The whole 32 bit address is stored using a second event record\r
+ for the upper 16 bit */\r
+ addr_low = (uint16_t)prvTraceGetParam(0xFFFF, address);\r
+ addr_high = 0;\r
+ #endif\r
+\r
+ ma = (MemEventAddr *) prvTraceNextFreeEventBufferSlot();\r
+ if (ma != NULL)\r
+ {\r
+ ma->addr_low = addr_low;\r
+ ma->addr_high = addr_high;\r
+ ma->type = (uint8_t) (ecode + 1); /* Note this! */\r
+ ms->type = (uint8_t) ecode;\r
+ prvTraceUpdateCounters(); \r
+ RecorderDataPtr->heapMemUsage = heapMemUsage;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+#endif /* TRC_CFG_SCHEDULING_ONLY */\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreKernelCall\r
+ *\r
+ * This is the main integration point for storing kernel calls, and\r
+ * is called by the hooks in trcKernelHooks.h (see trcKernelPort.h for event codes).\r
+ ******************************************************************************/\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+void prvTraceStoreKernelCall(uint32_t ecode, traceObjectClass objectClass, uint32_t objectNumber)\r
+{\r
+ KernelCall * kse;\r
+ uint16_t dts1;\r
+ uint8_t hnd8;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ASSERT(ecode < 0xFF, "prvTraceStoreKernelCall: ecode >= 0xFF", TRC_UNUSED);\r
+ TRACE_ASSERT(objectClass < TRACE_NCLASSES, "prvTraceStoreKernelCall: objectClass >= TRACE_NCLASSES", TRC_UNUSED);\r
+ TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "prvTraceStoreKernelCall: Invalid value for objectNumber", TRC_UNUSED);\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("Recorder busy - high priority ISR using syscall? (2)");\r
+ return;\r
+ }\r
+\r
+ if (handle_of_last_logged_task == 0)\r
+ {\r
+ return;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+ /* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */\r
+ if (nISRactive || !inExcludedTask)\r
+ {\r
+ /* Check if the referenced object or the event code is excluded */\r
+ if (!uiTraceIsObjectExcluded(objectClass, (traceHandle)objectNumber) && !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(ecode))\r
+ {\r
+ dts1 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+ hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);\r
+ kse = (KernelCall*) prvTraceNextFreeEventBufferSlot();\r
+ if (kse != NULL)\r
+ {\r
+ kse->dts = dts1;\r
+ kse->type = (uint8_t)ecode;\r
+ kse->objHandle = hnd8;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+#endif /* TRC_CFG_SCHEDULING_ONLY */\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreKernelCallWithParam\r
+ *\r
+ * Used for storing kernel calls with a handle and a numeric parameter. If the\r
+ * numeric parameter does not fit in one byte, and extra XPS event is inserted\r
+ * before the kernel call event containing the three upper bytes.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+void prvTraceStoreKernelCallWithParam(uint32_t evtcode,\r
+ traceObjectClass objectClass,\r
+ uint32_t objectNumber,\r
+ uint32_t param)\r
+{\r
+ KernelCallWithParamAndHandle * kse;\r
+ uint8_t dts2;\r
+ uint8_t hnd8;\r
+ uint8_t p8;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ASSERT(evtcode < 0xFF, "prvTraceStoreKernelCallWithParam: evtcode >= 0xFF", TRC_UNUSED);\r
+ TRACE_ASSERT(objectClass < TRACE_NCLASSES, "prvTraceStoreKernelCallWithParam: objectClass >= TRACE_NCLASSES", TRC_UNUSED);\r
+ TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "prvTraceStoreKernelCallWithParam: Invalid value for objectNumber", TRC_UNUSED);\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("Recorder busy - high priority ISR using syscall? (3)");\r
+ return;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive && handle_of_last_logged_task && (! inExcludedTask || nISRactive))\r
+ {\r
+ /* Check if the referenced object or the event code is excluded */\r
+ if (!uiTraceIsObjectExcluded(objectClass, (traceHandle)objectNumber) &&\r
+ !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))\r
+ {\r
+ dts2 = (uint8_t)prvTraceGetDTS(0xFF);\r
+ p8 = (uint8_t) prvTraceGetParam(0xFF, param);\r
+ hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);\r
+ kse = (KernelCallWithParamAndHandle*) prvTraceNextFreeEventBufferSlot();\r
+ if (kse != NULL)\r
+ {\r
+ kse->dts = dts2;\r
+ kse->type = (uint8_t)evtcode;\r
+ kse->objHandle = hnd8;\r
+ kse->param = p8;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+#endif /* TRC_CFG_SCHEDULING_ONLY */\r
+\r
+\r
+/*******************************************************************************\r
+ * prvTraceGetParam\r
+ *\r
+ * Used for storing extra bytes for kernel calls with numeric parameters.\r
+ *\r
+ * May only be called within a critical section!\r
+ ******************************************************************************/\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+static uint32_t prvTraceGetParam(uint32_t param_max, uint32_t param)\r
+{\r
+ XPSEvent* xps;\r
+\r
+ TRACE_ASSERT(param_max == 0xFF || param_max == 0xFFFF,\r
+ "prvTraceGetParam: Invalid value for param_max", param);\r
+\r
+ if (param <= param_max)\r
+ {\r
+ return param;\r
+ }\r
+ else\r
+ {\r
+ xps = (XPSEvent*) prvTraceNextFreeEventBufferSlot();\r
+ if (xps != NULL)\r
+ {\r
+ xps->type = DIV_XPS;\r
+ xps->xps_8 = (uint8_t)(param & (0xFF00 & ~param_max)) >> 8;\r
+ xps->xps_16 = (uint16_t)(param & (0xFFFF0000 & ~param_max)) >> 16;\r
+ prvTraceUpdateCounters();\r
+ }\r
+\r
+ return param & param_max;\r
+ }\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreKernelCallWithNumericParamOnly\r
+ *\r
+ * Used for storing kernel calls with numeric parameters only. This is\r
+ * only used for traceTASK_DELAY and traceDELAY_UNTIL at the moment.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_SCHEDULING_ONLY == 0)\r
+void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param)\r
+{\r
+ KernelCallWithParam16 * kse;\r
+ uint8_t dts6;\r
+ uint16_t restParam;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ restParam = 0;\r
+\r
+ TRACE_ASSERT(evtcode < 0xFF, "prvTraceStoreKernelCallWithNumericParamOnly: Invalid value for evtcode", TRC_UNUSED);\r
+\r
+ if (recorder_busy)\r
+ {\r
+ /*************************************************************************\r
+ * This occurs if an ISR calls a trace function, preempting a previous\r
+ * trace call that is being processed in a different ISR or task. \r
+ * If this occurs, there is probably a problem in the definition of the\r
+ * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
+ * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
+ * and any other ISRs that calls the trace recorder directly or via\r
+ * traced kernel functions. The ARM port disables all interrupts using the\r
+ * PRIMASK register to avoid this issue.\r
+ *************************************************************************/\r
+ prvTraceError("Recorder busy - high priority ISR using syscall? (4)");\r
+ return;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ if (RecorderDataPtr->recorderActive && handle_of_last_logged_task\r
+ && (! inExcludedTask || nISRactive))\r
+ {\r
+ /* Check if the event code is excluded */\r
+ if (!TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))\r
+ {\r
+ dts6 = (uint8_t)prvTraceGetDTS(0xFF);\r
+ restParam = (uint16_t)prvTraceGetParam(0xFFFF, param);\r
+ kse = (KernelCallWithParam16*) prvTraceNextFreeEventBufferSlot();\r
+ if (kse != NULL)\r
+ {\r
+ kse->dts = dts6;\r
+ kse->type = (uint8_t)evtcode;\r
+ kse->param = restParam;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+}\r
+#endif /* TRC_CFG_SCHEDULING_ONLY */\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreTaskswitch\r
+ * Called by the scheduler from the SWITCHED_OUT hook, and by uiTraceStart.\r
+ * At this point interrupts are assumed to be disabled!\r
+ ******************************************************************************/\r
+void prvTraceStoreTaskswitch(traceHandle task_handle)\r
+{\r
+ uint16_t dts3;\r
+ TSEvent* ts;\r
+ int8_t skipEvent;\r
+ uint8_t hnd8;\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
+ extern int32_t isPendingContextSwitch;\r
+#endif\r
+ trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY();\r
+\r
+ skipEvent = 0;\r
+\r
+ TRACE_ASSERT(task_handle <= TRC_CFG_NTASK,\r
+ "prvTraceStoreTaskswitch: Invalid value for task_handle", TRC_UNUSED);\r
+\r
+ /* Skip the event if the task has been excluded, using vTraceExcludeTask */\r
+ if (TRACE_GET_TASK_FLAG_ISEXCLUDED(task_handle))\r
+ {\r
+ skipEvent = 1;\r
+ inExcludedTask = 1;\r
+ }\r
+ else\r
+ {\r
+ inExcludedTask = 0;\r
+ }\r
+\r
+ trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY();\r
+\r
+ /* Skip the event if the same task is scheduled */\r
+ if (task_handle == handle_of_last_logged_task)\r
+ {\r
+ skipEvent = 1;\r
+ }\r
+\r
+ if (!RecorderDataPtr->recorderActive)\r
+ {\r
+ skipEvent = 1;\r
+ }\r
+\r
+ /* If this event should be logged, log it! */\r
+ if (skipEvent == 0)\r
+ {\r
+#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
+ isPendingContextSwitch = 0;\r
+#endif\r
+\r
+ dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+ handle_of_last_logged_task = task_handle;\r
+ hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);\r
+ ts = (TSEvent*)prvTraceNextFreeEventBufferSlot();\r
+\r
+ if (ts != NULL)\r
+ {\r
+ if (prvTraceGetObjectState(TRACE_CLASS_TASK,\r
+ handle_of_last_logged_task) == TASK_STATE_INSTANCE_ACTIVE)\r
+ {\r
+ ts->type = TS_TASK_RESUME;\r
+ }\r
+ else\r
+ {\r
+ ts->type = TS_TASK_BEGIN;\r
+ }\r
+\r
+ ts->dts = dts3;\r
+ ts->objHandle = hnd8;\r
+\r
+ prvTraceSetObjectState(TRACE_CLASS_TASK,\r
+ handle_of_last_logged_task,\r
+ TASK_STATE_INSTANCE_ACTIVE);\r
+\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+\r
+ trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY();\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvTraceStoreObjectNameOnCloseEvent\r
+ *\r
+ * Updates the symbol table with the name of this object from the dynamic\r
+ * objects table and stores a "close" event, holding the mapping between handle\r
+ * and name (a symbol table handle). The stored name-handle mapping is thus the\r
+ * "old" one, valid up until this point.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
+void prvTraceStoreObjectNameOnCloseEvent(traceHandle handle,\r
+ traceObjectClass objectclass)\r
+{\r
+ ObjCloseNameEvent * ce;\r
+ const char * name;\r
+ traceString idx;\r
+\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
+ "prvTraceStoreObjectNameOnCloseEvent: objectclass >= TRACE_NCLASSES", TRC_UNUSED);\r
+ TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
+ "prvTraceStoreObjectNameOnCloseEvent: Invalid value for handle", TRC_UNUSED);\r
+\r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+ uint8_t hnd8 = prvTraceGet8BitHandle(handle);\r
+ name = TRACE_PROPERTY_NAME_GET(objectclass, handle);\r
+ idx = prvTraceOpenSymbol(name, 0);\r
+\r
+ // Interrupt disable not necessary, already done in trcHooks.h macro\r
+ ce = (ObjCloseNameEvent*) prvTraceNextFreeEventBufferSlot();\r
+ if (ce != NULL)\r
+ {\r
+ ce->type = (uint8_t) (EVENTGROUP_OBJCLOSE_NAME + objectclass);\r
+ ce->objHandle = hnd8;\r
+ ce->symbolIndex = idx;\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+}\r
+\r
+void prvTraceStoreObjectPropertiesOnCloseEvent(traceHandle handle,\r
+ traceObjectClass objectclass)\r
+{\r
+ ObjClosePropEvent * pe;\r
+\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
+ "prvTraceStoreObjectPropertiesOnCloseEvent: objectclass >= TRACE_NCLASSES", TRC_UNUSED);\r
+ TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
+ "prvTraceStoreObjectPropertiesOnCloseEvent: Invalid value for handle", TRC_UNUSED);\r
+\r
+ if (RecorderDataPtr->recorderActive)\r
+ {\r
+ // Interrupt disable not necessary, already done in trcHooks.h macro\r
+ pe = (ObjClosePropEvent*) prvTraceNextFreeEventBufferSlot();\r
+ if (pe != NULL)\r
+ {\r
+ if (objectclass == TRACE_CLASS_TASK)\r
+ {\r
+ pe->arg1 = TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle);\r
+ }\r
+ else\r
+ {\r
+ pe->arg1 = TRACE_PROPERTY_OBJECT_STATE(objectclass, handle);\r
+ }\r
+ pe->type = (uint8_t) (EVENTGROUP_OBJCLOSE_PROP + objectclass);\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+}\r
+#endif\r
+\r
+void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value)\r
+{\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
+ "prvTraceSetPriorityProperty: objectclass >= TRACE_NCLASSES", TRC_UNUSED);\r
+ TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
+ "prvTraceSetPriorityProperty: Invalid value for id", TRC_UNUSED);\r
+\r
+ TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id) = value;\r
+}\r
+\r
+uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id)\r
+{\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
+ "prvTraceGetPriorityProperty: objectclass >= TRACE_NCLASSES", 0);\r
+ TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
+ "prvTraceGetPriorityProperty: Invalid value for id", 0);\r
+\r
+ return TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id);\r
+}\r
+\r
+void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value)\r
+{\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
+ "prvTraceSetObjectState: objectclass >= TRACE_NCLASSES", TRC_UNUSED);\r
+ TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
+ "prvTraceSetObjectState: Invalid value for id", TRC_UNUSED);\r
+\r
+ TRACE_PROPERTY_OBJECT_STATE(objectclass, id) = value;\r
+}\r
+\r
+uint8_t prvTraceGetObjectState(uint8_t objectclass, traceHandle id)\r
+{\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
+ "prvTraceGetObjectState: objectclass >= TRACE_NCLASSES", 0);\r
+ TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
+ "prvTraceGetObjectState: Invalid value for id", 0);\r
+\r
+ return TRACE_PROPERTY_OBJECT_STATE(objectclass, id);\r
+}\r
+\r
+void prvTraceSetTaskInstanceFinished(traceHandle handle)\r
+{\r
+ TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_TASK],\r
+ "prvTraceSetTaskInstanceFinished: Invalid value for handle", TRC_UNUSED);\r
+\r
+#if (TRC_CFG_USE_IMPLICIT_IFE_RULES == 1)\r
+ TRACE_PROPERTY_OBJECT_STATE(TRACE_CLASS_TASK, handle) = 0;\r
+#endif\r
+}\r
+\r
+/*******************************************************************************\r
+ * Static data initializations\r
+ ******************************************************************************/\r
+\r
+/* Tasks and kernel objects can be explicitly excluded from the trace to reduce\r
+buffer usage. This structure handles the exclude flags for all objects and tasks. \r
+Note that slot 0 is not used, since not a valid handle. */\r
+uint8_t trcExcludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1] = { 0 };\r
+\r
+/* Specific events can also be excluded, i.e., by the event code. This can be\r
+used to exclude kernel calls that don't refer to a kernel object, like a delay.\r
+This structure handle the exclude flags for all event codes */\r
+uint8_t trcExcludedEventCodes[NEventCodes / 8 + 1] = { 0 };\r
+\r
+/* A set of stacks that keeps track of available object handles for each class.\r
+The stacks are empty initially, meaning that allocation of new handles will be \r
+based on a counter (for each object class). Any delete operation will\r
+return the handle to the corresponding stack, for reuse on the next allocate.*/\r
+objectHandleStackType objectHandleStacks = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };\r
+\r
+/* Initial TRC_HWTC_COUNT value, for detecting if the time-stamping source is \r
+enabled. If using the OS periodic timer for time-stamping, this might not \r
+have been configured on the earliest events during the startup. */\r
+uint32_t init_hwtc_count;\r
+\r
+/*******************************************************************************\r
+ * RecorderData\r
+ *\r
+ * The main data structure in snapshot mode, when using the default static memory\r
+ * allocation (TRC_RECORDER_BUFFER_ALLOCATION_STATIC). The recorder uses a pointer\r
+ * RecorderDataPtr to access the data, to also allow for dynamic or custom data\r
+ * allocation (see TRC_CFG_RECORDER_BUFFER_ALLOCATION).\r
+ ******************************************************************************/\r
+#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)\r
+RecorderDataType RecorderData;\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * RecorderDataPtr\r
+ *\r
+ * Pointer to the main data structure, when in snapshot mode. \r
+ ******************************************************************************/\r
+RecorderDataType* RecorderDataPtr = NULL;\r
+\r
+/* This version of the function dynamically allocates the trace data */\r
+void prvTraceInitTraceData()\r
+{ \r
+ \r
+ if (RecorderDataPtr == NULL)\r
+ {\r
+#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)\r
+ RecorderDataPtr = &RecorderData;\r
+#elif (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC)\r
+ RecorderDataPtr = (RecorderDataType*)TRACE_MALLOC(sizeof(RecorderDataType));\r
+ if (! RecorderDataPtr)\r
+ {\r
+ prvTraceError("Failed allocating recorder buffer!");\r
+ return;\r
+ }\r
+#elif (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
+ if (! RecorderDataPtr)\r
+ {\r
+ prvTraceError("Recorder data pointer not set! Use vTraceSetRecorderDataBuffer().");\r
+ return;\r
+ }\r
+#endif\r
+ }\r
+ else\r
+ {\r
+ if (RecorderDataPtr->startmarker0 == 1)\r
+ {\r
+ /* Already initialized */\r
+ return;\r
+ }\r
+ }\r
+ \r
+ init_hwtc_count = TRC_HWTC_COUNT;\r
+ \r
+ (void)memset(RecorderDataPtr, 0, sizeof(RecorderDataType));\r
+ \r
+ RecorderDataPtr->version = TRACE_KERNEL_VERSION;\r
+ RecorderDataPtr->minor_version = TRACE_MINOR_VERSION;\r
+ RecorderDataPtr->irq_priority_order = TRC_IRQ_PRIORITY_ORDER;\r
+ RecorderDataPtr->filesize = sizeof(RecorderDataType);\r
+ RecorderDataPtr->maxEvents = TRC_CFG_EVENT_BUFFER_SIZE;\r
+ RecorderDataPtr->debugMarker0 = (int32_t) 0xF0F0F0F0;\r
+ RecorderDataPtr->isUsing16bitHandles = TRC_CFG_USE_16BIT_OBJECT_HANDLES;\r
+ RecorderDataPtr->isrTailchainingThreshold = TRC_CFG_ISR_TAILCHAINING_THRESHOLD;\r
+\r
+ /* This function is kernel specific */\r
+ vTraceInitObjectPropertyTable();\r
+\r
+ RecorderDataPtr->debugMarker1 = (int32_t)0xF1F1F1F1;\r
+ RecorderDataPtr->SymbolTable.symTableSize = TRC_CFG_SYMBOL_TABLE_SIZE;\r
+ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex = 1;\r
+#if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)\r
+ RecorderDataPtr->exampleFloatEncoding = 1.0f; /* otherwise already zero */\r
+#endif\r
+ RecorderDataPtr->debugMarker2 = (int32_t)0xF2F2F2F2;\r
+ prvStrncpy(RecorderDataPtr->systemInfo, "Trace Recorder Demo", 80);\r
+ RecorderDataPtr->debugMarker3 = (int32_t)0xF3F3F3F3;\r
+ RecorderDataPtr->endmarker0 = 0x0A;\r
+ RecorderDataPtr->endmarker1 = 0x0B;\r
+ RecorderDataPtr->endmarker2 = 0x0C;\r
+ RecorderDataPtr->endmarker3 = 0x0D;\r
+ RecorderDataPtr->endmarker4 = 0x71;\r
+ RecorderDataPtr->endmarker5 = 0x72;\r
+ RecorderDataPtr->endmarker6 = 0x73;\r
+ RecorderDataPtr->endmarker7 = 0x74;\r
+ RecorderDataPtr->endmarker8 = 0xF1;\r
+ RecorderDataPtr->endmarker9 = 0xF2;\r
+ RecorderDataPtr->endmarker10 = 0xF3;\r
+ RecorderDataPtr->endmarker11 = 0xF4;\r
+\r
+#if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER\r
+ RecorderDataPtr->userEventBuffer.bufferID = 1;\r
+ RecorderDataPtr->userEventBuffer.version = 0;\r
+ RecorderDataPtr->userEventBuffer.numberOfSlots = TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE;\r
+ RecorderDataPtr->userEventBuffer.numberOfChannels = TRC_CFG_UB_CHANNELS + 1;\r
+#endif\r
+\r
+ /* Kernel specific initialization of the objectHandleStacks variable */\r
+ vTraceInitObjectHandleStack();\r
+\r
+ \r
+ /* Finally, the 12-byte "start markers" are initialized, allowing for \r
+ Tracealyzer to find the trace data in a larger RAM dump. \r
+ \r
+ The start and end markers must be unique, but without proper precautions there\r
+ might be a risk of accidental duplicates of the start/end markers, e.g., due to\r
+ compiler optimizations.\r
+ \r
+ The below initialization of the start marker is therefore made in reverse order \r
+ and the fields are volatile to ensure this assignment order. This to avoid any \r
+ chance of accidental duplicates of this elsewhere in memory.\r
+ \r
+ Moreover, the fields are set byte-by-byte to avoid endian issues.*/\r
+ \r
+ RecorderDataPtr->startmarker11 = 0xF4;\r
+ RecorderDataPtr->startmarker10 = 0xF3;\r
+ RecorderDataPtr->startmarker9 = 0xF2;\r
+ RecorderDataPtr->startmarker8 = 0xF1;\r
+ RecorderDataPtr->startmarker7 = 0x74;\r
+ RecorderDataPtr->startmarker6 = 0x73;\r
+ RecorderDataPtr->startmarker5 = 0x72;\r
+ RecorderDataPtr->startmarker4 = 0x71;\r
+ RecorderDataPtr->startmarker3 = 0x04;\r
+ RecorderDataPtr->startmarker2 = 0x03;\r
+ RecorderDataPtr->startmarker1 = 0x02; \r
+ RecorderDataPtr->startmarker0 = 0x01; \r
+\r
+ \r
+#ifdef TRC_PORT_SPECIFIC_INIT\r
+ TRC_PORT_SPECIFIC_INIT();\r
+#endif\r
+}\r
+\r
+\r
+void* prvTraceNextFreeEventBufferSlot(void)\r
+{\r
+ if (! RecorderDataPtr->recorderActive)\r
+ {\r
+ /* If an XTS or XPS event prior to the main event has filled the buffer\r
+ before saving the main event, and store mode is "stop when full". */\r
+ return NULL;\r
+ }\r
+\r
+ if (RecorderDataPtr->nextFreeIndex >= TRC_CFG_EVENT_BUFFER_SIZE)\r
+ {\r
+ prvTraceError("Attempt to index outside event buffer!");\r
+ return NULL;\r
+ }\r
+ return (void*)(&RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex*4]);\r
+}\r
+\r
+uint16_t uiIndexOfObject(traceHandle objecthandle, uint8_t objectclass)\r
+{\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES, \r
+ "uiIndexOfObject: Invalid value for objectclass", 0);\r
+ TRACE_ASSERT(objecthandle > 0 && objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], \r
+ "uiIndexOfObject: Invalid value for objecthandle", 0);\r
+\r
+ if ((objectclass < TRACE_NCLASSES) && (objecthandle > 0) && \r
+ (objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass]))\r
+ {\r
+ return (uint16_t)(RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[objectclass] + \r
+ (RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[objectclass] * (objecthandle-1)));\r
+ }\r
+\r
+ prvTraceError("Object table lookup with invalid object handle or object class!");\r
+ return 0;\r
+}\r
+\r
+traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass)\r
+{\r
+ traceHandle handle;\r
+ static int indexOfHandle;\r
+\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES, \r
+ "prvTraceGetObjectHandle: Invalid value for objectclass", (traceHandle)0);\r
+\r
+ indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];\r
+ if (objectHandleStacks.objectHandles[indexOfHandle] == 0)\r
+ {\r
+ /* Zero is used to indicate a never before used handle, i.e.,\r
+ new slots in the handle stack. The handle slot needs to\r
+ be initialized here (starts at 1). */\r
+ objectHandleStacks.objectHandles[indexOfHandle] =\r
+ (traceHandle)(1 + indexOfHandle -\r
+ objectHandleStacks.lowestIndexOfClass[objectclass]);\r
+ }\r
+\r
+ handle = objectHandleStacks.objectHandles[indexOfHandle];\r
+\r
+ if (objectHandleStacks.indexOfNextAvailableHandle[objectclass]\r
+ > objectHandleStacks.highestIndexOfClass[objectclass])\r
+ {\r
+ prvTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));\r
+ handle = 0;\r
+ }\r
+ else\r
+ {\r
+ int hndCount;\r
+ objectHandleStacks.indexOfNextAvailableHandle[objectclass]++;\r
+\r
+ hndCount = objectHandleStacks.indexOfNextAvailableHandle[objectclass] -\r
+ objectHandleStacks.lowestIndexOfClass[objectclass];\r
+\r
+ if (hndCount >\r
+ objectHandleStacks.handleCountWaterMarksOfClass[objectclass])\r
+ {\r
+ objectHandleStacks.handleCountWaterMarksOfClass[objectclass] =\r
+ (traceHandle)hndCount;\r
+ }\r
+ TRACE_CLEAR_OBJECT_FLAG_ISEXCLUDED(objectclass, handle);\r
+ }\r
+ return handle;\r
+}\r
+\r
+void prvTraceFreeObjectHandle(traceObjectClass objectclass, traceHandle handle)\r
+{\r
+ int indexOfHandle;\r
+\r
+ TRACE_ASSERT(objectclass < TRACE_NCLASSES, \r
+ "prvTraceFreeObjectHandle: Invalid value for objectclass", TRC_UNUSED);\r
+ TRACE_ASSERT(handle > 0 && handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], \r
+ "prvTraceFreeObjectHandle: Invalid value for handle", TRC_UNUSED);\r
+\r
+ /* Check that there is room to push the handle on the stack */\r
+ if ((objectHandleStacks.indexOfNextAvailableHandle[objectclass] - 1) <\r
+ objectHandleStacks.lowestIndexOfClass[objectclass])\r
+ {\r
+ /* Error */\r
+ prvTraceError("Attempt to free more handles than allocated!");\r
+ }\r
+ else\r
+ {\r
+ objectHandleStacks.indexOfNextAvailableHandle[objectclass]--;\r
+ indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];\r
+ objectHandleStacks.objectHandles[indexOfHandle] = handle;\r
+ }\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvMarkObjectAsUsed\r
+ *\r
+ * Sets an "is used flag" on object creation, using the first byte of the name\r
+ * field. This allows for counting the number of used Object Table slots, even\r
+ * if no names have been set.\r
+ ******************************************************************************/\r
+void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle)\r
+{\r
+ uint16_t idx = uiIndexOfObject(handle, objectclass);\r
+ RecorderDataPtr->ObjectPropertyTable.objbytes[idx] = 1;\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvStrncpy\r
+ *\r
+ * Private string copy function, to improve portability between compilers.\r
+ ******************************************************************************/\r
+static void prvStrncpy(char* dst, const char* src, uint32_t maxLength)\r
+{\r
+ uint32_t i;\r
+ for (i = 0; i < maxLength; i++)\r
+ {\r
+ dst[i] = src[i];\r
+ if (src[i] == 0)\r
+ break;\r
+ }\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvTraceSetObjectName\r
+ *\r
+ * Registers the names of queues, semaphores and other kernel objects in the\r
+ * recorder's Object Property Table, at the given handle and object class.\r
+ ******************************************************************************/\r
+void prvTraceSetObjectName(traceObjectClass objectclass,\r
+ traceHandle handle,\r
+ const char* name)\r
+{\r
+ static uint16_t idx;\r
+\r
+ TRACE_ASSERT(name != NULL, "prvTraceSetObjectName: name == NULL", TRC_UNUSED);\r
+\r
+ if (objectclass >= TRACE_NCLASSES)\r
+ {\r
+ prvTraceError("Illegal object class in prvTraceSetObjectName");\r
+ return;\r
+ }\r
+\r
+ if (handle == 0)\r
+ {\r
+ prvTraceError("Illegal handle (0) in prvTraceSetObjectName.");\r
+ return;\r
+ }\r
+\r
+ if (handle > RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass])\r
+ {\r
+ /* ERROR */\r
+ prvTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));\r
+ }\r
+ else\r
+ {\r
+ idx = uiIndexOfObject(handle, objectclass);\r
+\r
+ if (traceErrorMessage == NULL)\r
+ {\r
+ prvStrncpy((char*)&(RecorderDataPtr->ObjectPropertyTable.objbytes[idx]),\r
+ name,\r
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[ objectclass ]);\r
+ }\r
+ }\r
+}\r
+\r
+traceString prvTraceOpenSymbol(const char* name, traceString userEventChannel)\r
+{\r
+ uint16_t result;\r
+ uint8_t len;\r
+ uint8_t crc;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+ \r
+ len = 0;\r
+ crc = 0;\r
+ \r
+ TRACE_ASSERT(name != NULL, "prvTraceOpenSymbol: name == NULL", (traceString)0);\r
+\r
+ prvTraceGetChecksum(name, &crc, &len);\r
+\r
+ trcCRITICAL_SECTION_BEGIN();\r
+ result = prvTraceLookupSymbolTableEntry(name, crc, len, userEventChannel);\r
+ if (!result)\r
+ {\r
+ result = prvTraceCreateSymbolTableEntry(name, crc, len, userEventChannel);\r
+ }\r
+ trcCRITICAL_SECTION_END();\r
+\r
+ return result;\r
+}\r
+\r
+\r
+/******************************************************************************\r
+* vTraceSetFrequency\r
+*\r
+* Registers the clock rate of the time source for the event timestamping.\r
+* This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)\r
+* should be incorrect for your setup, you can override it using this function.\r
+*\r
+* Must be called prior to vTraceEnable, and the time source is assumed to\r
+* have a fixed clock frequency after the startup.\r
+*\r
+* Note that, in snapshot mode, the value is divided by the TRC_HWTC_DIVISOR.\r
+* This is a software "prescaler" that is also applied on the timestamps.\r
+*****************************************************************************/\r
+void vTraceSetFrequency(uint32_t frequency)\r
+{\r
+ timestampFrequency = frequency;\r
+}\r
+\r
+/*******************************************************************************\r
+ * Supporting functions\r
+ ******************************************************************************/\r
+\r
+/*******************************************************************************\r
+ * prvTraceError\r
+ *\r
+ * Called by various parts in the recorder. Stops the recorder and stores a\r
+ * pointer to an error message, which is printed by the monitor task.\r
+ * If you are not using the monitor task, you may use xTraceGetLastError()\r
+ * from your application to check if the recorder is OK.\r
+ *\r
+ * Note: If a recorder error is registered before vTraceStart is called, the\r
+ * trace start will be aborted. This can occur if any of the Nxxxx constants\r
+ * (e.g., TRC_CFG_NTASK) in trcConfig.h is too small.\r
+ ******************************************************************************/\r
+void prvTraceError(const char* msg)\r
+{\r
+ /* Stop the recorder */\r
+ vTraceStop();\r
+ \r
+ /* If first error only... */\r
+ if (traceErrorMessage == NULL)\r
+ {\r
+ traceErrorMessage = (char*)(intptr_t) msg;\r
+ if (RecorderDataPtr != NULL)\r
+ {\r
+ prvStrncpy(RecorderDataPtr->systemInfo, traceErrorMessage, 80);\r
+ RecorderDataPtr->internalErrorOccured = 1;\r
+ }\r
+ }\r
+}\r
+\r
+/******************************************************************************\r
+ * prvCheckDataToBeOverwrittenForMultiEntryEvents\r
+ *\r
+ * This checks if the next event to be overwritten is a multi-entry user event,\r
+ * i.e., a USER_EVENT followed by data entries.\r
+ * Such data entries do not have an event code at byte 0, as other events.\r
+ * All 4 bytes are user data, so the first byte of such data events must\r
+ * not be interpreted as type field. The number of data entries following\r
+ * a USER_EVENT is given in the event code of the USER_EVENT.\r
+ * Therefore, when overwriting a USER_EVENT (when using in ring-buffer mode)\r
+ * any data entries following must be replaced with NULL events (code 0).\r
+ *\r
+ * This is assumed to execute within a critical section...\r
+ *****************************************************************************/\r
+\r
+#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nofEntriesToCheck)\r
+{\r
+ /* Generic "int" type is desired - should be 16 bit variable on 16 bit HW */\r
+ unsigned int i = 0;\r
+ unsigned int e = 0;\r
+\r
+ TRACE_ASSERT(nofEntriesToCheck != 0, \r
+ "prvCheckDataToBeOverwrittenForMultiEntryEvents: nofEntriesToCheck == 0", TRC_UNUSED);\r
+\r
+ while (i < nofEntriesToCheck)\r
+ {\r
+ e = RecorderDataPtr->nextFreeIndex + i;\r
+ if ((RecorderDataPtr->eventData[e*4] > USER_EVENT) &&\r
+ (RecorderDataPtr->eventData[e*4] < USER_EVENT + 16))\r
+ {\r
+ uint8_t nDataEvents = (uint8_t)(RecorderDataPtr->eventData[e*4] - USER_EVENT);\r
+ if ((e + nDataEvents) < RecorderDataPtr->maxEvents)\r
+ {\r
+ (void)memset(& RecorderDataPtr->eventData[e*4], 0, (size_t) (4 + 4 * nDataEvents));\r
+ }\r
+ }\r
+ else if (RecorderDataPtr->eventData[e*4] == DIV_XPS)\r
+ {\r
+ if ((e + 1) < RecorderDataPtr->maxEvents)\r
+ {\r
+ /* Clear 8 bytes */\r
+ (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4 + 4);\r
+ }\r
+ else\r
+ {\r
+ /* Clear 8 bytes, 4 first and 4 last */\r
+ (void)memset(& RecorderDataPtr->eventData[0], 0, 4);\r
+ (void)memset(& RecorderDataPtr->eventData[e*4], 0, 4);\r
+ }\r
+ }\r
+ i++;\r
+ }\r
+}\r
+#endif\r
+\r
+/*******************************************************************************\r
+ * prvTraceUpdateCounters\r
+ *\r
+ * Updates the index of the event buffer.\r
+ ******************************************************************************/\r
+void prvTraceUpdateCounters(void)\r
+{ \r
+ if (RecorderDataPtr->recorderActive == 0)\r
+ {\r
+ return;\r
+ }\r
+ \r
+ RecorderDataPtr->numEvents++;\r
+\r
+ RecorderDataPtr->nextFreeIndex++;\r
+\r
+ if (RecorderDataPtr->nextFreeIndex >= TRC_CFG_EVENT_BUFFER_SIZE)\r
+ {\r
+#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+ RecorderDataPtr->bufferIsFull = 1;\r
+ RecorderDataPtr->nextFreeIndex = 0;\r
+#else\r
+ vTraceStop();\r
+#endif\r
+ }\r
+\r
+#if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
+ prvCheckDataToBeOverwrittenForMultiEntryEvents(1);\r
+#endif\r
+}\r
+\r
+/******************************************************************************\r
+ * prvTraceGetDTS\r
+ *\r
+ * Returns a differential timestamp (DTS), i.e., the time since\r
+ * last event, and creates an XTS event if the DTS does not fit in the\r
+ * number of bits given. The XTS event holds the MSB bytes of the DTS.\r
+ *\r
+ * The parameter param_maxDTS should be 0xFF for 8-bit dts or 0xFFFF for\r
+ * events with 16-bit dts fields.\r
+ *****************************************************************************/\r
+uint16_t prvTraceGetDTS(uint16_t param_maxDTS)\r
+{\r
+ static uint32_t old_timestamp = 0;\r
+ XTSEvent* xts = 0;\r
+ uint32_t dts = 0;\r
+ uint32_t timestamp = 0;\r
+\r
+ TRACE_ASSERT(param_maxDTS == 0xFF || param_maxDTS == 0xFFFF, "prvTraceGetDTS: Invalid value for param_maxDTS", 0);\r
+\r
+ \r
+ if (RecorderDataPtr->frequency == 0)\r
+ { \r
+ if (timestampFrequency != 0)\r
+ {\r
+ /* If to override default TRC_HWTC_FREQ_HZ value with value set by vTraceSetFrequency */\r
+ RecorderDataPtr->frequency = timestampFrequency / TRC_HWTC_DIVISOR;\r
+ } \r
+ else if (init_hwtc_count != TRC_HWTC_COUNT)\r
+ {\r
+ /* If using default value and timer has been started. \r
+ Note: If the default frequency value set here would be incorrect, e.g.,\r
+ if the timer has actually not been configured yet, override this \r
+ with vTraceSetFrequency.\r
+ */\r
+ RecorderDataPtr->frequency = TRC_HWTC_FREQ_HZ / TRC_HWTC_DIVISOR; \r
+ }\r
+ /* If no override (vTraceSetFrequency) and timer inactive -> no action */\r
+ }\r
+ \r
+ /**************************************************************************\r
+ * The below statements read the timestamp from the timer port module.\r
+ * If necessary, whole seconds are extracted using division while the rest\r
+ * comes from the modulo operation.\r
+ **************************************************************************/\r
+ \r
+ prvTracePortGetTimeStamp(×tamp); \r
+ \r
+ /***************************************************************************\r
+ * Since dts is unsigned the result will be correct even if timestamp has\r
+ * wrapped around.\r
+ ***************************************************************************/\r
+ dts = timestamp - old_timestamp;\r
+ old_timestamp = timestamp;\r
+\r
+ if (RecorderDataPtr->frequency > 0)\r
+ {\r
+ /* Check if dts > 1 second */\r
+ if (dts > RecorderDataPtr->frequency)\r
+ {\r
+ /* More than 1 second has passed */\r
+ RecorderDataPtr->absTimeLastEventSecond += dts / RecorderDataPtr->frequency;\r
+ /* The part that is not an entire second is added to absTimeLastEvent */\r
+ RecorderDataPtr->absTimeLastEvent += dts % RecorderDataPtr->frequency;\r
+ }\r
+ else\r
+ {\r
+ RecorderDataPtr->absTimeLastEvent += dts;\r
+ }\r
+\r
+ /* Check if absTimeLastEvent >= 1 second */\r
+ if (RecorderDataPtr->absTimeLastEvent >= RecorderDataPtr->frequency)\r
+ {\r
+ /* RecorderDataPtr->absTimeLastEvent is more than or equal to 1 second, but always less than 2 seconds */\r
+ RecorderDataPtr->absTimeLastEventSecond++;\r
+ RecorderDataPtr->absTimeLastEvent -= RecorderDataPtr->frequency;\r
+ /* RecorderDataPtr->absTimeLastEvent is now less than 1 second */\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Special case if the recorder has not yet started (frequency may be uninitialized, i.e., zero) */\r
+ RecorderDataPtr->absTimeLastEvent = timestamp;\r
+ }\r
+\r
+ /* If the dts (time since last event) does not fit in event->dts (only 8 or 16 bits) */\r
+ if (dts > param_maxDTS)\r
+ {\r
+ /* Create an XTS event (eXtended TimeStamp) containing the higher dts bits*/\r
+ xts = (XTSEvent*) prvTraceNextFreeEventBufferSlot();\r
+\r
+ if (xts != NULL)\r
+ {\r
+ if (param_maxDTS == 0xFFFF)\r
+ {\r
+ xts->type = XTS16;\r
+ xts->xts_16 = (uint16_t)((dts / 0x10000) & 0xFFFF);\r
+ xts->xts_8 = 0;\r
+ }\r
+ else if (param_maxDTS == 0xFF)\r
+ {\r
+ xts->type = XTS8;\r
+ xts->xts_16 = (uint16_t)((dts / 0x100) & 0xFFFF);\r
+ xts->xts_8 = (uint8_t)((dts / 0x1000000) & 0xFF);\r
+ }\r
+ else\r
+ {\r
+ prvTraceError("Bad param_maxDTS in prvTraceGetDTS");\r
+ }\r
+ prvTraceUpdateCounters();\r
+ }\r
+ }\r
+\r
+ return (uint16_t)dts & param_maxDTS;\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvTraceLookupSymbolTableEntry\r
+ *\r
+ * Find an entry in the symbol table, return 0 if not present.\r
+ *\r
+ * The strings are stored in a byte pool, with four bytes of "meta-data" for\r
+ * every string.\r
+ * byte 0-1: index of next entry with same checksum (for fast lookup).\r
+ * byte 2-3: reference to a symbol table entry, a label for vTracePrintF\r
+ * format strings only (the handle of the destination channel).\r
+ * byte 4..(4 + length): the string (object name or user event label), with\r
+ * zero-termination\r
+ ******************************************************************************/\r
+traceString prvTraceLookupSymbolTableEntry(const char* name,\r
+ uint8_t crc6,\r
+ uint8_t len,\r
+ traceString chn)\r
+{\r
+ uint16_t i = RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ];\r
+\r
+ TRACE_ASSERT(name != NULL, "prvTraceLookupSymbolTableEntry: name == NULL", (traceString)0);\r
+ TRACE_ASSERT(len != 0, "prvTraceLookupSymbolTableEntry: len == 0", (traceString)0);\r
+\r
+ while (i != 0)\r
+ {\r
+ if (RecorderDataPtr->SymbolTable.symbytes[i + 2] == (chn & 0x00FF))\r
+ {\r
+ if (RecorderDataPtr->SymbolTable.symbytes[i + 3] == (chn / 0x100))\r
+ {\r
+ if (RecorderDataPtr->SymbolTable.symbytes[i + 4 + len] == '\0')\r
+ {\r
+ if (strncmp((char*)(& RecorderDataPtr->SymbolTable.symbytes[i + 4]), name, len) == 0)\r
+ {\r
+ break; /* found */\r
+ }\r
+ }\r
+ }\r
+ }\r
+ i = (uint16_t)(RecorderDataPtr->SymbolTable.symbytes[i] + (RecorderDataPtr->SymbolTable.symbytes[i + 1] * 0x100));\r
+ }\r
+ return i;\r
+}\r
+\r
+/*******************************************************************************\r
+ * prvTraceCreateSymbolTableEntry\r
+ *\r
+ * Creates an entry in the symbol table, independent if it exists already.\r
+ *\r
+ * The strings are stored in a byte pool, with four bytes of "meta-data" for\r
+ * every string.\r
+ * byte 0-1: index of next entry with same checksum (for fast lookup).\r
+ * byte 2-3: reference to a symbol table entry, a label for vTracePrintF\r
+ * format strings only (the handle of the destination channel).\r
+ * byte 4..(4 + length): the string (object name or user event label), with\r
+ * zero-termination\r
+ ******************************************************************************/\r
+uint16_t prvTraceCreateSymbolTableEntry(const char* name,\r
+ uint8_t crc6,\r
+ uint8_t len,\r
+ traceString channel)\r
+{\r
+ uint16_t ret = 0;\r
+\r
+ TRACE_ASSERT(name != NULL, "prvTraceCreateSymbolTableEntry: name == NULL", 0);\r
+ TRACE_ASSERT(len != 0, "prvTraceCreateSymbolTableEntry: len == 0", 0);\r
+\r
+ if (RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + len + 4 >= TRC_CFG_SYMBOL_TABLE_SIZE)\r
+ {\r
+ prvTraceError("Symbol table full. Increase TRC_CFG_SYMBOL_TABLE_SIZE in trcConfig.h");\r
+ ret = 0;\r
+ }\r
+ else\r
+ {\r
+\r
+ RecorderDataPtr->SymbolTable.symbytes\r
+ [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex] =\r
+ (uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] & 0x00FF);\r
+\r
+ RecorderDataPtr->SymbolTable.symbytes\r
+ [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 1] =\r
+ (uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] / 0x100);\r
+\r
+ RecorderDataPtr->SymbolTable.symbytes\r
+ [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 2] =\r
+ (uint8_t)(channel & 0x00FF);\r
+\r
+ RecorderDataPtr->SymbolTable.symbytes\r
+ [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 3] =\r
+ (uint8_t)(channel / 0x100);\r
+\r
+ /* set name (bytes 4...4+len-1) */\r
+ prvStrncpy((char*)&(RecorderDataPtr->SymbolTable.symbytes\r
+ [ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4]), name, len);\r
+\r
+ /* Set zero termination (at offset 4+len) */\r
+ RecorderDataPtr->SymbolTable.symbytes\r
+ [RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4 + len] = '\0';\r
+\r
+ /* store index of entry (for return value, and as head of LL[crc6]) */\r
+ RecorderDataPtr->SymbolTable.latestEntryOfChecksum\r
+ [ crc6 ] = (uint16_t)RecorderDataPtr->SymbolTable.nextFreeSymbolIndex;\r
+\r
+ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex += (uint32_t) (len + 5);\r
+\r
+ ret = (uint16_t)(RecorderDataPtr->SymbolTable.nextFreeSymbolIndex - (uint8_t)(len + 5));\r
+ }\r
+\r
+ return ret;\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+ * prvTraceGetChecksum\r
+ *\r
+ * Calculates a simple 6-bit checksum from a string, used to index the string\r
+ * for fast symbol table lookup.\r
+ ******************************************************************************/\r
+void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength)\r
+{\r
+ unsigned char c;\r
+ int length = 1; /* Should be 1 to account for '\0' */\r
+ int crc = 0;\r
+\r
+ TRACE_ASSERT(pname != NULL, "prvTraceGetChecksum: pname == NULL", TRC_UNUSED);\r
+ TRACE_ASSERT(pcrc != NULL, "prvTraceGetChecksum: pcrc == NULL", TRC_UNUSED);\r
+ TRACE_ASSERT(plength != NULL, "prvTraceGetChecksum: plength == NULL", TRC_UNUSED);\r
+\r
+ if (pname != (const char *) 0)\r
+ {\r
+ for (; (c = (unsigned char) *pname++) != '\0';)\r
+ {\r
+ crc += c;\r
+ length++;\r
+ }\r
+ }\r
+ *pcrc = (uint8_t)(crc & 0x3F);\r
+ *plength = (uint8_t)length;\r
+}\r
+\r
+#if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
+\r
+static void prvTraceStoreXID(traceHandle handle); \r
+\r
+/******************************************************************************\r
+ * prvTraceStoreXID\r
+ *\r
+ * Stores an XID (eXtended IDentifier) event.\r
+ * This is used if an object/task handle is larger than 255.\r
+ * The parameter "handle" is the full (16 bit) handle, assumed to be 256 or \r
+ * larger. Handles below 256 should not use this function.\r
+ *\r
+ * NOTE: this function MUST be called from within a critical section.\r
+ *****************************************************************************/\r
+static void prvTraceStoreXID(traceHandle handle)\r
+{\r
+ XPSEvent* xid;\r
+\r
+ TRACE_ASSERT(handle >= 256, "prvTraceStoreXID: Handle < 256", TRC_UNUSED);\r
+\r
+ xid = (XPSEvent*)prvTraceNextFreeEventBufferSlot();\r
+\r
+ if (xid != NULL)\r
+ {\r
+ xid->type = XID;\r
+\r
+ /* This function is (only) used when traceHandle is 16 bit... */\r
+ xid->xps_16 = handle; \r
+\r
+ prvTraceUpdateCounters();\r
+ }\r
+}\r
+\r
+static uint8_t prvTraceGet8BitHandle(traceHandle handle)\r
+{\r
+ if (handle > 255)\r
+ { \r
+ prvTraceStoreXID(handle);\r
+ /* The full handle (16 bit) is stored in the XID event. \r
+ This code (255) is used instead of zero (which is an error code).*/\r
+ return 255; \r
+ }\r
+ return (uint8_t)(handle & 0xFF);\r
+}\r
+#endif /*(TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)*/\r
+\r
+\r
+/* If using DWT timestamping (default on ARM Cortex-M3, M4 and M7), make sure the DWT unit is initialized. */\r
+#ifndef TRC_CFG_ARM_CM_USE_SYSTICK\r
+#if ((TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M) && (defined (__CORTEX_M) && (__CORTEX_M >= 0x03)))\r
+void prvTraceInitCortexM()\r
+{\r
+ /* Ensure that the DWT registers are unlocked and can be modified. */\r
+ TRC_REG_ITM_LOCKACCESS = TRC_ITM_LOCKACCESS_UNLOCK;\r
+\r
+ /* Make sure DWT is enabled, if supported */\r
+ TRC_REG_DEMCR |= TRC_DEMCR_TRCENA;\r
+\r
+ do{\r
+ /* Verify that DWT is supported */\r
+ if (TRC_REG_DEMCR == 0)\r
+ {\r
+ /* This function is called on Cortex-M3, M4 and M7 devices to initialize\r
+ the DWT unit, assumed present. The DWT cycle counter is used for timestamping. \r
+ \r
+ If the below error is produced, the DWT unit does not seem to be available.\r
+ \r
+ In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build\r
+ to use SysTick timestamping instead, or define your own timestamping by \r
+ setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
+ and make the necessary definitions, as explained in trcHardwarePort.h.*/\r
+ \r
+ prvTraceError("DWT unit not available, see code comment.");\r
+ break;\r
+ }\r
+\r
+ /* Verify that DWT_CYCCNT is supported */\r
+ if (TRC_REG_DWT_CTRL & TRC_DWT_CTRL_NOCYCCNT)\r
+ {\r
+ /* This function is called on Cortex-M3, M4 and M7 devices to initialize\r
+ the DWT unit, assumed present. The DWT cycle counter is used for timestamping. \r
+ \r
+ If the below error is produced, the cycle counter does not seem to be available.\r
+ \r
+ In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build\r
+ to use SysTick timestamping instead, or define your own timestamping by \r
+ setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
+ and make the necessary definitions, as explained in trcHardwarePort.h.*/\r
+\r
+ prvTraceError("DWT_CYCCNT not available, see code comment.");\r
+ break;\r
+ }\r
+\r
+ /* Reset the cycle counter */\r
+ TRC_REG_DWT_CYCCNT = 0;\r
+\r
+ /* Enable the cycle counter */\r
+ TRC_REG_DWT_CTRL |= TRC_DWT_CTRL_CYCCNTENA;\r
+\r
+ }while(0); /* breaks above jump here */\r
+}\r
+#endif\r
+#endif\r
+\r
+/******************************************************************************\r
+ * prvTracePortGetTimeStamp\r
+ *\r
+ * Returns the current time based on the HWTC macros which provide a hardware\r
+ * isolation layer towards the hardware timer/counter.\r
+ *\r
+ * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue\r
+ * or the trace recorder library. Typically you should not need to change\r
+ * the code of prvTracePortGetTimeStamp if using the HWTC macros.\r
+ *\r
+ ******************************************************************************/\r
+void prvTracePortGetTimeStamp(uint32_t *pTimestamp)\r
+{\r
+ static uint32_t last_hwtc_count = 0;\r
+ uint32_t hwtc_count = 0;\r
+\r
+#if TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR\r
+ /* systick based timer */\r
+ static uint32_t last_traceTickCount = 0;\r
+ uint32_t traceTickCount = 0;\r
+#else /*TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR*/\r
+ /* Free running timer */\r
+ static uint32_t last_hwtc_rest = 0;\r
+ uint32_t diff = 0;\r
+ uint32_t diff_scaled = 0;\r
+#endif /*TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR*/\r
+\r
+ if (trace_disable_timestamp == 1)\r
+ {\r
+ if (pTimestamp)\r
+ *pTimestamp = last_timestamp;\r
+ return;\r
+ }\r
+\r
+ /* Retrieve TRC_HWTC_COUNT only once since the same value should be used all throughout this function. */\r
+#if (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR)\r
+ /* Get the increasing tick count */\r
+ hwtc_count = TRC_HWTC_COUNT;\r
+#elif (TRC_HWTC_TYPE == TRC_OS_TIMER_DECR || TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR)\r
+ /* Convert decreasing tick count into increasing tick count */\r
+ hwtc_count = TRC_HWTC_PERIOD - TRC_HWTC_COUNT;\r
+#else\r
+ #error "TRC_HWTC_TYPE has unexpected value"\r
+#endif\r
+\r
+#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)\r
+ /* The Win32 port uses ulGetRunTimeCounterValue for timestamping, which in turn\r
+ uses QueryPerformanceCounter. That function is not always reliable when used over\r
+ multiple threads. We must therefore handle rare cases where the timestamp is less\r
+ than the previous. In practice, this should "never" roll over since the\r
+ performance counter is 64 bit wide. */\r
+\r
+ if (last_hwtc_count > hwtc_count)\r
+ {\r
+ hwtc_count = last_hwtc_count;\r
+ }\r
+#endif\r
+\r
+#if (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)\r
+ /* Timestamping is based on a timer that wraps at TRC_HWTC_PERIOD */\r
+ if (last_traceTickCount - uiTraceTickCount - 1 < 0x80000000)\r
+ {\r
+ /* This means last_traceTickCount is higher than uiTraceTickCount,\r
+ so we have previously compensated for a missed tick.\r
+ Therefore we use the last stored value because that is more accurate. */\r
+ traceTickCount = last_traceTickCount;\r
+ }\r
+ else\r
+ {\r
+ /* Business as usual */\r
+ traceTickCount = uiTraceTickCount;\r
+ }\r
+\r
+ /* Check for overflow. May occur if the update of uiTraceTickCount has been\r
+ delayed due to disabled interrupts. */\r
+ if (traceTickCount == last_traceTickCount && hwtc_count < last_hwtc_count)\r
+ {\r
+ /* A trace tick has occurred but not been executed by the kernel, so we compensate manually. */\r
+ traceTickCount++;\r
+ }\r
+\r
+ /* Check if the return address is OK, then we perform the calculation. */\r
+ if (pTimestamp)\r
+ {\r
+ /* Get timestamp from trace ticks. Scale down the period to avoid unwanted overflows. */\r
+ last_timestamp = traceTickCount * (TRC_HWTC_PERIOD / TRC_HWTC_DIVISOR);\r
+ /* Increase timestamp by (hwtc_count + "lost hardware ticks from scaling down period") / TRC_HWTC_DIVISOR. */\r
+ last_timestamp += (hwtc_count + traceTickCount * (TRC_HWTC_PERIOD % TRC_HWTC_DIVISOR)) / TRC_HWTC_DIVISOR;\r
+ }\r
+ /* Store the previous value */\r
+ last_traceTickCount = traceTickCount;\r
+ \r
+#else /*(TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)*/\r
+ \r
+ /* Timestamping is based on a free running timer */\r
+ /* This part handles free running clocks that can be scaled down to avoid too large DTS values.\r
+ Without this, the scaled timestamp will incorrectly wrap at (2^32 / TRC_HWTC_DIVISOR) ticks.\r
+ The scaled timestamp returned from this function is supposed to go from 0 -> 2^32, which in real time would represent (0 -> 2^32 * TRC_HWTC_DIVISOR) ticks. */\r
+ \r
+ /* First we see how long time has passed since the last timestamp call, and we also add the ticks that was lost when we scaled down the last time. */\r
+ diff = (hwtc_count - last_hwtc_count) + last_hwtc_rest;\r
+ \r
+ /* Scale down the diff */\r
+ diff_scaled = diff / TRC_HWTC_DIVISOR;\r
+ \r
+ /* Find out how many ticks were lost when scaling down, so we can add them the next time */\r
+ last_hwtc_rest = diff % TRC_HWTC_DIVISOR;\r
+\r
+ /* We increase the scaled timestamp by the scaled amount */\r
+ last_timestamp += diff_scaled;\r
+#endif /*(TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)*/\r
+\r
+ /* Is anyone interested in the results? */\r
+ if (pTimestamp)\r
+ *pTimestamp = last_timestamp;\r
+\r
+ /* Store the previous value */\r
+ last_hwtc_count = hwtc_count;\r
+}\r
+\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/\r
--- /dev/null
+/*******************************************************************************\r
+ * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcStreamingRecorder.c\r
+ *\r
+ * The generic core of the trace recorder's streaming mode.\r
+ *\r
+ * Terms of Use\r
+ * This file is part of the trace recorder library (RECORDER), which is the \r
+ * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
+ * license as follows.\r
+ * The RECORDER may be used free of charge for the purpose of recording data\r
+ * intended for analysis in PERCEPIO products. It may not be used or modified\r
+ * for other purposes without explicit permission from PERCEPIO.\r
+ * You may distribute the RECORDER in its original source code form, assuming\r
+ * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
+ * allowed to distribute the RECORDER with minor modifications intended for\r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * specific processor, processor family or with a specific communication\r
+ * interface. Any such modifications should be documented directly below\r
+ * this comment block. \r
+ *\r
+ * Disclaimer\r
+ * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * performance or results you may obtain by using the RECORDER or documentation.\r
+ * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
+ * third party rights, merchantability, or fitness for any particular purpose.\r
+ * In no event will PERCEPIO, its technology partners, or distributors be liable\r
+ * to you for any consequential, incidental or special damages, including any\r
+ * lost profits or lost savings, even if a representative of PERCEPIO has been\r
+ * advised of the possibility of such damages, or for any claim by any third\r
+ * party. Some jurisdictions do not allow the exclusion or limitation of\r
+ * incidental, consequential or special damages, or the exclusion of implied\r
+ * warranties or limitations on how long an implied warranty may last, so the\r
+ * above limitations may not apply to you.\r
+ *\r
+ * Tabs are used for indent in this file (1 tab = 4 spaces)\r
+ *\r
+ * Copyright Percepio AB, 2017.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#include "trcRecorder.h"\r
+\r
+#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
+\r
+#if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
+\r
+typedef struct{\r
+ uint16_t EventID;\r
+ uint16_t EventCount;\r
+ uint32_t TS;\r
+} BaseEvent;\r
+\r
+typedef struct{\r
+ BaseEvent base;\r
+ uint32_t param1;\r
+} EventWithParam_1;\r
+\r
+typedef struct{\r
+ BaseEvent base;\r
+ uint32_t param1;\r
+ uint32_t param2;\r
+} EventWithParam_2;\r
+\r
+typedef struct{\r
+ BaseEvent base;\r
+ uint32_t param1;\r
+ uint32_t param2;\r
+ uint32_t param3;\r
+} EventWithParam_3;\r
+\r
+/* Used in event functions with variable number of parameters. */\r
+typedef struct\r
+{\r
+ BaseEvent base;\r
+ uint32_t data[15]; /* maximum payload size */\r
+} largestEventType;\r
+\r
+typedef struct{\r
+ uint32_t psf;\r
+ uint16_t version;\r
+ uint16_t platform;\r
+ uint32_t options;\r
+ uint16_t symbolSize;\r
+ uint16_t symbolCount;\r
+ uint16_t objectDataSize;\r
+ uint16_t objectDataCount;\r
+} PSFHeaderInfo;\r
+\r
+\r
+/* The size of each slot in the Symbol Table */\r
+#define SYMBOL_TABLE_SLOT_SIZE (sizeof(uint32_t) + (((TRC_CFG_SYMBOL_MAX_LENGTH)+(sizeof(uint32_t)-1))/sizeof(uint32_t))*sizeof(uint32_t))\r
+\r
+#define OBJECT_DATA_SLOT_SIZE (sizeof(uint32_t) + sizeof(uint32_t))\r
+\r
+/* The total size of the Symbol Table */\r
+#define SYMBOL_TABLE_BUFFER_SIZE ((TRC_CFG_SYMBOL_TABLE_SLOTS) * SYMBOL_TABLE_SLOT_SIZE)\r
+\r
+/* The total size of the Object Data Table */\r
+#define OBJECT_DATA_TABLE_BUFFER_SIZE ((TRC_CFG_OBJECT_DATA_SLOTS) * OBJECT_DATA_SLOT_SIZE)\r
+\r
+/* The Symbol Table type - just a byte array */\r
+typedef struct{\r
+ union\r
+ {\r
+ uint32_t pSymbolTableBufferUINT32[SYMBOL_TABLE_BUFFER_SIZE / sizeof(uint32_t)];\r
+ uint8_t pSymbolTableBufferUINT8[SYMBOL_TABLE_BUFFER_SIZE];\r
+ } SymbolTableBuffer;\r
+} SymbolTable;\r
+\r
+/* The Object Data Table type - just a byte array */\r
+typedef struct{\r
+ union\r
+ {\r
+ uint32_t pObjectDataTableBufferUINT32[OBJECT_DATA_TABLE_BUFFER_SIZE / sizeof(uint32_t)];\r
+ uint8_t pObjectDataTableBufferUINT8[OBJECT_DATA_TABLE_BUFFER_SIZE];\r
+ } ObjectDataTableBuffer;\r
+} ObjectDataTable;\r
+\r
+typedef struct{\r
+ uint8_t Status;\r
+ uint16_t BytesRemaining;\r
+ char* WritePointer;\r
+} PageType;\r
+\r
+/* Code used for "task address" when no task has started. (NULL = idle task) */\r
+#define HANDLE_NO_TASK 2\r
+\r
+#define PAGE_STATUS_FREE 0\r
+#define PAGE_STATUS_WRITE 1\r
+#define PAGE_STATUS_READ 2\r
+\r
+#define PSF_ASSERT(_assert, _err) if (! (_assert)){ prvTraceError(_err); return; }\r
+\r
+#define PSF_ERROR_NONE 0\r
+#define PSF_ERROR_EVENT_CODE_TOO_LARGE 1\r
+#define PSF_ERROR_ISR_NESTING_OVERFLOW 2\r
+#define PSF_ERROR_DWT_NOT_SUPPORTED 3\r
+#define PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED 4\r
+#define PSF_ERROR_AUTO_ISR_END 5\r
+\r
+/* Part of the PSF format - encodes the number of 32-bit params in an event */\r
+#define PARAM_COUNT(n) ((n & 0xF) << 12)\r
+\r
+/* The Symbol Table instance - keeps names of tasks and other named objects. */\r
+static SymbolTable symbolTable = { { { 0 } } };\r
+\r
+/* This points to the first unused entry in the symbol table. */\r
+static uint32_t firstFreeSymbolTableIndex = 0;\r
+\r
+/* The Object Data Table instance - keeps initial priorities of tasks. */\r
+static ObjectDataTable objectDataTable = { { { 0 } } };\r
+\r
+/* This points to the first unused entry in the object data table. */\r
+static uint32_t firstFreeObjectDataTableIndex = 0;\r
+\r
+/* Keeps track of ISR nesting */\r
+static uint32_t ISR_stack[TRC_CFG_MAX_ISR_NESTING];\r
+\r
+/* Keeps track of ISR nesting */\r
+static int8_t ISR_stack_index = -1;\r
+\r
+/* Any error that occurred in the recorder (also creates User Event) */\r
+static int errorCode = 0;\r
+\r
+/* Counts the number of trace sessions (not yet used) */\r
+static uint32_t SessionCounter = 0u;\r
+\r
+/* Master switch for recording (0 => Disabled, 1 => Enabled) */\r
+uint32_t RecorderEnabled = 0u;\r
+\r
+/* Used to determine endian of data (big/little) */\r
+static uint32_t PSFEndianessIdentifier = 0x50534600;\r
+\r
+/* Used to interpret the data format */\r
+static uint16_t FormatVersion = 0x0004;\r
+\r
+/* The number of events stored. Used as event sequence number. */\r
+static uint32_t eventCounter = 0;\r
+\r
+/* The user event channel for recorder warnings, defined in trcKernelPort.c */\r
+extern char* trcWarningChannel;\r
+\r
+/* Remembers if an earlier ISR in a sequence of adjacent ISRs has triggered a task switch.\r
+In that case, vTraceStoreISREnd does not store a return to the previously executing task. */\r
+int32_t isPendingContextSwitch = 0;\r
+\r
+uint32_t uiTraceTickCount = 0;\r
+uint32_t timestampFrequency = 0;\r
+uint32_t DroppedEventCounter = 0; // Total number of dropped events (failed allocations)\r
+uint32_t TotalBytesRemaining_LowWaterMark = TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE;\r
+uint32_t TotalBytesRemaining = TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE;\r
+\r
+PageType PageInfo[TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT];\r
+\r
+char* EventBuffer = NULL;\r
+\r
+/*******************************************************************************\r
+ * NoRoomForSymbol\r
+ *\r
+ * Incremented on prvTraceSaveSymbol if no room for saving the symbol name. This\r
+ * is used for storing the names of:\r
+ * - Tasks\r
+ * - Named ISRs (xTraceSetISRProperties)\r
+ * - Named kernel objects (vTraceStoreKernelObjectName)\r
+ * - User event channels (xTraceRegisterString)\r
+ *\r
+ * This variable should be zero. If not, it shows the number of missing slots so\r
+ * far. In that case, increment SYMBOL_TABLE_SLOTS with (at least) this value.\r
+ ******************************************************************************/\r
+volatile uint32_t NoRoomForSymbol = 0;\r
+\r
+/*******************************************************************************\r
+ * NoRoomForObjectData\r
+ *\r
+ * Incremented on prvTraceSaveObjectData if no room for saving the object data,\r
+ * i.e., the base priorities of tasks. There must be one slot for each task.\r
+ * If not, this variable will show the difference.\r
+ *\r
+ * This variable should be zero. If not, it shows the number of missing slots so\r
+ * far. In that case, increment OBJECT_DATA_SLOTS with (at least) this value.\r
+ ******************************************************************************/\r
+volatile uint32_t NoRoomForObjectData = 0;\r
+\r
+/*******************************************************************************\r
+ * LongestSymbolName\r
+ *\r
+ * Updated in prvTraceSaveSymbol. Should not exceed SYMBOL_MAX_LENGTH, otherwise\r
+ * symbol names will be truncated. In that case, set SYMBOL_MAX_LENGTH to (at\r
+ * least) this value.\r
+ ******************************************************************************/\r
+volatile uint32_t LongestSymbolName = 0;\r
+\r
+/*******************************************************************************\r
+ * MaxBytesTruncated\r
+ *\r
+ * Set in prvTraceStoreStringEvent if the total data payload exceeds 60 bytes,\r
+ * including data arguments and the string. For user events, that is 52 bytes\r
+ * for string and data arguments. In that is exceeded, the event is truncated\r
+ * (usually only the string, unless more than 15 parameters) and this variable\r
+ * holds the maximum number of truncated bytes, from any event.\r
+ ******************************************************************************/\r
+volatile uint32_t MaxBytesTruncated = 0;\r
+\r
+/* Internal common function for storing string events */\r
+static void prvTraceStoreStringEventHelper( int nArgs,\r
+ uint16_t eventID,\r
+ traceString userEvtChannel,\r
+ const char* str,\r
+ va_list* vl);\r
+static void prvTraceStoreSimpleStringEventHelper( traceString userEvtChannel,\r
+ const char* str);\r
+\r
+/* Stores the header information on Start */\r
+static void prvTraceStoreHeader(void);\r
+\r
+/* Stores the symbol table on Start */\r
+static void prvTraceStoreSymbolTable(void);\r
+\r
+/* Stores the object table on Start */\r
+static void prvTraceStoreObjectDataTable(void);\r
+\r
+/* Store the Timestamp Config on Start */\r
+static void prvTraceStoreTSConfig(void);\r
+\r
+/* Store the current warnings */\r
+static void prvTraceStoreWarnings(void);\r
+\r
+/* Internal function for starting/stopping the recorder. */\r
+static void prvSetRecorderEnabled(uint32_t isEnabled);\r
+\r
+/* Mark the page read as complete. */\r
+static void prvPageReadComplete(int pageIndex);\r
+\r
+/* Retrieve a buffer page to write to. */\r
+static int prvAllocateBufferPage(int prevPage);\r
+\r
+/* Get the current buffer page index and remaining number of bytes. */\r
+static int prvGetBufferPage(int32_t* bytesUsed);\r
+\r
+/* Performs timestamping using definitions in trcHardwarePort.h */\r
+static uint32_t prvGetTimestamp32(void);\r
+\r
+/* Signal an error. */\r
+void prvTraceError(int errCode);\r
+\r
+/******************************************************************************\r
+ * vTraceInstanceFinishedNow\r
+ *\r
+ * Creates an event that ends the current task instance at this very instant.\r
+ * This makes the viewer to splits the current fragment at this point and begin\r
+ * a new actor instance, even if no task-switch has occurred.\r
+ *****************************************************************************/\r
+void vTraceInstanceFinishedNow(void)\r
+{\r
+ prvTraceStoreEvent0(PSF_EVENT_IFE_DIRECT);\r
+}\r
+\r
+/******************************************************************************\r
+ * vTraceInstanceFinishedNext\r
+ *\r
+ * Marks the current "task instance" as finished on the next kernel call.\r
+ *\r
+ * If that kernel call is blocking, the instance ends after the blocking event\r
+ * and the corresponding return event is then the start of the next instance.\r
+ * If the kernel call is not blocking, the viewer instead splits the current\r
+ * fragment right before the kernel call, which makes this call the first event\r
+ * of the next instance.\r
+ *****************************************************************************/\r
+void vTraceInstanceFinishedNext(void)\r
+{\r
+ prvTraceStoreEvent0(PSF_EVENT_IFE_NEXT);\r
+}\r
+\r
+/*******************************************************************************\r
+ * xTraceRegisterString\r
+ *\r
+ * Stores a name for a user event channel, returns the handle.\r
+ ******************************************************************************/\r
+traceString xTraceRegisterString(const char* name)\r
+{\r
+ prvTraceSaveSymbol((const void*)name, name);\r
+\r
+ /* Always save in symbol table, if the recording has not yet started */\r
+ prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, (const char*)name, (uint32_t)name);\r
+\r
+ return (traceString)name;\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreKernelObjectName\r
+ *\r
+ * Parameter object: pointer to the Event Group that shall be named\r
+ * Parameter name: the name to set (const string literal)\r
+ *\r
+ * Sets a name for a kernel object for display in Tracealyzer.\r
+ ******************************************************************************/\r
+void vTraceStoreKernelObjectName(void* object, const char* name)\r
+{\r
+ /* Always save in symbol table, if the recording has not yet started */\r
+ prvTraceSaveSymbol(object, name);\r
+\r
+ prvTraceStoreStringEvent(1, PSF_EVENT_OBJ_NAME, name, (uint32_t)object);\r
+}\r
+\r
+\r
+/******************************************************************************\r
+* vTraceSetFrequency\r
+*\r
+* Registers the clock rate of the time source for the event timestamping.\r
+* This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)\r
+* should be incorrect for your setup, you can override it using this function.\r
+*\r
+* Must be called prior to vTraceEnable, and the time source is assumed to\r
+* have a fixed clock frequency after the startup.\r
+*****************************************************************************/\r
+void vTraceSetFrequency(uint32_t frequency)\r
+{\r
+ timestampFrequency = frequency;\r
+}\r
+\r
+/******************************************************************************\r
+ * vTracePrint\r
+ *\r
+ * Generates "User Events", with unformatted text.\r
+ *\r
+ * User Events can be used for very efficient application logging, and are shown\r
+ * as yellow labels in the main trace view.\r
+ *\r
+ * You may group User Events into User Event Channels. The yellow User Event \r
+ * labels shows the logged string, preceded by the channel name within \r
+ * brackets. For example:\r
+ *\r
+ * "[MyChannel] Hello World!"\r
+ *\r
+ * The User Event Channels are shown in the View Filter, which makes it easy to\r
+ * select what User Events you wish to display. User Event Channels are created\r
+ * using xTraceRegisterString().\r
+ *\r
+ * Example:\r
+ *\r
+ * traceString chn = xTraceRegisterString("MyChannel");\r
+ * ...\r
+ * vTracePrint(chn, "Hello World!");\r
+ *\r
+ ******************************************************************************/\r
+void vTracePrint(traceString chn, const char* str)\r
+{\r
+ prvTraceStoreSimpleStringEventHelper(chn, str);\r
+}\r
+\r
+/******************************************************************************\r
+ * vTracePrintF\r
+ *\r
+ * Generates "User Events", with formatted text and data, similar to a "printf".\r
+ * It is very fast since the actual formatting is done on the host side when the\r
+ * trace is displayed.\r
+ *\r
+ * User Events can be used for very efficient application logging, and are shown\r
+ * as yellow labels in the main trace view.\r
+ * An advantage of User Events is that data can be plotted in the "User Event\r
+ * Signal Plot" view, visualizing any data you log as User Events, discrete\r
+ * states or control system signals (e.g. system inputs or outputs).\r
+ *\r
+ * You may group User Events into User Event Channels. The yellow User Event \r
+ * labels show the logged string, preceded by the channel name within brackets.\r
+ * \r
+ * Example:\r
+ *\r
+ * "[MyChannel] Hello World!"\r
+ *\r
+ * The User Event Channels are shown in the View Filter, which makes it easy to\r
+ * select what User Events you wish to display. User Event Channels are created\r
+ * using xTraceRegisterString().\r
+ *\r
+ * Example:\r
+ *\r
+ * traceString adc_uechannel = xTraceRegisterString("ADC User Events");\r
+ * ...\r
+ * vTracePrintF(adc_uechannel,\r
+ * "ADC channel %d: %d volts",\r
+ * ch, adc_reading);\r
+ *\r
+ * All data arguments are assumed to be 32 bit wide. The following formats are\r
+ * supported:\r
+ * %d - signed integer. The following width and padding format is supported: "%05d" -> "-0042" and "%5d" -> " -42"\r
+ * %u - unsigned integer. The following width and padding format is supported: "%05u" -> "00042" and "%5u" -> " 42"\r
+ * %X - hexadecimal (uppercase). The following width and padding format is supported: "%04X" -> "002A" and "%4X" -> " 2A"\r
+ * %x - hexadecimal (lowercase). The following width and padding format is supported: "%04x" -> "002a" and "%4x" -> " 2a"\r
+ * %s - string (currently, this must be an earlier stored symbol name)\r
+ *\r
+ * Up to 15 data arguments are allowed, with a total size of maximum 60 byte\r
+ * including 8 byte for the base event fields and the format string. So with\r
+ * one data argument, the maximum string length is 48 chars. If this is exceeded\r
+ * the string is truncated (4 bytes at a time).\r
+ *\r
+ ******************************************************************************/\r
+void vTracePrintF(traceString chn, const char* fmt, ...)\r
+{\r
+ va_list vl;\r
+ int i = 0;\r
+\r
+ int nArgs = 0;\r
+\r
+ /* Count the number of arguments in the format string (e.g., %d) */\r
+ for (i = 0; (fmt[i] != 0) && (i < 52); i++)\r
+ {\r
+ if (fmt[i] == '%')\r
+ {\r
+ if (fmt[i + 1] != '%')\r
+ {\r
+ nArgs++; /* Found an argument */\r
+ }\r
+ \r
+ i++; /* Move past format specifier or non-argument '%' */\r
+ }\r
+ }\r
+\r
+ va_start(vl, fmt);\r
+ \r
+ if (chn != NULL)\r
+ {\r
+ prvTraceStoreStringEventHelper(nArgs, (uint16_t)(PSF_EVENT_USER_EVENT + nArgs + 1), chn, fmt, &vl);\r
+ }\r
+ else\r
+ {\r
+ prvTraceStoreStringEventHelper(nArgs, (uint16_t)(PSF_EVENT_USER_EVENT + nArgs), chn, fmt, &vl);\r
+ }\r
+\r
+ va_end(vl);\r
+}\r
+\r
+/*******************************************************************************\r
+ * xTraceSetISRProperties\r
+ *\r
+ * Stores a name and priority level for an Interrupt Service Routine, to allow\r
+ * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin. \r
+ *\r
+ * Example:\r
+ * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * ...\r
+ * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(Timer1Handle);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+traceHandle xTraceSetISRProperties(const char* name, uint8_t priority)\r
+{\r
+ /* Save object data in object data table */\r
+ prvTraceSaveObjectData((const void*)name, priority);\r
+ \r
+ /* Note: "name" is used both as a string argument, and the address as ID */\r
+ prvTraceStoreStringEvent(2, PSF_EVENT_DEFINE_ISR, name, name, priority);\r
+ \r
+ /* Always save in symbol table, if the recording has not yet started */\r
+ prvTraceSaveSymbol((const void*)name, name);\r
+ \r
+ return (traceHandle)name;\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreISRBegin\r
+ *\r
+ * Registers the beginning of an Interrupt Service Routine, using a traceHandle\r
+ * provided by xTraceSetISRProperties.\r
+ *\r
+ * Example:\r
+ * #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * ...\r
+ * traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(Timer1Handle);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+void vTraceStoreISRBegin(traceHandle handle)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ /* We are at the start of a possible ISR chain. \r
+ No context switches should have been triggered now. */\r
+ if (ISR_stack_index == -1)\r
+ isPendingContextSwitch = 0; \r
+ \r
+ if (ISR_stack_index < TRC_CFG_MAX_ISR_NESTING - 1)\r
+ {\r
+ ISR_stack_index++;\r
+ ISR_stack[ISR_stack_index] = (uint32_t)handle;\r
+ prvTraceStoreEvent1(PSF_EVENT_ISR_BEGIN, (uint32_t)handle);\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+ }\r
+ else\r
+ {\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+ prvTraceError(PSF_ERROR_ISR_NESTING_OVERFLOW);\r
+ }\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStoreISREnd\r
+ *\r
+ * Registers the end of an Interrupt Service Routine.\r
+ *\r
+ * The parameter pendingISR indicates if the interrupt has requested a\r
+ * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the \r
+ * interrupt is assumed to return to the previous context.\r
+ *\r
+ * Example:\r
+ * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
+ * traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder\r
+ * ...\r
+ * traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);\r
+ * ...\r
+ * void ISR_handler()\r
+ * {\r
+ * vTraceStoreISRBegin(traceHandleIsrTimer1);\r
+ * ...\r
+ * vTraceStoreISREnd(0);\r
+ * }\r
+ *\r
+ ******************************************************************************/\r
+void vTraceStoreISREnd(int isTaskSwitchRequired)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ /* Is there a pending task-switch? (perhaps from an earlier ISR) */\r
+ isPendingContextSwitch |= isTaskSwitchRequired;\r
+\r
+ if (ISR_stack_index > 0)\r
+ {\r
+ ISR_stack_index--;\r
+\r
+ /* Store return to interrupted ISR (if nested ISRs)*/\r
+ prvTraceStoreEvent1(PSF_EVENT_ISR_RESUME, (uint32_t)ISR_stack[ISR_stack_index]);\r
+ }\r
+ else\r
+ {\r
+ ISR_stack_index--;\r
+ \r
+ /* Store return to interrupted task, if no context switch will occur in between. */\r
+ if ((isPendingContextSwitch == 0) || (prvTraceIsSchedulerSuspended()))\r
+ {\r
+ prvTraceStoreEvent1(PSF_EVENT_TS_RESUME, (uint32_t)TRACE_GET_CURRENT_TASK());\r
+ }\r
+ }\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+ * xTraceGetLastError\r
+ *\r
+ * Returns the last error, if any.\r
+ *****************************************************************************/\r
+const char* xTraceGetLastError(void)\r
+{\r
+ if (NoRoomForSymbol > 0)\r
+ {\r
+ return "TRC_CFG_SYMBOL_TABLE_SLOTS too small.";\r
+ }\r
+\r
+ if (LongestSymbolName > (TRC_CFG_SYMBOL_MAX_LENGTH))\r
+ {\r
+ return "TRC_CFG_SYMBOL_MAX_LENGTH too small.";\r
+ }\r
+\r
+ if (NoRoomForObjectData > 0)\r
+ {\r
+ return "TRC_CFG_OBJECT_DATA_SLOTS too small.";\r
+ }\r
+\r
+ if (MaxBytesTruncated > 0)\r
+ {\r
+ return "String or User Event too long.";\r
+ }\r
+\r
+ switch (errorCode)\r
+ {\r
+ case PSF_ERROR_EVENT_CODE_TOO_LARGE:\r
+ return "An invalid event code was used.";\r
+ case PSF_ERROR_ISR_NESTING_OVERFLOW:\r
+ return "Too much ISR nesting.";\r
+ case PSF_ERROR_DWT_NOT_SUPPORTED:\r
+ return "DWT not supported by this chip.";\r
+ case PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED:\r
+ return "DWT_CYCCNT not supported by this chip.";\r
+ }\r
+ \r
+ return "";\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceClearError\r
+ *\r
+ * Clears any errors.\r
+ *****************************************************************************/\r
+void vTraceClearError(void)\r
+{\r
+ NoRoomForSymbol = 0;\r
+ LongestSymbolName = 0;\r
+ NoRoomForObjectData = 0;\r
+ MaxBytesTruncated = 0;\r
+ errorCode = PSF_ERROR_NONE;\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceStop\r
+ *\r
+ * Stops the tracing.\r
+ *****************************************************************************/\r
+void vTraceStop(void)\r
+{\r
+ prvSetRecorderEnabled(0);\r
+}\r
+\r
+/*******************************************************************************\r
+ * vTraceSetRecorderDataBuffer\r
+ *\r
+ * If custom allocation is used, this function must be called so the recorder\r
+ * library knows where to save the trace data.\r
+ ******************************************************************************/\r
+#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
+\r
+extern char* _TzTraceData;\r
+\r
+void vTraceSetRecorderDataBuffer(void* pRecorderData)\r
+{\r
+ _TzTraceData = pRecorderData;\r
+}\r
+#endif\r
+\r
+/******************************************************************************/\r
+/*** INTERNAL FUNCTIONS *******************************************************/\r
+/******************************************************************************/\r
+\r
+/* Internal function for starting/stopping the recorder. */\r
+static void prvSetRecorderEnabled(uint32_t isEnabled)\r
+{\r
+ void* currentTask;\r
+ \r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+ \r
+ currentTask = TRACE_GET_CURRENT_TASK();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ RecorderEnabled = isEnabled;\r
+\r
+ if (currentTask == NULL)\r
+ {\r
+ currentTask = (void*)HANDLE_NO_TASK;\r
+ }\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ prvTraceOnBegin();\r
+ \r
+ eventCounter = 0;\r
+ ISR_stack_index = -1;\r
+ prvTraceStoreHeader();\r
+ prvTraceStoreSymbolTable();\r
+ prvTraceStoreObjectDataTable();\r
+ prvTraceStoreEvent3( PSF_EVENT_TRACE_START,\r
+ (uint32_t)TRACE_GET_OS_TICKS(),\r
+ (uint32_t)currentTask,\r
+ SessionCounter++);\r
+ prvTraceStoreTSConfig();\r
+ prvTraceStoreWarnings();\r
+ }\r
+ else\r
+ {\r
+ prvTraceOnEnd();\r
+ }\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Stores the symbol table on Start */\r
+static void prvTraceStoreSymbolTable()\r
+{\r
+ uint32_t i = 0;\r
+ uint32_t j = 0;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+ \r
+ if (RecorderEnabled)\r
+ {\r
+ for (i = 0; i < (sizeof(SymbolTable) / sizeof(uint32_t)); i += (SYMBOL_TABLE_SLOT_SIZE / sizeof(uint32_t)))\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(uint32_t, data, SYMBOL_TABLE_SLOT_SIZE);\r
+ if (data != NULL)\r
+ {\r
+ for (j = 0; j < (SYMBOL_TABLE_SLOT_SIZE / sizeof(uint32_t)); j++)\r
+ {\r
+ data[j] = symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[i+j];\r
+ }\r
+ TRC_STREAM_PORT_COMMIT_EVENT(data, SYMBOL_TABLE_SLOT_SIZE);\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Stores the object table on Start */\r
+static void prvTraceStoreObjectDataTable()\r
+{\r
+ uint32_t i = 0;\r
+ uint32_t j = 0;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ for (i = 0; i < (sizeof(ObjectDataTable) / sizeof(uint32_t)); i += (OBJECT_DATA_SLOT_SIZE / sizeof(uint32_t)))\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(uint32_t, data, OBJECT_DATA_SLOT_SIZE);\r
+ if (data != NULL)\r
+ {\r
+ for (j = 0; j < (OBJECT_DATA_SLOT_SIZE / sizeof(uint32_t)); j++)\r
+ {\r
+ data[j] = objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[i+j];\r
+ }\r
+ TRC_STREAM_PORT_COMMIT_EVENT(data, OBJECT_DATA_SLOT_SIZE);\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Stores the header information on Start */\r
+static void prvTraceStoreHeader()\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(PSFHeaderInfo, header, sizeof(PSFHeaderInfo));\r
+ if (header != NULL)\r
+ {\r
+ header->psf = PSFEndianessIdentifier;\r
+ header->version = FormatVersion;\r
+ header->platform = TRACE_KERNEL_VERSION;\r
+ header->options = 0;\r
+ /* Lowest bit used for TRC_IRQ_PRIORITY_ORDER */\r
+ header->options = header->options | (TRC_IRQ_PRIORITY_ORDER << 0);\r
+ header->symbolSize = SYMBOL_TABLE_SLOT_SIZE;\r
+ header->symbolCount = (TRC_CFG_SYMBOL_TABLE_SLOTS);\r
+ header->objectDataSize = 8;\r
+ header->objectDataCount = TRC_CFG_OBJECT_DATA_SLOTS;\r
+ TRC_STREAM_PORT_COMMIT_EVENT(header, sizeof(PSFHeaderInfo));\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Store the current warnings */\r
+static void prvTraceStoreWarnings()\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ if (NoRoomForSymbol > 0)\r
+ {\r
+ vTracePrintF(trcWarningChannel, "TRC_CFG_SYMBOL_TABLE_SLOTS too small. Add %d slots.", NoRoomForSymbol);\r
+ }\r
+\r
+ if (LongestSymbolName > 0)\r
+ {\r
+ if (LongestSymbolName > (TRC_CFG_SYMBOL_MAX_LENGTH))\r
+ {\r
+ vTracePrintF(trcWarningChannel, "TRC_CFG_SYMBOL_MAX_LENGTH too small. Add %d chars.", LongestSymbolName - (TRC_CFG_SYMBOL_MAX_LENGTH));\r
+ }\r
+ }\r
+\r
+ if (NoRoomForObjectData > 0)\r
+ {\r
+ /* We don't know how many objects we actually need to make room for since NoRoomForObjectData can be increased multiple times for the same object! */\r
+ vTracePrintF(trcWarningChannel, "TRC_CFG_OBJECT_DATA_SLOTS too small. Add more slots.");\r
+ }\r
+\r
+ if (MaxBytesTruncated > 0)\r
+ {\r
+ /* Some string event generated a too long string that was truncated.\r
+ This may happen for the following functions:\r
+ - vTracePrintF\r
+ - vTraceStoreKernelObjectName\r
+ - vTraceStoreUserEventChannelName\r
+ - vTraceSetISRProperties\r
+\r
+ A PSF event may store maximum 60 bytes payload, including data arguments\r
+ and string characters. For User Events, also the User Event Channel ptr\r
+ must be squeezed in, if a channel is specified. */\r
+\r
+ vTracePrintF(trcWarningChannel, "String event too long, up to %d bytes truncated.", MaxBytesTruncated);\r
+ }\r
+\r
+ switch (errorCode)\r
+ {\r
+ case PSF_ERROR_EVENT_CODE_TOO_LARGE:\r
+ break;\r
+ case PSF_ERROR_ISR_NESTING_OVERFLOW: \r
+ break;\r
+ case PSF_ERROR_DWT_NOT_SUPPORTED:\r
+ vTracePrintF(trcWarningChannel, "DWT not supported, see prvTraceInitCortexM.");\r
+ break;\r
+ case PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED:\r
+ vTracePrintF(trcWarningChannel, "DWT_CYCCNT not supported, see prvTraceInitCortexM.");\r
+ break;\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Store an event with zero parameters (event ID only) */\r
+void prvTraceStoreEvent0(uint16_t eventID)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ eventCounter++;\r
+\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(BaseEvent, event, sizeof(BaseEvent));\r
+ if (event != NULL)\r
+ {\r
+ event->EventID = eventID | PARAM_COUNT(0);\r
+ event->EventCount = (uint16_t)eventCounter;\r
+ event->TS = prvGetTimestamp32();\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(BaseEvent));\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Store an event with one 32-bit parameter (pointer address or an int) */\r
+void prvTraceStoreEvent1(uint16_t eventID, uint32_t param1)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ eventCounter++;\r
+ \r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(EventWithParam_1, event, sizeof(EventWithParam_1));\r
+ if (event != NULL)\r
+ {\r
+ event->base.EventID = eventID | PARAM_COUNT(1);\r
+ event->base.EventCount = (uint16_t)eventCounter;\r
+ event->base.TS = prvGetTimestamp32();\r
+ event->param1 = (uint32_t)param1;\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(EventWithParam_1));\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Store an event with two 32-bit parameters */\r
+void prvTraceStoreEvent2(uint16_t eventID, uint32_t param1, uint32_t param2)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ eventCounter++;\r
+\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(EventWithParam_2, event, sizeof(EventWithParam_2));\r
+ if (event != NULL)\r
+ {\r
+ event->base.EventID = eventID | PARAM_COUNT(2);\r
+ event->base.EventCount = (uint16_t)eventCounter;\r
+ event->base.TS = prvGetTimestamp32();\r
+ event->param1 = (uint32_t)param1;\r
+ event->param2 = param2;\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(EventWithParam_2));\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Store an event with three 32-bit parameters */\r
+void prvTraceStoreEvent3( uint16_t eventID,\r
+ uint32_t param1,\r
+ uint32_t param2,\r
+ uint32_t param3)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ eventCounter++;\r
+\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_EVENT(EventWithParam_3, event, sizeof(EventWithParam_3));\r
+ if (event != NULL)\r
+ {\r
+ event->base.EventID = eventID | PARAM_COUNT(3);\r
+ event->base.EventCount = (uint16_t)eventCounter;\r
+ event->base.TS = prvGetTimestamp32();\r
+ event->param1 = (uint32_t)param1;\r
+ event->param2 = param2;\r
+ event->param3 = param3;\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, sizeof(EventWithParam_3));\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Stores an event with <nParam> 32-bit integer parameters */\r
+void prvTraceStoreEvent(int nParam, uint16_t eventID, ...)\r
+{\r
+ va_list vl;\r
+ int i;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ int eventSize = (int)sizeof(BaseEvent) + nParam * (int)sizeof(uint32_t);\r
+\r
+ eventCounter++;\r
+\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(largestEventType, event, eventSize);\r
+ if (event != NULL)\r
+ {\r
+ event->base.EventID = eventID | (uint16_t)PARAM_COUNT(nParam);\r
+ event->base.EventCount = (uint16_t)eventCounter;\r
+ event->base.TS = prvGetTimestamp32();\r
+\r
+ va_start(vl, eventID);\r
+ for (i = 0; i < nParam; i++)\r
+ {\r
+ uint32_t* tmp = (uint32_t*) &(event->data[i]);\r
+ *tmp = va_arg(vl, uint32_t);\r
+ }\r
+ va_end(vl);\r
+\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, (uint32_t)eventSize);\r
+ }\r
+ }\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Stories an event with a string and <nParam> 32-bit integer parameters */\r
+void prvTraceStoreStringEvent(int nArgs, uint16_t eventID, const char* str, ...)\r
+{\r
+ va_list vl;\r
+\r
+ va_start(vl, str);\r
+ prvTraceStoreStringEventHelper(nArgs, eventID, NULL, str, &vl);\r
+ va_end(vl);\r
+}\r
+\r
+/* Internal common function for storing string events */\r
+static void prvTraceStoreStringEventHelper( int nArgs,\r
+ uint16_t eventID,\r
+ traceString userEvtChannel,\r
+ const char* str, va_list* vl)\r
+{\r
+ int len;\r
+ int nWords;\r
+ int nStrWords;\r
+ int i;\r
+ int offset = 0;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ for (len = 0; (str[len] != 0) && (len < 52); len++); /* empty loop */\r
+ \r
+ /* The string length in multiples of 32 bit words (+1 for null character) */\r
+ nStrWords = (len+1+3)/4;\r
+\r
+ /* If a user event channel is specified, add in the list */\r
+ if (userEvtChannel)\r
+ nArgs++;\r
+\r
+ offset = nArgs * 4;\r
+\r
+ /* The total number of 32-bit words needed for the whole payload */\r
+ nWords = nStrWords + nArgs;\r
+\r
+ if (nWords > 15) /* if attempting to store more than 60 byte (= max) */\r
+ {\r
+ /* Truncate event if too large. The string characters are stored\r
+ last, so usually only the string is truncated, unless there a lot\r
+ of parameters... */\r
+\r
+ /* Diagnostics ... */\r
+ uint32_t bytesTruncated = (uint32_t)(nWords - 15) * 4;\r
+\r
+ if (bytesTruncated > MaxBytesTruncated)\r
+ {\r
+ MaxBytesTruncated = bytesTruncated;\r
+ }\r
+\r
+ nWords = 15;\r
+ len = 15 * 4 - offset;\r
+ }\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ int eventSize = (int)sizeof(BaseEvent) + nWords * (int)sizeof(uint32_t);\r
+\r
+ eventCounter++;\r
+\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(largestEventType, event, eventSize);\r
+ if (event != NULL)\r
+ {\r
+ uint32_t* data32;\r
+ uint8_t* data8;\r
+ event->base.EventID = (eventID) | (uint16_t)PARAM_COUNT(nWords);\r
+ event->base.EventCount = (uint16_t)eventCounter;\r
+ event->base.TS = prvGetTimestamp32();\r
+\r
+ /* 32-bit write-pointer for the data argument */\r
+ data32 = (uint32_t*) &(event->data[0]);\r
+\r
+ for (i = 0; i < nArgs; i++)\r
+ {\r
+ if ((userEvtChannel != NULL) && (i == 0))\r
+ {\r
+ /* First, add the User Event Channel if not NULL */\r
+ data32[i] = (uint32_t)userEvtChannel;\r
+ }\r
+ else\r
+ {\r
+ /* Add data arguments... */\r
+ data32[i] = va_arg(*vl, uint32_t);\r
+ }\r
+ }\r
+ data8 = (uint8_t*)&(event->data[0]);\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ data8[offset + i] = str[i];\r
+ }\r
+\r
+ if (len < (15 * 4 - offset))\r
+ data8[offset + len] = 0; /* Only truncate if we don't fill up the buffer completely */\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, (uint32_t)eventSize);\r
+ }\r
+ }\r
+ }\r
+ \r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Internal common function for storing string events without additional arguments */\r
+static void prvTraceStoreSimpleStringEventHelper( traceString userEvtChannel,\r
+ const char* str)\r
+{\r
+ int len;\r
+ int nWords;\r
+ int nStrWords;\r
+ int i;\r
+ int nArgs = 0;\r
+ int offset = 0;\r
+ uint16_t eventID = PSF_EVENT_USER_EVENT;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ PSF_ASSERT(eventID < 4096, PSF_ERROR_EVENT_CODE_TOO_LARGE);\r
+\r
+ for (len = 0; (str[len] != 0) && (len < 52); len++); /* empty loop */\r
+ \r
+ /* The string length in multiples of 32 bit words (+1 for null character) */\r
+ nStrWords = (len+1+3)/4;\r
+\r
+ /* If a user event channel is specified, add in the list */\r
+ if (userEvtChannel)\r
+ {\r
+ nArgs++;\r
+ eventID++;\r
+ }\r
+\r
+ offset = nArgs * 4;\r
+\r
+ /* The total number of 32-bit words needed for the whole payload */\r
+ nWords = nStrWords + nArgs;\r
+\r
+ if (nWords > 15) /* if attempting to store more than 60 byte (= max) */\r
+ {\r
+ /* Truncate event if too large. The string characters are stored\r
+ last, so usually only the string is truncated, unless there a lot\r
+ of parameters... */\r
+\r
+ /* Diagnostics ... */\r
+ uint32_t bytesTruncated = (uint32_t)(nWords - 15) * 4;\r
+\r
+ if (bytesTruncated > MaxBytesTruncated)\r
+ {\r
+ MaxBytesTruncated = bytesTruncated;\r
+ }\r
+\r
+ nWords = 15;\r
+ len = 15 * 4 - offset;\r
+ }\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ if (RecorderEnabled)\r
+ {\r
+ int eventSize = (int)sizeof(BaseEvent) + nWords * (int)sizeof(uint32_t);\r
+\r
+ eventCounter++;\r
+\r
+ {\r
+ TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(largestEventType, event, eventSize);\r
+ if (event != NULL)\r
+ {\r
+ uint32_t* data32;\r
+ uint8_t* data8;\r
+ event->base.EventID = (eventID) | (uint16_t)PARAM_COUNT(nWords);\r
+ event->base.EventCount = (uint16_t)eventCounter;\r
+ event->base.TS = prvGetTimestamp32();\r
+\r
+ /* 32-bit write-pointer for the data argument */\r
+ data32 = (uint32_t*) &(event->data[0]);\r
+\r
+ if (userEvtChannel != NULL)\r
+ {\r
+ /* First, add the User Event Channel if not NULL */\r
+ data32[0] = (uint32_t)userEvtChannel;\r
+ }\r
+\r
+ data8 = (uint8_t*) &(event->data[0]);\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ data8[offset + i] = str[i];\r
+ }\r
+\r
+ if (len < (15 * 4 - offset))\r
+ data8[offset + len] = 0; /* Only truncate if we don't fill up the buffer completely */\r
+ TRC_STREAM_PORT_COMMIT_EVENT(event, (uint32_t)eventSize);\r
+ }\r
+ }\r
+ }\r
+ \r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Saves a symbol name (task name etc.) in symbol table */\r
+void prvTraceSaveSymbol(const void *address, const char *name)\r
+{\r
+ uint32_t i;\r
+ uint32_t foundSlot;\r
+ uint32_t *ptrAddress;\r
+ uint8_t *ptrSymbol;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+ \r
+ foundSlot = firstFreeSymbolTableIndex;\r
+\r
+ /* First look for previous entries using this address */\r
+ for (i = 0; i < firstFreeSymbolTableIndex; i += SYMBOL_TABLE_SLOT_SIZE)\r
+ {\r
+ /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */\r
+ ptrAddress = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[i / sizeof(uint32_t)];\r
+ if (*ptrAddress == (uint32_t)address)\r
+ {\r
+ foundSlot = i;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (foundSlot < SYMBOL_TABLE_BUFFER_SIZE)\r
+ {\r
+ /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */\r
+ symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[foundSlot / sizeof(uint32_t)] = (uint32_t)address;\r
+ \r
+ /* We access the symbol table via the union member pSymbolTableBufferUINT8 to avoid strict-aliasing issues */\r
+ ptrSymbol = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT8[foundSlot + sizeof(uint32_t)];\r
+ for (i = 0; i < (TRC_CFG_SYMBOL_MAX_LENGTH); i++)\r
+ {\r
+ ptrSymbol[i] = (uint8_t)name[i]; /* We do this first to ensure we also get the 0 termination, if there is one */\r
+\r
+ if (name[i] == 0)\r
+ break;\r
+ }\r
+\r
+ /* Check the length of "name", if longer than SYMBOL_MAX_LENGTH */\r
+ while ((name[i] != 0) && i < 128)\r
+ {\r
+ i++;\r
+ }\r
+\r
+ /* Remember the longest symbol name, for diagnostic purposes */\r
+ if (i > LongestSymbolName)\r
+ {\r
+ LongestSymbolName = i;\r
+ }\r
+\r
+ /* Is this the last entry in the symbol table? */\r
+ if (foundSlot == firstFreeSymbolTableIndex)\r
+ {\r
+ firstFreeSymbolTableIndex += SYMBOL_TABLE_SLOT_SIZE;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ NoRoomForSymbol++;\r
+ }\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Deletes a symbol name (task name etc.) from symbol table */\r
+void prvTraceDeleteSymbol(void *address)\r
+{\r
+ uint32_t i, j;\r
+ uint32_t *ptr, *lastEntryPtr;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ for (i = 0; i < firstFreeSymbolTableIndex; i += SYMBOL_TABLE_SLOT_SIZE)\r
+ {\r
+ /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */\r
+ ptr = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[i / sizeof(uint32_t)];\r
+ if (*ptr == (uint32_t)address)\r
+ {\r
+ /* See if we have another entry in the table, and that this isn't already the last entry */\r
+ if (firstFreeSymbolTableIndex > SYMBOL_TABLE_SLOT_SIZE && i != (firstFreeSymbolTableIndex - SYMBOL_TABLE_SLOT_SIZE))\r
+ {\r
+ /* Another entry is available, get pointer to the last one */\r
+ /* We access the symbol table via the union member pSymbolTableBufferUINT32 to avoid strict-aliasing issues */\r
+ lastEntryPtr = &symbolTable.SymbolTableBuffer.pSymbolTableBufferUINT32[(firstFreeSymbolTableIndex - SYMBOL_TABLE_SLOT_SIZE) / sizeof(uint32_t)];\r
+ \r
+ /* Copy last entry to this position */\r
+ for (j = 0; j < (SYMBOL_TABLE_SLOT_SIZE) / sizeof(uint32_t); j++)\r
+ {\r
+ ptr[j] = lastEntryPtr[j];\r
+ }\r
+\r
+ /* For good measure we also zero out the original position */\r
+ *lastEntryPtr = 0;\r
+ }\r
+ else\r
+ *ptr = 0; /* No other entry found, or this is the last entry */\r
+\r
+ /* Lower index */\r
+ firstFreeSymbolTableIndex -= SYMBOL_TABLE_SLOT_SIZE;\r
+\r
+ break;\r
+ }\r
+ }\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Saves an object data entry (current task priority) in object data table */\r
+void prvTraceSaveObjectData(const void *address, uint32_t data)\r
+{\r
+ uint32_t i;\r
+ uint32_t foundSlot;\r
+ uint32_t *ptr;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+ \r
+ foundSlot = firstFreeObjectDataTableIndex;\r
+\r
+ /* First look for previous entries using this address */\r
+ for (i = 0; i < firstFreeObjectDataTableIndex; i += OBJECT_DATA_SLOT_SIZE)\r
+ {\r
+ /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */\r
+ ptr = &objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[i / sizeof(uint32_t)];\r
+ if (*ptr == (uint32_t)address)\r
+ {\r
+ foundSlot = i;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (foundSlot < OBJECT_DATA_TABLE_BUFFER_SIZE)\r
+ {\r
+ /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */\r
+ objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[foundSlot / sizeof(uint32_t)] = (uint32_t)address;\r
+ objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[foundSlot / sizeof(uint32_t) + 1] = data;\r
+\r
+ /* Is this the last entry in the object data table? */\r
+ if (foundSlot == firstFreeObjectDataTableIndex)\r
+ {\r
+ firstFreeObjectDataTableIndex += OBJECT_DATA_SLOT_SIZE;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ NoRoomForObjectData++;\r
+ }\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Removes an object data entry (task base priority) from object data table */\r
+void prvTraceDeleteObjectData(void *address)\r
+{\r
+ uint32_t i, j;\r
+ uint32_t *ptr, *lastEntryPtr;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+\r
+ for (i = 0; i < firstFreeObjectDataTableIndex; i += OBJECT_DATA_SLOT_SIZE)\r
+ {\r
+ /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */\r
+ ptr = &objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[i / sizeof(uint32_t)];\r
+ if (*ptr == (uint32_t)address)\r
+ {\r
+ /* See if we have another entry in the table, and that this isn't already the last entry */\r
+ if (firstFreeObjectDataTableIndex > OBJECT_DATA_SLOT_SIZE && i != (firstFreeObjectDataTableIndex - OBJECT_DATA_SLOT_SIZE))\r
+ {\r
+ /* Another entry is available, get pointer to the last one */\r
+ /* We access the data table via the union member pObjectDataTableBufferUINT32 to avoid strict-aliasing issues */\r
+ lastEntryPtr = &objectDataTable.ObjectDataTableBuffer.pObjectDataTableBufferUINT32[(firstFreeObjectDataTableIndex - OBJECT_DATA_SLOT_SIZE) / sizeof(uint32_t)];\r
+ \r
+ /* Copy last entry to this position */\r
+ for (j = 0; j < (OBJECT_DATA_SLOT_SIZE) / sizeof(uint32_t); j++)\r
+ {\r
+ ptr[j] = lastEntryPtr[j];\r
+ }\r
+\r
+ /* For good measure we also zero out the original position */\r
+ *lastEntryPtr = 0;\r
+ }\r
+ else\r
+ *ptr = 0; /* No other entry found, or this is the last entry */\r
+\r
+ /* Lower index */\r
+ firstFreeObjectDataTableIndex -= OBJECT_DATA_SLOT_SIZE;\r
+\r
+ break;\r
+ }\r
+ }\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Checks if the provided command is a valid command */\r
+int prvIsValidCommand(TracealyzerCommandType* cmd)\r
+{\r
+ uint16_t checksum = (uint16_t)(0xFFFF - ( cmd->cmdCode +\r
+ cmd->param1 +\r
+ cmd->param2 +\r
+ cmd->param3 +\r
+ cmd->param4 +\r
+ cmd->param5));\r
+\r
+ if (cmd->checksumMSB != (unsigned char)(checksum >> 8))\r
+ return 0;\r
+\r
+ if (cmd->checksumLSB != (unsigned char)(checksum & 0xFF))\r
+ return 0;\r
+\r
+ if (cmd->cmdCode > CMD_LAST_COMMAND)\r
+ return 0;\r
+\r
+ return 1;\r
+}\r
+\r
+/* Executed the received command (Start or Stop) */\r
+void prvProcessCommand(TracealyzerCommandType* cmd)\r
+{\r
+ switch(cmd->cmdCode)\r
+ {\r
+ case CMD_SET_ACTIVE:\r
+ prvSetRecorderEnabled(cmd->param1);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+}\r
+\r
+/* Called on critical errors in the recorder. Stops the recorder! */\r
+void prvTraceError(int errCode)\r
+{\r
+ if (! errorCode)\r
+ {\r
+ errorCode = errCode;\r
+ prvTraceStoreWarnings();\r
+ vTracePrintF(trcWarningChannel, "Error detected. Stopped recorder.");\r
+\r
+ prvSetRecorderEnabled(0);\r
+ }\r
+}\r
+\r
+/* If using DWT timestamping (default on ARM Cortex-M3, M4 and M7), make sure the DWT unit is initialized. */\r
+#ifndef TRC_CFG_ARM_CM_USE_SYSTICK\r
+#if ((TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M) && (defined (__CORTEX_M) && (__CORTEX_M >= 0x03)))\r
+\r
+void prvTraceInitCortexM()\r
+{\r
+ /* Make sure the DWT registers are unlocked, in case the debugger doesn't do this. */\r
+ TRC_REG_ITM_LOCKACCESS = TRC_ITM_LOCKACCESS_UNLOCK;\r
+\r
+ /* Make sure DWT is enabled is enabled, if supported */\r
+ TRC_REG_DEMCR |= TRC_DEMCR_TRCENA;\r
+\r
+ do\r
+ {\r
+ /* Verify that DWT is supported */\r
+ if (TRC_REG_DEMCR == 0)\r
+ {\r
+ /* This function is called on Cortex-M3, M4 and M7 devices to initialize\r
+ the DWT unit, assumed present. The DWT cycle counter is used for timestamping. \r
+ \r
+ If the below error is produced, the DWT unit does not seem to be available.\r
+ \r
+ In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build\r
+ to use SysTick timestamping instead, or define your own timestamping by \r
+ setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
+ and make the necessary definitions, as explained in trcHardwarePort.h.*/\r
+ \r
+ prvTraceError(PSF_ERROR_DWT_NOT_SUPPORTED);\r
+ break;\r
+ }\r
+\r
+ /* Verify that DWT_CYCCNT is supported */\r
+ if (TRC_REG_DWT_CTRL & TRC_DWT_CTRL_NOCYCCNT)\r
+ {\r
+ /* This function is called on Cortex-M3, M4 and M7 devices to initialize\r
+ the DWT unit, assumed present. The DWT cycle counter is used for timestamping. \r
+ \r
+ If the below error is produced, the cycle counter does not seem to be available.\r
+ \r
+ In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build\r
+ to use SysTick timestamping instead, or define your own timestamping by \r
+ setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
+ and make the necessary definitions, as explained in trcHardwarePort.h.*/\r
+\r
+ prvTraceError(PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED);\r
+ break;\r
+ }\r
+\r
+ /* Reset the cycle counter */\r
+ TRC_REG_DWT_CYCCNT = 0;\r
+\r
+ /* Enable the cycle counter */\r
+ TRC_REG_DWT_CTRL |= TRC_DWT_CTRL_CYCCNTENA;\r
+\r
+ } while(0); /* breaks above jump here */\r
+}\r
+#endif\r
+#endif\r
+\r
+/* Performs timestamping using definitions in trcHardwarePort.h */\r
+static uint32_t prvGetTimestamp32(void)\r
+{\r
+#if ((TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR) || (TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR))\r
+ return TRC_HWTC_COUNT;\r
+#endif\r
+ \r
+#if ((TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR))\r
+ return TRC_HWTC_COUNT;\r
+#endif\r
+ \r
+#if ((TRC_HWTC_TYPE == TRC_OS_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_OS_TIMER_DECR))\r
+ uint32_t ticks = TRACE_GET_OS_TICKS();\r
+ return (TRC_HWTC_COUNT & 0x00FFFFFFU) + ((ticks & 0x000000FFU) << 24);\r
+#endif\r
+}\r
+\r
+/* Store the Timestamp Config event */\r
+static void prvTraceStoreTSConfig(void)\r
+{\r
+ /* If not overridden using vTraceSetFrequency, use default value */\r
+ if (timestampFrequency == 0)\r
+ {\r
+ timestampFrequency = TRC_HWTC_FREQ_HZ;\r
+ }\r
+ \r
+ if (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR || TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR)\r
+ {\r
+ prvTraceStoreEvent(5, \r
+ PSF_EVENT_TS_CONFIG,\r
+ (uint32_t)timestampFrequency, \r
+ (uint32_t)TRACE_TICK_RATE_HZ,\r
+ (uint32_t)TRC_HWTC_TYPE,\r
+ (uint32_t)TRC_CFG_ISR_TAILCHAINING_THRESHOLD,\r
+ (uint32_t)TRC_HWTC_PERIOD);\r
+ }\r
+ else\r
+ {\r
+ prvTraceStoreEvent(4, \r
+ PSF_EVENT_TS_CONFIG,\r
+ (uint32_t)timestampFrequency, \r
+ (uint32_t)TRACE_TICK_RATE_HZ,\r
+ (uint32_t)TRC_HWTC_TYPE,\r
+ (uint32_t)TRC_CFG_ISR_TAILCHAINING_THRESHOLD);\r
+ }\r
+}\r
+\r
+/* Retrieve a buffer page to write to. */\r
+static int prvAllocateBufferPage(int prevPage)\r
+{\r
+ int index;\r
+ int count = 0;\r
+\r
+ index = (prevPage + 1) % TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT;\r
+\r
+ while((PageInfo[index].Status != PAGE_STATUS_FREE) && (count ++ < TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT))\r
+ {\r
+ index = (index + 1) % TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT;\r
+ }\r
+\r
+ if (PageInfo[index].Status == PAGE_STATUS_FREE)\r
+ {\r
+ return index;\r
+ }\r
+\r
+ return -1;\r
+}\r
+\r
+/* Mark the page read as complete. */\r
+static void prvPageReadComplete(int pageIndex)\r
+{\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+ PageInfo[pageIndex].BytesRemaining = TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE;\r
+ PageInfo[pageIndex].WritePointer = &EventBuffer[pageIndex * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE];\r
+ PageInfo[pageIndex].Status = PAGE_STATUS_FREE;\r
+\r
+ TotalBytesRemaining += TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE;\r
+\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+/* Get the current buffer page index and remaining number of bytes. */\r
+static int prvGetBufferPage(int32_t* bytesUsed)\r
+{\r
+ static int8_t lastPage = -1;\r
+ int count = 0;\r
+ int8_t index = (int8_t) ((lastPage + 1) % TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT);\r
+\r
+ while((PageInfo[index].Status != PAGE_STATUS_READ) && (count++ < TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT))\r
+ {\r
+ index = (int8_t)((index + 1) % TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT);\r
+ }\r
+\r
+ if (PageInfo[index].Status == PAGE_STATUS_READ)\r
+ {\r
+ *bytesUsed = TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE - PageInfo[index].BytesRemaining;\r
+ lastPage = index;\r
+ return index;\r
+ }\r
+\r
+ *bytesUsed = 0;\r
+\r
+ return -1;\r
+}\r
+\r
+/*******************************************************************************\r
+\r
+int32_t prvPagedEventBufferTransfer(int32_t (*writeFunc)(void* data,\r
+ uint32_t size),\r
+ int32_t* nofBytes)\r
+\r
+Transfers one block of trace data, if available for reading. Returns the number\r
+of bytes transfered, or a negative error code. If data was transferred (return\r
+value > 0), it can be good to call this function again until all data available\r
+has been transfered.\r
+\r
+This function is intended to be called by a periodic task with a suitable\r
+delay (e.g. 10-100 ms).\r
+\r
+Return value: as returned from writeFunc (0 == OK)\r
+\r
+Parameters:\r
+\r
+- writeFunc\r
+Function pointer (example: int32_t write(void* data, uint32_t size))\r
+The function passed as writeFunc should write "size" bytes from "data" to the\r
+socket/file/channel, and return a status code where 0 means OK,\r
+and any other non-zero value means an error.\r
+\r
+- int32_t* nofBytes\r
+Pointer to an integer assigned the number of bytes that was transfered.\r
+\r
+*******************************************************************************/\r
+int32_t prvPagedEventBufferTransfer(int32_t (*writeFunc)(void* data, uint32_t size, int32_t* ptrBytesWritten), int32_t* nofBytes)\r
+{\r
+ int8_t pageToTransfer = -1;\r
+ int32_t transferred = 0;\r
+ int32_t size = 0;\r
+ \r
+ pageToTransfer = (int8_t)prvGetBufferPage(nofBytes);\r
+ size = *nofBytes; // The number of bytes we want to transfer\r
+ transferred = 0; // The number of bytes we have transferred so far\r
+\r
+ if (pageToTransfer > -1)\r
+ {\r
+ while (1) // Keep going until we have transferred all that we intended to\r
+ {\r
+ if (writeFunc(&EventBuffer[pageToTransfer * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE + transferred], (uint32_t)(size - transferred), nofBytes) == 0)\r
+ {\r
+ // Write was successful. Update the number of transferred bytes.\r
+ transferred += *nofBytes;\r
+ if (size == transferred)\r
+ {\r
+ // All bytes have been transferred. Mark as Complete and return.\r
+ *nofBytes = transferred;\r
+ prvPageReadComplete(pageToTransfer);\r
+ return 0;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ *nofBytes = 0;\r
+ return 1;\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+\r
+/*******************************************************************************\r
+\r
+void* prvPagedEventBufferGetWritePointer(int sizeOfEvent)\r
+\r
+Returns a pointer to an available location in the buffer able to store the\r
+requested size.\r
+\r
+Return value: The pointer.\r
+\r
+Parameters:\r
+\r
+- sizeOfEvent\r
+The size of the event that is to be placed in the buffer.\r
+\r
+*******************************************************************************/\r
+void* prvPagedEventBufferGetWritePointer(int sizeOfEvent)\r
+{\r
+ void* ret;\r
+ static int currentWritePage = -1;\r
+\r
+ if (currentWritePage == -1)\r
+ {\r
+ currentWritePage = prvAllocateBufferPage(currentWritePage);\r
+ if (currentWritePage == -1)\r
+ {\r
+ DroppedEventCounter++;\r
+ return NULL;\r
+ }\r
+ }\r
+\r
+ if (PageInfo[currentWritePage].BytesRemaining - sizeOfEvent < 0)\r
+ {\r
+ PageInfo[currentWritePage].Status = PAGE_STATUS_READ;\r
+\r
+ TotalBytesRemaining -= PageInfo[currentWritePage].BytesRemaining; // Last trailing bytes\r
+\r
+ if (TotalBytesRemaining < TotalBytesRemaining_LowWaterMark)\r
+ TotalBytesRemaining_LowWaterMark = TotalBytesRemaining;\r
+\r
+ currentWritePage = prvAllocateBufferPage(currentWritePage);\r
+ if (currentWritePage == -1)\r
+ {\r
+ DroppedEventCounter++;\r
+ return NULL;\r
+ }\r
+ }\r
+ ret = PageInfo[currentWritePage].WritePointer;\r
+ PageInfo[currentWritePage].WritePointer += sizeOfEvent;\r
+ PageInfo[currentWritePage].BytesRemaining = (uint16_t)(PageInfo[currentWritePage].BytesRemaining -sizeOfEvent);\r
+\r
+ TotalBytesRemaining = (TotalBytesRemaining-(uint16_t)sizeOfEvent);\r
+\r
+ if (TotalBytesRemaining < TotalBytesRemaining_LowWaterMark)\r
+ TotalBytesRemaining_LowWaterMark = TotalBytesRemaining;\r
+\r
+ return ret;\r
+}\r
+\r
+/*******************************************************************************\r
+\r
+void prvPagedEventBufferInit(char* buffer)\r
+\r
+Assigns the buffer to use and initializes the PageInfo structure.\r
+\r
+Return value: void\r
+\r
+Parameters:\r
+\r
+- buffer\r
+Pointer to the buffer location that is dynamically or statically allocated by\r
+the caller.\r
+\r
+*******************************************************************************/\r
+void prvPagedEventBufferInit(char* buffer)\r
+{\r
+ int i;\r
+ TRACE_ALLOC_CRITICAL_SECTION();\r
+ \r
+ EventBuffer = buffer;\r
+ \r
+ TRACE_ENTER_CRITICAL_SECTION();\r
+ for (i = 0; i < TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT; i++)\r
+ {\r
+ PageInfo[i].BytesRemaining = TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE;\r
+ PageInfo[i].WritePointer = &EventBuffer[i * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE];\r
+ PageInfo[i].Status = PAGE_STATUS_FREE;\r
+ }\r
+ TRACE_EXIT_CRITICAL_SECTION();\r
+}\r
+\r
+#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
+\r
+#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
+++ /dev/null
-/*******************************************************************************\r
- * Tracealyzer v3.0.2 Recorder Library\r
- * Percepio AB, www.percepio.com\r
- *\r
- * trcUser.c\r
- *\r
- * The public API of the trace recorder library.\r
- *\r
- * Terms of Use\r
- * This software is copyright Percepio AB. The recorder library is free for\r
- * use together with Percepio products. You may distribute the recorder library\r
- * in its original form, including modifications in trcHardwarePort.c/.h\r
- * given that these modification are clearly marked as your own modifications\r
- * and documented in the initial comment section of these source files.\r
- * This software is the intellectual property of Percepio AB and may not be\r
- * sold or in other ways commercially redistributed without explicit written\r
- * permission by Percepio AB.\r
- *\r
- * Disclaimer\r
- * The trace tool and recorder library is being delivered to you AS IS and\r
- * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
- * not and cannot warrant the performance or results you may obtain by using the\r
- * software or documentation. Percepio AB make no warranties, express or\r
- * implied, as to noninfringement of third party rights, merchantability, or\r
- * fitness for any particular purpose. In no event will Percepio AB, its\r
- * technology partners, or distributors be liable to you for any consequential,\r
- * incidental or special damages, including any lost profits or lost savings,\r
- * even if a representative of Percepio AB has been advised of the possibility\r
- * of such damages, or for any claim by any third party. Some jurisdictions do\r
- * not allow the exclusion or limitation of incidental, consequential or special\r
- * damages, or the exclusion of implied warranties or limitations on how long an\r
- * implied warranty may last, so the above limitations may not apply to you.\r
- *\r
- * Tabs are used for indent in this file (1 tab = 4 spaces)\r
- *\r
- * Copyright Percepio AB, 2014.\r
- * www.percepio.com\r
- ******************************************************************************/\r
-#include "trcUser.h"\r
-\r
-#if (USE_TRACEALYZER_RECORDER == 1)\r
-\r
-#include <string.h>\r
-#include <stdarg.h>\r
-#include <stdint.h>\r
-\r
-TRACE_STOP_HOOK vTraceStopHookPtr = (TRACE_STOP_HOOK)0;\r
-\r
-extern uint8_t inExcludedTask;\r
-extern int8_t nISRactive;\r
-extern objectHandleType handle_of_last_logged_task;\r
-extern uint32_t dts_min;\r
-extern uint32_t hwtc_count_max_after_tick;\r
-extern uint32_t hwtc_count_sum_after_tick;\r
-extern uint32_t hwtc_count_sum_after_tick_counter;\r
-extern char* traceErrorMessage;\r
-\r
-/*** Private functions *******************************************************/\r
-void vTracePrintF_Helper(traceLabel eventLabel, const char* formatStr, va_list vl);\r
-\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
-void vTraceChannelPrintF_Helper(UserEventChannel channelPair, va_list vl);\r
-static void prvTraceUserEventHelper1(UserEventChannel channel, traceLabel eventLabel, traceLabel formatLabel, va_list vl);\r
-static void prvTraceUserEventHelper2(UserEventChannel channel, uint32_t* data, uint32_t noOfSlots);\r
-#endif\r
-\r
-static void prvTraceTaskInstanceFinish(int8_t direct);\r
-\r
-\r
-/*******************************************************************************\r
- * vTraceInitTraceData\r
- *\r
- * Allocates, if necessary, and initializes the recorder data structure, based\r
- * on the constants in trcConfig.h.\r
- ******************************************************************************/\r
-void vTraceInitTraceData(void)\r
-{\r
- prvTraceInitTraceData();\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceSetRecorderData\r
- *\r
- * If custom allocation is used, this function must be called so the recorder\r
- * library knows where to save the trace data.\r
- ******************************************************************************/\r
-#if TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_CUSTOM\r
-void vTraceSetRecorderData(void* pRecorderData)\r
-{\r
- TRACE_ASSERT(pRecorderData != NULL, "vTraceSetTraceData, pRecorderData == NULL", );\r
- RecorderDataPtr = pRecorderData;\r
-}\r
-#endif\r
-\r
-/*******************************************************************************\r
- * vTraceSetStopHook\r
- *\r
- * Sets a function to be called when the recorder is stopped.\r
- ******************************************************************************/\r
-void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction)\r
-{\r
- vTraceStopHookPtr = stopHookFunction;\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceClear\r
- *\r
- * Resets the recorder. Only necessary if a restart is desired - this is not\r
- * needed in the startup initialization.\r
- ******************************************************************************/\r
-void vTraceClear(void)\r
-{\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
- trcCRITICAL_SECTION_BEGIN();\r
-\r
- RecorderDataPtr->absTimeLastEventSecond = 0;\r
-\r
- RecorderDataPtr->absTimeLastEvent = 0;\r
- RecorderDataPtr->nextFreeIndex = 0;\r
- RecorderDataPtr->numEvents = 0;\r
- RecorderDataPtr->bufferIsFull = 0;\r
- traceErrorMessage = NULL;\r
- RecorderDataPtr->internalErrorOccured = 0;\r
-\r
- memset(RecorderDataPtr->eventData, 0, RecorderDataPtr->maxEvents * 4);\r
-\r
- handle_of_last_logged_task = 0;\r
- \r
- trcCRITICAL_SECTION_END();\r
-\r
-}\r
-\r
-/*******************************************************************************\r
- * uiTraceStart\r
- *\r
- * Starts the recorder. The recorder will not be started if an error has been\r
- * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h\r
- * has a too small value (NTASK, NQUEUE, etc).\r
- *\r
- * Returns 1 if the recorder was started successfully.\r
- * Returns 0 if the recorder start was prevented due to a previous internal\r
- * error. In that case, check vTraceGetLastError to get the error message.\r
- * Any error message is also presented when opening a trace file.\r
- ******************************************************************************/\r
-\r
-uint32_t uiTraceStart(void)\r
-{\r
- objectHandleType handle;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- handle = 0;\r
-\r
- if (RecorderDataPtr == NULL)\r
- {\r
- vTraceError("RecorderDataPtr is NULL. Call vTraceInitTraceData() before starting trace.");\r
- return 0;\r
- }\r
-\r
- if (traceErrorMessage == NULL)\r
- {\r
- trcCRITICAL_SECTION_BEGIN();\r
- RecorderDataPtr->recorderActive = 1;\r
-\r
- handle = TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK());\r
- if (handle == 0)\r
- {\r
- /* This occurs if the scheduler is not yet started.\r
- This creates a dummy "(startup)" task entry internally in the\r
- recorder */\r
- handle = xTraceGetObjectHandle(TRACE_CLASS_TASK);\r
- vTraceSetObjectName(TRACE_CLASS_TASK, handle, "(startup)");\r
-\r
- vTraceSetPriorityProperty(TRACE_CLASS_TASK, handle, 0);\r
- }\r
-\r
- vTraceStoreTaskswitch(handle); /* Register the currently running task */\r
- trcCRITICAL_SECTION_END();\r
- }\r
-\r
- return RecorderDataPtr->recorderActive;\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStart\r
- *\r
- * Starts the recorder. The recorder will not be started if an error has been\r
- * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h\r
- * has a too small value (NTASK, NQUEUE, etc).\r
- *\r
- * This function is obsolete, but has been saved for backwards compatibility.\r
- * We recommend using uiTraceStart instead.\r
- ******************************************************************************/\r
-void vTraceStart(void)\r
-{\r
- (void)uiTraceStart();\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStop\r
- *\r
- * Stops the recorder. The recording can be resumed by calling vTraceStart.\r
- * This does not reset the recorder. Use vTraceClear if that is desired.\r
- ******************************************************************************/\r
-void vTraceStop(void)\r
-{\r
- RecorderDataPtr->recorderActive = 0;\r
-\r
- if (vTraceStopHookPtr != (TRACE_STOP_HOOK)0)\r
- {\r
- (*vTraceStopHookPtr)(); /* An application call-back function. */\r
- }\r
-}\r
-\r
-/*******************************************************************************\r
- * xTraceGetLastError\r
- *\r
- * Gives the last error message, if any. NULL if no error message is stored.\r
- * Any error message is also presented when opening a trace file.\r
- ******************************************************************************/\r
-char* xTraceGetLastError(void)\r
-{\r
- return traceErrorMessage;\r
-}\r
-\r
-/*******************************************************************************\r
-* vTraceClearError\r
-*\r
-* Removes any previous error message generated by recorder calling vTraceError.\r
-* By calling this function, it may be possible to start/restart the trace\r
-* despite errors in the recorder, but there is no guarantee that the trace\r
-* recorder will work correctly in that case, depending on the type of error.\r
-******************************************************************************/\r
-void vTraceClearError(int resetErrorMessage)\r
-{\r
- ( void ) resetErrorMessage;\r
- traceErrorMessage = NULL;\r
- RecorderDataPtr->internalErrorOccured = 0;\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceGetTraceBuffer\r
- *\r
- * Returns a pointer to the recorder data structure. Use this together with\r
- * uiTraceGetTraceBufferSize if you wish to implement an own store/upload\r
- * solution, e.g., in case a debugger connection is not available for uploading\r
- * the data.\r
- ******************************************************************************/\r
-void* vTraceGetTraceBuffer(void)\r
-{\r
- return RecorderDataPtr;\r
-}\r
-\r
-/*******************************************************************************\r
- * uiTraceGetTraceBufferSize\r
- *\r
- * Gets the size of the recorder data structure. For use together with\r
- * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,\r
- * e.g., in case a debugger connection is not available for uploading the data.\r
- ******************************************************************************/\r
-uint32_t uiTraceGetTraceBufferSize(void)\r
-{\r
- return sizeof(RecorderDataType);\r
-}\r
-\r
-/******************************************************************************\r
- * prvTraceTaskInstanceFinish.\r
- *\r
- * Private common function for the vTraceTaskInstanceFinishXXX functions.\r
- * \r
- *****************************************************************************/\r
-void prvTraceTaskInstanceFinish(int8_t direct)\r
-{\r
- TaskInstanceStatusEvent* tis;\r
- uint8_t dts45;\r
-\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
- {\r
- dts45 = (uint8_t)prvTraceGetDTS(0xFF);\r
- tis = (TaskInstanceStatusEvent*) xTraceNextFreeEventBufferSlot();\r
- if (tis != NULL)\r
- {\r
- if (direct == 0)\r
- tis->type = TASK_INSTANCE_FINISHED_NEXT_KSE;\r
- else\r
- tis->type = TASK_INSTANCE_FINISHED_DIRECT;\r
-\r
- tis->dts = dts45;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-}\r
-\r
-/******************************************************************************\r
- * vTraceTaskInstanceFinish(void)\r
- *\r
- * Marks the current task instance as finished on the next kernel call.\r
- *\r
- * If that kernel call is blocking, the instance ends after the blocking event\r
- * and the corresponding return event is then the start of the next instance.\r
- * If the kernel call is not blocking, the viewer instead splits the current\r
- * fragment right before the kernel call, which makes this call the first event\r
- * of the next instance.\r
- *\r
- * See also USE_IMPLICIT_IFE_RULES in trcConfig.h\r
- *\r
- * Example:\r
- *\r
- * while(1)\r
- * {\r
- * xQueueReceive(CommandQueue, &command, timeoutDuration);\r
- * processCommand(command);\r
- * vTraceInstanceFinish();\r
- * }\r
- *\r
- * Note: This is only supported in Tracealyzer tools v2.7 or later\r
- *\r
- *****************************************************************************/\r
-void vTraceTaskInstanceFinish(void)\r
-{\r
- prvTraceTaskInstanceFinish(0);\r
-}\r
-\r
-/******************************************************************************\r
- * vTraceTaskInstanceFinishDirect(void)\r
- *\r
- * Marks the current task instance as finished at this very instant.\r
- * This makes the viewer to splits the current fragment at this point and begin\r
- * a new actor instance.\r
- *\r
- * See also USE_IMPLICIT_IFE_RULES in trcConfig.h\r
- *\r
- * Example:\r
- *\r
- * This example will generate two instances for each loop iteration.\r
- * The first instance ends at vTraceInstanceFinishDirect(), while the second\r
- * instance ends at the next xQueueReceive call.\r
- *\r
- * while (1)\r
- * {\r
- * xQueueReceive(CommandQueue, &command, timeoutDuration);\r
- * ProcessCommand(command);\r
- * vTraceInstanceFinishDirect();\r
- * DoSometingElse();\r
- * vTraceInstanceFinish();\r
- * }\r
- *\r
- * Note: This is only supported in Tracealyzer tools v2.7 or later\r
- *\r
- *****************************************************************************/\r
-void vTraceTaskInstanceFinishDirect(void)\r
-{\r
- prvTraceTaskInstanceFinish(1);\r
-}\r
-\r
-/*******************************************************************************\r
- * Interrupt recording functions\r
- ******************************************************************************/\r
-\r
-#if (INCLUDE_ISR_TRACING == 1)\r
-\r
-#define MAX_ISR_NESTING 16\r
-static uint8_t isrstack[MAX_ISR_NESTING];\r
-int32_t isPendingContextSwitch = 0;\r
-\r
-/*******************************************************************************\r
- * vTraceSetISRProperties\r
- *\r
- * Registers an Interrupt Service Routine in the recorder library, This must be\r
- * called before using vTraceStoreISRBegin to store ISR events. This is\r
- * typically called in the startup of the system, before the scheduler is\r
- * started.\r
- *\r
- * Example:\r
- * #define ID_ISR_TIMER1 1 // lowest valid ID is 1\r
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
- * ...\r
- * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);\r
- * ...\r
- * void ISR_handler()\r
- * {\r
- * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);\r
- * ...\r
- * vTraceStoreISREnd(0);\r
- * }\r
- *\r
- * NOTE: To safely record ISRs, you need to make sure that all traced\r
- * interrupts actually are disabled by trcCRITICAL_SECTION_BEGIN(). However,\r
- * in some ports this does not disable high priority interrupts!\r
- * If an ISR calls vTraceStoreISRBegin while the recorder is busy, it will\r
- * stop the recording and give an error message.\r
- ******************************************************************************/\r
-void vTraceSetISRProperties(objectHandleType handle, const char* name, char priority)\r
-{\r
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceSetISRProperties: Invalid value for handle", );\r
- TRACE_ASSERT(name != NULL, "vTraceSetISRProperties: name == NULL", );\r
-\r
- vTraceSetObjectName(TRACE_CLASS_ISR, handle, name);\r
- vTraceSetPriorityProperty(TRACE_CLASS_ISR, handle, priority);\r
-}\r
-\r
-#if (SELECTED_PORT == PORT_ARM_CortexM)\r
-/******************************************************************************\r
- * (Advanced...)\r
- *\r
- * ISR_TAILCHAINING_THRESHOLD (For Cortex-M devices only)\r
- *\r
- * ARM Cortex-M devices may execute ISRs back-to-back (tail-chained) without\r
- * resuming the previous context in between. Since this is decided in\r
- * hardware, we can only detect this indirectly, in the following manner:\r
- *\r
- * When entering vTraceStoreISRBegin, we check the number of CPU cycles since\r
- * the last return of vTraceStoreISREnd. If less or equal to the constant\r
- * ISR_TAILCHAINING_THRESHOLD it is assumed that the ISRs executed back-to-back\r
- * (tail-chained). In that case, the previously stored RESUME event\r
- * (pointed to by ptrLastISRExitEvent) is then deleted to avoid showing a\r
- * fragment of the previous context in between the ISR events. The delete is\r
- * made by replacing the event code with a XTS16L event, that serves to keep\r
- * the differential timestamp from the earlier event.\r
- *\r
- * The value of ISR_TAILCHAINING_THRESHOLD depends on the interrupt latency of\r
- * the processor, on the compiler and on the compiler settings, but should be\r
- * around 70 cycles. The default value is 66 cycles, which should be correct when\r
- * using GCC with optimizations disabled (-O0) and Cortex-M3/M4.\r
- *\r
- * To measure this value, see MEASURE_ISR_TAILCHAINING_THRESHOLD below.\r
- *\r
- * If this value set too low, tail-chained ISRs will incorrectly be shown\r
- * separated, with a short fragment of the previous task or ISR in between.\r
- * If this value is set too high, you get the opposite effect - separate ISRs\r
- * will appear to execute tail-chained and will appear to have higher execution\r
- * time and response time (maximum ISR_TAILCHAINING_THRESHOLD cycles more).\r
- *\r
- * Read the blog post explaining this on our website:\r
- * http://percepio.com/2014/05/06/sw-based-exc-tracing-arm-cortex-m/\r
- *\r
- *****************************************************************************/\r
-#define ISR_TAILCHAINING_THRESHOLD 66\r
-\r
-uint8_t* ptrLastISRExitEvent = NULL;\r
-uint32_t DWTCycleCountAtLastISRExit = 0;\r
-\r
-/******************************************************************************\r
- * (Advanced...)\r
- *\r
- * MEASURE_ISR_TAILCHAINING_THRESHOLD (For Cortex-M devices only)\r
- *\r
- * Allows for calibrating the value of ISR_TAILCHAINING_THRESHOLD (see above).\r
- *\r
- * This is intended to measure the minimum number of clock cycles from the end\r
- * of vTraceStoreISREnd to the beginning of the following vTraceStoreISRBegin.\r
- * For this purpose, we assume a test setup using the SysTick interrupt, which\r
- * is available on most Cortex-M devices and typically used by the RTOS kernel.\r
- * To do the measurement, follow these steps:\r
- *\r
- * 1. Make sure MEASURE_ISR_TAILCHAINING_THRESHOLD is enabled (defined as 1)\r
- *\r
- * 2. Temporarily replace your SysTick handler with the following:\r
- *\r
- * void xPortSysTickHandler( void )\r
- * {\r
- * vTraceStoreISRBegin(1);\r
- * vTraceStoreISREnd(0);\r
- * }\r
- *\r
- * 3. To make sure that the ISRs execute back-to-back, increase the OS tick\r
- * frequency to a very high level so that the OS tick interrupt execute\r
- * continuously with no application tasks in between, e.g. 10 MHz.\r
- *\r
- * 4. Put a breakpoint in the highest priority task and make sure it is not\r
- * reached. This means that the SysTick handler is executing at maximum rate\r
- * and thereby tail-chained, where the interrupt latency is 6 cycles.\r
- *\r
- * 5. Let the system run without breakpoints and inspect the value of\r
- * threshold_low_watermark. This is the minimum total latency observed.\r
- * The hardware latency is 6 clock cycles due to the tail-chaining, so the\r
- * software latency (SL) is then SL = threshold_low_watermark - 6.\r
- *\r
- * The threshold value ISR_TAILCHAINING_THRESHOLD should be SL + 2 * HL, where\r
- * HL is the normal hardware interrupt latency, i.e., the number of CPU\r
- * cycles to enter or exit the exception handler for an exception in task\r
- * context. The HL value is 12-16 depending on core, as shown below.\r
- *\r
- * Values for ISR_TAILCHAINING_THRESHOLD, assuming SL = 42\r
- * Cortex-M3 and M4 (HL = 12): 66 cycles\r
- * Cortex-M0 (HL = 16): 74 cycles\r
- * Cortex-M0+ (HL = 15): 72 cycles\r
- *\r
- * If the ISR_TAILCHAINING_THRESHOLD value is set too low, some tail-chained\r
- * ISRs be shown separated, with a short fragment of the previous context\r
- * in between. On the other hand, if the value is set too high, ISRs that \r
- * actually are separated may appear to execute back-to-back (tail-chained).\r
- *\r
- * Read the blog post explaining this on our website:\r
- * http://percepio.com/2014/05/06/sw-based-exc-tracing-arm-cortex-m/\r
- *\r
- *****************************************************************************/\r
-#define MEASURE_ISR_TAILCHAINING_THRESHOLD 1\r
-\r
-#if (MEASURE_ISR_TAILCHAINING_THRESHOLD == 1)\r
-volatile uint32_t threshold_low_watermark = 2000000000;\r
-#endif\r
-\r
-#endif\r
-\r
-/*******************************************************************************\r
- * vTraceStoreISRBegin\r
- *\r
- * Registers the beginning of an Interrupt Service Routine.\r
- *\r
- * Example:\r
- * #define ID_ISR_TIMER1 1 // lowest valid ID is 1\r
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
- * ...\r
- * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);\r
- * ...\r
- * void ISR_handler()\r
- * {\r
- * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);\r
- * ...\r
- * vTraceStoreISREnd(0);\r
- * }\r
- *\r
- ******************************************************************************/\r
-void vTraceStoreISRBegin(objectHandleType handle)\r
-{\r
- uint16_t dts4;\r
- #if (SELECTED_PORT == PORT_ARM_CortexM)\r
- uint32_t CPUCyclesSinceLastISRExit = REG_DWT_CYCCNT - DWTCycleCountAtLastISRExit;\r
- #endif\r
- TSEvent* ts;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- ts = NULL;\r
-\r
-#if (SELECTED_PORT == PORT_ARM_CortexM)\r
- if (DWTCycleCountAtLastISRExit > 0)\r
- {\r
- #if (MEASURE_ISR_TAILCHAINING_THRESHOLD == 1)\r
- /* Allows for verifying the value of ISR_TAILCHAINING_THRESHOLD */\r
- if (CPUCyclesSinceLastISRExit < threshold_low_watermark)\r
- {\r
- threshold_low_watermark = CPUCyclesSinceLastISRExit;\r
- }\r
- #endif\r
-\r
- if (CPUCyclesSinceLastISRExit <= ISR_TAILCHAINING_THRESHOLD)\r
- {\r
- /* This is judged to be a case of ISR tail-chaining since the\r
- number of cycles since the last vTraceStoreISREnd is shorter or equal to\r
- the threshold (ISR_TAILCHAINING_THRESHOLD) */\r
-\r
- if (ptrLastISRExitEvent != NULL)\r
- {\r
- /* Overwrite the last ISR exit event with a "neutral" event that only\r
- accounts for the time passed */\r
- *ptrLastISRExitEvent = XTS16L;\r
- }\r
- }\r
-\r
- }\r
-#endif\r
-\r
- if (recorder_busy)\r
- {\r
- vTraceError("Illegal call to vTraceStoreISRBegin, recorder busy!");\r
- return;\r
- }\r
- trcCRITICAL_SECTION_BEGIN();\r
- \r
- if (nISRactive == 0)\r
- isPendingContextSwitch = 0; /* We are at the start of a possible ISR chain. No context switches should have been triggered now. */\r
- \r
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
- {\r
-\r
- TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceStoreISRBegin: Invalid value for handle", );\r
- \r
- dts4 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
-\r
- if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */\r
- {\r
- if (nISRactive < MAX_ISR_NESTING)\r
- {\r
- uint8_t hnd8 = prvTraceGet8BitHandle(handle);\r
- isrstack[nISRactive] = handle;\r
- nISRactive++;\r
- ts = (TSEvent*)xTraceNextFreeEventBufferSlot();\r
- if (ts != NULL)\r
- {\r
- ts->type = TS_ISR_BEGIN;\r
- ts->dts = dts4;\r
- ts->objHandle = hnd8;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- else\r
- {\r
- /* This should not occur unless something is very wrong */\r
- vTraceError("Too many nested interrupts!");\r
- }\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-}\r
-\r
-/*******************************************************************************\r
- * vTraceStoreISREnd\r
- *\r
- * Registers the end of an Interrupt Service Routine.\r
- *\r
- * The parameter pendingISR indicates if the interrupt has requested a\r
- * task-switch (= 1) or if the interrupt returns to the earlier context (= 0)\r
- *\r
- * Example:\r
- *\r
- * #define ID_ISR_TIMER1 1 // lowest valid ID is 1\r
- * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
- * ...\r
- * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);\r
- * ...\r
- * void ISR_handler()\r
- * {\r
- * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);\r
- * ...\r
- * vTraceStoreISREnd(0);\r
- * }\r
- *\r
- ******************************************************************************/\r
-void vTraceStoreISREnd(int pendingISR)\r
-{\r
- TSEvent* ts;\r
- uint16_t dts5;\r
- uint8_t hnd8 = 0, type = 0;\r
- \r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- if (! RecorderDataPtr->recorderActive || ! handle_of_last_logged_task)\r
- {\r
- return;\r
- }\r
-\r
- if (recorder_busy)\r
- {\r
- vTraceError("Illegal call to vTraceStoreISREnd, recorder busy!");\r
- return;\r
- }\r
- \r
- if (nISRactive == 0)\r
- {\r
- vTraceError("Unmatched call to vTraceStoreISREnd (nISRactive == 0, expected > 0)");\r
- return;\r
- }\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- isPendingContextSwitch |= pendingISR; /* Is there a pending context switch right now? */\r
- nISRactive--;\r
- if (nISRactive > 0)\r
- {\r
- /* Return to another isr */\r
- type = TS_ISR_RESUME;\r
- hnd8 = prvTraceGet8BitHandle(isrstack[nISRactive - 1]); /* isrstack[nISRactive] is the handle of the ISR we're currently exiting. isrstack[nISRactive - 1] is the handle of the ISR that was executing previously. */\r
- }\r
- else if (isPendingContextSwitch == 0)\r
- {\r
- /* No context switch has been triggered by any ISR in the chain. Return to task */\r
- type = TS_TASK_RESUME;\r
- hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);\r
- }\r
- else\r
- {\r
- /* Context switch has been triggered by some ISR. We expect a proper context switch event shortly so we do nothing. */\r
- }\r
-\r
- if (type != 0)\r
- {\r
- dts5 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
- ts = (TSEvent*)xTraceNextFreeEventBufferSlot();\r
- if (ts != NULL)\r
- {\r
- ts->type = type;\r
- ts->objHandle = hnd8;\r
- ts->dts = dts5;\r
- prvTraceUpdateCounters();\r
- }\r
-\r
- #if (SELECTED_PORT == PORT_ARM_CortexM)\r
- /* Remember the last ISR exit event, as the event needs to be modified in case of a following ISR entry (if tail-chained ISRs) */\r
- ptrLastISRExitEvent = (uint8_t*)ts;\r
- #endif \r
- }\r
-\r
- #if (SELECTED_PORT == PORT_ARM_CortexM)\r
- DWTCycleCountAtLastISRExit = REG_DWT_CYCCNT;\r
- #endif\r
-\r
- trcCRITICAL_SECTION_END();\r
-}\r
-\r
-#else\r
-\r
-/* ISR tracing is turned off */\r
-void vTraceIncreaseISRActive(void)\r
-{\r
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
- nISRactive++;\r
-}\r
-\r
-void vTraceDecreaseISRActive(void)\r
-{\r
- if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
- nISRactive--;\r
-}\r
-#endif\r
-\r
-\r
-/********************************************************************************/\r
-/* User Event functions */\r
-/********************************************************************************/\r
-\r
-#if (INCLUDE_USER_EVENTS == 1)\r
-\r
-#define MAX_ARG_SIZE (4+32)\r
-/*** Locally used in vTracePrintF ***/\r
-static uint8_t writeInt8(void * buffer, uint8_t i, uint8_t value)\r
-{\r
- TRACE_ASSERT(buffer != NULL, "writeInt8: buffer == NULL", 0);\r
-\r
- if (i >= MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint8_t*)buffer)[i] = value;\r
-\r
- if (i + 1 > MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- return i + 1;\r
-}\r
-\r
-/*** Locally used in vTracePrintF ***/\r
-static uint8_t writeInt16(void * buffer, uint8_t i, uint16_t value)\r
-{\r
- TRACE_ASSERT(buffer != NULL, "writeInt16: buffer == NULL", 0);\r
-\r
- /* Align to multiple of 2 */\r
- while ((i % 2) != 0)\r
- {\r
- if (i >= MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint8_t*)buffer)[i] = 0;\r
- i++;\r
- }\r
-\r
- if (i + 2 > MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint16_t*)buffer)[i/2] = value;\r
-\r
- return i + 2;\r
-}\r
-\r
-/*** Locally used in vTracePrintF ***/\r
-static uint8_t writeInt32(void * buffer, uint8_t i, uint32_t value)\r
-{\r
- TRACE_ASSERT(buffer != NULL, "writeInt32: buffer == NULL", 0);\r
-\r
- /* A 32 bit value should begin at an even 4-byte address */\r
- while ((i % 4) != 0)\r
- {\r
- if (i >= MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint8_t*)buffer)[i] = 0;\r
- i++;\r
- }\r
-\r
- if (i + 4 > MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint32_t*)buffer)[i/4] = value;\r
-\r
- return i + 4;\r
-}\r
-\r
-#if (INCLUDE_FLOAT_SUPPORT)\r
-\r
-/*** Locally used in vTracePrintF ***/\r
-static uint8_t writeFloat(void * buffer, uint8_t i, float value)\r
-{\r
- TRACE_ASSERT(buffer != NULL, "writeFloat: buffer == NULL", 0);\r
-\r
- /* A 32 bit value should begin at an even 4-byte address */\r
- while ((i % 4) != 0)\r
- {\r
- if (i >= MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint8_t*)buffer)[i] = 0;\r
- i++;\r
- }\r
-\r
- if (i + 4 > MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((float*)buffer)[i/4] = value;\r
-\r
- return i + 4;\r
-}\r
-\r
-/*** Locally used in vTracePrintF ***/\r
-static uint8_t writeDouble(void * buffer, uint8_t i, double value)\r
-{\r
- uint32_t * dest;\r
- uint32_t * src = (uint32_t*)&value;\r
-\r
- TRACE_ASSERT(buffer != NULL, "writeDouble: buffer == NULL", 0);\r
-\r
- /* The double is written as two 32 bit values, and should begin at an even\r
- 4-byte address (to avoid having to align with 8 byte) */\r
- while (i % 4 != 0)\r
- {\r
- if (i >= MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- ((uint8_t*)buffer)[i] = 0;\r
- i++;\r
- }\r
-\r
- if (i + 8 > MAX_ARG_SIZE)\r
- {\r
- return 255;\r
- }\r
-\r
- dest = &(((uint32_t *)buffer)[i/4]);\r
-\r
- dest[0] = src[0];\r
- dest[1] = src[1];\r
-\r
- return i + 8;\r
-}\r
-\r
-#endif\r
-\r
-/*******************************************************************************\r
- * prvTraceUserEventFormat\r
- *\r
- * Parses the format string and stores the arguments in the buffer.\r
- ******************************************************************************/\r
-static uint8_t prvTraceUserEventFormat(const char* formatStr, va_list vl, uint8_t* buffer, uint8_t byteOffset)\r
-{\r
- uint16_t formatStrIndex = 0;\r
- uint8_t argCounter = 0;\r
- uint8_t i = byteOffset;\r
-\r
- while (formatStr[formatStrIndex] != '\0')\r
- {\r
- if (formatStr[formatStrIndex] == '%')\r
- {\r
- argCounter++;\r
-\r
- if (argCounter > 15)\r
- {\r
- vTraceError("vTracePrintF - Too many arguments, max 15 allowed!");\r
- return 0;\r
- }\r
-\r
- /*******************************************************************************\r
- * These below code writes raw data (primitive datatypes) in the event buffer,\r
- * instead of the normal event structs (where byte 0 is event type).\r
- * These data entries must never be interpreted as real event data, as the type\r
- * field would be misleading since used for payload data.\r
- *\r
- * The correctness of this encoding depends on two mechanisms:\r
- *\r
- * 1. An initial USER_EVENT, which type code tells the number of 32-bit data\r
- * entires that follows. (code - USER_EVENT = number of data entries).\r
- * Note that a data entry corresponds to the slots that normally corresponds to\r
- * one (1) event, i.e., 32 bits. vTracePrintF may encode several pieces of data\r
- * in one data entry, e.g., two 16-bit values or four 8-bit values, one 16-bit\r
- * value followed by two 8-bit values, etc.\r
- *\r
- * 2. A two-phase commit procedure, where the USER_EVENT and data entries are\r
- * written to a local buffer at first, and when all checks are OK then copied to\r
- * the main event buffer using a fast memcpy. The event code is finalized as the\r
- * very last step. Before that step, the event code indicates an unfinished\r
- * event, which causes it to be ignored and stop the loading of the file (since\r
- * an unfinished event is the last event in the trace).\r
- *******************************************************************************/\r
- formatStrIndex++;\r
-\r
- while ((formatStr[formatStrIndex] >= '0' && formatStr[formatStrIndex] <= '9') || formatStr[formatStrIndex] == '#' || formatStr[formatStrIndex] == '.')\r
- formatStrIndex++;\r
-\r
- if (formatStr[formatStrIndex] != '\0')\r
- {\r
- switch (formatStr[formatStrIndex])\r
- {\r
- case 'd': i = writeInt32( buffer,\r
- i,\r
- (uint32_t)va_arg(vl, uint32_t));\r
- break;\r
- case 'x':\r
- case 'X':\r
- case 'u': i = writeInt32( buffer,\r
- i,\r
- (uint32_t)va_arg(vl, uint32_t));\r
- break;\r
- case 's': i = writeInt16( buffer,\r
- i,\r
- (uint16_t)xTraceOpenLabel((char*)va_arg(vl, char*)));\r
- break;\r
-\r
-#if (INCLUDE_FLOAT_SUPPORT)\r
- /* Yes, "double" as type also in the float\r
- case. This since "float" is promoted into "double"\r
- by the va_arg stuff. */\r
- case 'f': i = writeFloat( buffer,\r
- i,\r
- (float)va_arg(vl, double));\r
- break;\r
-#else\r
- /* No support for floats, but attempt to store a float user event\r
- avoid a possible crash due to float reference. Instead store the\r
- data on uint_32 format (will not be displayed anyway). This is just\r
- to keep va_arg and i consistent. */\r
-\r
- case 'f': i = writeInt32( buffer,\r
- i,\r
- (uint32_t)va_arg(vl, double));\r
- break;\r
-#endif\r
- case 'l':\r
- formatStrIndex++;\r
- switch (formatStr[formatStrIndex])\r
- {\r
-#if (INCLUDE_FLOAT_SUPPORT)\r
- case 'f': i = writeDouble(buffer,\r
- i,\r
- (double)va_arg(vl, double));\r
- break;\r
-#else\r
- /* No support for floats, but attempt to store a float user event\r
- avoid a possible crash due to float reference. Instead store the\r
- data on uint_32 format (will not be displayed anyway). This is just\r
- to keep va_arg and i consistent. */\r
- case 'f': i = writeInt32( buffer, /* In this case, the value will not be shown anyway */\r
- i,\r
- (uint32_t)va_arg(vl, double));\r
-\r
- i = writeInt32( buffer, /* Do it twice, to write in total 8 bytes */\r
- i,\r
- (uint32_t)va_arg(vl, double));\r
- break;\r
-#endif\r
-\r
- }\r
- break;\r
- case 'h':\r
- formatStrIndex++;\r
- switch (formatStr[formatStrIndex])\r
- {\r
- case 'd': i = writeInt16( buffer,\r
- i,\r
- (uint16_t)va_arg(vl, uint32_t));\r
- break;\r
- case 'u': i = writeInt16( buffer,\r
- i,\r
- (uint16_t)va_arg(vl, uint32_t));\r
- break;\r
- }\r
- break;\r
- case 'b':\r
- formatStrIndex++;\r
- switch (formatStr[formatStrIndex])\r
- {\r
- case 'd': i = writeInt8( buffer,\r
- i,\r
- (uint8_t)va_arg(vl, uint32_t));\r
- break;\r
-\r
- case 'u': i = writeInt8( buffer,\r
- i,\r
- (uint8_t)va_arg(vl, uint32_t));\r
- break;\r
- }\r
- break;\r
- }\r
- }\r
- else\r
- break;\r
- }\r
- formatStrIndex++;\r
- if (i == 255)\r
- {\r
- vTraceError("vTracePrintF - Too large arguments, max 32 byte allowed!");\r
- return 0;\r
- }\r
- }\r
- return (i+3)/4;\r
-}\r
-\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
-\r
-/*******************************************************************************\r
- * prvTraceClearChannelBuffer\r
- *\r
- * Clears a number of items in the channel buffer, starting from nextSlotToWrite.\r
- ******************************************************************************/\r
-static void prvTraceClearChannelBuffer(uint32_t count)\r
-{\r
- uint32_t slots;\r
-\r
- TRACE_ASSERT(USER_EVENT_BUFFER_SIZE >= count,\r
- "prvTraceClearChannelBuffer: USER_EVENT_BUFFER_SIZE is too small to handle this event.", );\r
-\r
- /* Check if we're close to the end of the buffer */\r
- if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > USER_EVENT_BUFFER_SIZE)\r
- {\r
- slots = USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
- (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, slots);\r
- (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[0], 0, (count - slots));\r
- }\r
- else\r
- (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, count);\r
-}\r
-\r
-/*******************************************************************************\r
- * prvTraceCopyToDataBuffer\r
- *\r
- * Copies a number of items to the data buffer, starting from nextSlotToWrite.\r
- ******************************************************************************/\r
-static void prvTraceCopyToDataBuffer(uint32_t* data, uint32_t count)\r
-{\r
- TRACE_ASSERT(data != NULL,\r
- "prvTraceCopyToDataBuffer: data == NULL.", );\r
- TRACE_ASSERT(count <= USER_EVENT_BUFFER_SIZE,\r
- "prvTraceCopyToDataBuffer: USER_EVENT_BUFFER_SIZE is too small to handle this event.", );\r
-\r
- uint32_t slots;\r
- /* Check if we're close to the end of the buffer */\r
- if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > USER_EVENT_BUFFER_SIZE)\r
- {\r
- slots = USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
- (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, slots * 4);\r
- (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[0], data + slots, (count - slots) * 4);\r
- }\r
- else\r
- {\r
- (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, count * 4);\r
- }\r
-}\r
-\r
-/*******************************************************************************\r
- * prvTraceUserEventHelper1\r
- *\r
- * Calls on prvTraceUserEventFormat() to do the actual formatting, then goes on\r
- * to the next helper function.\r
- ******************************************************************************/\r
-static void prvTraceUserEventHelper1(UserEventChannel channel, traceLabel eventLabel, traceLabel formatLabel, va_list vl)\r
-{\r
- uint32_t data[(3 + MAX_ARG_SIZE) / 4];\r
- uint8_t byteOffset = 4; /* Need room for timestamp */\r
- uint8_t noOfSlots;\r
-\r
- if (channel == 0)\r
- {\r
- /* We are dealing with an unknown channel format pair */\r
- byteOffset += 4; /* Also need room for channel and format */\r
- ((uint16_t*)data)[2] = eventLabel;\r
- ((uint16_t*)data)[3] = formatLabel;\r
- }\r
-\r
- noOfSlots = prvTraceUserEventFormat((char*)&(RecorderDataPtr->SymbolTable.symbytes[formatLabel+4]), vl, (uint8_t*)data, byteOffset);\r
-\r
- prvTraceUserEventHelper2(channel, data, noOfSlots);\r
-}\r
-\r
-/*******************************************************************************\r
- * prvTraceUserEventHelper2\r
- *\r
- * This function simply copies the data buffer to the actual user event buffer.\r
- ******************************************************************************/\r
-static void prvTraceUserEventHelper2(UserEventChannel channel, uint32_t* data, uint32_t noOfSlots)\r
-{\r
- static uint32_t old_timestamp = 0;\r
- uint32_t old_nextSlotToWrite = 0;\r
-\r
- TRACE_ASSERT(USER_EVENT_BUFFER_SIZE >= noOfSlots, "vTracePrintF: USER_EVENT_BUFFER_SIZE is too small to handle this event.", );\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- /* Store the timestamp */\r
- vTracePortGetTimeStamp(data);\r
-\r
- if (*data < old_timestamp)\r
- {\r
- RecorderDataPtr->userEventBuffer.wraparoundCounter++;\r
- }\r
-\r
- old_timestamp = *data;\r
-\r
- /* Start by erasing any information in the channel buffer */\r
- prvTraceClearChannelBuffer(noOfSlots);\r
-\r
- prvTraceCopyToDataBuffer(data, noOfSlots); /* Will wrap around the data if necessary */\r
-\r
- old_nextSlotToWrite = RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Save the index that we want to write the channel data at when we're done */\r
- RecorderDataPtr->userEventBuffer.nextSlotToWrite = (RecorderDataPtr->userEventBuffer.nextSlotToWrite + noOfSlots) % USER_EVENT_BUFFER_SIZE; /* Make sure we never end up outside the buffer */\r
-\r
- /* Write to the channel buffer to indicate that this user event is ready to be used */\r
- if (channel != 0)\r
- {\r
- RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = channel;\r
- }\r
- else\r
- {\r
- /* 0xFF indicates that this is not a normal channel id */\r
- RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = (UserEventChannel)0xFF;\r
- }\r
- trcCRITICAL_SECTION_END();\r
-}\r
-\r
-/*******************************************************************************\r
- * xTraceRegisterChannelFormat\r
- *\r
- * Attempts to create a pair of the channel and format string.\r
- *\r
- * Note: This is only available if USE_SEPARATE_USER_EVENT_BUFFER is enabled in\r
- * trcConfig.h\r
- ******************************************************************************/\r
-UserEventChannel xTraceRegisterChannelFormat(traceLabel channel, traceLabel formatStr)\r
-{\r
- uint8_t i;\r
- UserEventChannel retVal = 0;\r
-\r
- TRACE_ASSERT(formatStr != 0, "vTraceRegisterChannelFormat: formatStr == 0", (UserEventChannel)0);\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- for (i = 1; i <= CHANNEL_FORMAT_PAIRS; i++) /* Size of the channels buffer is CHANNEL_FORMAT_PAIRS + 1. Index 0 is unused. */\r
- {\r
- if(RecorderDataPtr->userEventBuffer.channels[i].name == 0 && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == 0)\r
- {\r
- /* Found empty slot */\r
- RecorderDataPtr->userEventBuffer.channels[i].name = channel;\r
- RecorderDataPtr->userEventBuffer.channels[i].defaultFormat = formatStr;\r
- retVal = (UserEventChannel)i;\r
- break;\r
- }\r
-\r
- if (RecorderDataPtr->userEventBuffer.channels[i].name == channel && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == formatStr)\r
- {\r
- /* Found a match */\r
- retVal = (UserEventChannel)i;\r
- break;\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
- return retVal;\r
-}\r
-\r
-/******************************************************************************\r
- * vTraceChannelPrintF\r
- *\r
- * Slightly faster version of vTracePrintF() due to no lookups.\r
- *\r
- * Note: This is only available if USE_SEPARATE_USER_EVENT_BUFFER is enabled in\r
- * trcConfig.h\r
- *\r
- ******************************************************************************/\r
-void vTraceChannelPrintF(UserEventChannel channelPair, ...)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- va_list vl;\r
-\r
- va_start(vl, channelPair);\r
- vTraceChannelPrintF_Helper(channelPair, vl);\r
- va_end(vl);\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-\r
-void vTraceChannelPrintF_Helper(UserEventChannel channelPair, va_list vl)\r
-{\r
- traceLabel channel;\r
- traceLabel formatStr;\r
-\r
- TRACE_ASSERT(channelPair != 0, "vTraceChannelPrintF: channelPair == 0", );\r
- TRACE_ASSERT(channelPair <= CHANNEL_FORMAT_PAIRS, "vTraceChannelPrintF: ", );\r
-\r
- channel = RecorderDataPtr->userEventBuffer.channels[channelPair].name;\r
- formatStr = RecorderDataPtr->userEventBuffer.channels[channelPair].defaultFormat;\r
-\r
- prvTraceUserEventHelper1(channelPair, channel, formatStr, vl);\r
-}\r
-\r
-/******************************************************************************\r
- * vTraceChannelUserEvent\r
- *\r
- * Slightly faster version of vTraceUserEvent() due to no lookups.\r
- ******************************************************************************/\r
-void vTraceChannelUserEvent(UserEventChannel channelPair)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- uint32_t data[(3 + MAX_ARG_SIZE) / 4];\r
-\r
- TRACE_ASSERT(channelPair != 0, "vTraceChannelPrintF: channelPair == 0", );\r
- TRACE_ASSERT(channelPair <= CHANNEL_FORMAT_PAIRS, "vTraceChannelPrintF: ", );\r
-\r
- prvTraceUserEventHelper2(channelPair, data, 1); /* Only need one slot for timestamp */\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-#endif /* USE_SEPARATE_USER_EVENT_BUFFER == 1 */\r
-\r
-/******************************************************************************\r
- * vTracePrintF\r
- *\r
- * Advanced user events (Professional Edition only)\r
- *\r
- * Generates User Event with formatted text and data, similar to a "printf".\r
- * It is very fast compared to a normal "printf" since this function only\r
- * stores the arguments. The actual formatting is done\r
- * on the host PC when the trace is displayed in the viewer tool.\r
- *\r
- * User Event labels are created using xTraceOpenLabel.\r
- * Example:\r
- *\r
- * traceLabel adc_uechannel = xTraceOpenLabel("ADC User Events");\r
- * ...\r
- * vTracePrint(adc_uechannel,\r
- * "ADC channel %d: %lf volts",\r
- * ch, (double)adc_reading/(double)scale);\r
- *\r
- * This can be combined into one line, if desired, but this is slower:\r
- *\r
- * vTracePrint(xTraceOpenLabel("ADC User Events"),\r
- * "ADC channel %d: %lf volts",\r
- * ch, (double)adc_reading/(double)scale);\r
- *\r
- * Calling xTraceOpenLabel multiple times will not create duplicate entries, but\r
- * it is of course faster to just do it once, and then keep the handle for later\r
- * use. If you don�t have any data arguments, only a text label/string, it is\r
- * better to use vTraceUserEvent - it is faster.\r
- *\r
- * Format specifiers supported:\r
- * %d - 32 bit signed integer\r
- * %u - 32 bit unsigned integer\r
- * %f - 32 bit float\r
- * %s - string (is copied to the recorder symbol table)\r
- * %hd - 16 bit signed integer\r
- * %hu - 16 bit unsigned integer\r
- * %bd - 8 bit signed integer\r
- * %bu - 8 bit unsigned integer\r
- * %lf - double-precision float (Note! See below...)\r
- *\r
- * Up to 15 data arguments are allowed, with a total size of maximum 32 byte.\r
- * In case this is exceeded, the user event is changed into an error message.\r
- *\r
- * The data is stored in trace buffer, and is packed to allow storing multiple\r
- * smaller data entries in the same 4-byte record, e.g., four 8-bit values.\r
- * A string requires two bytes, as the symbol table is limited to 64K. Storing\r
- * a double (%lf) uses two records, so this is quite costly. Use float (%f)\r
- * unless the higher precision is really necessary.\r
- *\r
- * Note that the double-precision float (%lf) assumes a 64 bit double\r
- * representation. This does not seem to be the case on e.g. PIC24 and PIC32.\r
- * Before using a %lf argument on a 16-bit MCU, please verify that\r
- * "sizeof(double)" actually gives 8 as expected. If not, use %f instead.\r
- ******************************************************************************/\r
-\r
-void vTracePrintF(traceLabel eventLabel, const char* formatStr, ...)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
- va_list vl;\r
-\r
- va_start(vl, formatStr);\r
- vTracePrintF_Helper(eventLabel, formatStr, vl);\r
- va_end(vl);\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-\r
-void vTracePrintF_Helper(traceLabel eventLabel, const char* formatStr, va_list vl)\r
-{\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 0)\r
- uint32_t noOfSlots;\r
- UserEvent* ue1;\r
- uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- /**************************************************************************\r
- * The array tempDataBuffer is a local buffer used in a two-phase commit of\r
- * the event data, since a vTracePrintF may span over multiple slots in the\r
- * buffer.\r
- * This buffer can be made larger, of course, but remember the risk for\r
- * stack overflow. Note: This should be a LOCAL buffer, must not be made\r
- * global. That would cause data corruption when two calls to vTracePrintF\r
- * from different tasks overlaps (interrupts are only disabled in a small\r
- * part of this function, otherwise enabled)\r
- ***************************************************************************/\r
-\r
- TRACE_ASSERT(formatStr != NULL, "vTracePrintF: formatStr == NULL", );\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
-\r
- if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
- {\r
- /* First, write the "primary" user event entry in the local buffer, but\r
- let the event type be "EVENT_BEING_WRITTEN" for now...*/\r
-\r
- ue1 = (UserEvent*)(&tempDataBuffer[0]);\r
-\r
- ue1->type = EVENT_BEING_WRITTEN; /* Update this as the last step */\r
-\r
- noOfSlots = prvTraceUserEventFormat(formatStr, vl, (uint8_t*)tempDataBuffer, 4);\r
-\r
- /* Store the format string, with a reference to the channel symbol */\r
- ue1->payload = prvTraceOpenSymbol(formatStr, eventLabel);\r
-\r
- ue1->dts = (uint8_t)prvTraceGetDTS(0xFF);\r
-\r
- /* prvTraceGetDTS might stop the recorder in some cases... */\r
- if (RecorderDataPtr->recorderActive)\r
- {\r
-\r
- /* If the data does not fit in the remaining main buffer, wrap around to\r
- 0 if allowed, otherwise stop the recorder and quit). */\r
- if (RecorderDataPtr->nextFreeIndex + noOfSlots > RecorderDataPtr->maxEvents)\r
- {\r
- #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)\r
- (void)memset(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],\r
- 0,\r
- (RecorderDataPtr->maxEvents - RecorderDataPtr->nextFreeIndex)*4);\r
- RecorderDataPtr->nextFreeIndex = 0;\r
- RecorderDataPtr->bufferIsFull = 1;\r
- #else\r
-\r
- /* Stop recorder, since the event data will not fit in the\r
- buffer and not circular buffer in this case... */\r
- vTraceStop();\r
- #endif\r
- }\r
-\r
- /* Check if recorder has been stopped (i.e., vTraceStop above) */\r
- if (RecorderDataPtr->recorderActive)\r
- {\r
- /* Check that the buffer to be overwritten does not contain any user\r
- events that would be partially overwritten. If so, they must be "killed"\r
- by replacing the user event and following data with NULL events (i.e.,\r
- using a memset to zero).*/\r
- #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)\r
- prvCheckDataToBeOverwrittenForMultiEntryEvents((uint8_t)noOfSlots);\r
- #endif\r
- /* Copy the local buffer to the main buffer */\r
- (void)memcpy(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],\r
- tempDataBuffer,\r
- noOfSlots * 4);\r
-\r
- /* Update the event type, i.e., number of data entries following the\r
- main USER_EVENT entry (Note: important that this is after the memcpy,\r
- but within the critical section!)*/\r
- RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4] =\r
- (uint8_t) ( USER_EVENT + noOfSlots - 1 );\r
-\r
- /* Update the main buffer event index (already checked that it fits in\r
- the buffer, so no need to check for wrapping)*/\r
-\r
- RecorderDataPtr->nextFreeIndex += noOfSlots;\r
- RecorderDataPtr->numEvents += noOfSlots;\r
-\r
- if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)\r
- {\r
- #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)\r
- /* We have reached the end, but this is a ring buffer. Start from the beginning again. */\r
- RecorderDataPtr->bufferIsFull = 1;\r
- RecorderDataPtr->nextFreeIndex = 0;\r
- #else\r
- /* We have reached the end so we stop. */\r
- vTraceStop();\r
- #endif\r
- }\r
- }\r
-\r
- #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)\r
- /* Make sure the next entry is cleared correctly */\r
- prvCheckDataToBeOverwrittenForMultiEntryEvents(1);\r
- #endif\r
-\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-\r
-#elif (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
- /* Use the separate user event buffer */\r
- traceLabel formatLabel;\r
- UserEventChannel channel;\r
-\r
- if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
- {\r
- formatLabel = xTraceOpenLabel(formatStr);\r
-\r
- channel = xTraceRegisterChannelFormat(eventLabel, formatLabel);\r
-\r
- prvTraceUserEventHelper1(channel, eventLabel, formatLabel, vl);\r
- }\r
-#endif\r
-}\r
-\r
-/******************************************************************************\r
- * vTraceUserEvent\r
- *\r
- * Basic user event (Standard and Professional Edition only)\r
- *\r
- * Generates a User Event with a text label. The label is created/looked up\r
- * in the symbol table using xTraceOpenLabel.\r
- ******************************************************************************/\r
-void vTraceUserEvent(traceLabel eventLabel)\r
-{\r
-#if (TRACE_SCHEDULING_ONLY == 0)\r
-#if (USE_SEPARATE_USER_EVENT_BUFFER == 0)\r
- UserEvent* ue;\r
- uint8_t dts1;\r
- TRACE_SR_ALLOC_CRITICAL_SECTION();\r
-\r
- TRACE_ASSERT(eventLabel > 0, "vTraceUserEvent: Invalid value for eventLabel", );\r
-\r
- trcCRITICAL_SECTION_BEGIN();\r
- if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
- {\r
- dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
- ue = (UserEvent*) xTraceNextFreeEventBufferSlot();\r
- if (ue != NULL)\r
- {\r
- ue->dts = dts1;\r
- ue->type = USER_EVENT;\r
- ue->payload = eventLabel;\r
- prvTraceUpdateCounters();\r
- }\r
- }\r
- trcCRITICAL_SECTION_END();\r
-\r
-#elif (USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
- UserEventChannel channel;\r
- uint32_t noOfSlots = 1;\r
- uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];\r
- if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
- {\r
- channel = xTraceRegisterChannelFormat(0, eventLabel);\r
-\r
- if (channel == 0)\r
- {\r
- /* We are dealing with an unknown channel format pair */\r
- noOfSlots++; /* Also need room for channel and format */\r
- ((uint16_t*)tempDataBuffer)[2] = 0;\r
- ((uint16_t*)tempDataBuffer)[3] = eventLabel;\r
- }\r
-\r
- prvTraceUserEventHelper2(channel, tempDataBuffer, noOfSlots);\r
- }\r
-#endif\r
-#endif /* TRACE_SCHEDULING_ONLY */\r
-}\r
-\r
-/*******************************************************************************\r
- * xTraceOpenLabel\r
- *\r
- * Creates user event labels for user event channels or for individual events.\r
- * User events can be used to log application events and data for display in\r
- * the visualization tool. A user event is identified by a label, i.e., a string,\r
- * which is stored in the recorder's symbol table.\r
- * When logging a user event, a numeric handle (reference) to this string is\r
- * used to identify the event. This is obtained by calling\r
- *\r
- * xTraceOpenLabel()\r
- *\r
- * which adds the string to the symbol table (if not already present)\r
- * and returns the corresponding handle.\r
- *\r
- * This can be used in two ways:\r
- *\r
- * 1. The handle is looked up every time, when storing the user event.\r
- *\r
- * Example:\r
- * vTraceUserEvent(xTraceOpenLabel("MyUserEvent"));\r
- *\r
- * 2. The label is registered just once, with the handle stored in an\r
- * application variable - much like using a file handle.\r
- *\r
- * Example:\r
- * myEventHandle = xTraceOpenLabel("MyUserEvent");\r
- * ...\r
- * vTraceUserEvent(myEventHandle);\r
- *\r
- * The second option is faster since no lookup is required on each event, and\r
- * therefore recommended for user events that are frequently\r
- * executed and/or located in time-critical code. The lookup operation is\r
- * however fairly fast due to the design of the symbol table.\r
- ******************************************************************************/\r
-traceLabel xTraceOpenLabel(const char* label)\r
-{\r
- TRACE_ASSERT(label != NULL, "xTraceOpenLabel: label == NULL", (traceLabel)0);\r
-\r
- return prvTraceOpenSymbol(label, 0);\r
-}\r
-\r
-#endif\r
-\r
-#endif\r