Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zephyr: Move from newlibc to picolibc #1918

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 36 additions & 1 deletion core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions core/src/main/resources/lib/platform/zephyr/prj_lf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

# 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

# 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
2 changes: 1 addition & 1 deletion test/C/src/TestForPreviousOutput.lf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down