diff --git a/VerilogCodingStyle.md b/VerilogCodingStyle.md index a9ff36e..7de1b5e 100644 --- a/VerilogCodingStyle.md +++ b/VerilogCodingStyle.md @@ -1900,6 +1900,33 @@ separate combinational (`always_comb`) block. Ideally, sequential blocks should contain only a register instantiation, with perhaps a load enable or an increment. +Exception: Even in a sequential always block, use blocking assignments (`=`) for +clock dividers. See [Clock Generation](#clock-generation). + +### Clock Generation + +***All clock signals should be generated using blocking assignment even +for clock dividers.*** + +See #44 for more details. + +👍 +```systemverilog {.good} +// only for test bench code +logic clk; +initial begin + clk <= 1'b0; + forever #5 clk = ~clk; // blocking assignment +end + +// for both synthesizable and test bench code +logic clk_div2; +always_ff @(posedge clk or negedge rst_ni) begin + if (!rst_ni) clk_div2 = 1'b0; + else clk_div2 = ~clk_div2; // blocking assignment +end +``` + ### Don't Cares (`X`'s) ***The use of `X` literals in RTL code is strongly discouraged. RTL must not