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 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
2 changes: 1 addition & 1 deletion .github/actions/setup-zephyr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
- name: Setup environment variables
run: |
echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV
echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV
echo "ZEPHYR_VERSION=3.4.0" >> $GITHUB_ENV
shell: bash
- name: Dependencies
run: |
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/c-zephyr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
if: ${{ inputs.runtime-ref }}
- name: Run Zephyr smoke tests
run: |
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyr* core:integrationTestCodeCoverageReport
./gradlew core:integrationTest \
--tests org.lflang.tests.runtime.CZephyrTest.buildZephyrUnthreaded* \
--tests org.lflang.tests.runtime.CZephyrTest.buildZephyrThreaded* core:integrationTestCodeCoverageReport
./.github/scripts/run-zephyr-tests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Run basic tests
Expand All @@ -54,6 +56,10 @@ jobs:
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildConcurrent* core:integrationTestCodeCoverageReport
./.github/scripts/run-zephyr-tests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Run Zephyr board tests
run: |
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrBoards* core:integrationTestCodeCoverageReport
rm -r test/C/src-gen
- name: Report to CodeCov
uses: ./.github/actions/report-code-coverage
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private static boolean isExcludedFromCCpp(TestCategory category) {
isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER);
excluded |= category == TestCategory.ZEPHYR_UNTHREADED;
excluded |= category == TestCategory.ZEPHYR_THREADED;
excluded |= category == TestCategory.ZEPHYR_BOARDS;
excluded |= category == TestCategory.ARDUINO;
excluded |= category == TestCategory.NO_INLINING;
excluded |= category == TestCategory.VERIFIER;
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 buildZephyrBoardsTests() {
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
18 changes: 8 additions & 10 deletions core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ CodeBuilder generateCMakeCode(
cMakeCode.pr("# Selecting default board");
cMakeCode.pr("set(BOARD qemu_cortex_m3)");
}
cMakeCode.pr("# We recommend Zephyr v3.3.0 but we are compatible with older versions also");
cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.3.0)");
cMakeCode.pr("# We recommend Zephyr v3.4.0 but we are compatible with older versions also");
cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.4.0)");
cMakeCode.newLine();
cMakeCode.pr("project(" + executableName + " LANGUAGES C)");
cMakeCode.newLine();
Expand Down 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";
};

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 @@ -115,6 +115,7 @@ public static boolean compatibleWithThreadingOff(TestCategory category) {
|| category == TestCategory.ARDUINO
|| category == TestCategory.VERIFIER
|| category == TestCategory.ZEPHYR_UNTHREADED
|| category == TestCategory.ZEPHYR_BOARDS
|| category == TestCategory.ZEPHYR_THREADED;

// SERIALIZATION and TARGET tests are excluded on Windows.
Expand Down
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");
=}
}
Loading
Loading