aboutsummaryrefslogtreecommitdiffstats
path: root/generic/synth/prims.v
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-04-01 17:44:27 +0100
committerDavid Shah <dave@ds0.me>2019-04-02 15:30:01 +0100
commitf88ddf85b296e486731a79ec2c6fc698169a0657 (patch)
treed692e9ee8afaf1b428e7cfab0bff73b23477ac25 /generic/synth/prims.v
parent50fd8aa01fde3426ff74fcf9b0126a24f279efca (diff)
downloadnextpnr-f88ddf85b296e486731a79ec2c6fc698169a0657.tar.gz
nextpnr-f88ddf85b296e486731a79ec2c6fc698169a0657.tar.bz2
nextpnr-f88ddf85b296e486731a79ec2c6fc698169a0657.zip
generic: Add simple primitive library
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'generic/synth/prims.v')
-rw-r--r--generic/synth/prims.v59
1 files changed, 59 insertions, 0 deletions
diff --git a/generic/synth/prims.v b/generic/synth/prims.v
new file mode 100644
index 00000000..95fcfac7
--- /dev/null
+++ b/generic/synth/prims.v
@@ -0,0 +1,59 @@
+// LUT and DFF are combined to a GENERIC_SLICE
+
+module LUT #(
+ parameter K = 4,
+ parameter [2**K-1:0] INIT = 0,
+) (
+ input [K-1:0] I,
+ output Q
+);
+ assign Q = INIT[I];
+endmodule
+
+module DFF (
+ input CLK, D,
+ output reg Q
+);
+ always @(posedge CLK)
+ Q <= D;
+endmodule
+
+module GENERIC_SLICE #(
+ parameter K = 4,
+ parameter [2**K-1:0] INIT = 0,
+ parameter FF_USED = 1'b0
+) (
+ input CLK,
+ input [K-1:0] I,
+ output Q
+);
+
+ wire lut_q;
+ LUT #(.K(K), .INIT(INIT)) lut_i(.I(I), .Q(lut_q));
+
+ generate if (FF_USED)
+ DFF dff_i(.CLK(CLK), .D(lut_q), .Q(Q));
+ else
+ assign Q = lut_q;
+ endgenerate
+endmodule
+
+module GENERIC_IOB #(
+ parameter INPUT_USED = 1'b0,
+ parameter OUTPUT_USED = 1'b0,
+ parameter ENABLE_USED = 1'b0
+) (
+ inout PAD,
+ input I, EN,
+ output O
+);
+ generate if (OUTPUT_USED && ENABLE_USED)
+ assign PAD = EN ? I : 1'bz;
+ else if (OUTPUT_USED)
+ assign PAD = I;
+ endgenerate
+
+ generate if (INPUT_USED)
+ assign O = PAD;
+ endgenerate
+endmodule \ No newline at end of file