Update Sampler.v, moving clock domain crossing to FIFO interface.

Hopefully, I unscrewed the tab/space and line ending mismatches to minimize the diff.
This commit is contained in:
Jared Boone
2020-05-30 21:31:17 -07:00
parent adb9809692
commit db2ab8841a

View File

@@ -8,7 +8,7 @@
module Sampler ( module Sampler (
output [2:0] debug_state, output [2:0] debug_state,
output reg [7:0] opcode, output reg [7:0] opcode,
output reg req, output reg req,
input clock, input clock,
input index, input index,
input rdata, input rdata,
@@ -18,63 +18,65 @@ module Sampler (
//`#start body` -- edit after this line, do not edit this line //`#start body` -- edit after this line, do not edit this line
// NOTE: Reset pulse is used in both clock domains, and must be long enough
// to be detected in both.
reg [5:0] counter; reg [5:0] counter;
reg sampleclock_q;
reg index_q; reg index_q;
reg rdata_q; reg rdata_q;
reg sampleclock_edge;
reg index_edge; reg index_edge;
reg rdata_edge; reg rdata_edge;
always @(posedge clock) reg req_toggle;
always @(posedge sampleclock)
begin begin
if (reset) if (reset)
begin begin
sampleclock_edge <= 0;
index_edge <= 0; index_edge <= 0;
rdata_edge <= 0; rdata_edge <= 0;
sampleclock_q <= 0;
index_q <= 0; index_q <= 0;
rdata_q <= 0; rdata_q <= 0;
counter <= 0; counter <= 0;
req_toggle <= 0;
end end
else else
begin begin
/* Remember positive egdes for sampleclock, index and rdata. */ /* Both index and rdata are active high -- positive-going edges
* indicate the start of an index pulse and read pulse, respectively.
/* Positive-going edge detection of 16 MHz square-wave sample clock vs.
* 64 MHz clock.
*/ */
sampleclock_edge <= sampleclock && !sampleclock_q;
sampleclock_q <= sampleclock; index_edge <= index && !index_q;
index_q <= index;
/* Request to write FIFO is inactive by default */ rdata_edge <= rdata && !rdata_q;
req <= 0; rdata_q <= rdata;
if (sampleclock_edge) begin if (rdata_edge || index_edge || (counter == 6'h3f)) begin
/* Both index and rdata are active high -- positive-going edges opcode <= { rdata_edge, index_edge, counter };
* indicate the start of an index pulse and read pulse, respectively. req_toggle <= ~req_toggle;
*/ counter <= 1; /* remember to count this tick */
end else begin
index_edge <= index && !index_q; counter <= counter + 1;
index_q <= index;
rdata_edge <= rdata && !rdata_q;
rdata_q <= rdata;
if (rdata_edge || index_edge || (counter == 6'h3f)) begin
opcode <= { rdata_edge, index_edge, counter };
req <= 1;
counter <= 1;
end else begin
counter <= counter + 1;
end
end end
end end
end end
reg req_toggle_q;
always @(posedge clock)
begin
if (reset) begin
req_toggle_q <= 0;
req <= 0;
end else begin
req_toggle_q <= req_toggle;
req <= (req_toggle != req_toggle_q);
end
end
//`#end` -- edit above this line, do not edit this line //`#end` -- edit above this line, do not edit this line
endmodule endmodule
//`#start footer` -- edit after this line, do not edit this line //`#start footer` -- edit after this line, do not edit this line