I would save the previous state at the same time that you save your current state. For example, define two signal of the same state machine type:
type states is (idle, state1, ... other states);
signal current_state : state;
signal previous_state : state;
In your state machine, each time the current_state
changes to a different state, set previous_state
to current_state
.
This make previous state
always one step behind current state
.
Then, in your initial state, just set current_state
to previous_state
when you want to go back to where you were.
example_state_machine : process (clk, rst)
begin
if rst = '1' then
current_state <= idle;
previous_state <= state1; -- set this to the state you want to go to after first idle
elsif clk'event and clk = '1' then -- rising clock edge
case current is
when idle =>
if (something = '1') then
current_state <= previous_state;
previous_state <= current_state;
else
current_state <= idle;
end if;
when state1 =>
if (something = '1') then
current_state <= state2;
previous_state <= current_state;
elsif something_else = '1' then
current_state <= idle;
previous_state <= current_state;
else
current_state <= state1;
end if;
-- ... rest of states
when others => null;
end case;
end if;
end process;