forked from TinyTapeout/tt07-verilog-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module arbiter ( | ||
input wire out_1, out_2, clk, rst, | ||
output wire resp, finish | ||
); | ||
reg marked_1, marked_2; | ||
|
||
assign win_1 = (out_1 & ~out_2 & ~finish); | ||
assign win_2 = (out_2 & ~out_1 & ~finish); | ||
assign finish = (marked_1 | marked_2); | ||
|
||
always @ (posedge clk) begin | ||
if ((marked_1 == 'x && marked_2 == 'x) || rst) begin | ||
marked_1 = 0; | ||
marked_2 = 0; | ||
end | ||
|
||
if (win_1) begin | ||
resp = 1; | ||
marked_1 = 1; | ||
end | ||
|
||
else if (win_2) begin | ||
resp = 0; | ||
marked_2 = 1; | ||
end | ||
|
||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module counter( | ||
input wire in, clk, rst, | ||
output wire out | ||
); | ||
reg[15:0] ctr; | ||
reg finish; | ||
|
||
assign threshold = 'b11111111_11111111; | ||
assign out = (finish) ? 1 : 0; | ||
|
||
always @ (posedge clk) begin | ||
if (in) begin | ||
ctr = ctr + 1; | ||
end | ||
|
||
if (rst) begin | ||
ctr = 0; | ||
finish = 0; | ||
end | ||
|
||
if (ctr == threshold) begin | ||
finish = 1; | ||
end | ||
end | ||
|
||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module mux_16 ( | ||
input wire[15:0] ro, | ||
input wire[3:0] chall, | ||
output wire out | ||
); | ||
reg sel; | ||
assign out = sel; | ||
|
||
always @ (*) begin | ||
case (chall) | ||
'd0: sel = ro[0]; | ||
'd1: sel = ro[1]; | ||
'd2: sel = ro[2]; | ||
'd3: sel = ro[3]; | ||
'd4: sel = ro[4]; | ||
'd5: sel = ro[5]; | ||
'd6: sel = ro[6]; | ||
'd7: sel = ro[7]; | ||
'd8: sel = ro[8]; | ||
'd9: sel = ro[9]; | ||
'd10: sel = ro[10]; | ||
'd11: sel = ro[11]; | ||
'd12: sel = ro[12]; | ||
'd13: sel = ro[13]; | ||
'd14: sel = ro[14]; | ||
'd15: sel = ro[15]; | ||
default: sel = 'bx; | ||
endcase | ||
end | ||
|
||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module puf_bit( | ||
input wire[7:0] chall, | ||
input wire clk, rst, en, | ||
output wire resp, finish | ||
); | ||
|
||
localparam n_ro = 32; | ||
localparam n_half = n_ro / 2; | ||
|
||
wire[n_ro-1:0] ro_out; | ||
reg[n_ro-1:0] inter_en; | ||
|
||
wire mux_out_1, mux_out_2; | ||
wire ctr_out_1, ctr_out_2; | ||
|
||
assign inter_en[n_ro-1:0] = n_ro'd1; | ||
|
||
ring_osc ro_array_1[n_half-1:0] (inter_en[n_half-1:0], ro_out[n_half-1:0]); | ||
ring_osc ro_array_2[n_half-1:0] (inter_en[n_ro-1:n_half], ro_out[n_ro-1:n_half]); | ||
|
||
mux_16 mux_1(ro_out[n_half-1:0], chall[3:0], mux_out_1); | ||
mux_16 mux_2(ro_out[n_ro-1:n_half], chall[7:4], mux_out_2); | ||
|
||
counter cnt_1(mux_out_1, clk, rst, ctr_out_1); | ||
counter cnt_2(mux_out_2, clk, rst, ctr_out_2); | ||
|
||
arbiter race_arb(cnt_out_1, cnt_out_2, clk, rst, resp, finish); | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
module ring_osc( | ||
input wire en, | ||
output wire out | ||
); | ||
|
||
localparam num_inv = 7; | ||
genvar i; | ||
|
||
wire inter_wire[num_inv:0]; | ||
|
||
generate | ||
for (i = 0; i < num_inv; i = i+1) begin | ||
sky130_fd_sc_hd__inv_2 inv(inter_wire[i], inter_wire[i+1]); | ||
end | ||
endgenerate | ||
|
||
and and_gate(inter_wire[0], out, en); | ||
assign out = inter_wire[num_inv]; | ||
|
||
endmodule | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters