I'm learning Verilog, and trying to implement the CD54HC40105 chip. The part that's tripping me up is the bubbling logic.
Basically, this is a FIFO chip, and works by bubbling the words through the memory. One bit per word is used to track whether or not a word exists in that slot.
Here's the logic I need to implement: At any moment, if a word exists in some slot i, (which means ctrl[i] == 1), and no word exists in the next slot (ctrl[i + 1] == 0), then move the word in slot i to the next slot i+1, along with the control signal.
It might look something like this:
// Empty word next to B, it will shift right
+---+---+---+---+
| 1 | 1 | 0 | 0 |
+---+---+---+---+
| A | B | | |
+---+---+---+---+
// Empty word next to B and A, they will both shift right
+---+---+---+---+
| 1 | 0 | 1 | 0 |
+---+---+---+---+
| A | | B | |
+---+---+---+---+
// Empty word next to A, it will shift right
+---+---+---+---+
| 0 | 1 | 0 | 1 |
+---+---+---+---+
| | A | | B |
+---+---+---+---+
// No empty words
+---+---+---+---+
| 0 | 0 | 1 | 1 |
+---+---+---+---+
| | | A | B |
+---+---+---+---+
Now, this chip has no clock input, nor does it have any internal clock from the block diagram. Therefore, this is all done using some sort of logic that could be implemented in some sort of always block.
My initial intuition would be that this would be in an always block that is sensitive to a change in the ctrl register.
reg[15:0] ctrl;
// ...
always @(ctrl) begin
for (i = 0; i < 15; i = i + 1) begin
if (ctrl[i] == 1 && ctrl[i + 1] == 0) begin
ctrl[i + 1] <= 1;
mem[i + 1] <= mem[i];
ctrl[i] <= 0;
end
end
end
But I get the error Array ctrl needs an array index here. I can see why that is, but still I have no idea how I would do this otherwise.
Ideally, I need some syntax that does what this pseudosyntax would do:
// for all i's
always @(posedge ctrl[i]) begin
// there are 16 slots, so we can never bubble the last index
if (i != 15 && ctrl[i + 1] == 0) begin
// ...
end
end
Edit
I realized that the above pseudosolution wouldn't work because it wouldn't do anything when values are shifted out, causing ctrl[15] to become 0. So what do I do here?
Thanks,