Merged SVN matt/new_eth r10782:11633 into new_eth
[debian/gnuradio] / usrp2 / fpga / control_lib / newfifo / fifo36_to_ll8.v
1
2 module fifo36_to_ll8
3   (input clk, input reset, input clear,
4    input [35:0] f36_data,
5    input f36_src_rdy_i,
6    output f36_dst_rdy_o,
7
8    output reg [7:0] ll_data,
9    output ll_sof_n,
10    output ll_eof_n,
11    output ll_src_rdy_n,
12    input ll_dst_rdy_n,
13
14    output [31:0] debug);
15
16    wire  ll_sof, ll_eof, ll_src_rdy;
17    assign ll_sof_n = ~ll_sof;
18    assign ll_eof_n = ~ll_eof;
19    assign ll_src_rdy_n = ~ll_src_rdy;
20    wire ll_dst_rdy = ~ll_dst_rdy_n;
21
22    wire   f36_sof = f36_data[32];
23    wire   f36_eof = f36_data[33];
24    wire   f36_occ = f36_data[35:34];
25    wire advance, end_early;
26    reg [1:0] state;
27    assign debug    = {29'b0,state};
28
29    always @(posedge clk)
30      if(reset)
31        state      <= 0;
32      else
33        if(advance)
34          if(ll_eof)
35            state  <= 0;
36          else
37            state  <= state + 1;
38
39    always @*
40      case(state)
41        0 : ll_data = f36_data[31:24];
42        1 : ll_data = f36_data[23:16];
43        2 : ll_data = f36_data[15:8];
44        3 : ll_data = f36_data[7:0];
45        default : ll_data = f36_data[31:24];
46        endcase // case (state)
47    
48    assign ll_sof         = (state==0) & f36_sof;
49    assign ll_eof         = f36_eof & (((state==0)&(f36_occ==1)) |
50                                ((state==1)&(f36_occ==2)) |
51                                ((state==2)&(f36_occ==3)) |
52                                (state==3));
53    
54    assign ll_src_rdy     = f36_src_rdy_i;
55
56    assign advance        = ll_src_rdy & ll_dst_rdy;
57    assign f36_dst_rdy_o  = advance & ((state==3)|ll_eof);
58    assign debug          = state;
59    
60 endmodule // ll8_to_fifo36