@@ -47,8 +47,6 @@ module lifo #( parameter
47
47
// "FALSE" - normal fifo mode
48
48
49
49
DEPTH = 8 , // max elements count == DEPTH, DEPTH MUST be power of 2
50
- DEPTH_W = $clog2(DEPTH )+ 1 , // elements counter width, extra bit to store
51
- // "fifo full" state, see cnt[] variable comments
52
50
53
51
DATA_W = 32 // data field width
54
52
)(
@@ -72,76 +70,82 @@ module lifo #( parameter
72
70
output logic fail
73
71
);
74
72
75
- // lifo data
76
- logic [DEPTH - 1 : 0 ][DATA_W - 1 : 0 ] data = '0 ;
73
+ // elements counter width, extra bit to store
74
+ // "fifo full" state, see cnt[] variable comments
75
+ localparam DEPTH_W = $clog2 (DEPTH + 1 );
77
76
78
- // data output buffer for normal fifo mode
79
- logic [DATA_W - 1 : 0 ] data_buf = '0 ;
80
77
81
- // cnt[] vector always holds lifo elements count
82
- // data[cnt[]] points to the first empty lifo slot
83
- // when lifo is full data[cnt[]] points "outside" of data[]
78
+ // lifo data
79
+ logic [DEPTH - 1 : 0 ][DATA_W - 1 : 0 ] data = '0 ;
84
80
85
- // filtered requests
86
- logic w_req_f;
87
- assign w_req_f = w_req && ~ full;
81
+ // data output buffer for normal fifo mode
82
+ logic [DATA_W - 1 : 0 ] data_buf = '0 ;
88
83
89
- logic r_req_f;
90
- assign r_req_f = r_req && ~ empty;
84
+ // cnt[] vector always holds lifo elements count
85
+ // data[cnt[]] points to the first empty lifo slot
86
+ // when lifo is full data[cnt[]] points "outside" of data[]
91
87
88
+ // filtered requests
89
+ logic w_req_f;
90
+ assign w_req_f = w_req && ~ full;
92
91
93
- integer i;
94
- always_ff @ (posedge clk) begin
95
- if ( ~ nrst ) begin
96
- data <= '0 ;
97
- cnt[DEPTH_W - 1 : 0 ] <= '0 ;
98
- data_buf[DATA_W - 1 : 0 ] <= '0 ;
99
- end else begin
100
- unique case ({ w_req_f, r_req_f} )
101
- 2'b00 : ; // nothing
92
+ logic r_req_f;
93
+ assign r_req_f = r_req && ~ empty;
102
94
103
- 2'b01 : begin // reading out
104
- for ( i = (DEPTH - 1 ); i > 0 ; i-- ) begin
105
- data[i- 1 ] <= data[i];
95
+
96
+ integer i;
97
+ always_ff @ (posedge clk) begin
98
+ if ( ~ nrst ) begin
99
+ data <= '0 ;
100
+ cnt[DEPTH_W - 1 : 0 ] <= '0 ;
101
+ data_buf[DATA_W - 1 : 0 ] <= '0 ;
102
+ end else begin
103
+ unique case ({ w_req_f, r_req_f} )
104
+ 2'b00 : ; // nothing
105
+
106
+ 2'b01 : begin // reading out
107
+ for ( i = (DEPTH - 1 ); i > 0 ; i-- ) begin
108
+ data[i- 1 ] <= data[i];
109
+ end
110
+ cnt[DEPTH_W - 1 : 0 ] <= cnt[DEPTH_W - 1 : 0 ] - 1'b1 ;
106
111
end
107
- cnt[DEPTH_W - 1 : 0 ] <= cnt[DEPTH_W - 1 : 0 ] - 1'b1 ;
108
- end
109
112
110
- 2'b10 : begin // writing in
111
- data[cnt[DEPTH_W - 1 : 0 ]] <= w_data[DATA_W - 1 : 0 ];
112
- cnt[DEPTH_W - 1 : 0 ] <= cnt[DEPTH_W - 1 : 0 ] + 1'b1 ;
113
- end
113
+ 2'b10 : begin // writing in
114
+ data[cnt[DEPTH_W - 1 : 0 ]] <= w_data[DATA_W - 1 : 0 ];
115
+ cnt[DEPTH_W - 1 : 0 ] <= cnt[DEPTH_W - 1 : 0 ] + 1'b1 ;
116
+ end
114
117
115
- 2'b11 : begin // simultaneously reading and writing
116
- data[cnt[DEPTH_W - 1 : 0 ]- 1 ] <= w_data[DATA_W - 1 : 0 ];
117
- // data counter does not change here
118
- end
119
- endcase
118
+ 2'b11 : begin // simultaneously reading and writing
119
+ data[cnt[DEPTH_W - 1 : 0 ]- 1 ] <= w_data[DATA_W - 1 : 0 ];
120
+ // data counter does not change here
121
+ end
122
+ endcase
120
123
121
- // data buffer works only for normal lifo mode
122
- if ( r_req_f ) begin
123
- data_buf[DATA_W - 1 : 0 ] <= data[0 ];
124
+ // data buffer works only for normal lifo mode
125
+ if ( r_req_f ) begin
126
+ data_buf[DATA_W - 1 : 0 ] <= data[0 ];
127
+ end
124
128
end
125
129
end
126
- end
127
130
128
131
129
- always_comb begin
130
- empty = ( cnt[DEPTH_W - 1 : 0 ] == '0 );
131
- full = ( cnt[DEPTH_W - 1 : 0 ] == DEPTH );
132
+ always_comb begin
133
+ empty = ( cnt[DEPTH_W - 1 : 0 ] == '0 );
134
+ full = ( cnt[DEPTH_W - 1 : 0 ] == DEPTH );
132
135
133
- if ( FWFT_MODE == " TRUE" ) begin
134
- if (~ empty) begin
135
- r_data[DATA_W - 1 : 0 ] = data[0 ]; // first-word fall-through mode
136
+ if ( FWFT_MODE == " TRUE" ) begin
137
+ if (~ empty) begin
138
+ r_data[DATA_W - 1 : 0 ] = data[0 ]; // first-word fall-through mode
139
+ end else begin
140
+ r_data[DATA_W - 1 : 0 ] = '0 ;
141
+ end
136
142
end else begin
137
- r_data[DATA_W - 1 : 0 ] = '0 ;
143
+ r_data[DATA_W - 1 : 0 ] = data_buf[ DATA_W - 1 : 0 ]; // normal mode
138
144
end
139
- end else begin
140
- r_data[DATA_W - 1 : 0 ] = data_buf[DATA_W - 1 : 0 ]; // normal mode
141
- end
142
145
143
- fail = ( empty && r_req ) ||
144
- ( full && w_req );
145
- end
146
+ fail = ( empty && r_req ) ||
147
+ ( full && w_req );
148
+ end
146
149
147
150
endmodule
151
+
0 commit comments