diff --git a/.gitignore b/.gitignore index 087f0e67e..00340f9e4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ CTestTestfile.cmake *.dep *.o *.axf +*.elf *.map *.a *.htm diff --git a/README.md b/README.md index 256162ae4..bc1f2c850 100644 --- a/README.md +++ b/README.md @@ -94,27 +94,27 @@ The master branch has the most recent code with all new features and bug fixes. ### ThreadX ``` -arc_em cortex_a12 cortex_m0 cortex_r4 -arc_hs cortex_a15 cortex_m23 cortex_r5 -arm11 cortex_a17 cortex_m3 cortex_r7 -arm9 cortex_a34 cortex_m33 -c667x cortex_a35 cortex_m4 -linux cortex_a5 cortex_m55 -risc-v32 cortex_a53 cortex_m7 -rxv1 cortex_a55 cortex_m85 -rxv2 cortex_a57 -rxv3 cortex_a5x -win32 cortex_a65 -xtensa cortex_a65ae - cortex_a7 - cortex_a72 - cortex_a73 - cortex_a75 - cortex_a76 - cortex_a76ae - cortex_a77 - cortex_a8 - cortex_a9 +arc_em cortex_a12 cortex_m0 cortex_r4 +arc_hs cortex_a15 cortex_m23 cortex_r5 +arm11 cortex_a17 cortex_m3 cortex_r7 +arm9 cortex_a34 cortex_m33 +c667x cortex_a35 cortex_m4 +linux cortex_a5 cortex_m55 +risc-v32 cortex_a53 cortex_m7 +rxv1 cortex_a55 cortex_m85 +rxv2 cortex_a57 +rxv3 cortex_a5x +tricore_tc1_6_2 cortex_a65 +win32 cortex_a65ae +xtensa cortex_a7 + cortex_a72 + cortex_a73 + cortex_a75 + cortex_a76 + cortex_a76ae + cortex_a77 + cortex_a8 + cortex_a9 ``` ### ThreadX Modules diff --git a/cmake/tricore_tc1_6_2.cmake b/cmake/tricore_tc1_6_2.cmake new file mode 100644 index 000000000..e732e50a1 --- /dev/null +++ b/cmake/tricore_tc1_6_2.cmake @@ -0,0 +1,44 @@ +# Copyright (c) 2026 safecubed GmbH +# Copyright (c) 2026 Eclipse ThreadX contributors +# +# This program and the accompanying materials are made available under the +# terms of the MIT License which is available at +# https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: MIT + +# Portions of this file were generated with AI assistance. + +# Toolchain file for the TriCore TC1.6.2 port (Infineon AURIX TC3) with the +# AURIX GCC. +# +# The port uses no driver library. See +# ports/tricore_tc1_6_2/gnu/readme_threadx.txt. + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR tricore) + +set(THREADX_ARCH "tricore_tc1_6_2") +set(THREADX_TOOLCHAIN "gnu") + +set(CMAKE_C_COMPILER tricore-elf-gcc) +set(CMAKE_CXX_COMPILER tricore-elf-g++) +set(AS tricore-elf-as) +set(AR tricore-elf-ar) +set(OBJCOPY tricore-elf-objcopy) +set(OBJDUMP tricore-elf-objdump) +set(SIZE tricore-elf-size) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_C_FLAGS "-mcpu=tc38xx -std=c99 -fno-common -fstrict-volatile-bitfields -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") +set(CMAKE_EXE_LINKER_FLAGS "-mcpu=tc38xx -Wl,--gc-sections" CACHE INTERNAL "exe link flags") +set(CMAKE_C_FLAGS_DEBUG "-O0 -g3" CACHE INTERNAL "c debug compiler flags") +set(CMAKE_C_FLAGS_RELEASE "-O0" CACHE INTERNAL "c release compiler flags") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O0 -g3" CACHE INTERNAL "c relwithdebinfo compiler flags") +set(CMAKE_C_FLAGS_MINSIZEREL "-O0" CACHE INTERNAL "c minsizerel compiler flags") diff --git a/ports/tricore_tc1_6_2/gnu/CMakeLists.txt b/ports/tricore_tc1_6_2/gnu/CMakeLists.txt new file mode 100755 index 000000000..4126a9eaf --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/CMakeLists.txt @@ -0,0 +1,18 @@ +target_sources(${PROJECT_NAME} + PRIVATE + # {{BEGIN_TARGET_SOURCES}} + ${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_context_restore.c + ${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_context_save.c + ${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_interrupt_control.c + ${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_schedule.c + ${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_stack_build.c + ${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_system_return.c + ${CMAKE_CURRENT_LIST_DIR}/src/tx_timer_interrupt.c + # {{END_TARGET_SOURCES}} +) + +target_include_directories(${PROJECT_NAME} + SYSTEM + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/inc +) diff --git a/ports/tricore_tc1_6_2/gnu/example_build/build_threadx_sample.bat b/ports/tricore_tc1_6_2/gnu/example_build/build_threadx_sample.bat new file mode 100644 index 000000000..cefa7eb5e --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/example_build/build_threadx_sample.bat @@ -0,0 +1,57 @@ +@echo off +rem ########################################################################## +rem Copyright (c) 2026 safecubed GmbH +rem Copyright (c) 2026 Eclipse ThreadX contributors +rem +rem This program and the accompanying materials are made available under the +rem terms of the MIT License which is available at +rem https://opensource.org/licenses/MIT. +rem +rem SPDX-License-Identifier: MIT +rem ########################################################################## + +rem Portions of this file were generated with AI assistance. + +rem Builds the ThreadX library tx.a and sample_threadx.elf for the AURIX TC375 +rem Lite Kit without a driver library, as build_threadx_sample.sh does. The +rem start-up code is crt0-tc38xx.o of the AURIX GCC: the compiler has no TC37x +rem device, and the TC38x start-up code applies to the TC375 unchanged. +rem sample_threadx.ld replaces the memory description of the TC38x. +rem +rem CROSS_COMPILE selects the toolchain prefix. The default is the AURIX GCC +rem (tricore-elf-), which shall be on PATH. + +setlocal EnableExtensions +cd /d "%~dp0" + +if not defined CROSS_COMPILE set "CROSS_COMPILE=tricore-elf-" +set "CC=%CROSS_COMPILE%gcc" +rem tricore-elf-ar loads lib\bfd-plugins\libdep.a, which is no DLL. +set "AR=%CROSS_COMPILE%gcc-ar" + +set "THREADX_ROOT=..\..\..\.." +set "BUILD_DIR=build" + +set "CFLAGS=-mcpu=tc38xx -std=c99 -O0 -g3 -Wall -fmessage-length=0 -fno-common -fdata-sections -ffunction-sections" +set "INCLUDES=-I%THREADX_ROOT%/common/inc -I../inc" + +if exist "%BUILD_DIR%" rmdir /s /q "%BUILD_DIR%" +mkdir "%BUILD_DIR%\tx" "%BUILD_DIR%\sample" || exit /b 1 +del /q tx.a sample_threadx.elf sample_threadx.map 2>nul + +rem The archiver reads the object list from a response file. The response file +rem uses forward slashes, because the archiver treats a backslash in it as an +rem escape character. +for %%f in (..\src\*.c %THREADX_ROOT%\common\src\*.c) do ( + "%CC%" %CFLAGS% %INCLUDES% -c "%%f" -o "%BUILD_DIR%/tx/%%~nf.o" || exit /b 1 + echo %BUILD_DIR%/tx/%%~nf.o>>"%BUILD_DIR%\tx.rsp" +) +"%AR%" -r tx.a @%BUILD_DIR%/tx.rsp || exit /b 1 + +for %%f in (sample_threadx.c tx_initialize_low_level.c) do ( + "%CC%" %CFLAGS% %INCLUDES% -c "%%f" -o "%BUILD_DIR%/sample/%%~nf.o" || exit /b 1 +) + +"%CC%" -mcpu=tc38xx -T sample_threadx.ld -Wl,--gc-sections -Wl,-Map=sample_threadx.map ^ + -o sample_threadx.elf %BUILD_DIR%/sample/sample_threadx.o ^ + %BUILD_DIR%/sample/tx_initialize_low_level.o tx.a || exit /b 1 diff --git a/ports/tricore_tc1_6_2/gnu/example_build/build_threadx_sample.sh b/ports/tricore_tc1_6_2/gnu/example_build/build_threadx_sample.sh new file mode 100755 index 000000000..5581ff6e6 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/example_build/build_threadx_sample.sh @@ -0,0 +1,53 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2026 safecubed GmbH +# Copyright (c) 2026 Eclipse ThreadX contributors +# +# This program and the accompanying materials are made available under the +# terms of the MIT License which is available at +# https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: MIT +############################################################################## + +# Portions of this file were generated with AI assistance. + +# Builds the ThreadX library tx.a and sample_threadx.elf for the AURIX TC375 +# Lite Kit without a driver library. The start-up code is crt0-tc38xx.o of +# the AURIX GCC: the compiler has no TC37x device, and the TC38x start-up +# code applies to the TC375 unchanged. sample_threadx.ld replaces the memory +# description of the TC38x. +# +# CROSS_COMPILE selects the toolchain prefix. The default is the AURIX GCC +# (tricore-elf-), which shall be on PATH. + +set -e +cd "$(dirname "$0")" + +: "${CROSS_COMPILE:=tricore-elf-}" +CC="${CROSS_COMPILE}gcc" +AR="${CROSS_COMPILE}ar" + +THREADX_ROOT="../../../.." +BUILD_DIR="build" + +CFLAGS="-mcpu=tc38xx -std=c99 -O0 -g3 -Wall -fmessage-length=0 -fno-common \ +-fdata-sections -ffunction-sections" +INCLUDES="-I${THREADX_ROOT}/common/inc -I../inc" + +rm -rf "${BUILD_DIR}" +mkdir -p "${BUILD_DIR}/tx" "${BUILD_DIR}/sample" +rm -f tx.a sample_threadx.elf sample_threadx.map + +for src in ../src/*.c "${THREADX_ROOT}"/common/src/*.c; do + "${CC}" ${CFLAGS} ${INCLUDES} -c "${src}" -o "${BUILD_DIR}/tx/$(basename "${src%.c}").o" +done +"${AR}" -r tx.a "${BUILD_DIR}"/tx/*.o + +for src in sample_threadx.c tx_initialize_low_level.c; do + obj="${BUILD_DIR}/sample/$(basename "${src%.c}").o" + "${CC}" ${CFLAGS} ${INCLUDES} -c "${src}" -o "${obj}" +done + +"${CC}" -mcpu=tc38xx -T sample_threadx.ld -Wl,--gc-sections -Wl,-Map=sample_threadx.map \ + -o sample_threadx.elf "${BUILD_DIR}"/sample/*.o tx.a diff --git a/ports/tricore_tc1_6_2/gnu/example_build/sample_threadx.c b/ports/tricore_tc1_6_2/gnu/example_build/sample_threadx.c new file mode 100644 index 000000000..dcd1b5471 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/example_build/sample_threadx.c @@ -0,0 +1,397 @@ +/***************************************************************************/ +/* Copyright (c) 2024 Microsoft Corporation */ +/* Copyright (c) 2026 Eclipse ThreadX contributors */ +/* */ +/* This program and the accompanying materials are made available under */ +/* the terms of the MIT License which is available at */ +/* https://opensource.org/licenses/MIT. */ +/* */ +/* SPDX-License-Identifier: MIT */ +/***************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + +/* This is a small demo of the high-performance ThreadX kernel. It includes examples of eight + threads of different priorities, using a message queue, semaphore, mutex, event flags group, + byte pool, and block pool. */ + +#include "tx_api.h" + +#define DEMO_STACK_SIZE 1024 +#define DEMO_BYTE_POOL_SIZE 9120 +#define DEMO_BLOCK_POOL_SIZE 100 +#define DEMO_QUEUE_SIZE 100 + + +/* Define the ThreadX object control blocks... */ + +TX_THREAD thread_0; +TX_THREAD thread_1; +TX_THREAD thread_2; +TX_THREAD thread_3; +TX_THREAD thread_4; +TX_THREAD thread_5; +TX_THREAD thread_6; +TX_THREAD thread_7; +TX_QUEUE queue_0; +TX_SEMAPHORE semaphore_0; +TX_MUTEX mutex_0; +TX_EVENT_FLAGS_GROUP event_flags_0; +TX_BYTE_POOL byte_pool_0; +TX_BLOCK_POOL block_pool_0; +UCHAR memory_area[DEMO_BYTE_POOL_SIZE]; + +#ifdef TX_ENABLE_EVENT_TRACE +#define DEMO_TRACE_BUFFER_SIZE 4000 +#define DEMO_TRACE_REGISTRY_ENTRIES 30 + +/* tx_trace_enable stores word-sized entries, so the buffer is word-aligned. */ +ULONG trace_buffer[DEMO_TRACE_BUFFER_SIZE / sizeof(ULONG)]; +#endif + + +/* Define the counters used in the demo application... */ + +ULONG thread_0_counter; +ULONG thread_1_counter; +ULONG thread_1_messages_sent; +ULONG thread_2_counter; +ULONG thread_2_messages_received; +ULONG thread_3_counter; +ULONG thread_4_counter; +ULONG thread_5_counter; +ULONG thread_6_counter; +ULONG thread_7_counter; + + +/* Define thread prototypes. */ + +void thread_0_entry(ULONG thread_input); +void thread_1_entry(ULONG thread_input); +void thread_2_entry(ULONG thread_input); +void thread_3_and_4_entry(ULONG thread_input); +void thread_5_entry(ULONG thread_input); +void thread_6_and_7_entry(ULONG thread_input); + + +/* Define main entry point. */ + +int main() +{ + + /* Enter the ThreadX kernel. */ + tx_kernel_enter(); +} + + +/* Define what the initial system looks like. */ + +void tx_application_define(void *first_unused_memory) +{ + +CHAR *pointer = TX_NULL; + + +#ifdef TX_ENABLE_EVENT_TRACE + /* Kernel initialisation resets the trace, so tracing starts here, before + the first object is created. */ + tx_trace_enable(trace_buffer, DEMO_TRACE_BUFFER_SIZE, DEMO_TRACE_REGISTRY_ENTRIES); +#endif + + /* Create a byte memory pool from which to allocate the thread stacks. */ + tx_byte_pool_create(&byte_pool_0, "byte pool 0", memory_area, DEMO_BYTE_POOL_SIZE); + + /* Put system definition stuff in here, e.g. thread creates and other assorted + create information. */ + + /* Allocate the stack for thread 0. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + /* Create the main thread. */ + tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, + pointer, DEMO_STACK_SIZE, + 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); + + + /* Allocate the stack for thread 1. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + /* Create threads 1 and 2. These threads pass information through a ThreadX + message queue. It is also interesting to note that these threads have a time + slice. */ + tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1, + pointer, DEMO_STACK_SIZE, + 16, 16, 4, TX_AUTO_START); + + /* Allocate the stack for thread 2. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2, + pointer, DEMO_STACK_SIZE, + 16, 16, 4, TX_AUTO_START); + + /* Allocate the stack for thread 3. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + /* Create threads 3 and 4. These threads compete for a ThreadX counting semaphore. + An interesting thing here is that both threads share the same instruction area. */ + tx_thread_create(&thread_3, "thread 3", thread_3_and_4_entry, 3, + pointer, DEMO_STACK_SIZE, + 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START); + + /* Allocate the stack for thread 4. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + tx_thread_create(&thread_4, "thread 4", thread_3_and_4_entry, 4, + pointer, DEMO_STACK_SIZE, + 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START); + + /* Allocate the stack for thread 5. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + /* Create thread 5. This thread simply pends on an event flag which will be set + by thread_0. */ + tx_thread_create(&thread_5, "thread 5", thread_5_entry, 5, + pointer, DEMO_STACK_SIZE, + 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START); + + /* Allocate the stack for thread 6. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + /* Create threads 6 and 7. These threads compete for a ThreadX mutex. */ + tx_thread_create(&thread_6, "thread 6", thread_6_and_7_entry, 6, + pointer, DEMO_STACK_SIZE, + 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START); + + /* Allocate the stack for thread 7. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT); + + tx_thread_create(&thread_7, "thread 7", thread_6_and_7_entry, 7, + pointer, DEMO_STACK_SIZE, + 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START); + + /* Allocate the message queue. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT); + + /* Create the message queue shared by threads 1 and 2. */ + tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG)); + + /* Create the semaphore used by threads 3 and 4. */ + tx_semaphore_create(&semaphore_0, "semaphore 0", 1); + + /* Create the event flags group used by threads 1 and 5. */ + tx_event_flags_create(&event_flags_0, "event flags 0"); + + /* Create the mutex used by thread 6 and 7 without priority inheritance. */ + tx_mutex_create(&mutex_0, "mutex 0", TX_NO_INHERIT); + + /* Allocate the memory for a small block pool. */ + tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_BLOCK_POOL_SIZE, TX_NO_WAIT); + + /* Create a block memory pool to allocate a message buffer from. */ + tx_block_pool_create(&block_pool_0, "block pool 0", sizeof(ULONG), pointer, DEMO_BLOCK_POOL_SIZE); + + /* Allocate a block and release the block memory. */ + tx_block_allocate(&block_pool_0, (VOID **) &pointer, TX_NO_WAIT); + + /* Release the block back to the pool. */ + tx_block_release(pointer); +} + + + +/* Define the test threads. */ + +void thread_0_entry(ULONG thread_input) +{ + +UINT status; + + + /* This thread simply sits in while-forever-sleep loop. */ + while(1) + { + + /* Increment the thread counter. */ + thread_0_counter++; + + /* Sleep for 10 ticks. */ + tx_thread_sleep(10); + + /* Set event flag 0 to wakeup thread 5. */ + status = tx_event_flags_set(&event_flags_0, 0x1, TX_OR); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + } +} + + +void thread_1_entry(ULONG thread_input) +{ + +UINT status; + + + /* This thread simply sends messages to a queue shared by thread 2. */ + while(1) + { + + /* Increment the thread counter. */ + thread_1_counter++; + + /* Send message to queue 0. */ + status = tx_queue_send(&queue_0, &thread_1_messages_sent, TX_WAIT_FOREVER); + + /* Check completion status. */ + if (status != TX_SUCCESS) + break; + + /* Increment the message sent. */ + thread_1_messages_sent++; + } +} + + +void thread_2_entry(ULONG thread_input) +{ + +ULONG received_message; +UINT status; + + /* This thread retrieves messages placed on the queue by thread 1. */ + while(1) + { + + /* Increment the thread counter. */ + thread_2_counter++; + + /* Retrieve a message from the queue. */ + status = tx_queue_receive(&queue_0, &received_message, TX_WAIT_FOREVER); + + /* Check completion status and make sure the message is what we + expected. */ + if ((status != TX_SUCCESS) || (received_message != thread_2_messages_received)) + break; + + /* Otherwise, all is okay. Increment the received message count. */ + thread_2_messages_received++; + } +} + + +void thread_3_and_4_entry(ULONG thread_input) +{ + +UINT status; + + + /* This function is executed from thread 3 and thread 4. As the loop + below shows, these function compete for ownership of semaphore_0. */ + while(1) + { + + /* Increment the thread counter. */ + if (thread_input == 3) + thread_3_counter++; + else + thread_4_counter++; + + /* Get the semaphore with suspension. */ + status = tx_semaphore_get(&semaphore_0, TX_WAIT_FOREVER); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Sleep for 2 ticks to hold the semaphore. */ + tx_thread_sleep(2); + + /* Release the semaphore. */ + status = tx_semaphore_put(&semaphore_0); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + } +} + + +void thread_5_entry(ULONG thread_input) +{ + +UINT status; +ULONG actual_flags; + + + /* This thread simply waits for an event in a forever loop. */ + while(1) + { + + /* Increment the thread counter. */ + thread_5_counter++; + + /* Wait for event flag 0. */ + status = tx_event_flags_get(&event_flags_0, 0x1, TX_OR_CLEAR, + &actual_flags, TX_WAIT_FOREVER); + + /* Check status. */ + if ((status != TX_SUCCESS) || (actual_flags != 0x1)) + break; + } +} + + +void thread_6_and_7_entry(ULONG thread_input) +{ + +UINT status; + + + /* This function is executed from thread 6 and thread 7. As the loop + below shows, these function compete for ownership of mutex_0. */ + while(1) + { + + /* Increment the thread counter. */ + if (thread_input == 6) + thread_6_counter++; + else + thread_7_counter++; + + /* Get the mutex with suspension. */ + status = tx_mutex_get(&mutex_0, TX_WAIT_FOREVER); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Get the mutex again with suspension. This shows + that an owning thread may retrieve the mutex it + owns multiple times. */ + status = tx_mutex_get(&mutex_0, TX_WAIT_FOREVER); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Sleep for 2 ticks to hold the mutex. */ + tx_thread_sleep(2); + + /* Release the mutex. */ + status = tx_mutex_put(&mutex_0); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Release the mutex again. This will actually + release ownership since it was obtained twice. */ + status = tx_mutex_put(&mutex_0); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + } +} diff --git a/ports/tricore_tc1_6_2/gnu/example_build/sample_threadx.ld b/ports/tricore_tc1_6_2/gnu/example_build/sample_threadx.ld new file mode 100644 index 000000000..8df0b0eac --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/example_build/sample_threadx.ld @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + +/* Memory description of CPU0 of the TC375 for the default linker script of + the AURIX GCC and its start-up code crt0-tc38xx.o. + + The file is given with -T and augments the default linker script through + INSERT. It replaces the memory description that the compiler driver adds + for -mcpu=tc38xx. The start-up code occupies the start of program flash + bank 0, 0x80000000, which the boot mode header of the board selects + through its non-cached address 0xA0000000. */ + +__USTACK_SIZE = 4K; +__ISTACK_SIZE = 4K; +__HEAP_SIZE = 4K; +__CSA_SIZE = 16K; + +MEMORY +{ + PFLASH0 (rx!p): org = 0x80000000, len = 3M + DSPR0 (w!xp): org = 0x70000000, len = 240K +} + +REGION_ALIAS("CODE_MEM", PFLASH0) +REGION_ALIAS("DATA_MEM", DSPR0) +REGION_ALIAS("SDATA_MEM", DSPR0) +REGION_ALIAS("BSS_MEM", DSPR0) +REGION_ALIAS("ZDATA_MEM", DSPR0) +REGION_ALIAS("CSA_MEM", DSPR0) + +INSERT BEFORE .startup + + +/* Interrupt vector table of CPU0. TX_PORT_TRICORE_INTERRUPT in tx_port.h + places the entry of priority n in the section .intvec_tc0_, which is + located at BIV + 32 * n. The table holds the priorities 1 to 15 and is + aligned to its size of 512 bytes. */ + +SECTIONS +{ + .inttab_tc0 : ALIGN(512) + { + __INTTAB_CPU0 = .; + . = 0x020; KEEP (*(.intvec_tc0_1)) + . = 0x040; KEEP (*(.intvec_tc0_2)) + . = 0x060; KEEP (*(.intvec_tc0_3)) + . = 0x080; KEEP (*(.intvec_tc0_4)) + . = 0x0A0; KEEP (*(.intvec_tc0_5)) + . = 0x0C0; KEEP (*(.intvec_tc0_6)) + . = 0x0E0; KEEP (*(.intvec_tc0_7)) + . = 0x100; KEEP (*(.intvec_tc0_8)) + . = 0x120; KEEP (*(.intvec_tc0_9)) + . = 0x140; KEEP (*(.intvec_tc0_10)) + . = 0x160; KEEP (*(.intvec_tc0_11)) + . = 0x180; KEEP (*(.intvec_tc0_12)) + . = 0x1A0; KEEP (*(.intvec_tc0_13)) + . = 0x1C0; KEEP (*(.intvec_tc0_14)) + . = 0x1E0; KEEP (*(.intvec_tc0_15)) + } > CODE_MEM +} + +INSERT AFTER .inttab + + +/* The memory of DSPR0 after the context save areas is free. + _tx_initialize_low_level passes its start to tx_application_define. */ + +SECTIONS +{ + .tx_free_memory (NOLOAD) : ALIGN(8) + { + __TX_FREE_MEM = .; + } > DATA_MEM +} + +INSERT AFTER .csa diff --git a/ports/tricore_tc1_6_2/gnu/example_build/tx_initialize_low_level.c b/ports/tricore_tc1_6_2/gnu/example_build/tx_initialize_low_level.c new file mode 100644 index 000000000..6aef0405a --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/example_build/tx_initialize_low_level.c @@ -0,0 +1,253 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + +/* Low-level initialisation of ThreadX on CPU0 of the TC375 Lite Kit without + a driver library. + + The start-up code of the compiler (crt0) has disabled the CPU0 watchdog + and the safety watchdog, initialised the stacks, the context save areas + and the C data, and calls main of sample_threadx.c, which calls + tx_kernel_enter. The clock system keeps its reset state: the system runs + from the back-up clock of 100 MHz. + + _tx_initialize_low_level runs from tx_kernel_enter before the kernel and + the application are initialised. It installs the trap and interrupt + vector tables, the ThreadX timer on compare 0 of STM0 and the dispatch + interrupt of the port. Interrupts stay disabled until _tx_thread_schedule + starts the first thread. */ + +#include "tx_api.h" + + +/* Core special function registers. */ +#define CSFR_BIV 0xFE20 +#define CSFR_BTV 0xFE24 + +/* CPU0 watchdog: ENDINIT protects BIV and BTV. */ +#define SCU_WDTCPU0_CON0 (*(volatile unsigned int *) 0xF003624CUL) +#define WDT_CON0_ENDINIT 0x00000001UL +#define WDT_CON0_LCK 0x00000002UL +#define WDT_CON0_PW_OFF 2 +#define WDT_CON0_PW_MSK 0x3FFFUL +#define WDT_CON0_REL_MSK 0xFFFF0000UL +/* CON0.PW reads with bits 5:0 inverted. */ +#define WDT_CON0_PW_READ_INVERT 0x003FUL + +/* Clock control: fSTM = fSOURCE / CCUCON0.STMDIV, where fSOURCE is the + back-up clock while CCUCON0.CLKSEL = 0. */ +#define SCU_CCUCON0 (*(volatile unsigned int *) 0xF0036030UL) +#define CCUCON0_STMDIV_MSK 0x0000000FUL +#define BACKUP_CLOCK_FREQUENCY 100000000UL + +/* STM0 compare 0. */ +#define STM0_TIM0 (*(volatile unsigned int *) 0xF0001010UL) +#define STM0_CMP0 (*(volatile unsigned int *) 0xF0001030UL) +#define STM0_CMCON (*(volatile unsigned int *) 0xF0001038UL) +#define STM0_ICR (*(volatile unsigned int *) 0xF000103CUL) +#define STM0_ISCR (*(volatile unsigned int *) 0xF0001040UL) +#define STM_CMCON_CMP0_MSK 0x00001F1FUL /* MSTART0 and MSIZE0 */ +#define STM_CMCON_CMP0_32_BITS 0x0000001FUL /* MSTART0 = 0, MSIZE0 = 31 */ +#define STM_ICR_CMP0_MSK 0x00000007UL /* CMP0EN, CMP0IR and CMP0OS */ +#define STM_ICR_CMP0EN 0x00000001UL /* CMP0OS = 0: service request STMIR0 */ +#define STM_ISCR_CMP0IRR 0x00000001UL + +/* Service request STMIR0 of STM0. */ +#define SRC_STM0SR0 (*(volatile unsigned int *) 0xF0038300UL) + + +VOID _tx_timer_interrupt(VOID); + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) +VOID _tx_execution_isr_enter(VOID); +VOID _tx_execution_isr_exit(VOID); +#endif + +extern VOID *_tx_initialize_unused_memory; + +/* From the trap vector table below and the linker script. */ +extern UCHAR _tx_trap_table[]; +extern UCHAR __INTTAB_CPU0[]; +extern UCHAR __TX_FREE_MEM[]; + +/* STM ticks per ThreadX timer tick. */ +static ULONG timer_period; + + +/* Sets (endinit = WDT_CON0_ENDINIT) or clears (endinit = 0) the ENDINIT bit + of the CPU0 watchdog. A password access unlocks CON0, the modify access + then writes ENDINIT and locks CON0 again. */ +static VOID cpu0_endinit_write(ULONG endinit) +{ + + ULONG con0; + ULONG password; + + con0 = SCU_WDTCPU0_CON0; + password = (((con0 >> WDT_CON0_PW_OFF) & WDT_CON0_PW_MSK) ^ WDT_CON0_PW_READ_INVERT) << WDT_CON0_PW_OFF; + + if ((con0 & WDT_CON0_LCK) != 0U) + { + SCU_WDTCPU0_CON0 = (con0 & WDT_CON0_REL_MSK) | password | WDT_CON0_ENDINIT; + } + + SCU_WDTCPU0_CON0 = (con0 & WDT_CON0_REL_MSK) | password | WDT_CON0_LCK | endinit; + + /* The read back completes the write before ENDINIT protected registers + are accessed. */ + (VOID) SCU_WDTCPU0_CON0; +} + + +VOID _tx_initialize_low_level(VOID) +{ + + ULONG stm_frequency; + + _disable(); + + _tx_initialize_unused_memory = (VOID *) __TX_FREE_MEM; + + /* Trap and interrupt vector tables. BIV.VSS = 0: vector spacing of 32 + bytes. */ + cpu0_endinit_write(0U); + __mtcr(CSFR_BTV, (ULONG) _tx_trap_table); + __mtcr(CSFR_BIV, (ULONG) __INTTAB_CPU0); + _isync(); + cpu0_endinit_write(WDT_CON0_ENDINIT); + + /* ThreadX timer on compare 0 of STM0. The compare covers all 32 bits of + the lower timer word. */ + stm_frequency = BACKUP_CLOCK_FREQUENCY / (SCU_CCUCON0 & CCUCON0_STMDIV_MSK); + timer_period = (stm_frequency + (TX_TIMER_TICKS_PER_SECOND / 2U)) / TX_TIMER_TICKS_PER_SECOND; + + STM0_CMCON = (STM0_CMCON & ~STM_CMCON_CMP0_MSK) | STM_CMCON_CMP0_32_BITS; + STM0_CMP0 = STM0_TIM0 + timer_period; + STM0_ISCR = STM_ISCR_CMP0IRR; + STM0_ICR = (STM0_ICR & ~STM_ICR_CMP0_MSK) | STM_ICR_CMP0EN; + SRC_STM0SR0 = TX_PORT_TRICORE_SRC_CLRR_MSK | TX_PORT_TRICORE_SRC_SRE_MSK | + (0UL << TX_PORT_TRICORE_SRC_TOS_OFF) | TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY; + + /* Dispatch interrupt of the port. */ + TX_PORT_TRICORE_DISPATCH_SRC = TX_PORT_TRICORE_SRC_CLRR_MSK | TX_PORT_TRICORE_SRC_SRE_MSK | + (0UL << TX_PORT_TRICORE_SRC_TOS_OFF) | TX_PORT_TRICORE_DISPATCH_PRIORITY; +} + + +TX_PORT_TRICORE_INTERRUPT(_tx_timer_isr, TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY) +{ + + ULONG now; + ULONG next; + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) + _tx_execution_isr_enter(); +#endif + + STM0_ISCR = STM_ISCR_CMP0IRR; + + /* The next compare follows the previous one by one period. If the timer + has already passed that value, for example after a debugger halt, the + next compare is one period from now and the ticks in between are lost. + Without this check, the next interrupt would occur only after the + 32-bit timer wraps. */ + next = STM0_CMP0 + timer_period; + now = STM0_TIM0; + if ((LONG) (next - now) <= 0) + { + next = now + timer_period; + } + STM0_CMP0 = next; + + _tx_timer_interrupt(); + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) + _tx_execution_isr_exit(); +#endif +} + + +/* Receives the trap class and TIN of every trap except the system call and + shall not return. */ +VOID __attribute__( ( weak, noreturn ) ) tx_trap_error_hook(UINT trap_class, UINT tin) +{ + (VOID) trap_class; + (VOID) tin; + + _debug(); + while (TX_TRUE) + { + } +} + +/* Trap vector table of CPU0: eight entries of 32 bytes, aligned to 256 + bytes. The error entries jump, because a context management trap can + leave no free CSA. */ +__asm__ (".pushsection .traptab, \"ax\", @progbits\n" + " .align 8\n" + " .global _tx_trap_table\n" + " .type _tx_trap_table, @function\n" + "_tx_trap_table:\n" + + /* Class 0: MMU. */ + " mov %d4, 0\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 1: internal protection. */ + " mov %d4, 1\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 2: instruction errors. */ + " mov %d4, 2\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 3: context management. */ + " mov %d4, 3\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 4: system bus and peripheral errors. */ + " mov %d4, 4\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 5: assertion. */ + " mov %d4, 5\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 6: system call. The handler shall be called directly + (TX_PORT_TRICORE_SYSCALL_CALL_DEPTH). */ + " svlcx\n" + " mov %d4, %d15\n" + " call _tx_thread_syscall_handler\n" + " rslcx\n" + " rfe\n" + " .align 5\n" + + /* Class 7: non-maskable interrupt. */ + " mov %d4, 7\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + " .size _tx_trap_table, . - _tx_trap_table\n" + ".popsection\n"); diff --git a/ports/tricore_tc1_6_2/gnu/inc/tx_port.h b/ports/tricore_tc1_6_2/gnu/inc/tx_port.h new file mode 100755 index 000000000..7ab3a36e4 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/inc/tx_port.h @@ -0,0 +1,693 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* tx_port.h TriCore/GNU */ +/* 6.5.2 */ +/* */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the ThreadX */ +/* real-time kernel function identically on a variety of different */ +/* processor architectures. For example, the size or number of bits */ +/* in an "int" data type vary between microprocessor architectures and */ +/* even C compilers for the same microprocessor. ThreadX does not */ +/* directly use native C data types. Instead, ThreadX creates its */ +/* own special types that can be mapped to actual data types by this */ +/* file to guarantee consistency in the interface and functionality. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* 10-15-2021 William E. Lamie Modified comment(s), added */ +/* symbol ULONG64_DEFINED, */ +/* resulting in version 6.1.9 */ +/* 04-25-2022 William E. Lamie Modified comment(s), removed */ +/* useless definition, */ +/* resulting in version 6.1.11 */ +/* 10-31-2023 Yanwu Cai Modified comment(s), fixed */ +/* compile warnings, */ +/* resulting in version 6.3.0 */ +/* 11-04-2026 Andreas Neubauer Adapted for TriCore, */ +/* resulting in version 6.5.2 */ +/* */ +/**************************************************************************/ + +#ifndef TX_PORT_H +#define TX_PORT_H + + + +/* #define TX_MISRA_ENABLE */ + + +/* #define TX_INLINE_INITIALIZATION */ + +/* #define TX_NOT_INTERRUPTABLE */ +/* #define TX_TIMER_PROCESS_IN_ISR */ +/* #define TX_REACTIVATE_INLINE */ +/* #define TX_DISABLE_STACK_FILLING */ +/* #define TX_ENABLE_STACK_CHECKING */ +/* #define TX_DISABLE_PREEMPTION_THRESHOLD */ +/* #define TX_DISABLE_REDUNDANT_CLEARING */ +/* #define TX_DISABLE_NOTIFY_CALLBACKS */ +/* #define TX_INLINE_THREAD_RESUME_SUSPEND */ +/* #define TX_ENABLE_EVENT_TRACE */ + + +/* For MISRA, define enable performance info. Also, for MISRA TX_DISABLE_NOTIFY_CALLBACKS should not be defined. */ + + +/* #define TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO +#define TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO +#define TX_EVENT_FLAGS_ENABLE_PERFORMANCE_INFO +#define TX_MUTEX_ENABLE_PERFORMANCE_INFO +#define TX_QUEUE_ENABLE_PERFORMANCE_INFO +#define TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO +#define TX_THREAD_ENABLE_PERFORMANCE_INFO +#define TX_TIMER_ENABLE_PERFORMANCE_INFO */ + + + +/* Determine if the optional ThreadX user define file should be used. */ + +#ifdef TX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in tx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "tx_user.h" +#endif + + +/* Define compiler library include files. */ + +#include +#include +#include + +/* TriCore intrinsics of the AURIX GCC. */ +#include + + + + +/* Define ThreadX basic types for this port. */ + +#define VOID void +typedef char CHAR; +typedef unsigned char UCHAR; +typedef int INT; +typedef unsigned int UINT; +typedef long LONG; +typedef unsigned long ULONG; +typedef unsigned long long ULONG64; +typedef short SHORT; +typedef unsigned short USHORT; +#define ULONG64_DEFINED + + +/* Define automated coverage test extensions for the ThreadX regression test. */ + +#ifndef __ASSEMBLER__ + +typedef unsigned int TEST_FLAG; +extern TEST_FLAG threadx_byte_allocate_loop_test; +extern TEST_FLAG threadx_byte_release_loop_test; +extern TEST_FLAG threadx_mutex_suspension_put_test; +extern TEST_FLAG threadx_mutex_suspension_priority_test; +#ifndef TX_TIMER_PROCESS_IN_ISR +extern TEST_FLAG threadx_delete_timer_thread; +#endif + +extern void abort_and_resume_byte_allocating_thread(void); +extern void abort_all_threads_suspended_on_mutex(void); +extern void suspend_lowest_priority(void); +#ifndef TX_TIMER_PROCESS_IN_ISR +extern void delete_timer_thread(void); +#endif +extern TEST_FLAG test_stack_analyze_flag; +extern TEST_FLAG test_initialize_flag; +extern TEST_FLAG test_forced_mutex_timeout; + + +#ifdef TX_REGRESSION_TEST + +#define TX_BYTE_ALLOCATE_EXTENSION if (threadx_byte_allocate_loop_test == ((TEST_FLAG) 1)) \ + { \ + pool_ptr -> tx_byte_pool_owner = TX_NULL; \ + threadx_byte_allocate_loop_test = ((TEST_FLAG) 0); \ + } + +#define TX_BYTE_RELEASE_EXTENSION if (threadx_byte_release_loop_test == ((TEST_FLAG) 1)) \ + { \ + threadx_byte_release_loop_test = ((TEST_FLAG) 0); \ + abort_and_resume_byte_allocating_thread(); \ + } + +#define TX_MUTEX_PUT_EXTENSION_1 if (threadx_mutex_suspension_put_test == ((TEST_FLAG) 1)) \ + { \ + threadx_mutex_suspension_put_test = ((TEST_FLAG) 0); \ + abort_all_threads_suspended_on_mutex(); \ + } + +#define TX_MUTEX_PUT_EXTENSION_2 if (test_forced_mutex_timeout == ((TEST_FLAG) 1)) \ + { \ + test_forced_mutex_timeout = ((TEST_FLAG) 0); \ + _tx_thread_wait_abort(mutex_ptr -> tx_mutex_suspension_list); \ + } + +#define TX_MUTEX_PRIORITY_CHANGE_EXTENSION if (threadx_mutex_suspension_priority_test == ((TEST_FLAG) 1)) \ + { \ + threadx_mutex_suspension_priority_test = ((TEST_FLAG) 0); \ + suspend_lowest_priority(); \ + } + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define TX_TIMER_INITIALIZE_EXTENSION(a) if (threadx_delete_timer_thread == ((TEST_FLAG) 1)) \ + { \ + threadx_delete_timer_thread = ((TEST_FLAG) 0); \ + delete_timer_thread(); \ + (a) = ((UINT) 1); \ + } + +#endif + +#define TX_THREAD_STACK_ANALYZE_EXTENSION if (test_stack_analyze_flag == ((TEST_FLAG) 1)) \ + { \ + thread_ptr -> tx_thread_id = ((TEST_FLAG) 0); \ + test_stack_analyze_flag = ((TEST_FLAG) 0); \ + } \ + else if (test_stack_analyze_flag == ((TEST_FLAG) 2)) \ + { \ + stack_ptr = thread_ptr -> tx_thread_stack_start; \ + test_stack_analyze_flag = ((TEST_FLAG) 0); \ + } \ + else if (test_stack_analyze_flag == ((TEST_FLAG) 3)) \ + { \ + *stack_ptr = TX_STACK_FILL; \ + test_stack_analyze_flag = ((TEST_FLAG) 0); \ + } \ + else \ + { \ + test_stack_analyze_flag = ((TEST_FLAG) 0); \ + } + +#define TX_INITIALIZE_KERNEL_ENTER_EXTENSION if (test_initialize_flag == ((TEST_FLAG) 1)) \ + { \ + test_initialize_flag = ((TEST_FLAG) 0); \ + return; \ + } + +#endif /* TX_REGRESSION_TEST */ + +#endif /* __ASSEMBLER__ */ + + + + +/* TriCore core registers used by the inline functions of this file. The + definitions shared only by the port sources are in src/tx_port_tricore.h. */ + +#define TX_PORT_TRICORE_CSFR_PSW 0xFE04 +#define TX_PORT_TRICORE_CSFR_ICR 0xFE2C + +#define TX_PORT_TRICORE_PSW_IS_OFF 9 /* 1: interrupt stack in use */ +#define TX_PORT_TRICORE_ICR_CCPN_MSK 0x000000FFUL /* Current CPU priority number */ +#define TX_PORT_TRICORE_ICR_IE_MSK 0x00008000UL /* Global interrupt enable */ + +/* System call that enters the scheduler. */ +#define TX_PORT_TRICORE_SYSCALL_ID_SCHEDULE 0 + +/* Receives every other system call number. The weak default stops the CPU. */ +VOID tx_port_tricore_syscall_hook(UINT id); + + +/* Interrupt handlers of CPU0. + + TX_PORT_TRICORE_INTERRUPT(isr, priority) starts the definition of the + interrupt handler isr, for example: + + TX_PORT_TRICORE_INTERRUPT(timer_isr, 2) + { + ... + } + + It places the vector table entry in the section .intvec_tc0_. + The linker script shall locate this section at BIV + 32 * priority. The + entry saves the lower context and jumps to isr, which returns through + RSLCX and RFE. priority shall expand to a decimal integer literal without + parentheses or suffix, because it becomes part of the section name. */ + +#define TX_PORT_TRICORE_STRINGIFY(x) #x +#define TX_PORT_TRICORE_EXPAND_STRINGIFY(x) TX_PORT_TRICORE_STRINGIFY(x) + +#define TX_PORT_TRICORE_INTERRUPT(isr, priority) \ + __asm__ (".pushsection .intvec_tc0_" TX_PORT_TRICORE_EXPAND_STRINGIFY(priority) \ + ", \"ax\", @progbits\n" \ + " svlcx\n" \ + " movh.a %a14, hi:" #isr "\n" \ + " lea %a14, [%a14]lo:" #isr "\n" \ + " ji %a14\n" \ + ".popsection\n"); \ + void isr(void) __attribute__ ((interrupt_handler)); \ + void isr(void) + + +/* The dispatch interrupt switches threads on behalf of interrupt handlers. + Its priority shall be below every interrupt that calls ThreadX services, + including the timer interrupt. */ +#ifndef TX_PORT_TRICORE_DISPATCH_PRIORITY +#define TX_PORT_TRICORE_DISPATCH_PRIORITY 1 +#endif + +/* Address of the service request control register (SRC) of the dispatch + interrupt. The default is SRC_GPSR00, general purpose service request 0 + of group 0, of the TC3xx. The board shall configure this SRC for CPU0 + with TX_PORT_TRICORE_DISPATCH_PRIORITY and enable it. */ +#ifndef TX_PORT_TRICORE_DISPATCH_SRC_ADDRESS +#define TX_PORT_TRICORE_DISPATCH_SRC_ADDRESS 0xF0038990UL +#endif + +#define TX_PORT_TRICORE_DISPATCH_SRC (*(volatile unsigned int *) TX_PORT_TRICORE_DISPATCH_SRC_ADDRESS) + +/* Fields of an SRC. */ +#define TX_PORT_TRICORE_SRC_SRPN_MSK 0x000000FFUL /* Service request priority number */ +#define TX_PORT_TRICORE_SRC_SRE_MSK 0x00000400UL /* Service request enable */ +#define TX_PORT_TRICORE_SRC_TOS_OFF 11 /* Type of service, 0: CPU0 */ +#define TX_PORT_TRICORE_SRC_CLRR_MSK 0x02000000UL /* Request clear */ +#define TX_PORT_TRICORE_SRC_SETR_MSK 0x04000000UL /* Request set */ + +#ifndef TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY +#define TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY 2 +#endif + +/* Lower 32 bits of the system timer STM0 of the TC3xx: the default time + source of the trace and of the execution profile. */ +#define TX_PORT_TRICORE_STM0_TIM0 (*(volatile unsigned int *) 0xF0001010UL) + + +/* Define the TX_MEMSET macro to remove library reference. The local names + carry the prefix tx_memset_ so that they do not hide an argument of the + same name. */ + +#ifndef TX_MISRA_ENABLE +#define TX_MEMSET(a,b,c) do \ + { \ + UCHAR *tx_memset_ptr; \ + UCHAR tx_memset_value; \ + UINT tx_memset_index; \ + UINT tx_memset_size; \ + tx_memset_ptr = (UCHAR *) ((VOID *) (a)); \ + tx_memset_value = (UCHAR) (b); \ + tx_memset_size = (UINT) (c); \ + for (tx_memset_index = 0U; tx_memset_index < tx_memset_size; tx_memset_index++) \ + { \ + tx_memset_ptr[tx_memset_index] = tx_memset_value; \ + } \ + } while (0) +#endif + + +/* Define the priority levels for ThreadX. Legal values range + from 32 to 1024 and MUST be evenly divisible by 32. */ + +#ifndef TX_MAX_PRIORITIES +#define TX_MAX_PRIORITIES 32 +#endif + + +/* Define the minimum stack for a ThreadX thread on this processor. If the size supplied during + thread creation is less than this value, the thread create call will return an error. */ + +#ifndef TX_MINIMUM_STACK +#define TX_MINIMUM_STACK 200 /* Minimum stack size for this port */ +#endif + + +/* Define the system timer thread's default stack size and priority. These are only applicable + if TX_TIMER_PROCESS_IN_ISR is not defined. */ + +#ifndef TX_TIMER_THREAD_STACK_SIZE +#define TX_TIMER_THREAD_STACK_SIZE 1024 /* Default timer thread stack size */ +#endif + +#ifndef TX_TIMER_THREAD_PRIORITY +#define TX_TIMER_THREAD_PRIORITY 0 /* Default timer thread priority */ +#endif + + +/* By default, TX_DISABLE masks all interrupts by clearing ICR.IE. If + TX_PORT_USE_CCPN is defined, TX_DISABLE raises ICR.CCPN to TX_PORT_CCPN + instead, and interrupts with a priority above TX_PORT_CCPN stay enabled. + Such interrupts shall not call ThreadX services. TX_DISABLE never lowers + ICR.CCPN. Both symbols can be defined in tx_user.h. */ + +/* #define TX_PORT_USE_CCPN */ + +#ifndef TX_PORT_CCPN +#define TX_PORT_CCPN 31 +#endif + +/* Define various constants for the ThreadX port. */ + +/* The interrupt posture of tx_interrupt_control is ICR.IE. */ +#define TX_INT_DISABLE 0 +#define TX_INT_ENABLE TX_PORT_TRICORE_ICR_IE_MSK + + +#ifndef TX_TIMER_TICKS_PER_SECOND +#define TX_TIMER_TICKS_PER_SECOND (1000UL) +#endif + + +/* Define the clock source for trace event entry time stamp. The following two item are port specific. + For example, if the time source is at the address 0x0a800024 and is 16-bits in size, the clock + source constants would be: + +#define TX_TRACE_TIME_SOURCE *((ULONG *) 0x0a800024) +#define TX_TRACE_TIME_MASK 0x0000FFFFUL + +*/ + +#ifndef TX_MISRA_ENABLE +#ifndef TX_TRACE_TIME_SOURCE +#define TX_TRACE_TIME_SOURCE TX_PORT_TRICORE_STM0_TIM0 +#endif +#else +#ifndef TX_TRACE_TIME_SOURCE +ULONG _tx_misra_time_stamp_get(VOID); +#define TX_TRACE_TIME_SOURCE _tx_misra_time_stamp_get() +#endif +#endif + +/* Time source of the execution profile kit. */ +#ifndef TX_EXECUTION_TIME_SOURCE +#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) TX_PORT_TRICORE_STM0_TIM0 +#endif + +#ifndef TX_TRACE_TIME_MASK +#define TX_TRACE_TIME_MASK 0xFFFFFFFFUL +#endif + + + +/* Define the port specific options for the _tx_build_options variable. This variable indicates + how the ThreadX library was built. */ + +#define TX_PORT_SPECIFIC_BUILD_OPTIONS (0) + + +/* Define the in-line initialization constant so that modules with in-line + initialization capabilities can prevent their initialization from being + a function call. */ + +#ifdef TX_MISRA_ENABLE +#define TX_DISABLE_INLINE +#else +#define TX_INLINE_INITIALIZATION +#endif + + +/* Determine whether or not stack checking is enabled. By default, ThreadX stack checking is + disabled. When the following is defined, ThreadX thread stack checking is enabled. If stack + checking is enabled (TX_ENABLE_STACK_CHECKING is defined), the TX_DISABLE_STACK_FILLING + define is negated, thereby forcing the stack fill which is necessary for the stack checking + logic. */ + +#ifndef TX_MISRA_ENABLE +#ifdef TX_ENABLE_STACK_CHECKING +#undef TX_DISABLE_STACK_FILLING +#endif +#endif + + +/* Define the TX_THREAD control block extensions for this port. The main reason + for the multiple macros is so that backward compatibility can be maintained with + existing ThreadX kernel awareness modules. */ + +#define TX_THREAD_EXTENSION_0 UINT tx_thread_csa; +#define TX_THREAD_EXTENSION_1 +#define TX_THREAD_EXTENSION_2 +#define TX_THREAD_EXTENSION_3 + + + +/* Define the port extensions of the remaining ThreadX objects. */ + +#define TX_BLOCK_POOL_EXTENSION +#define TX_BYTE_POOL_EXTENSION +#define TX_EVENT_FLAGS_GROUP_EXTENSION +#define TX_MUTEX_EXTENSION +#define TX_QUEUE_EXTENSION +#define TX_SEMAPHORE_EXTENSION +#define TX_TIMER_EXTENSION + + +/* Define the user extension field of the thread control block. Nothing + additional is needed for this port so it is defined as white space. */ + +#ifndef TX_THREAD_USER_EXTENSION +#define TX_THREAD_USER_EXTENSION +#endif + + +/* Define the macros for processing extensions in tx_thread_create, tx_thread_delete, + tx_thread_shell_entry, and tx_thread_terminate. */ + + +#define TX_THREAD_CREATE_EXTENSION(thread_ptr) +struct TX_THREAD_STRUCT; +VOID _tx_thread_csa_release(struct TX_THREAD_STRUCT *thread_ptr); +#define TX_THREAD_DELETE_EXTENSION(thread_ptr) _tx_thread_csa_release(thread_ptr); +#define TX_THREAD_COMPLETED_EXTENSION(thread_ptr) +#define TX_THREAD_TERMINATED_EXTENSION(thread_ptr) + + +/* Define the ThreadX object creation extensions for the remaining objects. */ + +#define TX_BLOCK_POOL_CREATE_EXTENSION(pool_ptr) +#define TX_BYTE_POOL_CREATE_EXTENSION(pool_ptr) +#define TX_EVENT_FLAGS_GROUP_CREATE_EXTENSION(group_ptr) +#define TX_MUTEX_CREATE_EXTENSION(mutex_ptr) +#define TX_QUEUE_CREATE_EXTENSION(queue_ptr) +#define TX_SEMAPHORE_CREATE_EXTENSION(semaphore_ptr) +#define TX_TIMER_CREATE_EXTENSION(timer_ptr) + + +/* Define the ThreadX object deletion extensions for the remaining objects. */ + +#define TX_BLOCK_POOL_DELETE_EXTENSION(pool_ptr) +#define TX_BYTE_POOL_DELETE_EXTENSION(pool_ptr) +#define TX_EVENT_FLAGS_GROUP_DELETE_EXTENSION(group_ptr) +#define TX_MUTEX_DELETE_EXTENSION(mutex_ptr) +#define TX_QUEUE_DELETE_EXTENSION(queue_ptr) +#define TX_SEMAPHORE_DELETE_EXTENSION(semaphore_ptr) +#define TX_TIMER_DELETE_EXTENSION(timer_ptr) + + +/* Returns PSW.IS: 1 in interrupt and trap handlers, 0 in threads. */ + +__attribute__( ( always_inline ) ) static inline unsigned int __get_interrupt_state(void) +{ + UINT psw; + psw = __mfcr(TX_PORT_TRICORE_CSFR_PSW); + _isync(); + return (psw >> TX_PORT_TRICORE_PSW_IS_OFF) & 1U; +} + +#ifndef TX_THREAD_GET_SYSTEM_STATE +#ifndef TX_MISRA_ENABLE +#define TX_THREAD_GET_SYSTEM_STATE() (_tx_thread_system_state | __get_interrupt_state()) + + +#else /* TX_MISRA_ENABLE is defined, use MISRA function. */ +ULONG _tx_misra_interrupt_state_get(VOID); +#define TX_THREAD_GET_SYSTEM_STATE() (_tx_thread_system_state | _tx_misra_interrupt_state_get()) +#endif /* TX_MISRA_ENABLE */ +#endif /* TX_THREAD_GET_SYSTEM_STATE */ + + +/* Define the check for whether or not to call the _tx_thread_system_return function. A non-zero value + indicates that _tx_thread_system_return should not be called. This overrides the definition in tx_thread.h: + _tx_thread_system_return checks the interrupt state itself (PSW.IS), so only the preemption state is + checked here. */ + +#ifndef TX_THREAD_SYSTEM_RETURN_CHECK +#define TX_THREAD_SYSTEM_RETURN_CHECK(c) (c) = ((ULONG) _tx_thread_preempt_disable); +#endif + + +/* The switch takes place once no higher-priority interrupt is active. */ + +__attribute__( ( always_inline ) ) static inline void _tx_thread_dispatch_request(void) +{ + TX_PORT_TRICORE_DISPATCH_SRC |= (unsigned int) TX_PORT_TRICORE_SRC_SETR_MSK; + _dsync(); +} + +/* PSW.IS is 1 after reset, and start-up code may keep it. The initialisation runs on the user stack, so + _tx_initialize_kernel_enter clears PSW.IS: traps and interrupts then switch to the interrupt stack, and + TX_THREAD_GET_SYSTEM_STATE does not take the initialisation for an interrupt handler. The clear shall be + inline code of _tx_initialize_kernel_enter, which does not return: the return from a called function + would restore the PSW of its caller. */ +#define TX_PORT_SPECIFIC_PRE_INITIALIZATION __mtcr(TX_PORT_TRICORE_CSFR_PSW, __mfcr(TX_PORT_TRICORE_CSFR_PSW) & ~(1UL << TX_PORT_TRICORE_PSW_IS_OFF)); \ + _isync(); + +/* Define the macro to ensure _tx_thread_preempt_disable is set early in initialization in order to + prevent early scheduling. _tx_thread_schedule clears it before the first thread runs. */ +#define TX_PORT_SPECIFIC_POST_INITIALIZATION _tx_thread_preempt_disable++; + + + + +/* Define the interrupt disable/restore functions. */ + +__attribute__( ( always_inline ) ) static inline unsigned int __get_interrupt_posture(void) +{ + UINT posture; + posture = __mfcr(TX_PORT_TRICORE_CSFR_ICR); + _isync(); + return posture; +} + + +__attribute__( ( always_inline ) ) static inline void __set_ccpn_value(unsigned int ccpn_value) +{ + UINT icr; + icr = __mfcr(TX_PORT_TRICORE_CSFR_ICR); + icr = (icr & ~((UINT) TX_PORT_TRICORE_ICR_CCPN_MSK)) | (ccpn_value & ((UINT) TX_PORT_TRICORE_ICR_CCPN_MSK)); + __mtcr(TX_PORT_TRICORE_CSFR_ICR, icr); + _isync(); +} + +__attribute__( ( always_inline ) ) static inline void __enable_interrupts(void) +{ + _enable(); +} + +__attribute__( ( always_inline ) ) static inline void __restore_interrupt(unsigned int posture) +{ + __mtcr(TX_PORT_TRICORE_CSFR_ICR, posture); + _isync(); +} + +__attribute__( ( always_inline ) ) static inline unsigned int __disable_interrupts(void) +{ + UINT posture; + + posture = __get_interrupt_posture(); + +#ifdef TX_PORT_USE_CCPN + /* TX_DISABLE shall not lower CCPN. */ + if ((posture & TX_PORT_TRICORE_ICR_CCPN_MSK) < TX_PORT_CCPN) + { + __set_ccpn_value(TX_PORT_CCPN); + } +#else + _disable(); +#endif + + return posture; +} + + +/* tx_thread_system_return.c calls this function when TX_DISABLE_INLINE is + defined. */ +__attribute__( ( always_inline ) ) static inline void _tx_thread_system_return_inline(void) +{ + unsigned int interrupt_save; + + /* Thread code switches through the system call, interrupt and trap + handlers (PSW.IS = 1) through the dispatch interrupt. */ + if (__get_interrupt_state() == 0U) + { + interrupt_save = __get_interrupt_posture(); +#ifdef TX_PORT_USE_CCPN + __set_ccpn_value(0); +#else + __enable_interrupts(); +#endif + __syscall(TX_PORT_TRICORE_SYSCALL_ID_SCHEDULE); + __restore_interrupt(interrupt_save); + } + else + { + _tx_thread_dispatch_request(); + } +} + + +#ifndef TX_DISABLE_INLINE + +#define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; +#define TX_DISABLE interrupt_save = __disable_interrupts(); +#define TX_RESTORE __restore_interrupt(interrupt_save); + +/* Redefine _tx_thread_system_return for improved performance. */ + +#define _tx_thread_system_return _tx_thread_system_return_inline + +#else /* TX_DISABLE_INLINE is defined */ + +UINT _tx_thread_interrupt_disable(void); +VOID _tx_thread_interrupt_restore(UINT previous_posture); + +#define TX_INTERRUPT_SAVE_AREA UINT interrupt_save; + +#define TX_DISABLE interrupt_save = _tx_thread_interrupt_disable(); +#define TX_RESTORE _tx_thread_interrupt_restore(interrupt_save); +#endif /* TX_DISABLE_INLINE */ + + + +/* Define the version ID of ThreadX. This may be utilized by the application. */ + +#ifdef TX_THREAD_INIT +CHAR _tx_version_id[] = + "(c) 2024 Microsoft Corp. (c) 2026-present Eclipse ThreadX contributors. * ThreadX TriCore TC1.6.2/GNU Version 6.5.2.202603b *"; +#else +#ifdef TX_MISRA_ENABLE +extern CHAR _tx_version_id[100]; +#else +extern CHAR _tx_version_id[]; +#endif +#endif + + +#endif diff --git a/ports/tricore_tc1_6_2/gnu/readme_threadx.txt b/ports/tricore_tc1_6_2/gnu/readme_threadx.txt new file mode 100755 index 000000000..9dc9b8629 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/readme_threadx.txt @@ -0,0 +1,164 @@ + Eclipse ThreadX for TriCore TC1.6.2 (Infineon AURIX TC3) + + Using the AURIX GCC Tools + + +1. Prerequisites + +The port runs on CPU0 of an AURIX TC3 device and was developed on the AURIX +TC375 Lite Kit (KIT_A2G_TC375_LITE). It requires the AURIX GCC +(tricore-elf-gcc) on PATH and uses no driver library. + + +2. Building the ThreadX Run-time Library + +With CMake from the repository root, run: + + cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/tricore_tc1_6_2.cmake + cmake --build build + +The build produces the library tx.a, which the application links. tx.a does +not contain _tx_initialize_low_level and the timer interrupt, because both +depend on the board; the application provides them (section 4). + +inc/tx_port.h holds the definitions for the ThreadX common sources and the +application, including the settings that tx_user.h or the command line may +override. src/tx_port_tricore.h holds the internal definitions of the port. + + +3. Demonstration System + +In example_build, run: + + ./build_threadx_sample.sh + +or, on Windows: + + build_threadx_sample.bat + +This builds tx.a and sample_threadx.elf for the TC375 Lite Kit from: + + sample_threadx.c samples/demo_threadx.c with the event trace + start (section 8) + tx_initialize_low_level.c low-level initialisation, trap vector table + with the ThreadX system call and timer + interrupt + sample_threadx.ld memory description of CPU0 of the TC375 + +The start-up code is crt0-tc38xx.o of the AURIX GCC. The AURIX GCC has no +TC37x device; -mcpu=tc38xx selects the same TC1.6.2 core and start-up code +that applies to the TC375 unchanged. sample_threadx.ld, given with -T, +replaces the TC38x memory description of the compiler. The start-up code is +located at 0x80000000, the cached address of 0xA0000000, at which the boot +mode header of the board starts CPU0. The build produces no boot mode header. + +The clock system keeps its reset state: the system runs from the back-up +clock of 100 MHz, and the caches stay disabled. CPU1 and CPU2 stay halted. + + +4. System Initialization + +main calls tx_kernel_enter. Interrupts stay disabled from reset until +_tx_thread_schedule starts the first thread. The port clears PSW.IS at the +start of _tx_initialize_kernel_enter (TX_PORT_SPECIFIC_PRE_INITIALIZATION), +so traps and interrupts switch to the interrupt stack. + +_tx_initialize_low_level: + + - sets the first unused memory to __TX_FREE_MEM, which sample_threadx.ld + defines after the CSAs; the remaining data RAM of CPU0 is free for + tx_application_define, + - loads BTV with _tx_trap_table and BIV with __INTTAB_CPU0, the vector + table of sample_threadx.ld; it clears the CPU0 ENDINIT bit for both, + - sets up the ThreadX timer (section 7), + - sets up the dispatch interrupt: TX_PORT_TRICORE_DISPATCH_SRC for CPU0 + with TX_PORT_TRICORE_DISPATCH_PRIORITY, enabled (section 5). + + +5. Thread Scheduling + +ThreadX enters the scheduler through system call +TX_PORT_TRICORE_SYSCALL_ID_SCHEDULE. The class 6 trap entry shall save the +lower context with SVLCX and call _tx_thread_syscall_handler with the trap +identification number. Any other number goes to tx_port_tricore_syscall_hook, +which runs like an interrupt handler; its weak default stops the CPU. + +An interrupt or trap handler that makes another thread ready requests the +dispatch interrupt _tx_thread_dispatch_isr, a software request on the SRC at +TX_PORT_TRICORE_DISPATCH_SRC_ADDRESS (SRC_GPSR00 of the TC3xx, 0xF0038990, by +default) at TX_PORT_TRICORE_DISPATCH_PRIORITY (1 by default). + + +6. Thread Context + +A thread's context is its CSA chain; the port keeps the link to it in +tx_thread_csa (TX_THREAD_EXTENSION_0). The thread stack holds only local +data. A new thread starts at its entry function in supervisor mode with +interrupts enabled. The FPU state is part of the CSAs, so threads use the +FPU without setup. + +CSA budget: a suspended thread holds one CSA per call level plus two; each +active interrupt or trap holds two plus one per call level. ThreadX stack +checking does not cover the CSAs. The CSA area of CPU0 (__CSA_SIZE, 16 KiB, +in sample_threadx.ld) shall hold the chains of all threads plus the deepest +interrupt nesting, up to LCX as set by the start-up code. If the CSAs for a +new thread would reach LCX, tx_thread_create or tx_thread_reset raises FCD. + + +7. Timer and Interrupt Handling + +The ThreadX timer uses STM0 compare 0 with TX_TIMER_TICKS_PER_SECOND (1000 +by default) ticks per second. The timer interrupt has the priority +TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY (2 by default). If STM has passed +the next compare value, for example after a debugger halt, the ticks in +between are lost. + +TX_DISABLE clears ICR.IE by default. With TX_PORT_USE_CCPN defined, it +raises ICR.CCPN to TX_PORT_CCPN (31 by default) instead and never lowers it; +interrupts above TX_PORT_CCPN stay enabled in ThreadX critical sections and +shall not call ThreadX services. TX_RESTORE restores the previous ICR. + +An ISR that calls ThreadX services is a plain interrupt handler on CPU0 with +a priority above TX_PORT_TRICORE_DISPATCH_PRIORITY and, with +TX_PORT_USE_CCPN, not above TX_PORT_CCPN. _tx_thread_context_save and +_tx_thread_context_restore have no effect on this port. +TX_PORT_TRICORE_INTERRUPT(isr, priority) in tx_port.h defines such a handler +and places its vector table entry in the section .intvec_tc0_. +The linker script shall locate this section at BIV + 32 * priority; +sample_threadx.ld does so for the priorities 1 to 15. + +Interrupts and traps taken from a thread switch to the CPU0 interrupt stack +(__ISTACK_SIZE, 4 KiB, in sample_threadx.ld). It holds the local data of all +nested handlers, including the scheduler's idle wait, so thread stacks need +no interrupt reserve. + + +8. Event Trace + +With TX_ENABLE_EVENT_TRACE, the application calls tx_trace_enable with its +trace buffer, at the earliest at the start of tx_application_define, because +kernel initialisation resets the trace. The time stamp is the lower word of +STM0 (TX_TRACE_TIME_SOURCE in tx_port.h). + + +9. Execution Profile and Low Power + +For TX_EXECUTION_PROFILE_ENABLE and TX_LOW_POWER the port implements only the +callouts. The regression tests show only that the callouts do not disturb +the kernel. TX_LOW_POWER_TIMER_SETUP, TX_LOW_POWER_TICKLESS and +TX_LOW_POWER_USER_* are not defined. + + +10. Improving Performance + +The build scripts and cmake/tricore_tc1_6_2.cmake compile with -O0 -g3 for +debugging. The regression test also passes with -O2. TX_DISABLE_ERROR_CHECKING +removes the ThreadX API error checking. + + +11. Revision History + +For generic code revision information, refer to readme_threadx_generic.txt. +The following details the revision information of this port: + +Initial ThreadX version 6.5.2 for TriCore TC1.6.2 using AURIX GCC tools. diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_port_tricore.h b/ports/tricore_tc1_6_2/gnu/src/tx_port_tricore.h new file mode 100644 index 000000000..ff0a8e7c2 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_port_tricore.h @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/* Definitions shared by the sources of the TriCore port. Neither the ThreadX + common sources nor the application include this file. */ + +#ifndef TX_PORT_TRICORE_H +#define TX_PORT_TRICORE_H + + +/* TriCore core registers. */ + +#define TX_PORT_TRICORE_CSFR_PCXI 0xFE00 +#define TX_PORT_TRICORE_CSFR_FCX 0xFE38 +#define TX_PORT_TRICORE_CSFR_LCX 0xFE3C + +#define TX_PORT_TRICORE_PSW_CDC_MSK 0x7FUL /* Call depth counter, bits 6:0 */ +#define TX_PORT_TRICORE_PSW_CDE_OFF 7 /* Call depth count enable */ +#define TX_PORT_TRICORE_PSW_IO_OFF 10 /* I/O privilege level */ +#define TX_PORT_TRICORE_PCXI_UL_OFF 20 /* 1: link to an upper context */ +#define TX_PORT_TRICORE_PCXI_PIE_OFF 21 /* Previous interrupt enable */ + + +/* Context save areas (CSAs). A link word holds the segment of a CSA in bits + 19:16 and its offset, divided by 64, in bits 15:0. */ + +#define TX_PORT_TRICORE_CSA_SIZE 64 + +#define TX_PORT_TRICORE_CSA_LINK_SEGMENT_OFF 16 +#define TX_PORT_TRICORE_CSA_LINK_SEGMENT_MASK 0x000F0000UL +#define TX_PORT_TRICORE_CSA_LINK_OFFSET_MASK 0x0000FFFFUL +#define TX_PORT_TRICORE_CSA_LINK_MASK (TX_PORT_TRICORE_CSA_LINK_SEGMENT_MASK | TX_PORT_TRICORE_CSA_LINK_OFFSET_MASK) + +/* Bit positions of the segment and of the offset in the address of a CSA. */ +#define TX_PORT_TRICORE_CSA_ADDRESS_SEGMENT_OFF 28 +#define TX_PORT_TRICORE_CSA_ADDRESS_OFFSET_OFF 6 + +/* Word indices within a CSA. */ +#define TX_PORT_TRICORE_CSA_PCXI_LINK_WORD 0 +#define TX_PORT_TRICORE_CSA_LOWER_CONTEXT_A11_RA 1 + +#define TX_PORT_TRICORE_CSA_UPPER_CONTEXT_PCXI_LINK_WORD 0 +#define TX_PORT_TRICORE_CSA_UPPER_CONTEXT_PSW 1 +#define TX_PORT_TRICORE_CSA_UPPER_CONTEXT_A10_STACK_PTR 2 +#define TX_PORT_TRICORE_CSA_UPPER_CONTEXT_A11_RA 3 + +/* Initial context of a thread. */ +#define TX_PORT_TRICORE_PSW_IO_SUPERVISOR 2UL + +/* Supervisor mode, protection register set 0. PSW.CDC = 0x7F disables call + depth counting. */ +#define TX_PORT_TRICORE_CSA_INITIAL_SYSTEM_PSW ((TX_PORT_TRICORE_PSW_IO_SUPERVISOR << TX_PORT_TRICORE_PSW_IO_OFF) | \ + (1UL << TX_PORT_TRICORE_PSW_CDE_OFF) | \ + TX_PORT_TRICORE_PSW_CDC_MSK) +/* PCXI.UL = 1: links to an upper context. */ +#define TX_PORT_TRICORE_CSA_INITIAL_LOWER_PCXI ((1UL << TX_PORT_TRICORE_PCXI_UL_OFF) | (1UL << TX_PORT_TRICORE_PCXI_PIE_OFF)) +#define TX_PORT_TRICORE_CSA_INITIAL_UPPER_PCXI (1UL << TX_PORT_TRICORE_PCXI_PIE_OFF) + +#define TX_PORT_TRICORE_STACK_ALIGNMENT 8U + +#define TX_PORT_TRICORE_CSA_LINK_WORD_END_OF_CHAIN 0U + + +/* CSA links from _tx_thread_csa_save and _tx_thread_csa_restore back to the + lower context of the interrupted thread. */ + +#define TX_PORT_TRICORE_SYSCALL_CALL_DEPTH 3 +#define TX_PORT_TRICORE_DISPATCH_CALL_DEPTH 2 + + +#ifndef __ASSEMBLER__ + +#include "tx_api.h" + +UINT * _tx_thread_decode_link_word(UINT link_word); + +#endif /* __ASSEMBLER__ */ + +#endif /* TX_PORT_TRICORE_H */ diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_thread_context_restore.c b/ports/tricore_tc1_6_2/gnu/src/tx_thread_context_restore.c new file mode 100755 index 000000000..0e7a45ce5 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_thread_context_restore.c @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Thread */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_thread.h" +#include "tx_timer.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_context_restore TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function has no effect on this port. The dispatch interrupt */ +/* switches threads, so an ISR need not call this function. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* ISRs Interrupt Service Routines */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 11-04-2026 Andreas Neubauer Initial Version 6.5.2 */ +/* */ +/**************************************************************************/ +VOID _tx_thread_context_restore(VOID) +{ +} diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_thread_context_save.c b/ports/tricore_tc1_6_2/gnu/src/tx_thread_context_save.c new file mode 100755 index 000000000..37cb0ab8e --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_thread_context_save.c @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Thread */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_thread.h" +#include "tx_timer.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_context_save TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function has no effect on this port. The dispatch interrupt */ +/* switches threads, so an ISR need not call this function. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* ISRs */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 11-04-2026 Andreas Neubauer Initial Version 6.5.2 */ +/* */ +/**************************************************************************/ +VOID _tx_thread_context_save(VOID) +{ +} diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_thread_interrupt_control.c b/ports/tricore_tc1_6_2/gnu/src/tx_thread_interrupt_control.c new file mode 100755 index 000000000..e32161d58 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_thread_interrupt_control.c @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Thread */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_thread.h" + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_interrupt_control TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function is responsible for changing the interrupt lockout */ +/* posture of the system. */ +/* */ +/* INPUT */ +/* */ +/* new_posture New interrupt lockout posture */ +/* */ +/* OUTPUT */ +/* */ +/* old_posture Old interrupt lockout posture */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 11-04-2026 Andreas Neubauer Initial Version 6.5.2 */ +/* */ +/**************************************************************************/ +UINT _tx_thread_interrupt_control(UINT new_posture) +{ + + UINT icr; + + icr = __get_interrupt_posture(); + __restore_interrupt((icr & ~((UINT) TX_INT_ENABLE)) | (new_posture & ((UINT) TX_INT_ENABLE))); + + return(icr & ((UINT) TX_INT_ENABLE)); +} + + +#ifdef TX_DISABLE_INLINE +UINT _tx_thread_interrupt_disable(VOID) +{ + return(__disable_interrupts()); +} + + +VOID _tx_thread_interrupt_restore(UINT previous_posture) +{ + __restore_interrupt(previous_posture); +} +#endif + + +#ifdef TX_MISRA_ENABLE +ULONG _tx_misra_interrupt_state_get(VOID) +{ + return((ULONG) __get_interrupt_state()); +} +#endif + diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_thread_schedule.c b/ports/tricore_tc1_6_2/gnu/src/tx_thread_schedule.c new file mode 100755 index 000000000..9b52f431b --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_thread_schedule.c @@ -0,0 +1,284 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Thread */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_thread.h" +#include "tx_timer.h" +#include "tx_port_tricore.h" + + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) +VOID _tx_execution_thread_enter(VOID); +VOID _tx_execution_thread_exit(VOID); +#endif + +#ifdef TX_LOW_POWER +VOID tx_low_power_enter(VOID); +VOID tx_low_power_exit(VOID); +#endif + + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_schedule TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function starts the first thread. It clears */ +/* _tx_thread_preempt_disable, which is set during initialisation by */ +/* TX_PORT_SPECIFIC_POST_INITIALIZATION, enables interrupts and enters */ +/* the scheduler through the system call. The scheduler waits until */ +/* _tx_thread_execute_ptr holds a thread and switches to it. A timer */ +/* interrupt that is already pending can start the first thread */ +/* through the dispatch interrupt before the system call is reached. */ +/* This function does not return. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_thread_syscall_handler Through the system call */ +/* */ +/* CALLED BY */ +/* */ +/* _tx_initialize_kernel_enter ThreadX entry function */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 11-04-2026 Andreas Neubauer Initial Version 6.5.2 */ +/* */ +/**************************************************************************/ + + + +VOID _tx_thread_schedule(VOID) +{ + + /* _tx_initialize_low_level has set up the timer and the dispatch + interrupt. A timer interrupt that is already pending runs as soon as + interrupts are enabled; a thread it makes ready starts through the + dispatch interrupt, and the system call below is not reached. */ + _tx_thread_preempt_disable = 0; + _enable(); + + __syscall(TX_PORT_TRICORE_SYSCALL_ID_SCHEDULE); + while(TX_TRUE) + { + + } + +} + + +UINT * _tx_thread_decode_link_word( UINT link_word ) +{ + UINT linked_context; + + linked_context = ((link_word & TX_PORT_TRICORE_CSA_LINK_SEGMENT_MASK) << (TX_PORT_TRICORE_CSA_ADDRESS_SEGMENT_OFF - TX_PORT_TRICORE_CSA_LINK_SEGMENT_OFF)) | + ((link_word & TX_PORT_TRICORE_CSA_LINK_OFFSET_MASK) << TX_PORT_TRICORE_CSA_ADDRESS_OFFSET_OFF); + return ( UINT * ) linked_context; +} + + + + +/* Each of the following functions shall be a call of its own: call_depth counts + the CSA frames that the calls create. */ + +static VOID __attribute__( ( noinline ) ) _tx_thread_csa_save(UINT call_depth) +{ + UINT * csa_ptr; + UINT * lower_csa_ptr; + UINT * upper_csa_ptr; + UINT lower_csa; + + _dsync(); + csa_ptr = _tx_thread_decode_link_word(__mfcr(TX_PORT_TRICORE_CSFR_PCXI)); + + for (UINT i = 0U; i < (call_depth - 1U); i++) + { + csa_ptr = _tx_thread_decode_link_word(csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD]); + } + + lower_csa = csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD]; + lower_csa_ptr = _tx_thread_decode_link_word(lower_csa); + upper_csa_ptr = _tx_thread_decode_link_word(lower_csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD]); + + _tx_thread_current_ptr->tx_thread_stack_ptr = (VOID *) upper_csa_ptr[TX_PORT_TRICORE_CSA_UPPER_CONTEXT_A10_STACK_PTR]; + _tx_thread_current_ptr->tx_thread_csa = lower_csa; +} + + +static VOID __attribute__( ( noinline ) ) _tx_thread_csa_restore(UINT call_depth) +{ + UINT * csa_ptr; + + _dsync(); + csa_ptr = _tx_thread_decode_link_word(__mfcr(TX_PORT_TRICORE_CSFR_PCXI)); + + for (UINT i = 0U; i < (call_depth - 1U); i++) + { + csa_ptr = _tx_thread_decode_link_word(csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD]); + } + + csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] = _tx_thread_current_ptr->tx_thread_csa; +} + + +static VOID __attribute__( ( noinline ) ) _tx_ts_handler(UINT call_depth) +{ + + TX_THREAD *current_thread = _tx_thread_current_ptr; + TX_THREAD *next_thread; + + if (current_thread != TX_NULL) + { + if (_tx_timer_time_slice != 0U) + { + current_thread->tx_thread_time_slice = _tx_timer_time_slice; + _tx_timer_time_slice = 0; + } + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) + _disable(); + _tx_execution_thread_exit(); + _enable(); +#endif + + _tx_thread_csa_save(call_depth); + _tx_thread_current_ptr = TX_NULL; + } + + /* Increment the nested interrupt condition. */ + _tx_thread_system_state++; + + + /* Idle loop. ICR.CCPN blocks the dispatch interrupt here, so the loop + masks interrupts through ICR.IE. */ + while (TX_TRUE) + { + _disable(); + _nop(); + next_thread = _tx_thread_execute_ptr; + if (next_thread != TX_NULL) + { + _tx_thread_current_ptr = next_thread; + break; + } +#ifdef TX_LOW_POWER + tx_low_power_enter(); + tx_low_power_exit(); +#endif + _enable(); + _nop(); + } + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) + _tx_execution_thread_enter(); +#endif + + /* Interrupts stay disabled until the return to next_thread, so the switch + to next_thread satisfies every pending dispatch request. */ + TX_PORT_TRICORE_DISPATCH_SRC |= (unsigned int) TX_PORT_TRICORE_SRC_CLRR_MSK; + + next_thread->tx_thread_run_count++; + _tx_timer_time_slice = next_thread->tx_thread_time_slice; + + _tx_thread_system_state--; + + /* The CSA chain of the interrupted thread is still linked. */ + if (current_thread != next_thread) + { + _tx_thread_csa_restore(call_depth); + } + + return; +} + + + +/* An unsupported system call number is an error. */ +VOID __attribute__( ( weak ) ) tx_port_tricore_syscall_hook(UINT id) +{ + (VOID) id; + + _disable(); + _debug(); + while (TX_TRUE) + { + } +} + + +VOID _tx_thread_syscall_handler(UCHAR id ) +{ + switch(id) + { + case TX_PORT_TRICORE_SYSCALL_ID_SCHEDULE: + /* The dispatch interrupt shall not interrupt the scheduler. RFE + restores the CCPN of the thread that the trap returns to. */ + __set_ccpn_value(TX_PORT_TRICORE_DISPATCH_PRIORITY); + + _tx_ts_handler(TX_PORT_TRICORE_SYSCALL_CALL_DEPTH); + break; + + default: + tx_port_tricore_syscall_hook((UINT) id); + break; + } +} + + + +TX_PORT_TRICORE_INTERRUPT(_tx_thread_dispatch_isr, TX_PORT_TRICORE_DISPATCH_PRIORITY) +{ + /* A thread that has disabled preemption keeps the CPU. It enters the + scheduler through the system call once it enables preemption again. */ + if (_tx_thread_preempt_disable == 0U) + { + _tx_ts_handler(TX_PORT_TRICORE_DISPATCH_CALL_DEPTH); + } +} diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_thread_stack_build.c b/ports/tricore_tc1_6_2/gnu/src/tx_thread_stack_build.c new file mode 100755 index 000000000..333007cbc --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_thread_stack_build.c @@ -0,0 +1,193 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Thread */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_thread.h" + +#include "tx_port_tricore.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_stack_build TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function builds the initial context of a thread. It takes two */ +/* CSAs from the free context list: a lower context and an upper */ +/* context. The thread starts at function_ptr when the scheduler */ +/* first restores its context. */ +/* */ +/* A CSA chain that the thread still holds, as after tx_thread_reset, */ +/* is released first. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Pointer to thread control blk */ +/* function_ptr Function the thread starts at */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_thread_csa_release Release CSA chain of thread */ +/* _tx_thread_decode_link_word Convert link word to address */ +/* TX_MEMSET Clear CSA */ +/* */ +/* CALLED BY */ +/* */ +/* _tx_thread_create Create thread service */ +/* _tx_thread_reset Reset thread service */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 11-04-2026 Andreas Neubauer Initial Version 6.5.2 */ +/* */ +/**************************************************************************/ +VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID)) +{ + + TX_INTERRUPT_SAVE_AREA + UINT first_csa_pcxi_link_word = 0; + UINT second_csa_pcxi_link_word = 0; + UINT lcx_link_word; + UINT * first_csa_ptr = TX_NULL; + UINT * second_csa_ptr = TX_NULL; + UINT * thread_stack_ptr = (UINT *)((UINT)thread_ptr->tx_thread_stack_end & ~(TX_PORT_TRICORE_STACK_ALIGNMENT - 1U)); + + + /* tx_thread_reset rebuilds a thread that still holds its CSA chain. */ + _tx_thread_csa_release(thread_ptr); + + TX_DISABLE + + _dsync(); + + /* The CSA that LCX points to and the CSAs after it are the reserve of + the free context list depletion trap (FCD). The thread shall not + receive one of them. */ + lcx_link_word = __mfcr(TX_PORT_TRICORE_CSFR_LCX) & TX_PORT_TRICORE_CSA_LINK_MASK; + + /* Get first free Context Save Area. */ + first_csa_pcxi_link_word = __mfcr(TX_PORT_TRICORE_CSFR_FCX) & TX_PORT_TRICORE_CSA_LINK_MASK; + first_csa_ptr = _tx_thread_decode_link_word(first_csa_pcxi_link_word); + + if( first_csa_ptr != TX_NULL ) + { + /* Get second free Context Save Area. */ + second_csa_pcxi_link_word = first_csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] & TX_PORT_TRICORE_CSA_LINK_MASK; + second_csa_ptr = _tx_thread_decode_link_word(second_csa_pcxi_link_word); + } + + if( ( second_csa_ptr != TX_NULL ) && ( second_csa_pcxi_link_word != lcx_link_word ) ) + { + /* Remove the two CSAs from the free CSA list by setting FCX to the + link word of the second CSA. */ + __mtcr(TX_PORT_TRICORE_CSFR_FCX, second_csa_ptr[ TX_PORT_TRICORE_CSA_PCXI_LINK_WORD ] & TX_PORT_TRICORE_CSA_LINK_MASK); + _isync(); + } + else + { + + /* The first SVLCX takes the first CSA. The second SVLCX takes the + CSA that LCX points to and raises FCD, or raises FCU if the list + ends at the first CSA. */ + _svlcx(); + _svlcx(); + while (TX_TRUE) + { + + } + } + + TX_RESTORE + + /* Initialise the first CSA as lower context. */ + TX_MEMSET(first_csa_ptr, 0, TX_PORT_TRICORE_CSA_SIZE); + first_csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] = TX_PORT_TRICORE_CSA_INITIAL_LOWER_PCXI | + second_csa_pcxi_link_word; + first_csa_ptr[TX_PORT_TRICORE_CSA_LOWER_CONTEXT_A11_RA] = ( UINT ) function_ptr; + + /* Initialise the second CSA as upper context. */ + TX_MEMSET(second_csa_ptr, 0, TX_PORT_TRICORE_CSA_SIZE); + second_csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] = TX_PORT_TRICORE_CSA_INITIAL_UPPER_PCXI | + TX_PORT_TRICORE_CSA_LINK_WORD_END_OF_CHAIN; + second_csa_ptr[TX_PORT_TRICORE_CSA_UPPER_CONTEXT_A10_STACK_PTR] = ( UINT ) thread_stack_ptr; + second_csa_ptr[TX_PORT_TRICORE_CSA_UPPER_CONTEXT_PSW] = TX_PORT_TRICORE_CSA_INITIAL_SYSTEM_PSW; + + thread_ptr->tx_thread_csa = first_csa_pcxi_link_word; + + /* Setup a thread stack pointer. */ + thread_ptr -> tx_thread_stack_ptr = thread_stack_ptr; + +} + + +/* Returns the CSA chain of a completed or terminated thread to the free + context list. The last CSA of the chain links to no CSA. */ +VOID _tx_thread_csa_release(TX_THREAD *thread_ptr) +{ + + TX_INTERRUPT_SAVE_AREA + UINT head_csa_link_word; + UINT * csa_ptr; + + head_csa_link_word = thread_ptr -> tx_thread_csa & TX_PORT_TRICORE_CSA_LINK_MASK; + + if (head_csa_link_word != 0U) + { + /* A free CSA links by its address only. */ + csa_ptr = _tx_thread_decode_link_word(head_csa_link_word); + while ((csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] & TX_PORT_TRICORE_CSA_LINK_MASK) != TX_PORT_TRICORE_CSA_LINK_WORD_END_OF_CHAIN) + { + csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] &= TX_PORT_TRICORE_CSA_LINK_MASK; + csa_ptr = _tx_thread_decode_link_word(csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD]); + } + + TX_DISABLE + _dsync(); + csa_ptr[TX_PORT_TRICORE_CSA_PCXI_LINK_WORD] = __mfcr(TX_PORT_TRICORE_CSFR_FCX); + __mtcr(TX_PORT_TRICORE_CSFR_FCX, head_csa_link_word); + _isync(); + TX_RESTORE + + thread_ptr -> tx_thread_csa = 0; + } +} diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_thread_system_return.c b/ports/tricore_tc1_6_2/gnu/src/tx_thread_system_return.c new file mode 100755 index 000000000..b34045b11 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_thread_system_return.c @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Thread */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_thread.h" +#include "tx_timer.h" + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_system_return TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function transfers control from a thread back to the */ +/* scheduler. Thread code enters the scheduler through the system */ +/* call. Interrupt and trap handlers (PSW.IS = 1) request the */ +/* dispatch interrupt instead. The function is compiled only with */ +/* TX_DISABLE_INLINE; otherwise tx_port.h maps it to */ +/* _tx_thread_system_return_inline. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_thread_system_return_inline System return (inline) */ +/* */ +/* CALLED BY */ +/* */ +/* ThreadX components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 11-04-2026 Andreas Neubauer Initial Version 6.5.2 */ +/* */ +/**************************************************************************/ + +#ifdef TX_DISABLE_INLINE +VOID _tx_thread_system_return(VOID) +{ + _tx_thread_system_return_inline(); +} +#endif + diff --git a/ports/tricore_tc1_6_2/gnu/src/tx_timer_interrupt.c b/ports/tricore_tc1_6_2/gnu/src/tx_timer_interrupt.c new file mode 100755 index 000000000..d456f24c5 --- /dev/null +++ b/ports/tricore_tc1_6_2/gnu/src/tx_timer_interrupt.c @@ -0,0 +1,158 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** ThreadX Component */ +/** */ +/** Timer */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#define TX_SOURCE_CODE + + +/* Include necessary system files. */ + +#include "tx_api.h" +#include "tx_timer.h" +#include "tx_thread.h" + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_timer_interrupt TriCore/GNU */ +/* 6.5.2 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* Andreas Neubauer, safecubed GmbH */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function processes one ThreadX timer tick. This processing */ +/* includes incrementing the system clock and checking for time slice */ +/* and/or timer expiration. If either is found, the expiration */ +/* functions are called. The timer interrupt handler of the board */ +/* calls it once the timer hardware has been serviced. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_timer_expiration_process */ +/* _tx_thread_time_slice */ +/* */ +/* CALLED BY */ +/* */ +/* timer interrupt handler */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* 11-04-2026 Andreas Neubauer Adapted for TriCore, */ +/* resulting in version 6.5.2 */ +/* */ +/**************************************************************************/ +VOID _tx_timer_interrupt(VOID) +{ + + /* Increment the system clock. */ + _tx_timer_system_clock++; + + /* Test for time-slice expiration. */ + if (_tx_timer_time_slice != 0U) + { + + /* Decrement the time_slice. */ + _tx_timer_time_slice--; + + /* Check for expiration. */ + if (_tx_timer_time_slice == 0U) + { + + /* Set the time-slice expired flag. */ + _tx_timer_expired_time_slice = TX_TRUE; + } + } + + /* Test for timer expiration. */ + if (*_tx_timer_current_ptr != TX_NULL) + { + + /* Set expiration flag. */ + _tx_timer_expired = TX_TRUE; + } + else + { + + /* No timer expired, increment the timer pointer. */ + _tx_timer_current_ptr++; + + /* Check for wrap-around. */ + if (_tx_timer_current_ptr == _tx_timer_list_end) + { + + /* Wrap to beginning of list. */ + _tx_timer_current_ptr = _tx_timer_list_start; + } + } + + /* See if anything has expired. */ + if ((_tx_timer_expired_time_slice != TX_FALSE) || (_tx_timer_expired != TX_FALSE)) + { + + /* Did a timer expire? */ + if (_tx_timer_expired != TX_FALSE) + { + + /* Process timer expiration. */ + _tx_timer_expiration_process(); + } + + /* Did time slice expire? */ + if (_tx_timer_expired_time_slice != TX_FALSE) + { + + /* Time slice interrupted thread. */ + _tx_thread_time_slice(); + + /* _tx_thread_time_slice selects the next thread without a + system return. */ + if ((_tx_thread_preempt_disable == 0U) && + (_tx_thread_current_ptr != _tx_thread_execute_ptr)) + { + _tx_thread_dispatch_request(); + } + } + } + + +} + + + diff --git a/test/tx/cmake/tricore_tc1_6_2/.gitignore b/test/tx/cmake/tricore_tc1_6_2/.gitignore new file mode 100644 index 000000000..9ab2398c7 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/.gitignore @@ -0,0 +1,2 @@ +build/ +logs/ diff --git a/test/tx/cmake/tricore_tc1_6_2/CMakeLists.txt b/test/tx/cmake/tricore_tc1_6_2/CMakeLists.txt new file mode 100644 index 000000000..64ca62116 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/CMakeLists.txt @@ -0,0 +1,97 @@ +############################################################################## +# Copyright (c) 2026 safecubed GmbH +# Copyright (c) 2026 Eclipse ThreadX contributors +# +# This program and the accompanying materials are made available under the +# terms of the MIT License which is available at +# https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: MIT +############################################################################## + +# Portions of this file were generated with AI assistance. + +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) +cmake_policy(SET CMP0054 NEW) +cmake_policy(SET CMP0057 NEW) + +# ThreadX regression test for the TriCore TC1.6.2 port on the TC375 Lite Kit. +# All tests run in one image, regression.elf, which a debugger programs into +# the board. The test output goes to the UART of the board. See README.md. + +project(threadx_tricore_tc1_6_2_test LANGUAGES C) + +# Set build configurations +set(BUILD_CONFIGURATIONS default_build disable_notify_callbacks_build + stack_checking_build stack_checking_rand_fill_build + trace_build misra_build misra_trace_build + disable_inline_build port_use_ccpn_build + timer_process_in_isr_build not_interruptable_build + execution_profile_build low_power_build) +set(CMAKE_CONFIGURATION_TYPES + ${BUILD_CONFIGURATIONS} + CACHE STRING "list of supported configuration types" FORCE) +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + ${CMAKE_CONFIGURATION_TYPES}) +list(GET CMAKE_CONFIGURATION_TYPES 0 BUILD_TYPE) +if((NOT CMAKE_BUILD_TYPE) OR (NOT ("${CMAKE_BUILD_TYPE}" IN_LIST + CMAKE_CONFIGURATION_TYPES))) + set(CMAKE_BUILD_TYPE + "${BUILD_TYPE}" + CACHE STRING "Build Type of the project" FORCE) +endif() + +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") +message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") +message(STATUS "THREADX_ARCH: ${THREADX_ARCH}") + +# The configurations of test/tx/cmake/CMakeLists.txt. +set(default_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32) +set(disable_notify_callbacks_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_DISABLE_NOTIFY_CALLBACKS) +set(stack_checking_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_ENABLE_STACK_CHECKING) +set(stack_checking_rand_fill_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_ENABLE_STACK_CHECKING -DTX_ENABLE_RANDOM_NUMBER_STACK_FILLING) +set(trace_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_ENABLE_EVENT_TRACE) +set(misra_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_MISRA_ENABLE) +set(misra_trace_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_MISRA_ENABLE -DTX_ENABLE_EVENT_TRACE) + +# Options with code of their own in the port. +set(disable_inline_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_DISABLE_INLINE) +set(port_use_ccpn_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_PORT_USE_CCPN) +set(timer_process_in_isr_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_TIMER_PROCESS_IN_ISR) +set(not_interruptable_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_NOT_INTERRUPTABLE) +set(execution_profile_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_EXECUTION_PROFILE_ENABLE) +set(low_power_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_LOW_POWER) + +add_compile_options( + -O0 + -g3 + -fdiagnostics-color + -DTX_REGRESSION_TEST + -DTEST_STACK_SIZE_PRINTF=4096 + -DEXTERNAL_EXIT + ${${CMAKE_BUILD_TYPE}} +) + +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../.. threadx) +add_subdirectory(bsp) +add_subdirectory(regression) + +target_compile_options( + threadx + PRIVATE -Werror + -Wall + -Wextra + -fmessage-length=0 +) + +# tx_api.h includes tx_execution_profile.h when the option is set. +if("-DTX_EXECUTION_PROFILE_ENABLE" IN_LIST ${CMAKE_BUILD_TYPE}) + target_include_directories(threadx PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/../../../../utility/execution_profile_kit) +endif() + +# With TX_NOT_INTERRUPTABLE, the cleanup functions of the common sources do +# not use their suspension_sequence parameter. +if("-DTX_NOT_INTERRUPTABLE" IN_LIST ${CMAKE_BUILD_TYPE}) + target_compile_options(threadx PRIVATE -Wno-unused-parameter) +endif() diff --git a/test/tx/cmake/tricore_tc1_6_2/README.md b/test/tx/cmake/tricore_tc1_6_2/README.md new file mode 100644 index 000000000..696696823 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/README.md @@ -0,0 +1,123 @@ +# ThreadX regression test on the TriCore TC1.6.2 port + +This directory builds the ThreadX regression suite in `test/tx/regression` for +the AURIX TC375 Lite Kit. All tests run in one image: `testcontrol.c` is built +without `CTEST`, so its control thread runs every test in `test_control_tests[]` +one after the other. The test output goes to the UART of the Lite Kit. + +## Requirements + +- AURIX TC375 Lite Kit (TC375TP) +- AURIX GCC with `tricore-elf-gcc` on `PATH` (see [Compiler](#compiler)) +- CMake 3.13 or later and Ninja +- A terminal on the virtual COM port of the Lite Kit: 115200 baud + +## Compiler + +The tests ran with the following AURIX GCC for Linux x86-64: + +| Item | Version | +|--------------|------------------------------------------------------------| +| Package | AURIX GCC 03_2026 (`aurixgcc_03-2026_Linux_x86-x64`) | +| GCC | 11.3.1 20221230 (AURIX(tm) GCC - Built 2026-03-19 10:12:22) | +| Binutils | 2.40.50.20230607 | +| C library | newlib 4.2.0 | +| Start-up code| `lib/gcc/tricore-elf/11.3.1/crt0-tc38xx.o` | + +Infineon provides the AURIX GCC for download at +. +`tricore-elf-gcc --version` prints the GCC version and the build date of the +installed package. The download also offers a Windows package; `run.bat` +builds with it, but the tests ran only with the Linux package. + +## Build + +```bash +./run.sh build # default_build +./run.sh build trace_build # one or more configurations +./run.sh build all # every configuration +``` + +On Windows, `run.bat` takes the same arguments: + +```bat +run.bat build +run.bat build trace_build +run.bat build all +``` + +The configurations are those of `test/tx/cmake/CMakeLists.txt`: +`default_build`, `disable_notify_callbacks_build`, `stack_checking_build`, +`stack_checking_rand_fill_build`, `trace_build`, `misra_build` and +`misra_trace_build`. Six more configurations each set one option that has +code of its own in the port: `disable_inline_build` (`TX_DISABLE_INLINE`), +`port_use_ccpn_build` (`TX_PORT_USE_CCPN`), `timer_process_in_isr_build` +(`TX_TIMER_PROCESS_IN_ISR`), `not_interruptable_build` +(`TX_NOT_INTERRUPTABLE`), `execution_profile_build` +(`TX_EXECUTION_PROFILE_ENABLE`, with `utility/execution_profile_kit`) and +`low_power_build` (`TX_LOW_POWER`, with `utility/low_power`). Each one +builds into `build//regression/`: +`regression.elf`, `regression.map` and `regression.hex`. + +For `TX_EXECUTION_PROFILE_ENABLE` and `TX_LOW_POWER`, the port implements only +the callouts, and the regression test does not test their function. In +`execution_profile_build`, the scheduler calls `_tx_execution_thread_enter()` +and `_tx_execution_thread_exit()`, and the timer interrupt calls +`_tx_execution_isr_enter()` and `_tx_execution_isr_exit()`. No test reads +the measured times. In `low_power_build`, the idle loop of the scheduler calls +`tx_low_power_enter()` and `tx_low_power_exit()`. The build defines none of +the `TX_LOW_POWER_TIMER_SETUP`, `TX_LOW_POWER_TICKLESS` and +`TX_LOW_POWER_USER_*` macros, so the CPU does not enter a low-power mode and +no timer ticks are adjusted. Both configurations show only that the callouts +do not disturb the kernel. + +## Board support + +The test runs on the example of the port in +`ports/tricore_tc1_6_2/gnu/example_build`, without a driver library. The +start-up code is `crt0-tc38xx.o` of the compiler, and the system runs from +the back-up clock of 100 MHz. `bsp/` adds: + +- `tx_initialize_low_level.c`, a copy of the example's file whose timer + interrupt calls `test_interrupt_dispatch()` before + `_tx_timer_interrupt()`, as `test/tx/cmake` does for the Linux port. It + also offsets each timer compare by a pseudo-random 0 to 255 STM ticks. + Without the offset, the timer can stay in phase with a test loop that + waits for the interrupt, and the test never ends. +- `main.c` replaces `main()` of the example's `sample_threadx.c`, which the + test does not build. It clears the test memory, initialises ASCLIN0 + (P14.0, 115200 baud from the fast ASCLIN clock of 100 MHz), sends `printf` + output to it through `write()`, provides `external_exit()` and starts the + test control. +- `regression.ld`, given with `-T` after the example's `sample_threadx.ld`, + places the section `.bss_cpu1` in DSPR1. + +The build further changes the regression suite: + +- `testcontrol.c` is compiled with `EXTERNAL_EXIT` and with `main` renamed to + `tx_regression_main`. `regression/CMakeLists.txt` sets + `TEST_CONTROL_MEMORY_SIZE` to 0x6000 bytes and `TESTS_MEMORY_SIZE` to + 0x1C000 bytes, and `TEST_MEMORY_PLACEMENT` places both arrays in DSPR1 + (`.bss_cpu1` of `bsp/regression.ld`). The default of 0x60000 bytes each + does not fit the RAM of the TC375. The largest test uses about 94 KiB. +- `threadx_initialize_kernel_setup_test.c` is not built. It has its own `main` + and is not part of `test_control_tests[]`. + +The CSA area of CPU0 (`__CSA_SIZE`, 16 KiB, in `sample_threadx.ld`) holds +the CSA chains of the 25 threads of the multi-level preemption threshold +test. With 8 KiB, that test raises the free context list depletion trap +(FCD); 12 KiB suffice. + +## Expected output + +The run takes about half a minute. Each test prints one line, and the run +ends with: + +``` +**** Testing Complete **** +**** Test Summary: Tests Passed: 97 Tests Failed: 0 System Errors: 0 +**** REGRESSION EXIT CODE 0 **** +``` + +`test_control_return()` prints `Running Queue Max Message Size Test (32)` +after every test. The line belongs to the test control, not to a failure. diff --git a/test/tx/cmake/tricore_tc1_6_2/bsp/CMakeLists.txt b/test/tx/cmake/tricore_tc1_6_2/bsp/CMakeLists.txt new file mode 100644 index 000000000..9e5cb3a55 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/bsp/CMakeLists.txt @@ -0,0 +1,29 @@ +############################################################################## +# Copyright (c) 2026 safecubed GmbH +# Copyright (c) 2026 Eclipse ThreadX contributors +# +# This program and the accompanying materials are made available under the +# terms of the MIT License which is available at +# https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: MIT +############################################################################## + +# Portions of this file were generated with AI assistance. + +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) + +# BSP library for the regression test on the TC375 Lite Kit, based on the +# example of the port: its low-level initialisation with the trap vector +# table and the timer interrupt, and main.c, which sends printf output to the +# UART. The start-up code is crt0-tc38xx.o of the compiler. + +project(aurix_lite_kit_v2_bsp LANGUAGES C) + +set(BSP_DIR ${CMAKE_CURRENT_LIST_DIR}) + +add_library(aurix_lite_kit_v2_bsp + ${BSP_DIR}/main.c + ${BSP_DIR}/tx_initialize_low_level.c +) +target_link_libraries(aurix_lite_kit_v2_bsp PUBLIC azrtos::threadx) diff --git a/test/tx/cmake/tricore_tc1_6_2/bsp/main.c b/test/tx/cmake/tricore_tc1_6_2/bsp/main.c new file mode 100644 index 000000000..faf232cd8 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/bsp/main.c @@ -0,0 +1,182 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + +/* Regression test start-up for CPU0 of the TC375 Lite Kit without a driver + library. The start-up code of the compiler calls main. printf output goes + polled to ASCLIN0 (P14.0, 115200 8N1), the virtual COM port of the Lite + Kit. + + The clock system keeps its reset state, so the fast ASCLIN clock is the + back-up clock of 100 MHz divided by SCU_CCUCON2.ASCLINFDIV (1 after + reset). */ + +#include +#include +#include +#include "tx_api.h" + + +/* CPU0 watchdog: ENDINIT protects ASCLIN0_CLC. */ +#define SCU_WDTCPU0_CON0 (*(volatile unsigned int *) 0xF003624CUL) +#define WDT_CON0_ENDINIT 0x00000001UL +#define WDT_CON0_LCK 0x00000002UL +#define WDT_CON0_PW_OFF 2 +#define WDT_CON0_PW_MSK 0x3FFFUL +#define WDT_CON0_REL_MSK 0xFFFF0000UL +#define WDT_CON0_PW_READ_INVERT 0x003FUL + +/* ASCLIN0. */ +#define ASCLIN0_CLC (*(volatile unsigned int *) 0xF0000600UL) +#define ASCLIN0_TXFIFOCON (*(volatile unsigned int *) 0xF000060CUL) +#define ASCLIN0_BITCON (*(volatile unsigned int *) 0xF0000614UL) +#define ASCLIN0_FRAMECON (*(volatile unsigned int *) 0xF0000618UL) +#define ASCLIN0_DATCON (*(volatile unsigned int *) 0xF000061CUL) +#define ASCLIN0_BRG (*(volatile unsigned int *) 0xF0000620UL) +#define ASCLIN0_TXDATA (*(volatile unsigned int *) 0xF0000644UL) +#define ASCLIN0_CSR (*(volatile unsigned int *) 0xF000064CUL) + +#define ASCLIN_CLC_DISS 0x00000002UL +#define ASCLIN_CSR_CLKSEL_FAST 0x00000002UL /* fASCLINF */ +#define ASCLIN_CSR_CON 0x80000000UL +#define ASCLIN_FRAMECON_STOP_1 (1UL << 9) +#define ASCLIN_FRAMECON_MODE_ASC (1UL << 16) +#define ASCLIN_DATCON_DATLEN_8 7UL +#define ASCLIN_TXFIFOCON_FLUSH 0x00000001UL +#define ASCLIN_TXFIFOCON_ENO 0x00000002UL +#define ASCLIN_TXFIFOCON_INW_1 (1UL << 6) +#define ASCLIN_TXFIFOCON_FILL_OFF 16 +#define ASCLIN_TXFIFOCON_FILL_MSK 0x1FUL +#define ASCLIN_TX_FIFO_SIZE 16U + +/* 115200 baud from fASCLINF = 100 MHz: no prescaler, 16 samples per bit + (6.25 MHz) and the fractional divider 75/4069, which gives 115200.3 baud. + The bit is sampled once, at sample 8. */ +#define ASCLIN_BITCON_115200 ((8UL << 24) | (15UL << 16) | 0UL) +#define ASCLIN_BRG_115200 ((75UL << 16) | 4069UL) + +/* P14.0: push-pull output of alternate function 2, ASCLIN0 ATX. */ +#define P14_IOCR0 (*(volatile unsigned int *) 0xF003AE10UL) +#define PORT_IOCR0_PC0_MSK 0x000000F8UL +#define PORT_IOCR0_PC0_ALT2_PP (0x12UL << 3) + + +void tx_regression_main(void); + + +/* Sets (endinit = WDT_CON0_ENDINIT) or clears (endinit = 0) the ENDINIT bit + of the CPU0 watchdog. */ +static void cpu0_endinit_write(unsigned int endinit) +{ + unsigned int con0; + unsigned int password; + + con0 = SCU_WDTCPU0_CON0; + password = (((con0 >> WDT_CON0_PW_OFF) & WDT_CON0_PW_MSK) ^ WDT_CON0_PW_READ_INVERT) << WDT_CON0_PW_OFF; + if ((con0 & WDT_CON0_LCK) != 0U) + { + SCU_WDTCPU0_CON0 = (con0 & WDT_CON0_REL_MSK) | password | WDT_CON0_ENDINIT; + } + SCU_WDTCPU0_CON0 = (con0 & WDT_CON0_REL_MSK) | password | WDT_CON0_LCK | endinit; + (void) SCU_WDTCPU0_CON0; +} + + +static void uart_init(void) +{ + /* Enable the module. */ + cpu0_endinit_write(0U); + ASCLIN0_CLC = 0U; + cpu0_endinit_write(WDT_CON0_ENDINIT); + while ((ASCLIN0_CLC & ASCLIN_CLC_DISS) != 0U) + { + } + + /* The kernel clock is off while the module is configured. */ + ASCLIN0_CSR = 0U; + while ((ASCLIN0_CSR & ASCLIN_CSR_CON) != 0U) + { + } + + ASCLIN0_FRAMECON = 0U; + ASCLIN0_BITCON = ASCLIN_BITCON_115200; + ASCLIN0_BRG = ASCLIN_BRG_115200; + ASCLIN0_DATCON = ASCLIN_DATCON_DATLEN_8; + ASCLIN0_FRAMECON = ASCLIN_FRAMECON_STOP_1 | ASCLIN_FRAMECON_MODE_ASC; + ASCLIN0_TXFIFOCON = ASCLIN_TXFIFOCON_INW_1 | ASCLIN_TXFIFOCON_ENO | ASCLIN_TXFIFOCON_FLUSH; + + P14_IOCR0 = (P14_IOCR0 & ~PORT_IOCR0_PC0_MSK) | PORT_IOCR0_PC0_ALT2_PP; + + ASCLIN0_CSR = ASCLIN_CSR_CLKSEL_FAST; + while ((ASCLIN0_CSR & ASCLIN_CSR_CON) == 0U) + { + } +} + + +static void uart_put(char c) +{ + while (((ASCLIN0_TXFIFOCON >> ASCLIN_TXFIFOCON_FILL_OFF) & ASCLIN_TXFIFOCON_FILL_MSK) >= (ASCLIN_TX_FIFO_SIZE - 1U)) + { + } + ASCLIN0_TXDATA = (unsigned char) c; +} + + +/* Replaces write() of libos, which forwards output to a virtual I/O host. */ +int write(int desc, void *buf, size_t len) +{ + const char *p = (const char *) buf; + size_t i; + + (void) desc; + for (i = 0; i < len; i++) + { + if (p[i] == '\n') + { + uart_put('\r'); + } + uart_put(p[i]); + } + return (int) len; +} + + +void external_exit(UINT code) +{ + printf("**** REGRESSION EXIT CODE %u ****\n", code); + while (1) + { + } +} + + +/* Start and end of the test memory in DSPR1, from regression.ld. The start-up + code clears only the sections of the default linker script. */ +extern unsigned char __bss_cpu1_start[]; +extern unsigned char __bss_cpu1_end[]; + + +int main(void) +{ + memset(__bss_cpu1_start, 0, (size_t) (__bss_cpu1_end - __bss_cpu1_start)); + + uart_init(); + setvbuf(stdout, NULL, _IONBF, 0); + printf("\n**** REGRESSION START ****\n"); + + tx_regression_main(); + + while (1) + { + } +} diff --git a/test/tx/cmake/tricore_tc1_6_2/bsp/regression.ld b/test/tx/cmake/tricore_tc1_6_2/bsp/regression.ld new file mode 100644 index 000000000..c34616382 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/bsp/regression.ld @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + +/* Test memory of the regression test in DSPR1 of the TC375. The file is given + with -T after sample_threadx.ld of the example and augments the default + linker script of the AURIX GCC through INSERT. regression/CMakeLists.txt + places test_control_memory and tests_memory in the section .bss_cpu1; + main() clears it. */ + +MEMORY +{ + DSPR1 (w!xp): org = 0x60000000, len = 240K +} + +SECTIONS +{ + .bss_cpu1 (NOLOAD) : ALIGN(8) + { + __bss_cpu1_start = .; + *(.bss_cpu1) + . = ALIGN(8); + __bss_cpu1_end = .; + } > DSPR1 +} + +INSERT AFTER .csa diff --git a/test/tx/cmake/tricore_tc1_6_2/bsp/tx_initialize_low_level.c b/test/tx/cmake/tricore_tc1_6_2/bsp/tx_initialize_low_level.c new file mode 100644 index 000000000..ed1b1b879 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/bsp/tx_initialize_low_level.c @@ -0,0 +1,266 @@ +/*************************************************************************** + * Copyright (c) 2026 safecubed GmbH + * Copyright (c) 2026 Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +/* Portions of this file were generated with AI assistance. */ + +/* Low-level initialisation of ThreadX on CPU0 of the TC375 Lite Kit without + a driver library. A copy of the example's file whose timer interrupt also + calls test_interrupt_dispatch() and offsets each compare (timer_jitter). + + The start-up code of the compiler (crt0) has disabled the CPU0 watchdog + and the safety watchdog, initialised the stacks, the context save areas + and the C data, and calls main of sample_threadx.c, which calls + tx_kernel_enter. The clock system keeps its reset state: the system runs + from the back-up clock of 100 MHz. + + _tx_initialize_low_level runs from tx_kernel_enter before the kernel and + the application are initialised. It installs the trap and interrupt + vector tables, the ThreadX timer on compare 0 of STM0 and the dispatch + interrupt of the port. Interrupts stay disabled until _tx_thread_schedule + starts the first thread. */ + +#include "tx_api.h" + + +/* Core special function registers. */ +#define CSFR_BIV 0xFE20 +#define CSFR_BTV 0xFE24 + +/* CPU0 watchdog: ENDINIT protects BIV and BTV. */ +#define SCU_WDTCPU0_CON0 (*(volatile unsigned int *) 0xF003624CUL) +#define WDT_CON0_ENDINIT 0x00000001UL +#define WDT_CON0_LCK 0x00000002UL +#define WDT_CON0_PW_OFF 2 +#define WDT_CON0_PW_MSK 0x3FFFUL +#define WDT_CON0_REL_MSK 0xFFFF0000UL +/* CON0.PW reads with bits 5:0 inverted. */ +#define WDT_CON0_PW_READ_INVERT 0x003FUL + +/* Clock control: fSTM = fSOURCE / CCUCON0.STMDIV, where fSOURCE is the + back-up clock while CCUCON0.CLKSEL = 0. */ +#define SCU_CCUCON0 (*(volatile unsigned int *) 0xF0036030UL) +#define CCUCON0_STMDIV_MSK 0x0000000FUL +#define BACKUP_CLOCK_FREQUENCY 100000000UL + +/* STM0 compare 0. */ +#define STM0_TIM0 (*(volatile unsigned int *) 0xF0001010UL) +#define STM0_CMP0 (*(volatile unsigned int *) 0xF0001030UL) +#define STM0_CMCON (*(volatile unsigned int *) 0xF0001038UL) +#define STM0_ICR (*(volatile unsigned int *) 0xF000103CUL) +#define STM0_ISCR (*(volatile unsigned int *) 0xF0001040UL) +#define STM_CMCON_CMP0_MSK 0x00001F1FUL /* MSTART0 and MSIZE0 */ +#define STM_CMCON_CMP0_32_BITS 0x0000001FUL /* MSTART0 = 0, MSIZE0 = 31 */ +#define STM_ICR_CMP0_MSK 0x00000007UL /* CMP0EN, CMP0IR and CMP0OS */ +#define STM_ICR_CMP0EN 0x00000001UL /* CMP0OS = 0: service request STMIR0 */ +#define STM_ISCR_CMP0IRR 0x00000001UL + +/* Service request STMIR0 of STM0. */ +#define SRC_STM0SR0 (*(volatile unsigned int *) 0xF0038300UL) + + +VOID _tx_timer_interrupt(VOID); +VOID test_interrupt_dispatch(VOID); + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) +VOID _tx_execution_isr_enter(VOID); +VOID _tx_execution_isr_exit(VOID); +#endif + +extern VOID *_tx_initialize_unused_memory; + +/* From the trap vector table below and the linker script. */ +extern UCHAR _tx_trap_table[]; +extern UCHAR __INTTAB_CPU0[]; +extern UCHAR __TX_FREE_MEM[]; + +/* STM ticks per ThreadX timer tick. */ +static ULONG timer_period; + +/* Pseudo-random offset of 0 to 255 STM ticks of the current compare. It + keeps the timer interrupt from staying in phase with a test loop. */ +static ULONG timer_jitter; +static ULONG timer_jitter_seed = 1U; + + +/* Sets (endinit = WDT_CON0_ENDINIT) or clears (endinit = 0) the ENDINIT bit + of the CPU0 watchdog. A password access unlocks CON0, the modify access + then writes ENDINIT and locks CON0 again. */ +static VOID cpu0_endinit_write(ULONG endinit) +{ + + ULONG con0; + ULONG password; + + con0 = SCU_WDTCPU0_CON0; + password = (((con0 >> WDT_CON0_PW_OFF) & WDT_CON0_PW_MSK) ^ WDT_CON0_PW_READ_INVERT) << WDT_CON0_PW_OFF; + + if ((con0 & WDT_CON0_LCK) != 0U) + { + SCU_WDTCPU0_CON0 = (con0 & WDT_CON0_REL_MSK) | password | WDT_CON0_ENDINIT; + } + + SCU_WDTCPU0_CON0 = (con0 & WDT_CON0_REL_MSK) | password | WDT_CON0_LCK | endinit; + + /* The read back completes the write before ENDINIT protected registers + are accessed. */ + (VOID) SCU_WDTCPU0_CON0; +} + + +VOID _tx_initialize_low_level(VOID) +{ + + ULONG stm_frequency; + + _disable(); + + _tx_initialize_unused_memory = (VOID *) __TX_FREE_MEM; + + /* Trap and interrupt vector tables. BIV.VSS = 0: vector spacing of 32 + bytes. */ + cpu0_endinit_write(0U); + __mtcr(CSFR_BTV, (ULONG) _tx_trap_table); + __mtcr(CSFR_BIV, (ULONG) __INTTAB_CPU0); + _isync(); + cpu0_endinit_write(WDT_CON0_ENDINIT); + + /* ThreadX timer on compare 0 of STM0. The compare covers all 32 bits of + the lower timer word. */ + stm_frequency = BACKUP_CLOCK_FREQUENCY / (SCU_CCUCON0 & CCUCON0_STMDIV_MSK); + timer_period = (stm_frequency + (TX_TIMER_TICKS_PER_SECOND / 2U)) / TX_TIMER_TICKS_PER_SECOND; + + STM0_CMCON = (STM0_CMCON & ~STM_CMCON_CMP0_MSK) | STM_CMCON_CMP0_32_BITS; + STM0_CMP0 = STM0_TIM0 + timer_period; + STM0_ISCR = STM_ISCR_CMP0IRR; + STM0_ICR = (STM0_ICR & ~STM_ICR_CMP0_MSK) | STM_ICR_CMP0EN; + SRC_STM0SR0 = TX_PORT_TRICORE_SRC_CLRR_MSK | TX_PORT_TRICORE_SRC_SRE_MSK | + (0UL << TX_PORT_TRICORE_SRC_TOS_OFF) | TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY; + + /* Dispatch interrupt of the port. */ + TX_PORT_TRICORE_DISPATCH_SRC = TX_PORT_TRICORE_SRC_CLRR_MSK | TX_PORT_TRICORE_SRC_SRE_MSK | + (0UL << TX_PORT_TRICORE_SRC_TOS_OFF) | TX_PORT_TRICORE_DISPATCH_PRIORITY; +} + + +TX_PORT_TRICORE_INTERRUPT(_tx_timer_isr, TX_PORT_TRICORE_TIMER_INTERRUPT_PRIORITY) +{ + + ULONG now; + ULONG next; + ULONG jitter; + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) + _tx_execution_isr_enter(); +#endif + + STM0_ISCR = STM_ISCR_CMP0IRR; + + /* The next compare follows the previous one by one period. If the timer + has already passed that value, for example after a debugger halt, the + next compare is one period from now and the ticks in between are lost. + Without this check, the next interrupt would occur only after the + 32-bit timer wraps. */ + timer_jitter_seed = (timer_jitter_seed * 1664525UL) + 1013904223UL; + jitter = timer_jitter_seed >> 24; + next = STM0_CMP0 - timer_jitter + timer_period + jitter; + now = STM0_TIM0; + if ((LONG) (next - now) <= 0) + { + next = now + timer_period; + jitter = 0U; + } + timer_jitter = jitter; + STM0_CMP0 = next; + + test_interrupt_dispatch(); + _tx_timer_interrupt(); + +#if (defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) || defined(TX_EXECUTION_PROFILE_ENABLE)) + _tx_execution_isr_exit(); +#endif +} + + +/* Receives the trap class and TIN of every trap except the system call and + shall not return. */ +VOID __attribute__( ( weak, noreturn ) ) tx_trap_error_hook(UINT trap_class, UINT tin) +{ + (VOID) trap_class; + (VOID) tin; + + _debug(); + while (TX_TRUE) + { + } +} + +/* Trap vector table of CPU0: eight entries of 32 bytes, aligned to 256 + bytes. The error entries jump, because a context management trap can + leave no free CSA. */ +__asm__ (".pushsection .traptab, \"ax\", @progbits\n" + " .align 8\n" + " .global _tx_trap_table\n" + " .type _tx_trap_table, @function\n" + "_tx_trap_table:\n" + + /* Class 0: MMU. */ + " mov %d4, 0\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 1: internal protection. */ + " mov %d4, 1\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 2: instruction errors. */ + " mov %d4, 2\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 3: context management. */ + " mov %d4, 3\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 4: system bus and peripheral errors. */ + " mov %d4, 4\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 5: assertion. */ + " mov %d4, 5\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + /* Class 6: system call. The handler shall be called directly + (TX_PORT_TRICORE_SYSCALL_CALL_DEPTH). */ + " svlcx\n" + " mov %d4, %d15\n" + " call _tx_thread_syscall_handler\n" + " rslcx\n" + " rfe\n" + " .align 5\n" + + /* Class 7: non-maskable interrupt. */ + " mov %d4, 7\n" + " mov %d5, %d15\n" + " j tx_trap_error_hook\n" + " .align 5\n" + + " .size _tx_trap_table, . - _tx_trap_table\n" + ".popsection\n"); diff --git a/test/tx/cmake/tricore_tc1_6_2/regression/CMakeLists.txt b/test/tx/cmake/tricore_tc1_6_2/regression/CMakeLists.txt new file mode 100644 index 000000000..e9b3257f6 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/regression/CMakeLists.txt @@ -0,0 +1,67 @@ +############################################################################## +# Copyright (c) 2026 safecubed GmbH +# Copyright (c) 2026 Eclipse ThreadX contributors +# +# This program and the accompanying materials are made available under the +# terms of the MIT License which is available at +# https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: MIT +############################################################################## + +# Portions of this file were generated with AI assistance. + +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) + +project(tricore_tc1_6_2_regression_test LANGUAGES C) + +set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../regression) +set(BSP_DIR ${CMAKE_CURRENT_LIST_DIR}/../bsp) +set(EXAMPLE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../ports/tricore_tc1_6_2/gnu/example_build) + +# testcontrol.c runs every test of its table test_control_tests[] in one +# image, so every test file is linked. threadx_initialize_kernel_setup_test.c +# provides its own main() and is not part of the table. +file(GLOB regression_test_cases ${SOURCE_DIR}/threadx_*.c) +list(REMOVE_ITEM regression_test_cases + ${SOURCE_DIR}/threadx_initialize_kernel_setup_test.c) + +# The default test memories do not fit the RAM of the TC375. +set(TESTCONTROL_SOURCE ${SOURCE_DIR}/testcontrol.c) +set_source_files_properties(${TESTCONTROL_SOURCE} PROPERTIES + COMPILE_DEFINITIONS + "main=tx_regression_main;TEST_CONTROL_MEMORY_SIZE=0x6000;TESTS_MEMORY_SIZE=0x1C000;TEST_MEMORY_PLACEMENT=__attribute__((section(\".bss_cpu1\")))") + +set(WEAK_DEFAULTS_SOURCE ${CMAKE_CURRENT_LIST_DIR}/../../../../shared/regression/testcontrol_weak_defaults.c) + +# The kernel and the port call into these utilities when the option is set. +set(UTILITY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../utility) +set(utility_sources) +if("-DTX_EXECUTION_PROFILE_ENABLE" IN_LIST ${CMAKE_BUILD_TYPE}) + list(APPEND utility_sources ${UTILITY_DIR}/execution_profile_kit/tx_execution_profile.c) +endif() +if("-DTX_LOW_POWER" IN_LIST ${CMAKE_BUILD_TYPE}) + list(APPEND utility_sources ${UTILITY_DIR}/low_power/tx_low_power.c) +endif() + +add_executable(regression + ${TESTCONTROL_SOURCE} + ${regression_test_cases} + ${WEAK_DEFAULTS_SOURCE} + ${utility_sources}) +target_include_directories(regression PRIVATE ${SOURCE_DIR}) +# The BSP overrides write() of libos, so the whole BSP library is linked. +target_link_libraries(regression PRIVATE + -Wl,--whole-archive aurix_lite_kit_v2_bsp -Wl,--no-whole-archive + azrtos::threadx) +target_link_options(regression PRIVATE + "SHELL:-T ${EXAMPLE_DIR}/sample_threadx.ld" + "SHELL:-T ${BSP_DIR}/regression.ld" + -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/regression.map) +set_target_properties(regression PROPERTIES SUFFIX ".elf") + +add_custom_command(TARGET regression POST_BUILD + COMMAND ${OBJCOPY} -O ihex + $ ${CMAKE_CURRENT_BINARY_DIR}/regression.hex + COMMAND ${SIZE} $ + VERBATIM) diff --git a/test/tx/cmake/tricore_tc1_6_2/run.bat b/test/tx/cmake/tricore_tc1_6_2/run.bat new file mode 100644 index 000000000..b2fe00351 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/run.bat @@ -0,0 +1,100 @@ +@echo off +rem ########################################################################## +rem Copyright (c) 2026 safecubed GmbH +rem Copyright (c) 2026 Eclipse ThreadX contributors +rem +rem This program and the accompanying materials are made available under the +rem terms of the MIT License which is available at +rem https://opensource.org/licenses/MIT. +rem +rem SPDX-License-Identifier: MIT +rem ########################################################################## + +rem Portions of this file were generated with AI assistance. + +rem Regression test build runner for the TriCore TC1.6.2 port on Windows. +rem Usage: run.bat build [all| ...] +rem The AURIX GCC (tricore-elf-), CMake and Ninja shall be on PATH. The images +rem run on the TC375 Lite Kit, so this script only builds them. See README.md +rem for programming and running them. + +setlocal EnableExtensions EnableDelayedExpansion +set "SCRIPT_NAME=%~nx0" +cd /d "%~dp0" +for %%I in ("%~dp0..\..\..\..") do set "REPO_ROOT=%%~fI" +set "REPO_ROOT=%REPO_ROOT:\=/%" + +rem Parse the build configurations from the set(BUILD_CONFIGURATIONS ...) +rem command of CMakeLists.txt, which may span several lines. +set "CONFIGS=" +set "IN_LIST=" +for /f "usebackq delims=" %%L in ("CMakeLists.txt") do ( + set "LINE=%%L" + if not defined IN_LIST if not "!LINE:set(BUILD_CONFIGURATIONS=!"=="!LINE!" ( + set "IN_LIST=1" + set "LINE=!LINE:set(BUILD_CONFIGURATIONS=!" + ) + if defined IN_LIST ( + set "LAST=" + if not "!LINE:)=!"=="!LINE!" set "LAST=1" + set "LINE=!LINE:)= !" + for %%W in (!LINE!) do ( + set "WORD=%%W" + if not "!WORD:build=!"=="!WORD!" set "CONFIGS=!CONFIGS! %%W" + ) + if defined LAST set "IN_LIST=" + ) +) + +if not "%~1"=="build" goto help +shift + +set "BUILDS=" +if "%~1"=="" ( + for %%C in (%CONFIGS%) do if not defined BUILDS set "BUILDS=%%C" + goto run +) +if "%~1"=="all" if "%~2"=="" ( + set "BUILDS=%CONFIGS%" + goto run +) + +:args +if "%~1"=="" goto run +call :validate "%~1" || goto help +set "BUILDS=!BUILDS! %~1" +shift +goto args + +rem A failing configuration does not stop the ones after it. The status is +rem accumulated and returned. +:run +set "BUILD_STATUS=0" +for %%B in (%BUILDS%) do ( + echo Building %%B + call :generate %%B && call :build %%B || set "BUILD_STATUS=1" + echo. +) +exit /b %BUILD_STATUS% + +:help +echo Usage: %SCRIPT_NAME% build [all^|^ ...] +echo. +echo Available build configurations: +for %%C in (%CONFIGS%) do echo %%C +exit /b 1 + +:validate +for %%C in (%CONFIGS%) do if "%~1"=="%%C" exit /b 0 +exit /b 1 + +:generate +cmake -B"build/%~1" -GNinja ^ + -DCMAKE_TOOLCHAIN_FILE="%REPO_ROOT%/cmake/tricore_tc1_6_2.cmake" ^ + -DCMAKE_BUILD_TYPE="%~1" ^ + . +exit /b %ERRORLEVEL% + +:build +cmake --build "build/%~1" +exit /b %ERRORLEVEL% diff --git a/test/tx/cmake/tricore_tc1_6_2/run.sh b/test/tx/cmake/tricore_tc1_6_2/run.sh new file mode 100755 index 000000000..cdf5b6367 --- /dev/null +++ b/test/tx/cmake/tricore_tc1_6_2/run.sh @@ -0,0 +1,87 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2026 safecubed GmbH +# Copyright (c) 2026 Eclipse ThreadX contributors +# +# This program and the accompanying materials are made available under the +# terms of the MIT License which is available at +# https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: MIT +############################################################################## + +# Portions of this file were generated with AI assistance. + +set -e + +# Regression test build runner for the TriCore TC1.6.2 port. +# Usage: run.sh build [all| ...] +# The AURIX GCC (tricore-elf-) shall be on PATH. The images run on the TC375 +# Lite Kit, so this script only builds them. See README.md for programming and running them. + +function help() { + echo "Usage: $0 build [all| ...]" + echo "" + echo "Available build configurations:" + for build in ${build_configurations[*]}; do + echo " $build" + done + exit 1 +} + +function validate() { + for build in ${build_configurations[*]}; do + if [ "$1" == "$build" ]; then + return + fi + done + help +} + +function generate() { + local build=$1 + cmake -B"build/${build}" -GNinja \ + -DCMAKE_TOOLCHAIN_FILE="${REPO_ROOT}/cmake/tricore_tc1_6_2.cmake" \ + -DCMAKE_BUILD_TYPE="${build}" \ + . +} + +function build() { + cmake --build "build/$1" +} + +# Determine repo root and script directory +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../.." && pwd)" +cd "$SCRIPT_DIR" + +# Parse build configurations from CMakeLists.txt +result=$(sed -n "/(BUILD_CONFIGURATIONS/,/)/p" CMakeLists.txt | sed ':label;N;s/\n/ /;b label' | grep -Pzo "[a-zA-Z0-9_]*build[a-zA-Z0-9_]*\s*" | tr -d '\0') +IFS=' ' +read -ra build_configurations <<< "$result" + +if [ $# -lt 1 ] || [ "$1" != "build" ]; then + help +fi +shift + +if [ "$#" == "0" ]; then + builds=${build_configurations[0]} +elif [ "$*" == "all" ]; then + builds=${build_configurations[@]} +else + for item in $*; do + validate "$item" + done + builds=$* +fi + +# A failing configuration does not stop the ones after it. The status is +# accumulated and returned. +build_status=0 +for item in $builds; do + echo "Building ${item}" + { generate "$item" && build "$item"; } || build_status=$? + echo "" +done +exit $build_status diff --git a/test/tx/regression/testcontrol.c b/test/tx/regression/testcontrol.c index bec50ee76..d76fbe493 100644 --- a/test/tx/regression/testcontrol.c +++ b/test/tx/regression/testcontrol.c @@ -38,6 +38,18 @@ #endif /* Check THREADX_MINOR_VERSION */ +#ifndef TEST_CONTROL_MEMORY_SIZE +#define TEST_CONTROL_MEMORY_SIZE 0x60000 +#endif + +#ifndef TESTS_MEMORY_SIZE +#define TESTS_MEMORY_SIZE 0x60000 +#endif + +#ifndef TEST_MEMORY_PLACEMENT +#define TEST_MEMORY_PLACEMENT +#endif + #define TEST_STACK_SIZE 6144 @@ -118,8 +130,8 @@ UCHAR *test_free_memory_ptr; VOID (*test_isr_dispatch)(void); -UCHAR test_control_memory[0x60000]; -UCHAR tests_memory[0x60000]; +UCHAR test_control_memory[TEST_CONTROL_MEMORY_SIZE] TEST_MEMORY_PLACEMENT; +UCHAR tests_memory[TESTS_MEMORY_SIZE] TEST_MEMORY_PLACEMENT; /* Define the external reference for the preempt disable flag. */