Skip to the content.

SystemC CoSimulation

This section introduces how to simulate both an ARM processor as well custom hardware in SystemC. It is based on Xilinx Co-Simulation, please see the wiki for more detailed informaiton.

Prerequisites:

1. Compiling and Launching CoSimulation

1.1 Building the Hardware Model

Open a new terminal (lets call it HW) for SystemC compilation, clone and build the co-simulation demo (ie. the lab2 code).

git clone --recurse-submodules ${YOUR_LAB_REPO_URL}
cd ${YOUR_LAB_REPO_NAME}/hw
make 

This compiles the hardware model.

Create the directory which will contain the sockets for QEMU / SystemC communication.

mkdir ~/.cosim 

1.2 Start QEMU

Open a new terminal on the same host. Lets call this QEMU terminal.

Activate the SDK environment with setup-xarm.

Launch QEMU with the co-simulation option --cosim from the base directory of your example.

qemu-esl --cosim

QEMU will start and wait for the SystemC simulation to connect to it.

1.3 Start Hardware Simulation

In the terminal we used for HW compilation (i.e. HW terminal) start the cosimulation hardware portion.

make launch_cosim

Once the SystemC binary is launched, QEMU starts booting the Linux Kernel.

Be aware that while co-simulating, QEMU slows down considerably.

1.4 Compiling the SW Code

Open a third terminal (lets call it xcompile) on the same host as the other two terminals (HW, QEMU).

Activate the SDK environment with setup-xarm.

Compile and upload the binary (the upload target first compiles and then copies to the QEMU target.

cd sw
make upload

1.5 Run Code on QEMU

Finally, execute the application code on QEMU to talk to the SystemC simulated devices.

In the QEMU terminal, login to the simulated ARM instance with the username root (no password).

Validate that program upload worked and start the debugread program.

root@zedboard-esl:~# ls
debugread
root@zedboard-esl:~# ./debugread

With these steps you got the cosimulation running. Enjoy.

HINT: Want to even faster setup the cosimulation? Checkout the tmux script for cosimulation

2. Co-simulation Timing

QEMU and SystemC share simulation timing. The simulation timing resolution is called quantum. The default quantum is

  1. When launching the SystemC simulation, verify that the correct quantum value is used.

The quantum value for QEMU is defined by the ESL_QEMU_QUANTUM environment variable in the SDK environment.

3. Co-simulation Code Walkthrough

Take a look at the cosim walk through for an explanation on the different pieces of the cosim enviornment as well as how they interact with each other through TLM.

4. VCD Tracing of Target Traffic

Unfortunately tracing TLM traffic is not directly supported (e.g. discussion. Additional tools are needed for tracing. To minimize the installation effort, we can just add additional signals that will appear in the VCD trace. See TargetTLMTrace.