1 |
2 |
sinclairrf |
//
|
2 |
|
|
// PERIPHERAL inFIFO_async: @NAME@
|
3 |
10 |
sinclairrf |
// Copyright 2014, Sinclair R.F., Inc.
|
4 |
2 |
sinclairrf |
//
|
5 |
|
|
generate
|
6 |
|
|
// FIFO memory
|
7 |
|
|
reg [7:0] s__fifo[@DEPTH-1@:0];
|
8 |
|
|
// write side of the FIFO
|
9 |
|
|
reg [@DEPTH_NBITS-1@:0] s__ix_in = @DEPTH_NBITS@'h0;
|
10 |
|
|
always @ (posedge i_rst or posedge @INCLK@)
|
11 |
|
|
if (i_rst)
|
12 |
|
|
s__ix_in <= @DEPTH_NBITS@'h0;
|
13 |
|
|
else if (@DATA_WR@) begin
|
14 |
|
|
s__ix_in <= s__ix_in + @DEPTH_NBITS@'d1;
|
15 |
|
|
s__fifo[s__ix_in] <= @DATA@;
|
16 |
|
|
end else
|
17 |
|
|
s__ix_in <= s__ix_in;
|
18 |
|
|
// read side of the FIFO
|
19 |
|
|
reg [@DEPTH_NBITS-1@:0] s__ix_out = @DEPTH_NBITS@'h0;
|
20 |
|
|
always @ (posedge i_clk)
|
21 |
|
|
if (i_rst)
|
22 |
|
|
s__ix_out <= @DEPTH_NBITS@'h0;
|
23 |
|
|
else if (s_inport && (s_T == 8'd@IX_DATA@))
|
24 |
|
|
s__ix_out <= s__ix_out + @DEPTH_NBITS@'d1;
|
25 |
|
|
else
|
26 |
|
|
s__ix_out <= s__ix_out;
|
27 |
|
|
always @ (posedge i_clk)
|
28 |
|
|
s__data <= s__fifo[s__ix_out];
|
29 |
|
|
// empty indication to the micro controller
|
30 |
|
|
// Note: The lag in the "empty" indication is OK because of the minimum 2 clock
|
31 |
|
|
// delay between reading the data and then reading the "empty"
|
32 |
|
|
// indication.
|
33 |
|
|
reg [@DEPTH_NBITS-1@:0] s__ix_in_gray = @DEPTH_NBITS@'h0;
|
34 |
|
|
always @ (posedge @INCLK@)
|
35 |
|
|
s__ix_in_gray <= { 1'b0, s__ix_in[@DEPTH_NBITS-1@:1] } ^ s__ix_in;
|
36 |
|
|
reg [@DEPTH_NBITS-1@:0] s__ix_in_gray_s[2:0];
|
37 |
|
|
always @ (posedge i_clk) begin
|
38 |
|
|
s__ix_in_gray_s[0] <= s__ix_in_gray;
|
39 |
|
|
s__ix_in_gray_s[1] <= s__ix_in_gray_s[0];
|
40 |
|
|
s__ix_in_gray_s[2] <= s__ix_in_gray_s[1];
|
41 |
|
|
end
|
42 |
|
|
genvar ix__clk;
|
43 |
|
|
wire [@DEPTH_NBITS-1@:0] s__ix_in_clk;
|
44 |
|
|
assign s__ix_in_clk[@DEPTH_NBITS-1@] = s__ix_in_gray_s[2][@DEPTH_NBITS-1@];
|
45 |
|
|
for (ix__clk=@DEPTH_NBITS-1@; ix__clk>0; ix__clk=ix__clk-1) begin : gen__ix_in_clk
|
46 |
|
|
assign s__ix_in_clk[ix__clk-1] = s__ix_in_clk[ix__clk] ^ s__ix_in_gray_s[2][ix__clk-1];
|
47 |
|
|
end
|
48 |
|
|
always @ (posedge i_clk)
|
49 |
|
|
s__empty <= (s__ix_in_clk == s__ix_out);
|
50 |
|
|
// full indication to the fabric
|
51 |
|
|
reg [@DEPTH_NBITS-1@:0] s__ix_out_gray = @DEPTH_NBITS@'h0;
|
52 |
|
|
always @ (posedge i_clk)
|
53 |
|
|
s__ix_out_gray <= { 1'b0, s__ix_out[@DEPTH_NBITS-1@:1] } ^ s__ix_out;
|
54 |
|
|
reg [@DEPTH_NBITS-1@:0] s__ix_out_gray_s[2:0];
|
55 |
|
|
always @ (posedge @INCLK@) begin
|
56 |
|
|
s__ix_out_gray_s[0] <= s__ix_out_gray;
|
57 |
|
|
s__ix_out_gray_s[1] <= s__ix_out_gray_s[0];
|
58 |
|
|
s__ix_out_gray_s[2] <= s__ix_out_gray_s[1];
|
59 |
|
|
end
|
60 |
|
|
genvar ix__inclk;
|
61 |
|
|
wire [@DEPTH_NBITS-1@:0] s__ix_out_inclk;
|
62 |
|
|
assign s__ix_out_inclk[@DEPTH_NBITS-1@] = s__ix_out_gray_s[2][@DEPTH_NBITS-1@];
|
63 |
|
|
for (ix__inclk=@DEPTH_NBITS-1@; ix__inclk>0; ix__inclk=ix__inclk-1) begin : gen__ix_out_inclk
|
64 |
|
|
assign s__ix_out_inclk[ix__inclk-1] = s__ix_out_inclk[ix__inclk] ^ s__ix_out_gray_s[2][ix__inclk-1];
|
65 |
|
|
end
|
66 |
|
|
reg [@DEPTH_NBITS-1@:0] s__delta_inclk = @DEPTH_NBITS@'h0;
|
67 |
|
|
always @ (posedge @INCLK@)
|
68 |
|
|
s__delta_inclk <= s__ix_in - s__ix_out_inclk;
|
69 |
|
|
always @ (posedge @INCLK@)
|
70 |
|
|
@DATA_FULL@ <= &s__delta_inclk[@DEPTH_NBITS-1@:3];
|
71 |
|
|
endgenerate
|