From 4c47da1dd8c8cfc2727b4d04196e0ac567a8fd25 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Mon, 11 Mar 2024 16:21:26 -0700 Subject: [PATCH 1/5] Outdated Patmos docs that need to be updated to reflect reactor-c/pull/383 --- docs/embedded/patmos.mdx | 107 +++++++++++++++++++++++++++++++++++++++ docs/sidebars.ts | 6 ++- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 docs/embedded/patmos.mdx diff --git a/docs/embedded/patmos.mdx b/docs/embedded/patmos.mdx new file mode 100644 index 000000000..0b2d56e99 --- /dev/null +++ b/docs/embedded/patmos.mdx @@ -0,0 +1,107 @@ +--- +title: Patmos +description: Developing LF Programs for Patmos. +--- +# Overview +Lingua Franca's C-runtime supports [Patmos](https://github.com/t-crest/patmos), +a bare-metal execution platform that is optimized for time-predictable execution. +The time-predictability aspect of Patmos makes it easier to obtain a worst-case +execution time (WCET) for reactions. + +### Compiling and Running Reactors +Patmos can run in an FPGA, but there are also two +simulators available: + +1. `pasim` a software ISA simulator that is written in C++. +2. `patemu` a cycle-accurate hardware emulator generated from the hardware description. + +To execute reactions on Patmos, the [Patmos toolchain](https://github.com/t-crest/patmos) needs +to be installed. The web page contains a quick start, detailed information including how to +perform WCET analysis is available in the +[Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf). + +To execute the "hello world" reactor on Patmos use the LF compiler to generate the C code. +Compile the reactor with the Patmos compiler (in `src-gen`): + + patmos-clang Minimal.c -o Minimal.elf + +The reactor can be executed on the SW simulator with: + + pasim Minimal.elf + +As Patmos is a bare metal runtime that has no notion of calendar time, its start time +is considered the epoch and the following output will be observed: + +``` +Start execution at time Thu Jan 1 00:00:00 1970 +plus 640000 nanoseconds. +Hello World. +Elapsed logical time (in nsec): 0 +Elapsed physical time (in nsec): 3970000 +``` + +The reactor can also be executed on the hardware emulator of Patmos: + + patemu Minimal.elf + +This execution is considerably slower than the SW simulator, as the concrete hardware +of Patmos is simulated cycle-accurate. + +### Worst-Case Execution Time Analysis + +Following example is a code fragment from +[Wcet.lf](https://github.com/lf-lang/lingua-franca/blob/master/xtext/org.icyphy.linguafranca/src/test/C/src/Wcet.lf). + +```lf-c +reactor Work { + input in1: int; + input in2: int; + output out:int; + reaction(in1, in2) -> out {= + int ret; + if (in1 > 10) { + ret = in2 * in1; + } else { + ret = in2 + in1; + } + lf_set(out, ret); + =} +} +``` + +We want to perform WCET analysis of the single reaction of the Work reactor. +This reaction, depending on the input data, will either perform a multiplication, +which is more expensive in Patmos, or an addition. The WCET analysis shall consider +the multiplication path as the worst-case path. To generate the information for +WCET analysis by the compiler we have to compile the application as follows: + + patmos-clang -O2 -mserialize=wcet.pml Wcet.c + +We investigate the C source code `Wcet.c` and find that the reaction we +are interested is named `reaction_function1`. Therefore, we invoke WCET analysis +as follows: + + platin wcet -i wcet.pml -b a.out -e reaction_function1 --report + +This results in following report: + +``` +... +[platin] INFO: Finished run WCET analysis (platin) in 62 ms +[platin] INFO: best WCET bound: 242 cycles +--- +- analysis-entry: reaction_function1 + source: platin + cycles: 242 +... +``` + +The analysis gives the WCET of 242 clock cycles for the reaction, +which includes clock cycles for data cache misses. +Further details on the WCET analysis +tool `platin` and e.g., how to annotate loop bounds can be found in the +[Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf). + +Note, that the WCET analysis of a reaction does only include the code of the +reaction function, not the cache miss cost of calling the function from +the scheduler or the cache miss cost when returning to the scheduler. \ No newline at end of file diff --git a/docs/sidebars.ts b/docs/sidebars.ts index f13025991..310541eed 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -182,11 +182,15 @@ const sidebars: SidebarsConfig = { }, { "type": "doc", - "id": "embedded/zephyr" + "id": "embedded/patmos" }, { "type": "doc", "id": "embedded/rp2040" + }, + { + "type": "doc", + "id": "embedded/zephyr" } ] }, From 30adc834dd3254e777eab6beb3621222f30d22b0 Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Thu, 2 May 2024 23:06:06 +0200 Subject: [PATCH 2/5] Patmos docs updated to reflect pull 383 --- docs/embedded/patmos.mdx | 166 +++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 78 deletions(-) diff --git a/docs/embedded/patmos.mdx b/docs/embedded/patmos.mdx index 0b2d56e99..b8e246d3d 100644 --- a/docs/embedded/patmos.mdx +++ b/docs/embedded/patmos.mdx @@ -7,101 +7,111 @@ Lingua Franca's C-runtime supports [Patmos](https://github.com/t-crest/patmos), a bare-metal execution platform that is optimized for time-predictable execution. The time-predictability aspect of Patmos makes it easier to obtain a worst-case execution time (WCET) for reactions. - +## Prerequisites +- Linux or macOS development system. (use WSL on Windows) +- DE2-115 Development Kit, which is equipped with Altera Cyclone IV FPGA (optional) +### Getting Started +To know how to install the toolchain for building Patmos, read the Patmos project's readme at https://github.com/t-crest/patmos or study the sixth chapter of its handbook available here: [Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf) ### Compiling and Running Reactors -Patmos can run in an FPGA, but there are also two -simulators available: - -1. `pasim` a software ISA simulator that is written in C++. -2. `patemu` a cycle-accurate hardware emulator generated from the hardware description. - -To execute reactions on Patmos, the [Patmos toolchain](https://github.com/t-crest/patmos) needs -to be installed. The web page contains a quick start, detailed information including how to -perform WCET analysis is available in the -[Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf). - -To execute the "hello world" reactor on Patmos use the LF compiler to generate the C code. -Compile the reactor with the Patmos compiler (in `src-gen`): - - patmos-clang Minimal.c -o Minimal.elf - -The reactor can be executed on the SW simulator with: +Patmos can run in an FPGA, but there are also two simulators available: - pasim Minimal.elf +1. `pasim`: a software ISA simulator that is written in C++. +2. `patemu`: a cycle-accurate hardware emulator generated from the hardware description. -As Patmos is a bare metal runtime that has no notion of calendar time, its start time -is considered the epoch and the following output will be observed: +Consider the following simple LF program inside the HelloWorld.lf file: +```lf-c +target C { + single-threaded: true +} +main reactor { + reaction(startup) {= + lf_print("Hello World!"); + =} +} ``` -Start execution at time Thu Jan 1 00:00:00 1970 -plus 640000 nanoseconds. -Hello World. -Elapsed logical time (in nsec): 0 -Elapsed physical time (in nsec): 3970000 +After generating C code using `lfc HelloWorld.lf` command, add a Makefile file to compile LF-generated code inside `src-gen/HelloWorld` folder. In this Makefile mention the name of all generated c files, and the pathes of all header files. Here is a sample of such a Makefile file: +```Makefile +LF_PROJECT_ROOT ?= $(CURDIR)/../.. +LF_MAIN_TARGET ?= HelloWorld +LF_MAIN_TARGET_LC := $(shell echo $(LF_MAIN_TARGET) | tr '[:upper:]' '[:lower:]') +LIB_PATH := ~/t-crest/local/patmos-unknown-unknown-elf/lib +SERIAL?=/dev/ttyUSB0 + +INCS := -I"$(LF_PROJECT_ROOT)/include" \ + -I"$(LF_PROJECT_ROOT)/include/api" \ + -I"$(LF_PROJECT_ROOT)/include/core" \ + -I"$(LF_PROJECT_ROOT)/include/core/platform" \ + -I"$(LF_PROJECT_ROOT)/include/core/modal_models" \ + -I"$(LF_PROJECT_ROOT)/include/core/utils" \ + +CC := patmos-clang +CFLAGS := -O2 $(INCS) -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10 -DLF_SINGLE_THREADED=0 -DLF_REACTION_GRAPH_BREADTH=1 +SRC_FILES := _$(LF_MAIN_TARGET_LC)_main.c $(LF_MAIN_TARGET).c lib/schedule.c +SRC_FILES += core/reactor_common.c core/lf_token.c core/reactor.c core/tag.c core/environment.c +SRC_FILES += core/utils/util.c core/utils/vector.c +SRC_FILES += core/utils/pqueue.c core/utils/pqueue_tag.c core/utils/pqueue_base.c +SRC_FILES += core/utils/hashset/hashset_itr.c core/utils/hashset/hashset.c +SRC_FILES += core/clock.c core/platform/lf_atomic_patmos.c core/platform/lf_atomic_irq.c +SRC_FILES += core/platform/lf_patmos_support.c + +OBJ_FILES := $(patsubst %.c,%.o,$(SRC_FILES)) +EXE_NAME := $(LF_MAIN_TARGET).elf + +.PHONY: all clean wcet + +all: $(EXE_NAME) + +# Target for the executable +$(EXE_NAME): $(OBJ_FILES) + $(CC) $(CFLAGS) -o $@ $^ +# Rule to compile C files into object files +$(OBJ_FILES): %.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(OBJ_FILES) $(EXE_NAME) + ``` -The reactor can also be executed on the hardware emulator of Patmos: +Then move this Makefile inside the `src-gen/HelloWorld` folder and run the following make command: - patemu Minimal.elf + make -C src-gen/HelloWorld -This execution is considerably slower than the SW simulator, as the concrete hardware -of Patmos is simulated cycle-accurate. +If you are using an older version of LF that doesn't support Patmos, you need to copy `lf_patmos_support` c and h files in the related folders before executing make command whether manually or by executing the following bash file that automates the copying process (considering those files are located in a folder called `files`) -### Worst-Case Execution Time Analysis +```bash +PROJECT_ROOT="$PWD" +PROJECT_NAME="HelloWorld" -Following example is a code fragment from -[Wcet.lf](https://github.com/lf-lang/lingua-franca/blob/master/xtext/org.icyphy.linguafranca/src/test/C/src/Wcet.lf). - -```lf-c -reactor Work { - input in1: int; - input in2: int; - output out:int; - reaction(in1, in2) -> out {= - int ret; - if (in1 > 10) { - ret = in2 * in1; - } else { - ret = in2 + in1; - } - lf_set(out, ret); - =} -} +cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/include/core/platform/" +cp "$PROJECT_ROOT/files/platform.h" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/include/core/" +cp "$PROJECT_ROOT/files/lf_patmos_support.c" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/core/platform/" +cp "$PROJECT_ROOT/files/lf_atomic_patmos.c" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/core/platform/" +cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_ROOT/include/core/platform/" +cp "$PROJECT_ROOT/files/platform.h" "$PROJECT_ROOT/include/core" ``` -We want to perform WCET analysis of the single reaction of the Work reactor. -This reaction, depending on the input data, will either perform a multiplication, -which is more expensive in Patmos, or an addition. The WCET analysis shall consider -the multiplication path as the worst-case path. To generate the information for -WCET analysis by the compiler we have to compile the application as follows: +If there is no error after making, an HelloWorld.elf file must be generator inside `src-gen\HelloWorld` folder. Then, the reactor can be executed on the SW simulator with the following command: - patmos-clang -O2 -mserialize=wcet.pml Wcet.c + pasim src-gen\HelloWorld\HelloWorld.elf -We investigate the C source code `Wcet.c` and find that the reaction we -are interested is named `reaction_function1`. Therefore, we invoke WCET analysis -as follows: +After executing the above command, the following lines must be printed. +``` +Hello World! +---- Elapsed logical time (in nsec): 0 +---- Elapsed physical time (in nsec): 770,000 +``` - platin wcet -i wcet.pml -b a.out -e reaction_function1 --report +The reactor can also be executed on the hardware emulator of Patmos: -This results in following report: + patemu src-gen\helloworld\HelloWorld.elf + +This execution is considerably slower than the SW simulator, as the concrete hardware +of Patmos is simulated cycle-accurate. Here is a sample of its output: ``` -... -[platin] INFO: Finished run WCET analysis (platin) in 62 ms -[platin] INFO: best WCET bound: 242 cycles ---- -- analysis-entry: reaction_function1 - source: platin - cycles: 242 -... +Hello World! +---- Elapsed logical time (in nsec): 0 +---- Elapsed physical time (in nsec): 3,459,000 ``` - -The analysis gives the WCET of 242 clock cycles for the reaction, -which includes clock cycles for data cache misses. -Further details on the WCET analysis -tool `platin` and e.g., how to annotate loop bounds can be found in the -[Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf). - -Note, that the WCET analysis of a reaction does only include the code of the -reaction function, not the cache miss cost of calling the function from -the scheduler or the cache miss cost when returning to the scheduler. \ No newline at end of file From c67b2ee391d891a9a1e4dfb257903d6faa2c5840 Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Fri, 2 Aug 2024 15:58:53 +0200 Subject: [PATCH 3/5] wcet analysis added, upgraded based on the new approach of lf's foldering --- docs/embedded/patmos.mdx | 42 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/docs/embedded/patmos.mdx b/docs/embedded/patmos.mdx index b8e246d3d..2fb742342 100644 --- a/docs/embedded/patmos.mdx +++ b/docs/embedded/patmos.mdx @@ -12,7 +12,7 @@ execution time (WCET) for reactions. - DE2-115 Development Kit, which is equipped with Altera Cyclone IV FPGA (optional) ### Getting Started To know how to install the toolchain for building Patmos, read the Patmos project's readme at https://github.com/t-crest/patmos or study the sixth chapter of its handbook available here: [Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf) -### Compiling and Running Reactors +### Compiling and Running Lingua Franca codes Patmos can run in an FPGA, but there are also two simulators available: 1. `pasim`: a software ISA simulator that is written in C++. @@ -41,10 +41,16 @@ SERIAL?=/dev/ttyUSB0 INCS := -I"$(LF_PROJECT_ROOT)/include" \ -I"$(LF_PROJECT_ROOT)/include/api" \ -I"$(LF_PROJECT_ROOT)/include/core" \ - -I"$(LF_PROJECT_ROOT)/include/core/platform" \ - -I"$(LF_PROJECT_ROOT)/include/core/modal_models" \ - -I"$(LF_PROJECT_ROOT)/include/core/utils" \ - + -I"$(LF_PROJECT_ROOT)/include/$(LF_MAIN_TARGET)" \ + -I"$(CURDIR)/include/$(LF_MAIN_TARGET)" \ + -I"$(CURDIR)/include/core/modal_models" \ + -I"$(CURDIR)/include/core/utils" \ + -I"$(CURDIR)/tag/api"\ + -I"$(CURDIR)/low_level_platform/api" \ + -I"$(CURDIR)/logging/api" \ + -I"$(CURDIR)/version/api" \ + -I"$(CURDIR)/platform/api" \ + CC := patmos-clang CFLAGS := -O2 $(INCS) -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10 -DLF_SINGLE_THREADED=0 -DLF_REACTION_GRAPH_BREADTH=1 SRC_FILES := _$(LF_MAIN_TARGET_LC)_main.c $(LF_MAIN_TARGET).c lib/schedule.c @@ -52,8 +58,8 @@ SRC_FILES += core/reactor_common.c core/lf_token.c core/reactor.c core/tag.c cor SRC_FILES += core/utils/util.c core/utils/vector.c SRC_FILES += core/utils/pqueue.c core/utils/pqueue_tag.c core/utils/pqueue_base.c SRC_FILES += core/utils/hashset/hashset_itr.c core/utils/hashset/hashset.c -SRC_FILES += core/clock.c core/platform/lf_atomic_patmos.c core/platform/lf_atomic_irq.c -SRC_FILES += core/platform/lf_patmos_support.c +SRC_FILES += core/clock.c low_level_platform/impl/src/lf_atomic_patmos.c +SRC_FILES += low_level_platform/impl/src/lf_patmos_support.c OBJ_FILES := $(patsubst %.c,%.o,$(SRC_FILES)) EXE_NAME := $(LF_MAIN_TARGET).elf @@ -64,7 +70,7 @@ all: $(EXE_NAME) # Target for the executable $(EXE_NAME): $(OBJ_FILES) - $(CC) $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ -mserialize=$(PML_FILE_NAME).pml # Rule to compile C files into object files $(OBJ_FILES): %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< @@ -72,24 +78,27 @@ $(OBJ_FILES): %.o: %.c clean: rm -f $(OBJ_FILES) $(EXE_NAME) +wcet: $(EXE_NAME) + platin wcet --disable-ait -i $(PML_FILE_NAME).pml -b $(EXE_NAME) -e _helloworld_mainreaction_function_0 --report report.txt + ``` Then move this Makefile inside the `src-gen/HelloWorld` folder and run the following make command: make -C src-gen/HelloWorld -If you are using an older version of LF that doesn't support Patmos, you need to copy `lf_patmos_support` c and h files in the related folders before executing make command whether manually or by executing the following bash file that automates the copying process (considering those files are located in a folder called `files`) +Since LF still doesn't support Patmos officialy, you need to copy some files inluding `lf_patmos_support` c and h files in the related folders before executing make command whether manually or by executing the following shell file that automates the copying process (considering those files are located in a folder called `files`). If you choose shell file, you can also add Makefile to the list. -```bash +```shell PROJECT_ROOT="$PWD" PROJECT_NAME="HelloWorld" +PROJECT_DIR="$PROJECT_ROOT/src-gen/$PROJECT_NAME" -cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/include/core/platform/" -cp "$PROJECT_ROOT/files/platform.h" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/include/core/" -cp "$PROJECT_ROOT/files/lf_patmos_support.c" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/core/platform/" -cp "$PROJECT_ROOT/files/lf_atomic_patmos.c" "$PROJECT_ROOT/src-gen/$PROJECT_NAME/core/platform/" -cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_ROOT/include/core/platform/" -cp "$PROJECT_ROOT/files/platform.h" "$PROJECT_ROOT/include/core" +cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_DIR/low_level_platform/api/platform/" +cp "$PROJECT_ROOT/files/lf_patmos_support.c" "$PROJECT_DIR/low_level_platform/impl/src/" +cp "$PROJECT_ROOT/files/lf_atomic_patmos.c" "$PROJECT_DIR/low_level_platform/impl/src/" +cp "$PROJECT_ROOT/files/low_level_platform.h" "$PROJECT_DIR/low_level_platform/api/" +cp "$PROJECT_ROOT/files/Makefile" "$PROJECT_DIR" ``` If there is no error after making, an HelloWorld.elf file must be generator inside `src-gen\HelloWorld` folder. Then, the reactor can be executed on the SW simulator with the following command: @@ -115,3 +124,4 @@ Hello World! ---- Elapsed logical time (in nsec): 0 ---- Elapsed physical time (in nsec): 3,459,000 ``` +For doing WCET analysing, you can execute wcet target by running `make wcet` command. \ No newline at end of file From 7c39f5fd6c81c95497902d48a662307eebcc11fe Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Mon, 28 Oct 2024 11:40:08 +0100 Subject: [PATCH 4/5] updated based on cmake approach --- docs/embedded/patmos.mdx | 97 +++++++++------------------------------- 1 file changed, 20 insertions(+), 77 deletions(-) diff --git a/docs/embedded/patmos.mdx b/docs/embedded/patmos.mdx index 2fb742342..b421eec38 100644 --- a/docs/embedded/patmos.mdx +++ b/docs/embedded/patmos.mdx @@ -18,93 +18,35 @@ Patmos can run in an FPGA, but there are also two simulators available: 1. `pasim`: a software ISA simulator that is written in C++. 2. `patemu`: a cycle-accurate hardware emulator generated from the hardware description. -Consider the following simple LF program inside the HelloWorld.lf file: +Consider the following simple LF program inside the HelloPatmos.lf file located in `test/C/src/patmos/HelloPatmos.lf`: ```lf-c target C { - single-threaded: true + platform: "Patmos", + single-threaded: true, + build-type: Debug, } + main reactor { - reaction(startup) {= - lf_print("Hello World!"); - =} + reaction(startup) {= + printf("Hello World!\n"); + =} } + ``` -After generating C code using `lfc HelloWorld.lf` command, add a Makefile file to compile LF-generated code inside `src-gen/HelloWorld` folder. In this Makefile mention the name of all generated c files, and the pathes of all header files. Here is a sample of such a Makefile file: -```Makefile -LF_PROJECT_ROOT ?= $(CURDIR)/../.. -LF_MAIN_TARGET ?= HelloWorld -LF_MAIN_TARGET_LC := $(shell echo $(LF_MAIN_TARGET) | tr '[:upper:]' '[:lower:]') -LIB_PATH := ~/t-crest/local/patmos-unknown-unknown-elf/lib -SERIAL?=/dev/ttyUSB0 - -INCS := -I"$(LF_PROJECT_ROOT)/include" \ - -I"$(LF_PROJECT_ROOT)/include/api" \ - -I"$(LF_PROJECT_ROOT)/include/core" \ - -I"$(LF_PROJECT_ROOT)/include/$(LF_MAIN_TARGET)" \ - -I"$(CURDIR)/include/$(LF_MAIN_TARGET)" \ - -I"$(CURDIR)/include/core/modal_models" \ - -I"$(CURDIR)/include/core/utils" \ - -I"$(CURDIR)/tag/api"\ - -I"$(CURDIR)/low_level_platform/api" \ - -I"$(CURDIR)/logging/api" \ - -I"$(CURDIR)/version/api" \ - -I"$(CURDIR)/platform/api" \ - -CC := patmos-clang -CFLAGS := -O2 $(INCS) -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10 -DLF_SINGLE_THREADED=0 -DLF_REACTION_GRAPH_BREADTH=1 -SRC_FILES := _$(LF_MAIN_TARGET_LC)_main.c $(LF_MAIN_TARGET).c lib/schedule.c -SRC_FILES += core/reactor_common.c core/lf_token.c core/reactor.c core/tag.c core/environment.c -SRC_FILES += core/utils/util.c core/utils/vector.c -SRC_FILES += core/utils/pqueue.c core/utils/pqueue_tag.c core/utils/pqueue_base.c -SRC_FILES += core/utils/hashset/hashset_itr.c core/utils/hashset/hashset.c -SRC_FILES += core/clock.c low_level_platform/impl/src/lf_atomic_patmos.c -SRC_FILES += low_level_platform/impl/src/lf_patmos_support.c - -OBJ_FILES := $(patsubst %.c,%.o,$(SRC_FILES)) -EXE_NAME := $(LF_MAIN_TARGET).elf - -.PHONY: all clean wcet - -all: $(EXE_NAME) +You can generate C code using `lfc HelloPatmos.lf` command in the above folder: -# Target for the executable -$(EXE_NAME): $(OBJ_FILES) - $(CC) $(CFLAGS) -o $@ $^ -mserialize=$(PML_FILE_NAME).pml -# Rule to compile C files into object files -$(OBJ_FILES): %.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -clean: - rm -f $(OBJ_FILES) $(EXE_NAME) - -wcet: $(EXE_NAME) - platin wcet --disable-ait -i $(PML_FILE_NAME).pml -b $(EXE_NAME) -e _helloworld_mainreaction_function_0 --report report.txt - ``` - -Then move this Makefile inside the `src-gen/HelloWorld` folder and run the following make command: - - make -C src-gen/HelloWorld - -Since LF still doesn't support Patmos officialy, you need to copy some files inluding `lf_patmos_support` c and h files in the related folders before executing make command whether manually or by executing the following shell file that automates the copying process (considering those files are located in a folder called `files`). If you choose shell file, you can also add Makefile to the list. - -```shell -PROJECT_ROOT="$PWD" -PROJECT_NAME="HelloWorld" -PROJECT_DIR="$PROJECT_ROOT/src-gen/$PROJECT_NAME" - -cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_DIR/low_level_platform/api/platform/" -cp "$PROJECT_ROOT/files/lf_patmos_support.c" "$PROJECT_DIR/low_level_platform/impl/src/" -cp "$PROJECT_ROOT/files/lf_atomic_patmos.c" "$PROJECT_DIR/low_level_platform/impl/src/" -cp "$PROJECT_ROOT/files/low_level_platform.h" "$PROJECT_DIR/low_level_platform/api/" -cp "$PROJECT_ROOT/files/Makefile" "$PROJECT_DIR" +cd test/C/src/patmos/ +lfc HelloPatmos.lf ``` -If there is no error after making, an HelloWorld.elf file must be generator inside `src-gen\HelloWorld` folder. Then, the reactor can be executed on the SW simulator with the following command: - - pasim src-gen\HelloWorld\HelloWorld.elf +If there is no error after making, an executable file must be generator inside `src-gen/patmos/HelloPatmos` folder. Then, the reactor can be executed on the SW simulator with the following command: +``` +cd ../../src-gen/patmos/HelloPatmos/build +pasim HelloPatmos +``` After executing the above command, the following lines must be printed. ``` Hello World! @@ -114,7 +56,9 @@ Hello World! The reactor can also be executed on the hardware emulator of Patmos: - patemu src-gen\helloworld\HelloWorld.elf +``` +patemu HelloPatmos +``` This execution is considerably slower than the SW simulator, as the concrete hardware of Patmos is simulated cycle-accurate. Here is a sample of its output: @@ -124,4 +68,3 @@ Hello World! ---- Elapsed logical time (in nsec): 0 ---- Elapsed physical time (in nsec): 3,459,000 ``` -For doing WCET analysing, you can execute wcet target by running `make wcet` command. \ No newline at end of file From 1a4e70d20936b4c30853a5933911849bc6c3ad9f Mon Sep 17 00:00:00 2001 From: Ehsan Khodadad Date: Wed, 13 Nov 2024 13:31:15 +0100 Subject: [PATCH 5/5] patmos added to 0.9.0 --- .../version-0.9.0/embedded/patmos.mdx | 70 +++++++++++++++++++ versioned_docs/version-0.9.0/sidebars.ts | 4 ++ .../version-0.9.0-sidebars.json | 4 ++ 3 files changed, 78 insertions(+) create mode 100644 versioned_docs/version-0.9.0/embedded/patmos.mdx diff --git a/versioned_docs/version-0.9.0/embedded/patmos.mdx b/versioned_docs/version-0.9.0/embedded/patmos.mdx new file mode 100644 index 000000000..b421eec38 --- /dev/null +++ b/versioned_docs/version-0.9.0/embedded/patmos.mdx @@ -0,0 +1,70 @@ +--- +title: Patmos +description: Developing LF Programs for Patmos. +--- +# Overview +Lingua Franca's C-runtime supports [Patmos](https://github.com/t-crest/patmos), +a bare-metal execution platform that is optimized for time-predictable execution. +The time-predictability aspect of Patmos makes it easier to obtain a worst-case +execution time (WCET) for reactions. +## Prerequisites +- Linux or macOS development system. (use WSL on Windows) +- DE2-115 Development Kit, which is equipped with Altera Cyclone IV FPGA (optional) +### Getting Started +To know how to install the toolchain for building Patmos, read the Patmos project's readme at https://github.com/t-crest/patmos or study the sixth chapter of its handbook available here: [Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf) +### Compiling and Running Lingua Franca codes +Patmos can run in an FPGA, but there are also two simulators available: + +1. `pasim`: a software ISA simulator that is written in C++. +2. `patemu`: a cycle-accurate hardware emulator generated from the hardware description. + +Consider the following simple LF program inside the HelloPatmos.lf file located in `test/C/src/patmos/HelloPatmos.lf`: +```lf-c +target C { + platform: "Patmos", + single-threaded: true, + build-type: Debug, +} + +main reactor { + reaction(startup) {= + printf("Hello World!\n"); + =} +} + + +``` +You can generate C code using `lfc HelloPatmos.lf` command in the above folder: + +``` +cd test/C/src/patmos/ +lfc HelloPatmos.lf +``` + +If there is no error after making, an executable file must be generator inside `src-gen/patmos/HelloPatmos` folder. Then, the reactor can be executed on the SW simulator with the following command: + +``` +cd ../../src-gen/patmos/HelloPatmos/build +pasim HelloPatmos +``` +After executing the above command, the following lines must be printed. +``` +Hello World! +---- Elapsed logical time (in nsec): 0 +---- Elapsed physical time (in nsec): 770,000 +``` + +The reactor can also be executed on the hardware emulator of Patmos: + +``` +patemu HelloPatmos +``` + +This execution is considerably slower than the SW simulator, as the concrete hardware +of Patmos is simulated cycle-accurate. Here is a sample of its output: + +``` +Hello World! +---- Elapsed logical time (in nsec): 0 +---- Elapsed physical time (in nsec): 3,459,000 +``` diff --git a/versioned_docs/version-0.9.0/sidebars.ts b/versioned_docs/version-0.9.0/sidebars.ts index 42ef82c92..cde372c60 100644 --- a/versioned_docs/version-0.9.0/sidebars.ts +++ b/versioned_docs/version-0.9.0/sidebars.ts @@ -176,6 +176,10 @@ const sidebars: SidebarsConfig = { "type": "doc", "id": "embedded/arduino" }, + { + "type": "doc", + "id": "embedded/patmos" + }, { "type": "doc", "id": "embedded/zephyr" diff --git a/versioned_sidebars/version-0.9.0-sidebars.json b/versioned_sidebars/version-0.9.0-sidebars.json index a5a5ab3e1..9da5c6d87 100644 --- a/versioned_sidebars/version-0.9.0-sidebars.json +++ b/versioned_sidebars/version-0.9.0-sidebars.json @@ -162,6 +162,10 @@ "type": "doc", "id": "embedded/arduino" }, + { + "type": "doc", + "id": "embedded/patmos" + }, { "type": "doc", "id": "embedded/zephyr"