I know this is an old thread, but I wanted to update with some additional information I learned.
The idea: Allow a write to a special bit in a memory location to "soft reset" the system, but not reset the registers when doing so. The original code:
Code:
wire reset_en;
assign reset_en = (cart_config1_reg_ce & !clock & data[7]);
assign reset = (reset_en ? 0 : 1'bz);
assign reset_in = (reset_en ? 0 : !reset);
with a register defined as:
Code:
register cart_config1_reg(!clock, reset_in, ce, data, cart_config1);
The suggestion was to synchronize reset_en:
Code:
reg reset_en = 0;
always @(negedge clock) reset_en <= (cart_config1_reg_ce & data[7]);
I found that this also contained a race condition, in that reset_en would go high for the clock cycle, which would bring reset low, but at the same time set reset_in to 0. But, if reset was faster logic, it would go low before reset_in could be protected. I found the following addresses the issue:
Code:
reg [1:0]reset_ctr = 2'b0;
always @(negedge clock)
begin
if(cart_config1_reg_ce & data_in[7])
reset_ctr <= 1;
else if (reset_ctr != 0)
reset_ctr <= reset_ctr + 1;
end
assign reset = (reset_ctr == 2'b10 ? 0 : 1'bz);
assign reset_in = (reset_ctr != 0 ? 0 : !reset);
There are probably even neater ways to handle this, but I found this to work well.
Jim