FreeRTOS Trace Fixes (#888)

* Updating the FreeRTOS/Demo/Posix_GCC Demo's Trace.dump file Creation
* Updating the FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Posix Demo's Trace.dump file Creation

Co-authored-by: Soren Ptak <skptak@amazon.com>
pull/898/head
Soren Ptak 2 years ago committed by GitHub
parent 228f76cbe3
commit 1fc1e01fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,10 +43,10 @@
#define configUSE_TICK_HOOK 1 #define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1 #define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ #define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ #define configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 84 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 ) #define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 0 #define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0 #define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1 #define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1 #define configUSE_MUTEXES 1
@ -58,6 +58,7 @@
#define configUSE_ALTERNATIVE_API 0 #define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1 #define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1 #define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_STATIC_ALLOCATION 1
/* Software timer related configuration options. The maximum possible task /* Software timer related configuration options. The maximum possible task
@ -76,6 +77,10 @@ unsigned long ulGetRunTimeCounterValue( void ); /* Prototype of function that re
void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */
#define configGENERATE_RUN_TIME_STATS 1 #define configGENERATE_RUN_TIME_STATS 1
/* Co-routine related configuration options. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* This demo can use of one or more example stats formatting functions. These /* This demo can use of one or more example stats formatting functions. These
format the raw data provided by the uxTaskGetSystemState() function in to human format the raw data provided by the uxTaskGetSystemState() function in to human
readable ASCII form. See the notes in the implementation of vTaskList() within readable ASCII form. See the notes in the implementation of vTaskList() within
@ -122,15 +127,32 @@ used with multiple project configurations. If it is
#error projCOVERAGE_TEST should be defined to 1 or 0 on the command line. #error projCOVERAGE_TEST should be defined to 1 or 0 on the command line.
#endif #endif
/* Insert NOPs in empty decision paths to ensure both true and false paths #if( projCOVERAGE_TEST == 1 )
are being tested. */ /* Insert NOPs in empty decision paths to ensure both true and false paths
#define mtCOVERAGE_TEST_MARKER() __asm volatile( "NOP" ) are being tested. */
#define mtCOVERAGE_TEST_MARKER() __asm volatile( "NOP" )
/* Ensure the tick count overflows during the coverage test. */
#define configINITIAL_TICK_COUNT 0xffffd800UL
/* Allows tests of trying to allocate more than the heap has free. */
#define configUSE_MALLOC_FAILED_HOOK 0
/* Ensure the tick count overflows during the coverage test. */ /* To test builds that remove the static qualifier for debug builds. */
#define configINITIAL_TICK_COUNT 0xffffd800UL #define portREMOVE_STATIC_QUALIFIER
#else
/* It is a good idea to define configASSERT() while developing. configASSERT()
uses the same semantics as the standard C assert() macro. Don't define
configASSERT() when performing code coverage tests though, as it is not
intended to asserts() to fail, some some code is intended not to run if no
errors are present. */
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
/* Allows tests of trying to allocate more than the heap has free. */ #define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_MALLOC_FAILED_HOOK 0
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
#include "trcRecorder.h"
#endif
/* networking definitions */ /* networking definitions */
#define configMAC_ISR_SIMULATOR_PRIORITY ( configMAX_PRIORITIES - 1 ) #define configMAC_ISR_SIMULATOR_PRIORITY ( configMAX_PRIORITIES - 1 )

@ -2,6 +2,7 @@ CC := gcc
BIN := posix_tcp_demo BIN := posix_tcp_demo
BUILD_DIR := build BUILD_DIR := build
BUILD_DIR_ABS := $(abspath $(BUILD_DIR))
FREERTOS_DIR_REL := ../../../FreeRTOS FREERTOS_DIR_REL := ../../../FreeRTOS
FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL)) FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL))
@ -9,14 +10,21 @@ FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL))
FREERTOS_PLUS_DIR_REL := ../../../FreeRTOS-Plus FREERTOS_PLUS_DIR_REL := ../../../FreeRTOS-Plus
FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL)) FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL))
KERNEL_DIR := ${FREERTOS_DIR}/Source
INCLUDE_DIRS := -I. INCLUDE_DIRS := -I.
INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/include INCLUDE_DIRS += -I./Trace_Recorder_Configuration
INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix INCLUDE_DIRS += -I${KERNEL_DIR}/include
INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/utils INCLUDE_DIRS += -I${KERNEL_DIR}/portable/ThirdParty/GCC/Posix
INCLUDE_DIRS += -I${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/utils
INCLUDE_DIRS += -I${FREERTOS_DIR}/Demo/Common/include INCLUDE_DIRS += -I${FREERTOS_DIR}/Demo/Common/include
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/NetworkInterface/linux/ INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/NetworkInterface/linux/
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/include/ INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/include/
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/Compiler/GCC/ INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/Compiler/GCC/
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/Include
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/config
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/streamports/File/include
INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/streamports/File/config
# FreeRTOS Kernel source files # FreeRTOS Kernel source files
SOURCE_FILES := SOURCE_FILES :=
@ -28,8 +36,8 @@ SOURCE_FILES += ${FREERTOS_DIR}/Source/tasks.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/timers.c SOURCE_FILES += ${FREERTOS_DIR}/Source/timers.c
# FreeRTOS Kernel POSIX Port # FreeRTOS Kernel POSIX Port
SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c SOURCE_FILES += ${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c
SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/port.c SOURCE_FILES += ${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/port.c
# FreeRTOS+TCP demo source file # FreeRTOS+TCP demo source file
SOURCE_FILES += SimpleTCPEchoServer.c SOURCE_FILES += SimpleTCPEchoServer.c
@ -68,8 +76,33 @@ SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/FreeRTOS_UD
SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c
SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/NetworkInterface/linux/NetworkInterface.c SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/source/portable/NetworkInterface/linux/NetworkInterface.c
CFLAGS := -ggdb3 -O0 -DprojCOVERAGE_TEST=0 -D_WINDOWS_
LDFLAGS := -ggdb3 -O0 -pthread -lpcap CFLAGS := -ggdb3
LDFLAGS := -ggdb3 -pthread -lpcap
CPPFLAGS := $(INCLUDE_DIRS) -DBUILD_DIR=\"$(BUILD_DIR_ABS)\"
ifeq ($(TRACE_ON_ENTER),1)
CPPFLAGS += -DTRACE_ON_ENTER=1
else
CPPFLAGS += -DTRACE_ON_ENTER=0
endif
ifeq ($(COVERAGE_TEST),1)
CPPFLAGS += -DprojCOVERAGE_TEST=1
else
CPPFLAGS += -DprojCOVERAGE_TEST=0
# Trace library.
SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcKernelPort.c
SOURCE_FILES += $(wildcard ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/*.c )
endif
ifdef PROFILE
CFLAGS += -pg -O0
LDFLAGS += -pg -O0
else
CFLAGS += -O3
LDFLAGS += -O3
endif
OBJ_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o) OBJ_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)
@ -79,16 +112,21 @@ ${BIN} : $(BUILD_DIR)/$(BIN)
${BUILD_DIR}/${BIN} : ${OBJ_FILES} ${BUILD_DIR}/${BIN} : ${OBJ_FILES}
-mkdir -p ${@D} -mkdir -p ${@D}
$(CC) $^ $(CFLAGS) $(INCLUDE_DIRS) ${LDFLAGS} -o $@ $(CC) $^ ${LDFLAGS} -o $@
-include ${DEP_FILE} -include ${DEP_FILE}
${BUILD_DIR}/%.o : %.c ${BUILD_DIR}/%.o : %.c Makefile
-mkdir -p $(@D) -mkdir -p $(@D)
$(CC) $(CFLAGS) ${INCLUDE_DIRS} -MMD -c $< -o $@ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -c $< -o $@
.PHONY: clean .PHONY: clean
clean: clean:
-rm -rf $(BUILD_DIR) -rm -rf $(BUILD_DIR)
GPROF_OPTIONS := --directory-path=$(INCLUDE_DIRS)
profile:
gprof -a -p --all-lines $(GPROF_OPTIONS) $(BUILD_DIR)/$(BIN) $(BUILD_DIR)/gmon.out > $(BUILD_DIR)/prof_flat.txt
gprof -a --graph $(GPROF_OPTIONS) $(BUILD_DIR)/$(BIN) $(BUILD_DIR)/gmon.out > $(BUILD_DIR)/prof_call_graph.txt

@ -25,35 +25,35 @@
*/ */
/* /*
http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading * http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
the FAQ page "My application does not run, what could be wrong?". Have you * the FAQ page "My application does not run, what could be wrong?". Have you
defined configASSERT()? * defined configASSERT()?
*
http://www.FreeRTOS.org/support - In return for receiving this top quality * http://www.FreeRTOS.org/support - In return for receiving this top quality
embedded software for free we request you assist our global community by * embedded software for free we request you assist our global community by
participating in the support forum. * participating in the support forum.
*
http://www.FreeRTOS.org/training - Investing in training allows your team to * http://www.FreeRTOS.org/training - Investing in training allows your team to
be as productive as possible as early as possible. Now you can receive * be as productive as possible as early as possible. Now you can receive
FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers * FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
Ltd, and the world's leading authority on the world's leading RTOS. * Ltd, and the world's leading authority on the world's leading RTOS.
*
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, * http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS * including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack. * compatible FAT file system, and our tiny thread aware UDP/IP stack.
*
http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. * http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. * Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
*
http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High * http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS * Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and commercial middleware. * licenses offer ticketed support, indemnification and commercial middleware.
*
http://www.SafeRTOS.com - High Integrity Systems also provide a safety * http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and * engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability. * mission critical applications that require provable dependability.
*
*/ */
/* /*
* FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the * FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the
@ -67,6 +67,7 @@
/* Standard includes. */ /* Standard includes. */
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
/* FreeRTOS includes. */ /* FreeRTOS includes. */
#include "FreeRTOS.h" #include "FreeRTOS.h"
@ -78,33 +79,33 @@
#include "FreeRTOS_Sockets.h" #include "FreeRTOS_Sockets.h"
/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */ /* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */
#if( ipconfigUSE_TCP == 1 ) #if ( ipconfigUSE_TCP == 1 )
/* The maximum time to wait for a closing socket to close. */ /* The maximum time to wait for a closing socket to close. */
#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) ) #define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) )
/* The standard echo port number. */ /* The standard echo port number. */
#define tcpechoPORT_NUMBER 7 #define tcpechoPORT_NUMBER 7
/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by /* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by
ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be * ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be
configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note * configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note
ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP * ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in * stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in
FreeRTOSConfig.h as it is a demo application constant. */ * FreeRTOSConfig.h as it is a demo application constant. */
#ifndef configECHO_SERVER_TX_WINDOW_SIZE #ifndef configECHO_SERVER_TX_WINDOW_SIZE
#define configECHO_SERVER_TX_WINDOW_SIZE 2 #define configECHO_SERVER_TX_WINDOW_SIZE 2
#endif #endif
/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by /* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by
ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be * ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be
configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note * configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note
ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP * ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in * stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in
FreeRTOSConfig.h as it is a demo application constant. */ * FreeRTOSConfig.h as it is a demo application constant. */
#ifndef configECHO_SERVER_RX_WINDOW_SIZE #ifndef configECHO_SERVER_RX_WINDOW_SIZE
#define configECHO_SERVER_RX_WINDOW_SIZE 2 #define configECHO_SERVER_RX_WINDOW_SIZE 2
#endif #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -112,165 +113,185 @@ FreeRTOSConfig.h as it is a demo application constant. */
* Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task * Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task
* to handle each connection. * to handle each connection.
*/ */
static void prvConnectionListeningTask( void *pvParameters ); static void prvConnectionListeningTask( void * pvParameters );
/* /*
* Created by the connection listening task to handle a single connection. * Created by the connection listening task to handle a single connection.
*/ */
static void prvServerConnectionInstance( void *pvParameters ); static void prvServerConnectionInstance( void * pvParameters );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be /* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be
reused when the server listening task creates tasks to handle connections. */ * reused when the server listening task creates tasks to handle connections. */
static uint16_t usUsedStackSize = 0; static uint16_t usUsedStackSize = 0;
/*-----------------------------------------------------------*/ /* Create task stack and buffers for use in the Listening and Server connection tasks */
static StaticTask_t listenerTaskBuffer;
static StackType_t listenerTaskStack[ PTHREAD_STACK_MIN ];
static StaticTask_t echoServerTaskBuffer;
static StackType_t echoServerTaskStack[ PTHREAD_STACK_MIN ];
void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority ) /*-----------------------------------------------------------*/
{
/* Create the TCP echo server. */
xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL );
/* Remember the requested stack size so it can be re-used by the server void vStartSimpleTCPServerTasks( uint16_t usStackSize,
listening task when it creates tasks to handle connections. */ UBaseType_t uxPriority )
usUsedStackSize = usStackSize; {
} /* Create the TCP echo server. */
xTaskCreateStatic( prvConnectionListeningTask,
"ServerListener",
PTHREAD_STACK_MIN,
NULL,
uxPriority + 1,
listenerTaskStack,
&listenerTaskBuffer );
/* Remember the requested stack size so it can be re-used by the server
* listening task when it creates tasks to handle connections. */
usUsedStackSize = usStackSize;
}
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvConnectionListeningTask( void *pvParameters ) static void prvConnectionListeningTask( void * pvParameters )
{ {
struct freertos_sockaddr xClient, xBindAddress; struct freertos_sockaddr xClient, xBindAddress;
Socket_t xListeningSocket, xConnectedSocket; Socket_t xListeningSocket, xConnectedSocket;
socklen_t xSize = sizeof( xClient ); socklen_t xSize = sizeof( xClient );
static const TickType_t xReceiveTimeOut = portMAX_DELAY; static const TickType_t xReceiveTimeOut = portMAX_DELAY;
const BaseType_t xBacklog = 20; const BaseType_t xBacklog = 20;
#if( ipconfigUSE_TCP_WIN == 1 ) #if ( ipconfigUSE_TCP_WIN == 1 )
WinProperties_t xWinProps; WinProperties_t xWinProps;
/* Fill in the buffer and window sizes that will be used by the socket. */ /* Fill in the buffer and window sizes that will be used by the socket. */
xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH; xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH;
xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE; xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE;
xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH; xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH;
xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE; xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE;
#endif /* ipconfigUSE_TCP_WIN */ #endif /* ipconfigUSE_TCP_WIN */
/* Just to prevent compiler warnings. */ /* Just to prevent compiler warnings. */
( void ) pvParameters; ( void ) pvParameters;
/* Attempt to open the socket. */ /* Attempt to open the socket. */
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET ); configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
/* Set a time out so accept() will just wait for a connection. */ /* Set a time out so accept() will just wait for a connection. */
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
/* Set the window and buffer sizes. */ /* Set the window and buffer sizes. */
#if( ipconfigUSE_TCP_WIN == 1 ) #if ( ipconfigUSE_TCP_WIN == 1 )
{ {
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
} }
#endif /* ipconfigUSE_TCP_WIN */ #endif /* ipconfigUSE_TCP_WIN */
/* Bind the socket to the port that the client task will send to, then /* Bind the socket to the port that the client task will send to, then
listen for incoming connections. */ * listen for incoming connections. */
xBindAddress.sin_port = tcpechoPORT_NUMBER; xBindAddress.sin_port = tcpechoPORT_NUMBER;
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port ); xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
FreeRTOS_listen( xListeningSocket, xBacklog ); FreeRTOS_listen( xListeningSocket, xBacklog );
for( ;; ) for( ;; )
{ {
/* Wait for a client to connect. */ /* Wait for a client to connect. */
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize ); xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET ); configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
/* Spawn a task to handle the connection. */ /* Spawn a task to handle the connection. */
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL ); xTaskCreateStatic( prvServerConnectionInstance,
} "EchoServer",
} PTHREAD_STACK_MIN,
( void * ) xConnectedSocket,
tskIDLE_PRIORITY,
echoServerTaskStack,
&echoServerTaskBuffer );
}
}
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvServerConnectionInstance( void *pvParameters ) static void prvServerConnectionInstance( void * pvParameters )
{ {
int32_t lBytes, lSent, lTotalSent; int32_t lBytes, lSent, lTotalSent;
Socket_t xConnectedSocket; Socket_t xConnectedSocket;
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 ); static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 ); static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
TickType_t xTimeOnShutdown; TickType_t xTimeOnShutdown;
uint8_t *pucRxBuffer; uint8_t * pucRxBuffer;
xConnectedSocket = ( Socket_t ) pvParameters; xConnectedSocket = ( Socket_t ) pvParameters;
/* Attempt to create the buffer used to receive the string to be echoed /* Attempt to create the buffer used to receive the string to be echoed
back. This could be avoided using a zero copy interface that just returned * back. This could be avoided using a zero copy interface that just returned
the same buffer. */ * the same buffer. */
pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS ); pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS );
if( pucRxBuffer != NULL ) if( pucRxBuffer != NULL )
{ {
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
for( ;; ) for( ;; )
{ {
/* Zero out the receive array so there is NULL at the end of the string /* Zero out the receive array so there is NULL at the end of the string
when it is printed out. */ * when it is printed out. */
memset( pucRxBuffer, 0x00, ipconfigTCP_MSS ); memset( pucRxBuffer, 0x00, ipconfigTCP_MSS );
/* Receive data on the socket. */ /* Receive data on the socket. */
lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ); lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );
/* If data was received, echo it back. */ /* If data was received, echo it back. */
if( lBytes >= 0 ) if( lBytes >= 0 )
{ {
lSent = 0; lSent = 0;
lTotalSent = 0; lTotalSent = 0;
/* Call send() until all the data has been sent. */ /* Call send() until all the data has been sent. */
while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) ) while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
{ {
lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 ); lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 );
lTotalSent += lSent; lTotalSent += lSent;
} }
if( lSent < 0 ) if( lSent < 0 )
{ {
/* Socket closed? */ /* Socket closed? */
break; break;
} }
} }
else else
{ {
/* Socket closed? */ /* Socket closed? */
break; break;
} }
} }
} }
/* Initiate a shutdown in case it has not already been initiated. */ /* Initiate a shutdown in case it has not already been initiated. */
FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR ); FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );
/* Wait for the shutdown to take effect, indicated by FreeRTOS_recv() /* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
returning an error. */ * returning an error. */
xTimeOnShutdown = xTaskGetTickCount(); xTimeOnShutdown = xTaskGetTickCount();
do
{ do
if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 ) {
{ if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
break; {
} break;
} while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY ); }
} while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );
/* Finished with the socket, buffer, the task. */
vPortFree( pucRxBuffer ); /* Finished with the socket, buffer, the task. */
FreeRTOS_closesocket( xConnectedSocket ); vPortFree( pucRxBuffer );
FreeRTOS_closesocket( xConnectedSocket );
vTaskDelete( NULL );
} vTaskDelete( NULL );
}
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* The whole file is excluded if TCP is not compiled in. */ /* The whole file is excluded if TCP is not compiled in. */
#endif /* ipconfigUSE_TCP */ #endif /* ipconfigUSE_TCP */

@ -54,22 +54,22 @@
#if ( ipconfigUSE_TCP == 1 ) #if ( ipconfigUSE_TCP == 1 )
/* The echo tasks create a socket, send out a number of echo requests, listen /* The echo tasks create a socket, send out a number of echo requests, listen
for the echo reply, then close the socket again before starting over. This * for the echo reply, then close the socket again before starting over. This
delay is used between each iteration to ensure the network does not get too * delay is used between each iteration to ensure the network does not get too
congested. */ * congested. */
#define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS ) #define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS )
/* The echo server is assumed to be on port 7, which is the standard echo /* The echo server is assumed to be on port 7, which is the standard echo
protocol port. */ * protocol port. */
#define echoECHO_PORT ( 7 ) #define echoECHO_PORT ( 7 )
/* The size of the buffers is a multiple of the MSS - the length of the data /* The size of the buffers is a multiple of the MSS - the length of the data
sent is a pseudo random size between 20 and echoBUFFER_SIZES. */ * sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
#define echoBUFFER_SIZE_MULTIPLIER ( 3 ) #define echoBUFFER_SIZE_MULTIPLIER ( 3 )
#define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER ) #define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER )
/* The number of instances of the echo client task to create. */ /* The number of instances of the echo client task to create. */
#define echoNUM_ECHO_CLIENTS ( 1 ) #define echoNUM_ECHO_CLIENTS ( 1 )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -77,297 +77,301 @@ sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
* Uses a socket to send data to, then receive data from, the standard echo * Uses a socket to send data to, then receive data from, the standard echo
* port number 7. * port number 7.
*/ */
static void prvEchoClientTask( void *pvParameters ); static void prvEchoClientTask( void * pvParameters );
/* /*
* Creates a pseudo random sized buffer of data to send to the echo server. * Creates a pseudo random sized buffer of data to send to the echo server.
*/ */
static BaseType_t prvCreateTxData( char *ucBuffer, static BaseType_t prvCreateTxData( char * ucBuffer,
uint32_t ulBufferLength ); uint32_t ulBufferLength );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Rx and Tx time outs are used to ensure the sockets do not wait too long for /* Rx and Tx time outs are used to ensure the sockets do not wait too long for
missing data. */ * missing data. */
static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 ); static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 );
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 ); static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 );
/* Counters for each created task - for inspection only. */ /* Counters for each created task - for inspection only. */
static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 }, static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 },
ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 },
ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 }; ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
/* Rx and Tx buffers for each created task. */ /* Rx and Tx buffers for each created task. */
static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ], static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ],
cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ]; cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ];
static StaticTask_t echoServerTaskBuffer;
static StackType_t echoServerTaskStack[ PTHREAD_STACK_MIN ];
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority ) UBaseType_t uxTaskPriority )
{ {
BaseType_t x; BaseType_t x;
/* Create the echo client tasks. */ /* Create the echo client tasks. */
for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ ) for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
{ {
xTaskCreate( prvEchoClientTask, /* The function that implements the task. */ xTaskCreateStatic( prvEchoClientTask, /* The function that implements the task. */
"Echo0", /* Just a text name for the task to aid debugging. */ "Echo0", /* Just a text name for the task to aid debugging. */
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */ usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
( void * ) x, /* The task parameter, not used in this case. */ ( void * ) x, /* The task parameter, not used in this case. */
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */ uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
NULL ); /* The task handle is not used. */ echoServerTaskStack,
} &echoServerTaskBuffer ); /* The task handle is not used. */
} }
}
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvEchoClientTask( void *pvParameters ) static void prvEchoClientTask( void * pvParameters )
{ {
Socket_t xSocket; Socket_t xSocket;
struct freertos_sockaddr xEchoServerAddress; struct freertos_sockaddr xEchoServerAddress;
int32_t lLoopCount = 0UL; int32_t lLoopCount = 0UL;
const int32_t lMaxLoopCount = 1; const int32_t lMaxLoopCount = 1;
volatile uint32_t ulTxCount = 0UL; volatile uint32_t ulTxCount = 0UL;
BaseType_t xReceivedBytes, xReturned, xInstance; BaseType_t xReceivedBytes, xReturned, xInstance;
BaseType_t lTransmitted, lStringLength; BaseType_t lTransmitted, lStringLength;
char *pcTransmittedString, *pcReceivedString; char * pcTransmittedString, * pcReceivedString;
WinProperties_t xWinProps; WinProperties_t xWinProps;
TickType_t xTimeOnEntering; TickType_t xTimeOnEntering;
BaseType_t ret; BaseType_t ret;
/* Fill in the buffer and window sizes that will be used by the socket. */ /* Fill in the buffer and window sizes that will be used by the socket. */
xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS; xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS;
xWinProps.lTxWinSize = 3; xWinProps.lTxWinSize = 3;
xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS; xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS;
xWinProps.lRxWinSize = 3; xWinProps.lRxWinSize = 3;
/* This task can be created a number of times. Each instance is numbered /* This task can be created a number of times. Each instance is numbered
to enable each instance to use a different Rx and Tx buffer. The number is * to enable each instance to use a different Rx and Tx buffer. The number is
passed in as the task's parameter. */ * passed in as the task's parameter. */
xInstance = ( BaseType_t ) pvParameters; xInstance = ( BaseType_t ) pvParameters;
/* Point to the buffers to be used by this instance of this task. */ /* Point to the buffers to be used by this instance of this task. */
pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] ); pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] );
pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] ); pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] );
/* Echo requests are sent to the echo server. The address of the echo /* Echo requests are sent to the echo server. The address of the echo
server is configured by the constants configECHO_SERVER_ADDR0 to * server is configured by the constants configECHO_SERVER_ADDR0 to
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */ * configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT ); xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
configECHO_SERVER_ADDR1, configECHO_SERVER_ADDR1,
configECHO_SERVER_ADDR2, configECHO_SERVER_ADDR2,
configECHO_SERVER_ADDR3 ); configECHO_SERVER_ADDR3 );
for( ; ; ) for( ; ; )
{ {
/* Create a TCP socket. */ /* Create a TCP socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
configASSERT( xSocket != FREERTOS_INVALID_SOCKET ); configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
/* Set a time out so a missing reply does not cause the task to block /* Set a time out so a missing reply does not cause the task to block
indefinitely. */ * indefinitely. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
/* Set the window and buffer sizes. */ /* Set the window and buffer sizes. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) ); FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
/* Connect to the echo server. */ /* Connect to the echo server. */
printf( "connecting to echo server....\n" ); printf( "connecting to echo server....\n" );
ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) ); ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) );
if( ret == 0 ) if( ret == 0 )
{ {
printf( "Connected to server.. \n" ); printf( "Connected to server.. \n" );
ulConnections[ xInstance ]++; ulConnections[ xInstance ]++;
/* Send a number of echo requests. */ /* Send a number of echo requests. */
for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ ) for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
{ {
/* Create the string that is sent to the echo server. */ /* Create the string that is sent to the echo server. */
lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES ); lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES );
/* Add in some unique text at the front of the string. */ /* Add in some unique text at the front of the string. */
sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount ); sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount );
ulTxCount++; ulTxCount++;
printf( "sending data to the echo server \n" ); printf( "sending data to the echo server \n" );
/* Send the string to the socket. */ /* Send the string to the socket. */
lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */ lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */
( void * ) pcTransmittedString, /* The data being sent. */ ( void * ) pcTransmittedString, /* The data being sent. */
lStringLength, /* The length of the data being sent. */ lStringLength, /* The length of the data being sent. */
0 ); /* No flags. */ 0 ); /* No flags. */
if( lTransmitted < 0 ) if( lTransmitted < 0 )
{ {
/* Error? */ /* Error? */
break; break;
} }
/* Clear the buffer into which the echoed string will be /* Clear the buffer into which the echoed string will be
placed. */ * placed. */
memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES ); memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES );
xReceivedBytes = 0; xReceivedBytes = 0;
/* Receive data echoed back to the socket. */ /* Receive data echoed back to the socket. */
while( xReceivedBytes < lTransmitted ) while( xReceivedBytes < lTransmitted )
{ {
xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */ xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
&( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */ &( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */
lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */ lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */
0 ); /* No flags. */ 0 ); /* No flags. */
if( xReturned < 0 ) if( xReturned < 0 )
{ {
/* Error occurred. Latch it so it can be detected /* Error occurred. Latch it so it can be detected
below. */ * below. */
xReceivedBytes = xReturned; xReceivedBytes = xReturned;
break; break;
} }
else if( xReturned == 0 ) else if( xReturned == 0 )
{ {
/* Timed out. */ /* Timed out. */
break; break;
} }
else else
{ {
/* Keep a count of the bytes received so far. */ /* Keep a count of the bytes received so far. */
xReceivedBytes += xReturned; xReceivedBytes += xReturned;
} }
} }
/* If an error occurred it will be latched in xReceivedBytes, /* If an error occurred it will be latched in xReceivedBytes,
otherwise xReceived bytes will be just that - the number of * otherwise xReceived bytes will be just that - the number of
bytes received from the echo server. */ * bytes received from the echo server. */
if( xReceivedBytes > 0 ) if( xReceivedBytes > 0 )
{ {
/* Compare the transmitted string to the received string. */ /* Compare the transmitted string to the received string. */
configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 ); configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 );
if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 ) if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 )
{ {
/* The echo reply was received without error. */ /* The echo reply was received without error. */
ulTxRxCycles[ xInstance ]++; ulTxRxCycles[ xInstance ]++;
} }
else else
{ {
/* The received string did not match the transmitted /* The received string did not match the transmitted
string. */ * string. */
ulTxRxFailures[ xInstance ]++; ulTxRxFailures[ xInstance ]++;
break; break;
} }
} }
else if( xReceivedBytes < 0 ) else if( xReceivedBytes < 0 )
{ {
/* FreeRTOS_recv() returned an error. */ /* FreeRTOS_recv() returned an error. */
break; break;
} }
else else
{ {
/* Timed out without receiving anything? */ /* Timed out without receiving anything? */
break; break;
} }
} }
/* Finished using the connected socket, initiate a graceful close: /* Finished using the connected socket, initiate a graceful close:
FIN, FIN+ACK, ACK. */ * FIN, FIN+ACK, ACK. */
FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR ); FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR );
/* Expect FreeRTOS_recv() to return an error once the shutdown is /* Expect FreeRTOS_recv() to return an error once the shutdown is
complete. */ * complete. */
xTimeOnEntering = xTaskGetTickCount(); xTimeOnEntering = xTaskGetTickCount();
do do
{ {
xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */ xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
&( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */ &( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */
echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */ echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */
0 ); 0 );
if( xReturned < 0 ) if( xReturned < 0 )
{ {
break; break;
} }
} while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut ); } while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut );
} }
else else
{ {
printf( "Could not connect to server %ld\n", ret ); printf( "Could not connect to server %ld\n", ret );
} }
/* Close this socket before looping back to create another. */ /* Close this socket before looping back to create another. */
FreeRTOS_closesocket( xSocket ); FreeRTOS_closesocket( xSocket );
/* Pause for a short while to ensure the network is not too /* Pause for a short while to ensure the network is not too
congested. */ * congested. */
vTaskDelay( echoLOOP_DELAY ); vTaskDelay( echoLOOP_DELAY );
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static BaseType_t prvCreateTxData( char *cBuffer, static BaseType_t prvCreateTxData( char * cBuffer,
uint32_t ulBufferLength ) uint32_t ulBufferLength )
{ {
BaseType_t lCharactersToAdd, lCharacter; BaseType_t lCharactersToAdd, lCharacter;
char cChar = '0'; char cChar = '0';
const BaseType_t lMinimumLength = 60; const BaseType_t lMinimumLength = 60;
uint32_t ulRandomNumber; uint32_t ulRandomNumber;
/* Randomise the number of characters that will be sent in the echo /* Randomise the number of characters that will be sent in the echo
request. */ * request. */
do do
{ {
( void ) xApplicationGetRandomNumber( &ulRandomNumber ); ( void ) xApplicationGetRandomNumber( &ulRandomNumber );
lCharactersToAdd = ulRandomNumber % ( ulBufferLength - 20UL ); lCharactersToAdd = ulRandomNumber % ( ulBufferLength - 20UL );
} while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */ } while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */
/* Fill the buffer. */ /* Fill the buffer. */
for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ ) for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ )
{ {
cBuffer[ lCharacter ] = cChar; cBuffer[ lCharacter ] = cChar;
cChar++; cChar++;
if( cChar > '~' ) if( cChar > '~' )
{ {
cChar = '0'; cChar = '0';
} }
} }
return lCharactersToAdd; return lCharactersToAdd;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void ) BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void )
{ {
static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 }; static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
BaseType_t xReturn = pdPASS, x; BaseType_t xReturn = pdPASS, x;
/* Return fail is the number of cycles does not increment between /* Return fail is the number of cycles does not increment between
consecutive calls. */ * consecutive calls. */
for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ ) for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
{ {
if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] ) if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] )
{ {
xReturn = pdFAIL; xReturn = pdFAIL;
} }
else else
{ {
ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ]; ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ];
} }
if( ulConnections[ x ] == ulLastConnections[ x ] ) if( ulConnections[ x ] == ulLastConnections[ x ] )
{ {
xReturn = pdFAIL; xReturn = pdFAIL;
} }
else else
{ {
ulConnections[ x ] = ulLastConnections[ x ]; ulConnections[ x ] = ulLastConnections[ x ];
} }
} }
return xReturn; return xReturn;
} }
#endif /* ipconfigUSE_TCP */ #endif /* ipconfigUSE_TCP */

@ -0,0 +1,320 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Main configuration parameters for the trace recorder library.
* More settings can be found in trcStreamingConfig.h and trcSnapshotConfig.h.
*/
#ifndef TRC_CONFIG_H
#define TRC_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************
* 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." */
/**
* @def TRC_CFG_HARDWARE_PORT
* @brief 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_Win64
/**
* @def TRC_CFG_SCHEDULING_ONLY
* @brief 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 (unless filtered in other ways).
*
* Default value is 0 (= include additional events).
*/
#define TRC_CFG_SCHEDULING_ONLY 0
/**
* @def TRC_CFG_INCLUDE_MEMMANG_EVENTS
* @brief 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
/**
* @def TRC_CFG_INCLUDE_USER_EVENTS
* @brief Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), all code related to User Events is excluded in order
* to reduce code size. Any attempts of storing User Events are then silently
* ignored.
*
* User Events are application-generated events, like "printf" but for the
* trace log, generated using vTracePrint and vTracePrintF.
* The formatting is done on host-side, by Tracealyzer. User Events are
* therefore much faster than a console printf and can often be used
* in timing critical code without problems.
*
* Note: In streaming mode, User Events are used to provide error messages
* and warnings from the recorder (in case of incorrect configuration) for
* display in Tracealyzer. Disabling user events will also disable these
* warnings. You can however still catch them by calling xTraceErrorGetLast
* or by putting breakpoints in xTraceError and xTraceWarning.
*
* Default value is 1.
*/
#define TRC_CFG_INCLUDE_USER_EVENTS 1
/**
* @def TRC_CFG_INCLUDE_ISR_TRACING
* @brief 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. This means that any calls to
* vTraceStoreISRBegin/vTraceStoreISREnd will be ignored.
* This does not completely disable ISR tracing, in cases where an ISR is
* calling a traced kernel service. These events will still be recorded and
* show up in anonymous ISR instances in Tracealyzer, with names such as
* "ISR sending to <queue name>".
* To disable such tracing, please refer to vTraceSetFilterGroup and
* vTraceSetFilterMask.
*
* 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
/**
* @def TRC_CFG_INCLUDE_READY_EVENTS
* @brief 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
/**
* @def TRC_CFG_INCLUDE_OSTICK_EVENTS
* @brief 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 1.
*/
#define TRC_CFG_INCLUDE_OSTICK_EVENTS 1
/**
* @def TRC_CFG_ENABLE_STACK_MONITOR
* @brief If enabled (1), the recorder periodically reports the unused stack space of
* all active tasks.
* The stack monitoring runs in the Tracealyzer Control task, TzCtrl. This task
* is always created by the recorder when in streaming mode.
* In snapshot mode, the TzCtrl task is only used for stack monitoring and is
* not created unless this is enabled.
*/
#define TRC_CFG_ENABLE_STACK_MONITOR 1
/**
* @def TRC_CFG_STACK_MONITOR_MAX_TASKS
* @brief Macro which should be defined as a non-zero integer value.
*
* This controls how many tasks that can be monitored by the stack monitor.
* If this is too small, some tasks will be excluded and a warning is shown.
*
* Default value is 10.
*/
#define TRC_CFG_STACK_MONITOR_MAX_TASKS 10
/**
* @def TRC_CFG_STACK_MONITOR_MAX_REPORTS
* @brief Macro which should be defined as a non-zero integer value.
*
* This defines how many tasks that will be subject to stack usage analysis for
* each execution of the Tracealyzer Control task (TzCtrl). Note that the stack
* monitoring cycles between the tasks, so this does not affect WHICH tasks that
* are monitored, but HOW OFTEN each task stack is analyzed.
*
* This setting can be combined with TRC_CFG_CTRL_TASK_DELAY to tune the
* frequency of the stack monitoring. This is motivated since the stack analysis
* can take some time to execute.
* However, note that the stack analysis runs in a separate task (TzCtrl) that
* can be executed on low priority. This way, you can avoid that the stack
* analysis disturbs any time-sensitive tasks.
*
* Default value is 1.
*/
#define TRC_CFG_STACK_MONITOR_MAX_REPORTS 1
/**
* @def TRC_CFG_CTRL_TASK_PRIORITY
* @brief The scheduling priority of the Tracealyzer Control (TzCtrl) task.
*
* In streaming mode, TzCtrl is used to receive start/stop commands from
* Tracealyzer and in some cases also to transmit the trace data (for stream
* ports that uses the internal buffer, like TCP/IP). For such stream ports,
* make sure the TzCtrl priority is high enough to ensure reliable periodic
* execution and transfer of the data, but low enough to avoid disturbing any
* time-sensitive functions.
*
* In Snapshot mode, TzCtrl is only used for the stack usage monitoring and is
* not created if stack monitoring is disabled. TRC_CFG_CTRL_TASK_PRIORITY should
* be low, to avoid disturbing any time-sensitive tasks.
*/
#define TRC_CFG_CTRL_TASK_PRIORITY 1
/**
* @def TRC_CFG_CTRL_TASK_DELAY
* @brief The delay between loops of the TzCtrl task (see TRC_CFG_CTRL_TASK_PRIORITY),
* which affects the frequency of the stack monitoring.
*
* In streaming mode, this also affects the trace data transfer if you are using
* a stream port leveraging the internal buffer (like TCP/IP). A shorter delay
* increases the CPU load of TzCtrl somewhat, but may improve the performance of
* of the trace streaming, especially if the trace buffer is small.
*/
#define TRC_CFG_CTRL_TASK_DELAY 2
/**
* @def TRC_CFG_CTRL_TASK_STACK_SIZE
* @brief The stack size of the Tracealyzer Control (TzCtrl) task.
* See TRC_CFG_CTRL_TASK_PRIORITY for further information about TzCtrl.
*/
#define TRC_CFG_CTRL_TASK_STACK_SIZE 4096
/**
* @def TRC_CFG_RECORDER_BUFFER_ALLOCATION
* @brief 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
/**
* @def TRC_CFG_MAX_ISR_NESTING
* @brief 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
/**
* @def TRC_CFG_ISR_TAILCHAINING_THRESHOLD
* @brief 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
/**
* @def TRC_CFG_RECORDER_DATA_INIT
* @brief Macro which states wether the recorder data should have an initial value.
*
* In very specific cases where traced objects are created before main(),
* the recorder will need to be started even before that. In these cases,
* the recorder data would be initialized by vTraceEnable(TRC_INIT) but could
* then later be overwritten by the initialization value.
* If this is an issue for you, set TRC_CFG_RECORDER_DATA_INIT to 0.
* The following code can then be used before any traced objects are created:
*
* extern uint32_t RecorderEnabled;
* RecorderEnabled = 0;
* xTraceInitialize();
*
* After the clocks are properly initialized, use vTraceEnable(...) to start
* the tracing.
*
* Default value is 1.
*/
#define TRC_CFG_RECORDER_DATA_INIT 1
/**
* @def TRC_CFG_RECORDER_DATA_ATTRIBUTE
* @brief When setting TRC_CFG_RECORDER_DATA_INIT to 0, you might also need to make
* sure certain recorder data is placed in a specific RAM section to avoid being
* zeroed out after initialization. Define TRC_CFG_RECORDER_DATA_ATTRIBUTE as
* that attribute.
*
* Example:
* #define TRC_CFG_RECORDER_DATA_ATTRIBUTE __attribute__((section(".bss.trace_recorder_data")))
*
* Default value is empty.
*/
#define TRC_CFG_RECORDER_DATA_ATTRIBUTE
/**
* @def TRC_CFG_USE_TRACE_ASSERT
* @brief Enable or disable debug asserts. Information regarding any assert that is
* triggered will be in trcAssert.c.
*/
#define TRC_CFG_USE_TRACE_ASSERT 1
#ifdef __cplusplus
}
#endif
#endif /* _TRC_CONFIG_H */

@ -14,7 +14,7 @@
#define TRC_KERNEL_PORT_CONFIG_H #define TRC_KERNEL_PORT_CONFIG_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** /**
@ -30,7 +30,7 @@ extern "C" {
* TRC_RECORDER_MODE_SNAPSHOT * TRC_RECORDER_MODE_SNAPSHOT
* TRC_RECORDER_MODE_STREAMING * TRC_RECORDER_MODE_STREAMING
*/ */
#define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT #define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_SNAPSHOT
/** /**
* @def TRC_CFG_FREERTOS_VERSION * @def TRC_CFG_FREERTOS_VERSION
@ -56,7 +56,7 @@ extern "C" {
* TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0 * TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0
* TRC_FREERTOS_VERSION_10_4_1 If using FreeRTOS v10.4.1 or later * TRC_FREERTOS_VERSION_10_4_1 If using FreeRTOS v10.4.1 or later
*/ */
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_1 #define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_1
/** /**
* @def TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS * @def TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
@ -66,7 +66,7 @@ extern "C" {
* *
* Default value is 0 (excluded) since dependent on event_groups.c * Default value is 0 (excluded) since dependent on event_groups.c
*/ */
#define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 1 #define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 1
/** /**
* @def TRC_CFG_INCLUDE_TIMER_EVENTS * @def TRC_CFG_INCLUDE_TIMER_EVENTS
@ -76,7 +76,7 @@ extern "C" {
* *
* Default value is 0 since dependent on timers.c * Default value is 0 since dependent on timers.c
*/ */
#define TRC_CFG_INCLUDE_TIMER_EVENTS 1 #define TRC_CFG_INCLUDE_TIMER_EVENTS 1
/** /**
* @def TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS * @def TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
@ -87,7 +87,7 @@ extern "C" {
* *
* Default value is 0 since dependent on timers.c * Default value is 0 since dependent on timers.c
*/ */
#define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1 #define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1
/** /**
* @def TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS * @def TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
@ -98,7 +98,7 @@ extern "C" {
* *
* Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10) * Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10)
*/ */
#define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 1 #define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 1
/** /**
* @def TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND * @def TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND
@ -107,7 +107,7 @@ extern "C" {
* traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from * traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from
* other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED. * other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED.
*/ */
#define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND 0 /* TRC_ACKNOWLEDGED */ #define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND 0 /* TRC_ACKNOWLEDGED */
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -0,0 +1,69 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Kernel port configuration parameters for snapshot mode.
*/
#ifndef TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H
#define TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE...
* @brief 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 150
#define TRC_CFG_NISR 90
#define TRC_CFG_NQUEUE 90
#define TRC_CFG_NSEMAPHORE 90
#define TRC_CFG_NMUTEX 90
#define TRC_CFG_NTIMER 250
#define TRC_CFG_NEVENTGROUP 90
#define TRC_CFG_NSTREAMBUFFER 50
#define TRC_CFG_NMESSAGEBUFFER 50
/**
* @def TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ...
* @brief 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
#define TRC_CFG_NAME_LEN_STREAMBUFFER 15
#define TRC_CFG_NAME_LEN_MESSAGEBUFFER 15
#ifdef __cplusplus
}
#endif
#endif /* TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H */

@ -0,0 +1,245 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Configuration parameters for trace recorder library in snapshot mode.
* Read more at http://percepio.com/2016/10/05/rtos-tracing/
*/
#ifndef TRC_SNAPSHOT_CONFIG_H
#define TRC_SNAPSHOT_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def TRC_CFG_SNAPSHOT_MODE
* @brief 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
/**
* @def TRC_CFG_EVENT_BUFFER_SIZE
* @brief 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 50000
/**
* @def TRC_CFG_INCLUDE_FLOAT_SUPPORT
* @brief 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
/**
* @def TRC_CFG_SYMBOL_TABLE_SIZE
* @brief 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 8000
#if ( TRC_CFG_SYMBOL_TABLE_SIZE == 0 )
#error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!"
#endif
/******************************************************************************
*** 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.
*****************************************************************************/
/**
* @def TRC_CFG_HEAP_SIZE_BELOW_16M
* @brief 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
/**
* @def TRC_CFG_USE_IMPLICIT_IFE_RULES
* @brief 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 xTraceTaskInstanceFinishedNow and xTraceTaskInstanceFinishedNext.
*
* 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 xTraceTaskInstanceFinishedNow/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 xTraceTaskInstanceFinishedNow or
* xTraceTaskInstanceFinishedNext 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.
*/
#define TRC_CFG_USE_IMPLICIT_IFE_RULES 1
/**
* @def TRC_CFG_USE_16BIT_OBJECT_HANDLES
* @brief 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 1
/**
* @def TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER
* @brief 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:
* TraceStringHandle_t chn1;
* TraceStringHandle_t fmt1;
* xTraceStringRegister("Channel 1", &chn1);
* xTraceStringRegister("Event!", &fmt1);
* traceUBChannel UBCh1 = xTraceRegisterUBChannel(chn1, fmt1);
*
* TraceStringHandle_t chn2;
* TraceStringHandle_t fmt2;
* xTraceStringRegister("Channel 2", &chn2);
* xTraceStringRegister("X: %d, Y: %d", &fmt2);
* 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 xTracePrintF.
* 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")
* xTracePrintF(chn2, "%Z: %d", value1);
*
* // Finds the existing UB channel
* xTracePrintF(chn2, "%Z: %d", value2);
*/
#define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 1
/**
* @def TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE
* @brief 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
/**
* @def TRC_CFG_UB_CHANNELS
* @brief 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
#ifdef __cplusplus
}
#endif
#endif /*TRC_SNAPSHOT_CONFIG_H*/

@ -25,8 +25,8 @@
*/ */
/*----------------------------------------------------------- /*-----------------------------------------------------------
* Example console I/O wrappers. * Example console I/O wrappers.
*----------------------------------------------------------*/ *----------------------------------------------------------*/
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@ -37,21 +37,22 @@
SemaphoreHandle_t xStdioMutex; SemaphoreHandle_t xStdioMutex;
StaticSemaphore_t xStdioMutexBuffer; StaticSemaphore_t xStdioMutexBuffer;
void console_init(void) void console_init( void )
{ {
xStdioMutex = xSemaphoreCreateMutexStatic(&xStdioMutexBuffer); xStdioMutex = xSemaphoreCreateMutexStatic( &xStdioMutexBuffer );
} }
void console_print(const char *fmt, ...) void console_print( const char * fmt,
... )
{ {
va_list vargs; va_list vargs;
va_start(vargs, fmt); va_start( vargs, fmt );
xSemaphoreTake(xStdioMutex, portMAX_DELAY); xSemaphoreTake( xStdioMutex, portMAX_DELAY );
vprintf(fmt, vargs); vprintf( fmt, vargs );
va_end(vargs); va_end( vargs );
} }

@ -51,6 +51,9 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
#include <time.h>
#include <errno.h>
#include <string.h>
/* FreeRTOS kernel includes. */ /* FreeRTOS kernel includes. */
#include "FreeRTOS.h" #include "FreeRTOS.h"
@ -59,15 +62,17 @@
/* Local includes. */ /* Local includes. */
#include "console.h" #include "console.h"
#define ECHO_CLIENT_DEMO 0 #include <trcRecorder.h>
#define mainSELECTED_APPLICATION ECHO_CLIENT_DEMO #define ECHO_CLIENT_DEMO 0
#define mainSELECTED_APPLICATION ECHO_CLIENT_DEMO
/* This demo uses heap_3.c (the libc provided malloc() and free()). */ /* This demo uses heap_3.c (the libc provided malloc() and free()). */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
extern void main_tcp_echo_client_tasks( void ); extern void main_tcp_echo_client_tasks( void );
// static void traceOnEnter( void ); static void traceOnEnter( void );
/* /*
* Prototypes for the standard FreeRTOS application hook (callback) functions * Prototypes for the standard FreeRTOS application hook (callback) functions
@ -76,47 +81,62 @@ extern void main_tcp_echo_client_tasks( void );
void vApplicationMallocFailedHook( void ); void vApplicationMallocFailedHook( void );
void vApplicationIdleHook( void ); void vApplicationIdleHook( void );
void vApplicationStackOverflowHook( TaskHandle_t pxTask, void vApplicationStackOverflowHook( TaskHandle_t pxTask,
char *pcTaskName ); char * pcTaskName );
void vApplicationTickHook( void ); void vApplicationTickHook( void );
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer, StackType_t ** ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize ); uint32_t * pulIdleTaskStackSize );
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer, StackType_t ** ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize ); uint32_t * pulTimerTaskStackSize );
/* /*
* Writes trace data to a disk file when the trace recording is stopped. * Writes trace data to a disk file when the trace recording is stopped.
* This function will simply overwrite any trace files that already exist. * This function will simply overwrite any trace files that already exist.
*/ */
// static void prvSaveTraceFile( void ); static void prvSaveTraceFile( void );
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can /* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can
use a callback function to optionally provide the memory required by the idle * use a callback function to optionally provide the memory required by the idle
and timer tasks. This is the stack that will be used by the timer task. It is * and timer tasks. This is the stack that will be used by the timer task. It is
declared here, as a global, so it can be checked by a test that is implemented * declared here, as a global, so it can be checked by a test that is implemented
in a different file. */ * in a different file. */
StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
/* Notes if the trace is running or not. */ /* Notes if the trace is running or not. */
// static BaseType_t xTraceRunning = pdTRUE; static BaseType_t xTraceRunning = pdTRUE;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
int main( void ) int main( void )
{ {
/* Do not include trace code when performing a code coverage analysis. */
#if ( projCOVERAGE_TEST != 1 )
{
/* Initialise the trace recorder. Use of the trace recorder is optional.
* See http://www.FreeRTOS.org/trace for more information. */
xTraceEnable( TRC_START );
/* Start the trace recording - the recording is written to a file if
* configASSERT() is called. */
printf( "\r\nTrace started.\r\nThe trace will be dumped to disk if a call to configASSERT() fails.\r\n" );
printf( "\r\nThe trace will be dumped to disk if Enter is hit.\r\n" );
traceSTART();
}
#endif
console_init(); console_init();
#if ( mainSELECTED_APPLICATION == ECHO_CLIENT_DEMO ) #if ( mainSELECTED_APPLICATION == ECHO_CLIENT_DEMO )
{ {
console_print("Starting echo client demo\n"); console_print( "Starting echo client demo\n" );
main_tcp_echo_client_tasks(); main_tcp_echo_client_tasks();
} }
#else #else
{ {
#error "The selected demo is not valid" #error "The selected demo is not valid"
} }
#endif /* if ( mainSELECTED_APPLICATION ) */ #endif /* if ( mainSELECTED_APPLICATION ) */
return 0; return 0;
@ -126,17 +146,17 @@ int main( void )
void vApplicationMallocFailedHook( void ) void vApplicationMallocFailedHook( void )
{ {
/* vApplicationMallocFailedHook() will only be called if /* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
function that will get called if a call to pvPortMalloc() fails. * function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue, * pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created. It is also called by various parts of the * timer or semaphore is created. It is also called by various parts of the
demo application. If heap_1.c, heap_2.c or heap_4.c is being used, then the * demo application. If heap_1.c, heap_2.c or heap_4.c is being used, then the
size of the heap available to pvPortMalloc() is defined by * size of the heap available to pvPortMalloc() is defined by
configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() * configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
API function can be used to query the size of free heap space that remains * API function can be used to query the size of free heap space that remains
(although it does not provide information on how the remaining heap might be * (although it does not provide information on how the remaining heap might be
fragmented). See http://www.freertos.org/a00111.html for more * fragmented). See http://www.freertos.org/a00111.html for more
information. */ * information. */
vAssertCalled( __FILE__, __LINE__ ); vAssertCalled( __FILE__, __LINE__ );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -144,32 +164,32 @@ void vApplicationMallocFailedHook( void )
void vApplicationIdleHook( void ) void vApplicationIdleHook( void )
{ {
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle * to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
task. It is essential that code added to this hook function never attempts * task. It is essential that code added to this hook function never attempts
to block in any way (for example, call xQueueReceive() with a block time * to block in any way (for example, call xQueueReceive() with a block time
specified, or call vTaskDelay()). If application tasks make use of the * specified, or call vTaskDelay()). If application tasks make use of the
vTaskDelete() API function to delete themselves then it is also important * vTaskDelete() API function to delete themselves then it is also important
that vApplicationIdleHook() is permitted to return to its calling function, * that vApplicationIdleHook() is permitted to return to its calling function,
because it is the responsibility of the idle task to clean up memory * because it is the responsibility of the idle task to clean up memory
allocated by the kernel to any task that has since deleted itself. */ * allocated by the kernel to any task that has since deleted itself. */
usleep(15000); usleep( 15000 );
// traceOnEnter(); traceOnEnter();
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vApplicationStackOverflowHook( TaskHandle_t pxTask, void vApplicationStackOverflowHook( TaskHandle_t pxTask,
char *pcTaskName ) char * pcTaskName )
{ {
( void ) pcTaskName; ( void ) pcTaskName;
( void ) pxTask; ( void ) pxTask;
/* Run time stack overflow checking is performed if /* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook * configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. This function is * function is called if a stack overflow is detected. This function is
provided as an example only as stack overflow checking does not function * provided as an example only as stack overflow checking does not function
when running the FreeRTOS POSIX port. */ * when running the FreeRTOS POSIX port. */
vAssertCalled( __FILE__, __LINE__ ); vAssertCalled( __FILE__, __LINE__ );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -177,16 +197,44 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask,
void vApplicationTickHook( void ) void vApplicationTickHook( void )
{ {
/* This function will be called by each tick interrupt if /* This function will be called by each tick interrupt if
configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be * configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
added here, but the tick hook is called from an interrupt context, so * added here, but the tick hook is called from an interrupt context, so
code must not attempt to block, and only the interrupt safe FreeRTOS API * code must not attempt to block, and only the interrupt safe FreeRTOS API
functions can be used (those that end in FromISR()). */ * functions can be used (those that end in FromISR()). */
} }
void vLoggingPrintf( const char *pcFormat, void traceOnEnter()
{
int xReturn;
struct timeval tv = { 0L, 0L };
fd_set fds;
FD_ZERO( &fds );
FD_SET( STDIN_FILENO, &fds );
xReturn = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
if( xReturn > 0 )
{
if( xTraceRunning == pdTRUE )
{
taskENTER_CRITICAL();
{
prvSaveTraceFile();
}
taskEXIT_CRITICAL();
}
/* clear the buffer */
char buffer[ 1 ];
read( STDIN_FILENO, &buffer, 1 );
}
}
void vLoggingPrintf( const char * pcFormat,
... ) ... )
{ {
va_list arg; va_list arg;
va_start( arg, pcFormat ); va_start( arg, pcFormat );
vprintf( pcFormat, arg ); vprintf( pcFormat, arg );
@ -197,9 +245,9 @@ va_list arg;
void vApplicationDaemonTaskStartupHook( void ) void vApplicationDaemonTaskStartupHook( void )
{ {
/* This function will be called once only, when the daemon task starts to /* This function will be called once only, when the daemon task starts to
execute (sometimes called the timer task). This is useful if the * execute (sometimes called the timer task). This is useful if the
application includes initialisation code that would benefit from executing * application includes initialisation code that would benefit from executing
after the scheduler has been started. */ * after the scheduler has been started. */
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -208,67 +256,132 @@ void vAssertCalled( const char * const pcFileName,
{ {
static BaseType_t xPrinted = pdFALSE; static BaseType_t xPrinted = pdFALSE;
volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0; volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
/* Copy the parameters to local volatile variables, just for debugging */
volatile char * pcFile = ( volatile char * ) pcFileName;
volatile uint32_t ulLineNumber = ulLine;
/* Called if an assertion passed to configASSERT() fails. See /* Called if an assertion passed to configASSERT() fails. See
http://www.freertos.org/a00110.html#configASSERT for more information. */ * https://www.FreeRTOS.org/a00110.html#configASSERT for more information. */
/* Parameters are not used. */
( void ) ulLine;
( void ) pcFileName;
printf( "vAssertCalled( %s, %u )\n", pcFileName, ulLine ); taskENTER_CRITICAL();
exit(1); {
/* Stop the trace recording. */
if( xPrinted == pdFALSE )
{
xPrinted = pdTRUE;
if( xTraceRunning == pdTRUE )
{
prvSaveTraceFile();
}
}
/* You can step out of this function to debug the assertion by using
* the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero
* value. */
while( ulSetToNonZeroInDebuggerToContinue == 1 )
{
__asm volatile ( "NOP" );
__asm volatile ( "NOP" );
}
}
taskEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/
static void prvSaveTraceFile( void )
{
/* Tracing is not used when code coverage analysis is being performed. */
#if ( projCOVERAGE_TEST != 1 )
{
FILE * pxOutputFile;
pxOutputFile = fopen( "Trace.dump", "wb" );
if( pxOutputFile != NULL )
{
{
xTraceDisable();
fwrite( RecorderDataPtr, sizeof( RecorderDataType ), 1, pxOutputFile );
fclose( pxOutputFile );
printf( "\r\nTrace output saved to Trace.dump\r\n" );
xTraceEnable( TRC_START );
}
}
else
{
printf( "\r\nFailed to create trace dump file\r\n" );
}
}
#endif /* if ( projCOVERAGE_TEST != 1 ) */
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
implementation of vApplicationGetIdleTaskMemory() to provide the memory that is * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
used by the Idle task. */ * used by the Idle task. */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer, StackType_t ** ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize ) uint32_t * pulIdleTaskStackSize )
{ {
/* If the buffers to be provided to the Idle task are declared inside this /* If the buffers to be provided to the Idle task are declared inside this
function then they must be declared static - otherwise they will be allocated on * function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */ * the stack and so not exists after this function exits. */
static StaticTask_t xIdleTaskTCB; static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
state will be stored. */ * state will be stored. */
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB; *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
/* Pass out the array that will be used as the Idle task's stack. */ /* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = uxIdleTaskStack; *ppxIdleTaskStackBuffer = uxIdleTaskStack;
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t, * Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */ * configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
application must provide an implementation of vApplicationGetTimerTaskMemory() * application must provide an implementation of vApplicationGetTimerTaskMemory()
to provide the memory that is used by the Timer service task. */ * to provide the memory that is used by the Timer service task. */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer, StackType_t ** ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize ) uint32_t * pulTimerTaskStackSize )
{ {
/* If the buffers to be provided to the Timer task are declared inside this /* If the buffers to be provided to the Timer task are declared inside this
function then they must be declared static - otherwise they will be allocated on * function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */ * the stack and so not exists after this function exits. */
static StaticTask_t xTimerTaskTCB; static StaticTask_t xTimerTaskTCB;
/* Pass out a pointer to the StaticTask_t structure in which the Timer /* Pass out a pointer to the StaticTask_t structure in which the Timer
task's state will be stored. */ * task's state will be stored. */
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB; *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
/* Pass out the array that will be used as the Timer task's stack. */ /* Pass out the array that will be used as the Timer task's stack. */
*ppxTimerTaskStackBuffer = uxTimerTaskStack; *ppxTimerTaskStackBuffer = uxTimerTaskStack;
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t, * Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */ * configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
} }
static uint32_t ulEntryTime = 0U;
void vTraceTimerReset( void )
{
ulEntryTime = xTaskGetTickCount();
}
uint32_t uiTraceTimerGetFrequency( void )
{
return configTICK_RATE_HZ;
}
uint32_t uiTraceTimerGetValue( void )
{
return( xTaskGetTickCount() - ulEntryTime );
}

@ -34,7 +34,7 @@
* *
* Also note that it is assumed this demo is going to be used for short periods * Also note that it is assumed this demo is going to be used for short periods
* of time only, and therefore timer overflows are not handled. * of time only, and therefore timer overflows are not handled.
*/ */
#include <time.h> #include <time.h>
@ -48,20 +48,20 @@ static unsigned long ulStartTimeNs;
void vConfigureTimerForRunTimeStats( void ) void vConfigureTimerForRunTimeStats( void )
{ {
struct timespec xNow; struct timespec xNow;
clock_gettime(CLOCK_MONOTONIC, &xNow); clock_gettime( CLOCK_MONOTONIC, &xNow );
ulStartTimeNs = xNow.tv_sec * 1000000000ul + xNow.tv_nsec; ulStartTimeNs = xNow.tv_sec * 1000000000ul + xNow.tv_nsec;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
unsigned long ulGetRunTimeCounterValue( void ) unsigned long ulGetRunTimeCounterValue( void )
{ {
struct timespec xNow; struct timespec xNow;
/* Time at start. */ /* Time at start. */
clock_gettime(CLOCK_MONOTONIC, &xNow); clock_gettime( CLOCK_MONOTONIC, &xNow );
return xNow.tv_sec * 1000000000ul + xNow.tv_nsec - ulStartTimeNs; return xNow.tv_sec * 1000000000ul + xNow.tv_nsec - ulStartTimeNs;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

@ -1,290 +0,0 @@
/*******************************************************************************
* 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 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_Win32
/*******************************************************************************
* 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
/*******************************************************************************
* 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 (unless filtered in other ways).
*
* Default value is 0 (= include additional events).
******************************************************************************/
#define TRC_CFG_SCHEDULING_ONLY 0
/******************************************************************************
* 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), all code related to User Events is excluded in order
* to reduce code size. Any attempts of storing User Events are then silently
* ignored.
*
* User Events are application-generated events, like "printf" but for the
* trace log, generated using vTracePrint and vTracePrintF.
* The formatting is done on host-side, by Tracealyzer. User Events are
* therefore much faster than a console printf and can often be used
* in timing critical code without problems.
*
* Note: In streaming mode, User Events are used to provide error messages
* and warnings from the recorder (in case of incorrect configuration) for
* display in Tracealyzer. Disabling user events will also disable these
* warnings. You can however still catch them by calling xTraceGetLastError
* or by putting breakpoints in prvTraceError and prvTraceWarning.
*
* 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 1.
*****************************************************************************/
#define TRC_CFG_INCLUDE_OSTICK_EVENTS 1
/*****************************************************************************
* TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any "event group" events.
*
* Default value is 0 (excluded) since dependent on event_groups.c
*****************************************************************************/
#define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 1
/*****************************************************************************
* TRC_CFG_INCLUDE_TIMER_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any Timer events.
*
* Default value is 0 since dependent on timers.c
*****************************************************************************/
#define TRC_CFG_INCLUDE_TIMER_EVENTS 1
/*****************************************************************************
* TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any "pending function call"
* events, such as xTimerPendFunctionCall().
*
* Default value is 0 since dependent on timers.c
*****************************************************************************/
#define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1
/*******************************************************************************
* Configuration Macro: TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
*
* Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any stream buffer or message
* buffer events.
*
* Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10)
******************************************************************************/
#define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 1
/*******************************************************************************
* 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_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
#define TRC_CFG_CTRL_TASK_STACK_SIZE ( 1024 )
#define TRC_CFG_CTRL_TASK_PRIORITY 1
#define TRC_CFG_CTRL_TASK_DELAY 2
#define TRC_CFG_RECORDER_DATA_ATTRIBUTE
/* 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 */

@ -1,345 +0,0 @@
/*******************************************************************************
* 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_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 32000
/******************************************************************************
* 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_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 32000
#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
#define TRC_CFG_NAME_LEN_STREAMBUFFER 15
#define TRC_CFG_NAME_LEN_MESSAGEBUFFER 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*/

@ -13,6 +13,7 @@ FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL))
KERNEL_DIR := ${FREERTOS_DIR}/Source KERNEL_DIR := ${FREERTOS_DIR}/Source
INCLUDE_DIRS := -I. INCLUDE_DIRS := -I.
INCLUDE_DIRS += -I./Trace_Recorder_Configuration
INCLUDE_DIRS += -I${KERNEL_DIR}/include INCLUDE_DIRS += -I${KERNEL_DIR}/include
INCLUDE_DIRS += -I${KERNEL_DIR}/portable/ThirdParty/GCC/Posix INCLUDE_DIRS += -I${KERNEL_DIR}/portable/ThirdParty/GCC/Posix
INCLUDE_DIRS += -I${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/utils INCLUDE_DIRS += -I${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/utils

@ -0,0 +1,320 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Main configuration parameters for the trace recorder library.
* More settings can be found in trcStreamingConfig.h and trcSnapshotConfig.h.
*/
#ifndef TRC_CONFIG_H
#define TRC_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************
* 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." */
/**
* @def TRC_CFG_HARDWARE_PORT
* @brief 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_Win32
/**
* @def TRC_CFG_SCHEDULING_ONLY
* @brief 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 (unless filtered in other ways).
*
* Default value is 0 (= include additional events).
*/
#define TRC_CFG_SCHEDULING_ONLY 0
/**
* @def TRC_CFG_INCLUDE_MEMMANG_EVENTS
* @brief 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
/**
* @def TRC_CFG_INCLUDE_USER_EVENTS
* @brief Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), all code related to User Events is excluded in order
* to reduce code size. Any attempts of storing User Events are then silently
* ignored.
*
* User Events are application-generated events, like "printf" but for the
* trace log, generated using vTracePrint and vTracePrintF.
* The formatting is done on host-side, by Tracealyzer. User Events are
* therefore much faster than a console printf and can often be used
* in timing critical code without problems.
*
* Note: In streaming mode, User Events are used to provide error messages
* and warnings from the recorder (in case of incorrect configuration) for
* display in Tracealyzer. Disabling user events will also disable these
* warnings. You can however still catch them by calling xTraceErrorGetLast
* or by putting breakpoints in xTraceError and xTraceWarning.
*
* Default value is 1.
*/
#define TRC_CFG_INCLUDE_USER_EVENTS 1
/**
* @def TRC_CFG_INCLUDE_ISR_TRACING
* @brief 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. This means that any calls to
* vTraceStoreISRBegin/vTraceStoreISREnd will be ignored.
* This does not completely disable ISR tracing, in cases where an ISR is
* calling a traced kernel service. These events will still be recorded and
* show up in anonymous ISR instances in Tracealyzer, with names such as
* "ISR sending to <queue name>".
* To disable such tracing, please refer to vTraceSetFilterGroup and
* vTraceSetFilterMask.
*
* 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
/**
* @def TRC_CFG_INCLUDE_READY_EVENTS
* @brief 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
/**
* @def TRC_CFG_INCLUDE_OSTICK_EVENTS
* @brief 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 1.
*/
#define TRC_CFG_INCLUDE_OSTICK_EVENTS 1
/**
* @def TRC_CFG_ENABLE_STACK_MONITOR
* @brief If enabled (1), the recorder periodically reports the unused stack space of
* all active tasks.
* The stack monitoring runs in the Tracealyzer Control task, TzCtrl. This task
* is always created by the recorder when in streaming mode.
* In snapshot mode, the TzCtrl task is only used for stack monitoring and is
* not created unless this is enabled.
*/
#define TRC_CFG_ENABLE_STACK_MONITOR 1
/**
* @def TRC_CFG_STACK_MONITOR_MAX_TASKS
* @brief Macro which should be defined as a non-zero integer value.
*
* This controls how many tasks that can be monitored by the stack monitor.
* If this is too small, some tasks will be excluded and a warning is shown.
*
* Default value is 10.
*/
#define TRC_CFG_STACK_MONITOR_MAX_TASKS 10
/**
* @def TRC_CFG_STACK_MONITOR_MAX_REPORTS
* @brief Macro which should be defined as a non-zero integer value.
*
* This defines how many tasks that will be subject to stack usage analysis for
* each execution of the Tracealyzer Control task (TzCtrl). Note that the stack
* monitoring cycles between the tasks, so this does not affect WHICH tasks that
* are monitored, but HOW OFTEN each task stack is analyzed.
*
* This setting can be combined with TRC_CFG_CTRL_TASK_DELAY to tune the
* frequency of the stack monitoring. This is motivated since the stack analysis
* can take some time to execute.
* However, note that the stack analysis runs in a separate task (TzCtrl) that
* can be executed on low priority. This way, you can avoid that the stack
* analysis disturbs any time-sensitive tasks.
*
* Default value is 1.
*/
#define TRC_CFG_STACK_MONITOR_MAX_REPORTS 1
/**
* @def TRC_CFG_CTRL_TASK_PRIORITY
* @brief The scheduling priority of the Tracealyzer Control (TzCtrl) task.
*
* In streaming mode, TzCtrl is used to receive start/stop commands from
* Tracealyzer and in some cases also to transmit the trace data (for stream
* ports that uses the internal buffer, like TCP/IP). For such stream ports,
* make sure the TzCtrl priority is high enough to ensure reliable periodic
* execution and transfer of the data, but low enough to avoid disturbing any
* time-sensitive functions.
*
* In Snapshot mode, TzCtrl is only used for the stack usage monitoring and is
* not created if stack monitoring is disabled. TRC_CFG_CTRL_TASK_PRIORITY should
* be low, to avoid disturbing any time-sensitive tasks.
*/
#define TRC_CFG_CTRL_TASK_PRIORITY 1
/**
* @def TRC_CFG_CTRL_TASK_DELAY
* @brief The delay between loops of the TzCtrl task (see TRC_CFG_CTRL_TASK_PRIORITY),
* which affects the frequency of the stack monitoring.
*
* In streaming mode, this also affects the trace data transfer if you are using
* a stream port leveraging the internal buffer (like TCP/IP). A shorter delay
* increases the CPU load of TzCtrl somewhat, but may improve the performance of
* of the trace streaming, especially if the trace buffer is small.
*/
#define TRC_CFG_CTRL_TASK_DELAY 2
/**
* @def TRC_CFG_CTRL_TASK_STACK_SIZE
* @brief The stack size of the Tracealyzer Control (TzCtrl) task.
* See TRC_CFG_CTRL_TASK_PRIORITY for further information about TzCtrl.
*/
#define TRC_CFG_CTRL_TASK_STACK_SIZE 1024
/**
* @def TRC_CFG_RECORDER_BUFFER_ALLOCATION
* @brief 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
/**
* @def TRC_CFG_MAX_ISR_NESTING
* @brief 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
/**
* @def TRC_CFG_ISR_TAILCHAINING_THRESHOLD
* @brief 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
/**
* @def TRC_CFG_RECORDER_DATA_INIT
* @brief Macro which states wether the recorder data should have an initial value.
*
* In very specific cases where traced objects are created before main(),
* the recorder will need to be started even before that. In these cases,
* the recorder data would be initialized by vTraceEnable(TRC_INIT) but could
* then later be overwritten by the initialization value.
* If this is an issue for you, set TRC_CFG_RECORDER_DATA_INIT to 0.
* The following code can then be used before any traced objects are created:
*
* extern uint32_t RecorderEnabled;
* RecorderEnabled = 0;
* xTraceInitialize();
*
* After the clocks are properly initialized, use vTraceEnable(...) to start
* the tracing.
*
* Default value is 1.
*/
#define TRC_CFG_RECORDER_DATA_INIT 1
/**
* @def TRC_CFG_RECORDER_DATA_ATTRIBUTE
* @brief When setting TRC_CFG_RECORDER_DATA_INIT to 0, you might also need to make
* sure certain recorder data is placed in a specific RAM section to avoid being
* zeroed out after initialization. Define TRC_CFG_RECORDER_DATA_ATTRIBUTE as
* that attribute.
*
* Example:
* #define TRC_CFG_RECORDER_DATA_ATTRIBUTE __attribute__((section(".bss.trace_recorder_data")))
*
* Default value is empty.
*/
#define TRC_CFG_RECORDER_DATA_ATTRIBUTE
/**
* @def TRC_CFG_USE_TRACE_ASSERT
* @brief Enable or disable debug asserts. Information regarding any assert that is
* triggered will be in trcAssert.c.
*/
#define TRC_CFG_USE_TRACE_ASSERT 0
#ifdef __cplusplus
}
#endif
#endif /* _TRC_CONFIG_H */

@ -0,0 +1,116 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Configuration parameters for the kernel port.
* More settings can be found in trcKernelPortStreamingConfig.h and
* trcKernelPortSnapshotConfig.h.
*/
#ifndef TRC_KERNEL_PORT_CONFIG_H
#define TRC_KERNEL_PORT_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def TRC_CFG_RECORDER_MODE
* @brief 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
/**
* @def TRC_CFG_FREERTOS_VERSION
* @brief 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_X If using FreeRTOS v7.3.X
* TRC_FREERTOS_VERSION_7_4_X If using FreeRTOS v7.4.X
* TRC_FREERTOS_VERSION_7_5_X If using FreeRTOS v7.5.X
* TRC_FREERTOS_VERSION_7_6_X If using FreeRTOS v7.6.X
* TRC_FREERTOS_VERSION_8_X_X If using FreeRTOS v8.X.X
* TRC_FREERTOS_VERSION_9_0_0 If using FreeRTOS v9.0.0
* TRC_FREERTOS_VERSION_9_0_1 If using FreeRTOS v9.0.1
* TRC_FREERTOS_VERSION_9_0_2 If using FreeRTOS v9.0.2
* TRC_FREERTOS_VERSION_10_0_0 If using FreeRTOS v10.0.0
* TRC_FREERTOS_VERSION_10_0_1 If using FreeRTOS v10.0.1
* TRC_FREERTOS_VERSION_10_1_0 If using FreeRTOS v10.1.0
* TRC_FREERTOS_VERSION_10_1_1 If using FreeRTOS v10.1.1
* TRC_FREERTOS_VERSION_10_2_0 If using FreeRTOS v10.2.0
* TRC_FREERTOS_VERSION_10_2_1 If using FreeRTOS v10.2.1
* TRC_FREERTOS_VERSION_10_3_0 If using FreeRTOS v10.3.0
* TRC_FREERTOS_VERSION_10_3_1 If using FreeRTOS v10.3.1
* TRC_FREERTOS_VERSION_10_4_0 If using FreeRTOS v10.4.0
* TRC_FREERTOS_VERSION_10_4_1 If using FreeRTOS v10.4.1 or later
*/
#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_1
/**
* @def TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS
* @brief Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any "event group" events.
*
* Default value is 0 (excluded) since dependent on event_groups.c
*/
#define TRC_CFG_INCLUDE_EVENT_GROUP_EVENTS 1
/**
* @def TRC_CFG_INCLUDE_TIMER_EVENTS
* @brief Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any Timer events.
*
* Default value is 0 since dependent on timers.c
*/
#define TRC_CFG_INCLUDE_TIMER_EVENTS 1
/**
* @def TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS
* @brief Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any "pending function call"
* events, such as xTimerPendFunctionCall().
*
* Default value is 0 since dependent on timers.c
*/
#define TRC_CFG_INCLUDE_PEND_FUNC_CALL_EVENTS 1
/**
* @def TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS
* @brief Macro which should be defined as either zero (0) or one (1).
*
* If this is zero (0), the trace will exclude any stream buffer or message
* buffer events.
*
* Default value is 0 since dependent on stream_buffer.c (new in FreeRTOS v10)
*/
#define TRC_CFG_INCLUDE_STREAM_BUFFER_EVENTS 1
/**
* @def TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND
* @brief When using FreeRTOS v10.3.0 or v10.3.1, please make sure that the trace
* point in prvNotifyQueueSetContainer() in queue.c is renamed from
* traceQUEUE_SEND to traceQUEUE_SET_SEND in order to tell them apart from
* other traceQUEUE_SEND trace points. Then set this to TRC_ACKNOWLEDGED.
*/
#define TRC_CFG_ACKNOWLEDGE_QUEUE_SET_SEND 0 /* TRC_ACKNOWLEDGED */
#ifdef __cplusplus
}
#endif
#endif /* TRC_KERNEL_PORT_CONFIG_H */

@ -0,0 +1,69 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Kernel port configuration parameters for snapshot mode.
*/
#ifndef TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H
#define TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def TRC_CFG_NTASK, TRC_CFG_NISR, TRC_CFG_NQUEUE, TRC_CFG_NSEMAPHORE...
* @brief 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 150
#define TRC_CFG_NISR 90
#define TRC_CFG_NQUEUE 90
#define TRC_CFG_NSEMAPHORE 90
#define TRC_CFG_NMUTEX 90
#define TRC_CFG_NTIMER 250
#define TRC_CFG_NEVENTGROUP 90
#define TRC_CFG_NSTREAMBUFFER 50
#define TRC_CFG_NMESSAGEBUFFER 50
/**
* @def TRC_CFG_NAME_LEN_TASK, TRC_CFG_NAME_LEN_QUEUE, ...
* @brief 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
#define TRC_CFG_NAME_LEN_STREAMBUFFER 15
#define TRC_CFG_NAME_LEN_MESSAGEBUFFER 15
#ifdef __cplusplus
}
#endif
#endif /* TRC_KERNEL_PORT_SNAPSHOT_CONFIG_H */

@ -0,0 +1,245 @@
/*
* Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* Configuration parameters for trace recorder library in snapshot mode.
* Read more at http://percepio.com/2016/10/05/rtos-tracing/
*/
#ifndef TRC_SNAPSHOT_CONFIG_H
#define TRC_SNAPSHOT_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def TRC_CFG_SNAPSHOT_MODE
* @brief 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
/**
* @def TRC_CFG_EVENT_BUFFER_SIZE
* @brief 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 50000
/**
* @def TRC_CFG_INCLUDE_FLOAT_SUPPORT
* @brief 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
/**
* @def TRC_CFG_SYMBOL_TABLE_SIZE
* @brief 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 8000
#if ( TRC_CFG_SYMBOL_TABLE_SIZE == 0 )
#error "TRC_CFG_SYMBOL_TABLE_SIZE may not be zero!"
#endif
/******************************************************************************
*** 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.
*****************************************************************************/
/**
* @def TRC_CFG_HEAP_SIZE_BELOW_16M
* @brief 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
/**
* @def TRC_CFG_USE_IMPLICIT_IFE_RULES
* @brief 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 xTraceTaskInstanceFinishedNow and xTraceTaskInstanceFinishedNext.
*
* 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 xTraceTaskInstanceFinishedNow/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 xTraceTaskInstanceFinishedNow or
* xTraceTaskInstanceFinishedNext 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.
*/
#define TRC_CFG_USE_IMPLICIT_IFE_RULES 1
/**
* @def TRC_CFG_USE_16BIT_OBJECT_HANDLES
* @brief 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
/**
* @def TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER
* @brief 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:
* TraceStringHandle_t chn1;
* TraceStringHandle_t fmt1;
* xTraceStringRegister("Channel 1", &chn1);
* xTraceStringRegister("Event!", &fmt1);
* traceUBChannel UBCh1 = xTraceRegisterUBChannel(chn1, fmt1);
*
* TraceStringHandle_t chn2;
* TraceStringHandle_t fmt2;
* xTraceStringRegister("Channel 2", &chn2);
* xTraceStringRegister("X: %d, Y: %d", &fmt2);
* 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 xTracePrintF.
* 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")
* xTracePrintF(chn2, "%Z: %d", value1);
*
* // Finds the existing UB channel
* xTracePrintF(chn2, "%Z: %d", value2);
*/
#define TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER 0
/**
* @def TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE
* @brief 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
/**
* @def TRC_CFG_UB_CHANNELS
* @brief 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
#ifdef __cplusplus
}
#endif
#endif /*TRC_SNAPSHOT_CONFIG_H*/

@ -56,6 +56,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
#include <signal.h> #include <signal.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/select.h> #include <sys/select.h>
#include <time.h> #include <time.h>
@ -84,7 +85,7 @@
#ifdef USER_DEMO #ifdef USER_DEMO
#define mainSELECTED_APPLICATION USER_DEMO #define mainSELECTED_APPLICATION USER_DEMO
#else /* Default Setting */ #else /* Default Setting */
#define mainSELECTED_APPLICATION BLINKY_DEMO #define mainSELECTED_APPLICATION FULL_DEMO
#endif #endif
/* This demo uses heap_3.c (the libc provided malloc() and free()). */ /* This demo uses heap_3.c (the libc provided malloc() and free()). */
@ -146,7 +147,6 @@ StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
#endif #endif
static clockid_t cid = CLOCK_THREAD_CPUTIME_ID; static clockid_t cid = CLOCK_THREAD_CPUTIME_ID;
static uint32_t frequency;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -287,7 +287,7 @@ void traceOnEnter()
} }
/* clear the buffer */ /* clear the buffer */
char buffer[ 0 ]; char buffer[ 1 ];
read( STDIN_FILENO, &buffer, 1 ); read( STDIN_FILENO, &buffer, 1 );
} }
#endif /* if ( TRACE_ON_ENTER == 1 ) */ #endif /* if ( TRACE_ON_ENTER == 1 ) */
@ -359,7 +359,6 @@ static void prvSaveTraceFile( void )
#if ( projCOVERAGE_TEST != 1 ) #if ( projCOVERAGE_TEST != 1 )
{ {
FILE * pxOutputFile; FILE * pxOutputFile;
extern RecorderDataType* RecorderDataPtr;
vTraceStop(); vTraceStop();
@ -446,57 +445,20 @@ void handle_sigint( int signal )
exit( 2 ); exit( 2 );
} }
static uint32_t ulEntryTime = 0;
void vTraceTimerReset( void ) void vTraceTimerReset( void )
{ {
int xRet; ulEntryTime = xTaskGetTickCount();
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 0;
xRet = clock_settime( cid, &ts );
if( xRet != 0 )
{
printf( "Could not reset time: %s\n", strerror( errno ) );
}
} }
uint32_t uiTraceTimerGetFrequency( void ) uint32_t uiTraceTimerGetFrequency( void )
{ {
struct timespec res; return configTICK_RATE_HZ;
int xRet;
res.tv_nsec = 0;
res.tv_sec = 0;
xRet = clock_getres( cid, &res );
if( xRet == 0 )
{
// calculate frequency from timer definition
frequency = (uint64_t) 1000000000 / res.tv_nsec;
}
else
{
printf( "Could not get clock frequency: %s\n", strerror( errno ) );
}
return frequency;
} }
uint32_t uiTraceTimerGetValue( void ) uint32_t uiTraceTimerGetValue( void )
{ {
int xRet; return ( xTaskGetTickCount() - ulEntryTime );
struct timespec tp;
uint32_t result = 0;
xRet = clock_gettime( cid, &tp );
if( xRet == 0 )
{
result = tp.tv_nsec / frequency;
result += (tp.tv_sec * 1000000000) / frequency;
}
else
{
printf( "Could not get time: %s\n", strerror( errno ) );
}
return result;
} }

@ -426,7 +426,7 @@ static void prvCheckTask( void * pvParameters )
} }
#endif /* configSUPPORT_STATIC_ALLOCATION */ #endif /* configSUPPORT_STATIC_ALLOCATION */
printf( "%s - tick count %u \r\n", printf( "%s - tick count %lu \r\n",
pcStatusMessage, pcStatusMessage,
xTaskGetTickCount() ); xTaskGetTickCount() );

@ -1,378 +0,0 @@
/*******************************************************************************
* 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_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 32000
/*******************************************************************************
* 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 150
#define TRC_CFG_NISR 90
#define TRC_CFG_NQUEUE 90
#define TRC_CFG_NSEMAPHORE 90
#define TRC_CFG_NMUTEX 90
#define TRC_CFG_NTIMER 250
#define TRC_CFG_NEVENTGROUP 90
#define TRC_CFG_NSTREAMBUFFER 100
#define TRC_CFG_NMESSAGEBUFFER 100
/******************************************************************************
* 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_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 32000
#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
#define TRC_CFG_NAME_LEN_STREAMBUFFER 15
#define TRC_CFG_NAME_LEN_MESSAGEBUFFER 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*/

@ -631,6 +631,7 @@ ecdhe
ecdsa ecdsa
echobuffer echobuffer
echomultitx echomultitx
echoservertaskbuffer
ecjpake ecjpake
ecmd ecmd
ecp ecp

Loading…
Cancel
Save