-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathph_finder.v
77 lines (67 loc) · 2 KB
/
ph_finder.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Packet Header Finder: this module searches for the packet header in a stream of data
* Gedeon Nyengele <nyengele@stanford.edu>
* 08 January 2018
*/
/*
* @param rxbyteclkhs the byte clock to synchrnize to (input)
* @param reset an active-high synchronous reset signal (input)
* @param din 16-bit word input. MSB = lane1_byte, LSB = lane2_byte (input)
* @param din_valid defines if word_in is valid (input)
* @param dout 32-bit output containing either the packet header or forwarded data stream (output)
* PH is formatted as [ECC, WC_MSB, WC_LSB, DATA_ID]
* forwarded data stream format: MSB = lane1_byte, LSB = lane2_byte
* @param dout_valid defines if dout is valid (output)
* @param ph_select defines whether 'dout' contains the PH or not
*/
module ph_finder(rxbyteclkhs, reset, din, din_valid, dout, dout_valid, ph_select);
/* inputs */
input wire rxbyteclkhs, reset;
input wire [15:0] din; // { lane0[7:0], lane1[7:0] }
input wire din_valid;
/* outputs */
output reg [31:0] dout;
output reg dout_valid;
output reg ph_select;
/* internal decl */
parameter STATE_HALF_PH = 2'b00;
parameter STATE_FULL_PH = 2'b01;
parameter STATE_BYPASS = 2'b10;
reg [7:0] prev_byte1, prev_byte2;
reg [1:0] state;
/* state machine */
always @(posedge rxbyteclkhs) begin
if(reset | ~din_valid) begin
dout <= 32'd0;
dout_valid <= 1'b0;
ph_select <= 1'b0;
prev_byte1 <= 8'd0;
prev_byte2 <= 8'd0;
state <= STATE_HALF_PH;
end
else begin
case(state)
STATE_HALF_PH: begin
prev_byte1 <= din[15:8];
prev_byte2 <= din[7:0];
state <= STATE_FULL_PH;
end
STATE_FULL_PH: begin
dout <= {din[7:0], din[15:8], prev_byte2, prev_byte1};
dout_valid <= 1'b1;
ph_select <= 1'b1;
state <= STATE_BYPASS;
end
STATE_BYPASS: begin
dout <= {din, 16'd0};
ph_select <= 1'b0;
state <= STATE_BYPASS;
end
default: begin
dout <= 32'd0;
dout_valid <= 1'b0;
ph_select <= 1'b0;
end
endcase
end
end
endmodule