commit 08ff4b2dbb14f5eb398b802dbfb877f89fbc64f3 Author: Nam Tran Date: Mon Oct 12 21:04:59 2020 -0500 blinky on icefun diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25e0f01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*/obj_dir +*/build +*/*.bin +*/*.asc +*/*.json + diff --git a/blinky/.gitignore b/blinky/.gitignore new file mode 100644 index 0000000..7dd399a --- /dev/null +++ b/blinky/.gitignore @@ -0,0 +1 @@ +blinky diff --git a/blinky/Makefile b/blinky/Makefile new file mode 100644 index 0000000..0535e61 --- /dev/null +++ b/blinky/Makefile @@ -0,0 +1,45 @@ +SIM_TARGET = build/blinky +BIN_TARGET = build/blinky.bin +PCF = iceFUN.pcf +YOSYS = yosys +PNR = nextpnr-ice40 +IPACK = icepack +BURN = iceFUNprog + +VERILATOR=verilator +VERILATOR_ROOT ?= $(shell bash -c 'verilator -V|grep VERILATOR_ROOT | head -1 | sed -e "s/^.*=\s*//"') +VINC := $(VERILATOR_ROOT)/include + +.PHONY: all burn +all: $(SIM_TARGET) $(BIN_TARGET) + +# -GWIDTH=5 allows passing parameter to verilog module +obj_dir/Vblinky.cpp: blinky.v + @echo "Running verilator" + @$(VERILATOR) --trace -Wall -GWIDTH=20 -cc blinky.v + +obj_dir/Vblinky__ALL.a: obj_dir/Vblinky.cpp + @make --no-print-directory -C obj_dir -f Vblinky.mk + +# std=c++11 flag is needed from verilator v4.100 +$(SIM_TARGET): blinky.cpp obj_dir/Vblinky__ALL.a + @echo "Compiling simulation executable" + @mkdir -p build + @g++ -I$(VINC) -I obj_dir -std=c++11 $(VINC)/verilated.cpp $(VINC)/verilated_vcd_c.cpp \ + $^ -o $@ + @echo "Run simulation with ./$(TARGET)" + +$(BIN_TARGET): blinky.v $(PCF) + @echo "Building binary stream" + @$(YOSYS) -p "synth_ice40 -top blinky -json build/blinky.json" -q $< + @$(PNR) -r --hx8k --json build/blinky.json --package cb132 \ + --asc build/blinky.asc --opt-timing --pcf $(PCF) -q + @$(IPACK) build/blinky.asc build/blinky.bin + +burn: $(BIN_TARGET) + @$(BURN) $< + +.PHONY: clean +clean: + rm -rf obj_dir/ build/ + diff --git a/blinky/blinky.cpp b/blinky/blinky.cpp new file mode 100644 index 0000000..3de805e --- /dev/null +++ b/blinky/blinky.cpp @@ -0,0 +1,47 @@ +#include +#include +#include "verilated.h" +#include "verilated_vcd_c.h" +#include "Vblinky.h" + +void tick(int tickcount, Vblinky *tb, VerilatedVcdC* tfp) { + tb->eval(); + if (tfp) + tfp->dump(tickcount * 10 - 2); + tb->i_clk = 1; + tb->eval(); + if (tfp) + tfp->dump(tickcount * 10); + tb->i_clk = 0; + tb->eval(); + if (tfp) { + tfp->dump(tickcount * 10 + 5); + tfp->flush(); + } +} + +int main(int argc, char **argv) { + // Call commandArgs first! + Verilated::commandArgs(argc, argv); + + // Instantiate our design + Vblinky *tb = new Vblinky; + Verilated::traceEverOn(true); + VerilatedVcdC* tfp = new VerilatedVcdC; + + tb->trace(tfp, 00); + tfp->open("build/waveform.vcd"); + + unsigned tickcount = 0; + int last_led = tb->o_led; + + for(int k=0; k<(1 << 23); k++) { + tick(++tickcount, tb, tfp); + + if (last_led != tb->o_led) { + printf("k = %7d, led = %d\n", k, tb->o_led); + } + + last_led = tb->o_led; + } +} diff --git a/blinky/blinky.v b/blinky/blinky.v new file mode 100644 index 0000000..dc8a726 --- /dev/null +++ b/blinky/blinky.v @@ -0,0 +1,17 @@ +`default_nettype none + +module blinky(i_clk, o_led, lcol1); + parameter WIDTH = 24; + input wire i_clk; + output wire o_led; + output wire lcol1; + + reg [WIDTH-1:0] counter; + + always @(posedge i_clk) + counter <= counter + 1'b1; + + assign o_led = counter[WIDTH-1]; + assign lcol1 = 1'b0; +endmodule + diff --git a/blinky/iceFUN.pcf b/blinky/iceFUN.pcf new file mode 100644 index 0000000..c84781b --- /dev/null +++ b/blinky/iceFUN.pcf @@ -0,0 +1,5 @@ +# For iceFUN board + +set_io --warn-no-port o_led C10 +set_io --warn-no-port i_clk P7 +set_io --warn-no-port lcol1 A12