Properly signals an error and drops the remainder of the packet if there is an overru...
[debian/gnuradio] / usrp2 / fpga / simple_gemac / rxmac_to_ll8.v
1
2 module rxmac_to_ll8
3   (input clk, input reset, input clear,
4    input [7:0] rx_data, input rx_valid, input rx_error, input rx_ack,
5    output [7:0] ll_data, output ll_sof, output ll_eof, output ll_error, output ll_src_rdy, input ll_dst_rdy );
6
7    reg [2:0] xfer_state;
8
9    assign ll_data           = rx_data;
10    assign ll_src_rdy        = ((rx_valid & (xfer_state != XFER_OVERRUN2) )
11                                | (xfer_state == XFER_ERROR) 
12                                | (xfer_state == XFER_OVERRUN));
13    assign ll_sof            = ((xfer_state==XFER_IDLE)|(xfer_state==XFER_ERROR)|(xfer_state==XFER_OVERRUN));
14    assign ll_eof            = (rx_ack | (xfer_state==XFER_ERROR) | (xfer_state==XFER_OVERRUN));
15    assign ll_error          = (xfer_state == XFER_ERROR)|(xfer_state==XFER_OVERRUN);
16    
17    localparam XFER_IDLE     = 0;
18    localparam XFER_ACTIVE   = 1;
19    localparam XFER_ERROR    = 2;
20    localparam XFER_ERROR2   = 3;
21    localparam XFER_OVERRUN  = 4;
22    localparam XFER_OVERRUN2 = 5;
23       
24    always @(posedge clk)
25      if(reset | clear)
26        xfer_state          <= XFER_IDLE;
27      else
28        case(xfer_state)
29          XFER_IDLE :
30            if(rx_valid)
31              xfer_state <= XFER_ACTIVE;
32          XFER_ACTIVE :
33            if(rx_error)
34              xfer_state <= XFER_ERROR;
35            else if(~rx_valid)
36              xfer_state <= XFER_IDLE;
37            else if(~ll_dst_rdy)
38              xfer_state <= XFER_OVERRUN;
39          XFER_ERROR :
40            if(ll_dst_rdy)
41              xfer_state <= XFER_ERROR2;
42          XFER_ERROR2 :
43            if(~rx_error)
44              xfer_state <= XFER_IDLE;
45          XFER_OVERRUN :
46            if(ll_dst_rdy)
47              xfer_state <= XFER_OVERRUN2;
48          XFER_OVERRUN2 :
49            if(~rx_valid)
50              xfer_state <= XFER_IDLE;
51        endcase // case (xfer_state)
52
53    
54 endmodule // rxmac_to_ll8