|
| 1 | +--- |
| 2 | +title: Patmos |
| 3 | +description: Developing LF Programs for Patmos. |
| 4 | +--- |
| 5 | +# Overview |
| 6 | +Lingua Franca's C-runtime supports [Patmos](https://github.com/t-crest/patmos), |
| 7 | +a bare-metal execution platform that is optimized for time-predictable execution. |
| 8 | +The time-predictability aspect of Patmos makes it easier to obtain a worst-case |
| 9 | +execution time (WCET) for reactions. |
| 10 | +## Prerequisites |
| 11 | +- Linux or macOS development system. (use WSL on Windows) |
| 12 | +- DE2-115 Development Kit, which is equipped with Altera Cyclone IV FPGA (optional) |
| 13 | +### Getting Started |
| 14 | +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) |
| 15 | +### Compiling and Running Lingua Franca codes |
| 16 | +Patmos can run in an FPGA, but there are also two simulators available: |
| 17 | + |
| 18 | +1. `pasim`: a software ISA simulator that is written in C++. |
| 19 | +2. `patemu`: a cycle-accurate hardware emulator generated from the hardware description. |
| 20 | + |
| 21 | +Consider the following simple LF program inside the HelloPatmos.lf file located in `test/C/src/patmos/HelloPatmos.lf`: |
| 22 | +```lf-c |
| 23 | +target C { |
| 24 | + platform: "Patmos", |
| 25 | + single-threaded: true, |
| 26 | + build-type: Debug, |
| 27 | +} |
| 28 | +
|
| 29 | +main reactor { |
| 30 | + reaction(startup) {= |
| 31 | + printf("Hello World!\n"); |
| 32 | + =} |
| 33 | +} |
| 34 | + |
| 35 | +
|
| 36 | +``` |
| 37 | +You can generate C code using `lfc HelloPatmos.lf` command in the above folder: |
| 38 | + |
| 39 | +``` |
| 40 | +cd test/C/src/patmos/ |
| 41 | +lfc HelloPatmos.lf |
| 42 | +``` |
| 43 | + |
| 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: |
| 45 | + |
| 46 | +``` |
| 47 | +cd ../../src-gen/patmos/HelloPatmos/build |
| 48 | +pasim HelloPatmos |
| 49 | +``` |
| 50 | +After executing the above command, the following lines must be printed. |
| 51 | +``` |
| 52 | +Hello World! |
| 53 | +---- Elapsed logical time (in nsec): 0 |
| 54 | +---- Elapsed physical time (in nsec): 770,000 |
| 55 | +``` |
| 56 | + |
| 57 | +The reactor can also be executed on the hardware emulator of Patmos: |
| 58 | + |
| 59 | +``` |
| 60 | +patemu HelloPatmos |
| 61 | +``` |
| 62 | + |
| 63 | +This execution is considerably slower than the SW simulator, as the concrete hardware |
| 64 | +of Patmos is simulated cycle-accurate. Here is a sample of its output: |
| 65 | + |
| 66 | +``` |
| 67 | +Hello World! |
| 68 | +---- Elapsed logical time (in nsec): 0 |
| 69 | +---- Elapsed physical time (in nsec): 3,459,000 |
| 70 | +``` |
0 commit comments