2024-01-10 22:08:18 +01:00
|
|
|
{
|
2024-01-12 13:45:05 +01:00
|
|
|
description = "fox32 on FPGA";
|
2024-01-10 22:08:18 +01:00
|
|
|
|
|
|
|
inputs = {
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
|
|
|
flake-utils.lib.eachDefaultSystem (sys:
|
|
|
|
let pkgs = nixpkgs.legacyPackages.${sys};
|
|
|
|
|
|
|
|
verilator = import ./verilator.nix pkgs ;
|
2024-01-17 12:25:36 +01:00
|
|
|
yosys = pkgs.yosys;
|
2024-01-10 22:08:18 +01:00
|
|
|
|
2024-01-21 20:50:47 +01:00
|
|
|
vflags = ''-Wpedantic -Wwarn-lint -Wwarn-style -Wno-PINCONNECTEMPTY -Wno-BLKSEQ -CFLAGS "-Wpedantic -std=c++20"'';
|
2024-01-12 22:32:45 +01:00
|
|
|
|
2024-01-12 13:44:33 +01:00
|
|
|
verilate-src = cmd: ''
|
2024-01-17 13:37:02 +01:00
|
|
|
cp -r ${./src} ./src
|
2024-01-12 13:44:33 +01:00
|
|
|
cp -r ${./simulation} ./simulation
|
2024-01-17 13:37:02 +01:00
|
|
|
find ./src/ -name '*.v' -exec ${verilator}/bin/verilator ${vflags} ${cmd} {} +
|
2024-01-10 22:08:18 +01:00
|
|
|
'';
|
|
|
|
|
2024-01-12 13:44:33 +01:00
|
|
|
lint = pkgs.runCommand "lint" {} ''
|
|
|
|
${verilate-src "--lint-only"}
|
|
|
|
echo "compiler didn't get angry :3"
|
|
|
|
: 3 > $out
|
2024-01-10 22:08:18 +01:00
|
|
|
'';
|
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
alu-test = pkgs.runCommandCC "alu-sim" {} ''
|
2024-01-17 13:37:02 +01:00
|
|
|
${verilate-src "--cc --build --exe ./simulation/tester.cpp ./simulation/test_alu.cpp -top alu"}
|
2024-01-12 13:44:33 +01:00
|
|
|
mv obj_dir "$out"
|
2024-01-21 22:49:32 +01:00
|
|
|
mkdir "$out/bin" && cp "$out/Valu" "$out/bin/alu-test"
|
2024-01-10 22:08:18 +01:00
|
|
|
'';
|
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
alu-test-trace = pkgs.runCommandCC "alu-sim-trace" {} ''
|
2024-01-21 20:49:28 +01:00
|
|
|
${verilate-src "--cc --build --exe --trace -CFLAGS -DTRACE=1 ./simulation/tester.cpp ./simulation/test_alu.cpp -top alu"}
|
|
|
|
mv obj_dir "$out"
|
|
|
|
mkdir "$out/bin" && cp "$out/Valu" "$out/bin/alu-sim"
|
|
|
|
$out/bin/alu-sim $out/trace.vcd
|
|
|
|
echo "${pkgs.gtkwave}/bin/gtkwave $out/trace.vcd" > $out/bin/alu-sim-trace
|
|
|
|
chmod u+x $out/bin/alu-sim-trace
|
|
|
|
'';
|
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
synth = pkgs.runCommandCC "synth" {} ''
|
2024-01-17 12:25:36 +01:00
|
|
|
mkdir -p "$out"
|
2024-01-21 22:39:17 +01:00
|
|
|
find ${./src} -name '*.v' -exec ${yosys}/bin/yosys -f ' -sv' -Q -p "synth_ice40 -top topmost -json $out/synth.json -dsp" {} +
|
2024-01-17 12:25:36 +01:00
|
|
|
'';
|
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
pnr-interactive = pkgs.writeScriptBin "pnr-interactive" ''
|
|
|
|
${pkgs.nextpnrWithGui}/bin/nextpnr-ice40 --up5k --package sg48 --pcf ${./fpga-files/rot.pcf} --json ${synth}/synth.json --gui
|
2024-01-17 12:25:36 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
deps = [
|
2024-01-21 20:49:28 +01:00
|
|
|
yosys pkgs.nextpnrWithGui pkgs.icestorm verilator pkgs.gtkwave
|
2024-01-10 22:08:18 +01:00
|
|
|
];
|
|
|
|
in rec {
|
|
|
|
packages.verilator = verilator;
|
|
|
|
|
2024-01-12 13:44:33 +01:00
|
|
|
packages.lint = lint;
|
2024-01-10 22:08:18 +01:00
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
packages.alu-test = alu-test;
|
|
|
|
packages.alu-test-trace = alu-test-trace;
|
2024-01-21 20:49:28 +01:00
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
packages.synth = synth;
|
|
|
|
packages.pnr-interactive = pnr-interactive;
|
2024-01-17 12:25:36 +01:00
|
|
|
|
2024-01-21 22:49:32 +01:00
|
|
|
devShells.default = pkgs.mkShell { packages = deps; };
|
2024-01-10 22:08:18 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|