-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathskid_buffer.sv
85 lines (72 loc) · 4.26 KB
/
skid_buffer.sv
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
78
79
80
81
82
83
84
85
/*===============================================================================================================================
Module : Skid Buffer
Description : Skid Buffer is used as an elastic buffer to store the data when receiver applies backpressure to sender.
- Latency-0 buffer implemented with just one register.
- Simple valid-ready handshaking.
- Configurable data width.
Developer : Mitu Raj, chip@chipmunklogic.com at Chipmunk Logic ™, https://chipmunklogic.com
Notes : The upstream/downstream pipeline is assumed to be in the same reset domain, hence o_ready is 1'b1 on reset.
License : Open-source.
Date : Mar-26-2022
===============================================================================================================================*/
/*-------------------------------------------------------------------------------------------------------------------------------
S K I D B U F F E R
-------------------------------------------------------------------------------------------------------------------------------*/
module skid_buffer #(
// Global Parameters
parameter DWIDTH = 8 // Data width
)
(
input logic clk , // Clock
input logic rstn , // Active-low synchronous reset
// Input Interface (Upstream pipeline IF)
input logic [DWIDTH-1 : 0] i_data , // Data in
input logic i_valid , // Data in valid
output logic o_ready , // Ready out
// Output Interface (Downstream pipeline IF)
output logic [DWIDTH-1 : 0] o_data , // Data out
output logic o_valid , // Data out valid
input logic i_ready // Ready in
) ;
/*-------------------------------------------------------------------------------------------------------------------------------
Internal Registers/Signals
-------------------------------------------------------------------------------------------------------------------------------*/
logic [DWIDTH-1 : 0] data_rg ; // Data buffer
logic bypass_rg ; // Bypass signal to data and data valid muxes
/*-------------------------------------------------------------------------------------------------------------------------------
Synchronous logic
-------------------------------------------------------------------------------------------------------------------------------*/
always @(posedge clk) begin
// Reset
if (!rstn) begin
// Internal Registers
data_rg <= '0 ;
bypass_rg <= 1'b1 ;
end
// Out of reset
else begin
// Bypass state
if (bypass_rg) begin
if (!i_ready && i_valid) begin
data_rg <= i_data ; // Data skid happened, store to buffer
bypass_rg <= 1'b0 ; // To skid mode
end
end
// Skid state
else begin
if (i_ready) begin
bypass_rg <= 1'b1 ; // Back to bypass mode
end
end
end
end
/*-------------------------------------------------------------------------------------------------------------------------------
Continuous Assignments
-------------------------------------------------------------------------------------------------------------------------------*/
assign o_ready = bypass_rg ; // Ready to upstream pipeline
assign o_data = bypass_rg ? i_data : data_rg ; // Data mux
assign o_valid = bypass_rg ? i_valid : 1'b1 ; // Data valid mux
endmodule
/*-------------------------------------------------------------------------------------------------------------------------------
S K I D B U F F E R
-------------------------------------------------------------------------------------------------------------------------------*/