Skip to content

Commit 7c39f5f

Browse files
committed
updated based on cmake approach
1 parent c67b2ee commit 7c39f5f

File tree

1 file changed

+20
-77
lines changed

1 file changed

+20
-77
lines changed

docs/embedded/patmos.mdx

+20-77
Original file line numberDiff line numberDiff line change
@@ -18,93 +18,35 @@ Patmos can run in an FPGA, but there are also two simulators available:
1818
1. `pasim`: a software ISA simulator that is written in C++.
1919
2. `patemu`: a cycle-accurate hardware emulator generated from the hardware description.
2020

21-
Consider the following simple LF program inside the HelloWorld.lf file:
21+
Consider the following simple LF program inside the HelloPatmos.lf file located in `test/C/src/patmos/HelloPatmos.lf`:
2222
```lf-c
2323
target C {
24-
single-threaded: true
24+
platform: "Patmos",
25+
single-threaded: true,
26+
build-type: Debug,
2527
}
28+
2629
main reactor {
27-
reaction(startup) {=
28-
lf_print("Hello World!");
29-
=}
30+
reaction(startup) {=
31+
printf("Hello World!\n");
32+
=}
3033
}
34+
3135
3236
```
33-
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:
34-
```Makefile
35-
LF_PROJECT_ROOT ?= $(CURDIR)/../..
36-
LF_MAIN_TARGET ?= HelloWorld
37-
LF_MAIN_TARGET_LC := $(shell echo $(LF_MAIN_TARGET) | tr '[:upper:]' '[:lower:]')
38-
LIB_PATH := ~/t-crest/local/patmos-unknown-unknown-elf/lib
39-
SERIAL?=/dev/ttyUSB0
40-
41-
INCS := -I"$(LF_PROJECT_ROOT)/include" \
42-
-I"$(LF_PROJECT_ROOT)/include/api" \
43-
-I"$(LF_PROJECT_ROOT)/include/core" \
44-
-I"$(LF_PROJECT_ROOT)/include/$(LF_MAIN_TARGET)" \
45-
-I"$(CURDIR)/include/$(LF_MAIN_TARGET)" \
46-
-I"$(CURDIR)/include/core/modal_models" \
47-
-I"$(CURDIR)/include/core/utils" \
48-
-I"$(CURDIR)/tag/api"\
49-
-I"$(CURDIR)/low_level_platform/api" \
50-
-I"$(CURDIR)/logging/api" \
51-
-I"$(CURDIR)/version/api" \
52-
-I"$(CURDIR)/platform/api" \
53-
54-
CC := patmos-clang
55-
CFLAGS := -O2 $(INCS) -DINITIAL_EVENT_QUEUE_SIZE=10 -DINITIAL_REACT_QUEUE_SIZE=10 -DLF_SINGLE_THREADED=0 -DLF_REACTION_GRAPH_BREADTH=1
56-
SRC_FILES := _$(LF_MAIN_TARGET_LC)_main.c $(LF_MAIN_TARGET).c lib/schedule.c
57-
SRC_FILES += core/reactor_common.c core/lf_token.c core/reactor.c core/tag.c core/environment.c
58-
SRC_FILES += core/utils/util.c core/utils/vector.c
59-
SRC_FILES += core/utils/pqueue.c core/utils/pqueue_tag.c core/utils/pqueue_base.c
60-
SRC_FILES += core/utils/hashset/hashset_itr.c core/utils/hashset/hashset.c
61-
SRC_FILES += core/clock.c low_level_platform/impl/src/lf_atomic_patmos.c
62-
SRC_FILES += low_level_platform/impl/src/lf_patmos_support.c
63-
64-
OBJ_FILES := $(patsubst %.c,%.o,$(SRC_FILES))
65-
EXE_NAME := $(LF_MAIN_TARGET).elf
66-
67-
.PHONY: all clean wcet
68-
69-
all: $(EXE_NAME)
37+
You can generate C code using `lfc HelloPatmos.lf` command in the above folder:
7038

71-
# Target for the executable
72-
$(EXE_NAME): $(OBJ_FILES)
73-
$(CC) $(CFLAGS) -o $@ $^ -mserialize=$(PML_FILE_NAME).pml
74-
# Rule to compile C files into object files
75-
$(OBJ_FILES): %.o: %.c
76-
$(CC) $(CFLAGS) -c -o $@ $<
77-
78-
clean:
79-
rm -f $(OBJ_FILES) $(EXE_NAME)
80-
81-
wcet: $(EXE_NAME)
82-
platin wcet --disable-ait -i $(PML_FILE_NAME).pml -b $(EXE_NAME) -e _helloworld_mainreaction_function_0 --report report.txt
83-
8439
```
85-
86-
Then move this Makefile inside the `src-gen/HelloWorld` folder and run the following make command:
87-
88-
make -C src-gen/HelloWorld
89-
90-
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.
91-
92-
```shell
93-
PROJECT_ROOT="$PWD"
94-
PROJECT_NAME="HelloWorld"
95-
PROJECT_DIR="$PROJECT_ROOT/src-gen/$PROJECT_NAME"
96-
97-
cp "$PROJECT_ROOT/files/lf_patmos_support.h" "$PROJECT_DIR/low_level_platform/api/platform/"
98-
cp "$PROJECT_ROOT/files/lf_patmos_support.c" "$PROJECT_DIR/low_level_platform/impl/src/"
99-
cp "$PROJECT_ROOT/files/lf_atomic_patmos.c" "$PROJECT_DIR/low_level_platform/impl/src/"
100-
cp "$PROJECT_ROOT/files/low_level_platform.h" "$PROJECT_DIR/low_level_platform/api/"
101-
cp "$PROJECT_ROOT/files/Makefile" "$PROJECT_DIR"
40+
cd test/C/src/patmos/
41+
lfc HelloPatmos.lf
10242
```
10343

104-
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:
105-
106-
pasim src-gen\HelloWorld\HelloWorld.elf
44+
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:
10745

46+
```
47+
cd ../../src-gen/patmos/HelloPatmos/build
48+
pasim HelloPatmos
49+
```
10850
After executing the above command, the following lines must be printed.
10951
```
11052
Hello World!
@@ -114,7 +56,9 @@ Hello World!
11456

11557
The reactor can also be executed on the hardware emulator of Patmos:
11658

117-
patemu src-gen\helloworld\HelloWorld.elf
59+
```
60+
patemu HelloPatmos
61+
```
11862

11963
This execution is considerably slower than the SW simulator, as the concrete hardware
12064
of Patmos is simulated cycle-accurate. Here is a sample of its output:
@@ -124,4 +68,3 @@ Hello World!
12468
---- Elapsed logical time (in nsec): 0
12569
---- Elapsed physical time (in nsec): 3,459,000
12670
```
127-
For doing WCET analysing, you can execute wcet target by running `make wcet` command.

0 commit comments

Comments
 (0)