blinky on icefun
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
*/obj_dir
|
||||||
|
*/build
|
||||||
|
*/*.bin
|
||||||
|
*/*.asc
|
||||||
|
*/*.json
|
||||||
|
|
||||||
1
blinky/.gitignore
vendored
Normal file
1
blinky/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blinky
|
||||||
45
blinky/Makefile
Normal file
45
blinky/Makefile
Normal file
@@ -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/
|
||||||
|
|
||||||
47
blinky/blinky.cpp
Normal file
47
blinky/blinky.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
blinky/blinky.v
Normal file
17
blinky/blinky.v
Normal file
@@ -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
|
||||||
|
|
||||||
5
blinky/iceFUN.pcf
Normal file
5
blinky/iceFUN.pcf
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user