[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,4 @@
.sconsign.dblite
build/
src/FreeRTOS
src/FreeRTOS-Plus

View File

@ -0,0 +1,47 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch lldb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/posix_demo",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Launch GDB Ubuntu WSL",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/posix_demo",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Launch GDB MSYS2",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/posix_demo",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "${defaultBuildTask}"
}
]
}

View File

@ -0,0 +1,16 @@
{
"terminal.integrated.profiles.windows": {
"Ubuntu (WSL)": {
"path": "C:\\Windows\\Sysnative\\bash.exe",
},
"MSYS2": {
"path": "C:\\msys64\\usr\\bin\\bash.exe",
"args": ["--login", "-i"],
"env": {
"MSYSTEM": "MSYS",
"CHERE_INVOKING": "1",
}
}
},
"terminal.integrated.defaultProfile.windows": "MSYS2",
}

View File

@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Posix Demo",
"type": "shell",
"command": "make",
"problemMatcher": "$gcc",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

View File

@ -0,0 +1,5 @@
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,11
[InternetShortcut]
IDList=
URL=https://www.freertos.org/FreeRTOS-simulator-for-Linux.html

View File

@ -0,0 +1,180 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* https://www.FreeRTOS.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_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 configMINIMAL_STACK_SIZE ( ( unsigned short ) PTHREAD_STACK_MIN ) /* The stack size being passed is equal to the minimum stack size needed by pthread_create(). */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 1
/* Software timer related configuration options. The maximum possible task
* priority is configMAX_PRIORITIES - 1. The priority of the timer task is
* deliberately set higher to ensure it is correctly capped back to
* configMAX_PRIORITIES - 1. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
/* Run time stats gathering configuration options. */
unsigned long ulGetRunTimeCounterValue( void ); /* Prototype of function that returns run time counter. */
void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that initialises the run time counter. */
#define configGENERATE_RUN_TIME_STATS 1
/* 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
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Enables the test whereby a stack larger than the total heap size is
* requested. */
#define configSTACK_DEPTH_TYPE uint32_t
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_uxTaskGetStackHighWaterMark2 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
extern void vAssertCalled( const char * const pcFileName,
unsigned long ulLine );
/* projCOVERAGE_TEST should be defined on the command line so this file can be
* used with multiple project configurations. If it is
*/
#ifndef projCOVERAGE_TEST
#error projCOVERAGE_TEST should be defined to 1 or 0 on the command line.
#endif
#if ( projCOVERAGE_TEST == 1 )
/* Insert NOPs in empty decision paths to ensure both true and false paths
* 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
/* To test builds that remove the static qualifier for debug builds. */
#define portREMOVE_STATIC_QUALIFIER
#else /* if ( projCOVERAGE_TEST == 1 ) */
/* 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__ )
#define configUSE_MALLOC_FAILED_HOOK 1
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
#include "trcRecorder.h"
#endif /* if ( projCOVERAGE_TEST == 1 ) */
/* networking definitions */
#define configMAC_ISR_SIMULATOR_PRIORITY ( configMAX_PRIORITIES - 1 )
/* Prototype for the function used to print out. In this case it prints to the
* console before the network is connected then a UDP port after the network has
* connected. */
extern void vLoggingPrintf( const char * pcFormatString,
... );
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) vLoggingPrintf X
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 0
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) vLoggingPrintf X
#endif
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,135 @@
CC := gcc
BIN := posix_demo
BUILD_DIR := ./build
BUILD_DIR_ABS := $(abspath $(BUILD_DIR))
FREERTOS_DIR_REL := ../../../FreeRTOS
FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL))
FREERTOS_PLUS_DIR_REL := ../../../FreeRTOS-Plus
FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL))
KERNEL_DIR := ${FREERTOS_DIR}/Source
INCLUDE_DIRS := -I.
INCLUDE_DIRS += -I./Trace_Recorder_Configuration
INCLUDE_DIRS += -I${KERNEL_DIR}/include
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_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
SOURCE_FILES := $(wildcard *.c)
SOURCE_FILES += $(wildcard ${FREERTOS_DIR}/Source/*.c)
# Memory manager (use malloc() / free() )
SOURCE_FILES += ${KERNEL_DIR}/portable/MemMang/heap_3.c
# posix port
SOURCE_FILES += ${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c
SOURCE_FILES += ${KERNEL_DIR}/portable/ThirdParty/GCC/Posix/port.c
# Demo library.
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/AbortDelay.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/BlockQ.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/blocktim.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/countsem.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/death.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/dynamic.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/EventGroupsDemo.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/flop.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/GenQTest.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/integer.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/IntSemTest.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferAMP.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferDemo.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/PollQ.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QPeek.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueOverwrite.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSet.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSetPolling.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/recmutex.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/semtest.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StaticAllocation.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StreamBufferDemo.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StreamBufferInterrupt.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TaskNotify.c
SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TimerDemo.c
CFLAGS := -ggdb3
LDFLAGS := -ggdb3 -pthread
CPPFLAGS := $(INCLUDE_DIRS) -DBUILD_DIR=\"$(BUILD_DIR_ABS)\"
CPPFLAGS += -D_WINDOWS_
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
ifdef SANITIZE_ADDRESS
CFLAGS += -fsanitize=address -fsanitize=alignment
LDFLAGS += -fsanitize=address -fsanitize=alignment
endif
ifdef SANITIZE_LEAK
LDFLAGS += -fsanitize=leak
endif
ifeq ($(USER_DEMO),BLINKY_DEMO)
CPPFLAGS += -DUSER_DEMO=0
endif
ifeq ($(USER_DEMO),FULL_DEMO)
CPPFLAGS += -DUSER_DEMO=1
endif
OBJ_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)
DEP_FILE = $(OBJ_FILES:%.o=%.d)
${BIN} : $(BUILD_DIR)/$(BIN)
${BUILD_DIR}/${BIN} : ${OBJ_FILES}
-mkdir -p ${@D}
$(CC) $^ ${LDFLAGS} -o $@
-include ${DEP_FILE}
${BUILD_DIR}/%.o : %.c Makefile
-mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -c $< -o $@
.PHONY: clean
clean:
-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

View File

@ -0,0 +1,261 @@
# Setup your Development Environment
This demo requires the following packages to build and debug:
* Shell: A posix-like shell environmnet. (e.g., sh, bash, or zsh
* Posix Compatible Environment: (e.g., linux, macos, MSYS2, or Cygwin)
* Compiler: gcc or clang (with gcc frontend)
* Debugger: gdb or lldb
* Build Tool: make
* IDE (optional): Microsoft Visual Studio Code (VS Code)
## Microsoft Windows with MSYS2
### Install the MSYS2 Runtime
*Option A*: Download the gui installer from [msys2.org](https://www.msys2.org/) or
*Option B*: Instally msys2 using the [Microsoft winget](https://github.com/microsoft/winget-cli/releases) package manager:
>```powershell
>winget install msys2
>```
### Install the GCC MinGW Toolchain with pacman
Open the MSYS2 terminal ( *MSYS2 MSYS* in the start menu ).
Using the MSYS2 terminal, install the required packages with the pacman command:
>*MSYS2: bash*
>```bash
>pacman -S --needed --noconfirm base-devel mingw-w64-x86_64-toolchain
>```
Optionally, install the llvm / clang toolchain
>*MSYS2: bash*
>```bash
>pacman -S --needed mingw-w64-x86_64-lldb mingw-w64-x86_64-llvm mingw-w64-x86_64-clang
>```
Finally, determine the windows path for your MinGW bin directory with the following command:
>*MSYS2: bash*
>```bash
>cygpath -w $(dirname $(which gcc))
>```
### Add MinGW to your windows PATH
Add the Mingw-w64 bin folder to the Windows PATH with the following steps:
1. In the Windows search bar, search for and select ```Edit environment variables for your account```.
3. Under the *User Variables for YourUserName* header, Select the **Path** entry and select the **Edit** button.
4. Select the **New** button and add the MinGW bin directory path determined in the previous step (usually ```C:\msys64\mingw64\bin```) to the list.
5. Select the **OK** to save the updated PATH environment variable.
6. Select the **OK** to close the *Environment Variables* editor.
> Note: You will need to reopen any apps for the new PATH settings to take effect.
## Install Windows Subsystem for Linux (WSL)
Windows Subsystem for Linux provides a more or less complete linux distribution tightly integrated into Microsoft Windows.
Open an elevated Windows Powershell session:
1. Click the start button
2. Search for ```PowerShell```
3. Select ```Run as Administator```
In the elevated PowerShell console run the following command to install [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/install):
>*PowerShell*
> ```powershell
>wsl --install
>```
Open a terminal in your WSL linux environment and follow the instructions below for setting up the toolchain for your chosen Windows Subsystem for Linux Distibution.
## Debian / Ubuntu Linux and derivatives
From a terminal, install the required pakages wth apt-get:
>```
>sudo apt-get install -y build-essential gcc gdb make
>```
Optionally, install the LLVM toolchain with the following command:
>```
>sudo apt-get install -y llvm clang lldb
>```
## Redhat Linux and derivatives
From a terminal, install the required pakages with dnf:
>```
>sudo dnf install gcc gdb make
>```
Optionally, install the LLVM toolchain with the following command:
>```
>sudo dnf install -y llvm clang lldb
>```
## MacOS
Install the Apple commandline developer tools including the AppleClang toolchain with lldb using the following command in Terminal:
>```
>xcode-select --install
>```
Due to code signing requirments in MacOS, running gdb is challenging. For this reason, we suggest using the included clang compiler and lldb debugger.
Note: Apple's command line developer tools installer adds a clang wrapper in ```/usr/bin/gcc``` for compatibility.
## Install and Configure Visual Studio Code
Download the [Visual Studio Code package for your platform](https://code.visualstudio.com/Download) from the Visual Studio Code website and install it in the normal way for your platform.
> Note: For the Windows Subsystem for Linux platform, ensure that you install the native windows VS Code package.
> For more information, you may refernce the [Visual Studio Code WSL documentation](https://code.visualstudio.com/docs/remote/wsl).
### Install VS Code Extensions
Next, Install the following Visual Studio Code extensions by selecting the "install" button on the extension web page linked below or by searching for the relevant extension in the Visual Studio Code **Extensions** tab in the left-hand sidebar.
* [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) Extension, used to enable code syntax hilighting and debugging
* [Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) Extension Pack, paritcularly useful for WSL
### Add the VS Code launcher to your PATH
Launch Visual Studio Code and open the **Command Palette* with ```CTRL+SHIFT+P``` (windows, linux) or ```CMD+SHIFT+P``` (MacOS).
Search for "Shell Command: Install code command in Path" and select the command with the ```ENTER``` or ```RETURN``` key.
This allows you to launch VS Code from your system's commandline with the ```code``` commnd.
## Validate your installation:
Check that the necessary binaries are available in your terminal PATH by running the following commands:
>*bash*
>```bash
>gcc --version
>make --version
>lldb --version
>gdb --version
>```
# Build on the command line
Navigate to the Posix_GCC directory in your FreeRTOS download and build
>*bash*
>```bash
> cd /path/to/FreeRTOS/Demo/Posix_GCC
>```
## Building with GCC
>*bash*
>```bash
> make clean
> make CC=gcc
>```
## Building with Clang
>*bash*
>```bash
> make clean
> make CC=clang
>```
# Debugging with Visual Studio Code
## Open the Project in VS Code on Linux, MacOS, or Windows with MSYS2
Ooen the project directory in Visual Studio Code using one of the
>*bash*
>```
> code /path/to/FreeRTOS/Demo/Posix_GCC
>```
Alternatively, open VSCode from your system launcher, select **File**->**Open Folder** and navigate to the ```FreeRTOS/Demo/Posix_GCC``` directory.
## Open the Project in VS Code with Windows Subsystem for Linux
From your WSL Terminal, run the following command:
>*WSL Terminal*
>```bash
> code /path/in/wsl/to/FreeRTOS/Demo/Posix_GCC
>```
To open the project without using the command line:
1. Open VSCode from the start menu
2. Press the ```F1``` key or ```CTRL+SHIFT+P``` to open the VS Code command palette
3. Select **WSL: New WSL Window** for the default distro or **WSL: New WSL Window using Distro** for a specific distro.
4. Finally, select the **File**->**Open Folder** menu item and navigate to the ```FreeRTOS/Demo/Posix_GCC``` directory.
## Build the demo and run it in the debugger
1. On the VSCode left side panel, select **Run and Debug**
2. Select the relevant launch configuration for your preferred debugger:
- Linux: select either **Launch lldb** or **Launch gdb** depending on your preferred debugger
- Windows with MSYS2: select **Launch GDB MSYS2**
- Window Subsystem for Linux: select **Launch GDB Ubuntu WSL**
Finally, select the green triangle button to begin debugging.
## On Windows using Ubuntu WSL
On the VSCode left side panel, select the **Run and Debug** button, then select and press the green triangle button. This will build, run, and attach a debugger to the demo program.
For additional information, you may refer to the [Visual Studio Code mingw documentation](https://code.visualstudio.com/docs/cpp/config-mingw) page.
## On Windows using MSYS2
2. Open VSCode to the folder ```FreeRTOS/Demo/Posix_GCC```.
3. In ```.vscode/settings.json```, ensure the ```path``` variable under ```MSYS2``` is set to the ```bash.exe``` under your msys64 installation directory. The path should resemble ```${path to msys2 installation}\\msys64\\usr\\bin\\bash.exe```.
4. On the VSCode left side panel, select the “Run and Debug” button. Then select the “Launch GDB MSYS2” and press the play button to begin debugging.
1. If the demo was previously built by Ubuntu WSL, make sure to ```make clean``` before building on MSYS2.
# Profiling your application
## Introduction [(from the official gprof doc)](https://sourceware.org/binutils/docs/gprof/Introduction.html#Introduction)
Profiling allows you to learn where your program spent its time and which
functions called which other functions while it was executing. This information
can show you which pieces of your program are slower than you expected, and
might be candidates for rewriting to make your program execute faster. It can
also tell you which functions are being called more or less often than you
expected. This may help you spot bugs that had otherwise been unnoticed.
## Requirements
### gprof
Version as tested: GNU gprof (GNU Binutils) 2.36
### make
Version as tested: GNU Make 3.82
### gcc
Version as tested: gcc (GCC) 11.0.0
## Generating Profiles
```
$ make PROFILE=1
```
Run your application
```
$ ./build/posix_demo
```
Since FreeRTOS and its application never come to an end and typically run
forever. The user has to kill the application with **Ctrl_C** when they feel
satisfied that the application achieved its intented task. Killing the
application will force the profiling file *gmon.out* to be generated
automatically.
In order to make sense of this file, the user has to convert the file with:
```
$ make profile
```
After running the previous command, two (2) profiling files
*prof_call_graph.txt* and *prof_flat.txt* will be generated and placed in
the build directory.
* *prof_call_graph.txt*: The call graph shows which functions called which
others, and how much time each function used when its subroutine calls are
included.
* *prof_flat.txt*: The flat profile shows how much time was spent
executing directly in each function.
In order to understand the outputs generated, the best way is to read the
official documentation of gprof
[here](https://sourceware.org/binutils/docs/gprof/Output.html#Output)
# Run your application with Sanitizers
## Introduction
* AddressSanitizer, a fast memory error detector. Memory
access instructions are instrumented to detect out-of-bounds and use-after-free
bugs
* LeakSanitizer, a memory leak detector. This option only matters for linking of
executables and the executable is linked against a library that overrides malloc
and other allocator functions
## Building and Running the Application
```
$ make SANITIZE_ADDRESS=1
or
$ make SANITIZE_LEAK=1
```
Then run your program normally.
```
$ ./build/posix_demo
```
If an error is detected by the sanitizer, a report showing the error will be printed to stdout.

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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*/

View File

@ -0,0 +1,644 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* Contains sundry tests to exercise code that is not touched by the standard
* demo tasks (which are predominantly test tasks). Some tests are included
* here because they can only be executed when configASSERT() is not defined.
*/
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "event_groups.h"
#include "semphr.h"
#include "stream_buffer.h"
#include "message_buffer.h"
/*-----------------------------------------------------------*/
/*
* Try creating static objects with one of the mandatory parameters set to NULL.
* This can't be done in the standard demos as asserts() will get hit.
*/
static BaseType_t prvStaticAllocationsWithNullBuffers( void );
/*
* Code coverage analysis is performed with tracing turned off, so this
* function executes the trace specific utility functions that would not
* otherwise be executed..
*/
static BaseType_t prvTraceUtils( void );
/*
* The queue peek standard demo does not cover the case where an attempt to peek
* times out, so test that case.
*/
static BaseType_t prvPeekTimeout( void );
/*
* Calls various interrupt safe functions designed to query the state of a
* queue.
*/
static BaseType_t prvQueueQueryFromISR( void );
/*
* Hits a few paths in tasks state and status query functions not otherwise hit
* by standard demo and test files.
*/
static BaseType_t prvTaskQueryFunctions( void );
/*
* None of the standard demo tasks use the task tags - exercise them here.
*/
static BaseType_t prvTaskTags( void );
/*
* Exercises a few of the query functions that are not otherwise exercised in
* the standard demo and test functions.
*/
static BaseType_t prvTimerQuery( void );
/*-----------------------------------------------------------*/
static BaseType_t prvStaticAllocationsWithNullBuffers( void )
{
uintptr_t ulReturned = 0;
BaseType_t xReturn = pdPASS;
UBaseType_t uxDummy = 10;
/* Don't expect to create any of the objects as a NULL parameter is always
* passed in place of a required buffer. Hence if all passes then none of the
|= will be against 0, and ulReturned will still be zero at the end of this
* function. */
ulReturned |= ( uintptr_t ) xEventGroupCreateStatic( NULL );
/* Try creating a task twice, once with puxStackBuffer NULL, and once with
* pxTaskBuffer NULL. */
ulReturned |= ( uintptr_t ) xTaskCreateStatic( NULL, /* Task to run, not needed as the task is not created. */
"Dummy", /* Task name. */
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY,
NULL,
( StaticTask_t * ) &xReturn ); /* Dummy value just to pass a non NULL value in - won't get used. */
ulReturned |= ( uintptr_t ) xTaskCreateStatic( NULL, /* Task to run, not needed as the task is not created. */
"Dummy", /* Task name. */
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY,
( StackType_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );
ulReturned |= ( uintptr_t ) xQueueCreateStatic( uxDummy,
uxDummy,
( uint8_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );
/* Try creating a stream buffer twice, once with pucStreamBufferStorageArea
* set to NULL, and once with pxStaticStreamBuffer set to NULL. */
ulReturned |= ( uintptr_t ) xStreamBufferCreateStatic( uxDummy,
uxDummy,
NULL,
( StaticStreamBuffer_t * ) &xReturn ); /* Dummy value just to pass a non NULL value in - won't get used. */
ulReturned |= ( uintptr_t ) xStreamBufferCreateStatic( uxDummy,
uxDummy,
( uint8_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );
if( ulReturned != 0 )
{
/* Something returned a non-NULL value. */
xReturn = pdFAIL;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvTraceUtils( void )
{
EventGroupHandle_t xEventGroup;
QueueHandle_t xQueue;
BaseType_t xReturn = pdPASS;
const UBaseType_t xNumber = ( UBaseType_t ) 100, xQueueLength = ( UBaseType_t ) 1;
UBaseType_t uxValue;
TaskHandle_t xTaskHandle;
StreamBufferHandle_t xStreamBuffer;
MessageBufferHandle_t xMessageBuffer;
/* Exercise the event group trace utilities. */
xEventGroup = xEventGroupCreate();
if( xEventGroup != NULL )
{
vEventGroupSetNumber( xEventGroup, xNumber );
if( uxEventGroupGetNumber( NULL ) != 0 )
{
xReturn = pdFAIL;
}
if( uxEventGroupGetNumber( xEventGroup ) != xNumber )
{
xReturn = pdFAIL;
}
vEventGroupDelete( xEventGroup );
}
else
{
xReturn = pdFAIL;
}
/* Exercise the queue trace utilities. */
xQueue = xQueueCreate( xQueueLength, ( UBaseType_t ) sizeof( uxValue ) );
if( xQueue != NULL )
{
vQueueSetQueueNumber( xQueue, xNumber );
if( uxQueueGetQueueNumber( xQueue ) != xNumber )
{
xReturn = pdFAIL;
}
if( ucQueueGetQueueType( xQueue ) != queueQUEUE_TYPE_BASE )
{
xReturn = pdFAIL;
}
vQueueDelete( xQueue );
}
else
{
xReturn = pdFAIL;
}
/* Exercise the task trace utilities. Value of 100 is arbitrary, just want
* to check the value that is set is also read back. */
uxValue = 100;
xTaskHandle = xTaskGetCurrentTaskHandle();
vTaskSetTaskNumber( xTaskHandle, uxValue );
if( uxTaskGetTaskNumber( xTaskHandle ) != uxValue )
{
xReturn = pdFAIL;
}
if( uxTaskGetTaskNumber( NULL ) != 0 )
{
xReturn = pdFAIL;
}
/* Timer trace util functions are exercised in prvTimerQuery(). */
/* Exercise the stream buffer utilities. Try creating with a trigger level
* of 0, it should then get capped to 1. */
xStreamBuffer = xStreamBufferCreate( sizeof( uint32_t ), 0 );
if( xStreamBuffer != NULL )
{
vStreamBufferSetStreamBufferNumber( xStreamBuffer, uxValue );
if( uxStreamBufferGetStreamBufferNumber( xStreamBuffer ) != uxValue )
{
xReturn = pdFALSE;
}
if( ucStreamBufferGetStreamBufferType( xStreamBuffer ) != 0 )
{
/* "Is Message Buffer" flag should have been 0. */
xReturn = pdFALSE;
}
vStreamBufferDelete( xStreamBuffer );
}
else
{
xReturn = pdFALSE;
}
xMessageBuffer = xMessageBufferCreate( sizeof( uint32_t ) );
if( xMessageBuffer != NULL )
{
if( ucStreamBufferGetStreamBufferType( xMessageBuffer ) == 0 )
{
/* "Is Message Buffer" flag should have been 1. */
xReturn = pdFALSE;
}
vMessageBufferDelete( xMessageBuffer );
}
else
{
xReturn = pdFALSE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvPeekTimeout( void )
{
QueueHandle_t xHandle;
const UBaseType_t xQueueLength = 1;
BaseType_t xReturn = pdPASS;
TickType_t xBlockTime = ( TickType_t ) 2;
UBaseType_t uxReceived;
/* Create the queue just to try peeking it while it is empty. */
xHandle = xQueueCreate( xQueueLength, ( UBaseType_t ) sizeof( xQueueLength ) );
if( xHandle != NULL )
{
if( uxQueueMessagesWaiting( xHandle ) != 0 )
{
xReturn = pdFAIL;
}
/* Ensure peeking from the queue times out as the queue is empty. */
if( xQueuePeek( xHandle, &uxReceived, xBlockTime ) != pdFALSE )
{
xReturn = pdFAIL;
}
vQueueDelete( xHandle );
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvQueueQueryFromISR( void )
{
BaseType_t xReturn = pdPASS, xValue = 1;
const UBaseType_t xISRQueueLength = ( UBaseType_t ) 1;
const char * pcISRQueueName = "ISRQueue";
QueueHandle_t xISRQueue = NULL;
xISRQueue = xQueueCreate( xISRQueueLength, ( UBaseType_t ) sizeof( BaseType_t ) );
if( xISRQueue != NULL )
{
vQueueAddToRegistry( xISRQueue, pcISRQueueName );
if( strcmp( pcQueueGetName( xISRQueue ), pcISRQueueName ) )
{
xReturn = pdFAIL;
}
/* Expect the queue to be empty here. */
if( uxQueueMessagesWaitingFromISR( xISRQueue ) != 0 )
{
xReturn = pdFAIL;
}
if( xQueueIsQueueEmptyFromISR( xISRQueue ) != pdTRUE )
{
xReturn = pdFAIL;
}
if( xQueueIsQueueFullFromISR( xISRQueue ) != pdFALSE )
{
xReturn = pdFAIL;
}
/* Now fill the queue - it only has one space. */
if( xQueueSendFromISR( xISRQueue, &xValue, NULL ) != pdPASS )
{
xReturn = pdFAIL;
}
/* Check it now reports as full. */
if( uxQueueMessagesWaitingFromISR( xISRQueue ) != 1 )
{
xReturn = pdFAIL;
}
if( xQueueIsQueueEmptyFromISR( xISRQueue ) != pdFALSE )
{
xReturn = pdFAIL;
}
if( xQueueIsQueueFullFromISR( xISRQueue ) != pdTRUE )
{
xReturn = pdFAIL;
}
vQueueDelete( xISRQueue );
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvTaskQueryFunctions( void )
{
static TaskStatus_t xStatus, * pxStatusArray;
TaskHandle_t xTimerTask, xIdleTask;
BaseType_t xReturn = pdPASS;
UBaseType_t uxNumberOfTasks, uxReturned, ux;
uint32_t ulTotalRunTime1, ulTotalRunTime2;
const uint32_t ulRunTimeTollerance = ( uint32_t ) 0xfff;
/* Obtain task status with the stack high water mark and without the
* state. */
vTaskGetInfo( NULL, &xStatus, pdTRUE, eRunning );
if( uxTaskGetStackHighWaterMark( NULL ) != xStatus.usStackHighWaterMark )
{
xReturn = pdFAIL;
}
if( uxTaskGetStackHighWaterMark2( NULL ) != ( configSTACK_DEPTH_TYPE ) xStatus.usStackHighWaterMark )
{
xReturn = pdFAIL;
}
/* Now obtain a task status without the high water mark but with the state,
* which in the case of the idle task should be Read. */
xTimerTask = xTimerGetTimerDaemonTaskHandle();
vTaskSuspend( xTimerTask ); /* Should never suspend Timer task normally!. */
vTaskGetInfo( xTimerTask, &xStatus, pdFALSE, eInvalid );
if( xStatus.eCurrentState != eSuspended )
{
xReturn = pdFAIL;
}
if( xStatus.uxBasePriority != uxTaskPriorityGetFromISR( xTimerTask ) )
{
xReturn = pdFAIL;
}
if( xStatus.uxBasePriority != ( configMAX_PRIORITIES - 1 ) )
{
xReturn = pdFAIL;
}
xTaskResumeFromISR( xTimerTask );
vTaskGetInfo( xTimerTask, &xStatus, pdTRUE, eInvalid );
if( ( xStatus.eCurrentState != eReady ) && ( xStatus.eCurrentState != eBlocked ) )
{
xReturn = pdFAIL;
}
if( uxTaskGetStackHighWaterMark( xTimerTask ) != xStatus.usStackHighWaterMark )
{
xReturn = pdFAIL;
}
if( uxTaskGetStackHighWaterMark2( xTimerTask ) != ( configSTACK_DEPTH_TYPE ) xStatus.usStackHighWaterMark )
{
xReturn = pdFAIL;
}
/* Attempting to abort a delay in the idle task should be guaranteed to
* fail as the idle task should never block. */
xIdleTask = xTaskGetIdleTaskHandle();
if( xTaskAbortDelay( xIdleTask ) != pdFAIL )
{
xReturn = pdFAIL;
}
/* Create an array of task status objects large enough to hold information
* on the number of tasks at this time - note this may change at any time if
* higher priority tasks are executing and creating tasks. */
uxNumberOfTasks = uxTaskGetNumberOfTasks();
pxStatusArray = ( TaskStatus_t * ) pvPortMalloc( uxNumberOfTasks * sizeof( TaskStatus_t ) );
if( pxStatusArray != NULL )
{
/* Pass part of the array into uxTaskGetSystemState() to ensure it doesn't
* try using more space than there is available. */
uxReturned = uxTaskGetSystemState( pxStatusArray, uxNumberOfTasks / ( UBaseType_t ) 2, NULL );
if( uxReturned != ( UBaseType_t ) 0 )
{
xReturn = pdFAIL;
}
/* Now do the same but passing in the complete array size, this is done
* twice to check for a difference in the total run time. */
uxTaskGetSystemState( pxStatusArray, uxNumberOfTasks, &ulTotalRunTime1 );
memset( ( void * ) pxStatusArray, 0xaa, uxNumberOfTasks * sizeof( TaskStatus_t ) );
uxReturned = uxTaskGetSystemState( pxStatusArray, uxNumberOfTasks, &ulTotalRunTime2 );
if( ( ulTotalRunTime2 - ulTotalRunTime1 ) > ulRunTimeTollerance )
{
xReturn = pdFAIL;
}
/* Basic santity check of array contents. */
for( ux = 0; ux < uxReturned; ux++ )
{
if( pxStatusArray[ ux ].eCurrentState >= ( UBaseType_t ) eInvalid )
{
xReturn = pdFAIL;
}
if( pxStatusArray[ ux ].uxCurrentPriority >= ( UBaseType_t ) configMAX_PRIORITIES )
{
xReturn = pdFAIL;
}
}
vPortFree( pxStatusArray );
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvDummyTagFunction( void * pvParameter )
{
return ( BaseType_t ) pvParameter;
}
/*-----------------------------------------------------------*/
static BaseType_t prvTaskTags( void )
{
BaseType_t xReturn = pdPASS, xParameter = ( BaseType_t ) 0xDEADBEEF;
TaskHandle_t xTask;
/* First try with the handle of a different task. Use the timer task for
* convenience. */
xTask = xTimerGetTimerDaemonTaskHandle();
vTaskSetApplicationTaskTag( xTask, prvDummyTagFunction );
if( xTaskGetApplicationTaskTag( xTask ) != prvDummyTagFunction )
{
xReturn = pdFAIL;
}
else
{
if( xTaskCallApplicationTaskHook( xTask, ( void * ) xParameter ) != xParameter )
{
xReturn = pdFAIL;
}
if( xTaskCallApplicationTaskHook( xTask, ( void * ) NULL ) != pdFAIL )
{
xReturn = pdFAIL;
}
}
/* Try FromISR version too. */
if( xTaskGetApplicationTaskTagFromISR( xTask ) != prvDummyTagFunction )
{
xReturn = pdFAIL;
}
/* Now try with a NULL handle, so using this task. */
vTaskSetApplicationTaskTag( NULL, NULL );
if( xTaskGetApplicationTaskTag( NULL ) != NULL )
{
xReturn = pdFAIL;
}
if( xTaskGetApplicationTaskTagFromISR( NULL ) != NULL )
{
xReturn = pdFAIL;
}
vTaskSetApplicationTaskTag( NULL, prvDummyTagFunction );
if( xTaskGetApplicationTaskTag( NULL ) != prvDummyTagFunction )
{
xReturn = pdFAIL;
}
else
{
if( xTaskCallApplicationTaskHook( NULL, ( void * ) xParameter ) != xParameter )
{
xReturn = pdFAIL;
}
if( xTaskCallApplicationTaskHook( NULL, ( void * ) NULL ) != pdFAIL )
{
xReturn = pdFAIL;
}
}
/* Try FromISR version too. */
if( xTaskGetApplicationTaskTagFromISR( NULL ) != prvDummyTagFunction )
{
xReturn = pdFAIL;
}
vTaskSetApplicationTaskTag( NULL, NULL );
if( xTaskGetApplicationTaskTag( NULL ) != NULL )
{
xReturn = pdFAIL;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvTimerQuery( void )
{
TimerHandle_t xTimer;
BaseType_t xReturn = pdPASS;
const char * pcTimerName = "TestTimer";
const TickType_t xTimerPeriod = ( TickType_t ) 100;
const UBaseType_t uxTimerNumber = ( UBaseType_t ) 55;
xTimer = xTimerCreate( pcTimerName,
xTimerPeriod,
pdFALSE,
( void * ) xTimerPeriod,
NULL ); /* Not actually going to start timer so NULL callback is ok. */
if( xTimer != NULL )
{
if( xTimerGetPeriod( xTimer ) != xTimerPeriod )
{
xReturn = pdFAIL;
}
if( strcmp( pcTimerGetName( xTimer ), pcTimerName ) != 0 )
{
xReturn = pdFAIL;
}
vTimerSetTimerNumber( xTimer, uxTimerNumber );
if( uxTimerGetTimerNumber( xTimer ) != uxTimerNumber )
{
xReturn = pdFAIL;
}
xTimerDelete( xTimer, portMAX_DELAY );
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
/*-----------------------------------------------------------*/
BaseType_t xRunCodeCoverageTestAdditions( void )
{
BaseType_t xReturn = pdPASS;
xReturn &= prvStaticAllocationsWithNullBuffers();
xReturn &= prvTraceUtils();
xReturn &= prvPeekTimeout();
xReturn &= prvQueueQueryFromISR();
xReturn &= prvTaskQueryFunctions();
xReturn &= prvTaskTags();
xReturn &= prvTimerQuery();
return xReturn;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,59 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*-----------------------------------------------------------
* Example console I/O wrappers.
*----------------------------------------------------------*/
#include <stdarg.h>
#include <stdio.h>
#include <FreeRTOS.h>
#include <semphr.h>
SemaphoreHandle_t xStdioMutex;
StaticSemaphore_t xStdioMutexBuffer;
void console_init( void )
{
xStdioMutex = xSemaphoreCreateMutexStatic( &xStdioMutexBuffer );
}
void console_print( const char * fmt,
... )
{
va_list vargs;
va_start( vargs, fmt );
xSemaphoreTake( xStdioMutex, portMAX_DELAY );
vprintf( fmt, vargs );
xSemaphoreGive( xStdioMutex );
va_end( vargs );
}

View File

@ -0,0 +1,46 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef CONSOLE_H
#define CONSOLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------
* Example console I/O wrappers.
*----------------------------------------------------------*/
void console_init( void );
void console_print( const char * fmt,
... );
#ifdef __cplusplus
}
#endif
#endif /* CONSOLE_H */

View File

@ -0,0 +1,464 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/******************************************************************************
* This project provides two demo applications. A simple blinky style project,
* a more comprehensive test and demo application.
* The mainSELECTED_APPLICATION setting is used to select between
* the three
*
* If mainSELECTED_APPLICATION = BLINKY_DEMO the simple blinky demo will be built.
* The simply blinky demo is implemented and described in main_blinky.c.
*
* If mainSELECTED_APPLICATION = FULL_DEMO the more comprehensive test and demo
* application built. This is implemented and described in main_full.c.
*
* This file implements the code that is not demo specific, including the
* hardware setup and FreeRTOS hook functions.
*
*******************************************************************************
* NOTE: Linux will not be running the FreeRTOS demo threads continuously, so
* do not expect to get real time behaviour from the FreeRTOS Linux port, or
* this demo application. Also, the timing information in the FreeRTOS+Trace
* logs have no meaningful units. See the documentation page for the Linux
* port for further information:
* https://freertos.org/FreeRTOS-simulator-for-Linux.html
*
*******************************************************************************
*/
/* Standard includes. */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <sys/select.h>
#include <time.h>
/* FreeRTOS kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Local includes. */
#include "console.h"
#if ( projCOVERAGE_TEST != 1 )
#include <trcRecorder.h>
#endif
#define BLINKY_DEMO 0
#define FULL_DEMO 1
#ifdef BUILD_DIR
#define BUILD BUILD_DIR
#else
#define BUILD "./"
#endif
/* Demo type is passed as an argument */
#ifdef USER_DEMO
#define mainSELECTED_APPLICATION USER_DEMO
#else /* Default Setting */
#define mainSELECTED_APPLICATION FULL_DEMO
#endif
/* This demo uses heap_3.c (the libc provided malloc() and free()). */
/*-----------------------------------------------------------*/
extern void main_blinky( void );
extern void main_full( void );
static void traceOnEnter( void );
/*
* Only the comprehensive demo uses application hook (callback) functions. See
* https://www.FreeRTOS.org/a00016.html for more information.
*/
void vFullDemoTickHookFunction( void );
void vFullDemoIdleFunction( void );
/*
* Prototypes for the standard FreeRTOS application hook (callback) functions
* implemented within this file. See http://www.freertos.org/a00016.html .
*/
void vApplicationMallocFailedHook( void );
void vApplicationIdleHook( void );
void vApplicationStackOverflowHook( TaskHandle_t pxTask,
char * pcTaskName );
void vApplicationTickHook( void );
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize );
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize );
/*
* Writes trace data to a disk file when the trace recording is stopped.
* This function will simply overwrite any trace files that already exist.
*/
static void prvSaveTraceFile( void );
/*
* Signal handler for Ctrl_C to cause the program to exit, and generate the
* profiling info.
*/
static void handle_sigint( int signal );
/*-----------------------------------------------------------*/
/* 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
* 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
* in a different file. */
StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
/* Notes if the trace is running or not. */
#if ( projCOVERAGE_TEST == 1 )
static BaseType_t xTraceRunning = pdFALSE;
#else
static BaseType_t xTraceRunning = pdTRUE;
#endif
static clockid_t cid = CLOCK_THREAD_CPUTIME_ID;
/*-----------------------------------------------------------*/
int main( void )
{
/* SIGINT is not blocked by the posix port */
signal( SIGINT, handle_sigint );
/* 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. */
vTraceEnable( 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" );
#if ( TRACE_ON_ENTER == 1 )
printf( "\r\nThe trace will be dumped to disk if Enter is hit.\r\n" );
#endif
}
#endif /* if ( projCOVERAGE_TEST != 1 ) */
console_init();
#if ( mainSELECTED_APPLICATION == BLINKY_DEMO )
{
console_print( "Starting echo blinky demo\n" );
main_blinky();
}
#elif ( mainSELECTED_APPLICATION == FULL_DEMO )
{
console_print( "Starting full demo\n" );
main_full();
}
#else
{
#error "The selected demo is not valid"
}
#endif /* if ( mainSELECTED_APPLICATION ) */
return 0;
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook( void )
{
/* vApplicationMallocFailedHook() will only be called if
* 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.
* 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
* 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
* configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
* 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
* fragmented). See http://www.freertos.org/a00111.html for more
* information. */
vAssertCalled( __FILE__, __LINE__ );
}
/*-----------------------------------------------------------*/
void vApplicationIdleHook( void )
{
/* 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
* 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
* specified, or call vTaskDelay()). If application tasks make use of the
* vTaskDelete() API function to delete themselves then it is also important
* that vApplicationIdleHook() is permitted to return to its calling function,
* 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. */
usleep( 15000 );
traceOnEnter();
#if ( mainSELECTED_APPLICATION == FULL_DEMO )
{
/* Call the idle task processing used by the full demo. The simple
* blinky demo does not use the idle task hook. */
vFullDemoIdleFunction();
}
#endif
}
/*-----------------------------------------------------------*/
void vApplicationStackOverflowHook( TaskHandle_t pxTask,
char * pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;
/* Run time stack overflow checking is performed if
* configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
* function is called if a stack overflow is detected. This function is
* provided as an example only as stack overflow checking does not function
* when running the FreeRTOS POSIX port. */
vAssertCalled( __FILE__, __LINE__ );
}
/*-----------------------------------------------------------*/
void vApplicationTickHook( void )
{
/* This function will be called by each tick interrupt if
* 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
* code must not attempt to block, and only the interrupt safe FreeRTOS API
* functions can be used (those that end in FromISR()). */
#if ( mainSELECTED_APPLICATION == FULL_DEMO )
{
vFullDemoTickHookFunction();
}
#endif /* mainSELECTED_APPLICATION */
}
void traceOnEnter()
{
#if ( TRACE_ON_ENTER == 1 )
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 )
{
prvSaveTraceFile();
}
/* clear the buffer */
char buffer[ 1 ];
read( STDIN_FILENO, &buffer, 1 );
}
#endif /* if ( TRACE_ON_ENTER == 1 ) */
}
void vLoggingPrintf( const char * pcFormat,
... )
{
va_list arg;
va_start( arg, pcFormat );
vprintf( pcFormat, arg );
va_end( arg );
}
/*-----------------------------------------------------------*/
void vApplicationDaemonTaskStartupHook( void )
{
/* This function will be called once only, when the daemon task starts to
* execute (sometimes called the timer task). This is useful if the
* application includes initialisation code that would benefit from executing
* after the scheduler has been started. */
}
/*-----------------------------------------------------------*/
void vAssertCalled( const char * const pcFileName,
unsigned long ulLine )
{
static BaseType_t xPrinted = pdFALSE;
volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
/* Called if an assertion passed to configASSERT() fails. See
* https://www.FreeRTOS.org/a00110.html#configASSERT for more information. */
/* Parameters are not used. */
( void ) ulLine;
( void ) pcFileName;
taskENTER_CRITICAL();
{
/* 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 == 0 )
{
__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;
vTraceStop();
pxOutputFile = fopen( "Trace.dump", "wb" );
if( pxOutputFile != NULL )
{
fwrite( RecorderDataPtr, sizeof( RecorderDataType ), 1, pxOutputFile );
fclose( pxOutputFile );
printf( "\r\nTrace output saved to Trace.dump\r\n" );
}
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
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
* used by the Idle task. */
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize )
{
/* 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
* the stack and so not exists after this function exits. */
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
* state will be stored. */
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
/* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
* Note that, as the array is necessarily of type StackType_t,
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
/*-----------------------------------------------------------*/
/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
* application must provide an implementation of vApplicationGetTimerTaskMemory()
* to provide the memory that is used by the Timer service task. */
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize )
{
/* 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
* the stack and so not exists after this function exits. */
static StaticTask_t xTimerTaskTCB;
/* Pass out a pointer to the StaticTask_t structure in which the Timer
* task's state will be stored. */
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
/* Pass out the array that will be used as the Timer task's stack. */
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
* Note that, as the array is necessarily of type StackType_t,
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
void handle_sigint( int signal )
{
int xReturn;
xReturn = chdir( BUILD ); /* changing dir to place gmon.out inside build */
if( xReturn == -1 )
{
printf( "chdir into %s error is %d\n", BUILD, errno );
}
exit( 2 );
}
static uint32_t ulEntryTime = 0;
void vTraceTimerReset( void )
{
ulEntryTime = xTaskGetTickCount();
}
uint32_t uiTraceTimerGetFrequency( void )
{
return configTICK_RATE_HZ;
}
uint32_t uiTraceTimerGetValue( void )
{
return ( xTaskGetTickCount() - ulEntryTime );
}

View File

@ -0,0 +1,266 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/******************************************************************************
* NOTE 1: The FreeRTOS demo threads will not be running continuously, so
* do not expect to get real time behaviour from the FreeRTOS Linux port, or
* this demo application. Also, the timing information in the FreeRTOS+Trace
* logs have no meaningful units. See the documentation page for the Linux
* port for further information:
* https://freertos.org/FreeRTOS-simulator-for-Linux.html
*
* NOTE 2: This project provides two demo applications. A simple blinky style
* project, and a more comprehensive test and demo application. The
* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
* between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
* in main.c. This file implements the simply blinky version. Console output
* is used in place of the normal LED toggling.
*
* NOTE 3: This file only contains the source code that is specific to the
* basic demo. Generic functions, such FreeRTOS hook functions, are defined
* in main.c.
******************************************************************************
*
* main_blinky() creates one queue, one software timer, and two tasks. It then
* starts the scheduler.
*
* The Queue Send Task:
* The queue send task is implemented by the prvQueueSendTask() function in
* this file. It uses vTaskDelayUntil() to create a periodic task that sends
* the value 100 to the queue every 200 milliseconds (please read the notes
* above regarding the accuracy of timing under Linux).
*
* The Queue Send Software Timer:
* The timer is an auto-reload timer with a period of two seconds. The timer's
* callback function writes the value 200 to the queue. The callback function
* is implemented by prvQueueSendTimerCallback() within this file.
*
* The Queue Receive Task:
* The queue receive task is implemented by the prvQueueReceiveTask() function
* in this file. prvQueueReceiveTask() waits for data to arrive on the queue.
* When data is received, the task checks the value of the data, then outputs a
* message to indicate if the data came from the queue send task or the queue
* send software timer.
*
* Expected Behaviour:
* - The queue send task writes to the queue every 200ms, so every 200ms the
* queue receive task will output a message indicating that data was received
* on the queue from the queue send task.
* - The queue send software timer has a period of two seconds, and is reset
* each time a key is pressed. So if two seconds expire without a key being
* pressed then the queue receive task will output a message indicating that
* data was received on the queue from the queue send software timer.
*
* NOTE: Console input and output relies on Linux system calls, which can
* interfere with the execution of the FreeRTOS Linux port. This demo only
* uses Linux system call occasionally. Heavier use of Linux system calls
* may crash the port.
*/
#include <stdio.h>
#include <pthread.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"
/* Local includes. */
#include "console.h"
/* Priorities at which the tasks are created. */
#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* The rate at which data is sent to the queue. The times are converted from
* milliseconds to ticks using the pdMS_TO_TICKS() macro. */
#define mainTASK_SEND_FREQUENCY_MS pdMS_TO_TICKS( 200UL )
#define mainTIMER_SEND_FREQUENCY_MS pdMS_TO_TICKS( 2000UL )
/* The number of items the queue can hold at once. */
#define mainQUEUE_LENGTH ( 2 )
/* The values sent to the queue receive task from the queue send task and the
* queue send software timer respectively. */
#define mainVALUE_SENT_FROM_TASK ( 100UL )
#define mainVALUE_SENT_FROM_TIMER ( 200UL )
/*-----------------------------------------------------------*/
/*
* The tasks as described in the comments at the top of this file.
*/
static void prvQueueReceiveTask( void * pvParameters );
static void prvQueueSendTask( void * pvParameters );
/*
* The callback function executed when the software timer expires.
*/
static void prvQueueSendTimerCallback( TimerHandle_t xTimerHandle );
/*-----------------------------------------------------------*/
/* The queue used by both tasks. */
static QueueHandle_t xQueue = NULL;
/* A software timer that is started from the tick hook. */
static TimerHandle_t xTimer = NULL;
/*-----------------------------------------------------------*/
/*** SEE THE COMMENTS AT THE TOP OF THIS FILE ***/
void main_blinky( void )
{
const TickType_t xTimerPeriod = mainTIMER_SEND_FREQUENCY_MS;
/* Create the queue. */
xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );
if( xQueue != NULL )
{
/* Start the two tasks as described in the comments at the top of this
* file. */
xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */
"Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */
NULL, /* The parameter passed to the task - not used in this simple case. */
mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */
NULL ); /* The task handle is not required, so NULL is passed. */
xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
/* Create the software timer, but don't start it yet. */
xTimer = xTimerCreate( "Timer", /* The text name assigned to the software timer - for debug only as it is not used by the kernel. */
xTimerPeriod, /* The period of the software timer in ticks. */
pdTRUE, /* xAutoReload is set to pdTRUE. */
NULL, /* The timer's ID is not used. */
prvQueueSendTimerCallback ); /* The function executed when the timer expires. */
if( xTimer != NULL )
{
xTimerStart( xTimer, 0 );
}
/* Start the tasks and timer running. */
vTaskStartScheduler();
}
/* If all is well, the scheduler will now be running, and the following
* line will never be reached. If the following line does execute, then
* there was insufficient FreeRTOS heap memory available for the idle and/or
* timer tasks to be created. See the memory management section on the
* FreeRTOS web site for more details. */
for( ; ; )
{
}
}
/*-----------------------------------------------------------*/
static void prvQueueSendTask( void * pvParameters )
{
TickType_t xNextWakeTime;
const TickType_t xBlockTime = mainTASK_SEND_FREQUENCY_MS;
const uint32_t ulValueToSend = mainVALUE_SENT_FROM_TASK;
/* Prevent the compiler warning about the unused parameter. */
( void ) pvParameters;
/* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount();
for( ; ; )
{
/* Place this task in the blocked state until it is time to run again.
* The block time is specified in ticks, pdMS_TO_TICKS() was used to
* convert a time specified in milliseconds into a time specified in ticks.
* While in the Blocked state this task will not consume any CPU time. */
vTaskDelayUntil( &xNextWakeTime, xBlockTime );
/* Send to the queue - causing the queue receive task to unblock and
* write to the console. 0 is used as the block time so the send operation
* will not block - it shouldn't need to block as the queue should always
* have at least one space at this point in the code. */
xQueueSend( xQueue, &ulValueToSend, 0U );
}
}
/*-----------------------------------------------------------*/
static void prvQueueSendTimerCallback( TimerHandle_t xTimerHandle )
{
const uint32_t ulValueToSend = mainVALUE_SENT_FROM_TIMER;
/* This is the software timer callback function. The software timer has a
* period of two seconds and is reset each time a key is pressed. This
* callback function will execute if the timer expires, which will only happen
* if a key is not pressed for two seconds. */
/* Avoid compiler warnings resulting from the unused parameter. */
( void ) xTimerHandle;
/* Send to the queue - causing the queue receive task to unblock and
* write out a message. This function is called from the timer/daemon task, so
* must not block. Hence the block time is set to 0. */
xQueueSend( xQueue, &ulValueToSend, 0U );
}
/*-----------------------------------------------------------*/
static void prvQueueReceiveTask( void * pvParameters )
{
uint32_t ulReceivedValue;
/* Prevent the compiler warning about the unused parameter. */
( void ) pvParameters;
for( ; ; )
{
/* Wait until something arrives in the queue - this task will block
* indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
* FreeRTOSConfig.h. It will not use any CPU time while it is in the
* Blocked state. */
xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
/* To get here something must have been received from the queue, but
* is it an expected value? Normally calling printf() from a task is not
* a good idea. Here there is lots of stack space and only one task is
* using console IO so it is ok. However, note the comments at the top of
* this file about the risks of making Linux system calls (such as
* console output) from a FreeRTOS task. */
if( ulReceivedValue == mainVALUE_SENT_FROM_TASK )
{
console_print( "Message received from task\n" );
}
else if( ulReceivedValue == mainVALUE_SENT_FROM_TIMER )
{
console_print( "Message received from software timer\n" );
}
else
{
console_print( "Unexpected message\n" );
}
}
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,964 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
*******************************************************************************
* NOTE 1: The POSIX port is a simulation (or is that emulation?) only! Do not
* expect to get real time behaviour from the POSIX port or this demo
* application. It is provided as a convenient development and demonstration
* test bed only.
*
* Linux will not be running the FreeRTOS simulator threads continuously, so
* the timing information in the FreeRTOS+Trace logs have no meaningful units.
* See the documentation page for the Linux simulator for an explanation of
* the slow timing:
* https://www.freertos.org/FreeRTOS-simulator-for-Linux.html
* - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -
*
* NOTE 2: This project provides two demo applications. A simple blinky style
* project, and a more comprehensive test and demo application. The
* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
* between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
* in main.c. This file implements the comprehensive test and demo version.
*
* NOTE 3: This file only contains the source code that is specific to the
* full demo. Generic functions, such FreeRTOS hook functions, are defined in
* main.c.
*******************************************************************************
*
* main() creates all the demo application tasks, then starts the scheduler.
* The web documentation provides more details of the standard demo application
* tasks, which provide no particular functionality but do provide a good
* example of how to use the FreeRTOS API.
*
* In addition to the standard demo tasks, the following tasks and tests are
* defined and/or created within this file:
*
* "Check" task - This only executes every five seconds but has a high priority
* to ensure it gets processor time. Its main function is to check that all the
* standard demo tasks are still operational. While no errors have been
* discovered the check task will print out "OK" and the current simulated tick
* time. If an error is discovered in the execution of a task then the check
* task will print out an appropriate error message.
*
*/
/* Standard includes. */
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
/* Kernel includes. */
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <timers.h>
#include <semphr.h>
/* Standard demo includes. */
#include "BlockQ.h"
#include "integer.h"
#include "semtest.h"
#include "PollQ.h"
#include "GenQTest.h"
#include "QPeek.h"
#include "recmutex.h"
#include "flop.h"
#include "TimerDemo.h"
#include "countsem.h"
#include "death.h"
#include "dynamic.h"
#include "QueueSet.h"
#include "QueueOverwrite.h"
#include "EventGroupsDemo.h"
#include "IntSemTest.h"
#include "TaskNotify.h"
#include "QueueSetPolling.h"
#include "StaticAllocation.h"
#include "blocktim.h"
#include "AbortDelay.h"
#include "MessageBufferDemo.h"
#include "StreamBufferDemo.h"
#include "StreamBufferInterrupt.h"
#include "MessageBufferAMP.h"
#include "console.h"
/* Priorities at which the tasks are created. */
#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
#define mainTIMER_TEST_PERIOD ( 50 )
/*
* Exercises code that is not otherwise covered by the standard demo/test
* tasks.
*/
extern BaseType_t xRunCodeCoverageTestAdditions( void );
/* Task function prototypes. */
static void prvCheckTask( void * pvParameters );
/* A task that is created from the idle task to test the functionality of
* eTaskStateGet(). */
static void prvTestTask( void * pvParameters );
/*
* Called from the idle task hook function to demonstrate a few utility
* functions that are not demonstrated by any of the standard demo tasks.
*/
static void prvDemonstrateTaskStateAndHandleGetFunctions( void );
/*
* Called from the idle task hook function to demonstrate the use of
* xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by
* any of the standard demo tasks.
*/
static void prvDemonstratePendingFunctionCall( void );
/*
* The function that is pended by prvDemonstratePendingFunctionCall().
*/
static void prvPendedFunction( void * pvParameter1,
uint32_t ulParameter2 );
/*
* prvDemonstrateTimerQueryFunctions() is called from the idle task hook
* function to demonstrate the use of functions that query information about a
* software timer. prvTestTimerCallback() is the callback function for the
* timer being queried.
*/
static void prvDemonstrateTimerQueryFunctions( void );
static void prvTestTimerCallback( TimerHandle_t xTimer );
/*
* A task to demonstrate the use of the xQueueSpacesAvailable() function.
*/
static void prvDemoQueueSpaceFunctions( void * pvParameters );
/*
* Tasks that ensure indefinite delays are truly indefinite.
*/
static void prvPermanentlyBlockingSemaphoreTask( void * pvParameters );
static void prvPermanentlyBlockingNotificationTask( void * pvParameters );
/*
* The test function and callback function used when exercising the timer AP
* function that changes the timer's auto-reload mode.
*/
static void prvDemonstrateChangingTimerReloadMode( void * pvParameters );
static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer );
/*-----------------------------------------------------------*/
/* The variable into which error messages are latched. */
static char * pcStatusMessage = "OK: No errors";
int xErrorCount = 0;
/* This semaphore is created purely to test using the vSemaphoreDelete() and
* semaphore tracing API functions. It has no other purpose. */
static SemaphoreHandle_t xMutexToDelete = NULL;
/*-----------------------------------------------------------*/
int main_full( void )
{
/* Start the check task as described at the top of this file. */
xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
/* Create the standard demo tasks. */
vStartTaskNotifyTask();
/* vStartTaskNotifyArrayTask(); */
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
vStartQueuePeekTasks();
vStartMathTasks( mainFLOP_TASK_PRIORITY );
vStartRecursiveMutexTasks();
vStartCountingSemaphoreTasks();
vStartDynamicPriorityTasks();
vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
vStartEventGroupTasks();
vStartInterruptSemaphoreTasks();
vCreateBlockTimeTasks();
vCreateAbortDelayTasks();
xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );
vStartStreamBufferTasks();
vStartStreamBufferInterruptDemo();
vStartMessageBufferAMPTasks( configMINIMAL_STACK_SIZE );
#if ( configUSE_QUEUE_SETS == 1 )
{
vStartQueueSetTasks();
vStartQueueSetPollingTask();
}
#endif
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
{
vStartStaticallyAllocatedTasks();
}
#endif
#if ( configUSE_PREEMPTION != 0 )
{
/* Don't expect these tasks to pass when preemption is not used. */
vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
}
#endif
/* The suicide tasks must be created last as they need to know how many
* tasks were running prior to their creation. This then allows them to
* ascertain whether or not the correct/expected number of tasks are running at
* any given time. */
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
/* Create the semaphore that will be deleted in the idle task hook. This
* is done purely to test the use of vSemaphoreDelete(). */
xMutexToDelete = xSemaphoreCreateMutex();
/* Start the scheduler itself. */
vTaskStartScheduler();
/* Should never get here unless there was not enough heap space to create
* the idle and other system tasks. */
return 0;
}
/*-----------------------------------------------------------*/
static void prvCheckTask( void * pvParameters )
{
TickType_t xNextWakeTime;
const TickType_t xCycleFrequency = pdMS_TO_TICKS( 10000UL );
HeapStats_t xHeapStats;
/* Just to remove compiler warning. */
( void ) pvParameters;
/* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount();
for( ; ; )
{
/* Place this task in the blocked state until it is time to run again. */
vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
/* Check the standard demo tasks are running without error. */
#if ( configUSE_PREEMPTION != 0 )
{
/* These tasks are only created when preemption is used. */
if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
{
pcStatusMessage = "Error: TimerDemo";
xErrorCount++;
}
}
#endif
if( xAreStreamBufferTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: StreamBuffer";
xErrorCount++;
}
else if( xAreMessageBufferTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: MessageBuffer";
xErrorCount++;
}
else if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: Notification";
xErrorCount++;
}
/* else if( xAreTaskNotificationArrayTasksStillRunning() != pdTRUE )
* {
* pcStatusMessage = "Error: NotificationArray";
* xErrorCount++;
* } */
else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: IntSem";
xErrorCount++;
}
else if( xAreEventGroupTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: EventGroup";
xErrorCount++;
}
else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: IntMath";
xErrorCount++;
}
else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: GenQueue";
xErrorCount++;
}
else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: QueuePeek";
xErrorCount++;
}
else if( xAreBlockingQueuesStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: BlockQueue";
xErrorCount++;
}
else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: SemTest";
xErrorCount++;
}
else if( xArePollingQueuesStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: PollQueue";
xErrorCount++;
}
else if( xAreMathsTaskStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Flop";
xErrorCount++;
}
else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: RecMutex";
xErrorCount++;
}
else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: CountSem";
xErrorCount++;
}
else if( xIsCreateTaskStillRunning() != pdTRUE )
{
pcStatusMessage = "Error: Death";
xErrorCount++;
}
else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Dynamic";
xErrorCount++;
}
else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Queue overwrite";
xErrorCount++;
}
else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Block time";
xErrorCount++;
}
else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Abort delay";
xErrorCount++;
}
else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Stream buffer interrupt";
xErrorCount++;
}
else if( xAreMessageBufferAMPTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Message buffer AMP";
xErrorCount++;
}
#if ( configUSE_QUEUE_SETS == 1 )
else if( xAreQueueSetTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Queue set";
xErrorCount++;
}
else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
{
pcStatusMessage = "Error: Queue set polling";
xErrorCount++;
}
#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
else if( xAreStaticAllocationTasksStillRunning() != pdPASS )
{
xErrorCount++;
pcStatusMessage = "Error: Static allocation";
}
#endif /* configSUPPORT_STATIC_ALLOCATION */
printf( "%s - tick count %lu \r\n",
pcStatusMessage,
xTaskGetTickCount() );
if( xErrorCount != 0 )
{
exit( 1 );
}
/* Reset the error condition */
pcStatusMessage = "OK: No errors";
}
}
/*-----------------------------------------------------------*/
static void prvTestTask( void * pvParameters )
{
const unsigned long ulMSToSleep = 5;
/* Just to remove compiler warnings. */
( void ) pvParameters;
/* This task is just used to test the eTaskStateGet() function. It
* does not have anything to do. */
for( ; ; )
{
/* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
* tasks waiting to be terminated by the idle task. */
struct timespec ts;
ts.tv_sec = ulMSToSleep / 1000;
ts.tv_nsec = ulMSToSleep % 1000l * 1000000l;
nanosleep( &ts, NULL );
}
}
/*-----------------------------------------------------------*/
/* Called from vApplicationIdleHook(), which is defined in main.c. */
void vFullDemoIdleFunction( void )
{
const unsigned long ulMSToSleep = 15;
void * pvAllocated;
/* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
* tasks waiting to be terminated by the idle task. */
struct timespec ts;
ts.tv_sec = ulMSToSleep / 1000;
ts.tv_nsec = ulMSToSleep % 1000l * 1000000l;
nanosleep( &ts, NULL );
/* Demonstrate a few utility functions that are not demonstrated by any of
* the standard demo tasks. */
prvDemonstrateTaskStateAndHandleGetFunctions();
/* Demonstrate the use of xTimerPendFunctionCall(), which is not
* demonstrated by any of the standard demo tasks. */
prvDemonstratePendingFunctionCall();
/* Demonstrate the use of functions that query information about a software
* timer. */
prvDemonstrateTimerQueryFunctions();
/* If xMutexToDelete has not already been deleted, then delete it now.
* This is done purely to demonstrate the use of, and test, the
* vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
* that has tasks blocked on it. */
if( xMutexToDelete != NULL )
{
/* For test purposes, add the mutex to the registry, then remove it
* again, before it is deleted - checking its name is as expected before
* and after the assertion into the registry and its removal from the
* registry. */
configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );
configASSERT( strcmp( pcQueueGetName( xMutexToDelete ), "Test_Mutex" ) == 0 );
vQueueUnregisterQueue( xMutexToDelete );
configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
vSemaphoreDelete( xMutexToDelete );
xMutexToDelete = NULL;
}
/* Exercise heap_5 a bit. The malloc failed hook will trap failed
* allocations so there is no need to test here. */
pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );
vPortFree( pvAllocated );
/* Exit after a fixed time so code coverage results are written to the
* disk. */
#if ( projCOVERAGE_TEST == 1 )
{
const TickType_t xMaxRunTime = pdMS_TO_TICKS( 30000UL );
/* Exercise code not otherwise executed by standard demo/test tasks. */
if( xRunCodeCoverageTestAdditions() != pdPASS )
{
pcStatusMessage = "Code coverage additions failed.\r\n";
xErrorCount++;
}
if( ( xTaskGetTickCount() - configINITIAL_TICK_COUNT ) >= xMaxRunTime )
{
vTaskEndScheduler();
}
}
#endif /* if ( projCOVERAGE_TEST == 1 ) */
}
/*-----------------------------------------------------------*/
/* Called by vApplicationTickHook(), which is defined in main.c. */
void vFullDemoTickHookFunction( void )
{
TaskHandle_t xTimerTask;
/* Call the periodic timer test, which tests the timer API functions that
* can be called from an ISR. */
#if ( configUSE_PREEMPTION != 0 )
{
/* Only created when preemption is used. */
vTimerPeriodicISRTests();
}
#endif
/* Call the periodic queue overwrite from ISR demo. */
vQueueOverwritePeriodicISRDemo();
#if ( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */
{
/* Write to a queue that is in use as part of the queue set demo to
* demonstrate using queue sets from an ISR. */
vQueueSetAccessQueueSetFromISR();
vQueueSetPollingInterruptAccess();
}
#endif
/* Exercise event groups from interrupts. */
vPeriodicEventGroupsProcessing();
/* Exercise giving mutexes from an interrupt. */
vInterruptSemaphorePeriodicTest();
/* Exercise using task notifications from an interrupt. */
xNotifyTaskFromISR();
/* xNotifyArrayTaskFromISR(); */
/* Writes to stream buffer byte by byte to test the stream buffer trigger
* level functionality. */
vPeriodicStreamBufferProcessing();
/* Writes a string to a string buffer four bytes at a time to demonstrate
* a stream being sent from an interrupt to a task. */
vBasicStreamBufferSendFromISR();
/* For code coverage purposes. */
xTimerTask = xTimerGetTimerDaemonTaskHandle();
configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );
}
/*-----------------------------------------------------------*/
static void prvPendedFunction( void * pvParameter1,
uint32_t ulParameter2 )
{
static intptr_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;
intptr_t ulParameter1;
ulParameter1 = ( intptr_t ) pvParameter1;
/* Ensure the parameters are as expected. */
configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );
configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );
/* Remember the parameters for the next time the function is called. */
ulLastParameter1 = ulParameter1;
ulLastParameter2 = ulParameter2;
/* Remove compiler warnings in case configASSERT() is not defined. */
( void ) ulLastParameter1;
( void ) ulLastParameter2;
}
/*-----------------------------------------------------------*/
static void prvTestTimerCallback( TimerHandle_t xTimer )
{
/* This is the callback function for the timer accessed by
* prvDemonstrateTimerQueryFunctions(). The callback does not do anything. */
( void ) xTimer;
}
/*-----------------------------------------------------------*/
static void prvDemonstrateTimerQueryFunctions( void )
{
static TimerHandle_t xTimer = NULL;
const char * pcTimerName = "TestTimer";
volatile TickType_t xExpiryTime;
const TickType_t xDontBlock = 0;
if( xTimer == NULL )
{
xTimer = xTimerCreate( pcTimerName, portMAX_DELAY, pdTRUE, NULL, prvTestTimerCallback );
if( xTimer != NULL )
{
/* Called from the idle task so a block time must not be
* specified. */
xTimerStart( xTimer, xDontBlock );
}
}
if( xTimer != NULL )
{
/* Demonstrate querying a timer's name. */
configASSERT( strcmp( pcTimerGetName( xTimer ), pcTimerName ) == 0 );
/* Demonstrate querying a timer's period. */
configASSERT( xTimerGetPeriod( xTimer ) == portMAX_DELAY );
/* Demonstrate querying a timer's next expiry time, although nothing is
* done with the returned value. Note if the expiry time is less than the
* maximum tick count then the expiry time has overflowed from the current
* time. In this case the expiry time was set to portMAX_DELAY, so it is
* expected to be less than the current time until the current time has
* itself overflowed. */
xExpiryTime = xTimerGetExpiryTime( xTimer );
( void ) xExpiryTime;
}
}
/*-----------------------------------------------------------*/
static void prvDemonstratePendingFunctionCall( void )
{
static intptr_t ulParameter1 = 1000UL, ulParameter2 = 0UL;
const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */
/* prvPendedFunction() just expects the parameters to be incremented by one
* each time it is called. */
ulParameter1++;
ulParameter2++;
/* Pend the function call, sending the parameters. */
xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );
}
/*-----------------------------------------------------------*/
static void prvDemonstrateTaskStateAndHandleGetFunctions( void )
{
TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;
char * pcTaskName;
static portBASE_TYPE xPerformedOneShotTests = pdFALSE;
TaskHandle_t xTestTask;
TaskStatus_t xTaskInfo;
extern StackType_t uxTimerTaskStack[];
/* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and
* xTaskGetIdleTaskHandle() functions. Also try using the function that sets
* the task number. */
xIdleTaskHandle = xTaskGetIdleTaskHandle();
xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();
/* This is the idle hook, so the current task handle should equal the
* returned idle task handle. */
if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )
{
pcStatusMessage = "Error: Returned idle task handle was incorrect";
xErrorCount++;
}
/* Check the same handle is obtained using the idle task's name. First try
* with the wrong name, then the right name. */
if( xTaskGetHandle( "Idle" ) == xIdleTaskHandle )
{
pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
xErrorCount++;
}
if( xTaskGetHandle( "IDLE" ) != xIdleTaskHandle )
{
pcStatusMessage = "Error: Returned handle for name Idle was incorrect";
xErrorCount++;
}
/* Check the timer task handle was returned correctly. */
pcTaskName = pcTaskGetName( xTimerTaskHandle );
if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )
{
pcStatusMessage = "Error: Returned timer task handle was incorrect";
xErrorCount++;
}
if( xTaskGetHandle( "Tmr Svc" ) != xTimerTaskHandle )
{
pcStatusMessage = "Error: Returned handle for name Tmr Svc was incorrect";
xErrorCount++;
}
/* This task is running, make sure it's state is returned as running. */
if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
{
pcStatusMessage = "Error: Returned idle task state was incorrect";
xErrorCount++;
}
/* If this task is running, then the timer task must be blocked. */
if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
{
pcStatusMessage = "Error: Returned timer task state was incorrect";
xErrorCount++;
}
/* Also with the vTaskGetInfo() function. */
vTaskGetInfo( xTimerTaskHandle, /* The task being queried. */
&xTaskInfo, /* The structure into which information on the task will be written. */
pdTRUE, /* Include the task's high watermark in the structure. */
eInvalid ); /* Include the task state in the structure. */
/* Check the information returned by vTaskGetInfo() is as expected. */
if( ( xTaskInfo.eCurrentState != eBlocked ) ||
( strcmp( xTaskInfo.pcTaskName, "Tmr Svc" ) != 0 ) ||
( xTaskInfo.uxCurrentPriority != configTIMER_TASK_PRIORITY ) ||
( xTaskInfo.pxStackBase != uxTimerTaskStack ) ||
( xTaskInfo.xHandle != xTimerTaskHandle ) )
{
pcStatusMessage = "Error: vTaskGetInfo() returned incorrect information about the timer task";
xErrorCount++;
}
/* Other tests that should only be performed once follow. The test task
* is not created on each iteration because to do so would cause the death
* task to report an error (too many tasks running). */
if( xPerformedOneShotTests == pdFALSE )
{
/* Don't run this part of the test again. */
xPerformedOneShotTests = pdTRUE;
/* Create a test task to use to test other eTaskStateGet() return values. */
if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
{
/* If this task is running, the test task must be in the ready state. */
if( eTaskStateGet( xTestTask ) != eReady )
{
pcStatusMessage = "Error: Returned test task state was incorrect 1";
xErrorCount++;
}
/* Now suspend the test task and check its state is reported correctly. */
vTaskSuspend( xTestTask );
if( eTaskStateGet( xTestTask ) != eSuspended )
{
pcStatusMessage = "Error: Returned test task state was incorrect 2";
xErrorCount++;
}
/* Now delete the task and check its state is reported correctly. */
vTaskDelete( xTestTask );
if( eTaskStateGet( xTestTask ) != eDeleted )
{
pcStatusMessage = "Error: Returned test task state was incorrect 3";
xErrorCount++;
}
}
}
}
/*-----------------------------------------------------------*/
static void prvDemoQueueSpaceFunctions( void * pvParameters )
{
QueueHandle_t xQueue = NULL;
const unsigned portBASE_TYPE uxQueueLength = 10;
unsigned portBASE_TYPE uxReturn, x;
/* Remove compiler warnings. */
( void ) pvParameters;
/* Create the queue that will be used. Nothing is actually going to be
* sent or received so the queue item size is set to 0. */
xQueue = xQueueCreate( uxQueueLength, 0 );
configASSERT( xQueue );
for( ; ; )
{
for( x = 0; x < uxQueueLength; x++ )
{
/* Ask how many messages are available... */
uxReturn = uxQueueMessagesWaiting( xQueue );
/* Check the number of messages being reported as being available
* is as expected, and force an assert if not. */
if( uxReturn != x )
{
/* xQueue cannot be NULL so this is deliberately causing an
* assert to be triggered as there is an error. */
configASSERT( xQueue == NULL );
}
/* Ask how many spaces remain in the queue... */
uxReturn = uxQueueSpacesAvailable( xQueue );
/* Check the number of spaces being reported as being available
* is as expected, and force an assert if not. */
if( uxReturn != ( uxQueueLength - x ) )
{
/* xQueue cannot be NULL so this is deliberately causing an
* assert to be triggered as there is an error. */
configASSERT( xQueue == NULL );
}
/* Fill one more space in the queue. */
xQueueSendToBack( xQueue, NULL, 0 );
}
/* Perform the same check while the queue is full. */
uxReturn = uxQueueMessagesWaiting( xQueue );
if( uxReturn != uxQueueLength )
{
configASSERT( xQueue == NULL );
}
uxReturn = uxQueueSpacesAvailable( xQueue );
if( uxReturn != 0 )
{
configASSERT( xQueue == NULL );
}
/* The queue is full, start again. */
xQueueReset( xQueue );
#if ( configUSE_PREEMPTION == 0 )
taskYIELD();
#endif
}
}
/*-----------------------------------------------------------*/
static void prvPermanentlyBlockingSemaphoreTask( void * pvParameters )
{
SemaphoreHandle_t xSemaphore;
/* Prevent compiler warning about unused parameter in the case that
* configASSERT() is not defined. */
( void ) pvParameters;
/* This task should block on a semaphore, and never return. */
xSemaphore = xSemaphoreCreateBinary();
configASSERT( xSemaphore );
xSemaphoreTake( xSemaphore, portMAX_DELAY );
/* The above xSemaphoreTake() call should never return, force an assert if
* it does. */
configASSERT( pvParameters != NULL );
vTaskDelete( NULL );
}
/*-----------------------------------------------------------*/
static void prvPermanentlyBlockingNotificationTask( void * pvParameters )
{
/* Prevent compiler warning about unused parameter in the case that
* configASSERT() is not defined. */
( void ) pvParameters;
/* This task should block on a task notification, and never return. */
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
/* The above ulTaskNotifyTake() call should never return, force an assert
* if it does. */
configASSERT( pvParameters != NULL );
vTaskDelete( NULL );
}
/*-----------------------------------------------------------*/
static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer )
{
intptr_t ulTimerID;
/* Increment the timer's ID to show the callback has executed. */
ulTimerID = ( intptr_t ) pvTimerGetTimerID( xTimer );
ulTimerID++;
vTimerSetTimerID( xTimer, ( void * ) ulTimerID );
}
/*-----------------------------------------------------------*/
static void prvDemonstrateChangingTimerReloadMode( void * pvParameters )
{
TimerHandle_t xTimer;
const char * const pcTimerName = "TestTimer";
const TickType_t x100ms = pdMS_TO_TICKS( 100UL );
/* Avoid compiler warnings about unused parameter. */
( void ) pvParameters;
xTimer = xTimerCreate( pcTimerName,
x100ms,
pdFALSE, /* Created as a one-shot timer. */
0,
prvReloadModeTestTimerCallback );
configASSERT( xTimer );
configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE );
configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL );
configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 );
configASSERT( xTimerGetPeriod( xTimer ) == x100ms );
/* Timer was created as a one-shot timer. Its callback just increments the
* timer's ID - so set the ID to 0, let the timer run for a number of timeout
* periods, then check the timer has only executed once. */
vTimerSetTimerID( xTimer, ( void * ) 0 );
xTimerStart( xTimer, portMAX_DELAY );
vTaskDelay( 3UL * x100ms );
configASSERT( ( ( uintptr_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL );
/* Now change the timer to be an auto-reload timer and check it executes
* the expected number of times. */
vTimerSetReloadMode( xTimer, pdTRUE );
vTimerSetTimerID( xTimer, ( void * ) 0 );
xTimerStart( xTimer, 0 );
vTaskDelay( ( 3UL * x100ms ) + ( x100ms / 2UL ) ); /* Three full periods. */
configASSERT( ( uintptr_t ) ( pvTimerGetTimerID( xTimer ) ) == 3UL );
configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );
/* Now change the timer back to be a one-shot timer and check it only
* executes once. */
vTimerSetReloadMode( xTimer, pdFALSE );
vTimerSetTimerID( xTimer, ( void * ) 0 );
xTimerStart( xTimer, 0 );
vTaskDelay( 3UL * x100ms );
configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );
configASSERT( ( uintptr_t ) ( pvTimerGetTimerID( xTimer ) ) == 1UL );
/* Clean up at the end. */
xTimerDelete( xTimer, portMAX_DELAY );
vTaskDelete( NULL );
}

View File

@ -0,0 +1,67 @@
/*
* FreeRTOS V202212.01
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* Utility functions required to gather run time statistics. See:
* https://www.FreeRTOS.org/rtos-run-time-stats.html
*
* Note that this is a simulated port, where simulated time is a lot slower than
* real time, therefore the run time counter values have no real meaningful
* units.
*
* 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.
*/
#include <time.h>
/* FreeRTOS includes. */
#include <FreeRTOS.h>
/* Time at start of day (in ns). */
static unsigned long ulStartTimeNs;
/*-----------------------------------------------------------*/
void vConfigureTimerForRunTimeStats( void )
{
struct timespec xNow;
clock_gettime( CLOCK_MONOTONIC, &xNow );
ulStartTimeNs = xNow.tv_sec * 1000000000ul + xNow.tv_nsec;
}
/*-----------------------------------------------------------*/
unsigned long ulGetRunTimeCounterValue( void )
{
struct timespec xNow;
/* Time at start. */
clock_gettime( CLOCK_MONOTONIC, &xNow );
return xNow.tv_sec * 1000000000ul + xNow.tv_nsec - ulStartTimeNs;
}
/*-----------------------------------------------------------*/

View File

@ -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 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 */

View File

@ -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 */