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

add SystemC example #443

Merged
merged 42 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ef2c56
add systemC tb
davideschiavone Jan 26, 2024
df9e8ff
add systemC target
davideschiavone Feb 2, 2024
59d36a6
fix compilation
davideschiavone Feb 2, 2024
2784110
fix compilation
davideschiavone Feb 2, 2024
8cd358d
improving C++ tb
davideschiavone Feb 2, 2024
6adf95d
improving C++ tb
davideschiavone Feb 2, 2024
82af5c8
add systemC reset cycle
davideschiavone Feb 2, 2024
291e636
wip on traces
davideschiavone Feb 8, 2024
3a77aa2
add vcd waveform
davideschiavone Feb 21, 2024
818e7ed
Merge branch 'esl-epfl:main' into add_systemc_example
davideschiavone Feb 23, 2024
93f4d1d
working tb
davideschiavone Feb 23, 2024
ac0037f
add README
davideschiavone Feb 23, 2024
6f95d21
fix vendor
davideschiavone Feb 23, 2024
90b7914
fix .core
davideschiavone Feb 23, 2024
b47de09
fix Debug doc
davideschiavone Feb 23, 2024
e1ce405
Merge branch 'esl-epfl:main' into add_systemc_example
davideschiavone Feb 26, 2024
dfdf402
add systemc sw target
davideschiavone Feb 28, 2024
0ea25f1
add systemC tlm memory
davideschiavone Feb 29, 2024
5b8a28e
add test in example_dma
davideschiavone Feb 29, 2024
3635d88
fix verible
davideschiavone Mar 1, 2024
13d17c5
start adding cache in sc (untested)
davideschiavone Mar 1, 2024
a43feec
Merge remote-tracking branch 'origin/main' into add_systemc_example
davideschiavone Mar 2, 2024
22895e4
fix cache dump
davideschiavone Mar 3, 2024
9c318d7
fix address in tb
davideschiavone Mar 4, 2024
cb203ca
Fix cache
davideschiavone Mar 4, 2024
7122a44
improve log in Cache
davideschiavone Mar 4, 2024
1374b02
improed functions
davideschiavone Mar 4, 2024
8d928e8
add cache bypass
davideschiavone Mar 4, 2024
9df6df2
fix tb
davideschiavone Mar 5, 2024
65ca611
add new test
davideschiavone Mar 5, 2024
fa7e094
fix new test
davideschiavone Mar 5, 2024
f00bb28
update lib
davideschiavone Mar 5, 2024
0c84ded
adding test (wip)
davideschiavone Mar 5, 2024
f751471
fix app
davideschiavone Mar 6, 2024
578d79e
fix slow memory tb
davideschiavone Mar 6, 2024
5e74249
removed compiled data
davideschiavone Mar 6, 2024
d61646a
revert address change
davideschiavone Mar 6, 2024
300738d
revert again
davideschiavone Mar 6, 2024
ebdb30b
fix cache and test
davideschiavone Mar 7, 2024
e7f0a43
fix cache
davideschiavone Mar 7, 2024
e4151c9
add documentation
davideschiavone Mar 7, 2024
e0f0760
add readme
davideschiavone Mar 7, 2024
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
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ verible:

## Generates the build folder in sw using CMake to build (compile and linking)
## @param PROJECT=<folder_name_of_the_project_to_be_built>
## @param TARGET=sim(default),pynq-z2,nexys-a7-100t
## @param TARGET=sim(default),systemc,pynq-z2,nexys-a7-100t
## @param LINKER=on_chip(default),flash_load,flash_exec
## @param COMPILER=gcc(default), clang
## @param COMPILER_PREFIX=riscv32-unknown-(default)
Expand All @@ -153,10 +153,14 @@ app-compile-all:

## @section Simulation

## Verilator simulation
## Verilator simulation with C++
verilator-sim:
$(FUSESOC) --cores-root . run --no-export --target=sim --tool=verilator $(FUSESOC_FLAGS) --build openhwgroup.org:systems:core-v-mini-mcu ${FUSESOC_PARAM} 2>&1 | tee buildsim.log

## Verilator simulation with SystemC
verilator-sim-sc:
$(FUSESOC) --cores-root . run --no-export --target=sim_sc --tool=verilator $(FUSESOC_FLAGS) --build openhwgroup.org:systems:core-v-mini-mcu ${FUSESOC_PARAM} 2>&1 | tee buildsim.log

## Questasim simulation
questasim-sim:
$(FUSESOC) --cores-root . run --no-export --target=sim --tool=modelsim $(FUSESOC_FLAGS) --build openhwgroup.org:systems:core-v-mini-mcu ${FUSESOC_PARAM} 2>&1 | tee buildsim.log
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ make app
To run any other application, please use the following command with appropiate parameters:

```
app PROJECT=<folder_name_of_the_project_to_be_built> TARGET=sim(default),pynq-z2 LINKER=on_chip(default),flash_load,flash_exec COMPILER=gcc(default),clang COMPILER_PREFIX=riscv32-unknown-(default) ARCH=rv32imc(default),<any RISC-V ISA string supported by the CPU>
app PROJECT=<folder_name_of_the_project_to_be_built> TARGET=sim(default),systemc,pynq-z2,nexys-a7-100t LINKER=on_chip(default),flash_load,flash_exec COMPILER=gcc(default),clang COMPILER_PREFIX=riscv32-unknown-(default) ARCH=rv32imc(default),<any RISC-V ISA string supported by the CPU>

Params:
- PROJECT (ex: <folder_name_of_the_project_to_be_built>, hello_world(default))
Expand Down Expand Up @@ -281,7 +281,7 @@ For example, if you want to set the `FPU` and `COREV_PULP` parameters of the `cv
you need to add next to your compilation command `FUSESOC_PARAM="--COREV_PULP=1 --FPU=1"`
Below the different EDA examples commands.

### Compiling for Verilator
### Compiling for Verilator (C++ testbench)

To simulate your application with Verilator, first compile the HDL:

Expand All @@ -307,6 +307,39 @@ or to execute all these three steps type:
make run-helloworld
```

### Compiling for Verilator (SystemC testbench)

To simulate your application with Verilator using `SystemC`,

make sure you have `SystemC 2.3.3` installed, if not, find it [here](https://www.accellera.org/downloads/standards/systemc).

Make sure to have the following env variables set:

```
export SYSTEMC_INCLUDE=/your_path_to_systemc/systemc/include/
export SYSTEMC_LIBDIR=/your_path_to_systemc/systemc/lib-linux64/
```

Compile the HDL:

```
make verilator-sim-sc
```

then, go to your target system built folder

```
cd ./build/openhwgroup.org_systems_core-v-mini-mcu_0/sim_sc-verilator
```

and type to run your compiled software:

```
./Vtestharness +firmware=../../../sw/build/main.hex
```

If you want to know what is special about the SystemC testbench, have a look [here](./docs/source/How_to/SystemC.md)

### Compiling for VCS

To simulate your application with VCS, first compile the HDL:
Expand Down
50 changes: 50 additions & 0 deletions core-v-mini-mcu.core
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ filesets:

tb-verilator:
files:
- tb/XHEEP_CmdLineOptions.hh: { is_include_file: true }
- tb/XHEEP_CmdLineOptions.cpp
- tb/tb_top.cpp
file_type: cppSource

Expand All @@ -201,6 +203,14 @@ filesets:
- tb/tb_top.sv
file_type: systemVerilogSource

tb-sc-verilator:
files:
- tb/XHEEP_CmdLineOptions.hh: { is_include_file: true }
- tb/XHEEP_CmdLineOptions.cpp
- tb/tb_sc_top.cpp
file_type: cppSource


openroad_base_files:
files:
- flow/OpenROAD-flow-scripts/flow/Makefile : {file_type: Makefile}
Expand Down Expand Up @@ -261,6 +271,10 @@ parameters:
datatype: bool
paramtype: vlogdefine
default: false
SIM_SYSTEMC:
datatype: bool
paramtype: vlogdefine
default: false
FPGA_NEXYS:
datatype: bool
paramtype: vlogdefine
Expand Down Expand Up @@ -301,6 +315,8 @@ targets:
- files_rtl_generic
- target_sim ? (rtl-simulation)
- target_sim ? (tool_verilator? (files_verilator_waiver))
- target_sim_sc ? (rtl-simulation)
- target_sim_sc ? (tool_verilator? (files_verilator_waiver))
toplevel: [core_v_mini_mcu]

sim:
Expand Down Expand Up @@ -392,6 +408,40 @@ targets:
- '-LDFLAGS "-pthread -lutil -lelf"'
- "-Wall"

sim_sc:
<<: *default_target
default_tool: modelsim
filesets_append:
- tb-utils
- tool_verilator? (tb-sc-verilator)
- "!integrated_heep? (x_heep_system)"
toplevel:
- tool_verilator? (testharness)
parameters:
- COREV_PULP
- FPU
- JTAG_DPI
- X_EXT
- USE_EXTERNAL_DEVICE_EXAMPLE
- USE_UPF
- REMOVE_OBI_FIFO
- SIM_SYSTEMC=true
tools:
verilator:
mode: sc
verilator_options:
- '--sc'
- '--trace'
- '--trace-structs'
- '--trace-params'
- '--trace-max-array 1024'
- '--x-assign unique'
- '--x-initial unique'
- '--exe tb_sc_top.cpp'
- '-CFLAGS "-std=c++11 -Wall -g -fpermissive"'
- '-LDFLAGS "-pthread -lutil -lelf $(SYSTEMC_LIBDIR)/libsystemc.a"'
- "-Wall"

nexys-a7-100t:
<<: *default_target
default_tool: vivado
Expand Down
2 changes: 1 addition & 1 deletion docs/source/How_to/Debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Now we are going to Simulate debugging with core-v-mini-mcu.
In this setup, OpenOCD communicates with the remote bitbang server by means of DPIs.
The remote bitbang server is simplemented in the folder ./hw/vendor/pulp_platform_pulpissimo/rtl/tb/remote_bitbang and it will be compiled using fusesoc.

### Verilator
### Verilator (C++ only)

To simulate your application with Questasim using the remote_bitbang server, you need to compile you system adding the `JTAG DPI` functions:

Expand Down
16 changes: 16 additions & 0 deletions docs/source/How_to/SystemC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SystemC model

Supporting SystemC model in `X-HEEP` is still a work-in-progress.
However, a simple example is provided in the SystemC testbench available in `tb/tb_sc_top.cpp`.

When compiling the `X-HEEP` with Verilator using SystemC, the above testbench is used for simulation.
The testbench gets an `X-HEEP` external-memory `obi` master port to communicate with a SystemC memory model.

Such model is very simple as meant to be an example and is provided in `tb/systemc_tb`.
For those who want to extend the functionality of `X-HEEP` with SystemC, such examples can be used as starting point.

The SystemC modules leverages `TLM-2.0` as well as baseline SystemC functionalities.

The `X-HEEP` `obi` port is connected to a `C++` direct-mapped cache who handles `hit` and `miss` with pre-defined latencies.
It uses `TLM-2.0` to communicate with the external SystemC memory on `miss` cache-transactions.
A module in SystemC then communicates with the RTL SystemC model compiled by Verilator to provides read/write data.
35 changes: 22 additions & 13 deletions hw/ip_examples/slow_memory/rtl/slow_memory.sv
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,35 @@ module slow_memory #(


always_comb begin
gnt_o = 1'b0;
rvalid_o = rvalid_q;
state_n = state_q;
counter_n = counter_q - 1;
rvalid_n = rvalid_q;

gnt_o = 1'b0;
rvalid_o = rvalid_q;
state_n = state_q;
counter_n = counter_q - 1;
rvalid_n = rvalid_q;
mem_req = '0;
mem_we = '0;
mem_addr = '0;
mem_wdata = '0;
mem_be = '0;
mem_req_n = mem_req_q;
mem_we_n = mem_we_q;
mem_addr_n = mem_addr_q;
mem_wdata_n = mem_wdata_q;
mem_be_n = mem_be_q;
unique case (state_q)

READY: begin
rvalid_n = 1'b0;
if (req_i) begin
gnt_o = random1[0];
if (gnt_o) begin
state_n = WAIT_RVALID;
counter_n = random2[4:0] + 1;
mem_req_n <= req_i;
mem_we_n <= we_i;
mem_addr_n <= addr_i;
mem_wdata_n <= wdata_i;
mem_be_n <= be_i;
state_n = WAIT_RVALID;
counter_n = random2[4:0] + 1;
mem_req_n = req_i;
mem_we_n = we_i;
mem_addr_n = addr_i;
mem_wdata_n = wdata_i;
mem_be_n = be_i;
end
end
end
Expand Down
1 change: 1 addition & 0 deletions hw/vendor/esl_epfl_cv32e40px.core
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ targets:
- files_rtl
- ff_regfile
- target_sim? (files_clk_gate)
- target_sim_sc? (files_clk_gate)
1 change: 1 addition & 0 deletions hw/vendor/openhwgroup_cv32e20/cve2_top.core
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ targets:
- tool_veriblelint ? (files_lint_verible)
- files_rtl
- target_sim ? (files_clk_gate)
- target_sim_sc ? (files_clk_gate)
toplevel: cve2_top
parameters:
- tool_vivado ? (FPGA_XILINX=true)
Expand Down
1 change: 1 addition & 0 deletions hw/vendor/openhwgroup_cv32e40p.core
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ targets:
- files_rtl
- ff_regfile
- target_sim? (files_clk_gate)
- target_sim_sc? (files_clk_gate)
1 change: 1 addition & 0 deletions hw/vendor/openhwgroup_cv32e40x.core
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ targets:
filesets:
- files_rtl
- target_sim? (files_clk_gate)
- target_sim_sc? (files_clk_gate)
12 changes: 12 additions & 0 deletions hw/vendor/patches/openhwgroup_cv32e20/cv32e20_core.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/cve2_top.core b/cve2_top.core
index cb4e23b4..0d9d2c5c 100644
--- a/cve2_top.core
+++ b/cve2_top.core
@@ -75,6 +75,7 @@ targets:
- tool_veriblelint ? (files_lint_verible)
- files_rtl
- target_sim ? (files_clk_gate)
+ - target_sim_sc ? (files_clk_gate)
toplevel: cve2_top
parameters:
- tool_vivado ? (FPGA_XILINX=true)
1 change: 1 addition & 0 deletions hw/vendor/pulp_platform_gpio.core
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ targets:
- rtl
- "gpio-test? (testbench)"
- target_sim? (clock-gate)
- target_sim_sc? (clock-gate)
- target_asic_synthesis? (clock-gate)
- target_asic_yosys_synthesis? (clock-gate)
- target_nexys-a7-100t? (no-clock-gate)
Expand Down
1 change: 1 addition & 0 deletions hw/vendor/pulp_platform_tech_cells_generic.core
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ targets:
default:
filesets:
- target_sim? (rtl_sim)
- target_sim_sc? (rtl_sim)
4 changes: 2 additions & 2 deletions sw/applications/example_dma/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int main(int argc, char *argv[])

#endif // TEST_ADDRESS_MODE

#ifndef TARGET_PYNQ_Z2
#if defined(TARGET_SIM) || defined(TARGET_SYSTEMC)

#ifdef TEST_ADDRESS_MODE_EXTERNAL_DEVICE

Expand Down Expand Up @@ -275,7 +275,7 @@ int main(int argc, char *argv[])
#endif //TEST_ADDRESS_MODE_EXTERNAL_DEVICE

#else
#pragma message( "TEST_ADDRESS_MODE_EXTERNAL_DEVICE is not executed on PYNQ Z2" )
#pragma message( "TEST_ADDRESS_MODE_EXTERNAL_DEVICE is not executed on target different than TARGET_SIM" )
#endif

#ifdef TEST_PENDING_TRANSACTION
Expand Down
Loading
Loading