From a7b238e07f8a1a4ea35b81beddd70693fa4eb438 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 23 Aug 2007 03:28:16 +0100 Subject: [PATCH] use Generator to produce root.v --- src/edu/berkeley/fleet/fpga/Generator.java | 31 +++++++++++++ src/edu/berkeley/fleet/fpga/root.v | 67 ---------------------------- 2 files changed, 31 insertions(+), 67 deletions(-) delete mode 100644 src/edu/berkeley/fleet/fpga/root.v diff --git a/src/edu/berkeley/fleet/fpga/Generator.java b/src/edu/berkeley/fleet/fpga/Generator.java index 8053896..8cd21cc 100644 --- a/src/edu/berkeley/fleet/fpga/Generator.java +++ b/src/edu/berkeley/fleet/fpga/Generator.java @@ -426,6 +426,37 @@ public class Generator { Module fifoship = mkfifo("fifo", 4, fifo4, prefix); mkBox("outbox", false, prefix, fifo4); mkBox("inbox", true, prefix, fifo4); + + Module fabric = new Module("fabric"); + fabric.createInputPort("horn_in", WIDTH_PACKET); + fabric.createOutputPort("funnel_out", WIDTH_PACKET, ""); + mkRoot("root", prefix, fabric); + } + + private static Module mkRoot(String name, String prefix, Module fabricm) throws Exception { + Module root = new Module(name); + Module.SourcePort in = root.createInputPort("in", 8); + Module.SinkPort out = root.createOutputPort("out", 8, ""); + Module.InstantiatedModule fabric = root.new InstantiatedModule(fabricm); + Module.SinkPort fabric_in = fabric.getInputPort("horn_in"); + Module.SourcePort fabric_out = fabric.getOutputPort("funnel_out"); + Module.Latch count = root.new Latch("count", 8); + Module.Latch count_out = root.new Latch("count_out", 8); + root.addPreCrap("initial count = 0;"); + root.addPreCrap("initial count_out = 0;"); + root.new Event(new Object[] { in, fabric_in }, + new Object[] { new SimpleAction(fabric_in.getName()+" <= ("+fabric_in.getName()+" << 8) | in;"), + new SimpleAction("if (count >= 5) begin count <= 0; "+fabric_in.getName()+"_r <= 1; end else count <= count+1; "), + in + }); + root.new Event(new Object[] { out, fabric_out }, + new Object[] { new SimpleAction(out.getName()+" <= ("+fabric_out.getName()+">> (count_out*8));"), + new SimpleAction("if (count_out >= 5) begin count_out <= 0; "+fabric_out.getName()+"_a <= 1; end else count_out <= count_out+1; "), + out }); + PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(prefix+"/"+name+".v"))); + root.dump(pw); + pw.flush(); + return root; } private static Module mkfunnel(String name, String prefix) throws Exception { diff --git a/src/edu/berkeley/fleet/fpga/root.v b/src/edu/berkeley/fleet/fpga/root.v deleted file mode 100644 index caa3041..0000000 --- a/src/edu/berkeley/fleet/fpga/root.v +++ /dev/null @@ -1,67 +0,0 @@ -`include "macros.v" - -module root(clk, in_r, in_a_, in_d, - out_r_, out_a, out_d_); - - input clk; - - `input(in_r, in_a, in_a_, [7:0], in_d) - `output(out_r, out_r_, out_a, [7:0], out_d_) - - `defreg(horn_in_r_, [0:0], horn_in_r) - `defreg(horn_in_d_, [(`PACKET_WIDTH-1):0], horn_in_d) - `defreg(funnel_out_a_, [0:0], funnel_out_a) - - reg [(`DATAWIDTH-1):0] out_d; - assign out_d_ = out_d[7:0]; - - reg [7:0] count_in; - reg [7:0] count_out; - reg full_in; - reg full_out; - - initial full_in = 0; - initial count_in = 0; - initial full_out = 0; - initial count_out = 0; - - wire [(`DATAWIDTH-1):0] funnel_out_d; - fabric fabric(clk, horn_in_r_, horn_in_a, horn_in_d_, - funnel_out_r, funnel_out_a_, funnel_out_d); - - // host -> fpga - always @(posedge clk) begin - if (!full_in) begin - `onread(in_r, in_a) - horn_in_d = (horn_in_d << 8) | in_d; - count_in = count_in + 1; - if (count_in >= 6) full_in = 1; - end - end else begin - if (full_in) begin - `onwrite(horn_in_r, horn_in_a) - full_in = 0; - count_in = 0; - end - end - end - end - - // fpga -> host - always @(posedge clk) begin - if (!full_out) begin - `onread(funnel_out_r, funnel_out_a) - full_out = 1; - count_out = 6; - out_d = funnel_out_d; - end - end else begin - `onwrite(out_r, out_a) - out_d = out_d >> 8; - count_out = count_out - 1; - if (count_out==0) full_out = 0; - end - end - end - -endmodule -- 1.7.10.4