38d8d38fcd159fb4a21d2a5d6fe28f39725313d9
[debian/gnuradio] / usrp2 / fpga / eth / mac_txfifo_int.v
1
2 module mac_txfifo_int
3   (input clk, input rst, input mac_clk,
4
5    // To MAC
6    input Tx_mac_wa,
7    output Tx_mac_wr,
8    output [31:0] Tx_mac_data,
9    output [1:0] Tx_mac_BE,
10    output Tx_mac_sop,
11    output Tx_mac_eop,
12
13    // To buffer interface
14    input [31:0] rd_dat_i,
15    output rd_read_o,
16    output rd_done_o,
17    output rd_error_o,
18    input rd_sop_i,
19    input rd_eop_i,
20
21    // FIFO Status
22    output [15:0] fifo_occupied,
23    output fifo_full,
24    output fifo_empty  );
25
26    wire  empty, full, sfifo_write, sfifo_read;
27    wire [33:0] sfifo_in, sfifo_out;
28
29    /*
30    shortfifo #(.WIDTH(34)) txmac_sfifo
31      (.clk(clk),.rst(rst),.clear(0),
32       .datain(sfifo_in),.write(sfifo_write),.full(full),
33       .dataout(sfifo_out),.read(sfifo_read),.empty(empty));
34     */
35    fifo_xlnx_512x36_2clk mac_tx_fifo_2clk
36      (.rst(rst),
37       .wr_clk(clk),.din({2'b0,sfifo_in}),.full(full),.wr_en(sfifo_write),.wr_data_count(fifo_occupied[8:0]),
38       .rd_clk(mac_clk),.dout(sfifo_out),.empty(empty),.rd_en(sfifo_read),.rd_data_count() );
39    assign      fifo_occupied[15:9] = 0;
40    assign      fifo_full = full;
41    assign      fifo_empty = empty;   // Note empty is in wrong clock domain
42    
43    // MAC side signals
44    //  We are allowed to do one more write after we are told the FIFO is full
45    //  This allows us to register the _wa signal and speed up timing.
46    
47    reg         tx_mac_wa_d1;
48    always @(posedge clk)
49      tx_mac_wa_d1 <= Tx_mac_wa;
50    
51    assign      sfifo_read = ~empty & tx_mac_wa_d1;
52
53    assign      Tx_mac_wr = sfifo_read;
54    assign      Tx_mac_data = sfifo_out[31:0];
55    assign      Tx_mac_BE = 0;  // Since we only deal with packets that are multiples of 32 bits long
56    assign      Tx_mac_sop = sfifo_out[33];
57    assign      Tx_mac_eop = sfifo_out[32];
58
59
60    // BUFFER side signals
61    reg         xfer_active;
62    always @(posedge clk)
63      if(rst)
64        xfer_active <= 0;
65      else if(rd_eop_i & ~full)
66        xfer_active <= 0;
67      else if(rd_sop_i)
68        xfer_active <= 1;
69    
70    assign      sfifo_in = {rd_sop_i, rd_eop_i, rd_dat_i};
71    assign      sfifo_write = xfer_active & ~full;
72
73    assign      rd_read_o = sfifo_write;
74    assign      rd_done_o = 0;  // Always send everything we're given?
75    assign      rd_error_o = 0;  // No possible error situations?
76    
77 endmodule // mac_txfifo_int