Skip to content

Commit b5f23b8

Browse files
committed
Fix most TODOs
1 parent 37bccf2 commit b5f23b8

File tree

1 file changed

+63
-51
lines changed

1 file changed

+63
-51
lines changed

docs/embedded/flexpret.mdx

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,9 @@ description: Developing LF Programs for FlexPRET.
44
---
55
# Overview
66

7-
FlexPRET is a precision-timed (PRET) machine designed for mixed-criticality
8-
systems. As of 2024, PRET machines are an open field of research. Refer to its
9-
[github page](https://github.com/pretis/flexpret) for more in-depth information.
10-
FlexPRET either needs to be emulated or run on a Field-Programmable Gate Array
11-
(FPGA). In this guide we will show you how to pair FlexPRET with Lingua Franca,
12-
leaving you with precise software execution.
13-
14-
As a developer, you should be aware of a significant difference between FlexPRET's
15-
notion of threads versus other platforms. FlexPRET uses fined-grained *hardware*
16-
threads, as opposed to the usual (software) threads. This means that if multiple
17-
threads are running, they can swap every clock cycle. In addition, hardware
18-
threads are designed to be isolated, meaning the execution time of one thread
19-
will not affect the execution time of another, as opposed to concurrent software
20-
threads. Since the threads are implemented in hardware, FlexPRET can only have
21-
a maximum of eight.
22-
23-
# Prerequisites
24-
25-
- cmake
26-
- sbt to build FlexPRET
7+
FlexPRET is a precision-timed (PRET) machine designed for mixed-criticality systems. As of 2024, PRET machines are an open field of research. Refer to its [github page](https://github.com/pretis/flexpret) for more in-depth information. FlexPRET either needs to be emulated or run on a Field-Programmable Gate Array (FPGA). In this guide we will show you how to pair FlexPRET with Lingua Franca, leaving you with precise software execution.
8+
9+
As a developer, you should be aware of a significant difference between FlexPRET's notion of threads versus other platforms. FlexPRET uses fined-grained *hardware* threads, as opposed to the usual (software) threads. This means that if multiple threads are running, they can swap every clock cycle. In addition, hardware threads are designed to be isolated, meaning the execution time of one thread will not affect the execution time of another, as opposed to concurrent software threads. Since the threads are implemented in hardware, FlexPRET can only have a maximum of eight.
2710

2811
# Getting started
2912

@@ -32,7 +15,7 @@ a maximum of eight.
3215
1. We start out by setting up a development environment. Clone the
3316
`lf-flexpret-template` from Github:
3417
```
35-
TODO: Github link with --recurse-submodules
18+
TODO: Github link with --recurse-submodules && cd lf-flexpret-workspace
3619
```
3720
2. Source the `env.bash` or `env.fish` to set up necessary environment variables. You will need to do this every time, so it could be a good idea to add this to your `~/.bashrc`.
3821
```
@@ -46,55 +29,81 @@ source env.fish
4629

4730
3. Now we will build the FlexPRET emulator. Step into the FlexPRET directory and build the default configuration with `cmake`.
4831
```
49-
cd flexpret
32+
cd $FP_PATH
5033
cmake -B build && cd build && make
5134
```
5235

36+
(It is possible to name the build folder something other than `build`, but `bin` is reserved.)
37+
5338
4. You should now install the FlexPRET build to the FlexPRET software development kit (SDK). This provides the SDK with the necessary knowledge of FlexPRET's hardware configuration, such as the amount of data memory available.
5439
```
5540
make install
5641
```
5742

5843
5. Next, step into the SDK and compile it. This step is strictly speaking not necessary, but it is good to know the system works as expected.
5944
```
60-
cd ../sdk
45+
cd $FP_SDK_PATH
6146
cmake -B build && cd build && make && ctest
6247
```
6348

6449
## Lingua Franca on FlexPRET
6550

6651
6. Step back to the top-level directory and compile a sample LF application.
6752
```
68-
lfc src/Test.lf
53+
lfc src/HelloWorld.lf
6954
```
7055

7156
7. Run the compiled program on the FlexPRET emulator.
7257
```
73-
fp-emu +ispm=src-gen/Test/build/Test.mem
58+
./bin/HelloWorld
7459
```
7560

61+
(This is just a `bash` script that runs the emulator and passes the correct program binary file to it underneath the hood.)
62+
7663
8. Verify that you see the expected output
7764
```
78-
TODO: Add expected output
65+
[0]: ---- Start execution ----
66+
[0]: Environment 0: ---- Intializing start tag
67+
[0]: Environment 0: ---- Spawning 1 workers.
68+
[1]: Hello world from FlexPRET
69+
[1]: Goodbye
7970
```
8071

81-
## Building FlexPRET with another configuration
72+
(The `[<n>]` means hardware thread `n` is printing.)
8273

83-
TODO: URL
84-
Refer to the [FlexPRET docs](./flexpret/README.md#Configuration) for more information on how to run a non-default and custom FlexPRET configuration.
74+
# FlexPRET specific features
8575

86-
# FlexPRET on FPGA
76+
Some of FlexPRET's specific features are highlighted in the sample programs. These include `interrupt on expire`, which triggers an interrupt at some scheduled point in time and temporal isolation of hardware threads (i.e., isolated in timing).
8777

88-
TODO: Write
78+
## Interrupt on expire
8979

90-
# FlexPRET specific features
80+
The sample code is available in `src/InterruptExpire.lf`.
81+
82+
Run the application like so:
83+
84+
```
85+
lfc src/InterruptExpire.lf && ./bin/InterruptExpire
86+
```
87+
88+
## Temporal isolation
89+
90+
See `src/multi-threaded/Isolation.lf` for the sample application. The application runs a hardware thread in the background of an LF reactor that triggers every 50 milliseconds. The interrupt handler runs a long `for` loop. On other platforms, the interrupt handler would distrup the timing of the LF reaction. But due to temporal isolation, the LF reaction's timing is unaffected by the interrupts.
9191

92+
Run the application like so:
9293

93-
TODO: Describe and create example program
94-
1. fp_int_on_expire()
95-
2. interrupt temporal isolation
94+
```
95+
lfc src/multi-threaded/Isolation.lf && ./bin/Isolation
96+
```
97+
98+
## Building FlexPRET with another configuration
9699

100+
Refer to the [FlexPRET docs](https://github.com/pretis/flexpret?tab=readme-ov-file#configuration) for more information on how to run a non-default and custom FlexPRET configuration.
97101

102+
# FlexPRET on FPGA
103+
104+
It is possible to realize FlexPRET on a Field-Programmable Gate Array (FPGA). Refer to [the docs](https://github.com/pretis/flexpret?tab=readme-ov-file#running-on-fpga).
105+
106+
Please note that for FPGA, only hardware thread 0 is connected to a UART peripheral, meaning only hardware thread 0 can print using that.
98107

99108
# Troubleshooting
100109

@@ -132,36 +141,39 @@ An error that looks like this means your program (i.e., your instructions) are
132141
too large to fit inside the instruction memory.
133142

134143
```
135-
/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: HelloWorld.riscv section `.text' will not fit in region `ROM'
144+
/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: HelloWorld section `.text' will not fit in region `ROM'
136145
/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: region `ROM' overflowed by 70664 bytes
137146
```
138147

139148
There are two possible solutions to this issue:
140149
1. Reduce the size of your program. `printf` is notorious for taking up a lot of
141-
space, so consider replacing it with a lower footprint version. Tip: To inspect
150+
space, so consider replacing it with a lower footprint version (or nothing at all). Tip: To inspect
142151
what takes up space in your final executible, use `nm`, like so:
143-
`nm HelloWorld.riscv --size-sort`.
144-
2. Increase the size of the instruction memory. This is done in FlexPRET's
145-
configs (see TODO: LINK: ./flexpret/README.md#Configuration). This is easily
146-
done when emulating FlexPRET, but might not be so simple on an FPGA.
152+
`nm HelloWorld --size-sort`.
153+
1. Increase the size of the instruction memory. This is done in FlexPRET's
154+
configs (see [FlexPRET's README](https://github.com/pretis/flexpret?tab=readme-ov-file#configuration)). This is easily
155+
done when emulating FlexPRET, but might not be so simple when realizing the design on an FPGA.
147156

148157
## Bootloader not found
149158

150-
This error should only occur if you have specified `fpga` in the board target
151-
property. It means that you do not have a bootloader installed to the FlexPRET
152-
SDK.
153-
159+
This error should only occur if you have specified `fpga` in the board target property. It means that you do not have not built the bootloader in the FlexPRET SDK.
154160
```
155-
Could not find
156-
/home/magnus/ntnu/mttk/var2024/master/lf-flexpret/flexpret/sdk/flexpret/bootloader.cmake,
157-
which is required to build software for FlexPRET on FPGA using the
158-
bootloader.
161+
/opt/riscv/lib/gcc/riscv32-unknown-elf/11.1.0/../../../../riscv32-unknown-elf/bin/ld: cannot open linker script file bootloader.ld: No such file or directory
159162
```
160163

161-
The solution is to build the SDK; it will build the bootloder and automatically
162-
install it.
164+
The solution is to build the SDK; it will build the bootloder and generate a `bootloader.ld`.
163165

164166
```
165167
cd $FP_SDK_PATH
166168
cmake -B build && cd build && make
167169
```
170+
171+
## Hardware vs. software configuration mismatch
172+
173+
This error occurs if the configuration used to build FlexPRET does not match the hardware configuration installed to FlexPRET's SDK.
174+
175+
```
176+
Reset_Handler: 165: Abort:[0]: Hardware and software configuration mismatch (0xef49961d vs. 0x79d84635)
177+
```
178+
179+
The solution is to rebuild FlexPRET and install its hardware configuration to the SDK with `make install`.

0 commit comments

Comments
 (0)