This project is a demonstration of how to use a composable, cross-language messaging library (written using Bluespec generics) to connect a simple host application to an FPGA.
This code was written as part of a 2020 Google internship.
See CONTRIBUTING.md
for details.
Apache 2.0; see LICENSE
for details.
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.
- Install bsc
- Clone the bsc-contrib repository in the same top-level directory as this one
$ git clone https://github.com/b-lang-org/bsc-contrib
- Install required python libraries
$ python3 -m pip install pyserial cffi eventfd cobs
On some systems you may need to manually install tkinter as well
$ sudo apt install python3-tk
- Build everything by running
make
. This will- Compile the Bluespec source files and libraries
- Generate Verilog for the top-level
mkTop
module specified inDemo.bs
- Generate demo message library C source and header files
demo.c
anddemo.h
- Build a Python FFI wrapper module
_demo
for the C message library - Generate a Bluesim simulator for the top-level
sysDemoSim
module specified inDemoSim.bs
- Generate C source and header files for an additional message library used by the simulator interface,
demo_sim.c
anddemo_sim.h
- Build a corresponding Python FFI wrapper module
_demo_sim
- Run
./sysDemoSim.out
to start the simulator; this will print the name of the simulated serial device and launch a graphical interface with mock LEDs and buttons.
$ ./sysDemoSim.out
Initialized simulated serial device at /dev/pts/44
- Launch the host application with the specified device
./app.py /dev/pts/44
- Try
- Enter numbers in the host application to change the counter values
- Select colors in the host application to change the LED colors in the simulator interface
- Click the buttons in the simulator interface to trigger a popup in the host application
- When finished, closing the host application should also cause the simulator to exit.
- Alternatively, the
counter_test.py
,rgb_test.py
andbutton_test.py
scripts can be run to exercise each feature of the design.
The design can also be run in hardware on an Arty A7 FPGA board.
- Install Vivado and the Digilent board files. Note that there are multiple versions available; ensure that the installed version supports Xilinx FPGAs.
- Open the
bs-generics-demo.xpr
project file in Vivado - Generate a bitstream file and program the device. A serial device corresponding to the FPGA board should appear, e.g.
/dev/ttyUSB1
- Run any of the host application scripts using the serial device
./app.py /dev/ttyUSB1