@@ -22,9 +22,9 @@ Documentation and Reference
22
22
23
23
## OVERVIEW
24
24
25
- A FIFO is a special type of buffer. The name FIFO stands for first in first out
26
- and means that the data written into the buffer first comes out of it first.
27
- A synchronous FIFO is a FIFO where the same clock is used for both reading and
25
+ A FIFO is a special type of buffer. The name LIFO stands for lst in first out
26
+ and means that the data written into the buffer last comes out of it first.
27
+ A synchronous LIFO is a LIFO where the same clock is used for both reading and
28
28
writing.
29
29
30
30
_ I used
@@ -47,7 +47,7 @@ The structure is,
47
47
48
48
The full and empy logic is,
49
49
50
- ![ IMAGE - fifo_compare_and_status.jpg - IMAGE] ( ../../../docs/pics/sequential-logic/fifo_compare_and_status .jpg )
50
+ ![ IMAGE - fifo_compare_and_status.jpg - IMAGE] ( ../../../docs/pics/sequential-logic/lifo_compare_and_status .jpg )
51
51
52
52
## TRUTH TABLE
53
53
@@ -56,25 +56,25 @@ but I wanted to show all the cases.
56
56
It's really just pushing and popping data
57
57
off the FIFO.
58
58
59
- | rst | we | full | data_in | re | empty | data_out | comment |
60
- | :---:| :--:| :----:| :--------:| :--:| :-----:| :--------:| :----------------:|
61
- | 1 | 0 | 0 | xxxxxxxx | 0 | 0 | xxxxxxxx | RESETS PTRS |
62
- | 0 | 0 | 0 | xxxxxxxx | 0 | 0 | data_out | - |
63
- | 0 | 0 | 0 | xxxxxxxx | 0 | 1 | data_out | EMPTY |
64
- | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | POP | POP |
65
- | 0 | 0 | 0 | xxxxxxxx | 1 | 1 | data_out | NO POP - EMPTY |
66
- | 0 | 0 | 1 | xxxxxxxx | 0 | 0 | data_out | FULL |
67
- | 0 | 0 | 1 | xxxxxxxx | 0 | 1 | - | N/A |
68
- | 0 | 0 | 1 | xxxxxxxx | 1 | 0 | POP | FULL - POP |
69
- | 0 | 0 | 1 | xxxxxxxx | 1 | 1 | - | N/A |
70
- | 0 | 1 | 0 | data | 0 | 0 | data_out | PUSH |
71
- | 0 | 1 | 0 | data | 0 | 1 | data_out | PUSH - EMPTY |
72
- | 0 | 1 | 0 | data | 1 | 0 | POP | PUSH - POP |
73
- | 0 | 1 | 0 | data | 1 | 1 | data_out | N/A |
74
- | 0 | 1 | 1 | xxxxxxxx | 0 | 0 | data_out | NO PUSH - FULL |
75
- | 0 | 1 | 1 | xxxxxxxx | 0 | 1 | data_out | N/A |
76
- | 0 | 1 | 1 | xxxxxxxx | 1 | 0 | POP | N/A |
77
- | 0 | 1 | 1 | xxxxxxxx | 1 | 1 | data_out | N/A |
59
+ | rst | push | full | data_in | pop | empty | data_out | comment |
60
+ | :---:| :---- :| :----:| :--------:| :- --:| :-----:| :--------:| :----------------:|
61
+ | 1 | 0 | 0 | xxxxxxxx | 0 | 0 | xxxxxxxx | RESETS PTR |
62
+ | 0 | 0 | 0 | xxxxxxxx | 0 | 0 | data_out | - |
63
+ | 0 | 0 | 0 | xxxxxxxx | 0 | 1 | data_out | EMPTY |
64
+ | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | POP | POP |
65
+ | 0 | 0 | 0 | xxxxxxxx | 1 | 1 | data_out | NO POP - EMPTY |
66
+ | 0 | 0 | 1 | xxxxxxxx | 0 | 0 | data_out | FULL |
67
+ | 0 | 0 | 1 | xxxxxxxx | 0 | 1 | - | N/A |
68
+ | 0 | 0 | 1 | xxxxxxxx | 1 | 0 | POP | FULL - POP |
69
+ | 0 | 0 | 1 | xxxxxxxx | 1 | 1 | - | N/A |
70
+ | 0 | 1 | 0 | data | 0 | 0 | data_out | PUSH |
71
+ | 0 | 1 | 0 | data | 0 | 1 | data_out | PUSH - EMPTY |
72
+ | 0 | 1 | 0 | data | 1 | 0 | POP | PUSH - POP |
73
+ | 0 | 1 | 0 | data | 1 | 1 | data_out | N/A |
74
+ | 0 | 1 | 1 | xxxxxxxx | 0 | 0 | data_out | NO PUSH - FULL |
75
+ | 0 | 1 | 1 | xxxxxxxx | 0 | 1 | data_out | N/A |
76
+ | 0 | 1 | 1 | xxxxxxxx | 1 | 0 | POP | N/A |
77
+ | 0 | 1 | 1 | xxxxxxxx | 1 | 1 | data_out | N/A |
78
78
79
79
## VERILOG CODE
80
80
@@ -104,69 +104,53 @@ behavioral model,
104
104
end
105
105
```
106
106
107
- ### WRITE AND READ PTRS
107
+ ### STACK PTRS
108
108
109
- ``` verilog
110
- // ALWAYS BLOCK with NON-BLOCKING PROCEDURAL ASSIGNMENT STATEMENT
111
- always @ (posedge clk) begin
112
- if (rst) begin
113
- w_ptr <= 3'b000;
114
- end else if (w_next) begin
115
- w_ptr <= w_ptr + 1;
116
- end else begin
117
- w_ptr <= w_ptr;
118
- end
119
- end
120
- ```
109
+ The top memory location is unused since the logic required to utilize that location
110
+ would take up more real estate than it's worth.
121
111
122
112
``` verilog
123
113
// ALWAYS BLOCK with NON-BLOCKING PROCEDURAL ASSIGNMENT STATEMENT
124
114
always @ (posedge clk) begin
115
+ //RESET
125
116
if (rst) begin
126
- r_ptr <= 3'b000;
117
+ wrt_ptr <= 4'b0000;
118
+ rd_ptr <= 4'b0000;
119
+ // BOTTOM - PUSH
120
+ end else if ((wrt_ptr == 4'b0000) & (w_next)) begin
121
+ wrt_ptr <= wrt_ptr + 1;
122
+ // BOTTOM - POP
123
+ end else if ((rd_ptr == 4'b0000) & (r_next)) begin
124
+ wrt_ptr <= 4'b0000;
125
+ // PUSH
126
+ end else if (w_next) begin
127
+ wrt_ptr <= wrt_ptr + 1;
128
+ rd_ptr <= rd_ptr + 1;
129
+ // POP
127
130
end else if (r_next) begin
128
- r_ptr <= r_ptr + 1;
129
- end else begin
130
- r_ptr <= r_ptr;
131
+ wrt_ptr <= wrt_ptr - 1;
132
+ rd_ptr <= rd_ptr - 1;
131
133
end
132
134
end
133
135
```
134
136
135
137
### COMPARE AND STATUS LOGIC
136
138
137
139
``` verilog
138
- parameter depth = 4'b1111; // Depth of the FIFO
139
-
140
- // DATA TYPES
141
- reg [3:0] ptr_diff;
142
-
143
- // FULL STATUS
144
- always @(*) begin
145
- if (ptr_diff == depth) begin
146
- full = 1'b1;
147
- end else begin
148
- full = 1'b0;
149
- end
150
- end
151
-
152
- // EMPTY STATUS
153
- always @(*) begin
154
- if (ptr_diff == 0) begin
155
- empty = 1'b1;
156
- end else begin
157
- empty = 1'b0;
158
- end
159
- end
140
+ parameter depth = 4'b1111; // Depth of the FIFO
160
141
161
142
// HOW MUCH MEMORY USED
162
143
// ALWAYS BLOCK with NON-BLOCKING PROCEDURAL ASSIGNMENT STATEMENT
163
144
always @(*) begin
164
- if (w_ptr > r_ptr) begin
165
- ptr_diff <= w_ptr - r_ptr + 1;
166
- end else if (w_ptr < r_ptr) begin
167
- ptr_diff <= (depth - r_ptr) + w_ptr + 1;
168
- end else if (w_ptr == r_ptr) begin
169
- ptr_diff <= 0;
145
+ if (wrt_ptr == 0) begin
146
+ full <= 1'b0;
147
+ empty <= 1'b1;
148
+ end else if (wrt_ptr < depth) begin
149
+ full <= 1'b0;
150
+ empty <= 1'b0;
151
+ end else if (wrt_ptr == depth) begin
152
+ full <= 1'b1;
153
+ empty <= 1'b0;
170
154
end
171
155
end
172
156
```
@@ -204,7 +188,61 @@ vvp lifo_synchronous_tb.vvp
204
188
The output of the test,
205
189
206
190
``` text
207
- ??????
191
+ TEST START --------------------------------
192
+
193
+ | TIME(ns) | RST | PUSH | FULL | DATA_IN | POP | EMPTY | DATA_OUT |
194
+ ----------------------------------------------------------------
195
+ 1 INIT | 15 | 0 | 0 | x | xxxxxxxx | 0 | x | xxxxxxxx |
196
+ 2 RESET | 35 | 1 | 0 | 0 | xxxxxxxx | 0 | 1 | xxxxxxxx |
197
+ 3 PUSH-1 | 55 | 0 | 1 | 0 | 00001111 | 0 | 0 | xxxxxxxx |
198
+ 4 PUSH-2 | 75 | 0 | 1 | 0 | 11110000 | 0 | 0 | 00001111 |
199
+ 5 PUSH-3 | 95 | 0 | 1 | 0 | 10101010 | 0 | 0 | 11110000 |
200
+ 6 - | 115 | 0 | 0 | 0 | xxxxxxxx | 0 | 0 | 10101010 |
201
+ 7 - | 135 | 0 | 0 | 0 | xxxxxxxx | 0 | 0 | 10101010 |
202
+ 8 - | 155 | 0 | 0 | 0 | xxxxxxxx | 0 | 0 | 10101010 |
203
+ 9 POP-3 | 175 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 10101010 |
204
+ 10 POP-2 | 195 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 11110000 |
205
+ 11 POP-1 | 215 | 0 | 0 | 0 | xxxxxxxx | 1 | 1 | 00001111 |
206
+ 12 POP-NULL | 235 | 0 | 0 | 0 | xxxxxxxx | 1 | 1 | 00001111 |
207
+ 13 POP-NULL | 255 | 0 | 0 | 0 | xxxxxxxx | 1 | 1 | 00001111 |
208
+ 14 POP-NULL | 275 | 0 | 0 | 0 | xxxxxxxx | 1 | 1 | 00001111 |
209
+ 15 - | 295 | 0 | 0 | 0 | xxxxxxxx | 0 | 1 | 00001111 |
210
+ 16 - | 315 | 0 | 0 | 0 | xxxxxxxx | 0 | 1 | 00001111 |
211
+ 17 - | 335 | 0 | 0 | 0 | xxxxxxxx | 0 | 1 | 00001111 |
212
+ 18 PUSH-1 | 355 | 0 | 1 | 0 | 00001111 | 0 | 0 | 00001111 |
213
+ 19 PUSH-2 | 375 | 0 | 1 | 0 | 11110000 | 0 | 0 | 00001111 |
214
+ 20 PUSH-3 | 395 | 0 | 1 | 0 | 10101010 | 0 | 0 | 11110000 |
215
+ 21 PUSH-4 | 415 | 0 | 1 | 0 | 01001111 | 0 | 0 | 10101010 |
216
+ 22 PUSH-5 | 435 | 0 | 1 | 0 | 11110000 | 0 | 0 | 01001111 |
217
+ 23 POP-5 | 455 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 11110000 |
218
+ 24 POP-4 | 475 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 01001111 |
219
+ 25 PUSH-4 | 495 | 0 | 1 | 0 | 10101011 | 0 | 0 | 10101010 |
220
+ 26 PUSH-5 | 515 | 0 | 1 | 0 | 00001110 | 0 | 0 | 10101011 |
221
+ 27 PUSH-6 | 535 | 0 | 1 | 0 | 11110001 | 0 | 0 | 00001110 |
222
+ 28 PUSH-7 | 555 | 0 | 1 | 0 | 10101000 | 0 | 0 | 11110001 |
223
+ 29 PUSH-8 | 575 | 0 | 1 | 0 | 10111000 | 0 | 0 | 10101000 |
224
+ 30 PUSH-9 | 595 | 0 | 1 | 0 | 10111000 | 0 | 0 | 10111000 |
225
+ 31 PUSH-10 | 615 | 0 | 1 | 0 | 10111000 | 0 | 0 | 10111000 |
226
+ 32 PUSH-11 | 635 | 0 | 1 | 0 | 10111000 | 0 | 0 | 10111000 |
227
+ 33 PUSH-12 | 655 | 0 | 1 | 0 | 10111001 | 0 | 0 | 10111000 |
228
+ 34 PUSH-13 | 675 | 0 | 1 | 0 | 10111010 | 0 | 0 | 10111001 |
229
+ 35 PUSH-14 | 695 | 0 | 1 | 0 | 10111100 | 0 | 0 | 10111010 |
230
+ 36 PUSH-15 | 715 | 0 | 1 | 1 | 00110000 | 0 | 0 | 10111100 |
231
+ 37 PUSH-NULL | 735 | 0 | 1 | 1 | 01011000 | 0 | 0 | 00110000 |
232
+ 38 PUSH-NULL | 755 | 0 | 1 | 1 | 00001011 | 0 | 0 | 00110000 |
233
+ 39 PUSH-NULL | 775 | 0 | 1 | 1 | 00011111 | 0 | 0 | 00110000 |
234
+ 40 - | 795 | 0 | 0 | 1 | xxxxxxxx | 0 | 0 | 00110000 |
235
+ 41 - | 815 | 0 | 0 | 1 | xxxxxxxx | 0 | 0 | 00110000 |
236
+ 42 - | 835 | 0 | 0 | 1 | xxxxxxxx | 0 | 0 | 00110000 |
237
+ 43 POP-15 | 855 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 00110000 |
238
+ 44 POP-14 | 875 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 10111100 |
239
+ 45 POP-13 | 895 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 10111010 |
240
+ 46 POP-12 | 915 | 0 | 0 | 0 | xxxxxxxx | 1 | 0 | 10111001 |
241
+
242
+ VECTORS: 46
243
+ ERRORS: 0
244
+
245
+ TEST END ----------------------------------
208
246
```
209
247
210
248
## VIEW WAVEFORM
0 commit comments