|
| 1 | +//----------------------------------------------------------------------------- |
| 2 | +// Copyright 2017 Damien Pretet ThotIP |
| 3 | +// Copyright 2018 Julius Baxter |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | +//----------------------------------------------------------------------------- |
| 17 | + |
| 18 | +`timescale 1 ns / 1 ps |
| 19 | +`default_nettype none |
| 20 | + |
| 21 | +module async_bidir_ramif_fifo |
| 22 | + |
| 23 | + #( |
| 24 | + parameter DSIZE = 8, |
| 25 | + parameter ASIZE = 4, |
| 26 | + parameter FALLTHROUGH = "FALSE" // First word fall-through, not sure it can be disabled for this |
| 27 | + ) ( |
| 28 | + input wire a_clk, |
| 29 | + input wire a_rst_n, |
| 30 | + input wire a_winc, |
| 31 | + input wire [DSIZE-1:0] a_wdata, |
| 32 | + input wire a_rinc, |
| 33 | + output wire [DSIZE-1:0] a_rdata, |
| 34 | + output wire a_full, |
| 35 | + output wire a_afull, |
| 36 | + output wire a_empty, |
| 37 | + output wire a_aempty, |
| 38 | + input wire a_dir, // dir = 1: this side is writing, dir = 0: this side is reading |
| 39 | + |
| 40 | + |
| 41 | + input wire b_clk, |
| 42 | + input wire b_rst_n, |
| 43 | + input wire b_winc, |
| 44 | + input wire [DSIZE-1:0] b_wdata, |
| 45 | + input wire b_rinc, |
| 46 | + output wire [DSIZE-1:0] b_rdata, |
| 47 | + output wire b_full, |
| 48 | + output wire b_afull, |
| 49 | + output wire b_empty, |
| 50 | + output wire b_aempty, |
| 51 | + input wire b_dir, // dir = 1: this side is writing, dir = 0: this side is reading |
| 52 | + |
| 53 | + // Dual-port RAM interface |
| 54 | + output wire o_ram_a_clk, |
| 55 | + output wire [DSIZE-1:0] o_ram_a_wdata, |
| 56 | + input wire [DSIZE-1:0] i_ram_a_rdata, |
| 57 | + output wire [ASIZE-1:0] o_ram_a_addr, |
| 58 | + output wire o_ram_a_rinc, |
| 59 | + output wire o_ram_a_winc, |
| 60 | + output wire o_ram_b_clk, |
| 61 | + output wire [DSIZE-1:0] o_ram_b_wdata, |
| 62 | + input wire [DSIZE-1:0] i_ram_b_rdata, |
| 63 | + output wire [ASIZE-1:0] o_ram_b_addr, |
| 64 | + output wire o_ram_b_rinc, |
| 65 | + output wire o_ram_b_winc |
| 66 | + ); |
| 67 | + |
| 68 | + wire [ASIZE-1:0] a_addr, b_addr; |
| 69 | + wire [ASIZE-1:0] a_waddr, a_raddr, b_waddr, b_raddr; |
| 70 | + wire [ ASIZE:0] a_wptr, b_rptr, a2b_wptr, b2a_rptr; |
| 71 | + wire [ ASIZE:0] a_rptr, b_wptr, a2b_rptr, b2a_wptr; |
| 72 | + |
| 73 | + assign a_addr = a_dir ? a_waddr : a_raddr; |
| 74 | + assign b_addr = b_dir ? b_waddr : b_raddr; |
| 75 | + |
| 76 | + ////////////////////////////////////////////////////////////////////////////// |
| 77 | + // A-side logic |
| 78 | + ////////////////////////////////////////////////////////////////////////////// |
| 79 | + |
| 80 | + // Sync b write pointer to a domain |
| 81 | + sync_ptr #(ASIZE) |
| 82 | + sync_b2a_wptr |
| 83 | + ( |
| 84 | + .dest_clk (a_clk), |
| 85 | + .dest_rst_n (a_rst_n), |
| 86 | + .src_ptr (b_wptr), |
| 87 | + .dest_ptr (b2a_wptr) |
| 88 | + ); |
| 89 | + |
| 90 | + // Sync b read pointer to a domain |
| 91 | + sync_ptr #(ASIZE) |
| 92 | + sync_b2a_rptr |
| 93 | + ( |
| 94 | + .dest_clk (a_clk), |
| 95 | + .dest_rst_n (a_rst_n), |
| 96 | + .src_ptr (b_rptr), |
| 97 | + .dest_ptr (b2a_rptr) |
| 98 | + ); |
| 99 | + |
| 100 | + // The module handling the write requests |
| 101 | + // outputs valid when dir == 0 (a is writing) |
| 102 | + wptr_full #(ASIZE) |
| 103 | + a_wptr_inst |
| 104 | + ( |
| 105 | + .wclk (a_clk), |
| 106 | + .wrst_n (a_rst_n), |
| 107 | + .winc (a_winc), |
| 108 | + .wq2_rptr (b2a_rptr), |
| 109 | + .awfull (a_afull), |
| 110 | + .wfull (a_full), |
| 111 | + .waddr (a_waddr), |
| 112 | + .wptr (a_wptr) |
| 113 | + ); |
| 114 | + |
| 115 | + // dir == 1 read pointer on a side calculation |
| 116 | + rptr_empty #(ASIZE) |
| 117 | + a_rptr_inst |
| 118 | + ( |
| 119 | + .rclk (a_clk), |
| 120 | + .rrst_n (a_rst_n), |
| 121 | + .rinc (a_rinc), |
| 122 | + .rq2_wptr (b2a_wptr), |
| 123 | + .arempty (a_aempty), |
| 124 | + .rempty (a_empty), |
| 125 | + .raddr (a_raddr), |
| 126 | + .rptr (a_rptr) |
| 127 | + ); |
| 128 | + |
| 129 | + ////////////////////////////////////////////////////////////////////////////// |
| 130 | + // B-side logic |
| 131 | + ////////////////////////////////////////////////////////////////////////////// |
| 132 | + |
| 133 | + // Sync a write pointer to b domain |
| 134 | + sync_ptr #(ASIZE) |
| 135 | + sync_a2b_wptr |
| 136 | + ( |
| 137 | + .dest_clk (b_clk), |
| 138 | + .dest_rst_n (b_rst_n), |
| 139 | + .src_ptr (a_wptr), |
| 140 | + .dest_ptr (a2b_wptr) |
| 141 | + ); |
| 142 | + |
| 143 | + // Sync a read pointer to b domain |
| 144 | + sync_ptr #(ASIZE) |
| 145 | + sync_a2b_rptr |
| 146 | + ( |
| 147 | + .dest_clk (b_clk), |
| 148 | + .dest_rst_n (b_rst_n), |
| 149 | + .src_ptr (a_rptr), |
| 150 | + .dest_ptr (a2b_rptr) |
| 151 | + ); |
| 152 | + |
| 153 | + // The module handling the write requests |
| 154 | + // outputs valid when dir == 0 (b is writing) |
| 155 | + wptr_full #(ASIZE) |
| 156 | + b_wptr_inst |
| 157 | + ( |
| 158 | + .wclk (b_clk), |
| 159 | + .wrst_n (b_rst_n), |
| 160 | + .winc (b_winc), |
| 161 | + .wq2_rptr (a2b_rptr), |
| 162 | + .awfull (b_afull), |
| 163 | + .wfull (b_full), |
| 164 | + .waddr (b_waddr), |
| 165 | + .wptr (b_wptr) |
| 166 | + ); |
| 167 | + |
| 168 | + // dir == 1 read pointer on b side calculation |
| 169 | + rptr_empty #(ASIZE) |
| 170 | + b_rptr_inst |
| 171 | + ( |
| 172 | + .rclk (b_clk), |
| 173 | + .rrst_n (b_rst_n), |
| 174 | + .rinc (b_rinc), |
| 175 | + .rq2_wptr (a2b_wptr), |
| 176 | + .arempty (b_aempty), |
| 177 | + .rempty (b_empty), |
| 178 | + .raddr (b_raddr), |
| 179 | + .rptr (b_rptr) |
| 180 | + ); |
| 181 | + |
| 182 | + ////////////////////////////////////////////////////////////////////////////// |
| 183 | + // FIFO RAM interface |
| 184 | + ////////////////////////////////////////////////////////////////////////////// |
| 185 | + |
| 186 | + assign o_ram_a_clk = a_clk; |
| 187 | + assign o_ram_a_wdata = a_wdata; |
| 188 | + assign a_rdata = i_ram_a_rdata; |
| 189 | + assign o_ram_a_addr = a_addr; |
| 190 | + assign o_ram_a_rinc = a_rinc & !a_dir; |
| 191 | + assign o_ram_a_winc = a_winc & a_dir; |
| 192 | + assign o_ram_b_clk = b_clk; |
| 193 | + assign o_ram_b_wdata = b_wdata; |
| 194 | + assign b_rdata = i_ram_b_rdata; |
| 195 | + assign o_ram_b_addr = b_addr; |
| 196 | + assign o_ram_b_rinc = b_rinc & !b_dir; |
| 197 | + assign o_ram_b_winc = b_winc & b_dir; |
| 198 | + |
| 199 | +endmodule |
| 200 | + |
| 201 | +`resetall |
0 commit comments