From 8400aac26019593d841bf03c6f5ed2cf441b5b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20W=C3=B3jcik?= Date: Sun, 12 Apr 2026 09:08:32 +0200 Subject: [PATCH 1/3] Add configurable header to FreeRTOS module --- modules/freertos/build.zig | 22 +++ ...reeRTOSConfig.h => FreeRTOSConfig.h.cmake} | 7 +- .../freertos/config/RP2040/FreeRTOSConfig.h | 146 ------------------ 3 files changed, 26 insertions(+), 149 deletions(-) rename modules/freertos/config/{RP2350_ARM/FreeRTOSConfig.h => FreeRTOSConfig.h.cmake} (96%) delete mode 100644 modules/freertos/config/RP2040/FreeRTOSConfig.h diff --git a/modules/freertos/build.zig b/modules/freertos/build.zig index acf03f589..744ce64d5 100644 --- a/modules/freertos/build.zig +++ b/modules/freertos/build.zig @@ -6,6 +6,12 @@ const FreeRTOSPort = enum { RP2350_RISCV, }; +const FreeRTOSConfig = struct { + // Scheduler related + configUSE_IDLE_HOOK: bool = false, + configUSE_TICK_HOOK: bool = false, +}; + pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -17,10 +23,24 @@ pub fn build(b: *std.Build) void { "FreeRTOS port to use", ) orelse .RP2040; + const cfg_idle_hook = b.option(bool, "idle_hook", "Enable FreeRTOS idle hook") orelse false; + const cfg_tick_hook = b.option(bool, "tick_hook", "Enable FreeRTOS tick hook") orelse false; + if (port_name != .RP2040 and port_name != .RP2350_ARM) { @panic("Right now only RP2040 and RP2350_ARM ports are supported"); } + // In future this config might be validated against port-specific capabilities + const config = FreeRTOSConfig{ + .configUSE_IDLE_HOOK = cfg_idle_hook, + .configUSE_TICK_HOOK = cfg_tick_hook, + }; + + const config_header = b.addConfigHeader(.{ + .style = .{ .cmake = b.path("config/FreeRTOSConfig.h.cmake") }, + .include_path = "FreeRTOSConfig.h", + }, config); + const foundationlibc_dep = b.dependency("foundationlibc", .{ .target = target, .optimize = optimize, @@ -34,6 +54,8 @@ pub fn build(b: *std.Build) void { // Link libc freertos_lib.linkLibrary(foundationlibc_dep.artifact("foundation")); + // Add generated configuration header + freertos_lib.addConfigHeader(config_header); const freertos_kernel_dep = b.dependency("freertos_kernel", .{}); const freertos_kernel_community_dep = b.dependency("freertos_kernel_community", .{}); diff --git a/modules/freertos/config/RP2350_ARM/FreeRTOSConfig.h b/modules/freertos/config/FreeRTOSConfig.h.cmake similarity index 96% rename from modules/freertos/config/RP2350_ARM/FreeRTOSConfig.h rename to modules/freertos/config/FreeRTOSConfig.h.cmake index 2ffdd90fd..f44fd52c1 100644 --- a/modules/freertos/config/RP2350_ARM/FreeRTOSConfig.h +++ b/modules/freertos/config/FreeRTOSConfig.h.cmake @@ -43,8 +43,9 @@ /* Scheduler Related */ #define configUSE_PREEMPTION 1 #define configUSE_TICKLESS_IDLE 0 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 +// FIXME: must be without indent to work, remove after Zig 0.16 release: https://codeberg.org/ziglang/zig/issues/31164 +#cmakedefine01 configUSE_IDLE_HOOK +#cmakedefine01 configUSE_TICK_HOOK #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMAX_PRIORITIES 32 #define configMINIMAL_STACK_SIZE ( uint32_t ) 256 @@ -118,7 +119,7 @@ #define configSUPPORT_PICO_SYNC_INTEROP 0 #define configSUPPORT_PICO_TIME_INTEROP 0 - /* RP2350 required */ + /* Dependent on processor */ #define configENABLE_FPU 1 #define configENABLE_MPU 0 #define configENABLE_TRUSTZONE 0 diff --git a/modules/freertos/config/RP2040/FreeRTOSConfig.h b/modules/freertos/config/RP2040/FreeRTOSConfig.h deleted file mode 100644 index 4bc05c76a..000000000 --- a/modules/freertos/config/RP2040/FreeRTOSConfig.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * FreeRTOS V202107.00 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ - - #ifndef FREERTOS_CONFIG_H - #define FREERTOS_CONFIG_H - - /*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. - * - * See http://www.freertos.org/a00110.html - *----------------------------------------------------------*/ - - /* Scheduler Related */ - #define configUSE_PREEMPTION 1 - #define configUSE_TICKLESS_IDLE 0 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 - #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) - #define configMAX_PRIORITIES 32 - #define configMINIMAL_STACK_SIZE ( uint32_t ) 256 - #define configUSE_16_BIT_TICKS 0 - - #define configIDLE_SHOULD_YIELD 1 - - /* Synchronization Related */ - #define configUSE_MUTEXES 1 - #define configUSE_RECURSIVE_MUTEXES 1 - #define configUSE_APPLICATION_TASK_TAG 0 - #define configUSE_COUNTING_SEMAPHORES 1 - #define configQUEUE_REGISTRY_SIZE 8 - #define configUSE_QUEUE_SETS 1 - #define configUSE_TIME_SLICING 1 - #define configUSE_NEWLIB_REENTRANT 0 - #define configENABLE_BACKWARD_COMPATIBILITY 0 - #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 - - /* System */ - #define configSTACK_DEPTH_TYPE uint32_t - #define configMESSAGE_BUFFER_LENGTH_TYPE size_t - - /* Memory allocation related definitions. */ - #define configSUPPORT_STATIC_ALLOCATION 0 - #define configSUPPORT_DYNAMIC_ALLOCATION 1 - #define configTOTAL_HEAP_SIZE (128*1024) - #define configAPPLICATION_ALLOCATED_HEAP 0 - - /* Hook function related definitions. */ - #define configCHECK_FOR_STACK_OVERFLOW 2 - #define configUSE_MALLOC_FAILED_HOOK 0 - #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 - - /* Run time and task stats gathering related definitions. */ - #define configGENERATE_RUN_TIME_STATS 0 - #define configUSE_TRACE_FACILITY 1 - #define configUSE_STATS_FORMATTING_FUNCTIONS 0 - - /* Co-routine related definitions. */ - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES 1 - - /* Software timer related definitions. */ - #define configUSE_TIMERS 1 - #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) - #define configTIMER_QUEUE_LENGTH 10 - #define configTIMER_TASK_STACK_DEPTH 1024 - - /* Interrupt nesting behaviour configuration. */ - /* - #define configKERNEL_INTERRUPT_PRIORITY [dependent of processor] - #define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application] - #define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application] - */ - - /* SMP port only */ - #define configNUMBER_OF_CORES 1 - #define configTICK_CORE 0 - #define configRUN_MULTIPLE_PRIORITIES 1 - #define configUSE_CORE_AFFINITY 0 - #define configUSE_PASSIVE_IDLE_HOOK 0 - - /* PicoSDK interop — DISABLED because MicroZig does not run .init_array - * constructors. The FreeRTOS RP2040 port relies on a - * __attribute__((constructor)) function (prvRuntimeInitializer in port.c) to - * initialise pxCrossCoreSpinLock and an internal xEventGroup *before* main(). - * Without that, the doorbell ISR dereferences a NULL spin-lock pointer and - * triggers a Usage Fault immediately after the scheduler starts. - * Re-enable these only after adding .init_array support to MicroZig startup. */ - #define configSUPPORT_PICO_SYNC_INTEROP 0 - #define configSUPPORT_PICO_TIME_INTEROP 0 - - #include - /* Define to trap errors during development. */ - #define configASSERT(x) assert(x) - - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 1 - #define INCLUDE_uxTaskPriorityGet 1 - #define INCLUDE_vTaskDelete 1 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 - #define INCLUDE_xTaskGetSchedulerState 1 - #define INCLUDE_xTaskGetCurrentTaskHandle 1 - #define INCLUDE_uxTaskGetStackHighWaterMark 1 - #define INCLUDE_xTaskGetIdleTaskHandle 1 - #define INCLUDE_eTaskGetState 1 - #define INCLUDE_xTimerPendFunctionCall 1 - #define INCLUDE_xTaskAbortDelay 1 - #define INCLUDE_xTaskGetHandle 1 - #define INCLUDE_xTaskResumeFromISR 1 - #define INCLUDE_xQueueGetMutexHolder 1 - - /* A header file that defines trace macro can be included here. */ - - #endif /* FREERTOS_CONFIG_H */ \ No newline at end of file From 6e7d66a3c807dccd0704f55589a32375d0d430f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20W=C3=B3jcik?= Date: Sun, 12 Apr 2026 18:22:23 +0200 Subject: [PATCH 2/3] Change type names --- modules/freertos/build.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/freertos/build.zig b/modules/freertos/build.zig index 744ce64d5..41ee11c80 100644 --- a/modules/freertos/build.zig +++ b/modules/freertos/build.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const FreeRTOSPort = enum { +const FreeRTOS_Port = enum { RP2040, RP2350_ARM, RP2350_RISCV, }; -const FreeRTOSConfig = struct { +const FreeRTOS_Config = struct { // Scheduler related configUSE_IDLE_HOOK: bool = false, configUSE_TICK_HOOK: bool = false, @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void { // Configurable options const port_name = b.option( - FreeRTOSPort, + FreeRTOS_Port, "port_name", "FreeRTOS port to use", ) orelse .RP2040; @@ -31,7 +31,7 @@ pub fn build(b: *std.Build) void { } // In future this config might be validated against port-specific capabilities - const config = FreeRTOSConfig{ + const config = FreeRTOS_Config{ .configUSE_IDLE_HOOK = cfg_idle_hook, .configUSE_TICK_HOOK = cfg_tick_hook, }; From 6def779fa9a3cfad1e457fb8c556e0a60fb62a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20W=C3=B3jcik?= Date: Sun, 12 Apr 2026 18:30:02 +0200 Subject: [PATCH 3/3] Better comment --- modules/freertos/config/FreeRTOSConfig.h.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/freertos/config/FreeRTOSConfig.h.cmake b/modules/freertos/config/FreeRTOSConfig.h.cmake index f44fd52c1..2c581c8be 100644 --- a/modules/freertos/config/FreeRTOSConfig.h.cmake +++ b/modules/freertos/config/FreeRTOSConfig.h.cmake @@ -43,7 +43,7 @@ /* Scheduler Related */ #define configUSE_PREEMPTION 1 #define configUSE_TICKLESS_IDLE 0 -// FIXME: must be without indent to work, remove after Zig 0.16 release: https://codeberg.org/ziglang/zig/issues/31164 +// FIXME: must be without indent to work, please fix (add indent) after Zig 0.16 release: https://codeberg.org/ziglang/zig/issues/31164 #cmakedefine01 configUSE_IDLE_HOOK #cmakedefine01 configUSE_TICK_HOOK #define configTICK_RATE_HZ ( ( TickType_t ) 1000 )