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

Usage of high-resolution counter device on Zephyr boards. Update to v3.4.0 #2007

Merged
merged 17 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "org.lflang/src/lib/c/reactor-c"]
path = core/src/main/resources/lib/c/reactor-c
url = https://github.com/lf-lang/reactor-c.git
url = git@github.com:lf-lang/reactor-c.git
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
[submodule "org.lflang/src/lib/cpp/reactor-cpp"]
path = core/src/main/resources/lib/cpp/reactor-cpp
url = https://github.com/lf-lang/reactor-cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public void buildZephyrUnthreadedTests() {
false);
}

@Test
public void buildZephyrBoardTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
super.runTestsFor(
List.of(Target.C),
Message.DESC_ZEPHYR,
TestCategory.ZEPHYR_BOARDS::equals,
Configurators::noChanges,
TestLevel.BUILD,
false);
}

@Test
public void buildZephyrThreadedTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
Expand Down
14 changes: 6 additions & 8 deletions core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,25 +326,23 @@ CodeBuilder generateCMakeCode(
cMakeCode.newLine();
}

if (targetConfig.threading) {
if (targetConfig.threading && targetConfig.platformOptions.platform != Platform.ZEPHYR) {
// If threaded computation is requested, add the threads option.
cMakeCode.pr("# Find threads and link to it");
cMakeCode.pr("find_package(Threads REQUIRED)");
cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE Threads::Threads)");
cMakeCode.newLine();
// If the LF program itself is threaded, we need to define NUMBER_OF_WORKERS so that
// platform-specific C files will contain the appropriate functions
}

// Add additional flags so runtime can distinguish between multi-threaded and single-threaded
// mode
if (targetConfig.threading) {
cMakeCode.pr("# Set the number of workers to enable threading/tracing");
cMakeCode.pr(
"target_compile_definitions(${LF_MAIN_TARGET} PUBLIC NUMBER_OF_WORKERS="
+ targetConfig.workers
+ ")");
cMakeCode.newLine();
}

// Add additional flags so runtime can distinguish between multi-threaded and single-threaded
// mode
if (targetConfig.threading) {
cMakeCode.pr("# Set flag to indicate a multi-threaded runtime");
cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC LF_THREADED=1)");
} else {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/resources/lib/platform/zephyr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Zephyr platform files
These are files needed to compile LF programs for the Zephyr target.
All of the files in the `boards` directory are for enabling a Timer peripheral for different devices so that we can use a Counter device for time-keeping. These device tree config overlays are copied from the `alarm` example found in the zephyr source tree under `samples/drivers/counter/alarm`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Enable RTC
CONFIG_I2C=y
CONFIG_COUNTER=y
CONFIG_COUNTER_MICROCHIP_MCP7940N=y
CONFIG_COUNTER_INIT_PRIORITY=65
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2021 Laird Connectivity
*
* SPDX-License-Identifier: Apache-2.0
*/

&i2c1 {
/* Connect MCP7940N MFP pin TP9 to P0.04 */
extrtc0: mcp7940n@6f {
int-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <29999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <44999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <44999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <26999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <41999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <41999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <49999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <49999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <49999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
*/

&timer0 {
status = "okay";
prescaler = <59999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer1 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&rtc0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer1 {
status = "okay";
};
erlingrj marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&rtc0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2022 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

&stm0 {
prescaler = <1>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2022 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

&stm0 {
prescaler = <1>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
&timers2 {
st,prescaler = <83>;
counter {
status = "okay";
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Copyright (c) 2022 O.S.Systems
#
# SPDX-License-Identifier: Apache-2.0
#
CONFIG_BUILD_WITH_TFM=y
CONFIG_TFM_PROFILE_TYPE_MEDIUM=y
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public enum TestCategory {
ARDUINO(false, "", TestLevel.BUILD),
ZEPHYR_THREADED(false, "zephyr" + File.separator + "threaded", TestLevel.BUILD),
ZEPHYR_UNTHREADED(false, "zephyr" + File.separator + "unthreaded", TestLevel.BUILD),
ZEPHYR_BOARDS(false, "zephyr" + File.separator + "boards", TestLevel.BUILD),
VERIFIER(false, "verifier", TestLevel.EXECUTION),
TARGET(false, "", TestLevel.EXECUTION);

Expand Down
14 changes: 14 additions & 0 deletions test/C/src/zephyr/boards/ArduinoDue.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target C {
platform: {
name: Zephyr,
board: arduino_due
}
}

main reactor {
timer t(0, 1 sec)

reaction(t) {=
printf("Hello\n");
=}
}
14 changes: 14 additions & 0 deletions test/C/src/zephyr/boards/ESP32.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target C {
platform: {
name: Zephyr,
board: esp32
}
}

main reactor {
timer t(0, 1 sec)

reaction(t) {=
printf("Hello\n");
=}
}
14 changes: 14 additions & 0 deletions test/C/src/zephyr/boards/GD32.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target C {
platform: {
name: Zephyr,
board: gd32f403z_eval
}
}

main reactor {
timer t(0, 1 sec)

reaction(t) {=
printf("Hello\n");
=}
}
14 changes: 14 additions & 0 deletions test/C/src/zephyr/boards/NRF52.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target C {
platform: {
name: Zephyr,
board: nrf52dk_nrf52832
}
}

main reactor {
timer t(0, 1 sec)

reaction(t) {=
printf("Hello\n");
=}
}
14 changes: 14 additions & 0 deletions test/C/src/zephyr/boards/NXPIMXRT1170.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target C {
platform: {
name: Zephyr,
board: mimxrt1170_evk_cm7
}
}

main reactor {
timer t(0, 1 sec)

reaction(t) {=
printf("Hello\n");
=}
}
14 changes: 14 additions & 0 deletions test/C/src/zephyr/boards/NXPS32.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target C {
platform: {
name: Zephyr,
board: s32z270dc2_rtu0_r52
}
}

main reactor {
timer t(0, 1 sec)

reaction(t) {=
printf("Hello\n");
=}
}
Loading