So in the faster case, we start in the wait state and don't exit it until the positive edge of cpu clock, but then we miss the write signal. Why does it happen in the slow case?
Interesting behavior here where the state is changing at the same cycle as next_state (for the first 2 transitions). This should only be possible on reset going into state 3. Is this a simulation bug, or bad coding?
Seems like the problem is to do with comparing to clk_cpu, as in both cases where next_state and state change at the same time, it is because we are basing next_state on the output of a comparison with clk_cpu
if(i_cs)beginw_addr={{i_addr[24:2]},{1'b0}};;// divide by 2, set last bit to 0if(i_rwb)begin//readw_read='1;w_last='1;// dm is not needed for reads?if(w_rd_ack)next_state=READ_WAIT;endelsebegin//writew_data_i=i_data<<(8*i_addr[1:0]);//w_data_i = {4{i_data}}; //does anything get through?w_dm=~(4'b1<<i_addr[1:0]);if(~i_cpuclk)beginw_write='1;w_last='1;next_state=WRITE_WAIT;endendend
You see how we are dependent on i_cs being high, but i_cpuclk being low. These are never supposed to happen together, since when i_cpuclk goes low, that is the end of the write cycle and i_cs will change again. tbh I am not sure why this even worked at the slow speed.
aha, its called there because we get a break instruction, which is then calling into offsets for stuff that it probably shouldn't. At 434us there is a BRK.