Statistics
| Branch: | Tag: | Revision:

root / usrp2 / udp / prot_eng_rx.v @ bea538ba

History | View | Annotate | Download (3.36 KB)

1

    
2

    
3

    
4
// Protocol Engine Receiver
5
//  Checks each line (16 bits) against values in setting regs
6
//  3 options for each line -- 
7
//      Error if mismatch, Slowpath if mismatch, or ignore line
8
//  The engine increases the length of each packet by 32 or 48 bits,
9
//   bringing the total length to a multiple of 32 bits.  The last line
10
//   is entirely new, and contains the results of the matching operation:
11
//      16 bits of flags, 16 bits of data.  Flags indicate error or slowpath
12
//      Data indicates line that caused mismatch if any.
13

    
14

    
15
//   Flags[2:0] is {occ, eop, sop}
16
//   Protocol word format is:
17
//             22   Last Header Line
18
//             21   SLOWPATH if mismatch
19
//             20   ERROR if mismatch
20
//             19   This is the IP checksum
21
//             18   This is the UDP checksum
22
//             17   Compute IP checksum on this word
23
//             16   Compute UDP checksum on this word
24
//           15:0   data word to be matched
25

    
26
module prot_eng_rx
27
  #(parameter BASE=0)
28
   (input clk, input reset, input clear,
29
    input set_stb, input [7:0] set_addr, input [31:0] set_data,
30
    input [18:0] datain, input src_rdy_i, output dst_rdy_o,
31
    output [18:0] dataout, output src_rdy_o, input dst_rdy_i);
32

    
33
   localparam HDR_WIDTH  = 16 + 7;  // 16 bits plus flags
34
   localparam HDR_LEN 	 = 32;      // Up to 64 bytes of protocol
35
   
36
   // Store header values in a small dual-port (distributed) ram
37
   reg [HDR_WIDTH-1:0] header_ram[0:HDR_LEN-1];
38
   wire [HDR_WIDTH-1:0] header_word;
39
   
40
   always @(posedge clk)
41
     if(set_stb & ((set_addr & 8'hE0) == BASE))
42
       header_ram[set_addr[4:0]] <= set_data;
43

    
44
   assign header_word 	= header_ram[state];
45

    
46
   wire consume_input 	= src_rdy_i & dst_rdy_o;
47
   wire produce_output 	= src_rdy_o & dst_rdy_i;
48
   
49
   // Main State Machine
50
   reg [15:0] pkt_length, fail_word, dataout_int;
51
   
52
   reg slowpath, error, sof_o, eof_o, occ_o, odd;
53

    
54
   assign dataout    = {occ_o, eof_o, sof_o, dataout_int};
55

    
56
   wire [15:0] calc_ip_checksum, calc_udp_checksum;
57
   reg [15:0] rx_ip_checksum, rx_udp_checksum;
58

    
59
   always @(posedge clk) 
60
     if(header_word[19]) 
61
       rx_ip_checksum  <= datain[15:0];
62
   always @(posedge clk) 
63
     if(header_word[18]) 
64
       rx_udp_checksum <= datain[15:0];
65
   
66
   always @(posedge clk)
67
     if(reset | clear)
68
       begin
69
	  slowpath     <= 0;
70
	  error        <= 0;
71
	  state        <= 0;
72
	  fail_word    <= 0;
73
	  eof_o        <= 0;
74
	  occ_o        <= 0;
75
       end
76
     else if(src_rdy_i & dst_rdy_i)
77
       case (state)
78
	 0 :
79
	   begin
80
	      slowpath 	   <= 0;
81
	      error 	   <= 0;
82
	      eof_o 	   <= 0;
83
	      occ_o 	   <= 0;
84
	      state 	   <= 1;
85
	   end
86

    
87
	 ST_SLOWPATH :
88
	   ;
89
	 ST_ERROR :
90
	   ;
91
	 ST_PAYLOAD :
92
	   ;
93
	 ST_FILLER :
94
	   ;
95
	 ST_END1 :
96
	   ;
97
	 ST_END2 :
98
	   ;
99
	 default :
100
	   if(header_word[21] && mismatch)
101
	     state <= ST_SLOWPATH;
102
	   else if(header_word[20] && mismatch)
103
	     state <= ST_ERROR;
104
	   else if(header_word[22])
105
	     state <= ST_PAYLOAD;
106
	   else
107
	     state <= state + 1;
108
       endcase // case (state)
109
   
110

    
111

    
112
   // IP + UDP checksum state machines
113
   checksum_sm ip_chk
114
     (.clk(clk), .reset(reset), .in(datain), 
115
      .calc(consume_input & header_word[17]), .clear(state==0), .checksum(ip_checksum));
116
   
117
   checksum_sm udp_chk
118
     (.clk(clk), .reset(reset), .in(datain), 
119
      .calc(consume_input & header_word[16]), .clear(state==0), .checksum(udp_checksum));
120
   
121
endmodule // prot_eng_rx