by alain94040 · 7y ago · 0 comments
if(~old_download && ioctl_download) begin
cnt <= 8'b0;
timeout <= 32'b0;
end
timeout <= timeout + 1'b1;
That's why in Verilog RTL we generally try to keep always blocks as small as possible, so they focus on assigning the same small set of signals in all branches.It's hard to change your mindset from a programming language to a hardware description language and not make mistakes like these, especially when just starting to learn Verilog. :-)
This code would work just fine (many people would argue it's not very readable -- but it saves you a lot of else branches):
// Default
timeout <= timeout + 1'b1;
// Special cases
if(~old_download && ioctl_download) begin
cnt <= 8'b0;
timeout <= 32'b0;
endI hope my next project will have cleaner code, be more readable and have less issues like these. HDL languages seem to have a rather steep learning curve and it takes some effort to distance yourself from the usual programming mindset.
And you are mixing <= and = in the same code (look in execute() ) this should never happen.
In general use <= in places that are gated by an "always @(posedge clk)" and = in things gated by "always @(*)"
(with the exception that it's OK to assign a temp variable in a clocked always with '=' provided its lifetime doesn't extend past the block's execution (your use of SKIP_FLAG is an example of this being done correctly)
When performing boolean condition testing, eg "if (~a & b)", always use "!" for negation instead of "~", "&&" for logical and, and "||" for logical or for exactly the same reasons you should do it for C code.
If the operands are all 1 bit, either option works fine. But if you ever accidentally use a vector where you intended a bit, one generates a warning and the other doesn't.