Hello All,
I am writing basic state machine which maintains 8 different states and there is posibility that system may be in multiple states at a time (Except for state1 to state3. menas only once state can be active at a time from state1 to state3).
I have declared enum like one below
Now my requirement is that state1 to state3 can not be active at a given instance.
Example if machine is in state1 then; state variabale would be -->
... then when system changes its state to to state3 ... state variable should become
.
Note :- "x'" indicates other state variable which should not get affected because of above operations.
So you have a variable (e.g. state) that presumably should always have no more than one of the three low order bits set. (Or, maybe you mean it should always have exactly one of the three low order bits set. Your specification is ambiguous as to which of these you mean.)
How will you tell your machine to change state?
Will you call a function to change the state? If so, why is that function not just an assignment to state? Is it that you want to verify that the requested new state has no more than one (or exactly one) of the three low order bits set?
Maybe you want a function that takes two arguments, states to add to state and states to remove from state.
What language are you using? (I could guess C, but it isn't the only language that includes enums.)
Dear Don Cragun,
Thank you very much for your reply.
I am using C macro to accomplish this. I can not pass states to remove from
as I am not aware of previous state. What I want is their should always have no more than one of the three low order bits set.
Example :- If I am in
currently then my state variable would be
. Now If I want to set state to
then my state variable should become
Thank you.
Dear Don Cragun,
Thank you very much for your reply.
I am using C macro to accomplish this. I can not pass states to remove from
as I am not aware of previous state. What I want is their should always have no more than one of the three low order bits set.
Example :- If I am in
currently then my state variable would be
. Now If I want to set state to
then my state variable should become
Thank you.
This makes no sense. If your program isn't aware of your current state (previous state when you want to change to a new set of states), then setting the new state is just a statement like:
If you can't restrain yourself from writing code like:
and you aren't going to set up a function to perform verification of state changes, I have no idea what you are trying to do. And, doing this, there are never any unknown (or unchanged states); you replace (rather than update) states every time to assign a new value to state. So you won't have xxxx x100, you'll have 0000 0001, 0100 1100, or (the undesired) 0000 0011, respectively, for the three samples above; but never any xs.
I must be missing something in your description of what you're trying to do.
Dear ,
I am really sorry for my idiot reply in last post.
Yes I store the last state which I am exposing to my application through another macro.
Thus there are basically two macros each for saving the state and getting the current state.
Dear ,
I am really sorry for my idiot reply in last post.
Yes I store the last state which I am exposing to my application through another macro.
Thus there are basically two macros each for saving the state and getting the current state.
OK. So, show us the macros! And, tell us what you want each of those macros to do that they are not doing now.
Here are the macros :-
The problem with above macro is that when i switch from
to
; state variable becomes
that means both
and
are active where as what I want is when I switch from
to
state variable should be
meaning only
is active
Hi I wanted to call the AutoFsm function (given below) in vim to generate a code something like:
**********verilog code to generate *************
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
state_r <= #1 next_stateascii_r; ... (0 Replies)