From bd18a2813e3c4913e0c098831a0078b1d225f337 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Thu, 8 Jun 2023 01:12:16 +0200 Subject: [PATCH 1/5] Move from newlibc to picolibc --- .../src/main/resources/lib/platform/zephyr/prj_lf.conf | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf index 88613edc08..764938f64e 100644 --- a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf +++ b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf @@ -7,8 +7,12 @@ # Enable printf CONFIG_PRINTK=y -# Use the newlib C library -CONFIG_NEWLIB_LIBC=y -CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y +# Use the picolib C library. This is used instead of newlib because it also +# supports regexp used by federate.c +CONFIG_PICOLIBC=y +CONFIG_PICOLIBC_IO_FLOAT=y +CONFIG_PICOLIBC_IO_C99_FORMATS=y +CONFIG_PICOLIBC_IO_LONG_LONG=y + # Enable the counter API used for hi-res clock CONFIG_COUNTER=y From ad76349cb3cca50f1c25ad0569f36e434a31fc90 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 26 Jul 2023 10:48:45 +0200 Subject: [PATCH 2/5] Dont do Cmake install when target platform is Zephyr --- .../lflang/generator/c/CCmakeGenerator.java | 8 ++-- .../org/lflang/generator/c/CCompiler.java | 37 ++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java index c9c2c9e943..4945d07f72 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -317,9 +317,11 @@ CodeBuilder generateCMakeCode( } cMakeCode.newLine(); - // Add the install option - cMakeCode.pr(installCode); - cMakeCode.newLine(); + // Add the install option. Unless we are targeting Zephyr + if (targetConfig.platformOptions.platform != Platform.ZEPHYR) { + cMakeCode.pr(installCode); + cMakeCode.newLine(); + } // Add the include file for (String includeFile : targetConfig.cmakeIncludes) { diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 0933d95594..2b107b6d8c 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -150,7 +150,12 @@ public boolean runCCompiler(GeneratorBase generator, LFGeneratorContext context) int makeReturnCode = 0; if (cMakeReturnCode == 0) { - LFCommand build = buildCmakeCommand(); + LFCommand build; + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + build = buildCmakeZephyrCommand(); + } else { + build = buildCmakeCommand(); + } makeReturnCode = build.run(context.getCancelIndicator()); @@ -308,6 +313,36 @@ public LFCommand buildCmakeCommand() { return command; } + /** + * @return A command to build a file with CMake when the platform is Zephyr. This is identical + * to the normal command except we dont use --target install. + */ + public LFCommand buildCmakeZephyrCommand() { + // Set the build directory to be "build" + Path buildPath = fileConfig.getSrcGenPath().resolve("build"); + String cores = String.valueOf(Runtime.getRuntime().availableProcessors()); + LFCommand command = + commandFactory.createCommand( + "cmake", + List.of( + "--build", + ".", + "--parallel", + cores, + "--config", + buildTypeToCmakeConfig(targetConfig.cmakeBuildType)), + buildPath); + if (command == null) { + messageReporter + .nowhere() + .error( + "The C/CCpp target requires CMAKE >= 3.5 to compile the generated code." + + " Auto-compiling can be disabled using the \"no-compile: true\" target" + + " property."); + } + return command; + } + /** * Return a flash/emulate command using west. If board is null (defaults to qemu_cortex_m3) or * qemu_* Return a flash command which runs the target as an emulation If ordinary target, return From 86c289c6f7e24337d3893952a1126247ac1dd86b Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 26 Jul 2023 15:09:12 -0700 Subject: [PATCH 3/5] Apply formatter --- core/src/main/java/org/lflang/generator/c/CCompiler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 2b107b6d8c..88a0970989 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -314,8 +314,8 @@ public LFCommand buildCmakeCommand() { } /** - * @return A command to build a file with CMake when the platform is Zephyr. This is identical - * to the normal command except we dont use --target install. + * @return A command to build a file with CMake when the platform is Zephyr. This is identical to + * the normal command except we dont use --target install. */ public LFCommand buildCmakeZephyrCommand() { // Set the build directory to be "build" From 163a6a403f178e09d60c85c9dc4efb036673c204 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 27 Jul 2023 09:41:24 +0200 Subject: [PATCH 4/5] Dont use gettimeofday in tests (only works with proper OS) --- test/C/src/TestForPreviousOutput.lf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/C/src/TestForPreviousOutput.lf b/test/C/src/TestForPreviousOutput.lf index cd11767592..2340af45c1 100644 --- a/test/C/src/TestForPreviousOutput.lf +++ b/test/C/src/TestForPreviousOutput.lf @@ -17,7 +17,7 @@ reactor Source { reaction(startup) -> out {= // Set a seed for random number generation based on the current time. - srand(time(0)); + srand(lf_time_physical()); // Randomly produce an output or not. if (rand() % 2) { lf_set(out, 21); From ef1aaeb640b474b7a79e933355f4a5836ee65780 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 27 Jul 2023 09:57:55 +0200 Subject: [PATCH 5/5] Add CONFIG_FILE_SYSTEM to get some stdio functions in picolibc --- core/src/main/resources/lib/platform/zephyr/prj_lf.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf index 764938f64e..3d421cd6f9 100644 --- a/core/src/main/resources/lib/platform/zephyr/prj_lf.conf +++ b/core/src/main/resources/lib/platform/zephyr/prj_lf.conf @@ -14,5 +14,8 @@ CONFIG_PICOLIBC_IO_FLOAT=y CONFIG_PICOLIBC_IO_C99_FORMATS=y CONFIG_PICOLIBC_IO_LONG_LONG=y +# To get `read`, `write`, `lseek` and `close` used by tracing infrastructure. +CONFIG_FILE_SYSTEM=y + # Enable the counter API used for hi-res clock CONFIG_COUNTER=y