Update to the latest trace recorder library.

pull/1/head
Richard Barry 8 years ago
parent 9f84f353d0
commit f289bfb388

@ -1,477 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcConfig.h
*
* Configuration parameters for the trace recorder library. Before using the
* trace recorder library, please check that the default settings are
* appropriate for your system, and if necessary adjust these. Most likely, you
* will need to adjust the NTask, NISR, NQueue, NMutex and NSemaphore values to
* reflect the number of such objects in your system. These may be
* over-approximated, although larger values values implies more RAM usage.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#ifndef TRCCONFIG_H
#define TRCCONFIG_H
/******************************************************************************
* SELECTED_PORT
*
* Macro that specifies what hardware port that should be used.
* Available ports are:
*
* Port Name Code Official OS supported
* PORT_APPLICATION_DEFINED -2 - -
* PORT_NOT_SET -1 - -
* PORT_HWIndependent 0 Yes Any
* PORT_Win32 1 Yes FreeRTOS on Win32
* PORT_Atmel_AT91SAM7 2 No Any
* PORT_Atmel_UC3A0 3 No Any
* PORT_ARM_CortexM 4 Yes Any
* PORT_Renesas_RX600 5 Yes Any
* PORT_Microchip_dsPIC_AND_PIC24 6 Yes Any
* PORT_TEXAS_INSTRUMENTS_TMS570 7 No Any
* PORT_TEXAS_INSTRUMENTS_MSP430 8 No Any
* PORT_MICROCHIP_PIC32MX 9 Yes Any
* PORT_XILINX_PPC405 10 No FreeRTOS
* PORT_XILINX_PPC440 11 No FreeRTOS
* PORT_XILINX_MICROBLAZE 12 No Any
* PORT_NXP_LPC210X 13 No Any
* PORT_MICROCHIP_PIC32MZ 14 Yes Any
* PORT_ARM_CORTEX_A9 15 No Any
* PORT_ARM_CORTEX_M0 16 Yes Any
*****************************************************************************/
// Set the port setting here!
#define SELECTED_PORT PORT_NOT_SET
#if (SELECTED_PORT == PORT_ARM_CortexM)
/* For ARM Cortex-M: make sure ARM's CMSIS library is included here, which
is used for accessing the PRIMASK register. e.g. #include "board.h" */
#endif
#if (SELECTED_PORT == PORT_NOT_SET)
#error "You need to define SELECTED_PORT here!"
#endif
/******************************************************************************
* FREERTOS_VERSION
*
* Specify what version of FreeRTOS that is used. This is necessary compensate
* for renamed symbols in the FreeRTOS kernel (does not build if incorrect).
*
* FREERTOS_VERSION_7_3_OR_7_4 (= 1) If using FreeRTOS v7.3.0 - v7.4.2
* FREERTOS_VERSION_7_5_OR_7_6 (= 2) If using FreeRTOS v7.5.0 - v7.6.0
* FREERTOS_VERSION_8_0_OR_LATER (= 3) If using FreeRTOS v8.0.0 or later
*****************************************************************************/
#define FREERTOS_VERSION FREERTOS_VERSION_8_0_OR_LATER
/******************************************************************************
* TRACE_RECORDER_STORE_MODE
*
* Macro which should be defined as one of:
* - TRACE_STORE_MODE_RING_BUFFER
* - TRACE_STORE_MODE_STOP_WHEN_FULL
* Default is TRACE_STORE_MODE_RING_BUFFER.
*
* With TRACE_RECORDER_STORE_MODE set to TRACE_STORE_MODE_RING_BUFFER, the
* events are stored in a ring buffer, i.e., where the oldest events are
* overwritten when the buffer becomes full. This allows you to get the last
* events leading up to an interesting state, e.g., an error, without having
* to store the whole run since startup.
*
* When TRACE_RECORDER_STORE_MODE is TRACE_STORE_MODE_STOP_WHEN_FULL, the
* recording is stopped when the buffer becomes full. This is useful for
* recording events following a specific state, e.g., the startup sequence.
*****************************************************************************/
#define TRACE_RECORDER_STORE_MODE TRACE_STORE_MODE_RING_BUFFER
/*******************************************************************************
* TRACE_SCHEDULING_ONLY
*
* Macro which should be defined as an integer value.
*
* If this setting is enabled (= 1), only scheduling events are recorded.
* If disabled (= 0), all events are recorded.
*
* For users of "Free Edition", that only displays scheduling events, this
* option can be used to avoid storing other events.
*
* Default value is 0 (store all enabled events).
*
******************************************************************************/
#define TRACE_SCHEDULING_ONLY 0
/*******************************************************************************
* EVENT_BUFFER_SIZE
*
* Macro which should be defined as an integer value.
*
* This defines the capacity of the event buffer, i.e., the number of records
* it may store. Most events use one record (4 byte), although some events
* require multiple 4-byte records. You should adjust this to the amount of RAM
* available in the target system.
*
* Default value is 1000, which means that 4000 bytes is allocated for the
* event buffer.
******************************************************************************/
#define EVENT_BUFFER_SIZE 1000
/*******************************************************************************
* NTask, NISR, NQueue, NSemaphore, NMutex
*
* A group of macros which should be defined as integer values, zero or larger.
*
* These define the capacity of the Object Property Table, i.e., the maximum
* number of objects active at any given point, within each object class (e.g.,
* task, queue, semaphore, ...).
*
* If tasks or other other objects are deleted in your system, this
* setting does not limit the total amount of objects created, only the number
* of objects that have been successfully created but not yet deleted.
*
* Using too small values will cause vTraceError to be called, which stores an
* error message in the trace that is shown when opening the trace file.
*
* It can be wise to start with large values for these constants,
* unless you are very confident on these numbers. Then do a recording and
* check the actual usage by selecting View menu -> Trace Details ->
* Resource Usage -> Object Table.
******************************************************************************/
#define NTask 15
#define NISR 5
#define NQueue 10
#define NSemaphore 10
#define NMutex 10
#define NTimer 2
#define NEventGroup 2
/******************************************************************************
* INCLUDE_MEMMANG_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* This controls if malloc and free calls should be traced. Set this to zero to
* exclude malloc/free calls, or one (1) to include such events in the trace.
*
* Default value is 1.
*****************************************************************************/
#define INCLUDE_MEMMANG_EVENTS 1
/******************************************************************************
* INCLUDE_USER_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0) the code for creating User Events is excluded to
* reduce code size. User Events are application-generated events, like
* "printf" but for the trace log instead of console output. User Events are
* much faster than a printf and can therefore be used in timing critical code.
* See vTraceUserEvent() and vTracePrintF() in trcUser.h
*
* Default value is 1.
*
* Note that User Events are only displayed in Professional Edition.
*****************************************************************************/
#define INCLUDE_USER_EVENTS 1
/*****************************************************************************
* INCLUDE_ISR_TRACING
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the code for recording Interrupt Service Routines is
* excluded to reduce code size.
*
* Default value is 1.
*
* Note, if the kernel has no central interrupt dispatcher, recording ISRs
* require that you insert calls to vTraceStoreISRBegin and vTraceStoreISREnd
* in your interrupt handlers.
*****************************************************************************/
#define INCLUDE_ISR_TRACING 1
/*****************************************************************************
* INCLUDE_READY_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If one (1), events are recorded when tasks enter scheduling state "ready".
* This uses a lot of space in the event buffer, so excluding "ready events"
* will allow for longer traces. Including ready events however allows for
* showing the initial pending time before tasks enter the execution state, and
* for presenting accurate response times.
*
* Default value is 1.
*****************************************************************************/
#define INCLUDE_READY_EVENTS 1
/*****************************************************************************
* INCLUDE_NEW_TIME_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (1), events will be generated whenever the OS clock is
* increased.
*
* Default value is 0.
*****************************************************************************/
#define INCLUDE_NEW_TIME_EVENTS 0
/******************************************************************************
* INCLUDE_FLOAT_SUPPORT
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), all references to floating point values are removed,
* in case floating point values are not supported by the platform used.
* Floating point values are only used in vTracePrintF and its subroutines, to
* store float (%f) or double (%lf) arguments.
*
* vTracePrintF can be used with integer and string arguments in either case.
*
* Default value is 1.
*****************************************************************************/
#define INCLUDE_FLOAT_SUPPORT 1
/******************************************************************************
* INCLUDE_OBJECT_DELETE
*
* Macro which should be defined as either zero (0) or one (1).
*
* This must be enabled (1) if tasks, queues or other
* traced kernel objects are deleted at runtime. If no deletes are made, this
* can be set to 0 in order to exclude the delete-handling code.
*
* Default value is 1.
*****************************************************************************/
#define INCLUDE_OBJECT_DELETE 1
/*******************************************************************************
* SYMBOL_TABLE_SIZE
*
* Macro which should be defined as an integer value.
*
* This defines the capacity of the symbol table, in bytes. This symbol table
* stores User Events labels and names of deleted tasks, queues, or other kernel
* objects. If you don't use User Events or delete any kernel
* objects you set this to a very low value. The minimum recommended value is 4.
* A size of zero (0) is not allowed since a zero-sized array may result in a
* 32-bit pointer, i.e., using 4 bytes rather than 0.
*
* Default value is 800.
******************************************************************************/
#define SYMBOL_TABLE_SIZE 800
#if (SYMBOL_TABLE_SIZE == 0)
#error "SYMBOL_TABLE_SIZE may not be zero!"
#endif
/******************************************************************************
* NameLenTask, NameLenQueue, ...
*
* Macros that specify the maximum lengths (number of characters) for names of
* kernel objects, such as tasks and queues. If longer names are used, they will
* be truncated when stored in the recorder.
*****************************************************************************/
#define NameLenTask 15
#define NameLenISR 15
#define NameLenQueue 15
#define NameLenSemaphore 15
#define NameLenMutex 15
#define NameLenTimer 15
#define NameLenEventGroup 15
/******************************************************************************
* TRACE_DATA_ALLOCATION
*
* This defines how to allocate the recorder data structure, i.e., using a
* static declaration or using a dynamic allocation in runtime (malloc).
*
* Should be one of these two options:
* - TRACE_DATA_ALLOCATION_STATIC (default)
* - TRACE_DATA_ALLOCATION_DYNAMIC
*
* Using static allocation has the benefits of compile-time errors if the buffer
* is too large (too large constants in trcConfig.h) and no need to call the
* initialization routine (xTraceInitTraceData).
*
* Using dynamic allocation may give more flexibility in some cases.
*****************************************************************************/
#define TRACE_DATA_ALLOCATION TRACE_DATA_ALLOCATION_STATIC
/******************************************************************************
*** ADVANCED SETTINGS ********************************************************
******************************************************************************
* The remaining settings are not necessary to modify but allows for optimizing
* the recorder setup for your specific needs, e.g., to exclude events that you
* are not interested in, in order to get longer traces.
*****************************************************************************/
/******************************************************************************
* HEAP_SIZE_BELOW_16M
*
* An integer constant that can be used to reduce the buffer usage of memory
* allocation events (malloc/free). This value should be 1 if the heap size is
* below 16 MB (2^24 byte), and you can live with reported addresses showing the
* lower 24 bits only. If 0, you get the full 32-bit addresses.
*
* Default value is 0.
******************************************************************************/
#define HEAP_SIZE_BELOW_16M 0
/******************************************************************************
* USE_LINKER_PRAGMA
*
* Macro which should be defined as an integer value, default is 0.
*
* If this is 1, the header file "recorderdata_linker_pragma.h" is included just
* before the declaration of RecorderData (in trcBase.c), i.e., the trace data
* structure. This allows the user to specify a pragma with linker options.
*
* Example (for IAR Embedded Workbench and NXP LPC17xx):
* #pragma location="AHB_RAM_MEMORY"
*
* This example instructs the IAR linker to place RecorderData in another RAM
* bank, the AHB RAM. This can also be used for other compilers with a similar
* pragmas for linker options.
*
* Note that this only applies if using static allocation, see below.
******************************************************************************/
#define USE_LINKER_PRAGMA 0
/******************************************************************************
* USE_IMPLICIT_IFE_RULES
*
* Macro which should be defined as either zero (0) or one (1).
* Default is 1.
*
* Tracealyzer groups the events into actor instances, based on context-switches
* and a definition of "Instance Finish Events", or IFEs. These are kernel calls
* considered to be the last event in a task instance. Some kernel calls are
* considered IFEs by default (e.g., delay functions), but it is also possible
* to specify this individually for each task (see vTraceTaskInstanceFinish).
*
* If USE_IMPLICIT_IFE_RULES is one (1), the default IFEs will be enabled, which
* gives a "typical" grouping of events into instances. You can combine this
* with calls to vTraceTaskInstanceFinish for specific tasks.
*
* If USE_IMPLICIT_IFE_RULES is zero (0), the implicit IFEs are disabled and all
* events withing each task is then shown as a single instance, unless you call
* vTraceTaskInstanceFinish() at suitable locations to mark the IFEs.
*****************************************************************************/
#define USE_IMPLICIT_IFE_RULES 1
/******************************************************************************
* USE_16BIT_OBJECT_HANDLES
*
* Macro which should be defined as either zero (0) or one (1).
*
* If set to 0 (zero), the recorder uses 8-bit handles to identify kernel
* objects such as tasks and queues. This limits the supported number of
* concurrently active objects to 255 of each type (object class).
*
* If set to 1 (one), the recorder uses 16-bit handles to identify kernel
* objects such as tasks and queues. This limits the supported number of
* concurrent objects to 65535 of each type (object class). However, since the
* object property table is limited to 64 KB, the practical limit is about
* 3000 objects in total.
*
* Default is 0.
*
* NOTE: An object with handle above 255 will use an extra 4-byte record in
* the event buffer whenever referenced. Moreover, some internal tables in the
* recorder gets larger when using 16-bit handles. The additional RAM usage is
* 5-10 byte plus 1 byte per kernel object i.e., task, queue, mutex, etc.
*****************************************************************************/
#define USE_16BIT_OBJECT_HANDLES 0
/******************************************************************************
* USE_TRACE_ASSERT
*
* Macro which should be defined as either zero (0) or one (1).
* Default is 1.
*
* If this is one (1), the TRACE_ASSERT macro will verify that a condition is
* true. If the condition is false, vTraceError() will be called.
* This is used on several places in the recorder code for sanity checks on
* parameters. Can be switched off to reduce CPU usage of the tracing.
*****************************************************************************/
#define USE_TRACE_ASSERT 1
/*******************************************************************************
* USE_SEPARATE_USER_EVENT_BUFFER
*
* Macro which should be defined as an integer value.
* Default is zero (0).
*
* This enables and disables the use of the separate user event buffer. Using
* this separate buffer has the benefit of not overwriting the user events with
* kernel events (usually generated at a much higher rate), i.e., when using
* ring-buffer mode.
*
* Note: When using the separate user event buffer, you may get an artificial
* task instance named "Unknown actor". This is added as a placeholder when the
* user event history is longer than the task scheduling history.
******************************************************************************/
#define USE_SEPARATE_USER_EVENT_BUFFER 0
/*******************************************************************************
* USER_EVENT_BUFFER_SIZE
*
* Macro which should be defined as an integer value.
*
* This defines the capacity of the user event buffer, in number of slots.
* A single user event can use between 1 and X slots, depending on the data.
*
* Only in use if USE_SEPARATE_USER_EVENT_BUFFER is set to 1.
******************************************************************************/
#define USER_EVENT_BUFFER_SIZE 10
/*******************************************************************************
* USER_EVENT_CHANNELS
*
* Macro which should be defined as an integer value.
*
* This defines the number of allowed user event channels.
*
* Only in use if USE_SEPARATE_USER_EVENT_BUFFER is set to 1.
******************************************************************************/
#define CHANNEL_FORMAT_PAIRS 32
#endif

@ -1,550 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcBase.h
*
* Core functionality of the Tracealyzer recorder library.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#ifndef TRCBASE_H
#define TRCBASE_H
#define TRACE_MINOR_VERSION 4
#define TRACE_STORE_MODE_STOP_WHEN_FULL 1
#define TRACE_STORE_MODE_RING_BUFFER 2
#define TRACE_DATA_ALLOCATION_STATIC 1
#define TRACE_DATA_ALLOCATION_DYNAMIC 2
#define TRACE_DATA_ALLOCATION_CUSTOM 3
#include "trcKernelPort.h"
#if (USE_TRACEALYZER_RECORDER == 1)
#include <stdio.h>
#include <string.h>
#ifndef USE_SEPARATE_USER_EVENT_BUFFER
#define USE_SEPARATE_USER_EVENT_BUFFER 0
#endif
#ifndef TRACE_SR_ALLOC_CRITICAL_SECTION
#define TRACE_SR_ALLOC_CRITICAL_SECTION()
#endif
/* Max number of event codes supported */
#define NEventCodes 0x100
/* Keeps track of the recorder's critical sections */
extern volatile int recorder_busy;
/* Our local critical sections for the recorder */
#define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}
#define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}
/* 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. */
extern uint8_t excludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1];
/* Structure to handle the exclude flags for all event codes */
extern uint8_t excludedEventCodes[NEventCodes / 8 + 1];
/******************************************************************************
* ObjectHandleStack
* This data-structure is used to provide a mechanism for 1-byte trace object
* handles. This way, only 1 byte is necessary instead of 4 bytes (a pointer)
* when storing a reference to an object. This allows for up to 255 objects of
* each object class active at any given moment. There can be more "historic"
* objects, that have been deleted - that number is only limited by the size of
* the symbol table.
* Note that handle zero (0) is not used, it is a code for an invalid handle.
*
* This data structure keeps track of the FREE handles, not the handles in use.
* This data structure contains one stack per object class. When a handle is
* allocated to an object, the next free handle is popped from the stack. When
* a handle is released (on object delete), it is pushed back on the stack.
* Note that there is no initialization code that pushed the free handles
* initially, that is not necessary due to the following optimization:
*
* The stack of handles (objectHandles) is initially all zeros. Since zero
* is not a valid handle, that is a signal of additional handles needed.
* If a zero is received when popping a new handle, it is replaced by the
* index of the popped handle instead.
*
*****************************************************************************/
typedef struct
{
/* For each object class, the index of the next handle to allocate */
uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];
/* The lowest index of this class (constant) */
uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];
/* The highest index of this class (constant) */
uint16_t highestIndexOfClass[ TRACE_NCLASSES ];
/* The highest use count for this class (for statistics) */
uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];
/* The free object handles - a set of stacks within this array */
objectHandleType objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];
} objectHandleStackType;
extern objectHandleStackType objectHandleStacks;
/******************************************************************************
* Object Property Table
* The Object Table contains name and other properties of the objects (tasks,
* queues, mutexes, etc). The below data structures defines the properties of
* each object class and are used to cast the byte buffer into a cleaner format.
*
* The values in the object table are continuously overwritten and always
* represent the current state. If a property is changed during runtime, the OLD
* value should be stored in the trace buffer, not the new value (since the new
* value is found in the Object Property Table).
* For close events this mechanism is the old names are stored in the symbol
* table), for "priority set" (the old priority is stored in the event data)
* and for "isActive", where the value decides if the task switch event type
* should be "new" or "resume".
******************************************************************************/
typedef struct
{
/* = NCLASSES */
uint32_t NumberOfObjectClasses;
uint32_t ObjectPropertyTableSizeInBytes;
/* This is used to calculate the index in the dynamic object table
(handle - 1 - nofStaticObjects = index)*/
#if (USE_16BIT_OBJECT_HANDLES == 1)
objectHandleType NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];
#else
objectHandleType NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];
#endif
/* Allocation size rounded up to the closest multiple of 4 */
uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];
uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];
/* Allocation size rounded up to the closest multiple of 2 */
uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];
/* The actual handles issued, should be Initiated to all zeros */
uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];
} ObjectPropertyTableType;
/* Symbol table data structure */
typedef struct
{
/* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */
uint32_t symTableSize;
/* Entry 0 is reserved. Any reference to entry 0 implies NULL*/
uint32_t nextFreeSymbolIndex;
/* Size rounded up to closest multiple of 4, to avoid alignment issues*/
uint8_t symbytes[4*((SYMBOL_TABLE_SIZE+3)/4)];
/* Used for lookups - Up to 64 linked lists within the symbol table
connecting all entries with the same 6 bit checksum.
This field holds the current list heads. Should be initiated to zeros */
uint16_t latestEntryOfChecksum[64];
} symbolTableType;
/*******************************************************************************
* The data structures of the different events, all 4 bytes long
******************************************************************************/
typedef struct
{
uint8_t type;
uint8_t objHandle;
uint16_t dts; /* differential timestamp - time since last event */
} TSEvent, TREvent;
typedef struct
{
uint8_t type;
uint8_t dummy;
uint16_t dts; /* differential timestamp - time since last event */
} LPEvent;
typedef struct
{
uint8_t type;
uint8_t objHandle;
uint16_t dts; /* differential timestamp - time since last event */
} KernelCall;
typedef struct
{
uint8_t type;
uint8_t objHandle;
uint8_t param;
uint8_t dts; /* differential timestamp - time since last event */
} KernelCallWithParamAndHandle;
typedef struct
{
uint8_t type;
uint8_t dts; /* differential timestamp - time since last event */
uint16_t param;
} KernelCallWithParam16;
typedef struct
{
uint8_t type;
uint8_t objHandle; /* the handle of the closed object */
uint16_t symbolIndex; /* the name of the closed object */
} ObjCloseNameEvent;
typedef struct
{
uint8_t type;
uint8_t arg1;
uint8_t arg2;
uint8_t arg3;
} ObjClosePropEvent;
typedef struct
{
uint8_t type;
uint8_t unused1;
uint8_t unused2;
uint8_t dts;
} TaskInstanceStatusEvent;
typedef struct
{
uint8_t type;
uint8_t dts;
uint16_t payload; /* the name of the user event */
} UserEvent;
typedef struct
{
uint8_t type;
/* 8 bits extra for storing DTS, if it does not fit in ordinary event
(this one is always MSB if used) */
uint8_t xts_8;
/* 16 bits extra for storing DTS, if it does not fit in ordinary event. */
uint16_t xts_16;
} XTSEvent;
typedef struct
{
uint8_t type;
uint8_t xps_8;
uint16_t xps_16;
} XPSEvent;
typedef struct{
uint8_t type;
uint8_t dts;
uint16_t size;
} MemEventSize;
typedef struct{
uint8_t type;
uint8_t addr_high;
uint16_t addr_low;
} MemEventAddr;
/*******************************************************************************
* The separate user event buffer structure. Can be enabled in trcConfig.h.
******************************************************************************/
#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)
typedef struct
{
traceLabel name;
traceLabel defaultFormat;
} ChannelFormatPair;
typedef struct
{
uint16_t bufferID;
uint16_t version;
uint32_t wraparoundCounter;
uint32_t numberOfSlots;
uint32_t nextSlotToWrite;
uint8_t numberOfChannels;
uint8_t padding1;
uint8_t padding2;
uint8_t padding3;
ChannelFormatPair channels[CHANNEL_FORMAT_PAIRS+1];
uint8_t channelBuffer[(USER_EVENT_BUFFER_SIZE + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */
uint8_t dataBuffer[USER_EVENT_BUFFER_SIZE * 4]; /* 4 bytes per slot */
} UserEventBuffer;
#endif
/*******************************************************************************
* The main data structure, read by Tracealyzer from the RAM dump
******************************************************************************/
typedef struct
{
uint8_t startmarker0;
uint8_t startmarker1;
uint8_t startmarker2;
uint8_t startmarker3;
uint8_t startmarker4;
uint8_t startmarker5;
uint8_t startmarker6;
uint8_t startmarker7;
uint8_t startmarker8;
uint8_t startmarker9;
uint8_t startmarker10;
uint8_t startmarker11;
/* Used to determine Kernel and Endianess */
uint16_t version;
/* Currently 3 */
uint8_t minor_version;
/* This should be 0 if lower IRQ priority values implies higher priority
levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,
if higher IRQ priority values means higher priority, this should be 1. */
uint8_t irq_priority_order;
/* sizeof(RecorderDataType) - just for control */
uint32_t filesize;
/* Current number of events recorded */
uint32_t numEvents;
/* The buffer size, in number of event records */
uint32_t maxEvents;
/* The event buffer index, where to write the next event */
uint32_t nextFreeIndex;
/* 1 if the buffer is full, 0 otherwise */
uint32_t bufferIsFull;
/* The frequency of the clock/timer/counter used as time base */
uint32_t frequency;
/* The absolute timestamp of the last stored event, in the native
timebase, modulo frequency! */
uint32_t absTimeLastEvent;
/* The number of seconds in total - lasts for 136 years */
uint32_t absTimeLastEventSecond;
/* 1 if the recorder has been started, 0 if not yet started or stopped.
This is a 32 bit variable due to alignment issues. */
uint32_t recorderActive;
/* Not used, remains for compatibility and future use */
uint8_t notused[28];
/* The amount of heap memory remaining at the last malloc or free event */
uint32_t heapMemUsage;
/* 0xF0F0F0F0 - for control only */
int32_t debugMarker0;
/* Set to value of USE_16BIT_OBJECT_HANDLES */
uint32_t isUsing16bitHandles;
/* The Object Property Table holds information about currently active
tasks, queues, and other recorded objects. This is updated on each
create call and includes object name and other properties. */
ObjectPropertyTableType ObjectPropertyTable;
/* 0xF1F1F1F1 - for control only */
int32_t debugMarker1;
/* The Symbol Table stores strings for User Events and is also used to
store names of deleted objects, which still may be in the trace but no
longer are available. */
symbolTableType SymbolTable;
/* For inclusion of float support, and for endian detection of floats.
The value should be (float)1 or (uint32_t)0 */
#if (INCLUDE_FLOAT_SUPPORT == 1)
float exampleFloatEncoding;
#else
uint32_t exampleFloatEncoding;
#endif
/* This is non-zero if an internal error occurred in the recorder, e.g., if
one of the Nxxx constants was too small. The systemInfo string will then
contain an error message that is displayed when attempting to view the
trace file. */
uint32_t internalErrorOccured;
/* 0xF2F2F2F2 - for control only */
int32_t debugMarker2;
/* Error messages from the recorder. */
char systemInfo[80];
/* 0xF3F3F3F3 - for control only */
int32_t debugMarker3;
/* The event data, in 4-byte records */
uint8_t eventData[ EVENT_BUFFER_SIZE * 4 ];
#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)
UserEventBuffer userEventBuffer;
#endif
/* This should always be 0 */
uint32_t endOfSecondaryBlocks;
uint8_t endmarker0;
uint8_t endmarker1;
uint8_t endmarker2;
uint8_t endmarker3;
uint8_t endmarker4;
uint8_t endmarker5;
uint8_t endmarker6;
uint8_t endmarker7;
uint8_t endmarker8;
uint8_t endmarker9;
uint8_t endmarker10;
uint8_t endmarker11;
} RecorderDataType;
extern RecorderDataType* RecorderDataPtr;
/* Internal functions */
uint16_t prvTraceGetDTS(uint16_t param_maxDTS);
void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength);
traceLabel prvTraceCreateSymbolTableEntry(const char* name,
uint8_t crc6,
uint8_t len,
traceLabel channel);
traceLabel prvTraceLookupSymbolTableEntry(const char* name,
uint8_t crc6,
uint8_t len,
traceLabel channel);
traceLabel prvTraceOpenSymbol(const char* name, traceLabel userEventChannel);
void prvTraceUpdateCounters(void);
void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nEntries);
objectHandleType xTraceGetObjectHandle(traceObjectClass objectclass);
void vTraceFreeObjectHandle(traceObjectClass objectclass,
objectHandleType handle);
void vTraceSetObjectName(traceObjectClass objectclass,
objectHandleType handle,
const char* name);
void* xTraceNextFreeEventBufferSlot(void);
#if (USE_16BIT_OBJECT_HANDLES == 1)
unsigned char prvTraceGet8BitHandle(objectHandleType handle);
#else
#define prvTraceGet8BitHandle(x) ((unsigned char)x)
#endif
uint16_t uiIndexOfObject(objectHandleType objecthandle,
uint8_t objectclass);
/*******************************************************************************
* vTraceError
*
* Called by various parts in the recorder. Stops the recorder and stores a
* pointer to an error message, which is printed by the monitor task.
******************************************************************************/
void vTraceError(const char* msg);
/*******************************************************************************
* prvTraceInitTraceData
*
* Allocates and initializes the recorder data structure, based on the constants
* in trcConfig.h. This allows for allocating the data on the heap, instead of
* using a static declaration.
******************************************************************************/
void prvTraceInitTraceData(void);
/* Internal macros */
#define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \
(const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \
[uiIndexOfObject(objecthandle, objectclass)])
#define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \
RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]
#define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \
RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \
+ RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]
#define TRACE_SET_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] |= (1 << ((bitIndex) & 7))
#define TRACE_CLEAR_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] &= ~(1 << ((bitIndex) & 7))
#define TRACE_GET_FLAG_ISEXCLUDED(flags, bitIndex) (flags[(bitIndex) >> 3] & (1 << ((bitIndex) & 7)))
#define TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_SET_FLAG_ISEXCLUDED(excludedEventCodes, eventCode)
#define TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_CLEAR_FLAG_ISEXCLUDED(excludedEventCodes, eventCode)
#define TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_GET_FLAG_ISEXCLUDED(excludedEventCodes, eventCode)
/* DEBUG ASSERTS */
#if defined USE_TRACE_ASSERT && USE_TRACE_ASSERT != 0
#define TRACE_ASSERT(eval, msg, defRetVal) \
if (!(eval)) \
{ \
vTraceError("TRACE_ASSERT: " msg); \
return defRetVal; \
}
#else
#define TRACE_ASSERT(eval, msg, defRetVal)
#endif
#endif
#endif

@ -1,120 +1,59 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcHardwarePort.h
*
* Contains together with trcHardwarePort.c all hardware portability issues of
* the trace recorder library.
* The hardware abstraction layer for the trace recorder.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcPort.c and trcPort.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRCPORT_H
#define TRCPORT_H
#include <stdint.h>
#ifndef TRC_HARDWARE_PORT_H
#define TRC_HARDWARE_PORT_H
/* If Win32 port */
#ifdef WIN32
#include "trcPortDefines.h"
/* Standard includes. */
#include <stdio.h>
#include <windows.h>
#include <direct.h>
/*******************************************************************************
* The Win32 port by default saves the trace to file and then kills the
* program when the recorder is stopped, to facilitate quick, simple tests
* of the recorder.
******************************************************************************/
#define WIN32_PORT_SAVE_WHEN_STOPPED 1
#define WIN32_PORT_EXIT_WHEN_STOPPED 1
#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NOT_SET)
#error "TRC_CFG_HARDWARE_PORT not selected - see trcConfig.h"
#endif
#define DIRECTION_INCREMENTING 1
#define DIRECTION_DECREMENTING 2
/******************************************************************************
* Supported ports
*
* PORT_HWIndependent
* A hardware independent fallback option for event timestamping. Provides low
* resolution timestamps based on the OS tick.
* This may be used on the Win32 port, but may also be used on embedded hardware
* platforms. All time durations will be truncated to the OS tick frequency,
* typically 1 KHz. This means that a task or ISR that executes in less than
* 1 ms get an execution time of zero.
*
* PORT_APPLICATION_DEFINED
* Allows for defining the port macros in other source code files.
*
* PORT_Win32
* "Accurate" timestamping based on the Windows performance counter for Win32
* builds. Note that this gives the host machine time, not the kernel time.
*
* Hardware specific ports
* To get accurate timestamping, a hardware timer is necessary. Below are the
* available ports. Some of these are "unofficial", meaning that
* they have not yet been verified by Percepio but have been contributed by
* external developers. They should work, otherwise let us know by emailing
* support@percepio.com. Some work on any OS platform, while other are specific
* to a certain operating system.
*****************************************************************************/
/****** Port Name ********************** Code ***** Official ** OS Platform *********/
#define PORT_APPLICATION_DEFINED -2 /* - - */
#define PORT_NOT_SET -1 /* - - */
#define PORT_HWIndependent 0 /* Yes Any */
#define PORT_Win32 1 /* Yes FreeRTOS on Win32 */
#define PORT_Atmel_AT91SAM7 2 /* No Any */
#define PORT_Atmel_UC3A0 3 /* No Any */
#define PORT_ARM_CortexM 4 /* Yes Any */
#define PORT_Renesas_RX600 5 /* Yes Any */
#define PORT_Microchip_dsPIC_AND_PIC24 6 /* Yes Any */
#define PORT_TEXAS_INSTRUMENTS_TMS570 7 /* No Any */
#define PORT_TEXAS_INSTRUMENTS_MSP430 8 /* No Any */
#define PORT_MICROCHIP_PIC32MX 9 /* Yes Any */
#define PORT_XILINX_PPC405 10 /* No FreeRTOS */
#define PORT_XILINX_PPC440 11 /* No FreeRTOS */
#define PORT_XILINX_MICROBLAZE 12 /* No Any */
#define PORT_NXP_LPC210X 13 /* No Any */
#define PORT_MICROCHIP_PIC32MZ 14 /* Yes Any */
#define PORT_ARM_CORTEX_A9 15 /* No Any */
#define PORT_ARM_CORTEX_M0 16 /* Yes Any */
#include "trcConfig.h"
/*******************************************************************************
* IRQ_PRIORITY_ORDER
* TRC_IRQ_PRIORITY_ORDER
*
* Macro which should be defined as an integer of 0 or 1.
*
@ -130,235 +69,265 @@
*
* HWTC Macros
*
* These four HWTC macros provides a hardware isolation layer representing a
* generic hardware timer/counter used for driving the operating system tick,
* such as the SysTick feature of ARM Cortex M3/M4, or the PIT of the Atmel
* AT91SAM7X.
* These macros provides a hardware isolation layer representing the
* hardware timer/counter used for the event timestamping.
*
* TRC_HWTC_COUNT: How to read the current value of the timer/counter.
*
* TRC_HWTC_TYPE: Tells the type of timer/counter used for TRC_HWTC_COUNT:
*
* HWTC_COUNT: The current value of the counter. This is expected to be reset
* a each tick interrupt. Thus, when the tick handler starts, the counter has
* already wrapped.
* - TRC_FREE_RUNNING_32BIT_INCR:
* Free-running 32-bit timer/counter, counting upwards from 0.
*
* HWTC_COUNT_DIRECTION: Should be one of:
* - DIRECTION_INCREMENTING - for hardware timer/counters of incrementing type
* such as the PIT on Atmel AT91SAM7X.
* When the counter value reach HWTC_PERIOD, it is reset to zero and the
* interrupt is signaled.
* - DIRECTION_DECREMENTING - for hardware timer/counters of decrementing type
* such as the SysTick on ARM Cortex M3/M4 chips.
* When the counter value reach 0, it is reset to HWTC_PERIOD and the
* interrupt is signaled.
* - TRC_FREE_RUNNING_32BIT_DECR
* Free-running 32-bit timer/counter, counting downwards from 0xFFFFFFFF.
*
* HWTC_PERIOD: The number of increments or decrements of HWTC_COUNT between
* two OS tick interrupts. This should preferably be mapped to the reload
* register of the hardware timer, to make it more portable between chips in the
* same family. The macro should in most cases be (reload register + 1).
* For FreeRTOS, this can in most cases be defined as
* #define HWTC_PERIOD (configCPU_CLOCK_HZ / configTICK_RATE_HZ)
* - TRC_OS_TIMER_INCR
* Periodic timer that drives the OS tick interrupt, counting upwards
* from 0 until (TRC_HWTC_PERIOD-1).
*
* HWTC_DIVISOR: If the timer frequency is very high, like on the Cortex M chips
* (where the SysTick runs at the core clock frequency), the "differential
* timestamping" used in the recorder will more frequently insert extra XTS
* events to store the timestamps, which increases the event buffer usage.
* In such cases, to reduce the number of XTS events and thereby get longer
* traces, you use HWTC_DIVISOR to scale down the timestamps and frequency.
* Assuming a OS tick rate of 1 KHz, it is suggested to keep the effective timer
* frequency below 65 MHz to avoid an excessive amount of XTS events. Thus, a
* Cortex M chip running at 72 MHZ should use a HWTC_DIVISOR of 2, while a
* faster chip require a higher HWTC_DIVISOR value.
* - TRC_OS_TIMER_DECR
* Periodic timer that drives the OS tick interrupt, counting downwards
* from TRC_HWTC_PERIOD-1 until 0.
*
* The HWTC macros and vTracePortGetTimeStamp is the main porting issue
* or the trace recorder library. Typically you should not need to change
* the code of vTracePortGetTimeStamp if using the HWTC macros.
* - TRC_CUSTOM_TIMER_INCR
* A custom timer or counter independent of the OS tick, counting
* downwards from TRC_HWTC_PERIOD-1 until 0. (Currently only supported
* in streaming mode).
*
* - TRC_CUSTOM_TIMER_DECR
* A custom timer independent of the OS tick, counting downwards
* from TRC_HWTC_PERIOD-1 until 0. (Currently only supported
* in streaming mode).
*
* TRC_HWTC_PERIOD: The number of HWTC_COUNT ticks until the timer wraps
* around. If using TRC_FREE_RUNNING_32BIT_INCR/DECR, this should be 0.
*
* TRC_HWTC_FREQ_HZ: The clock rate of the TRC_HWTC_COUNT counter in Hz. If using
* TRC_OS_TIMER_INCR/DECR, this is should be TRC_HWTC_PERIOD * TRACE_TICK_RATE_HZ.
* If using a free-running timer, this is often TRACE_CPU_CLOCK_HZ (if running at
* the core clock rate). If using TRC_CUSTOM_TIMER_INCR/DECR, this should match
* the clock rate of your custom timer (i.e., TRC_HWTC_COUNT). If the default value
* of TRC_HWTC_FREQ_HZ is incorrect for your setup, you can override it by calling
* vTraceSetFrequency before calling vTraceEnable.
*
* TRC_HWTC_DIVISOR (used in snapshot mode only):
* In snapshot mode, the timestamp resolution is TRC_HWTC_FREQ_HZ/TRC_HWTC_DIVISOR.
* If the timer frequency is very high (hundreds of MHz), we recommend increasing
* the TRC_HWTC_DIVISOR prescaler, to reduce the bandwidth needed to store
* timestamps. This since extra "XTS" events are inserted if the time since the
* previous event exceeds a certain limit (255 or 65535 depending on event type).
* It is advised to keep the time between most events below 65535 native ticks
* (after division by TRC_HWTC_DIVISOR) to avoid frequent XTS events.
******************************************************************************/
#if (SELECTED_PORT == PORT_Win32)
// This can be used as a template for any free-running 32-bit counter
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (ulGetRunTimeCounterValue())
#define HWTC_PERIOD 0
#define HWTC_DIVISOR 1
// Please update according to your system...
#define IRQ_PRIORITY_ORDER 1
#elif (SELECTED_PORT == PORT_HWIndependent)
// OS Tick only (typically 1 ms resolution)
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT 0
#define HWTC_PERIOD 1
#define HWTC_DIVISOR 1
// Please update according to your system...
#define IRQ_PRIORITY_ORDER NOT_SET
#elif (SELECTED_PORT == PORT_ARM_CortexM)
void prvTraceInitCortexM(void);
#define REG_DEMCR (*(volatile unsigned int*)0xE000EDFC)
#define REG_DWT_CTRL (*(volatile unsigned int*)0xE0001000)
#define REG_DWT_CYCCNT (*(volatile unsigned int*)0xE0001004)
#define REG_DWT_EXCCNT (*(volatile unsigned int*)0xE000100C)
/* Bit mask for TRCENA bit in DEMCR - Global enable for DWT and ITM */
#define DEMCR_TRCENA (1 << 24)
/* Bit mask for NOPRFCNT bit in DWT_CTRL. If 1, DWT_EXCCNT is not supported */
#define DWT_CTRL_NOPRFCNT (1 << 24)
/* Bit mask for NOCYCCNT bit in DWT_CTRL. If 1, DWT_CYCCNT is not supported */
#define DWT_CTRL_NOCYCCNT (1 << 25)
/* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_EXCCNT */
#define DWT_CTRL_EXCEVTENA (1 << 18)
/* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_CYCCNT */
#define DWT_CTRL_CYCCNTENA (1)
#define PORT_SPECIFIC_INIT() prvTraceInitCortexM()
extern uint32_t DWT_CYCLES_ADDED;
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (REG_DWT_CYCCNT + DWT_CYCLES_ADDED)
#define HWTC_PERIOD 0
#define HWTC_DIVISOR 4
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NOT_SET)
#error "TRC_CFG_HARDWARE_PORT not selected - see trcConfig.h"
#endif
#elif (SELECTED_PORT == PORT_ARM_CORTEX_M0)
#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
#define HWTC_COUNT (*((uint32_t*)0xE000E018))
#define HWTC_PERIOD ((*(uint32_t*)0xE000E014) + 1)
#define HWTC_DIVISOR 2
#if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Win32)
/* This can be used as a template for any free-running 32-bit counter */
#define TRC_HWTC_TYPE TRC_FREE_RUNNING_32BIT_INCR
#define TRC_HWTC_COUNT (ulGetRunTimeCounterValue())
#define TRC_HWTC_PERIOD 0
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ 100000
#define TRC_IRQ_PRIORITY_ORDER 1
#define TRC_PORT_SPECIFIC_INIT()
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_HWIndependent)
/* Timestamping by OS tick only (typically 1 ms resolution) */
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT 0
#define TRC_HWTC_PERIOD 1
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ TRACE_TICK_RATE_HZ
/* Set the meaning of IRQ priorities in ISR tracing - see above */
#define TRC_IRQ_PRIORITY_ORDER NOT_SET
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)
#ifndef __CORTEX_M
#error "Can't find the CMSIS API. Please include your processor's header file in trcConfig.h"
#endif
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
/**************************************************************************
* For Cortex-M3, M4 and M7, the DWT cycle counter is used for timestamping.
* For Cortex-M0 and M0+, the SysTick timer is used since DWT is not
* available. Systick timestamping can also be forced on Cortex-M3, M4 and
* M7 by defining the preprocessor directive TRC_CFG_ARM_CM_USE_SYSTICK,
* either directly below or in trcConfig.h.
*
* #define TRC_CFG_ARM_CM_USE_SYSTICK
**************************************************************************/
#if ((__CORTEX_M >= 0x03) && (! defined TRC_CFG_ARM_CM_USE_SYSTICK))
void prvTraceInitCortexM(void);
#define TRC_REG_DEMCR (*(volatile uint32_t*)0xE000EDFC)
#define TRC_REG_DWT_CTRL (*(volatile uint32_t*)0xE0001000)
#define TRC_REG_DWT_CYCCNT (*(volatile uint32_t*)0xE0001004)
#define TRC_REG_DWT_EXCCNT (*(volatile uint32_t*)0xE000100C)
#define TRC_REG_ITM_LOCKACCESS (*(volatile uint32_t*)0xE0001FB0)
#define TRC_ITM_LOCKACCESS_UNLOCK (0xC5ACCE55)
/* Bit mask for TRCENA bit in DEMCR - Global enable for DWT and ITM */
#define TRC_DEMCR_TRCENA (1 << 24)
/* Bit mask for NOPRFCNT bit in DWT_CTRL. If 1, DWT_EXCCNT is not supported */
#define TRC_DWT_CTRL_NOPRFCNT (1 << 24)
/* Bit mask for NOCYCCNT bit in DWT_CTRL. If 1, DWT_CYCCNT is not supported */
#define TRC_DWT_CTRL_NOCYCCNT (1 << 25)
/* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_EXCCNT */
#define TRC_DWT_CTRL_EXCEVTENA (1 << 18)
/* Bit mask for EXCEVTENA_ bit in DWT_CTRL. Set to 1 to enable DWT_CYCCNT */
#define TRC_DWT_CTRL_CYCCNTENA (1)
#define TRC_PORT_SPECIFIC_INIT() prvTraceInitCortexM()
#define TRC_HWTC_TYPE TRC_FREE_RUNNING_32BIT_INCR
#define TRC_HWTC_COUNT TRC_REG_DWT_CYCCNT
#define TRC_HWTC_PERIOD 0
#define TRC_HWTC_DIVISOR 4
#define TRC_HWTC_FREQ_HZ TRACE_CPU_CLOCK_HZ
#define TRC_IRQ_PRIORITY_ORDER 0
#else
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
#define TRC_HWTC_COUNT (*((volatile uint32_t*)0xE000E018))
#define TRC_HWTC_PERIOD ((*((volatile uint32_t*)0xE000E014)) + 1)
#define TRC_HWTC_DIVISOR 4
#define TRC_HWTC_FREQ_HZ TRACE_CPU_CLOCK_HZ
#define TRC_IRQ_PRIORITY_ORDER 0
#endif
#elif (SELECTED_PORT == PORT_Renesas_RX600)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Renesas_RX600)
#include "iodefine.h"
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (CMT0.CMCNT)
#define HWTC_PERIOD (CMT0.CMCOR + 1)
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant
#elif ((SELECTED_PORT == PORT_MICROCHIP_PIC32MX) || (SELECTED_PORT == PORT_MICROCHIP_PIC32MZ))
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (TMR1)
#define HWTC_PERIOD (PR1 + 1)
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#elif (SELECTED_PORT == PORT_Microchip_dsPIC_AND_PIC24)
/* For Microchip PIC24 and dsPIC (16 bit) */
/* Note: The trace library is designed for 32-bit MCUs and is slower than
intended on 16-bit MCUs. Storing an event on a PIC24 takes about 70 usec.
In comparison, this is 10-20 times faster on a 32-bit MCU... */
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT (CMT0.CMCNT)
#elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
/* Decreasing counters better for Tickless Idle? */
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
#define TRC_HWTC_COUNT (CMT0.CMCOR - CMT0.CMCNT)
#endif
#define TRC_HWTC_PERIOD (CMT0.CMCOR + 1)
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 1
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32)
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT (TMR1)
#define TRC_HWTC_PERIOD (PR1 + 1)
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48)
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (TMR1)
#define HWTC_PERIOD (PR1+1)
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#define TRC_RTIFRC0 *((uint32_t *)0xFFFFFC10)
#define TRC_RTICOMP0 *((uint32_t *)0xFFFFFC50)
#define TRC_RTIUDCP0 *((uint32_t *)0xFFFFFC54)
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT (TRC_RTIFRC0 - (TRC_RTICOMP0 - TRC_RTIUDCP0))
#define TRC_HWTC_PERIOD (TRC_RTIUDCP0)
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (SELECTED_PORT == PORT_Atmel_AT91SAM7)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Atmel_AT91SAM7)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT ((uint32_t)(AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF))
#define HWTC_PERIOD ((uint32_t)(AT91C_BASE_PITC->PITC_PIMR + 1))
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT ((uint32_t)(AT91C_BASE_PITC->PITC_PIIR & 0xFFFFF))
#define TRC_HWTC_PERIOD ((uint32_t)(AT91C_BASE_PITC->PITC_PIMR + 1))
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 1
#elif (SELECTED_PORT == PORT_Atmel_UC3A0)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_Atmel_UC3A0)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
/* For Atmel AVR32 (AT32UC3A).*/
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO*/
/* For Atmel AVR32 (AT32UC3A) */
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT ((uint32_t)sysreg_read(AVR32_COUNT))
#define HWTC_PERIOD ((uint32_t)(sysreg_read(AVR32_COMPARE) + 1))
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT ((uint32_t)sysreg_read(AVR32_COUNT))
#define TRC_HWTC_PERIOD ((uint32_t)(sysreg_read(AVR32_COMPARE) + 1))
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 1
#elif (SELECTED_PORT == PORT_NXP_LPC210X)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_NXP_LPC210X)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
/* Tested with LPC2106, but should work with most LPC21XX chips. */
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT *((uint32_t *)0xE0004008 )
#define HWTC_PERIOD *((uint32_t *)0xE0004018 )
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT *((uint32_t *)0xE0004008 )
#define TRC_HWTC_PERIOD *((uint32_t *)0xE0004018 )
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_TMS570)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_MSP430)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
/* UNOFFICIAL PORT - NOT YET VERIFIED */
#define TRC_HWTC_TYPE TRC_OS_TIMER_INCR
#define TRC_HWTC_COUNT (TA0R)
#define TRC_HWTC_PERIOD (((uint16_t)TACCR0)+1)
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 1
#define TRC_RTIFRC0 *((uint32_t *)0xFFFFFC10)
#define TRC_RTICOMP0 *((uint32_t *)0xFFFFFC50)
#define TRC_RTIUDCP0 *((uint32_t *)0xFFFFFC54)
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (TRC_RTIFRC0 - (TRC_RTICOMP0 - TRC_RTIUDCP0))
#define HWTC_PERIOD (RTIUDCP0)
#define HWTC_DIVISOR 1
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_PPC405)
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
/* UNOFFICIAL PORT - NOT YET VERIFIED */
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
#define TRC_HWTC_COUNT mfspr(0x3db)
#define TRC_HWTC_PERIOD (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (SELECTED_PORT == PORT_TEXAS_INSTRUMENTS_MSP430)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_PPC440)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
/* UNOFFICIAL PORT */
#define HWTC_COUNT_DIRECTION DIRECTION_INCREMENTING
#define HWTC_COUNT (TA0R)
#define HWTC_PERIOD (((uint16_t)TACCR0)+1)
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant
#elif (SELECTED_PORT == PORT_XILINX_PPC405)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
#define HWTC_COUNT mfspr(0x3db)
#if (defined configCPU_CLOCK_HZ && defined configTICK_RATE_HZ) // Check if FreeRTOS
/* For FreeRTOS only - found no generic OS independent solution for the PPC405 architecture. */
#define HWTC_PERIOD ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) // Same as in port.c for PPC405
#else
/* Not defined for other operating systems yet */
#error HWTC_PERIOD must be defined to give the number of hardware timer ticks per OS tick.
#endif
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#elif (SELECTED_PORT == PORT_XILINX_PPC440)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
/* This should work with most PowerPC chips */
#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
#define HWTC_COUNT mfspr(0x016)
#if (defined configCPU_CLOCK_HZ && defined configTICK_RATE_HZ) // Check if FreeRTOS
/* For FreeRTOS only - found no generic OS independent solution for the PPC440 architecture. */
#define HWTC_PERIOD ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) // Same as in port.c for PPC440
#else
/* Not defined for other operating systems yet */
#error HWTC_PERIOD must be defined to give the number of hardware timer ticks per OS tick.
#endif
#define HWTC_DIVISOR 1
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
#define TRC_HWTC_COUNT mfspr(0x016)
#define TRC_HWTC_PERIOD (TRACE_CPU_CLOCK_HZ / TRACE_TICK_RATE_HZ)
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (SELECTED_PORT == PORT_XILINX_MICROBLAZE)
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_XILINX_MICROBLAZE)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
@ -367,101 +336,128 @@
* If an AXI Timer 0 peripheral is available on your hardware platform, no modifications are required.
*/
#include "xtmrctr_l.h"
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
#define TRC_HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 )
#define TRC_HWTC_PERIOD (XTmrCtr_mGetLoadReg( XPAR_TMRCTR_0_BASEADDR, 0) + 1)
#define TRC_HWTC_DIVISOR 16
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_CORTEX_A9)
/* INPUT YOUR PERIPHERAL BASE ADDRESS HERE */
#define TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS 0xSOMETHING
#define TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET 0x0600
#define TRC_CA9_MPCORE_PRIVCTR_PERIOD_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x00))
#define TRC_CA9_MPCORE_PRIVCTR_COUNTER_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x04))
#define TRC_CA9_MPCORE_PRIVCTR_CONTROL_REG (*(volatile uint32_t*)(TRC_CA9_MPCORE_PERIPHERAL_BASE_ADDRESS + TRC_CA9_MPCORE_PRIVATE_MEMORY_OFFSET + 0x08))
#define TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK 0x0000FF00
#define TRC_CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT 8
#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)
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
#define TRC_HWTC_COUNT TRC_CA9_MPCORE_PRIVCTR_COUNTER_REG
#define TRC_HWTC_PERIOD (TRC_CA9_MPCORE_PRIVCTR_PERIOD_REG + 1)
/****************************************************************************************
NOTE: The private timer ticks with a very high frequency (half the core-clock usually),
depending on the prescaler used. If a low prescaler is used, the number of HW ticks between
the trace events gets large, and thereby inefficient to store (sometimes extra events are
needed). To improve efficiency, you may use the TRC_HWTC_DIVISOR as an additional prescaler.
*****************************************************************************************/
#define TRC_HWTC_DIVISOR 1
#define TRC_HWTC_FREQ_HZ (TRACE_TICK_RATE_HZ * TRC_HWTC_PERIOD)
#define TRC_IRQ_PRIORITY_ORDER 0
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_POWERPC_Z4)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
#define TRC_HWTC_TYPE TRC_OS_TIMER_DECR
//#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
#define TRC_HWTC_COUNT PIT.TIMER[configTICK_PIT_CHANNEL].CVAL.R // must be the PIT channel used for the systick
#define TRC_HWTC_PERIOD ((configPIT_CLOCK_HZ / configTICK_RATE_HZ) - 1U) // TODO FIXME or maybe not -1? what's the right "period" value?
#define TRC_HWTC_FREQ_HZ configPIT_CLOCK_HZ
#define TRC_HWTC_DIVISOR 1
#define TRC_IRQ_PRIORITY_ORDER 1 // higher IRQ priority values are more significant
#elif (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_APPLICATION_DEFINED)
#if !( defined (TRC_HWTC_TYPE) && defined (TRC_HWTC_COUNT) && defined (TRC_HWTC_PERIOD) && defined (TRC_HWTC_FREQ_HZ) && defined (TRC_IRQ_PRIORITY_ORDER) )
#error "The hardware port is not completely defined!"
#endif
#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
#define HWTC_COUNT XTmrCtr_GetTimerCounterReg( XPAR_TMRCTR_0_BASEADDR, 0 )
#define HWTC_PERIOD (XTmrCtr_mGetLoadReg( XPAR_TMRCTR_0_BASEADDR, 0) + 1)
#define HWTC_DIVISOR 16
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#elif (SELECTED_PORT == PORT_ARM_CORTEX_A9)
/* UNOFFICIAL PORT - NOT YET VERIFIED BY PERCEPIO */
#define CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK 0x0000FF00
#define CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT 8
#define CA9_MPCORE_PRIVCTR_PERIOD_REG (*(volatile uint32_t*)(0xF8F00600 + 0))
#define CA9_MPCORE_PRIVCTR_COUNTER_REG (*(volatile uint32_t*)(0xF8F00600 + 4))
#define CA9_MPCORE_PRIVCTR_CONTROL_REG (*(volatile uint32_t*)(0xF8F00600 + 8))
#define CA9_MPCORE_PRIVCTR_PRESCALER (((CA9_MPCORE_PRIVCTR_CONTROL_REG & CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_MASK) >> CA9_MPCORE_PRIVCTR_CONTROL_PRESCALER_SHIFT) + 1)
#elif (TRC_CFG_HARDWARE_PORT != TRC_HARDWARE_PORT_NOT_SET)
#error "TRC_CFG_HARDWARE_PORT had unsupported value!"
#define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET
#define HWTC_COUNT_DIRECTION DIRECTION_DECREMENTING
#define HWTC_COUNT CA9_MPCORE_PRIVCTR_COUNTER_REG
#define HWTC_PERIOD ((CA9_MPCORE_PRIVCTR_PERIOD_REG * CA9_MPCORE_PRIVCTR_PRESCALER) + 1)
#endif
//NOTE: The private timer ticks with a very high frequency (half the core-clock usually),
//but offers the possibility to apply a prescaler. Depending on the prescaler you set the
//HWTC_DIVISOR may need to be raised. Refer to the notes at the beginning of this file
//for more information.
#define HWTC_DIVISOR 1
#ifndef TRC_HWTC_DIVISOR
#define TRC_HWTC_DIVISOR 1
#endif
#define IRQ_PRIORITY_ORDER 0 // lower IRQ priority values are more significant
#ifndef TRC_PORT_SPECIFIC_INIT
#define TRC_PORT_SPECIFIC_INIT()
#endif
#elif (SELECTED_PORT == PORT_APPLICATION_DEFINED)
/* If Win32 port */
#ifdef WIN32
#if !( defined (HWTC_COUNT_DIRECTION) && defined (HWTC_COUNT) && defined (HWTC_PERIOD) && defined (HWTC_DIVISOR) && defined (IRQ_PRIORITY_ORDER) )
#error SELECTED_PORT is PORT_APPLICATION_DEFINED but not all of the necessary constants have been defined.
#endif
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#elif (SELECTED_PORT != PORT_NOT_SET)
/* Standard includes. */
#include <stdio.h>
#include <windows.h>
#include <direct.h>
#error "SELECTED_PORT had unsupported value!"
#define SELECTED_PORT PORT_NOT_SET
/***************************************************************************
* The Win32 port by default saves the trace to file and then kills the
* program when the recorder is stopped, to facilitate quick, simple tests
* of the recorder.
***************************************************************************/
#define WIN32_PORT_SAVE_WHEN_STOPPED 1
#define WIN32_PORT_EXIT_WHEN_STOPPED 1
#endif
#if (SELECTED_PORT != PORT_NOT_SET)
#ifndef HWTC_COUNT_DIRECTION
#error "HWTC_COUNT_DIRECTION is not set!"
#if (TRC_CFG_HARDWARE_PORT != TRC_HARDWARE_PORT_NOT_SET)
#ifndef TRC_HWTC_TYPE
#error "TRC_HWTC_TYPE is not set!"
#endif
#ifndef HWTC_COUNT
#error "HWTC_COUNT is not set!"
#ifndef TRC_HWTC_COUNT
#error "TRC_HWTC_COUNT is not set!"
#endif
#ifndef HWTC_PERIOD
#error "HWTC_PERIOD is not set!"
#ifndef TRC_HWTC_PERIOD
#error "TRC_HWTC_PERIOD is not set!"
#endif
#ifndef HWTC_DIVISOR
#error "HWTC_DIVISOR is not set!"
#ifndef TRC_HWTC_DIVISOR
#error "TRC_HWTC_DIVISOR is not set!"
#endif
#ifndef IRQ_PRIORITY_ORDER
#error "IRQ_PRIORITY_ORDER is not set!"
#elif (IRQ_PRIORITY_ORDER != 0) && (IRQ_PRIORITY_ORDER != 1)
#error "IRQ_PRIORITY_ORDER has bad value!"
#ifndef TRC_IRQ_PRIORITY_ORDER
#error "TRC_IRQ_PRIORITY_ORDER is not set!"
#elif (TRC_IRQ_PRIORITY_ORDER != 0) && (TRC_IRQ_PRIORITY_ORDER != 1)
#error "TRC_IRQ_PRIORITY_ORDER has bad value!"
#endif
#if (HWTC_DIVISOR < 1)
#error "HWTC_DIVISOR must be a non-zero positive value!"
#if (TRC_HWTC_DIVISOR < 1)
#error "TRC_HWTC_DIVISOR must be a non-zero positive value!"
#endif
#ifndef TRC_HWTC_FREQ_HZ
#error "TRC_HWTC_FREQ_HZ not defined!"
#endif
#endif
/*******************************************************************************
* vTraceConsoleMessage
*
* A wrapper for your system-specific console "printf" console output function.
* This needs to be correctly defined to see status reports from the trace
* status monitor task (this is defined in trcUser.c).
******************************************************************************/
#define vTraceConsoleMessage(x)
/*******************************************************************************
* vTracePortGetTimeStamp
*
* Returns the current time based on the HWTC macros which provide a hardware
* isolation layer towards the hardware timer/counter.
*
* The HWTC macros and vTracePortGetTimeStamp is the main porting issue
* or the trace recorder library. Typically you should not need to change
* the code of vTracePortGetTimeStamp if using the HWTC macros.
*
******************************************************************************/
void vTracePortGetTimeStamp(uint32_t *puiTimestamp);
#endif
#endif /*TRC_SNAPSHOT_HARDWARE_PORT_H*/

@ -1,94 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcKernel.h
*
* Functions used by trcKernelHooks.h.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Copyright Percepio AB, 2013.
* www.percepio.com
******************************************************************************/
#ifndef TRCKERNEL_H
#define TRCKERNEL_H
#include "trcKernelPort.h"
#if (USE_TRACEALYZER_RECORDER == 1)
/* Internal functions */
#if !defined INCLUDE_READY_EVENTS || INCLUDE_READY_EVENTS == 1
void vTraceSetReadyEventsEnabled(int status);
void vTraceStoreTaskReady(objectHandleType handle);
#else
#define vTraceSetReadyEventsEnabled(status)
#endif
void vTraceStoreLowPower(uint32_t flag);
void vTraceStoreTaskswitch(objectHandleType task_handle);
void vTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t byteParam);
void vTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode,
uint32_t param);
void vTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,
uint32_t objectNumber, uint32_t param);
void vTraceSetTaskInstanceFinished(objectHandleType handle);
void vTraceSetPriorityProperty(uint8_t objectclass, objectHandleType id, uint8_t value);
uint8_t uiTraceGetPriorityProperty(uint8_t objectclass, objectHandleType id);
void vTraceSetObjectState(uint8_t objectclass, objectHandleType id, uint8_t value);
uint8_t uiTraceGetObjectState(uint8_t objectclass, objectHandleType id);
#if (INCLUDE_OBJECT_DELETE == 1)
void vTraceStoreObjectNameOnCloseEvent(objectHandleType handle,
traceObjectClass objectclass);
void vTraceStoreObjectPropertiesOnCloseEvent(objectHandleType handle,
traceObjectClass objectclass);
#endif
/* Internal constants for task state */
#define TASK_STATE_INSTANCE_NOT_ACTIVE 0
#define TASK_STATE_INSTANCE_ACTIVE 1
#endif
#endif

@ -1,213 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcKernelHooks.h
*
* The kernel integration hooks.
*
* NOTE:
* For IAR Embedded Workbench for ARM, you need to have a preprocessor condition
* on the include, to except it from the assembler step which otherwise give
* compile-time errors.
*
* #ifdef __ICCARM__
* #include "trcKernelPort.h"
* #endif
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcPort.c and trcPort.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Copyright Percepio AB, 2013.
* www.percepio.com
******************************************************************************/
#ifndef TRCKERNELHOOKS_H
#define TRCKERNELHOOKS_H
#if (USE_TRACEALYZER_RECORDER == 1)
#undef INCLUDE_xTaskGetSchedulerState
#define INCLUDE_xTaskGetSchedulerState 1
#undef INCLUDE_xTaskGetCurrentTaskHandle
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#ifndef INCLUDE_OBJECT_DELETE
#define INCLUDE_OBJECT_DELETE 0
#endif
#ifndef INCLUDE_READY_EVENTS
#define INCLUDE_READY_EVENTS 1
#endif
#ifndef INCLUDE_NEW_TIME_EVENTS
#define INCLUDE_NEW_TIME_EVENTS 0
#endif
#if (INCLUDE_OBJECT_DELETE == 1)
/* This macro will remove the task and store it in the event buffer */
#undef trcKERNEL_HOOKS_TASK_DELETE
#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB) \
vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
vTraceStoreObjectNameOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \
vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \
vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \
vTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \
vTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
#else
#undef trcKERNEL_HOOKS_TASK_DELETE
#define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB)
#endif
#if (INCLUDE_OBJECT_DELETE == 1)
/* This macro will remove the object and store it in the event buffer */
#undef trcKERNEL_HOOKS_OBJECT_DELETE
#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject) \
vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \
vTraceStoreObjectNameOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \
vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \
vTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
#else
#undef trcKERNEL_HOOKS_OBJECT_DELETE
#define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject)
#endif
/* This macro will create a task in the object table */
#undef trcKERNEL_HOOKS_TASK_CREATE
#define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \
TRACE_SET_TASK_NUMBER(pxTCB) \
vTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \
vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \
vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
/* This macro will create a failed create call to create a task */
#undef trcKERNEL_HOOKS_TASK_CREATE_FAILED
#define trcKERNEL_HOOKS_TASK_CREATE_FAILED(SERVICE, CLASS) \
vTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, FAILED, CLASS, 0), TRACE_CLASS_TASK, 0);
/* This macro will setup a task in the object table */
#undef trcKERNEL_HOOKS_OBJECT_CREATE
#define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\
TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\
vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \
vTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);
/* This macro will create a failed create call to create an object */
#undef trcKERNEL_HOOKS_OBJECT_CREATE_FAILED
#define trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(SERVICE, CLASS, kernelClass) \
vTraceStoreKernelCall(TRACE_GET_CLASS_EVENT_CODE(SERVICE, FAILED, CLASS, kernelClass), TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass), 0);
/* This macro will create a call to a kernel service with a certain result, with an object as parameter */
#undef trcKERNEL_HOOKS_KERNEL_SERVICE
#define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, RESULT, CLASS, pxObject) \
vTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
/* This macro will set the state for an object */
#undef trcKERNEL_HOOKS_SET_OBJECT_STATE
#define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \
vTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), STATE);
/* This macro will flag a certain task as a finished instance */
#undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED
#define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \
vTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));
#if INCLUDE_READY_EVENTS == 1
/* This macro will create an event to indicate that a task became Ready */
#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE
#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \
vTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));
#else
#undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE
#define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)
#endif
/* This macro will update the internal tick counter and call vTracePortGetTimeStamp(0) to update the internal counters */
#undef trcKERNEL_HOOKS_INCREMENT_TICK
#define trcKERNEL_HOOKS_INCREMENT_TICK() \
{ extern uint32_t uiTraceTickCount; uiTraceTickCount++; vTracePortGetTimeStamp(0); }
#if INCLUDE_NEW_TIME_EVENTS == 1
/* This macro will create an event indicating that the OS tick count has increased */
#undef trcKERNEL_HOOKS_NEW_TIME
#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \
vTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);
#else
#undef trcKERNEL_HOOKS_NEW_TIME
#define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)
#endif
/* This macro will create a task switch event to the currently executing task */
#undef trcKERNEL_HOOKS_TASK_SWITCH
#define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \
vTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));
/* This macro will create an event to indicate that the task has been suspended */
#undef trcKERNEL_HOOKS_TASK_SUSPEND
#define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \
vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
vTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));
/* This macro will create an event to indicate that a task has called a wait/delay function */
#undef trcKERNEL_HOOKS_TASK_DELAY
#define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \
vTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \
vTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));
/* This macro will create an event to indicate that a task has gotten its priority changed */
#undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE
#define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \
vTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), uiTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\
vTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority);
/* This macro will create an event to indicate that the task has been resumed */
#undef trcKERNEL_HOOKS_TASK_RESUME
#define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \
vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
#undef trcKERNEL_HOOKS_TIMER_EVENT
#define trcKERNEL_HOOKS_TIMER_EVENT(SERVICE, pxTimer) \
vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));
/* This macro will create a timer in the object table and assign the timer a trace handle (timer number).*/
#undef trcKERNEL_HOOKS_TIMER_CREATE
#define trcKERNEL_HOOKS_TIMER_CREATE(SERVICE, pxTimer) \
TRACE_SET_TIMER_NUMBER(pxTimer); \
vTraceSetObjectName(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_GET_TIMER_NAME(pxTimer)); \
vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));
#endif
#undef trcKERNEL_HOOKS_TIMER_DELETE
#define trcKERNEL_HOOKS_TIMER_DELETE(SERVICE, pxTimer) \
vTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer)); \
vTraceStoreObjectNameOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \
vTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \
vTraceFreeObjectHandle(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));
#endif /* TRCKERNELHOOKS_H */

@ -0,0 +1,120 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcPortDefines.h
*
* Some common defines for the trace recorder.
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRC_PORTDEFINES_H
#define TRC_PORTDEFINES_H
#define TRC_FREE_RUNNING_32BIT_INCR 1
#define TRC_FREE_RUNNING_32BIT_DECR 2
#define TRC_OS_TIMER_INCR 3
#define TRC_OS_TIMER_DECR 4
#define TRC_CUSTOM_TIMER_INCR 5
#define TRC_CUSTOM_TIMER_DECR 6
/* Start options for vTraceEnable. */
#define TRC_INIT 0
#define TRC_START 1
#define TRC_START_AWAIT_HOST 2
/* Command codes for TzCtrl task */
#define CMD_SET_ACTIVE 1 /* Start (param1 = 1) or Stop (param1 = 0) */
/* The final command code, used to validate commands. */
#define CMD_LAST_COMMAND 1
#define TRC_RECORDER_MODE_SNAPSHOT 0
#define TRC_RECORDER_MODE_STREAMING 1
#define TRC_RECORDER_BUFFER_ALLOCATION_STATIC (0x00)
#define TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC (0x01)
#define TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM (0x02)
/******************************************************************************
* Supported ports
*
* TRC_HARDWARE_PORT_HWIndependent
* A hardware independent fallback option for event timestamping. Provides low
* resolution timestamps based on the OS tick.
* This may be used on the Win32 port, but may also be used on embedded hardware
* platforms. All time durations will be truncated to the OS tick frequency,
* typically 1 KHz. This means that a task or ISR that executes in less than
* 1 ms get an execution time of zero.
*
* TRC_HARDWARE_PORT_APPLICATION_DEFINED
* Allows for defining the port macros in other source code files.
*
* TRC_HARDWARE_PORT_Win32
* "Accurate" timestamping based on the Windows performance counter for Win32
* builds. Note that this gives the host machine time, not the kernel time.
*
* Hardware specific ports
* To get accurate timestamping, a hardware timer is necessary. Below are the
* available ports. Some of these are "unofficial", meaning that
* they have not yet been verified by Percepio but have been contributed by
* external developers. They should work, otherwise let us know by emailing
* support@percepio.com. Some work on any OS platform, while other are specific
* to a certain operating system.
*****************************************************************************/
/****** Port Name ************************************* Code ** Official ** OS Platform *********/
#define TRC_HARDWARE_PORT_APPLICATION_DEFINED 98 /* - - */
#define TRC_HARDWARE_PORT_NOT_SET 99 /* - - */
#define TRC_HARDWARE_PORT_HWIndependent 0 /* Yes Any */
#define TRC_HARDWARE_PORT_Win32 1 /* Yes FreeRTOS on Win32 */
#define TRC_HARDWARE_PORT_Atmel_AT91SAM7 2 /* No Any */
#define TRC_HARDWARE_PORT_Atmel_UC3A0 3 /* No Any */
#define TRC_HARDWARE_PORT_ARM_Cortex_M 4 /* Yes Any */
#define TRC_HARDWARE_PORT_Renesas_RX600 6 /* Yes Any */
#define TRC_HARDWARE_PORT_MICROCHIP_PIC24_PIC32 7 /* Yes Any */
#define TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48 8 /* Yes Any */
#define TRC_HARDWARE_PORT_TEXAS_INSTRUMENTS_MSP430 9 /* No Any */
#define TRC_HARDWARE_PORT_XILINX_PPC405 11 /* No FreeRTOS */
#define TRC_HARDWARE_PORT_XILINX_PPC440 12 /* No FreeRTOS */
#define TRC_HARDWARE_PORT_XILINX_MICROBLAZE 13 /* No Any */
#define TRC_HARDWARE_PORT_NXP_LPC210X 14 /* No Any */
#define TRC_HARDWARE_PORT_ARM_CORTEX_A9 15 /* Yes Any */
#define TRC_HARDWARE_PORT_POWERPC_Z4 16 /* No FreeRTOS */
#endif /*TRC_PORTDEFINES_H*/

@ -1,58 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcTypes.h
*
* Data types used by the trace recorder library.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#ifndef TRCTYPES_H
#define TRCTYPES_H
#include <stdint.h>
#include <trcConfig.h>
typedef uint16_t traceLabel;
typedef uint8_t UserEventChannel;
#if (USE_16BIT_OBJECT_HANDLES == 1)
typedef uint16_t objectHandleType;
#else
typedef uint8_t objectHandleType;
#endif
typedef uint8_t traceObjectClass;
#endif

@ -1,465 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcUser.h
* The public API of the trace recorder library.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#ifndef TRCUSER_H
#define TRCUSER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "trcKernelPort.h"
#if (USE_TRACEALYZER_RECORDER == 1)
#ifndef USE_SEPARATE_USER_EVENT_BUFFER
#define USE_SEPARATE_USER_EVENT_BUFFER 0
#endif
/*******************************************************************************
* TRACE_STOP_HOOK - Hook Pointer Data Type
*
* Declares a data type for a call back function that will be invoked whenever
* the recorder is stopped.
******************************************************************************/
typedef void (*TRACE_STOP_HOOK)(void);
/*******************************************************************************
* vTraceStopHookPtr
*
* Points to a call back function that is called from vTraceStop().
******************************************************************************/
extern TRACE_STOP_HOOK vTraceStopHookPtr;
/*******************************************************************************
* vTraceInitTraceData
*
* Allocates, if necessary, and initializes the recorder data structure, based
* on the constants in trcConfig.h.
******************************************************************************/
void vTraceInitTraceData(void);
/*******************************************************************************
* vTraceSetRecorderData
*
* If custom allocation is used, this function must be called so the recorder
* library knows where to save the trace data.
******************************************************************************/
#if (TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_CUSTOM)
void vTraceSetRecorderData(void* pRecorderData);
#endif
/*******************************************************************************
* vTraceSetStopHook
*
* Sets a function to be called when the recorder is stopped.
******************************************************************************/
void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);
/*******************************************************************************
* uiTraceStart
*
* Starts the recorder. The recorder will not be started if an error has been
* indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h
* has a too small value (NTASK, NQUEUE, etc).
*
* Returns 1 if the recorder was started successfully.
* Returns 0 if the recorder start was prevented due to a previous internal
* error. In that case, check vTraceGetLastError to get the error message.
* Any error message is also presented when opening a trace file.
*
******************************************************************************/
uint32_t uiTraceStart(void);
/*******************************************************************************
* vTraceStart
*
* Starts the recorder. The recorder will not be started if an error has been
* indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h
* has a too small value (NTASK, NQUEUE, etc).
*
* This function is obsolete, but has been saved for backwards compatibility.
* We recommend using uiTraceStart instead.
******************************************************************************/
void vTraceStart(void);
/*******************************************************************************
* vTraceStop
*
* Stops the recorder. The recording can be resumed by calling vTraceStart.
* This does not reset the recorder. Use vTraceClear is that is desired.
******************************************************************************/
void vTraceStop(void);
/*******************************************************************************
* xTraceGetLastError
*
* Gives the last error message, if any. NULL if no error message is stored.
* Any error message is also presented when opening a trace file.
******************************************************************************/
char* xTraceGetLastError(void);
/*******************************************************************************
* vTraceClear
*
* Resets the recorder. Only necessary if a restart is desired - this is not
* needed in the startup initialization.
******************************************************************************/
void vTraceClear(void);
/*******************************************************************************
* vTraceClearError
*
* Removes any previous error message generated by recorder calling vTraceError.
* By calling this function, it may be possible to start/restart the trace
* despite errors in the recorder, but there is no guarantee that the trace
* recorder will work correctly in that case, depending on the type of error.
******************************************************************************/
void vTraceClearError(int resetErrorMessage);
#if (INCLUDE_ISR_TRACING == 1)
/*******************************************************************************
* vTraceSetISRProperties
*
* Registers an Interrupt Service Routine in the recorder library, This must be
* called before using vTraceStoreISRBegin to store ISR events. This is
* typically called in the startup of the system, before the scheduler is
* started.
*
* Example:
* #define ID_ISR_TIMER1 1 // lowest valid ID is 1
* #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
* ...
* vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
* ...
* void ISR_handler()
* {
* vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
* ...
* vTraceStoreISREnd(0);
* }
******************************************************************************/
void vTraceSetISRProperties(objectHandleType handle, const char* name, char priority);
/*******************************************************************************
* vTraceStoreISRBegin
*
* Registers the beginning of an Interrupt Service Routine.
* If allowing nested ISRs, this must be called with interrupts disabled.
*
* Example:
* #define ID_ISR_TIMER1 1 // lowest valid ID is 1
* #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
* ...
* vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
* ...
* void ISR_handler()
* {
* vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
* ...
* vTraceStoreISREnd(0);
* }
*
******************************************************************************/
void vTraceStoreISRBegin(objectHandleType id);
/*******************************************************************************
* vTraceStoreISREnd
*
* Registers the end of an Interrupt Service Routine.
*
* The parameter pendingISR indicates if the interrupt has requested a
* task-switch (= 1) or if the interrupt returns to the earlier context (= 0)
*
* Example:
* #define ID_ISR_TIMER1 1 // lowest valid ID is 1
* #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
* ...
* vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
* ...
* void ISR_handler()
* {
* vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
* ...
* vTraceStoreISREnd(0);
* }
*
******************************************************************************/
void vTraceStoreISREnd(int pendingISR);
#else
/* If not including the ISR recording */
void vTraceIncreaseISRActive(void);
void vTraceDecreaseISRActive(void);
#define vTraceSetISRProperties(handle, name, priority)
#define vTraceStoreISRBegin(id) vTraceIncreaseISRActive()
#define vTraceStoreISREnd() vTraceDecreaseISRActive()
#endif
/******************************************************************************
* vTraceTaskInstanceFinish(void)
*
* Marks the current task instance as finished on the next kernel call.
*
* If that kernel call is blocking, the instance ends after the blocking event
* and the corresponding return event is then the start of the next instance.
* If the kernel call is not blocking, the viewer instead splits the current
* fragment right before the kernel call, which makes this call the first event
* of the next instance.
*
* See also USE_IMPLICIT_IFE_RULES in trcConfig.h
*
* Example:
*
* while(1)
* {
* xQueueReceive(CommandQueue, &command, timeoutDuration);
* processCommand(command);
* vTraceInstanceFinish();
* }
*
*****************************************************************************/
void vTraceTaskInstanceFinish(void);
/******************************************************************************
* vTraceTaskInstanceFinishDirect(void)
*
* Marks the current task instance as finished at this very instant.
* This makes the viewer to splits the current fragment at this point and begin
* a new actor instance.
*
* See also USE_IMPLICIT_IFE_RULES in trcConfig.h
*
* Example:
*
* This example will generate two instances for each loop iteration.
* The first instance ends at vTraceInstanceFinishDirect(), while the second
* instance ends at the next xQueueReceive call.
*
* while (1)
* {
* xQueueReceive(CommandQueue, &command, timeoutDuration);
* ProcessCommand(command);
* vTraceInstanceFinishDirect();
* DoSometingElse();
* vTraceInstanceFinish();
* }
*
*
*****************************************************************************/
void vTraceTaskInstanceFinishDirect(void);
/*******************************************************************************
* vTraceGetTraceBuffer
*
* Returns a pointer to the recorder data structure. Use this together with
* uiTraceGetTraceBufferSize if you wish to implement an own store/upload
* solution, e.g., in case a debugger connection is not available for uploading
* the data.
******************************************************************************/
void* vTraceGetTraceBuffer(void);
/*******************************************************************************
* uiTraceGetTraceBufferSize
*
* Gets the size of the recorder data structure. For use together with
* vTraceGetTraceBuffer if you wish to implement an own store/upload solution,
* e.g., in case a debugger connection is not available for uploading the data.
******************************************************************************/
uint32_t uiTraceGetTraceBufferSize(void);
#if (INCLUDE_USER_EVENTS == 1)
/*******************************************************************************
* xTraceOpenLabel
*
* Creates user event labels for user event channels or for individual events.
* User events can be used to log application events and data for display in
* the visualization tool. A user event is identified by a label, i.e., a string,
* which is stored in the recorder's symbol table.
* When logging a user event, a numeric handle (reference) to this string is
* used to identify the event. This is obtained by calling
*
* xTraceOpenLabel()
*
* whihc adds the string to the symbol table (if not already present)
* and returns the corresponding handle.
*
* This can be used in two ways:
*
* 1. The handle is looked up every time, when storing the user event.
*
* Example:
* vTraceUserEvent(xTraceOpenLabel("MyUserEvent"));
*
* 2. The label is registered just once, with the handle stored in an
* application variable - much like using a file handle.
*
* Example:
* myEventHandle = xTraceOpenLabel("MyUserEvent");
* ...
* vTraceUserEvent(myEventHandle);
*
* The second option is faster since no lookup is required on each event, and
* therefore recommended for user events that are frequently
* executed and/or located in time-critical code. The lookup operation is
* however fairly fast due to the design of the symbol table.
******************************************************************************/
traceLabel xTraceOpenLabel(const char* label);
/******************************************************************************
* vTraceUserEvent
*
* Basic user event (Standard and Professional Edition only)
*
* Generates a User Event with a text label. The label is created/looked up
* in the symbol table using xTraceOpenLabel.
******************************************************************************/
void vTraceUserEvent(traceLabel eventLabel);
/******************************************************************************
* vTracePrintF
*
* Advanced user events (Professional Edition only)
*
* Generates User Event with formatted text and data, similar to a "printf".
* It is very fast compared to a normal "printf" since this function only
* stores the arguments. The actual formatting is done
* on the host PC when the trace is displayed in the viewer tool.
*
* User Event labels are created using xTraceOpenLabel.
* Example:
*
* traceLabel adc_uechannel = xTraceOpenLabel("ADC User Events");
* ...
* vTracePrint(adc_uechannel,
* "ADC channel %d: %lf volts",
* ch, (double)adc_reading/(double)scale);
*
* This can be combined into one line, if desired, but this is slower:
*
* vTracePrint(xTraceOpenLabel("ADC User Events"),
* "ADC channel %d: %lf volts",
* ch, (double)adc_reading/(double)scale);
*
* Calling xTraceOpenLabel multiple times will not create duplicate entries, but
* it is of course faster to just do it once, and then keep the handle for later
* use. If you don<EFBFBD>t have any data arguments, only a text label/string, it is
* better to use vTraceUserEvent - it is faster.
*
* Format specifiers supported:
* %d - 32 bit signed integer
* %u - 32 bit unsigned integer
* %f - 32 bit float
* %s - string (is copied to the recorder symbol table)
* %hd - 16 bit signed integer
* %hu - 16 bit unsigned integer
* %bd - 8 bit signed integer
* %bu - 8 bit unsigned integer
* %lf - double-precision float (Note! See below...)
*
* Up to 15 data arguments are allowed, with a total size of maximum 32 byte.
* In case this is exceeded, the user event is changed into an error message.
*
* The data is stored in trace buffer, and is packed to allow storing multiple
* smaller data entries in the same 4-byte record, e.g., four 8-bit values.
* A string requires two bytes, as the symbol table is limited to 64K. Storing
* a double (%lf) uses two records, so this is quite costly. Use float (%f)
* unless the higher precision is really necessary.
*
* Note that the double-precision float (%lf) assumes a 64 bit double
* representation. This does not seem to be the case on e.g. PIC24 and PIC32.
* Before using a %lf argument on a 16-bit MCU, please verify that
* "sizeof(double)" actually gives 8 as expected. If not, use %f instead.
******************************************************************************/
void vTracePrintF(traceLabel eventLabel, const char* formatStr, ...);
#if (USE_SEPARATE_USER_EVENT_BUFFER == 1)
UserEventChannel xTraceRegisterChannelFormat(traceLabel channel, traceLabel formatStr);
void vTraceChannelPrintF(UserEventChannel channel, ...);
void vTraceChannelUserEvent(UserEventChannel channel);
#endif
#else
#define vTracePrintF(eventLabel, formatStr, ...);
#define xTraceOpenLabel(label) 0
#define vTraceUserEvent(eventLabel)
#endif
#else
/* Empty defines for user functions to avoid compiler errors if trace is not to be used */
#define vTraceInitTraceData()
#define uiTraceStart() (1) // Fake "success", if used when recorder is excluded from build
#define vTraceStart()
#define vTraceStop()
#define vTraceClear()
#define vTraceStartStatusMonitor()
#define vTraceGetTraceBuffer() ((void*)0)
#define uiTraceGetTraceBufferSize() 0
#define xTraceOpenLabel(label) 0
#define vTraceUserEvent(eventLabel)
#define vTracePrintF(eventLabel,formatStr,...)
#define vTraceExcludeTaskFromSchedulingTrace(name)
#define vTraceSetISRProperties(handle, name, priority)
#define vTraceStoreISRBegin(id)
#define vTraceStoreISREnd(flag)
#define vTraceExcludeTaskFromTrace(handle)
#define vTraceSetQueueName(a, b)
#define vTraceSetMutexName(a, b)
#define vTraceSetSemaphoreName(a, b)
#define vTraceSetEventGroupName(a, b)
#define vTraceSetStopHook(a)
#endif
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,159 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcConfig.h
*
* Main configuration parameters for the trace recorder library.
* More settings can be found in trcStreamingConfig.h and trcSnapshotConfig.h.
*
* Read more at http://percepio.com/2016/10/05/rtos-tracing/
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2016.
* www.percepio.com
******************************************************************************/
#ifndef TRC_CONFIG_H
#define TRC_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "trcPortDefines.h"
/******************************************************************************
* Include of processor header file
*
* Here you may need to include the header file for your processor. This is
* required at least for the ARM Cortex-M port, that uses the ARM CMSIS API.
* Try that in case of build problems. Otherwise, remove the #error line below.
*****************************************************************************/
#error "Trace Recorder: Please include your processor's header file here and remove this line."
/*******************************************************************************
* Configuration Macro: TRC_CFG_HARDWARE_PORT
*
* Specify what hardware port to use (i.e., the "timestamping driver").
*
* All ARM Cortex-M MCUs are supported by "TRC_HARDWARE_PORT_ARM_Cortex_M".
* This port uses the DWT cycle counter for Cortex-M3/M4/M7 devices, which is
* available on most such devices. In case your device don't have DWT support,
* you will get an error message opening the trace. In that case, you may
* force the recorder to use SysTick timestamping instead, using this define:
*
* #define TRC_CFG_ARM_CM_USE_SYSTICK
*
* For ARM Cortex-M0/M0+ devices, SysTick mode is used automatically.
*
* See trcHardwarePort.h for available ports and information on how to
* define your own port, if not already present.
******************************************************************************/
#define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET
/*******************************************************************************
* Configuration Macro: TRC_CFG_RECORDER_MODE
*
* Specify what recording mode to use. Snapshot means that the data is saved in
* an internal RAM buffer, for later upload. Streaming means that the data is
* transferred continuously to the host PC.
*
* For more information, see http://percepio.com/2016/10/05/rtos-tracing/
* and the Tracealyzer User Manual.
*
* Values:
* TRC_RECORDER_MODE_SNAPSHOT
* TRC_RECORDER_MODE_STREAMING
******************************************************************************/
#define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT
/*******************************************************************************
* Configuration Macro: TRC_CFG_RECORDER_BUFFER_ALLOCATION
*
* Specifies how the recorder buffer is allocated (also in case of streaming, in
* port using the recorder's internal temporary buffer)
*
* Values:
* TRC_RECORDER_BUFFER_ALLOCATION_STATIC - Static allocation (internal)
* TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC - Malloc in vTraceEnable
* TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM - Use vTraceSetRecorderDataBuffer
*
* Static and dynamic mode does the allocation for you, either in compile time
* (static) or in runtime (malloc).
* The custom mode allows you to control how and where the allocation is made,
* for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer().
******************************************************************************/
#define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC
/******************************************************************************
* TRC_CFG_FREERTOS_VERSION
*
* Specify what version of FreeRTOS that is used (don't change unless using the
* trace recorder library with an older version of FreeRTOS).
*
* TRC_FREERTOS_VERSION_7_3_OR_7_4 If using FreeRTOS v7.3.0 - v7.4.2
* TRC_FREERTOS_VERSION_7_5_OR_7_6 If using FreeRTOS v7.5.0 - v7.6.0
* TRC_FREERTOS_VERSION_8_X If using FreeRTOS v8.X.X
* TRC_FREERTOS_VERSION_9_X If using FreeRTOS v9.X.X
*****************************************************************************/
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_9_X
/******************************************************************************
* TRC_CFG_MAX_ISR_NESTING
*
* Defines how many levels of interrupt nesting the recorder can handle, in
* case multiple ISRs are traced and ISR nesting is possible. If this
* is exceeded, the particular ISR will not be traced and the recorder then
* logs an error message. This setting is used to allocate an internal stack
* for keeping track of the previous execution context (4 byte per entry).
*
* This value must be a non-zero positive constant, at least 1.
*
* Default value: 8
*****************************************************************************/
#define TRC_CFG_MAX_ISR_NESTING 8
/* Specific configuration, depending on Streaming/Snapshot mode */
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
#include "trcSnapshotConfig.h"
#elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
#include "trcStreamingConfig.h"
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TRC_CONFIG_H */

@ -0,0 +1,472 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcSnapshotConfig.h
*
* Configuration parameters for trace recorder library in snapshot mode.
* Read more at http://percepio.com/2016/10/05/rtos-tracing/
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRC_SNAPSHOT_CONFIG_H
#define TRC_SNAPSHOT_CONFIG_H
#define TRC_SNAPSHOT_MODE_RING_BUFFER (0x01)
#define TRC_SNAPSHOT_MODE_STOP_WHEN_FULL (0x02)
/******************************************************************************
* TRC_CFG_SNAPSHOT_MODE
*
* Macro which should be defined as one of:
* - TRC_SNAPSHOT_MODE_RING_BUFFER
* - TRC_SNAPSHOT_MODE_STOP_WHEN_FULL
* Default is TRC_SNAPSHOT_MODE_RING_BUFFER.
*
* With TRC_CFG_SNAPSHOT_MODE set to TRC_SNAPSHOT_MODE_RING_BUFFER, the
* events are stored in a ring buffer, i.e., where the oldest events are
* overwritten when the buffer becomes full. This allows you to get the last
* events leading up to an interesting state, e.g., an error, without having
* to store the whole run since startup.
*
* When TRC_CFG_SNAPSHOT_MODE is TRC_SNAPSHOT_MODE_STOP_WHEN_FULL, the
* recording is stopped when the buffer becomes full. This is useful for
* recording events following a specific state, e.g., the startup sequence.
*****************************************************************************/
#define TRC_CFG_SNAPSHOT_MODE TRC_SNAPSHOT_MODE_RING_BUFFER
/*******************************************************************************
* TRC_CFG_SCHEDULING_ONLY
*
* Macro which should be defined as an integer value.
*
* If this setting is enabled (= 1), only scheduling events are recorded.
* If disabled (= 0), all events are recorded.
*
* For users of Tracealyzer Free Edition, that only displays scheduling events, this
* option can be used to avoid storing other events.
*
* Default value is 0 (store all enabled events).
*
******************************************************************************/
#define TRC_CFG_SCHEDULING_ONLY 0
/*******************************************************************************
* TRC_CFG_EVENT_BUFFER_SIZE
*
* Macro which should be defined as an integer value.
*
* This defines the capacity of the event buffer, i.e., the number of records
* it may store. Most events use one record (4 byte), although some events
* require multiple 4-byte records. You should adjust this to the amount of RAM
* available in the target system.
*
* Default value is 1000, which means that 4000 bytes is allocated for the
* event buffer.
******************************************************************************/
#define TRC_CFG_EVENT_BUFFER_SIZE 1000
/*******************************************************************************
* TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE...
*
* A group of macros which should be defined as integer values, zero or larger.
*
* These define the capacity of the Object Property Table, i.e., the maximum
* number of objects active at any given point, within each object class (e.g.,
* task, queue, semaphore, ...).
*
* If tasks or other objects are deleted in your system, this
* setting does not limit the total amount of objects created, only the number
* of objects that have been successfully created but not yet deleted.
*
* Using too small values will cause vTraceError to be called, which stores an
* error message in the trace that is shown when opening the trace file. The
* error message can also be retrieved using xTraceGetLastError.
*
* It can be wise to start with large values for these constants,
* unless you are very confident on these numbers. Then do a recording and
* check the actual usage by selecting View menu -> Trace Details ->
* Resource Usage -> Object Table.
******************************************************************************/
#define TRC_CFG_NTASK 10
#define TRC_CFG_NISR 5
#define TRC_CFG_NQUEUE 10
#define TRC_CFG_NSEMAPHORE 10
#define TRC_CFG_NMUTEX 10
#define TRC_CFG_NTIMER 5
#define TRC_CFG_NEVENTGROUP 5
/******************************************************************************
* TRC_CFG_INCLUDE_MEMMANG_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* This controls if malloc and free calls should be traced. Set this to zero (0)
* to exclude malloc/free calls, or one (1) to include such events in the trace.
*
* Default value is 1.
*****************************************************************************/
#define TRC_CFG_INCLUDE_MEMMANG_EVENTS 1
/******************************************************************************
* TRC_CFG_INCLUDE_USER_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0) the code for creating User Events is excluded to
* reduce code size. User Events are application-generated events, like
* "printf" but for the trace log and the formatting is done offline, by the
* Tracealyzer visualization tool. User Events are much faster than a printf
* and can therefore be used in timing critical code.
*
* Default value is 1.
*****************************************************************************/
#define TRC_CFG_INCLUDE_USER_EVENTS 1
/*****************************************************************************
* TRC_CFG_INCLUDE_ISR_TRACING
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the code for recording Interrupt Service Routines is
* excluded, in order to reduce code size.
*
* Default value is 1.
*
* Note: tracing ISRs requires that you insert calls to vTraceStoreISRBegin
* and vTraceStoreISREnd in your interrupt handlers.
*****************************************************************************/
#define TRC_CFG_INCLUDE_ISR_TRACING 1
/*****************************************************************************
* TRC_CFG_INCLUDE_READY_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If one (1), events are recorded when tasks enter scheduling state "ready".
* This allows Tracealyzer to show the initial pending time before tasks enter
* the execution state, and present accurate response times.
* If zero (0), "ready events" are not created, which allows for recording
* longer traces in the same amount of RAM.
*
* Default value is 1.
*****************************************************************************/
#define TRC_CFG_INCLUDE_READY_EVENTS 1
/*****************************************************************************
* TRC_CFG_INCLUDE_OSTICK_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is one (1), events will be generated whenever the OS clock is
* increased. If zero (0), OS tick events are not generated, which allows for
* recording longer traces in the same amount of RAM.
*
* Default value is 0.
*****************************************************************************/
#define TRC_CFG_INCLUDE_OSTICK_EVENTS 0
/******************************************************************************
* TRC_CFG_INCLUDE_FLOAT_SUPPORT
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the support for logging floating point values in
* vTracePrintF is stripped out, in case floating point values are not used or
* supported by the platform used.
*
* Floating point values are only used in vTracePrintF and its subroutines, to
* allow for storing float (%f) or double (%lf) arguments.
*
* vTracePrintF can be used with integer and string arguments in either case.
*
* Default value is 0.
*****************************************************************************/
#define TRC_CFG_INCLUDE_FLOAT_SUPPORT 0
/******************************************************************************
* TRC_CFG_INCLUDE_OBJECT_DELETE
*
* Macro which should be defined as either zero (0) or one (1).
*
* This must be enabled (1) if tasks, queues or other
* traced kernel objects are deleted at runtime. If no deletes are made, this
* can be set to 0 in order to exclude the delete-handling code.
*
* Default value is 1.
*****************************************************************************/
#define TRC_CFG_INCLUDE_OBJECT_DELETE 1
/*******************************************************************************
* TRC_CFG_SYMBOL_TABLE_SIZE
*
* Macro which should be defined as an integer value.
*
* This defines the capacity of the symbol table, in bytes. This symbol table
* stores User Events labels and names of deleted tasks, queues, or other kernel
* objects. If you don't use User Events or delete any kernel
* objects you set this to a very low value. The minimum recommended value is 4.
* A size of zero (0) is not allowed since a zero-sized array may result in a
* 32-bit pointer, i.e., using 4 bytes rather than 0.
*
* Default value is 800.
******************************************************************************/
#define TRC_CFG_SYMBOL_TABLE_SIZE 800
#if (TRC_CFG_SYMBOL_TABLE_SIZE == 0)
#error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!"
#endif
/******************************************************************************
* TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ...
*
* Macros that specify the maximum lengths (number of characters) for names of
* kernel objects, such as tasks and queues. If longer names are used, they will
* be truncated when stored in the recorder.
*****************************************************************************/
#define TRC_CFG_NAME_LEN_TASK 15
#define TRC_CFG_NAME_LEN_ISR 15
#define TRC_CFG_NAME_LEN_QUEUE 15
#define TRC_CFG_NAME_LEN_SEMAPHORE 15
#define TRC_CFG_NAME_LEN_MUTEX 15
#define TRC_CFG_NAME_LEN_TIMER 15
#define TRC_CFG_NAME_LEN_EVENTGROUP 15
/******************************************************************************
*** ADVANCED SETTINGS ********************************************************
******************************************************************************
* The remaining settings are not necessary to modify but allows for optimizing
* the recorder setup for your specific needs, e.g., to exclude events that you
* are not interested in, in order to get longer traces.
*****************************************************************************/
/******************************************************************************
* TRC_CFG_HEAP_SIZE_BELOW_16M
*
* An integer constant that can be used to reduce the buffer usage of memory
* allocation events (malloc/free). This value should be 1 if the heap size is
* below 16 MB (2^24 byte), and you can live with reported addresses showing the
* lower 24 bits only. If 0, you get the full 32-bit addresses.
*
* Default value is 0.
******************************************************************************/
#define TRC_CFG_HEAP_SIZE_BELOW_16M 0
/******************************************************************************
* TRC_CFG_USE_IMPLICIT_IFE_RULES
*
* Macro which should be defined as either zero (0) or one (1).
* Default is 1.
*
* Tracealyzer groups the events into "instances" based on Instance Finish
* Events (IFEs), produced either by default rules or calls to the recorder
* functions vTraceInstanceFinishedNow and vTraceInstanceFinishedNext.
*
* If TRC_CFG_USE_IMPLICIT_IFE_RULES is one (1), the default IFE rules is
* used, resulting in a "typical" grouping of events into instances.
* If these rules don't give appropriate instances in your case, you can
* override the default rules using vTraceInstanceFinishedNow/Next for one
* or several tasks. The default IFE rules are then disabled for those tasks.
*
* If TRC_CFG_USE_IMPLICIT_IFE_RULES is zero (0), the implicit IFE rules are
* disabled globally. You must then call vTraceInstanceFinishedNow or
* vTraceInstanceFinishedNext to manually group the events into instances,
* otherwise the tasks will appear a single long instance.
*
* The default IFE rules count the following events as "instance finished":
* - Task delay, delay until
* - Task suspend
* - Blocking on "input" operations, i.e., when the task is waiting for the
* next a message/signal/event. But only if this event is blocking.
*
* For details, see trcSnapshotKernelPort.h and look for references to the
* macro trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED.
*****************************************************************************/
#define TRC_CFG_USE_IMPLICIT_IFE_RULES 1
/******************************************************************************
* TRC_CFG_USE_16BIT_OBJECT_HANDLES
*
* Macro which should be defined as either zero (0) or one (1).
*
* If set to 0 (zero), the recorder uses 8-bit handles to identify kernel
* objects such as tasks and queues. This limits the supported number of
* concurrently active objects to 255 of each type (tasks, queues, mutexes,
* etc.) Note: 255, not 256, since handle 0 is reserved.
*
* If set to 1 (one), the recorder uses 16-bit handles to identify kernel
* objects such as tasks and queues. This limits the supported number of
* concurrent objects to 65535 of each type (object class). However, since the
* object property table is limited to 64 KB, the practical limit is about
* 3000 objects in total.
*
* Default is 0 (8-bit handles)
*
* NOTE: An object with handle above 255 will use an extra 4-byte record in
* the event buffer whenever the object is referenced. Moreover, some internal
* tables in the recorder gets slightly larger when using 16-bit handles.
*****************************************************************************/
#define TRC_CFG_USE_16BIT_OBJECT_HANDLES 0
/******************************************************************************
* TRC_CFG_USE_TRACE_ASSERT
*
* Macro which should be defined as either zero (0) or one (1).
* Default is 1.
*
* If this is one (1), the TRACE_ASSERT macro (used at various locations in the
* trace recorder) will verify that a relevant condition is true.
* If the condition is false, prvTraceError() will be called, which stops the
* recording and stores an error message that is displayed when opening the
* trace in Tracealyzer.
*
* This is used on several places in the recorder code for sanity checks on
* parameters. Can be switched off to reduce the footprint of the tracing, but
* we recommend to have it enabled initially.
*****************************************************************************/
#define TRC_CFG_USE_TRACE_ASSERT 1
/*******************************************************************************
* TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER
*
* Macro which should be defined as an integer value.
*
* Set TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER to 1 to enable the
* separate user event buffer (UB).
* In this mode, user events are stored separately from other events,
* e.g., RTOS events. Thereby you can get a much longer history of
* user events as they don't need to share the buffer space with more
* frequent events.
*
* The UB is typically used with the snapshot ring-buffer mode, so the
* recording can continue when the main buffer gets full. And since the
* main buffer then overwrites the earliest events, Tracealyzer displays
* "Unknown Actor" instead of task scheduling for periods with UB data only.
*
* In UB mode, user events are structured as UB channels, which contains
* a channel name and a default format string. Register a UB channel using
* xTraceRegisterUBChannel.
*
* Events and data arguments are written using vTraceUBEvent and
* vTraceUBData. They are designed to provide efficient logging of
* repeating events, using the same format string within each channel.
*
* Examples:
*
* traceString chn1 = xTraceRegisterString("Channel 1");
* traceString fmt1 = xTraceRegisterString("Event!");
* traceUBChannel UBCh1 = xTraceRegisterUBChannel(chn1, fmt1);
*
* traceString chn2 = xTraceRegisterString("Channel 2");
* traceString fmt2 = xTraceRegisterString("X: %d, Y: %d");
* traceUBChannel UBCh2 = xTraceRegisterUBChannel(chn2, fmt2);
*
* // Result in "[Channel 1] Event!"
* vTraceUBEvent(UBCh1);
*
* // Result in "[Channel 2] X: 23, Y: 19"
* vTraceUBData(UBCh2, 23, 19);
*
* You can also use the other user event functions, like vTracePrintF.
* as they are then rerouted to the UB instead of the main event buffer.
* vTracePrintF then looks up the correct UB channel based on the
* provided channel name and format string, or creates a new UB channel
* if no match is found. The format string should therefore not contain
* "random" messages but mainly format specifiers. Random strings should
* be stored using %s and with the string as an argument.
*
* // Creates a new UB channel ("Channel 2", "%Z: %d")
* vTracePrintF(chn2, "%Z: %d", value1);
*
* // Finds the existing UB channel
* vTracePrintF(chn2, "%Z: %d", value2);
******************************************************************************/
#define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 0
/*******************************************************************************
* TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE
*
* Macro which should be defined as an integer value.
*
* This defines the capacity of the user event buffer (UB), in number of slots.
* A single user event can use multiple slots, depending on the arguments.
*
* Only applicable if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is 1.
******************************************************************************/
#define TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE 200
/*******************************************************************************
* TRC_CFG_UB_CHANNELS
*
* Macro which should be defined as an integer value.
*
* This defines the number of User Event Buffer Channels (UB channels).
* These are used to structure the events when using the separate user
* event buffer, and contains both a User Event Channel (the name) and
* a default format string for the channel.
*
* Only applicable if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is 1.
******************************************************************************/
#define TRC_CFG_UB_CHANNELS 32
/*******************************************************************************
* TRC_CFG_ISR_TAILCHAINING_THRESHOLD
*
* Macro which should be defined as an integer value.
*
* If tracing multiple ISRs, this setting allows for accurate display of the
* context-switching also in cases when the ISRs execute in direct sequence.
*
* vTraceStoreISREnd normally assumes that the ISR returns to the previous
* context, i.e., a task or a preempted ISR. But if another traced ISR
* executes in direct sequence, Tracealyzer may incorrectly display a minimal
* fragment of the previous context in between the ISRs.
*
* By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is
* however a threshold value that must be measured for your specific setup.
* See http://percepio.com/2014/03/21/isr_tailchaining_threshold/
*
* The default setting is 0, meaning "disabled" and that you may get an
* extra fragments of the previous context in between tail-chained ISRs.
*
* Note: This setting has separate definitions in trcSnapshotConfig.h and
* trcStreamingConfig.h, since it is affected by the recorder mode.
******************************************************************************/
#define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0
#endif /*TRC_SNAPSHOT_CONFIG_H*/

@ -0,0 +1,170 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcStreamingConfig.h
*
* Configuration parameters for the trace recorder library in streaming mode.
* Read more at http://percepio.com/2016/10/05/rtos-tracing/
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRC_STREAMING_CONFIG_H
#define TRC_STREAMING_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* Configuration Macro: TRC_CFG_SYMBOL_TABLE_SLOTS
*
* The maximum number of symbols names that can be stored. This includes:
* - Task names
* - Named ISRs (vTraceSetISRProperties)
* - Named kernel objects (vTraceStoreKernelObjectName)
* - User event channels (vTraceStoreUserEventChannelName)
*
* If this value is too small, not all symbol names will be stored and the
* trace display will be affected. In that case, there will be warnings
* (as User Events) from TzCtrl task, that monitors this.
******************************************************************************/
#define TRC_CFG_SYMBOL_TABLE_SLOTS 40
/*******************************************************************************
* Configuration Macro: TRC_CFG_SYMBOL_MAX_LENGTH
*
* The maximum length of symbol names, including:
* - Task names
* - Named ISRs (vTraceSetISRProperties)
* - Named kernel objects (vTraceStoreKernelObjectName)
* - User event channel names (vTraceStoreUserEventChannelName)
*
* If longer symbol names are used, they will be truncated by the recorder,
* which will affect the trace display. In that case, there will be warnings
* (as User Events) from TzCtrl task, that monitors this.
******************************************************************************/
#define TRC_CFG_SYMBOL_MAX_LENGTH 25
/*******************************************************************************
* Configuration Macro: TRC_CFG_OBJECT_DATA_SLOTS
*
* The maximum number of object data entries (used for task priorities) that can
* be stored at the same time. Must be sufficient for all tasks, otherwise there
* will be warnings (as User Events) from TzCtrl task, that monitors this.
******************************************************************************/
#define TRC_CFG_OBJECT_DATA_SLOTS 40
/*******************************************************************************
* Configuration Macro: TRC_CFG_CTRL_TASK_STACK_SIZE
*
* The stack size of the TzCtrl task, that receive commands.
* We are aiming to remove this extra task in future versions.
******************************************************************************/
#define TRC_CFG_CTRL_TASK_STACK_SIZE (configMINIMAL_STACK_SIZE * 2)
/*******************************************************************************
* Configuration Macro: TRC_CFG_CTRL_TASK_PRIORITY
*
* The priority of the TzCtrl task, that receive commands from Tracealyzer.
* Most stream ports also rely on the TzCtrl task to transmit the data from the
* internal buffer to the stream interface (all except for the J-Link port).
* For such ports, make sure the TzCtrl priority is high enough to ensure
* reliable periodic execution and transfer of the data.
******************************************************************************/
#define TRC_CFG_CTRL_TASK_PRIORITY 1
/*******************************************************************************
* Configuration Macro: TRC_CFG_CTRL_TASK_DELAY
*
* The delay between every loop of the TzCtrl task. A high delay will reduce the
* CPU load, but may cause missed events if the TzCtrl task is performing the
* trace transfer.
******************************************************************************/
#define TRC_CFG_CTRL_TASK_DELAY ((10 * configTICK_RATE_HZ) / 1000)
/*******************************************************************************
* Configuration Macro: TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT
*
* Specifies the number of pages used by the paged event buffer.
* This may need to be increased if there are a lot of missed events.
*
* Note: not used by the J-Link RTT stream port (see SEGGER_RTT_Conf.h instead)
******************************************************************************/
#define TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT 2
/*******************************************************************************
* Configuration Macro: TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE
*
* Specifies the size of each page in the paged event buffer. This can be tuned
* to match any internal low-level buffers used by the streaming interface, like
* the Ethernet MTU (Maximum Transmission Unit).
*
* Note: not used by the J-Link RTT stream port (see SEGGER_RTT_Conf.h instead)
******************************************************************************/
#define TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE 2500
/*******************************************************************************
* TRC_CFG_ISR_TAILCHAINING_THRESHOLD
*
* Macro which should be defined as an integer value.
*
* If tracing multiple ISRs, this setting allows for accurate display of the
* context-switching also in cases when the ISRs execute in direct sequence.
*
* vTraceStoreISREnd normally assumes that the ISR returns to the previous
* context, i.e., a task or a preempted ISR. But if another traced ISR
* executes in direct sequence, Tracealyzer may incorrectly display a minimal
* fragment of the previous context in between the ISRs.
*
* By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is
* however a threshold value that must be measured for your specific setup.
* See http://percepio.com/2014/03/21/isr_tailchaining_threshold/
*
* The default setting is 0, meaning "disabled" and that you may get an
* extra fragments of the previous context in between tail-chained ISRs.
*
* Note: This setting has separate definitions in trcSnapshotConfig.h and
* trcStreamingConfig.h, since it is affected by the recorder mode.
******************************************************************************/
#define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0
#ifdef __cplusplus
}
#endif
#endif /* TRC_STREAMING_CONFIG_H */

@ -1,114 +0,0 @@
Tracealyzer - Uploading the trace data
-----------------------------------------
Percepio AB, Jan. 23, 2014
This document decribes how to upload the trace data from the target system to
Tracealyzer.
Tracealyzer uses your existing debugger to upload the trace data from the
chip RAM. This is a plain RAM dump, that is done whenever you want to look at
the trace buffer contents. This means it works with essentially with any debug
probe on the market.
Built-in support for Segger J-Link/J-Trace and Atmel SAM-ICE
------------------------------------------------------------
Tracealyzer v2.3 supports Segger J-Link and J-Link compatible debuggers
directly, without any debugger IDE involved. Using other debug probes is
also possible, but requires some extra steps, described below.
If you have a Segger J-Link/J-Trace debug probe or another J-Link compatible
debug probe, just select "Read Trace" in the "J-Link" menu. Note that this
menu is only available if a compatible debug probe is found.
This opens a dialog where you get to enter the memory region where
the recorder data structure is located. Normally you select the entire
internal RAM according to the datasheet of your MCU, but the exact address
can be found can by inspecting the "RecorderData" struct or the
"RecorderDataPtr" pointer with your debugger.
J-Link compatible debug probes also include Atmel SAM-ICE and many built-in
debug interfaces on demonstration/evaluation boards (where there is a USB
connection directly to the board). Look for a Segger J-Link label on the board.
MemoryLogger extension in Atmel Studio 6
----------------------------------------
Atmel's MemoryLogger extension provides a superb integration with FreeRTOS+Trace.
Look for "MemoryLogger" in Atmel Gallery, available in Atmel Studio and at the
Atmel website (http://gallery.atmel.com).
This extension automatically detects the path to FreeRTOS+Trace, if
installed, and gives you a single-click upload/refresh. You can use it
while debugging and optionally get an automatic refresh eash time the
MCU is halted, e.g., on each breakpoint.
Using other development environments and debug probes
-----------------------------------------------------
Most debuggers are able to save the RAM contents to a file. Tracealyzer
supports the following common formats:
- Binary (.bin), supporting gdb, J-Link and Renesas HEW.
- Intel Hex (.hex), supporting IAR Embedded Workbench and Atmel Studio (atprogram.exe)
- MCH (.mch), supporting Microchip MPLAB.
When you store the RAM dump, you must also make sure to select the right region,
i.e., start address and size. The recorder data is stored in a single data
block, identified by the pointer RecorderDataPtr.
It is not necessary to match the begin and end of the recorder data, as long as
it is fully included by the dumped memory region. Tracealyzer automatically
finds the trace data in the RAM dump, thanks to special signatures. For chips
with on-chip RAM only, we therefore recommend to dump the entire RAM. This is
usually very fast.
For chips with larger amounts of (external) RAM, it is typically possible to
dump a limited region where the data is typically found.
Using IAR Embedded Workbench for ARM, version 6.3
-------------------------------------------------
In the debugger view, when stopped on a breakpoint:
- Select "Debug" menu, "Memory" submenu, "Save..." (keyboard shortcut: ALT,d,y,s)
- In the Save dialog
- Zone: Memory
- Start Adress: 10000000 (for NXP LPC1766 in the demo project)
- End Adress: 1000FFFF (for NXP LPC1766 in the demo project)
- File format: Intel Extended
- Filename: <name>.hex
- Press "Save" button
You can now open <name>.hex in Tracealyzer.
To find the right Start and End addresses, check the address of the symbol
"RecorderData". The addresses does not need to match this symbol exactly, as
long as the whole data is included.
Using Renesas High-performance Embedded Workshop v4.09
------------------------------------------------------
In the debugger view, when stopped on a breakpoint:
- Select "Debug" menu, "Save Memory..." (keyboard shortcut: ALT,d,a)
- In the Save dialog
- Format: Binary
- Filename: <name>.bin
- Start Address: 00000000 (For RX62N in the demo project)
- End Address: 0000FFFF (For RX62N in the demo project)
- Access size: 1
- Press "Save" button and open <name>.bin in Tracealyzer.
Using Microchip MPLAB v8.86
------------------------------------------------------
- Select "View" -> "File Registers". This shows you the memory contents.
- Make sure "Hex" is selected in the bottom left (instead of "Symbolic"). Hex mode seems to be default.
- Right click in the view and select "Export Table...".
- In the dialog ("Export As"), make sure "Single Column Output" is selected (seems to be default).
- Select start address 0x0000 and make sure the end address is beyond the RecorderData structure.
The default values seems to be the whole RAM, so you probably don't need to change this.
- 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).
Using STM32 ST-Link
------------------------------------------------------
- Start "ST-Link Utility"
- Connect to the device and view the device memory.
- Set the view to display the entire RAM, or at least the section containing the RecorderData structure.
- Select "Save as" and choose binary (.bin) or Intel Hex (.hex) format.
- Open the resulting file in Tracealyzer.
In case you have any question, contact support@percepio.com
Percepio AB
www.percepio.com

@ -1,57 +1,152 @@
-------------------------------------------------------------------------------
Tracealyzer for FreeRTOS - Trace Recorder Library v3.1.1
-------------------------------------------------------------------------------
Tracealyzer Trace Recorder Library
-------------------------------------
Percepio AB
www.percepio.com
This directory contains the a generic trace recorder library for Tracealyzer v3.0.2.
For information on how to upload the trace data from your target system RAM to
Tracealyzer, see the User Manual.
Files included
--------------
- trcConfig.h - The recorder's configuration file, set your recorder configuration here!
- trcUser.c/.h - The main API towards the application (trcUser.h in the only include necessary).
- trcKernel.c/.h - Internal routines for storing kernel events.
- trcBase.c/.h - Internal routines for manipulating the data structures and calculating timestamps.
- trcHardwarePort.c/.h - The hardware interface, especially for timestamping.
- trcKernelPort.h - Wrapper for trcKernelPortFreeRTOS.h (for portability).
- trcKernelPortFreeRTOS.c/.h - FreeRTOS-specific trace macros and helper functions.
- trcKernelHooks.h - Generic trace macros (OS independent), used by trcKernelPortFreeRTOS.
- trcTypes.h - Type definitions used.
Hardware Timer Ports
--------------------
This release contains hardware timer ports for the following hardware architectures:
- ARM Cortex M3/M4/M0/M0+ (all brands, such as Atmel SAM3x/SAM4x/SAM D20, NXP 17xx, 18xx, 43xx, STM32, Freescale Kinetis, ...)
- Atmel AT91SAM7x
- Atmel AT32UC3 (AVR32)
- Renesas RX600 (e.g., RX62N)
- Microchip dsPIC/PIC24
- Microchip PIC32MX
- Microchip PIC32MZ
- NXP LPC2106
- Texas Instruments TMS570 (Cortex-R4)
- Texas Instruments MSP430
- Xilinx PowerPC 405
- Xilinx PowerPC 440
- Xilinx Microblaze
- ARM Cortex-A9
These are defined in trcHardwarePort.h. Some of these are "unofficial" ports, provided by external contributors.
By unofficial, it means that they are not yet verified by Percepio AB. Please refer to trcHardwarePort.h for detailed information.
If you use an unofficial port and believe it is incorrect, please let us know! (support@percepio.com)
In case your MCU is not yet supported directly, developing a new port is quite easy, just a matter of defining a few macros
according to your specific MCU. See trcHardwarePort.h for further information.
In case you have any questions, do not hesitate to contact support@percepio.com
Percepio AB
Köpmangatan 1A
72215 Västerås
Sweden
www.percepio.com
Tracealyzer for FreeRTOS is a sophisticated tool for tracing and visualization
of FreeRTOS-based systems. Tracealyzer gives an unprecedented insight into the
runtime behavior, which speeds up debugging, validation and optimization.
To learn more about this, see
- Getting Started (videos etc): http://percepio.com/gettingstarted/tz-freertos/
- User Manual (incl. Recorder API): http://percepio.com/docs/FreeRTOS/manual
- FAQ: http://percepio.com/category/faq/
In case you have any questions, don't hesitate to contact support@percepio.com
-------------------------------------------------------------------------------
Changes, v3.1.1 -> v3.1.2
- Fixed two bugs related to User Events, one in vTracePrintF and other in vTracePrint.
- Fixed a build problem related to a single reference of the old FreeRTOS type "xTaskHandle", in trcKernelPort.c.
Changed to "TaskHandle_t", unless if using an older FreeRTOS kernel or the "compatibility mode".
- Removed traceCREATE_MUTEX hook for FreeRTOS v9 or later (no longer required)
- Updated the User Manual regarding snapshot trace via IAR Embedded Workbench.
- Renamed vTraceGetTraceBuffer to xTraceGetTraceBuffer, since returning a pointer.
-------------------------------------------------------------------------------
Changes, v3.1.0 -> v3.1.1
After the major changes in the v3.1.0 trace recorder library, this update
corrects a number of minor issues. Only minor functional improvements.
- You can now use TRC_ALLOC_CUSTOM_BUFFER to declare a trace buffer on a custom
location (using linker directives).
The related function vTraceSetRecorderDataBuffer has been promoted to the
Common API (previously only supported in snapshot mode, but custom allocation
is now generally supported also in streaming mode).
- Removed TRC_CFG_USE_LINKER_PRAGMA. No longer necessary thanks to the custom
allocation mode.
- Added support for timestamping from custom periodic timers, required for
accurate timestamping on Cortex-M0/M0+ devices when using tickless idle.
Only for streaming mode so far. See TRC_CUSTOM_TIMER_INCR / DECR.
- ARM Cortex-M port: Made sure the DWT unit is initialized properly, in case
the debugger doesn't handle this.
- ARM Cortex-M port: Added possibility to use Systick timestamping also on
Cortex-M3/M4/M7 devices (that otherwise use DWT timestamping by default).
To use this option, define the macro TRC_CFG_ARM_CM_USE_SYSTICK.
- J-Link streaming: The default RTT buffer has been changed from 0 to 1.
- J-Link streaming: The RTT buffer settings for buffer 1 and higher, are now
found in trcStreamingPort.h. Note: These settings don't apply to buffer 0.
- vTracePrint has been optimized for better performance in string logging.
- Minor performance improvement related to symbol table transfer in streaming mode.
- Timer names now registered also in streaming mode.
- Timer start and stop event are now traced.
- Implemented support for queue registry (traceQUEUE_REGISTRY_ADD) also for streaming.
- Fixed a bug related to repeated calls of vTraceEnable.
- Fixed a bug where task-switches seemed to occur even though the scheduler was disabled.
- Renamed HARDWARE_PORT_TEXAS_INSTRUMENTS_TMS570_RM48, added prefix TRC.
- Fixed several language issues in the comments and documentation.
- Fixed several minor issues and warnings from different compilers
(including PowerPC/gcc) and configurations.
-------------------------------------------------------------------------------
Changes, v3.0.9 -> v3.1.0
- Merge of previously separated snapshot and streaming recorders into a single
recorder supporting both streaming and snapshot as different modes.
- New common API for supporting both streaming and snapshot modes.
- New integration guide, see the User Manual.
- Major improvement of API documentation in source files and User Manual.
- New concept of "stream ports", giving a better structure defining streaming
interfaces, and restructured the J-Link and TCP/IP streaming as stream ports.
- Added a stream port for USB CDC connections, with STM32 as example.
Since Tracealyzer now can receive serial data on Windows COM ports, this is
really easy to use.
- Added a warning (#error) for cases where FreeRTOS tickless idle mode is used
together with timestamping using SysTick or other periodic interrupt timers,
Tracing with tickless idle requires an independent time source to correctly
capture the length of the idle periods.
- Major changes in the recorder API. Important examples are:
* Some configuration macros have changed names, e.g. for "hardware port".
Make sure to remove any old "trcConfig.h" files if upgrading from an
earlier version!
* Recorder configuration in trcConfig.h has been minimized and now only
includes the important settings that are independent of recorder mode.
Advanced settings for each mode are found in trcSnapshotConfig.h and
trcStreamingConfig.h.
* vTraceEnable replaces Trace_Init and vTraceInitTraceData, as well as
vTraceStart and uiTraceStart.
* vTraceStop now part of the common API and thereby available also in
streaming. And since vTraceEnable can start the streaming directly
you have the option control the tracing from target, e.g., for
streaming to a device file system.
* vTraceStoreKernelObjectName from old streaming recorder has been replaced
by vTraceSetQueueName, vTraceSetSemaphoreName, etc.
* vTraceSetISRProperties now returns a "traceHandle" that should be passed as
parameter to vTraceStoreISRBegin and vTraceStoreISREnd.
* xTraceRegisterString has replaced the old functions xTraceOpenLabel and
vTraceStoreUserEventChannelName. This now returns a "traceString" for use
as "channel" parameter in vTracePrintF, and in other places where strings
are stored.
* Removed vTraceStoreISREndManual and vTraceStoreISREndAuto, use
vTraceStoreISREnd instead.
* Renamed the functions for saving User Events in a separate buffer:
- xTraceRegisterChannelFormat -> xTraceRegisterUBChannel
- vTraceChannelPrintF -> vTraceUBData
- vTraceChannelUserEvent -> vTraceUBEvent
-------------------------------------------------------------------------------
Copyright Percepio AB, 2017.

@ -0,0 +1,22 @@
Tracealyzer Stream Port for SEGGER J-Link
-----------------------------------------
This directory contains a "stream port" for the Tracealyzer recorder library,
i.e., the specific code needed to use a particular interface for streaming a
Tracealyzer RTOS trace. The stream port is defined by a set of macros in
trcStreamingPort.h, found in the "include" directory.
This particular stream port targets SEGGER J-Link debug probes, using the RTT
interface provided by SEGGER.
To use this stream port, make sure that include/trcStreamingPort.h is found
by the compiler (i.e., add this folder to your project's include paths) and
add all included source files to your build. Make sure no other versions of
trcStreamingPort.h are included by mistake!
Note that this stream port also contains SEGGER's RTT driver.
See also http://percepio.com/2016/10/05/rtos-tracing.
Percepio AB
www.percepio.com

@ -0,0 +1,505 @@
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co. KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER RTT * Real Time Transfer for embedded targets *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* * This software may in its unmodified form be freely redistributed *
* in source, linkable, or executable form. *
* * The source code may be modified, provided the source code *
* retains the above copyright notice, this list of conditions and *
* the following disclaimer. *
* * Modified versions of this software in source, executable, or *
* linkable form may not be distributed without prior consent of *
* SEGGER. *
* * This software may only be used for communication with SEGGER *
* J-Link debug probes. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
* DAMAGE. *
* *
**********************************************************************
* *
* RTT version: 6.00e *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
File : SEGGER_RTT_printf.c
Purpose : Replacement for printf to write formatted data via RTT
Revision: $Rev: 3667 $
----------------------------------------------------------------------
*/
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64)
#endif
#include <stdlib.h>
#include <stdarg.h>
#define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0)
#define FORMAT_FLAG_PAD_ZERO (1u << 1)
#define FORMAT_FLAG_PRINT_SIGN (1u << 2)
#define FORMAT_FLAG_ALTERNATE (1u << 3)
/*********************************************************************
*
* Types
*
**********************************************************************
*/
typedef struct {
char* pBuffer;
unsigned BufferSize;
unsigned Cnt;
int ReturnValue;
unsigned RTTBufferIndex;
} SEGGER_RTT_PRINTF_DESC;
/*********************************************************************
*
* Function prototypes
*
**********************************************************************
*/
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _StoreChar
*/
static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) {
unsigned Cnt;
Cnt = p->Cnt;
if ((Cnt + 1u) <= p->BufferSize) {
*(p->pBuffer + Cnt) = c;
p->Cnt = Cnt + 1u;
p->ReturnValue++;
}
//
// Write part of string, when the buffer is full
//
if (p->Cnt == p->BufferSize) {
if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) {
p->ReturnValue = -1;
} else {
p->Cnt = 0u;
}
}
}
/*********************************************************************
*
* _PrintUnsigned
*/
static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
unsigned Div;
unsigned Digit;
unsigned Number;
unsigned Width;
char c;
Number = v;
Digit = 1u;
//
// Get actual field width
//
Width = 1u;
while (Number >= Base) {
Number = (Number / Base);
Width++;
}
if (NumDigits > Width) {
Width = NumDigits;
}
//
// Print leading chars if necessary
//
if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {
if (FieldWidth != 0u) {
if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {
c = '0';
} else {
c = ' ';
}
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, c);
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
if (pBufferDesc->ReturnValue >= 0) {
//
// Compute Digit.
// Loop until Digit has the value of the highest digit required.
// Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.
//
while (1) {
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)
NumDigits--;
} else {
Div = v / Digit;
if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done
break;
}
}
Digit *= Base;
}
//
// Output digits
//
do {
Div = v / Digit;
v -= Div * Digit;
_StoreChar(pBufferDesc, _aV2C[Div]);
if (pBufferDesc->ReturnValue < 0) {
break;
}
Digit /= Base;
} while (Digit);
//
// Print trailing spaces if necessary
//
if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
if (FieldWidth != 0u) {
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, ' ');
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
}
}
/*********************************************************************
*
* _PrintInt
*/
static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
unsigned Width;
int Number;
Number = (v < 0) ? -v : v;
//
// Get actual field width
//
Width = 1u;
while (Number >= (int)Base) {
Number = (Number / (int)Base);
Width++;
}
if (NumDigits > Width) {
Width = NumDigits;
}
if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
FieldWidth--;
}
//
// Print leading spaces if necessary
//
if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {
if (FieldWidth != 0u) {
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, ' ');
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
//
// Print sign if necessary
//
if (pBufferDesc->ReturnValue >= 0) {
if (v < 0) {
v = -v;
_StoreChar(pBufferDesc, '-');
} else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
_StoreChar(pBufferDesc, '+');
} else {
}
if (pBufferDesc->ReturnValue >= 0) {
//
// Print leading zeros if necessary
//
if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {
if (FieldWidth != 0u) {
while ((FieldWidth != 0u) && (Width < FieldWidth)) {
FieldWidth--;
_StoreChar(pBufferDesc, '0');
if (pBufferDesc->ReturnValue < 0) {
break;
}
}
}
}
if (pBufferDesc->ReturnValue >= 0) {
//
// Print number without sign
//
_PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags);
}
}
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* SEGGER_RTT_vprintf
*
* Function description
* Stores a formatted string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* sFormat Pointer to format string
* pParamList Pointer to the list of arguments for the format string
*
* Return values
* >= 0: Number of bytes which have been stored in the "Up"-buffer.
* < 0: Error
*/
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) {
char c;
SEGGER_RTT_PRINTF_DESC BufferDesc;
int v;
unsigned NumDigits;
unsigned FormatFlags;
unsigned FieldWidth;
char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE];
BufferDesc.pBuffer = acBuffer;
BufferDesc.BufferSize = SEGGER_RTT_PRINTF_BUFFER_SIZE;
BufferDesc.Cnt = 0u;
BufferDesc.RTTBufferIndex = BufferIndex;
BufferDesc.ReturnValue = 0;
do {
c = *sFormat;
sFormat++;
if (c == 0u) {
break;
}
if (c == '%') {
//
// Filter out flags
//
FormatFlags = 0u;
v = 1;
do {
c = *sFormat;
switch (c) {
case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break;
case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break;
case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break;
default: v = 0; break;
}
} while (v);
//
// filter out field with
//
FieldWidth = 0u;
do {
c = *sFormat;
if ((c < '0') || (c > '9')) {
break;
}
sFormat++;
FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0');
} while (1);
//
// Filter out precision (number of digits to display)
//
NumDigits = 0u;
c = *sFormat;
if (c == '.') {
sFormat++;
do {
c = *sFormat;
if ((c < '0') || (c > '9')) {
break;
}
sFormat++;
NumDigits = NumDigits * 10u + ((unsigned)c - '0');
} while (1);
}
//
// Filter out length modifier
//
c = *sFormat;
do {
if ((c == 'l') || (c == 'h')) {
sFormat++;
c = *sFormat;
} else {
break;
}
} while (1);
//
// Handle specifiers
//
switch (c) {
case 'c': {
char c0;
v = va_arg(*pParamList, int);
c0 = (char)v;
_StoreChar(&BufferDesc, c0);
break;
}
case 'd':
v = va_arg(*pParamList, int);
_PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);
break;
case 'u':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags);
break;
case 'x':
case 'X':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags);
break;
case 's':
{
const char * s = va_arg(*pParamList, const char *);
do {
c = *s;
s++;
if (c == '\0') {
break;
}
_StoreChar(&BufferDesc, c);
} while (BufferDesc.ReturnValue >= 0);
}
break;
case 'p':
v = va_arg(*pParamList, int);
_PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u);
break;
case '%':
_StoreChar(&BufferDesc, '%');
break;
default:
break;
}
sFormat++;
} else {
_StoreChar(&BufferDesc, c);
}
} while (BufferDesc.ReturnValue >= 0);
if (BufferDesc.ReturnValue > 0) {
//
// Write remaining data, if any
//
if (BufferDesc.Cnt != 0u) {
SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt);
}
BufferDesc.ReturnValue += (int)BufferDesc.Cnt;
}
return BufferDesc.ReturnValue;
}
/*********************************************************************
*
* SEGGER_RTT_printf
*
* Function description
* Stores a formatted string in SEGGER RTT control block.
* This data is read by the host.
*
* Parameters
* BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
* sFormat Pointer to format string, followed by the arguments for conversion
*
* Return values
* >= 0: Number of bytes which have been stored in the "Up"-buffer.
* < 0: Error
*
* Notes
* (1) Conversion specifications have following syntax:
* %[flags][FieldWidth][.Precision]ConversionSpecifier
* (2) Supported flags:
* -: Left justify within the field width
* +: Always print sign extension for signed conversions
* 0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision
* Supported conversion specifiers:
* c: Print the argument as one char
* d: Print the argument as a signed integer
* u: Print the argument as an unsigned integer
* x: Print the argument as an hexadecimal integer
* s: Print the string pointed to by the argument
* p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.)
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) {
int r;
va_list ParamList;
va_start(ParamList, sFormat);
r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList);
va_end(ParamList);
return r;
}
/*************************** End of file ****************************/

@ -0,0 +1,238 @@
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co. KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER RTT * Real Time Transfer for embedded targets *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* * This software may in its unmodified form be freely redistributed *
* in source, linkable, or executable form. *
* * The source code may be modified, provided the source code *
* retains the above copyright notice, this list of conditions and *
* the following disclaimer. *
* * Modified versions of this software in source, executable, or *
* linkable form may not be distributed without prior consent of *
* SEGGER. *
* * This software may only be used for communication with SEGGER *
* J-Link debug probes. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
* DAMAGE. *
* *
**********************************************************************
* *
* RTT version: 6.00e *
* *
**********************************************************************
---------------------------END-OF-HEADER------------------------------
File : SEGGER_RTT.h
Purpose : Implementation of SEGGER real-time transfer which allows
real-time communication on targets which support debugger
memory accesses while the CPU is running.
Revision: $Rev: 4079 $
----------------------------------------------------------------------
*/
#ifndef SEGGER_RTT_H
#define SEGGER_RTT_H
#include "SEGGER_RTT_Conf.h"
/*********************************************************************
*
* Defines, fixed
*
**********************************************************************
*/
/*********************************************************************
*
* Types
*
**********************************************************************
*/
//
// Description for a circular buffer (also called "ring buffer")
// which is used as up-buffer (T->H)
//
typedef struct {
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
char* pBuffer; // Pointer to start of buffer
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.
unsigned WrOff; // Position of next item to be written by either target.
volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
unsigned Flags; // Contains configuration flags
} SEGGER_RTT_BUFFER_UP;
//
// Description for a circular buffer (also called "ring buffer")
// which is used as down-buffer (H->T)
//
typedef struct {
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
char* pBuffer; // Pointer to start of buffer
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.
volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
unsigned RdOff; // Position of next item to be read by target (down-buffer).
unsigned Flags; // Contains configuration flags
} SEGGER_RTT_BUFFER_DOWN;
//
// RTT control block which describes the number of buffers available
// as well as the configuration for each buffer
//
//
typedef struct {
char acID[16]; // Initialized to "SEGGER RTT"
int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
} SEGGER_RTT_CB;
/*********************************************************************
*
* Global data
*
**********************************************************************
*/
extern SEGGER_RTT_CB _SEGGER_RTT;
/*********************************************************************
*
* RTT API functions
*
**********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
int SEGGER_RTT_GetKey (void);
unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
int SEGGER_RTT_HasKey (void);
void SEGGER_RTT_Init (void);
unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
int SEGGER_RTT_WaitKey (void);
unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
//
// Function macro for performance optimization
//
#define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
/*********************************************************************
*
* RTT "Terminal" API functions
*
**********************************************************************
*/
int SEGGER_RTT_SetTerminal (char TerminalId);
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
/*********************************************************************
*
* RTT printf functions (require SEGGER_RTT_printf.c)
*
**********************************************************************
*/
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
#ifdef __cplusplus
}
#endif
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
//
// Operating modes. Define behavior if buffer is full (not enough space for entire message)
//
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0U) // Skip. Do not block, output nothing. (Default)
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1U) // Trim: Do not block, output as much as fits.
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2U) // Block: Wait until there is space in the buffer.
#define SEGGER_RTT_MODE_MASK (3U)
//
// Control sequences, based on ANSI.
// Can be used to control color, and clear the screen
//
#define RTT_CTRL_RESET "" // Reset to default colors
#define RTT_CTRL_CLEAR "" // Clear screen, reposition cursor to top left
#define RTT_CTRL_TEXT_BLACK ""
#define RTT_CTRL_TEXT_RED ""
#define RTT_CTRL_TEXT_GREEN ""
#define RTT_CTRL_TEXT_YELLOW ""
#define RTT_CTRL_TEXT_BLUE ""
#define RTT_CTRL_TEXT_MAGENTA ""
#define RTT_CTRL_TEXT_CYAN ""
#define RTT_CTRL_TEXT_WHITE ""
#define RTT_CTRL_TEXT_BRIGHT_BLACK ""
#define RTT_CTRL_TEXT_BRIGHT_RED ""
#define RTT_CTRL_TEXT_BRIGHT_GREEN ""
#define RTT_CTRL_TEXT_BRIGHT_YELLOW ""
#define RTT_CTRL_TEXT_BRIGHT_BLUE ""
#define RTT_CTRL_TEXT_BRIGHT_MAGENTA ""
#define RTT_CTRL_TEXT_BRIGHT_CYAN ""
#define RTT_CTRL_TEXT_BRIGHT_WHITE ""
#define RTT_CTRL_BG_BLACK ""
#define RTT_CTRL_BG_RED ""
#define RTT_CTRL_BG_GREEN ""
#define RTT_CTRL_BG_YELLOW ""
#define RTT_CTRL_BG_BLUE ""
#define RTT_CTRL_BG_MAGENTA ""
#define RTT_CTRL_BG_CYAN ""
#define RTT_CTRL_BG_WHITE ""
#define RTT_CTRL_BG_BRIGHT_BLACK ""
#define RTT_CTRL_BG_BRIGHT_RED ""
#define RTT_CTRL_BG_BRIGHT_GREEN ""
#define RTT_CTRL_BG_BRIGHT_YELLOW ""
#define RTT_CTRL_BG_BRIGHT_BLUE ""
#define RTT_CTRL_BG_BRIGHT_MAGENTA ""
#define RTT_CTRL_BG_BRIGHT_CYAN ""
#define RTT_CTRL_BG_BRIGHT_WHITE ""
#endif
/*************************** End of file ****************************/

@ -0,0 +1,259 @@
/*********************************************************************
* SEGGER MICROCONTROLLER GmbH & Co. KG *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 2014 - 2016 SEGGER Microcontroller GmbH & Co. KG *
* *
* www.segger.com Support: support@segger.com *
* *
**********************************************************************
* *
* SEGGER RTT * Real Time Transfer for embedded targets *
* *
**********************************************************************
* *
* All rights reserved. *
* *
* * This software may in its unmodified form be freely redistributed *
* in source, linkable, or executable form. *
* * The source code may be modified, provided the source code *
* retains the above copyright notice, this list of conditions and *
* the following disclaimer. *
* * Modified versions of this software in source, executable, or *
* linkable form may not be distributed without prior consent of *
* SEGGER. *
* * This software may only be used for communication with SEGGER *
* J-Link debug probes. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
* DAMAGE. *
* *
**********************************************************************
* *
* RTT version: 6.00e *
* *
**********************************************************************
----------------------------------------------------------------------
File : SEGGER_RTT_Conf.h
Purpose : Implementation of SEGGER real-time transfer (RTT) which
allows real-time communication on targets which support
debugger memory accesses while the CPU is running.
Revision: $Rev: 3892 $
---------------------------END-OF-HEADER------------------------------
*/
#ifndef SEGGER_RTT_CONF_H
#define SEGGER_RTT_CONF_H
#ifdef __IAR_SYSTEMS_ICC__
#include <intrinsics.h>
#endif
/*********************************************************************
*
* Defines, configurable
*
**********************************************************************
*/
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
#define BUFFER_SIZE_UP (64) // Size of the buffer for terminal output of target, up to host (Default: 1k)
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
//
// Target is not allowed to perform other RTT operations while string still has not been stored completely.
// Otherwise we would probably end up with a mixed string in the buffer.
// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
//
// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
// (Higher priority = lower priority number)
// Default value for embOS: 128u
// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
// or define SEGGER_RTT_LOCK() to completely disable interrupts.
//
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
/*********************************************************************
*
* RTT lock configuration for SEGGER Embedded Studio,
* Rowley CrossStudio and GCC
*/
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
#ifdef __ARM_ARCH_6M__
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
__asm volatile ("mrs %0, primask \n\t" \
"mov r1, $1 \n\t" \
"msr primask, r1 \n\t" \
: "=r" (LockState) \
: \
: "r1" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
: \
: "r" (LockState) \
: \
); \
}
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
__asm volatile ("mrs %0, basepri \n\t" \
"mov r1, %1 \n\t" \
"msr basepri, r1 \n\t" \
: "=r" (LockState) \
: "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
: "r1" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
: \
: "r" (LockState) \
: \
); \
}
#elif defined(__ARM_ARCH_7A__)
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
__asm volatile ("mrs r1, CPSR \n\t" \
"mov %0, r1 \n\t" \
"orr r1, r1, #0xC0 \n\t" \
"msr CPSR_c, r1 \n\t" \
: "=r" (LockState) \
: \
: "r1" \
);
#define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
"mrs r1, CPSR \n\t" \
"bic r1, r1, #0xC0 \n\t" \
"and r0, r0, #0xC0 \n\t" \
"orr r1, r1, r0 \n\t" \
"msr CPSR_c, r1 \n\t" \
: \
: "r" (LockState) \
: "r0", "r1" \
); \
}
#else
#define SEGGER_RTT_LOCK()
#define SEGGER_RTT_UNLOCK()
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for IAR EWARM
*/
#ifdef __ICCARM__
#if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
LockState = __get_PRIMASK(); \
__set_PRIMASK(1);
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
}
#elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
LockState = __get_BASEPRI(); \
__set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
#define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration for IAR RX
*/
#ifdef __ICCRX__
#define SEGGER_RTT_LOCK() { \
unsigned long LockState; \
LockState = __get_interrupt_state(); \
__disable_interrupt();
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
}
#endif
/*********************************************************************
*
* RTT lock configuration for KEIL ARM
*/
#ifdef __CC_ARM
#if (defined __TARGET_ARCH_6S_M)
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
register unsigned char PRIMASK __asm( "primask"); \
LockState = PRIMASK; \
PRIMASK = 1u; \
__schedule_barrier();
#define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
__schedule_barrier(); \
}
#elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
#endif
#define SEGGER_RTT_LOCK() { \
unsigned int LockState; \
register unsigned char BASEPRI __asm( "basepri"); \
LockState = BASEPRI; \
BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
__schedule_barrier();
#define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
__schedule_barrier(); \
}
#endif
#endif
/*********************************************************************
*
* RTT lock configuration fallback
*/
#ifndef SEGGER_RTT_LOCK
#define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
#endif
#ifndef SEGGER_RTT_UNLOCK
#define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
#endif
#endif
/*************************** End of file ****************************/

@ -0,0 +1,192 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcStreamingPort.h
*
* The interface definitions for trace streaming ("stream ports").
* This "stream port" sets up the recorder to use SEGGER RTT as streaming channel.
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRC_STREAMING_PORT_H
#define TRC_STREAMING_PORT_H
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* Configuration Macro: TRC_CFG_RTT_BUFFER_SIZE_UP
*
* Defines the size of the "up" RTT buffer (target -> host) to use for writing
* the trace data, for RTT buffer 1 or higher.
*
* This setting is ignored for RTT buffer 0, which can't be reconfigured
* in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.
*
* Default buffer size for Tracealyzer is 5000 bytes.
*
* If you have a stand-alone J-Link probe, the can be decreased to around 1 KB.
* But integrated J-Link OB interfaces are slower and needs about 5-10 KB,
* depending on the amount of data produced.
******************************************************************************/
#define TRC_CFG_RTT_BUFFER_SIZE_UP 5000
/*******************************************************************************
* Configuration Macro: TRC_CFG_RTT_BUFFER_SIZE_DOWN
*
* Defines the size of the "down" RTT buffer (host -> target) to use for reading
* commands from Tracealyzer, for RTT buffer 1 or higher.
*
* Default buffer size for Tracealyzer is 32 bytes.
*
* This setting is ignored for RTT buffer 0, which can't be reconfigured
* in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.
******************************************************************************/
#define TRC_CFG_RTT_BUFFER_SIZE_DOWN 32
/*******************************************************************************
* Configuration Macro: TRC_CFG_RTT_UP_BUFFER_INDEX
*
* Defines the RTT buffer to use for writing the trace data. Make sure that
* the PC application has the same setting (File->Settings).
*
* Default: 1
*
* We don't recommend using RTT buffer 0, since mainly intended for terminals.
* If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h.
******************************************************************************/
#define TRC_CFG_RTT_UP_BUFFER_INDEX 1
/*******************************************************************************
* Configuration Macro: TRC_CFG_RTT_DOWN_BUFFER_INDEX
*
* Defines the RTT buffer to use for reading the trace data. Make sure that
* the PC application has the same setting (File->Settings).
*
* Default: 1
*
* We don't recommend using RTT buffer 0, since mainly intended for terminals.
* If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h.
******************************************************************************/
#define TRC_CFG_RTT_DOWN_BUFFER_INDEX 1
/*******************************************************************************
* TRC_CFG_RTT_MODE
* This stream port for J-Link streaming relies on SEGGER RTT, that contains an
* internal RAM buffer read by the J-Link probes during execution.
*
* Possible values:
* - SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (default)
* - SEGGER_RTT_MODE_NO_BLOCK_SKIP
*
* We recommend using SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL, to ensure you get a
* complete and valid trace. This may however cause blocking if your streaming
* interface isn't fast enough, which may disturb the real-time behavior.
* We therefore recommend to try SEGGER_RTT_MODE_NO_BLOCK_SKIP as well.
* In this mode, Tracealyzer will report lost events if the transfer is not
* fast enough. In that case, try increasing the size of the "up buffer".
******************************************************************************/
#define TRC_CFG_RTT_MODE SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
#include "SEGGER_RTT_Conf.h"
#include "SEGGER_RTT.h"
#if (TRC_CFG_RTT_UP_BUFFER_INDEX >= SEGGER_RTT_MAX_NUM_UP_BUFFERS)
#error "TRC_CFG_RTT_UP_BUFFER_INDEX must be smaller than SEGGER_RTT_MAX_NUM_UP_BUFFERS"
#endif
#if (TRC_CFG_RTT_DOWN_BUFFER_INDEX >= SEGGER_RTT_MAX_NUM_DOWN_BUFFERS)
#error "TRC_CFG_RTT_DOWN_BUFFER_INDEX must be smaller than SEGGER_RTT_MAX_NUM_DOWN_BUFFERS"
#endif
/* If index is defined as 0, the internal RTT buffers will be used instead of this. */
#if TRC_CFG_RTT_UP_BUFFER_INDEX == 0
#define TRC_RTT_ALLOC_UP() static char* _TzTraceData = NULL; /* Not actually used. Ignore allocation method. */
#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
#define TRC_ALLOC_CUSTOM_BUFFER(bufname) /* Only for custom allocation */
#else
#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC
#define TRC_RTT_ALLOC_UP() char _TzTraceData[TRC_CFG_RTT_BUFFER_SIZE_UP]; /* Static allocation */
#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
#define TRC_ALLOC_CUSTOM_BUFFER(bufname) /* Only for custom allocation */
#endif
#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC
#define TRC_RTT_ALLOC_UP() char* _TzTraceData = NULL; /* Dynamic allocation */
#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_CFG_RTT_BUFFER_SIZE_UP);
#define TRC_ALLOC_CUSTOM_BUFFER(bufname) /* Only for custom allocation */
#endif
#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM
#define TRC_RTT_ALLOC_UP() char* _TzTraceData = NULL; /* Custom allocation, user needs to call vTraceSetRecorderDataBuffer before vTraceEnable, to assign this */
#define TRC_STREAM_PORT_MALLOC() /* Not used in custom mode */
#define TRC_ALLOC_CUSTOM_BUFFER(bufname) char bufname [TRC_CFG_RTT_BUFFER_SIZE_UP]; /* Not static in this case, since declared in user code */
#endif
#endif
/* Down-buffer. If index is defined as 0, the internal RTT buffers will be used instead of this. */ \
#if TRC_CFG_RTT_DOWN_BUFFER_INDEX == 0
#define TRC_RTT_ALLOC_DOWN() static char* _TzCtrlData = NULL; /* Not actually used. Ignore allocation method. */
#else
#define TRC_RTT_ALLOC_DOWN() static char _TzCtrlData[TRC_CFG_RTT_BUFFER_SIZE_DOWN]; /* Always static allocation, since usually small. */
#endif
#define TRC_STREAM_PORT_ALLOCATE_FIELDS() \
TRC_RTT_ALLOC_UP() /* Macro that will result in proper UP buffer allocation */ \
TRC_RTT_ALLOC_DOWN() /* Macro that will result in proper DOWN buffer allocation */
#define TRC_STREAM_PORT_INIT() \
TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \
SEGGER_RTT_ConfigUpBuffer(TRC_CFG_RTT_UP_BUFFER_INDEX, "TzData", _TzTraceData, TRC_CFG_RTT_BUFFER_SIZE_UP, TRC_CFG_RTT_MODE ); \
SEGGER_RTT_ConfigDownBuffer(TRC_CFG_RTT_DOWN_BUFFER_INDEX, "TzCtrl", _TzCtrlData, TRC_CFG_RTT_BUFFER_SIZE_DOWN, TRC_CFG_RTT_MODE);
#define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type _tmpArray[_size / sizeof(_type)]; _type* _ptrData = _tmpArray;
#define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) _type _tmpArray[sizeof(largestEventType) / sizeof(_type)]; _type* _ptrData = _tmpArray;
#define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) SEGGER_RTT_Write(TRC_CFG_RTT_UP_BUFFER_INDEX, (const char*)_ptrData, _size);
#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);
#define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent)
#define TRC_STREAM_PORT_ON_TRACE_BEGIN() /* Do nothing */
#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */
#ifdef __cplusplus
}
#endif
#endif /* TRC_STREAMING_PORT_H */

@ -0,0 +1,22 @@
Tracealyzer Stream Port for TCP/IP (lwIP example)
-------------------------------------------------
This directory contains a "stream port" for the Tracealyzer recorder library,
i.e., the specific code needed to use a particular interface for streaming a
Tracealyzer RTOS trace. The stream port is defined by a set of macros in
trcStreamingPort.h, found in the "include" directory.
This particular stream port targets TCP/IP. This example assumes lwIP but is
easy to modify for other TCP/IP stacks.
To use this stream port, make sure that include/trcStreamingPort.h is found
by the compiler (i.e., add this folder to your project's include paths) and
add all included source files to your build. Make sure no other versions of
trcStreamingPort.h are included by mistake!
Note that lwIP is not included, but assumed to exist in the project already.
See also http://percepio.com/2016/10/05/rtos-tracing.
Percepio AB
www.percepio.com

@ -0,0 +1,90 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcStreamingPort.h
*
* The interface definitions for trace streaming ("stream ports").
* This "stream port" sets up the recorder to use TCP/IP as streaming channel.
* The example is for lwIP.
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRC_STREAMING_PORT_H
#define TRC_STREAMING_PORT_H
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* TRC_RECORDER_TRANSFER_METHOD_TCPIP
*
* This stream port for TCP/IP uses a temporary buffer consisting of multiple
* pages, that are transmitted periodically by the TzCtrl task. You can modify
* the supporting functions to match your system. See trcStreamingPort.c
******************************************************************************/
int32_t trcTcpWrite(void* data, uint32_t size, int32_t *ptrBytesWritten);
int32_t trcTcpRead(void* data, uint32_t size, int32_t *ptrBytesRead);
#if TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC
#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. */
#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
#else
#define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char* _TzTraceData = NULL; /* Dynamic allocation. */
#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE);
#endif
#define TRC_STREAM_PORT_INIT() \
TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \
prvPagedEventBufferInit(_TzTraceData);
#define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)prvPagedEventBufferGetWritePointer(_size);
#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 */
#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. */
#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcTcpRead(_ptrData, _size, _ptrBytesRead);
#define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent) prvPagedEventBufferTransfer(trcTcpWrite, _ptrBytesSent);
#define TRC_STREAM_PORT_ON_TRACE_BEGIN() prvPagedEventBufferInit(_TzTraceData);
#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */
#ifdef __cplusplus
}
#endif
#endif /* TRC_STREAMING_PORT_H */

@ -0,0 +1,183 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcStreamingPort.c
*
* Supporting functions for trace streaming, used by the "stream ports"
* for reading and writing data to the interface.
* Existing ports can easily be modified to fit another setup, e.g., a
* different TCP/IP stack, or to define your own stream port.
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#include "trcRecorder.h"
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
#if (TRC_USE_TRACEALYZER_RECORDER == 1)
/* TCP/IP includes */
#include "lwip/tcpip.h"
#include "lwip/sockets.h"
int errno;
#define TRC_TCPIP_PORT 12000
int sock = -1, new_sd = -1;
int flags = 0;
int remoteSize;
struct sockaddr_in address, remote;
int32_t trcSocketSend( void* data, int32_t size, int32_t* bytesWritten )
{
if (new_sd < 0)
return -1;
*bytesWritten = send( new_sd, data, size, 0 );
if (*bytesWritten < 0)
{
/* EWOULDBLOCK may be expected when buffers are full */
if (errno != EWOULDBLOCK)
{
closesocket(new_sd);
new_sd = -1;
return -1;
}
else
*bytesWritten = 0;
}
return 0;
}
int32_t trcSocketReceive( void* data, int32_t size, int32_t* bytesRead )
{
if (new_sd < 0)
return -1;
*bytesRead = recv( new_sd, data, size, 0 );
if ( *bytesRead < 0 )
{
/* EWOULDBLOCK may be expected when there is no data to receive */
if (errno != EWOULDBLOCK)
{
closesocket(new_sd);
new_sd = -1;
return -1;
}
else
*bytesRead = 0;
}
return 0;
}
int32_t trcSocketInitializeListener()
{
if (sock >= 0)
return 0;
sock = lwip_socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
return -1;
address.sin_family = AF_INET;
address.sin_port = htons( TRC_TCPIP_PORT );
address.sin_addr.s_addr = INADDR_ANY;
if (bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0)
{
closesocket(sock);
sock = -1;
return -1;
}
if (lwip_listen(sock, 5) < 0)
{
closesocket(sock);
sock = -1;
return -1;
}
return 0;
}
int32_t trcSocketAccept()
{
if (sock < 0)
return -1;
if (new_sd >= 0)
return 0;
remoteSize = sizeof( remote );
new_sd = accept( sock, (struct sockaddr *)&remote, (socklen_t*)&remoteSize );
flags = fcntl( new_sd, F_GETFL, 0 );
fcntl( new_sd, F_SETFL, flags | O_NONBLOCK );
if( new_sd < 0 )
{
closesocket(new_sd);
new_sd = -1;
closesocket(sock);
sock = -1;
return -1;
}
return 0;
}
/************** MODIFY THE ABOVE PART TO USE YOUR TPC/IP STACK ****************/
int32_t trcTcpWrite(void* data, uint32_t size, int32_t *ptrBytesWritten)
{
return trcSocketSend(data, size, ptrBytesWritten);
}
int32_t trcTcpRead(void* data, uint32_t size, int32_t *ptrBytesRead)
{
trcSocketInitializeListener();
trcSocketAccept();
return trcSocketReceive(data, size, ptrBytesRead);
}
#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/

@ -0,0 +1,27 @@
Tracealyzer Stream Port for USB CDC (STM32 example)
---------------------------------------------------
This directory contains a "stream port" for the Tracealyzer recorder library,
i.e., the specific code needed to use a particular interface for streaming a
Tracealyzer RTOS trace. The stream port is defined by a set of macros in
trcStreamingPort.h, found in the "include" directory.
This particular stream port targets USB CDC. This is an example for the STM32 USB
stack (from the STM32CubeMX code generation tool, v1.4.1) and has been tested on
a STM32F767ZI device on a Nucleo board. See this blog post:
http://percepio.com/2017/02/03/usb-trace-streaming-st-nucleo-f767zi-board/
However, it should be straight-forward to modify this for other USB stacks.
To use this stream port, make sure that include/trcStreamingPort.h is found
by the compiler (i.e., add this folder to your project's include paths) and
add all included source files to your build. Make sure no other versions of
trcStreamingPort.h are included by mistake!
Note that the USB stack not included, but assumed to exist in the project already.
See also http://percepio.com/2016/10/05/rtos-tracing.
Percepio AB
www.percepio.com

@ -0,0 +1,104 @@
/*******************************************************************************
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcStreamingPort.h
*
* The interface definitions for trace streaming ("stream ports").
* This "stream port" sets up the recorder to use USB CDC as streaming channel.
* The example is for STM32 using STM32Cube.
*
* Terms of Use
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#ifndef TRC_STREAMING_PORT_H
#define TRC_STREAMING_PORT_H
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* Implement the below macros to define your own stream port. If your transfer
* method uses RTOS functions, you should not send the data directly but use
* the recorder's internal buffer to store the trace data, for later transfer by
* the TzCtrl task. Check the predefined stream ports for examples on how to use
* the internal buffer (e.g., TCP/IP, UART or USB CDC).
*
* Read more at http://percepio.com/2016/10/05/rtos-tracing/
******************************************************************************/
/* Include files as needed, in this case it is files from STM32Cube FW_F7 V1.4.1 */
#include "usb_device.h"
#include "usbd_cdc.h"
#include "usbd_CDC_if.h"
#include "usb_device.h"
/* Tested on STM32 devices using Keil/CMSIS USB stack */
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
int32_t trcCDCReceive(void *data, uint32_t size, int32_t* NumBytes);
int32_t trcCDCTransmit(void* data, uint32_t size, int32_t * noOfBytesSent );
#if TRC_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC
#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. */
#define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */
#else
#define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char* _TzTraceData = NULL; /* Dynamic allocation. */
#define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_PAGED_EVENT_BUFFER_PAGE_SIZE);
#endif
#define TRC_STREAM_PORT_INIT() \
MX_USB_DEVICE_Init(); \
TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */
#define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)prvPagedEventBufferGetWritePointer(_size);
#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 */
#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. */
#define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcCDCReceive(_ptrData, _size, _ptrBytesRead);
#define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent) prvPagedEventBufferTransfer(trcCDCTransmit, _ptrBytesSent);
#define TRC_STREAM_PORT_ON_TRACE_BEGIN() { prvPagedEventBufferInit(_TzTraceData); }
#define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */
#ifdef __cplusplus
}
#endif
#endif /* TRC_STREAMING_PORT_H */

@ -0,0 +1,239 @@
#include "trcRecorder.h"
#if (TRC_USE_TRACEALYZER_RECORDER == 1)
#if(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
#include "stdint.h"
/* Include files as needed, in this case it is files from STM32Cube FW_F7 V1.4.1 */
#include "usb_device.h"
#include "usbd_cdc.h"
#include "usbd_CDC_if.h"
#include "usb_device.h"
#define BUFSIZE 64
typedef struct{
uint32_t idx;
uint8_t data[BUFSIZE];
}recBuf;
/* Define size for the receive and transmit buffer over CDC */
#define APP_RX_DATA_SIZE 8
#define APP_TX_DATA_SIZE 64
/* Received Data over USB are stored in this buffer */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
/* Send Data over USB CDC are stored in this buffer */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
extern USBD_HandleTypeDef hUsbDeviceFS;
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
recBuf commandBuffer;
static int8_t CDC_Init_FS (void);
static int8_t CDC_DeInit_FS (void);
static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length);
static int8_t CDC_Receive_FS (uint8_t* pbuf, uint32_t *Len);
USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
CDC_Init_FS,
CDC_DeInit_FS,
CDC_Control_FS,
CDC_Receive_FS
};
/* Private functions ---------------------------------------------------------*/
/**
* @brief CDC_Init_FS
* Initializes the CDC media low layer over the FS USB IP
* @param None
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Init_FS(void)
{
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
return (USBD_OK);
}
/**
* @brief CDC_DeInit_FS
* DeInitializes the CDC media low layer
* @param None
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_DeInit_FS(void)
{
return (USBD_OK);
}
/**
* @brief CDC_Control_FS
* Manage the CDC class requests
* @param cmd: Command code
* @param pbuf: Buffer containing command data (request parameters)
* @param length: Number of data to be sent (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
switch (cmd)
{
case CDC_SEND_ENCAPSULATED_COMMAND:
break;
case CDC_GET_ENCAPSULATED_RESPONSE:
break;
case CDC_SET_COMM_FEATURE:
break;
case CDC_GET_COMM_FEATURE:
break;
case CDC_CLEAR_COMM_FEATURE:
break;
/*******************************************************************************/
/* Line Coding Structure */
/*-----------------------------------------------------------------------------*/
/* Offset | Field | Size | Value | Description */
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
/* 4 | bCharFormat | 1 | Number | Stop bits */
/* 0 - 1 Stop bit */
/* 1 - 1.5 Stop bits */
/* 2 - 2 Stop bits */
/* 5 | bParityType | 1 | Number | Parity */
/* 0 - None */
/* 1 - Odd */
/* 2 - Even */
/* 3 - Mark */
/* 4 - Space */
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
/*******************************************************************************/
case CDC_SET_LINE_CODING:
break;
case CDC_GET_LINE_CODING:
break;
case CDC_SET_CONTROL_LINE_STATE:
break;
case CDC_SEND_BREAK:
break;
default:
break;
}
return (USBD_OK);
}
/**
* @brief CDC_Receive_FS
* Data received over USB OUT endpoint are sent over CDC interface
* through this function.
*
* @note
* This function will block any OUT packet reception on USB endpoint
* until exiting this function. If you exit this function before transfer
* is complete on CDC interface (i.e. using DMA controller) it will result
* in receiving more data while previous ones are still not sent.
*
* @param Buf: Buffer of data to be received
* @param Len: Number of data received (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
for( uint32_t i=0;i<* Len;i++)
{
commandBuffer.data[commandBuffer.idx]=Buf[i];
commandBuffer.idx++;
}
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
}
/**
* @brief CDC_Transmit_FS
* Data send over USB IN endpoint are sent over CDC interface
* through this function.
* @note
*
*
* @param Buf: Buffer of data to be send
* @param Len: Number of data to be send (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
*/
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
return result;
}
int32_t trcCDCReceive(void *data, uint32_t size, int32_t* NumBytes)
{
uint32_t i,diff;
if(commandBuffer.idx>0)
{
if (size >= commandBuffer.idx) // more than what is stored, number of bytes will be .idx
{
memcpy(data,commandBuffer.data, commandBuffer.idx);
*NumBytes=commandBuffer.idx;
commandBuffer.idx=0; // Make the buffer ready for a new command
}
else //If some data in the buffer is not read
{
diff = commandBuffer.idx-size;
memcpy(data,commandBuffer.data, size);
for(i=0;i<diff;i++)
{
commandBuffer.data[i]=commandBuffer.data[i+size];
}
*NumBytes=size;
commandBuffer.idx=diff;
}
}
else
{
*NumBytes=0;
}
return 0;
}
int32_t trcCDCTransmit(void* data, uint32_t size, int32_t * noOfBytesSent )
{
int32_t result;
result=CDC_Transmit_FS(data,size);
*noOfBytesSent=size;
return result;
}
/**
* @brief This function handles USB On The Go FS global interrupt.
*/
void OTG_FS_IRQHandler(void)
{
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
}
#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/

@ -1,867 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcBase.c
*
* Core functionality of the trace recorder library.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#include "trcBase.h"
#if (USE_TRACEALYZER_RECORDER == 1)
#include <stdint.h>
/*******************************************************************************
* Static data initializations
******************************************************************************/
/* Tasks and kernel objects can be explicitly excluded from the trace to reduce
buffer usage. This structure handles the exclude flags for all objects and tasks.
Note that slot 0 is not used, since not a valid handle. */
uint8_t excludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1] = { 0 };
/* Specific events can also be excluded, i.e., by the event code. This can be
used to exclude kernel calls that don't refer to a kernel object, like a delay.
This structure handle the exclude flags for all event codes */
uint8_t excludedEventCodes[NEventCodes / 8 + 1] = { 0 };
/* A set of stacks that keeps track of available object handles for each class.
The stacks are empty initially, meaning that allocation of new handles will be
based on a counter (for each object class). Any delete operation will
return the handle to the corresponding stack, for reuse on the next allocate.*/
objectHandleStackType objectHandleStacks = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };
/* Initial HWTC_COUNT value, for detecting if the time-stamping source is
enabled. If using the OS periodic timer for time-stamping, this might not
have been configured on the earliest events during the startup. */
uint32_t init_hwtc_count;
/*******************************************************************************
* RecorderData
*
* The main data structure. This is the data read by the Tracealyzer tools,
* typically through a debugger RAM dump. The recorder uses the pointer
* RecorderDataPtr for accessing this, to allow for dynamic allocation.
*
* On the NXP LPC17xx you may use the secondary RAM bank (AHB RAM) for this
* purpose. For instance, the LPC1766 has 32 KB AHB RAM which allows for
* allocating a buffer size of at least 7500 events without affecting the main
* RAM. To place RecorderData in this RAM bank using IAR Embedded Workbench
* for ARM, use this pragma right before the declaration:
*
* #pragma location="AHB_RAM_MEMORY"
*
* This of course works for other hardware architectures with additional RAM
* banks as well, just replace "AHB_RAM_MEMORY" with the section name from the
* linker .map file, or simply the desired address.
*
* For portability reasons, we don't add the pragma directly in trcBase.c, but
* in a header file included below. To include this header, you need to enable
* USE_LINKER_PRAGMA, defined in trcConfig.h.
*
* If using GCC, you need to modify the declaration as follows:
*
* RecorderDataType RecorderData __attribute__ ((section ("name"))) = ...
*
* Remember to replace "name" with the correct section name.
******************************************************************************/
static void vInitStartMarkers(void);
#if (TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_STATIC)
#if (USE_LINKER_PRAGMA == 1)
#include "recorderdata_linker_pragma.h"
#endif
RecorderDataType RecorderData;
#endif
RecorderDataType* RecorderDataPtr = NULL;
/* This version of the function dynamically allocates the trace data */
void prvTraceInitTraceData()
{
init_hwtc_count = HWTC_COUNT;
#if TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_STATIC
RecorderDataPtr = &RecorderData;
#elif TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_DYNAMIC
RecorderDataPtr = (RecorderDataType*)TRACE_MALLOC(sizeof(RecorderDataType));
#elif TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_CUSTOM
/* DO NOTHING */
#endif
TRACE_ASSERT(RecorderDataPtr != NULL, "prvTraceInitTraceData, RecorderDataPtr == NULL", );
if (! RecorderDataPtr)
{
vTraceError("No recorder data structure allocated!");
return;
}
(void)memset(RecorderDataPtr, 0, sizeof(RecorderDataType));
RecorderDataPtr->startmarker0 = 0x00;
RecorderDataPtr->startmarker1 = 0x01;
RecorderDataPtr->startmarker2 = 0x02;
RecorderDataPtr->startmarker3 = 0x03;
RecorderDataPtr->startmarker4 = 0x70;
RecorderDataPtr->startmarker5 = 0x71;
RecorderDataPtr->startmarker6 = 0x72;
RecorderDataPtr->startmarker7 = 0x73;
RecorderDataPtr->startmarker8 = 0xF0;
RecorderDataPtr->startmarker9 = 0xF1;
RecorderDataPtr->startmarker10 = 0xF2;
RecorderDataPtr->startmarker11 = 0xF3;
RecorderDataPtr->version = TRACE_KERNEL_VERSION;
RecorderDataPtr->minor_version = TRACE_MINOR_VERSION;
RecorderDataPtr->irq_priority_order = IRQ_PRIORITY_ORDER;
RecorderDataPtr->filesize = sizeof(RecorderDataType);
RecorderDataPtr->maxEvents = EVENT_BUFFER_SIZE;
RecorderDataPtr->debugMarker0 = 0xF0F0F0F0;
RecorderDataPtr->isUsing16bitHandles = USE_16BIT_OBJECT_HANDLES;
/* This function is kernel specific */
vTraceInitObjectPropertyTable();
RecorderDataPtr->debugMarker1 = 0xF1F1F1F1;
RecorderDataPtr->SymbolTable.symTableSize = SYMBOL_TABLE_SIZE;
RecorderDataPtr->SymbolTable.nextFreeSymbolIndex = 1;
#if (INCLUDE_FLOAT_SUPPORT == 1)
RecorderDataPtr->exampleFloatEncoding = 1.0f; /* otherwise already zero */
#endif
RecorderDataPtr->debugMarker2 = 0xF2F2F2F2;
(void)strncpy(RecorderDataPtr->systemInfo, "Trace Recorder Demo", 80);
RecorderDataPtr->debugMarker3 = 0xF3F3F3F3;
RecorderDataPtr->endmarker0 = 0x0A;
RecorderDataPtr->endmarker1 = 0x0B;
RecorderDataPtr->endmarker2 = 0x0C;
RecorderDataPtr->endmarker3 = 0x0D;
RecorderDataPtr->endmarker4 = 0x71;
RecorderDataPtr->endmarker5 = 0x72;
RecorderDataPtr->endmarker6 = 0x73;
RecorderDataPtr->endmarker7 = 0x74;
RecorderDataPtr->endmarker8 = 0xF1;
RecorderDataPtr->endmarker9 = 0xF2;
RecorderDataPtr->endmarker10 = 0xF3;
RecorderDataPtr->endmarker11 = 0xF4;
#if USE_SEPARATE_USER_EVENT_BUFFER
RecorderDataPtr->userEventBuffer.bufferID = 1;
RecorderDataPtr->userEventBuffer.version = 0;
RecorderDataPtr->userEventBuffer.numberOfSlots = USER_EVENT_BUFFER_SIZE;
RecorderDataPtr->userEventBuffer.numberOfChannels = CHANNEL_FORMAT_PAIRS + 1;
#endif
/* Kernel specific initialization of the objectHandleStacks variable */
vTraceInitObjectHandleStack();
/* Fix the start markers of the trace data structure */
vInitStartMarkers();
#ifdef PORT_SPECIFIC_INIT
PORT_SPECIFIC_INIT();
#endif
}
static void vInitStartMarkers()
{
uint32_t i;
uint8_t *ptr = (uint8_t*)&(RecorderDataPtr->startmarker0);
if ((*ptr) == 0)
{
for (i = 0; i < 12; i++)
{
ptr[i] += 1;
}
}
else
{
vTraceError("Trace start markers already initialized!");
}
}
volatile int recorder_busy = 0;
/* Gives the last error message of the recorder. NULL if no error message. */
const char* traceErrorMessage = NULL;
void* xTraceNextFreeEventBufferSlot(void)
{
if (! RecorderDataPtr->recorderActive)
{
// If the associated XTS or XPS event prio to the main event has filled the buffer and store mode "stop when full".
return NULL;
}
if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)
{
vTraceError("Attempt to index outside event buffer!");
return NULL;
}
return (void*)(&RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex*4]);
}
uint16_t uiIndexOfObject(objectHandleType objecthandle, uint8_t objectclass)
{
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"uiIndexOfObject: Invalid value for objectclass", 0);
TRACE_ASSERT(objecthandle > 0 && objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"uiIndexOfObject: Invalid value for objecthandle", 0);
if ((objectclass < TRACE_NCLASSES) && (objecthandle > 0) &&
(objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass]))
{
return (uint16_t)(RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[objectclass] +
(RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[objectclass] * (objecthandle-1)));
}
vTraceError("Object table lookup with invalid object handle or object class!");
return 0;
}
/*******************************************************************************
* Object handle system
* This provides a mechanism to assign each kernel object (tasks, queues, etc)
* with a 1-byte handle, that is used to identify the object in the trace.
* This way, only one byte instead of four is necessary to identify the object.
* This allows for maximum 255 objects, of each object class, active at any
* moment.
* Note that zero is reserved as an error code and is not a valid handle.
*
* In order to allow for fast dynamic allocation and release of object handles,
* the handles of each object class (e.g., TASK) are stored in a stack. When a
* handle is needed, e.g., on task creation, the next free handle is popped from
* the stack. When an object (e.g., task) is deleted, its handle is pushed back
* on the stack and can thereby be reused for other objects.
*
* Since this allows for reuse of object handles, a specific handle (e.g, "8")
* may refer to TASK_X at one point, and later mean "TASK_Y". To resolve this,
* the recorder uses "Close events", which are stored in the main event buffer
* when objects are deleted and their handles are released. The close event
* contains the mapping between object handle and object name which was valid up
* to this point in time. The object name is stored as a symbol table entry.
******************************************************************************/
objectHandleType xTraceGetObjectHandle(traceObjectClass objectclass)
{
objectHandleType handle;
static int indexOfHandle;
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"xTraceGetObjectHandle: Invalid value for objectclass", (objectHandleType)0);
indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];
if (objectHandleStacks.objectHandles[indexOfHandle] == 0)
{
/* Zero is used to indicate a never before used handle, i.e.,
new slots in the handle stack. The handle slot needs to
be initialized here (starts at 1). */
objectHandleStacks.objectHandles[indexOfHandle] =
(objectHandleType)(1 + indexOfHandle -
objectHandleStacks.lowestIndexOfClass[objectclass]);
}
handle = objectHandleStacks.objectHandles[indexOfHandle];
if (objectHandleStacks.indexOfNextAvailableHandle[objectclass]
> objectHandleStacks.highestIndexOfClass[objectclass])
{
/* ERROR */
vTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));
handle = 0; /* an invalid/anonymous handle - but the recorder is stopped now... */
}
else
{
int hndCount;
objectHandleStacks.indexOfNextAvailableHandle[objectclass]++;
hndCount = objectHandleStacks.indexOfNextAvailableHandle[objectclass] -
objectHandleStacks.lowestIndexOfClass[objectclass];
if (hndCount >
objectHandleStacks.handleCountWaterMarksOfClass[objectclass])
{
objectHandleStacks.handleCountWaterMarksOfClass[objectclass] =
(objectHandleType)hndCount;
}
TRACE_CLEAR_OBJECT_FLAG_ISEXCLUDED(objectclass, handle);
}
return handle;
}
void vTraceFreeObjectHandle(traceObjectClass objectclass, objectHandleType handle)
{
int indexOfHandle;
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"vTraceFreeObjectHandle: Invalid value for objectclass", );
TRACE_ASSERT(handle > 0 && handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"vTraceFreeObjectHandle: Invalid value for handle", );
/* Check that there is room to push the handle on the stack */
if ((objectHandleStacks.indexOfNextAvailableHandle[objectclass] - 1) <
objectHandleStacks.lowestIndexOfClass[objectclass])
{
/* Error */
vTraceError("Attempt to free more handles than allocated!");
}
else
{
objectHandleStacks.indexOfNextAvailableHandle[objectclass]--;
indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];
objectHandleStacks.objectHandles[indexOfHandle] = handle;
}
}
/*******************************************************************************
* Objects Property Table
*
* This holds the names and properties of the currently active objects, such as
* tasks and queues. This is developed to support "dynamic" objects which might
* be deleted during runtime. Their handles are only valid during their
* lifetime, i.e., from create to delete, as they might be reused on later
* create operations. When an object is deleted from the OPT, its data is moved
* to the trace buffer and/or the symbol table.
* When an object (task, queue, etc.) is created, it receives a handle, which
* together with the object class specifies its location in the OPT. Thus,
* objects of different types may share the same name and/or handle, but still
* be independent objects.
******************************************************************************/
/*******************************************************************************
* vTraceSetObjectName
*
* Registers the names of queues, semaphores and other kernel objects in the
* recorder's Object Property Table, at the given handle and object class.
******************************************************************************/
void vTraceSetObjectName(traceObjectClass objectclass,
objectHandleType handle,
const char* name)
{
static uint16_t idx;
TRACE_ASSERT(name != NULL, "vTraceSetObjectName: name == NULL", );
if (objectclass >= TRACE_NCLASSES)
{
vTraceError("Illegal object class in vTraceSetObjectName");
return;
}
if (handle == 0)
{
vTraceError("Illegal handle (0) in vTraceSetObjectName.");
return;
}
if (handle > RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass])
{
/* ERROR */
vTraceError(pszTraceGetErrorNotEnoughHandles(objectclass));
}
else
{
idx = uiIndexOfObject(handle, objectclass);
if (traceErrorMessage == NULL)
{
(void)strncpy((char*)&(RecorderDataPtr->ObjectPropertyTable.objbytes[idx]),
name,
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[ objectclass ]);
}
}
}
traceLabel prvTraceOpenSymbol(const char* name, traceLabel userEventChannel)
{
uint16_t result;
uint8_t len;
uint8_t crc;
TRACE_SR_ALLOC_CRITICAL_SECTION();
len = 0;
crc = 0;
TRACE_ASSERT(name != NULL, "prvTraceOpenSymbol: name == NULL", (traceLabel)0);
prvTraceGetChecksum(name, &crc, &len);
trcCRITICAL_SECTION_BEGIN();
result = prvTraceLookupSymbolTableEntry(name, crc, len, userEventChannel);
if (!result)
{
result = prvTraceCreateSymbolTableEntry(name, crc, len, userEventChannel);
}
trcCRITICAL_SECTION_END();
return result;
}
/*******************************************************************************
* Supporting functions
******************************************************************************/
/*******************************************************************************
* vTraceError
*
* Called by various parts in the recorder. Stops the recorder and stores a
* pointer to an error message, which is printed by the monitor task.
* If you are not using the monitor task, you may use xTraceGetLastError()
* from your application to check if the recorder is OK.
*
* Note: If a recorder error is registered before vTraceStart is called, the
* trace start will be aborted. This can occur if any of the Nxxxx constants
* (e.g., NTask) in trcConfig.h is too small.
******************************************************************************/
void vTraceError(const char* msg)
{
TRACE_ASSERT(msg != NULL, "vTraceError: msg == NULL", );
TRACE_ASSERT(RecorderDataPtr != NULL, "vTraceError: RecorderDataPtr == NULL", );
/* Stop the recorder. Note: We do not call vTraceStop, since that adds a weird
and unnecessary dependency to trcUser.c */
RecorderDataPtr->recorderActive = 0;
if (traceErrorMessage == NULL)
{
traceErrorMessage = msg;
(void)strncpy(RecorderDataPtr->systemInfo, traceErrorMessage, 80);
RecorderDataPtr->internalErrorOccured = 1;
}
}
/******************************************************************************
* prvCheckDataToBeOverwrittenForMultiEntryEvents
*
* This checks if the next event to be overwritten is a multi-entry user event,
* i.e., a USER_EVENT followed by data entries.
* Such data entries do not have an event code at byte 0, as other events.
* All 4 bytes are user data, so the first byte of such data events must
* not be interpreted as type field. The number of data entries following
* a USER_EVENT is given in the event code of the USER_EVENT.
* Therefore, when overwriting a USER_EVENT (when using in ringbuffer mode)
* any data entries following must be replaced with NULL events (code 0).
*
* This is assumed to execute within a critical section...
*****************************************************************************/
void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nofEntriesToCheck)
{
/* Generic "int" type is desired - should be 16 bit variable on 16 bit HW */
unsigned int i = 0;
unsigned int e = 0;
TRACE_ASSERT(nofEntriesToCheck != 0,
"prvCheckDataToBeOverwrittenForMultiEntryEvents: nofEntriesToCheck == 0", );
while (i < nofEntriesToCheck)
{
e = RecorderDataPtr->nextFreeIndex + i;
if ((RecorderDataPtr->eventData[e*4] > USER_EVENT) &&
(RecorderDataPtr->eventData[e*4] < USER_EVENT + 16))
{
uint8_t nDataEvents = (uint8_t)(RecorderDataPtr->eventData[e*4] - USER_EVENT);
if ((e + nDataEvents) < RecorderDataPtr->maxEvents)
{
(void)memset(& RecorderDataPtr->eventData[e*4], 0, 4 + 4 * nDataEvents);
}
}
else if (RecorderDataPtr->eventData[e*4] == DIV_XPS)
{
if ((e + 1) < RecorderDataPtr->maxEvents)
{
/* Clear 8 bytes */
(void)memset(& RecorderDataPtr->eventData[e*4], 0, 4 + 4);
}
else
{
/* Clear 8 bytes, 4 first and 4 last */
(void)memset(& RecorderDataPtr->eventData[0], 0, 4);
(void)memset(& RecorderDataPtr->eventData[e*4], 0, 4);
}
}
i++;
}
}
/*******************************************************************************
* prvTraceUpdateCounters
*
* Updates the index of the event buffer.
******************************************************************************/
void prvTraceUpdateCounters(void)
{
if (RecorderDataPtr->recorderActive == 0)
{
return;
}
RecorderDataPtr->numEvents++;
RecorderDataPtr->nextFreeIndex++;
if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)
{
#if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)
RecorderDataPtr->bufferIsFull = 1;
RecorderDataPtr->nextFreeIndex = 0;
#else
vTraceStop();
#endif
}
#if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)
prvCheckDataToBeOverwrittenForMultiEntryEvents(1);
#endif
}
/******************************************************************************
* prvTraceGetDTS
*
* Returns a differential timestamp (DTS), i.e., the time since
* last event, and creates an XTS event if the DTS does not fit in the
* number of bits given. The XTS event holds the MSB bytes of the DTS.
*
* The parameter param_maxDTS should be 0xFF for 8-bit dts or 0xFFFF for
* events with 16-bit dts fields.
*****************************************************************************/
uint16_t prvTraceGetDTS(uint16_t param_maxDTS)
{
static uint32_t old_timestamp = 0;
XTSEvent* xts = 0;
uint32_t dts = 0;
uint32_t timestamp = 0;
TRACE_ASSERT(param_maxDTS == 0xFF || param_maxDTS == 0xFFFF, "prvTraceGetDTS: Invalid value for param_maxDTS", 0);
#if (SELECTED_PORT != PORT_ARM_CortexM)
if (RecorderDataPtr->frequency == 0 && init_hwtc_count != HWTC_COUNT)
{
/* If HWTC_PERIOD is mapped to the timer reload register,
it might not be initialized before the scheduler has been started.
We therefore store the frequency of the timer when the counter
register has changed from its initial value.
(Note that this function is called also by vTraceStart and
uiTraceStart, which might be called before the scheduler
has been started.) */
#if (SELECTED_PORT == PORT_Win32)
RecorderDataPtr->frequency = 100000;
#elif (SELECTED_PORT == PORT_HWIndependent)
RecorderDataPtr->frequency = TRACE_TICK_RATE_HZ;
#else
RecorderDataPtr->frequency = (HWTC_PERIOD * TRACE_TICK_RATE_HZ) / (uint32_t)HWTC_DIVISOR;
#endif
}
#endif
/**************************************************************************
* The below statements read the timestamp from the timer port module.
* If necessary, whole seconds are extracted using division while the rest
* comes from the modulo operation.
**************************************************************************/
vTracePortGetTimeStamp(&timestamp);
/***************************************************************************
* Since dts is unsigned the result will be correct even if timestamp has
* wrapped around.
***************************************************************************/
dts = timestamp - old_timestamp;
old_timestamp = timestamp;
if (RecorderDataPtr->frequency > 0)
{
/* Check if dts > 1 second */
if (dts > RecorderDataPtr->frequency)
{
/* More than 1 second has passed */
RecorderDataPtr->absTimeLastEventSecond += dts / RecorderDataPtr->frequency;
/* The part that is not an entire second is added to absTimeLastEvent */
RecorderDataPtr->absTimeLastEvent += dts % RecorderDataPtr->frequency;
}
else
{
RecorderDataPtr->absTimeLastEvent += dts;
}
/* Check if absTimeLastEvent >= 1 second */
if (RecorderDataPtr->absTimeLastEvent >= RecorderDataPtr->frequency)
{
/* RecorderDataPtr->absTimeLastEvent is more than or equal to 1 second, but always less than 2 seconds */
RecorderDataPtr->absTimeLastEventSecond++;
RecorderDataPtr->absTimeLastEvent -= RecorderDataPtr->frequency;
/* RecorderDataPtr->absTimeLastEvent is now less than 1 second */
}
}
else
{
/* Special case if the recorder has not yet started (frequency may be uninitialized, i.e., zero) */
RecorderDataPtr->absTimeLastEvent = timestamp;
}
/* If the dts (time since last event) does not fit in event->dts (only 8 or 16 bits) */
if (dts > param_maxDTS)
{
/* Create an XTS event (eXtended TimeStamp) containing the higher dts bits*/
xts = (XTSEvent*) xTraceNextFreeEventBufferSlot();
if (xts != NULL)
{
if (param_maxDTS == 0xFFFF)
{
xts->type = XTS16;
xts->xts_16 = (uint16_t)((dts / 0x10000) & 0xFFFF);
xts->xts_8 = 0;
}
else if (param_maxDTS == 0xFF)
{
xts->type = XTS8;
xts->xts_16 = (uint16_t)((dts / 0x100) & 0xFFFF);
xts->xts_8 = (uint8_t)((dts / 0x1000000) & 0xFF);
}
else
{
vTraceError("Bad param_maxDTS in prvTraceGetDTS");
}
prvTraceUpdateCounters();
}
}
return (uint16_t)dts & param_maxDTS;
}
/*******************************************************************************
* prvTraceLookupSymbolTableEntry
*
* Find an entry in the symbol table, return 0 if not present.
*
* The strings are stored in a byte pool, with four bytes of "meta-data" for
* every string.
* byte 0-1: index of next entry with same checksum (for fast lookup).
* byte 2-3: reference to a symbol table entry, a label for vTracePrintF
* format strings only (the handle of the destination channel).
* byte 4..(4 + length): the string (object name or user event label), with
* zero-termination
******************************************************************************/
traceLabel prvTraceLookupSymbolTableEntry(const char* name,
uint8_t crc6,
uint8_t len,
traceLabel chn)
{
uint16_t i = RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ];
TRACE_ASSERT(name != NULL, "prvTraceLookupSymbolTableEntry: name == NULL", (traceLabel)0);
TRACE_ASSERT(len != 0, "prvTraceLookupSymbolTableEntry: len == 0", (traceLabel)0);
while (i != 0)
{
if (RecorderDataPtr->SymbolTable.symbytes[i + 2] == (chn & 0x00FF))
{
if (RecorderDataPtr->SymbolTable.symbytes[i + 3] == (chn / 0x100))
{
if (RecorderDataPtr->SymbolTable.symbytes[i + 4 + len] == '\0')
{
if (strncmp((char*)(& RecorderDataPtr->SymbolTable.symbytes[i + 4]), name, len) == 0)
{
break; /* found */
}
}
}
}
i = (uint16_t)(RecorderDataPtr->SymbolTable.symbytes[i] + (RecorderDataPtr->SymbolTable.symbytes[i + 1] * 0x100));
}
return i;
}
/*******************************************************************************
* prvTraceCreateSymbolTableEntry
*
* Creates an entry in the symbol table, independent if it exists already.
*
* The strings are stored in a byte pool, with four bytes of "meta-data" for
* every string.
* byte 0-1: index of next entry with same checksum (for fast lookup).
* byte 2-3: reference to a symbol table entry, a label for vTracePrintF
* format strings only (the handle of the destination channel).
* byte 4..(4 + length): the string (object name or user event label), with
* zero-termination
******************************************************************************/
uint16_t prvTraceCreateSymbolTableEntry(const char* name,
uint8_t crc6,
uint8_t len,
traceLabel channel)
{
uint16_t ret = 0;
TRACE_ASSERT(name != NULL, "prvTraceCreateSymbolTableEntry: name == NULL", 0);
TRACE_ASSERT(len != 0, "prvTraceCreateSymbolTableEntry: len == 0", 0);
if (RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + len + 4 >= SYMBOL_TABLE_SIZE)
{
vTraceError("Symbol table full. Increase SYMBOL_TABLE_SIZE in trcConfig.h");
ret = 0;
}
else
{
RecorderDataPtr->SymbolTable.symbytes
[ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex] =
(uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] & 0x00FF);
RecorderDataPtr->SymbolTable.symbytes
[ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 1] =
(uint8_t)(RecorderDataPtr->SymbolTable.latestEntryOfChecksum[ crc6 ] / 0x100);
RecorderDataPtr->SymbolTable.symbytes
[ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 2] =
(uint8_t)(channel & 0x00FF);
RecorderDataPtr->SymbolTable.symbytes
[ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 3] =
(uint8_t)(channel / 0x100);
/* set name (bytes 4...4+len-1) */
(void)strncpy((char*)&(RecorderDataPtr->SymbolTable.symbytes
[ RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4]), name, len);
/* Set zero termination (at offset 4+len) */
RecorderDataPtr->SymbolTable.symbytes
[RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + 4 + len] = '\0';
/* store index of entry (for return value, and as head of LL[crc6]) */
RecorderDataPtr->SymbolTable.latestEntryOfChecksum
[ crc6 ] = (uint16_t)RecorderDataPtr->SymbolTable.nextFreeSymbolIndex;
RecorderDataPtr->SymbolTable.nextFreeSymbolIndex += (len + 5);
ret = (uint16_t)(RecorderDataPtr->SymbolTable.nextFreeSymbolIndex -
(len + 5));
}
return ret;
}
/*******************************************************************************
* prvTraceGetChecksum
*
* Calculates a simple 6-bit checksum from a string, used to index the string
* for fast symbol table lookup.
******************************************************************************/
void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength)
{
unsigned char c;
int length = 1; /* Should be 1 to account for '\0' */
int crc = 0;
TRACE_ASSERT(pname != NULL, "prvTraceGetChecksum: pname == NULL", );
TRACE_ASSERT(pcrc != NULL, "prvTraceGetChecksum: pcrc == NULL", );
TRACE_ASSERT(plength != NULL, "prvTraceGetChecksum: plength == NULL", );
if (pname != (const char *) 0)
{
for (; (c = *pname++) != '\0';)
{
crc += c;
length++;
}
}
*pcrc = (uint8_t)(crc & 0x3F);
*plength = (uint8_t)length;
}
#if (USE_16BIT_OBJECT_HANDLES == 1)
void prvTraceStoreXID(objectHandleType handle);
/******************************************************************************
* prvTraceStoreXID
*
* Stores an XID (eXtended IDentifier) event.
* This is used if an object/task handle is larger than 255.
* The parameter "handle" is the full (16 bit) handle, assumed to be 256 or
* larger. Handles below 256 should not use this function.
*
* NOTE: this function MUST be called from within a critical section.
*****************************************************************************/
void prvTraceStoreXID(objectHandleType handle)
{
XPSEvent* xid;
TRACE_ASSERT(handle >= 256, "prvTraceStoreXID: Handle < 256", );
xid = (XPSEvent*)xTraceNextFreeEventBufferSlot();
if (xid != NULL)
{
xid->type = XID;
/* This function is (only) used when objectHandleType is 16 bit... */
xid->xps_16 = handle;
prvTraceUpdateCounters();
}
}
unsigned char prvTraceGet8BitHandle(objectHandleType handle)
{
if (handle > 255)
{
prvTraceStoreXID(handle);
/* The full handle (16 bit) is stored in the XID event.
This code (255) is used instead of zero (which is an error code).*/
return 255;
}
return (unsigned char)(handle & 0xFF);
}
#endif
#endif

@ -1,186 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcHardwarePort.c
*
* Contains together with trcHardwarePort.h all hardware portability issues of
* the trace recorder library.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcPort.c and trcPort.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#include "trcHardwarePort.h"
#include "trcKernelPort.h"
#if (USE_TRACEALYZER_RECORDER == 1)
#include <stdint.h>
uint32_t trace_disable_timestamp = 0;
uint32_t last_timestamp = 0;
/*******************************************************************************
* uiTraceTickCount
*
* This variable is should be updated by the Kernel tick interrupt. This does
* not need to be modified when developing a new timer port. It is preferred to
* keep any timer port changes in the HWTC macro definitions, which typically
* give sufficient flexibility.
******************************************************************************/
uint32_t uiTraceTickCount = 0;
uint32_t DWT_CYCLES_ADDED = 0; /* Used on ARM Cortex-M only */
#if (SELECTED_PORT == PORT_ARM_CortexM)
void prvTraceInitCortexM()
{
/* Make sure DWT is enabled is enabled, if supported */
REG_DEMCR |= DEMCR_TRCENA;
do{
/* Verify that DWT is supported */
if (REG_DEMCR == 0)
{
vTraceError("DWT not supported by this chip!");
break;
}
/* Verify that DWT_CYCCNT is supported */
if (REG_DWT_CTRL & DWT_CTRL_NOCYCCNT)
{
vTraceError("DWT_CYCCNT not supported by this chip!");
break;
}
/* Reset the cycle counter */
REG_DWT_CYCCNT = 0;
/* Enable the cycle counter */
REG_DWT_CTRL |= DWT_CTRL_CYCCNTENA;
}while(0); /* breaks above jump here */
if (RecorderDataPtr->frequency == 0)
{
RecorderDataPtr->frequency = TRACE_CPU_CLOCK_HZ / HWTC_DIVISOR;
}
}
#endif
/******************************************************************************
* vTracePortGetTimeStamp
*
* Returns the current time based on the HWTC macros which provide a hardware
* isolation layer towards the hardware timer/counter.
*
* The HWTC macros and vTracePortGetTimeStamp is the main porting issue
* or the trace recorder library. Typically you should not need to change
* the code of vTracePortGetTimeStamp if using the HWTC macros.
*
******************************************************************************/
void vTracePortGetTimeStamp(uint32_t *pTimestamp)
{
static uint32_t last_traceTickCount = 0;
static uint32_t last_hwtc_count = 0;
uint32_t traceTickCount = 0;
uint32_t hwtc_count = 0;
if (trace_disable_timestamp == 1)
{
if (pTimestamp)
*pTimestamp = last_timestamp;
return;
}
/* Retrieve HWTC_COUNT only once since the same value should be used all throughout this function. */
#if (HWTC_COUNT_DIRECTION == DIRECTION_INCREMENTING)
hwtc_count = HWTC_COUNT;
#elif (HWTC_COUNT_DIRECTION == DIRECTION_DECREMENTING)
hwtc_count = HWTC_PERIOD - HWTC_COUNT;
#else
Junk text to cause compiler error - HWTC_COUNT_DIRECTION is not set correctly!
Should be DIRECTION_INCREMENTING or DIRECTION_DECREMENTING
#endif
#if (SELECTED_PORT == PORT_Win32)
/* The Win32 port uses ulGetRunTimeCounterValue for timestamping, which in turn
uses QueryPerformanceCounter. That function is not always reliable when used over
multiple threads. We must therefore handle rare cases where the timestamp is less
than the previous. In practice, the Win32 should "never" roll over since the
performance counter is 64 bit wide. */
if (last_hwtc_count > hwtc_count)
{
hwtc_count = last_hwtc_count;
}
#endif
if (last_traceTickCount - uiTraceTickCount - 1 < 0x80000000)
{
/* This means last_traceTickCount is higher than uiTraceTickCount,
so we have previously compensated for a missed tick.
Therefore we use the last stored value because that is more accurate. */
traceTickCount = last_traceTickCount;
}
else
{
/* Business as usual */
traceTickCount = uiTraceTickCount;
}
/* Check for overflow. May occur if the update of uiTraceTickCount has been
delayed due to disabled interrupts. */
if (traceTickCount == last_traceTickCount && hwtc_count < last_hwtc_count)
{
/* A trace tick has occurred but not been executed by the kernel, so we compensate manually. */
traceTickCount++;
}
/* Check if the return address is OK, then we perform the calculation. */
if (pTimestamp)
{
/* Get timestamp from trace ticks. Scale down the period to avoid unwanted overflows. */
*pTimestamp = traceTickCount * (HWTC_PERIOD / HWTC_DIVISOR);
/* Increase timestamp by (hwtc_count + "lost hardware ticks from scaling down period") / HWTC_DIVISOR. */
*pTimestamp += (hwtc_count + traceTickCount * (HWTC_PERIOD % HWTC_DIVISOR)) / HWTC_DIVISOR;
last_timestamp = *pTimestamp;
}
/* Store the previous values. */
last_traceTickCount = traceTickCount;
last_hwtc_count = hwtc_count;
}
#endif

@ -1,679 +0,0 @@
/*******************************************************************************
* Tracealyzer v3.0.2 Recorder Library
* Percepio AB, www.percepio.com
*
* trcKernel.c
*
* Functions used by trcKernelHooks.h for storing various kernel events.
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2014.
* www.percepio.com
******************************************************************************/
#include "trcKernel.h"
#if (USE_TRACEALYZER_RECORDER == 1)
#include <stdint.h>
/* Internal variables */
int8_t nISRactive = 0;
objectHandleType handle_of_last_logged_task = 0;
uint8_t inExcludedTask = 0;
#if (INCLUDE_MEMMANG_EVENTS == 1) && (TRACE_SCHEDULING_ONLY == 0)
/* Current heap usage. Always updated. */
static uint32_t heapMemUsage = 0;
#endif
#if (TRACE_SCHEDULING_ONLY == 0)
static uint32_t prvTraceGetParam(uint32_t, uint32_t);
#endif
#if !defined INCLUDE_READY_EVENTS || INCLUDE_READY_EVENTS == 1
static int readyEventsEnabled = 1;
void vTraceSetReadyEventsEnabled(int status)
{
readyEventsEnabled = status;
}
/*******************************************************************************
* vTraceStoreTaskReady
*
* This function stores a ready state for the task handle sent in as parameter.
******************************************************************************/
void vTraceStoreTaskReady(objectHandleType handle)
{
uint16_t dts3;
TREvent* tr;
uint8_t hnd8;
TRACE_SR_ALLOC_CRITICAL_SECTION();
if (handle == 0)
{
/* On FreeRTOS v7.3.0, this occurs when creating tasks due to a bad
placement of the trace macro. In that case, the events are ignored. */
return;
}
if (! readyEventsEnabled)
{
/* When creating tasks, ready events are also created. If creating
a "hidden" (not traced) task, we must therefore disable recording
of ready events to avoid an undesired ready event... */
return;
}
TRACE_ASSERT(handle <= NTask, "vTraceStoreTaskReady: Invalid value for handle", );
if (recorder_busy)
{
/***********************************************************************
* This should never occur, as the tick- and kernel call ISR is on lowest
* interrupt priority and always are disabled during the critical sections
* of the recorder.
***********************************************************************/
vTraceError("Recorder busy - high priority ISR using syscall? (1)");
return;
}
trcCRITICAL_SECTION_BEGIN();
if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
{
if (!TRACE_GET_TASK_FLAG_ISEXCLUDED(handle))
{
dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);
hnd8 = prvTraceGet8BitHandle(handle);
tr = (TREvent*)xTraceNextFreeEventBufferSlot();
if (tr != NULL)
{
tr->type = DIV_TASK_READY;
tr->dts = dts3;
tr->objHandle = hnd8;
prvTraceUpdateCounters();
}
}
}
trcCRITICAL_SECTION_END();
}
#endif
/*******************************************************************************
* vTraceStoreLowPower
*
* This function stores a low power state.
******************************************************************************/
void vTraceStoreLowPower(uint32_t flag)
{
uint16_t dts;
LPEvent* lp;
TRACE_SR_ALLOC_CRITICAL_SECTION();
TRACE_ASSERT(flag <= 1, "vTraceStoreLowPower: Invalid flag value", );
if (recorder_busy)
{
/***********************************************************************
* This should never occur, as the tick- and kernel call ISR is on lowest
* interrupt priority and always are disabled during the critical sections
* of the recorder.
***********************************************************************/
vTraceError("Recorder busy - high priority ISR using syscall? (1)");
return;
}
trcCRITICAL_SECTION_BEGIN();
if (RecorderDataPtr->recorderActive)
{
dts = (uint16_t)prvTraceGetDTS(0xFFFF);
lp = (LPEvent*)xTraceNextFreeEventBufferSlot();
if (lp != NULL)
{
lp->type = LOW_POWER_BEGIN + ( uint8_t ) flag; /* BEGIN or END depending on flag */
lp->dts = dts;
prvTraceUpdateCounters();
}
}
trcCRITICAL_SECTION_END();
}
/*******************************************************************************
* vTraceStoreMemMangEvent
*
* This function stores malloc and free events. Each call requires two records,
* for size and address respectively. The event code parameter (ecode) is applied
* to the first record (size) and the following address record gets event
* code "ecode + 1", so make sure this is respected in the event code table.
* Note: On "free" calls, the signed_size parameter should be negative.
******************************************************************************/
#if (INCLUDE_MEMMANG_EVENTS == 1)
void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_size)
{
#if (TRACE_SCHEDULING_ONLY == 0)
uint8_t dts1;
MemEventSize * ms;
MemEventAddr * ma;
uint16_t size_low;
uint16_t addr_low;
uint8_t addr_high;
uint32_t size;
TRACE_SR_ALLOC_CRITICAL_SECTION();
if (RecorderDataPtr == NULL) // This happens in vTraceInitTraceData, if using dynamic allocation...
return;
if (signed_size < 0)
size = (uint32_t)(- signed_size);
else
size = (uint32_t)(signed_size);
trcCRITICAL_SECTION_BEGIN();
heapMemUsage += signed_size;
if (RecorderDataPtr->recorderActive)
{
/* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */
if (nISRactive || !inExcludedTask)
{
dts1 = (uint8_t)prvTraceGetDTS(0xFF);
size_low = (uint16_t)prvTraceGetParam(0xFFFF, size);
ms = (MemEventSize *)xTraceNextFreeEventBufferSlot();
if (ms != NULL)
{
ms->dts = dts1;
ms->type = NULL_EVENT; /* Updated when all events are written */
ms->size = size_low;
prvTraceUpdateCounters();
/* Storing a second record with address (signals "failed" if null) */
#if (HEAP_SIZE_BELOW_16M)
/* If the heap address range is within 16 MB, i.e., the upper 8 bits
of addresses are constant, this optimization avoids storing an extra
event record by ignoring the upper 8 bit of the address */
addr_low = address & 0xFFFF;
addr_high = (address >> 16) & 0xFF;
#else
/* The whole 32 bit address is stored using a second event record
for the upper 16 bit */
addr_low = (uint16_t)prvTraceGetParam(0xFFFF, address);
addr_high = 0;
#endif
ma = (MemEventAddr *) xTraceNextFreeEventBufferSlot();
if (ma != NULL)
{
ma->addr_low = addr_low;
ma->addr_high = addr_high;
ma->type = ( ( uint8_t) ecode ) + 1; /* Note this! */
ms->type = (uint8_t)ecode;
prvTraceUpdateCounters();
RecorderDataPtr->heapMemUsage = heapMemUsage;
}
}
}
}
trcCRITICAL_SECTION_END();
#endif /* TRACE_SCHEDULING_ONLY */
}
#endif
/*******************************************************************************
* vTraceStoreKernelCall
*
* This is the main integration point for storing kernel calls, and
* is called by the hooks in trcKernelHooks.h (see trcKernelPort.h for event codes).
******************************************************************************/
void vTraceStoreKernelCall(uint32_t ecode, traceObjectClass objectClass, uint32_t objectNumber)
{
#if (TRACE_SCHEDULING_ONLY == 0)
KernelCall * kse;
uint16_t dts1;
uint8_t hnd8;
TRACE_SR_ALLOC_CRITICAL_SECTION();
TRACE_ASSERT(ecode < 0xFF, "vTraceStoreKernelCall: ecode >= 0xFF", );
TRACE_ASSERT(objectClass < TRACE_NCLASSES, "vTraceStoreKernelCall: objectClass >= TRACE_NCLASSES", );
TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "vTraceStoreKernelCall: Invalid value for objectNumber", );
if (recorder_busy)
{
/*************************************************************************
* This may occur if a high-priority ISR is illegally using a system call,
* or creates a user event.
* Only ISRs that are disabled by TRACE_ENTER_CRITICAL_SECTION may use system calls
* or user events (see TRACE_MAX_SYSCALL_INTERRUPT_PRIORITY).
*************************************************************************/
vTraceError("Recorder busy - high priority ISR using syscall? (2)");
return;
}
if (handle_of_last_logged_task == 0)
{
return;
}
trcCRITICAL_SECTION_BEGIN();
if (RecorderDataPtr->recorderActive)
{
/* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */
if (nISRactive || !inExcludedTask)
{
/* Check if the referenced object or the event code is excluded */
if (!uiTraceIsObjectExcluded(objectClass, (objectHandleType)objectNumber) && !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(ecode))
{
dts1 = (uint16_t)prvTraceGetDTS(0xFFFF);
hnd8 = prvTraceGet8BitHandle(objectNumber);
kse = (KernelCall*) xTraceNextFreeEventBufferSlot();
if (kse != NULL)
{
kse->dts = dts1;
kse->type = (uint8_t)ecode;
kse->objHandle = hnd8;
prvTraceUpdateCounters();
}
}
}
}
trcCRITICAL_SECTION_END();
#endif /* TRACE_SCHEDULING_ONLY */
}
/*******************************************************************************
* vTraceStoreKernelCallWithParam
*
* Used for storing kernel calls with a handle and a numeric parameter. If the
* numeric parameter does not fit in one byte, and extra XPS event is inserted
* before the kernel call event containing the three upper bytes.
******************************************************************************/
void vTraceStoreKernelCallWithParam(uint32_t evtcode,
traceObjectClass objectClass,
uint32_t objectNumber,
uint32_t param)
{
#if (TRACE_SCHEDULING_ONLY == 0)
KernelCallWithParamAndHandle * kse;
uint8_t dts2;
uint8_t hnd8;
uint8_t p8;
TRACE_SR_ALLOC_CRITICAL_SECTION();
TRACE_ASSERT(evtcode < 0xFF, "vTraceStoreKernelCall: evtcode >= 0xFF", );
TRACE_ASSERT(objectClass < TRACE_NCLASSES, "vTraceStoreKernelCallWithParam: objectClass >= TRACE_NCLASSES", );
TRACE_ASSERT(objectNumber <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectClass], "vTraceStoreKernelCallWithParam: Invalid value for objectNumber", );
if (recorder_busy)
{
/*************************************************************************
* This may occur if a high-priority ISR is illegally using a system call,
* or creates a user event.
* Only ISRs that are disabled by TRACE_ENTER_CRITICAL_SECTION may use system calls
* or user events (see TRACE_MAX_SYSCALL_INTERRUPT_PRIORITY).
*************************************************************************/
vTraceError("Recorder busy - high priority ISR using syscall? (3)");
return;
}
trcCRITICAL_SECTION_BEGIN();
if (RecorderDataPtr->recorderActive && handle_of_last_logged_task && (! inExcludedTask || nISRactive))
{
/* Check if the referenced object or the event code is excluded */
if (!uiTraceIsObjectExcluded(objectClass, (objectHandleType)objectNumber) &&
!TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))
{
dts2 = (uint8_t)prvTraceGetDTS(0xFF);
p8 = (uint8_t) prvTraceGetParam(0xFF, param);
hnd8 = prvTraceGet8BitHandle((objectHandleType)objectNumber);
kse = (KernelCallWithParamAndHandle*) xTraceNextFreeEventBufferSlot();
if (kse != NULL)
{
kse->dts = dts2;
kse->type = (uint8_t)evtcode;
kse->objHandle = hnd8;
kse->param = p8;
prvTraceUpdateCounters();
}
}
}
trcCRITICAL_SECTION_END();
#endif /* TRACE_SCHEDULING_ONLY */
}
#if (TRACE_SCHEDULING_ONLY == 0)
/*******************************************************************************
* prvTraceGetParam
*
* Used for storing extra bytes for kernel calls with numeric parameters.
*
* May only be called within a critical section!
******************************************************************************/
static uint32_t prvTraceGetParam(uint32_t param_max, uint32_t param)
{
XPSEvent* xps;
TRACE_ASSERT(param_max == 0xFF || param_max == 0xFFFF,
"prvTraceGetParam: Invalid value for param_max", param);
if (param <= param_max)
{
return param;
}
else
{
xps = (XPSEvent*) xTraceNextFreeEventBufferSlot();
if (xps != NULL)
{
xps->type = DIV_XPS;
xps->xps_8 = (param & (0xFF00 & ~param_max)) >> 8;
xps->xps_16 = (param & (0xFFFF0000 & ~param_max)) >> 16;
prvTraceUpdateCounters();
}
return param & param_max;
}
}
#endif
/*******************************************************************************
* vTraceStoreKernelCallWithNumericParamOnly
*
* Used for storing kernel calls with numeric parameters only. This is
* only used for traceTASK_DELAY and traceDELAY_UNTIL at the moment.
******************************************************************************/
void vTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param)
{
#if (TRACE_SCHEDULING_ONLY == 0)
KernelCallWithParam16 * kse;
uint8_t dts6;
uint16_t restParam;
TRACE_SR_ALLOC_CRITICAL_SECTION();
restParam = 0;
TRACE_ASSERT(evtcode < 0xFF,
"vTraceStoreKernelCallWithNumericParamOnly: Invalid value for evtcode", );
if (recorder_busy)
{
/*************************************************************************
* This may occur if a high-priority ISR is illegally using a system call,
* or creates a user event.
* Only ISRs that are disabled by TRACE_ENTER_CRITICAL_SECTION may use system calls
* or user events (see TRACE_MAX_SYSCALL_INTERRUPT_PRIORITY).
*************************************************************************/
vTraceError("Recorder busy - high priority ISR using syscall? (4)");
return;
}
trcCRITICAL_SECTION_BEGIN();
if (RecorderDataPtr->recorderActive && handle_of_last_logged_task
&& (! inExcludedTask || nISRactive))
{
/* Check if the event code is excluded */
if (!TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))
{
dts6 = (uint8_t)prvTraceGetDTS(0xFF);
restParam = (uint16_t)prvTraceGetParam(0xFFFF, param);
kse = (KernelCallWithParam16*) xTraceNextFreeEventBufferSlot();
if (kse != NULL)
{
kse->dts = dts6;
kse->type = (uint8_t)evtcode;
kse->param = restParam;
prvTraceUpdateCounters();
}
}
}
trcCRITICAL_SECTION_END();
#endif /* TRACE_SCHEDULING_ONLY */
}
/*******************************************************************************
* vTraceStoreTaskswitch
* Called by the scheduler from the SWITCHED_OUT hook, and by uiTraceStart.
* At this point interrupts are assumed to be disabled!
******************************************************************************/
void vTraceStoreTaskswitch(objectHandleType task_handle)
{
uint16_t dts3;
TSEvent* ts;
int8_t skipEvent;
uint8_t hnd8;
TRACE_SR_ALLOC_CRITICAL_SECTION();
skipEvent = 0;
TRACE_ASSERT(task_handle <= NTask,
"vTraceStoreTaskswitch: Invalid value for task_handle", );
/***************************************************************************
This is used to detect if a high-priority ISRs is illegally using the
recorder ISR trace functions (vTraceStoreISRBegin and ...End) while the
recorder is busy with a task-level event or lower priority ISR event.
If this is detected, it triggers a call to vTraceError with the error
"Illegal call to vTraceStoreISRBegin/End". If you get this error, it means
that the macro trcCRITICAL_SECTION_BEGIN does not disable this ISR, as required.
Note: Setting recorder_busy is normally handled in our macros
trcCRITICAL_SECTION_BEGIN and _END, but is needed explicitly in this
function since critical sections should not be used in the context switch
event...)
***************************************************************************/
/* Skip the event if the task has been excluded, using vTraceExcludeTask */
if (TRACE_GET_TASK_FLAG_ISEXCLUDED(task_handle))
{
skipEvent = 1;
inExcludedTask = 1;
}
else
{
inExcludedTask = 0;
}
trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY();
/* Skip the event if the same task is scheduled */
if (task_handle == handle_of_last_logged_task)
{
skipEvent = 1;
}
if (!RecorderDataPtr->recorderActive)
{
skipEvent = 1;
}
/* If this event should be logged, log it! */
if (skipEvent == 0)
{
dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);
handle_of_last_logged_task = task_handle;
hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);
ts = (TSEvent*)xTraceNextFreeEventBufferSlot();
if (ts != NULL)
{
if (uiTraceGetObjectState(TRACE_CLASS_TASK,
handle_of_last_logged_task) == TASK_STATE_INSTANCE_ACTIVE)
{
ts->type = TS_TASK_RESUME;
}
else
{
ts->type = TS_TASK_BEGIN;
}
ts->dts = dts3;
ts->objHandle = hnd8;
vTraceSetObjectState(TRACE_CLASS_TASK,
handle_of_last_logged_task,
TASK_STATE_INSTANCE_ACTIVE);
prvTraceUpdateCounters();
}
}
trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY();
}
/*******************************************************************************
* vTraceStoreNameCloseEvent
*
* Updates the symbol table with the name of this object from the dynamic
* objects table and stores a "close" event, holding the mapping between handle
* and name (a symbol table handle). The stored name-handle mapping is thus the
* "old" one, valid up until this point.
******************************************************************************/
#if (INCLUDE_OBJECT_DELETE == 1)
void vTraceStoreObjectNameOnCloseEvent(objectHandleType handle,
traceObjectClass objectclass)
{
ObjCloseNameEvent * ce;
const char * name;
traceLabel idx;
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"vTraceStoreObjectNameOnCloseEvent: objectclass >= TRACE_NCLASSES", );
TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"vTraceStoreObjectNameOnCloseEvent: Invalid value for handle", );
if (RecorderDataPtr->recorderActive)
{
uint8_t hnd8 = prvTraceGet8BitHandle(handle);
name = TRACE_PROPERTY_NAME_GET(objectclass, handle);
idx = prvTraceOpenSymbol(name, 0);
// Interrupt disable not necessary, already done in trcHooks.h macro
ce = (ObjCloseNameEvent*) xTraceNextFreeEventBufferSlot();
if (ce != NULL)
{
ce->type = EVENTGROUP_OBJCLOSE_NAME + objectclass;
ce->objHandle = hnd8;
ce->symbolIndex = idx;
prvTraceUpdateCounters();
}
}
}
void vTraceStoreObjectPropertiesOnCloseEvent(objectHandleType handle,
traceObjectClass objectclass)
{
ObjClosePropEvent * pe;
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"vTraceStoreObjectPropertiesOnCloseEvent: objectclass >= TRACE_NCLASSES", );
TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"vTraceStoreObjectPropertiesOnCloseEvent: Invalid value for handle", );
if (RecorderDataPtr->recorderActive)
{
// Interrupt disable not necessary, already done in trcHooks.h macro
pe = (ObjClosePropEvent*) xTraceNextFreeEventBufferSlot();
if (pe != NULL)
{
if (objectclass == TRACE_CLASS_TASK)
{
pe->arg1 = TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle);
}
else
{
pe->arg1 = TRACE_PROPERTY_OBJECT_STATE(objectclass, handle);
}
pe->type = EVENTGROUP_OBJCLOSE_PROP + objectclass;
prvTraceUpdateCounters();
}
}
}
#endif
void vTraceSetPriorityProperty(uint8_t objectclass, objectHandleType id, uint8_t value)
{
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"vTraceSetPriorityProperty: objectclass >= TRACE_NCLASSES", );
TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"vTraceSetPriorityProperty: Invalid value for id", );
TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id) = value;
}
uint8_t uiTraceGetPriorityProperty(uint8_t objectclass, objectHandleType id)
{
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"uiTraceGetPriorityProperty: objectclass >= TRACE_NCLASSES", 0);
TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"uiTraceGetPriorityProperty: Invalid value for id", 0);
return TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, id);
}
void vTraceSetObjectState(uint8_t objectclass, objectHandleType id, uint8_t value)
{
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"vTraceSetObjectState: objectclass >= TRACE_NCLASSES", );
TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"vTraceSetObjectState: Invalid value for id", );
TRACE_PROPERTY_OBJECT_STATE(objectclass, id) = value;
}
uint8_t uiTraceGetObjectState(uint8_t objectclass, objectHandleType id)
{
TRACE_ASSERT(objectclass < TRACE_NCLASSES,
"uiTraceGetObjectState: objectclass >= TRACE_NCLASSES", 0);
TRACE_ASSERT(id <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],
"uiTraceGetObjectState: Invalid value for id", 0);
return TRACE_PROPERTY_OBJECT_STATE(objectclass, id);
}
void vTraceSetTaskInstanceFinished(objectHandleType handle)
{
TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_TASK],
"vTraceSetTaskInstanceFinished: Invalid value for handle", );
#if (USE_IMPLICIT_IFE_RULES == 1)
TRACE_PROPERTY_OBJECT_STATE(TRACE_CLASS_TASK, handle) = 0;
#endif
}
#endif

@ -1,107 +1,452 @@
/*******************************************************************************
* Tracealyzer v2.7.7 Recorder Library
* Trace Recorder Library for Tracealyzer v3.1.2
* Percepio AB, www.percepio.com
*
* trcKernelPort.c
*
* Kernel-specific functionality for FreeRTOS, used by the recorder library.
* The FreeRTOS-specific parts of the trace recorder
*
* Terms of Use
* This software is copyright Percepio AB. The recorder library is free for
* use together with Percepio products. You may distribute the recorder library
* in its original form, including modifications in trcHardwarePort.c/.h
* given that these modification are clearly marked as your own modifications
* and documented in the initial comment section of these source files.
* This software is the intellectual property of Percepio AB and may not be
* sold or in other ways commercially redistributed without explicit written
* permission by Percepio AB.
* This file is part of the trace recorder library (RECORDER), which is the
* intellectual property of Percepio AB (PERCEPIO) and provided under a
* license as follows.
* The RECORDER may be used free of charge for the purpose of recording data
* intended for analysis in PERCEPIO products. It may not be used or modified
* for other purposes without explicit permission from PERCEPIO.
* You may distribute the RECORDER in its original source code form, assuming
* this text (terms of use, disclaimer, copyright notice) is unchanged. You are
* allowed to distribute the RECORDER with minor modifications intended for
* configuration or porting of the RECORDER, e.g., to allow using it on a
* specific processor, processor family or with a specific communication
* interface. Any such modifications should be documented directly below
* this comment block.
*
* Disclaimer
* The trace tool and recorder library is being delivered to you AS IS and
* Percepio AB makes no warranty as to its use or performance. Percepio AB does
* not and cannot warrant the performance or results you may obtain by using the
* software or documentation. Percepio AB make no warranties, express or
* implied, as to noninfringement of third party rights, merchantability, or
* fitness for any particular purpose. In no event will Percepio AB, its
* technology partners, or distributors be liable to you for any consequential,
* incidental or special damages, including any lost profits or lost savings,
* even if a representative of Percepio AB has been advised of the possibility
* of such damages, or for any claim by any third party. Some jurisdictions do
* not allow the exclusion or limitation of incidental, consequential or special
* damages, or the exclusion of implied warranties or limitations on how long an
* implied warranty may last, so the above limitations may not apply to you.
* The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty
* as to its use or performance. PERCEPIO does not and cannot warrant the
* performance or results you may obtain by using the RECORDER or documentation.
* PERCEPIO make no warranties, express or implied, as to noninfringement of
* third party rights, merchantability, or fitness for any particular purpose.
* In no event will PERCEPIO, its technology partners, or distributors be liable
* to you for any consequential, incidental or special damages, including any
* lost profits or lost savings, even if a representative of PERCEPIO has been
* advised of the possibility of such damages, or for any claim by any third
* party. Some jurisdictions do not allow the exclusion or limitation of
* incidental, consequential or special damages, or the exclusion of implied
* warranties or limitations on how long an implied warranty may last, so the
* above limitations may not apply to you.
*
* Tabs are used for indent in this file (1 tab = 4 spaces)
*
* Copyright Percepio AB, 2012-2015.
* Copyright Percepio AB, 2017.
* www.percepio.com
******************************************************************************/
#include "trcKernelPort.h"
#include "FreeRTOS.h"
#if (USE_TRACEALYZER_RECORDER == 1)
#if (!defined(TRC_USE_TRACEALYZER_RECORDER) && configUSE_TRACE_FACILITY == 1)
#error Trace Recorder: You need to include trcRecorder.h at the end of your FreeRTOSConfig.h!
#endif
#if (defined(TRC_USE_TRACEALYZER_RECORDER) && TRC_USE_TRACEALYZER_RECORDER == 1)
#if (configUSE_TICKLESS_IDLE != 0 && (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR))
/*
The below error message is to alert you on the following issue:
The hardware port selected in trcConfig.h uses the operating system timer for the
timestamping, i.e., the periodic interrupt timer that drives the OS tick interrupt.
When using tickless idle, the recorder needs an independent time source in order to
correctly record the durations of the idle times. Otherwise, the trace may appear
to have a different length than in reality, and the reported CPU load is also affected.
You may override this warning by defining the TRC_CFG_ACKNOWLEDGE_TICKLESS_IDLE_WARNING
macro in your trcConfig.h file. But then the time scale may be incorrect during
tickless idle periods.
#include <stdint.h>
To get this correct, override the default timestamping by setting TRC_CFG_HARDWARE_PORT
in trcConfig.h to TRC_HARDWARE_PORT_APPLICATION_DEFINED and define the HWTC macros
accordingly, using a free running counter or an independent periodic interrupt timer.
See trcHardwarePort.h for details.
For ARM Cortex-M3, M4 and M7 MCUs this is not an issue, since the recorder uses the
DWT cycle counter for timestamping in these cases.
*/
#ifndef TRC_CFG_ACKNOWLEDGE_TICKLESS_IDLE_WARNING
#error Trace Recorder: This timestamping mode is not recommended with Tickless Idle.
#endif
#endif
#include "task.h"
#include "queue.h"
/* For classes implemented as FreeRTOS Queues:
This translates queue.type to the corresponding trace object class. */
traceObjectClass TraceObjectClassTable[5] = {
TRACE_CLASS_QUEUE,
TRACE_CLASS_MUTEX,
TRACE_CLASS_SEMAPHORE,
TRACE_CLASS_SEMAPHORE,
TRACE_CLASS_MUTEX
};
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
int uiInEventGroupSetBitsFromISR = 0;
static void* pCurrentTCB = NULL;
#if (defined(configENABLE_BACKWARD_COMPATIBILITY) && configENABLE_BACKWARD_COMPATIBILITY == 0)
/* We're explicitly not using compatibility mode */
static TaskHandle_t HandleTzCtrl = NULL; /* TzCtrl task TCB */
#else
/* We're using compatibility mode, or we're running an old kernel */
static xTaskHandle HandleTzCtrl = NULL; /* TzCtrl task TCB */
#endif
#if (configSUPPORT_STATIC_ALLOCATION == 1)
static StackType_t stackTzCtrl[TRC_CFG_CTRL_TASK_STACK_SIZE];
static StaticTask_t tcbTzCtrl;
#endif
/* Monitored by TzCtrl task, that give warnings as User Events */
extern volatile uint32_t NoRoomForSymbol;
extern volatile uint32_t NoRoomForObjectData;
extern volatile uint32_t LongestSymbolName;
extern volatile uint32_t MaxBytesTruncated;
/* Keeps track of previous values, to only react on changes. */
static uint32_t NoRoomForSymbol_last = 0;
static uint32_t NoRoomForObjectData_last = 0;
static uint32_t LongestSymbolName_last = 0;
static uint32_t MaxBytesTruncated_last = 0;
extern unsigned char ucQueueGetQueueType(void*);
/* User Event Channel for giving warnings regarding NoRoomForSymbol etc. */
traceString trcWarningChannel;
#if (FREERTOS_VERSION < FREERTOS_VERSION_8_0_OR_LATER)
#define TRC_PORT_MALLOC(size) pvPortMalloc(size)
extern portBASE_TYPE ucQueueGetQueueNumber(void*);
TRC_STREAM_PORT_ALLOCATE_FIELDS()
objectHandleType prvTraceGetObjectNumber(void* handle)
/* Called by TzCtrl task periodically (Normally every 100 ms) */
static void prvCheckRecorderStatus(void);
/* The TzCtrl task - receives commands from Tracealyzer (start/stop) */
static portTASK_FUNCTION( TzCtrl, pvParameters );
/*******************************************************************************
* vTraceEnable
*
* Function that enables the tracing and creates the control task. It will halt
* execution until a Start command has been received if haltUntilStart is true.
*
******************************************************************************/
void vTraceEnable(int startOption)
{
return (objectHandleType) ucQueueGetQueueNumber(handle);
}
int bytes = 0;
extern uint32_t RecorderEnabled;
TracealyzerCommandType msg;
if (HandleTzCtrl != NULL)
return; /* Seems we already initiated */
TRC_STREAM_PORT_INIT();
if (startOption == TRC_START_AWAIT_HOST)
{
/* We keep trying to read commands until the recorder has been started */
do
{
bytes = 0;
TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), &bytes);
if (bytes == sizeof(TracealyzerCommandType))
{
if (prvIsValidCommand(&msg))
{
if (msg.cmdCode == CMD_SET_ACTIVE && msg.param1 == 1)
{
/* On start, init and reset the timestamping */
TRC_PORT_SPECIFIC_INIT();
}
prvProcessCommand(&msg);
}
}
}
while (RecorderEnabled == 0);
}
else if (startOption == TRC_START)
{
/* We start streaming directly - this assumes that the interface is ready! */
TRC_PORT_SPECIFIC_INIT();
msg.cmdCode = CMD_SET_ACTIVE;
msg.param1 = 1;
prvProcessCommand(&msg);
}
else
{
/* On TRC_INIT */
TRC_PORT_SPECIFIC_INIT();
}
trcWarningChannel = xTraceRegisterString("Warnings from Recorder");
/* Creates the TzCtrl task - receives trace commands (start, stop, ...) */
#if (configSUPPORT_STATIC_ALLOCATION == 1)
HandleTzCtrl = xTaskCreateStatic(TzCtrl, "TzCtrl", TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, stackTzCtrl, &tcbTzCtrl);
(void)HandleTzCtrl;
#else
xTaskCreate( TzCtrl, "TzCtrl", TRC_CFG_CTRL_TASK_STACK_SIZE, NULL, TRC_CFG_CTRL_TASK_PRIORITY, &HandleTzCtrl );
#endif
}
extern portBASE_TYPE uxQueueGetQueueNumber(void*);
/*******************************************************************************
* prvTraceOnBegin
*
* Called on trace begin.
******************************************************************************/
void prvTraceOnBegin()
{
TRC_STREAM_PORT_ON_TRACE_BEGIN();
}
objectHandleType prvTraceGetObjectNumber(void* handle)
/*******************************************************************************
* prvTraceOnEnd
*
* Called on trace end.
******************************************************************************/
void prvTraceOnEnd()
{
return (objectHandleType) uxQueueGetQueueNumber(handle);
TRC_STREAM_PORT_ON_TRACE_END();
}
#endif
/*******************************************************************************
* vTraceSetQueueName(void* object, const char* name)
*
* Parameter object: pointer to the Queue that shall be named
* Parameter name: the name to set (const string literal)
*
* Sets a name for Queue objects for display in Tracealyzer.
******************************************************************************/
void vTraceSetQueueName(void* object, const char* name)
{
vTraceStoreKernelObjectName(object, name);
}
unsigned char prvTraceGetObjectType(void* handle)
/*******************************************************************************
* vTraceSetSemaphoreName(void* object, const char* name)
*
* Parameter object: pointer to the Semaphore that shall be named
* Parameter name: the name to set (const string literal)
*
* Sets a name for Semaphore objects for display in Tracealyzer.
******************************************************************************/
void vTraceSetSemaphoreName(void* object, const char* name)
{
return ucQueueGetQueueType(handle);
vTraceStoreKernelObjectName(object, name);
}
objectHandleType prvTraceGetTaskNumber(void* handle)
/*******************************************************************************
* vTraceSetMutexName(void* object, const char* name)
*
* Parameter object: pointer to the Mutex that shall be named
* Parameter name: the name to set (const string literal)
*
* Sets a name for Semaphore objects for display in Tracealyzer.
******************************************************************************/
void vTraceSetMutexName(void* object, const char* name)
{
return (objectHandleType)uxTaskGetTaskNumber(handle);
vTraceStoreKernelObjectName(object, name);
}
unsigned char prvTraceIsSchedulerActive()
/*******************************************************************************
* prvGetCurrentTaskHandle
*
* Function that returns the handle to the currently executing task.
*
******************************************************************************/
void* prvTraceGetCurrentTaskHandle(void)
{
return xTaskGetCurrentTaskHandle();
}
/*******************************************************************************
* prvIsNewTCB
*
* Tells if this task is already executing, or if there has been a task-switch.
* Assumed to be called within a trace hook in kernel context.
******************************************************************************/
uint32_t prvIsNewTCB(void* pNewTCB)
{
return xTaskGetSchedulerState() == taskSCHEDULER_RUNNING;
if (pCurrentTCB != pNewTCB)
{
pCurrentTCB = pNewTCB;
return 1;
}
return 0;
}
/*******************************************************************************
* prvTraceIsSchedulerSuspended
*
* Returns true if the RTOS scheduler currently is disabled, thus preventing any
* task-switches from occurring. Only called from vTraceStoreISREnd.
******************************************************************************/
unsigned char prvTraceIsSchedulerSuspended()
{
/* Assumed to be available in FreeRTOS. According to the FreeRTOS docs,
INCLUDE_xTaskGetSchedulerState or configUSE_TIMERS must be set to 1 in
FreeRTOSConfig.h for this function to be available. */
return xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED;
}
unsigned char prvTraceIsSchedulerStarted()
/*******************************************************************************
* prvCheckRecorderStatus
*
* Called by TzCtrl task periodically (every 100 ms - seems reasonable).
* Checks a number of diagnostic variables and give warnings as user events,
* in most cases including a suggested solution.
******************************************************************************/
static void prvCheckRecorderStatus(void)
{
return xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED;
if (NoRoomForSymbol > NoRoomForSymbol_last)
{
vTracePrintF(trcWarningChannel, "TRC_CFG_SYMBOL_TABLE_SLOTS too small. Add %d slots.",
NoRoomForSymbol);
NoRoomForSymbol_last = NoRoomForSymbol;
}
if (NoRoomForObjectData > NoRoomForObjectData_last)
{
vTracePrintF(trcWarningChannel, "TRC_CFG_OBJECT_DATA_SLOTS too small. Add %d slots.",
NoRoomForObjectData);
NoRoomForObjectData_last = NoRoomForObjectData;
}
if (LongestSymbolName > LongestSymbolName_last)
{
if (LongestSymbolName > TRC_CFG_SYMBOL_MAX_LENGTH)
{
vTracePrintF(trcWarningChannel, "TRC_CFG_SYMBOL_MAX_LENGTH too small. Add %d chars.",
LongestSymbolName);
}
LongestSymbolName_last = LongestSymbolName;
}
if (MaxBytesTruncated > MaxBytesTruncated_last)
{
/* Some string event generated a too long string that was truncated.
This may happen for the following functions:
- vTracePrintF
- vTracePrintF
- vTraceStoreKernelObjectName
- vTraceStoreUserEventChannelName
- vTraceSetISRProperties
A PSF event may store maximum 60 bytes payload, including data arguments
and string characters. For User Events, also the User Event Channel ptr
must be squeezed in, if a channel is specified. */
vTracePrintF(trcWarningChannel, "String event too long, up to %d bytes truncated.",
MaxBytesTruncated);
MaxBytesTruncated_last = MaxBytesTruncated;
}
}
/*******************************************************************************
* TzCtrl
*
* Task for receiving commands from Tracealyzer and for recorder diagnostics.
*
******************************************************************************/
static portTASK_FUNCTION( TzCtrl, pvParameters )
{
TracealyzerCommandType msg;
int bytes = 0;
(void)pvParameters;
while (1)
{
do
{
/* Listen for new commands */
bytes = 0;
TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), &bytes);
if (bytes == sizeof(TracealyzerCommandType))
{
if (prvIsValidCommand(&msg))
{
prvProcessCommand(&msg); /* Start or Stop currently... */
}
}
/* Send periodic data */
bytes = 0;
TRC_STREAM_PORT_PERIODIC_SEND_DATA(&bytes);
/* 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. */
}
while (bytes != 0);
prvCheckRecorderStatus();
vTaskDelay(TRC_CFG_CTRL_TASK_DELAY); /* 10ms */
}
}
#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
/* Internal flag to tell the context of tracePEND_FUNC_CALL_FROM_ISR */
int uiInEventGroupSetBitsFromISR = 0;
/******************************************************************************
* TraceObjectClassTable
* Translates a FreeRTOS QueueType into trace objects classes (TRACE_CLASS_).
* Has one entry for each QueueType, gives TRACE_CLASS ID.
******************************************************************************/
traceObjectClass TraceObjectClassTable[5] = {
TRACE_CLASS_QUEUE,
TRACE_CLASS_MUTEX,
TRACE_CLASS_SEMAPHORE,
TRACE_CLASS_SEMAPHORE,
TRACE_CLASS_MUTEX
};
/*******************************************************************************
* vTraceSetQueueName(void* object, const char* name)
*
* Parameter object: pointer to the Queue that shall be named
* Parameter name: the name to set (const string literal)
*
* Sets a name for Queue objects for display in Tracealyzer.
******************************************************************************/
void vTraceSetQueueName(void* object, const char* name)
{
prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);
}
/*******************************************************************************
* vTraceSetSemaphoreName(void* object, const char* name)
*
* Parameter object: pointer to the Semaphore that shall be named
* Parameter name: the name to set (const string literal)
*
* Sets a name for Semaphore objects for display in Tracealyzer.
******************************************************************************/
void vTraceSetSemaphoreName(void* object, const char* name)
{
prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);
}
/*******************************************************************************
* vTraceSetMutexName(void* object, const char* name)
*
* Parameter object: pointer to the Mutex that shall be named
* Parameter name: the name to set (const string literal)
*
* Sets a name for Semaphore objects for display in Tracealyzer.
******************************************************************************/
void vTraceSetMutexName(void* object, const char* name)
{
prvTraceSetObjectName(TRACE_GET_OBJECT_TRACE_CLASS(TRC_UNUSED, object), TRACE_GET_OBJECT_NUMBER(TRC_UNUSED, object), name);
}
void* prvTraceGetCurrentTaskHandle()
@ -109,24 +454,46 @@ void* prvTraceGetCurrentTaskHandle()
return xTaskGetCurrentTaskHandle();
}
#if (TRC_CFG_FREERTOS_VERSION < TRC_FREERTOS_VERSION_8_X)
traceHandle prvTraceGetObjectNumber(void* handle)
{
return (traceHandle) ucQueueGetQueueNumber(handle);
}
#else /* For FreeRTOS v8 and later */
traceHandle prvTraceGetObjectNumber(void* handle)
{
return (traceHandle) uxQueueGetQueueNumber(handle);
}
#endif
uint8_t prvTraceGetObjectType(void* handle)
{
return ucQueueGetQueueType(handle);
}
traceHandle prvTraceGetTaskNumber(void* handle)
{
return (traceHandle)uxTaskGetTaskNumber(handle);
}
/* Initialization of the object property table */
void vTraceInitObjectPropertyTable()
{
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectClasses = TRACE_NCLASSES;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[0] = NQueue;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[1] = NSemaphore;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[2] = NMutex;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[3] = NTask;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[4] = NISR;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[5] = NTimer;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[6] = NEventGroup;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[0] = NameLenQueue;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[1] = NameLenSemaphore;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[2] = NameLenMutex;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[3] = NameLenTask;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[4] = NameLenISR;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[5] = NameLenTimer;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[6] = NameLenEventGroup;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[0] = TRC_CFG_NQUEUE;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[1] = TRC_CFG_NSEMAPHORE;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[2] = TRC_CFG_NMUTEX;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[3] = TRC_CFG_NTASK;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[4] = TRC_CFG_NISR;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[5] = TRC_CFG_NTIMER;
RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[6] = TRC_CFG_NEVENTGROUP;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[0] = TRC_CFG_NAME_LEN_QUEUE;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[1] = TRC_CFG_NAME_LEN_SEMAPHORE;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[2] = TRC_CFG_NAME_LEN_MUTEX;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[3] = TRC_CFG_NAME_LEN_TASK;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[4] = TRC_CFG_NAME_LEN_ISR;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[5] = TRC_CFG_NAME_LEN_TIMER;
RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[6] = TRC_CFG_NAME_LEN_EVENTGROUP;
RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[0] = PropertyTableSizeQueue;
RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[1] = PropertyTableSizeSemaphore;
RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[2] = PropertyTableSizeMutex;
@ -144,24 +511,24 @@ void vTraceInitObjectPropertyTable()
RecorderDataPtr->ObjectPropertyTable.ObjectPropertyTableSizeInBytes = TRACE_OBJECT_TABLE_SIZE;
}
/* Initialization of the handle mechanism, see e.g, xTraceGetObjectHandle */
/* Initialization of the handle mechanism, see e.g, prvTraceGetObjectHandle */
void vTraceInitObjectHandleStack()
{
objectHandleStacks.indexOfNextAvailableHandle[0] = objectHandleStacks.lowestIndexOfClass[0] = 0;
objectHandleStacks.indexOfNextAvailableHandle[1] = objectHandleStacks.lowestIndexOfClass[1] = NQueue;
objectHandleStacks.indexOfNextAvailableHandle[2] = objectHandleStacks.lowestIndexOfClass[2] = NQueue + NSemaphore;
objectHandleStacks.indexOfNextAvailableHandle[3] = objectHandleStacks.lowestIndexOfClass[3] = NQueue + NSemaphore + NMutex;
objectHandleStacks.indexOfNextAvailableHandle[4] = objectHandleStacks.lowestIndexOfClass[4] = NQueue + NSemaphore + NMutex + NTask;
objectHandleStacks.indexOfNextAvailableHandle[5] = objectHandleStacks.lowestIndexOfClass[5] = NQueue + NSemaphore + NMutex + NTask + NISR;
objectHandleStacks.indexOfNextAvailableHandle[6] = objectHandleStacks.lowestIndexOfClass[6] = NQueue + NSemaphore + NMutex + NTask + NISR + NTimer;
objectHandleStacks.highestIndexOfClass[0] = NQueue - 1;
objectHandleStacks.highestIndexOfClass[1] = NQueue + NSemaphore - 1;
objectHandleStacks.highestIndexOfClass[2] = NQueue + NSemaphore + NMutex - 1;
objectHandleStacks.highestIndexOfClass[3] = NQueue + NSemaphore + NMutex + NTask - 1;
objectHandleStacks.highestIndexOfClass[4] = NQueue + NSemaphore + NMutex + NTask + NISR - 1;
objectHandleStacks.highestIndexOfClass[5] = NQueue + NSemaphore + NMutex + NTask + NISR + NTimer - 1;
objectHandleStacks.highestIndexOfClass[6] = NQueue + NSemaphore + NMutex + NTask + NISR + NTimer + NEventGroup - 1;
objectHandleStacks.indexOfNextAvailableHandle[1] = objectHandleStacks.lowestIndexOfClass[1] = TRC_CFG_NQUEUE;
objectHandleStacks.indexOfNextAvailableHandle[2] = objectHandleStacks.lowestIndexOfClass[2] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE;
objectHandleStacks.indexOfNextAvailableHandle[3] = objectHandleStacks.lowestIndexOfClass[3] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX;
objectHandleStacks.indexOfNextAvailableHandle[4] = objectHandleStacks.lowestIndexOfClass[4] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK;
objectHandleStacks.indexOfNextAvailableHandle[5] = objectHandleStacks.lowestIndexOfClass[5] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR;
objectHandleStacks.indexOfNextAvailableHandle[6] = objectHandleStacks.lowestIndexOfClass[6] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR + TRC_CFG_NTIMER;
objectHandleStacks.highestIndexOfClass[0] = TRC_CFG_NQUEUE - 1;
objectHandleStacks.highestIndexOfClass[1] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE - 1;
objectHandleStacks.highestIndexOfClass[2] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX - 1;
objectHandleStacks.highestIndexOfClass[3] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK - 1;
objectHandleStacks.highestIndexOfClass[4] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR - 1;
objectHandleStacks.highestIndexOfClass[5] = TRC_CFG_NQUEUE + TRC_CFG_NSEMAPHORE + TRC_CFG_NMUTEX + TRC_CFG_NTASK + TRC_CFG_NISR + TRC_CFG_NTIMER - 1;
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;
}
/* Returns the "Not enough handles" error message for this object class */
@ -170,50 +537,69 @@ const char* pszTraceGetErrorNotEnoughHandles(traceObjectClass objectclass)
switch(objectclass)
{
case TRACE_CLASS_TASK:
return "Not enough TASK handles - increase NTask in trcConfig.h";
return "Not enough TASK handles - increase TRC_CFG_NTASK in trcSnapshotConfig.h";
case TRACE_CLASS_ISR:
return "Not enough ISR handles - increase NISR in trcConfig.h";
return "Not enough ISR handles - increase TRC_CFG_NISR in trcSnapshotConfig.h";
case TRACE_CLASS_SEMAPHORE:
return "Not enough SEMAPHORE handles - increase NSemaphore in trcConfig.h";
return "Not enough SEMAPHORE handles - increase TRC_CFG_NSEMAPHORE in trcSnapshotConfig.h";
case TRACE_CLASS_MUTEX:
return "Not enough MUTEX handles - increase NMutex in trcConfig.h";
return "Not enough MUTEX handles - increase TRC_CFG_NMUTEX in trcSnapshotConfig.h";
case TRACE_CLASS_QUEUE:
return "Not enough QUEUE handles - increase NQueue in trcConfig.h";
return "Not enough QUEUE handles - increase TRC_CFG_NQUEUE in trcSnapshotConfig.h";
case TRACE_CLASS_TIMER:
return "Not enough TIMER handles - increase NTimer in trcConfig.h";
return "Not enough TIMER handles - increase TRC_CFG_NTIMER in trcSnapshotConfig.h";
case TRACE_CLASS_EVENTGROUP:
return "Not enough EVENTGROUP handles - increase NEventGroup in trcConfig.h";
return "Not enough EVENTGROUP handles - increase TRC_CFG_NEVENTGROUP in trcSnapshotConfig.h";
default:
return "pszTraceGetErrorHandles: Invalid objectclass!";
}
}
/* Returns the exclude state of the object */
uint8_t uiTraceIsObjectExcluded(traceObjectClass objectclass, objectHandleType handle)
uint8_t uiTraceIsObjectExcluded(traceObjectClass objectclass, traceHandle handle)
{
TRACE_ASSERT(objectclass < TRACE_NCLASSES, "prvTraceIsObjectExcluded: objectclass >= TRACE_NCLASSES", 1);
TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], "uiTraceIsObjectExcluded: Invalid value for handle", 1);
TRACE_ASSERT(objectclass < TRACE_NCLASSES, "prvIsObjectExcluded: objectclass >= TRACE_NCLASSES", 1);
TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], "prvIsObjectExcluded: Invalid value for handle", 1);
switch(objectclass)
{
case TRACE_CLASS_TASK:
return TRACE_GET_TASK_FLAG_ISEXCLUDED(handle);
return (uint8_t) TRACE_GET_TASK_FLAG_ISEXCLUDED(handle);
case TRACE_CLASS_SEMAPHORE:
return TRACE_GET_SEMAPHORE_FLAG_ISEXCLUDED(handle);
return (uint8_t) TRACE_GET_SEMAPHORE_FLAG_ISEXCLUDED(handle);
case TRACE_CLASS_MUTEX:
return TRACE_GET_MUTEX_FLAG_ISEXCLUDED(handle);
return (uint8_t) TRACE_GET_MUTEX_FLAG_ISEXCLUDED(handle);
case TRACE_CLASS_QUEUE:
return TRACE_GET_QUEUE_FLAG_ISEXCLUDED(handle);
return (uint8_t) TRACE_GET_QUEUE_FLAG_ISEXCLUDED(handle);
case TRACE_CLASS_TIMER:
return TRACE_GET_TIMER_FLAG_ISEXCLUDED(handle);
return (uint8_t) TRACE_GET_TIMER_FLAG_ISEXCLUDED(handle);
case TRACE_CLASS_EVENTGROUP:
return TRACE_GET_EVENTGROUP_FLAG_ISEXCLUDED(handle);
return (uint8_t) TRACE_GET_EVENTGROUP_FLAG_ISEXCLUDED(handle);
}
vTraceError("Invalid object class ID in uiTraceIsObjectExcluded!");
prvTraceError("Invalid object class ID in prvIsObjectExcluded!");
/* Must never reach */
return 1;
}
#endif
/*******************************************************************************
* prvTraceIsSchedulerSuspended
*
* Returns true if the RTOS scheduler currently is disabled, thus preventing any
* task-switches from occurring. Only called from vTraceStoreISREnd.
******************************************************************************/
#if (TRC_CFG_INCLUDE_ISR_TRACING == 1)
unsigned char prvTraceIsSchedulerSuspended()
{
/* Assumed to be available in FreeRTOS. According to the FreeRTOS docs,
INCLUDE_xTaskGetSchedulerState or configUSE_TIMERS must be set to 1 in
FreeRTOSConfig.h for this function to be available. */
return xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED;
}
#endif
#endif /* Snapshot mode */
#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save