mark RFX boards as i_and_q_swapped
[debian/gnuradio] / usrp2 / fpga / control_lib / shortfifo.v
1
2 module shortfifo
3   #(parameter WIDTH=32)
4     (input clk, input rst,
5      input [WIDTH-1:0] datain,
6      output [WIDTH-1:0] dataout,
7      input read,
8      input write,
9      input clear,
10      output reg full,
11      output reg empty,
12      output [4:0] space,
13      output [4:0] occupied);
14    
15    reg [3:0]      a;
16    genvar         i;
17    
18    generate
19       for (i=0;i<WIDTH;i=i+1)
20         begin : gen_srl16
21            SRL16E
22              srl16e(.Q(dataout[i]),
23                     .A0(a[0]),.A1(a[1]),.A2(a[2]),.A3(a[3]),
24                     .CE(write),.CLK(clk),.D(datain[i]));
25         end
26    endgenerate
27    
28    always @(posedge clk)
29      if(rst)
30        begin
31           a <= 0;
32           empty <= 1;
33           full <= 0;
34        end
35      else if(clear)
36        begin
37           a <= 0;
38           empty <= 1;
39           full<= 0;
40        end
41      else if(read & ~write)
42        begin
43           full <= 0;
44           if(a==0)
45             empty <= 1;
46           else
47             a <= a - 1;
48        end
49      else if(write & ~read)
50        begin
51           empty <= 0;
52           if(~empty)
53             a <= a + 1;
54           if(a == 14)
55             full <= 1;
56        end
57
58    // NOTE will fail if you write into a full fifo or read from an empty one
59
60    assign space = full ? 0 : empty ? 16 : 15-a;
61    assign occupied = empty ? 0 : full ? 16 : a+1;
62    
63 endmodule // shortfifo