-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register initialization #823
Comments
You initialize registers via reset. always_ff {
if_reset {
regs[0] = '0;
} else {
...
}
} |
Thanks @nblei for your quick reply, while this indeed works, using a reset signal does not seem behaviorally equivalent as we need to introduce an input reset signal in the module ports and assert it high at startup. Is this a desired design decision? I guess this is not a bad thing since it means that the design can easily be ported to devices without initialization capabilities like ASICs. Although initialization with
|
Veryl is a hardware description language --- not a simulation language. As flops take random values on power-on, initializing them in an $readmemh "works" because SystemVerilog system functions get transpiled literally. |
I'm not at all an expert but initial blocks are not just used for simulation, some FPGAs do support flip-flop initialization, I have for instance used Anyway the proposed solution does work although it's a workaround, so I'm closing this issue. |
FPGA BRAM is implemented as SRAMs, not flops. |
Makes sense |
In most FPGAs, the initial state of the flops is determined by the configuration bitstream. Therefore, the initial initialization is successfully synthesized for the FPGA. This is convenient when, for example, there is no external reset signal. |
I agree that this use case is common in FPGA. But I think allowing this feature unconditionally is not good. This is because ASIC synthesizers (possibly few FPGA synthesizer too?) ignore |
@dalance, thanks for the reply. One solution is to create a Verilog module with a register and necessary initialization. It is only need to tell the module about clock polarity and reset type. Is it possible as I know? |
By following code, clock polarity and reset type which Verilog module receives can be specified. module Module (
i_clk: input clock,
i_rst: input reset,
) {
let w_clk: `_ clock_posedge = i_clk as clock_posedge;
let w_rst: reset_async_high = i_rst as reset_async_high;
inst u: $sv::ModuleSv (
i_clk: w_clk,
i_rst: w_rst,
);
} |
I think the following design may be acceptable.
pub module RegisterFile (
i_clk: input clock,
) {
var regs: logic<16>[8];
#[allow(initial_assign)]
initial {
regs[0] = '0;
}
}
This restriction is required to prevent that FPGA only project is added to ASIC project through dependencies. |
Hi, thanks for the good work!
Maybe I missed something, but I couldn't find an example of how to initialize a register value:
Fails with:
I also tried
var reg: logic<1> = 1'b1;
but this also fails.Is there a way to achieve this already?
The text was updated successfully, but these errors were encountered: