-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple with m.State("..."):
statements for the same state
#195
Comments
It's hard for me to suggest something truly idiomatic without seeing a wider picture here. Can you post the entire module, or at least sketch it out? |
Here's what I have so far. "Edgelord" is a module that reproduces the clk state for use in combinatorial logic, without subjecting the clk signal to combinatorial logic. The goal here is to provide the output signals as a readable table, rather than scattered throughout the FSM.
|
Try this: tcycles = {
"INACTIVE": 0,
"TCYCLE1": 1,
"TCYCLE2": 2,
"TCYCLE3": 3,
"TCYCLE4": 4,
"TCYCLE5": 5
}
with m.FSM(domain="pos", reset="INACTIVE") as fsm:
tcycle = Signal(max=len(tcycles))
for state, index in tcycles.items():
with m.State(state):
m.d.comb += tcycle.eq(index)
m.d.comb += self.tcycle.eq(tcycle)
m.d.comb += self.extra_tcycle(self.extend_cycle and tcycle >= 4)
m.d.comb += self.A.eq(Array([0, pc, pc, ra, ra, ra])[tcycle])
m.d.comb += self.nMREQ.eq(Array([1, c, 0, c, ~c, 1])[tcycle])
m.d.comb += self.nRD.eq(Array([1, c, 0, 1, 1, 1])[tcycle])
m.d.comb += self.nM1.eq(Array([1, 0, 0, 1, 1, 1])[tcycle])
m.d.comb += self.nRFSH.eq(Array([1, 1, 1, 0, 0, 1])[tcycle])
m.d.comb += self.done.eq(Array([0, 0, 0, 0, ~c, 1])[tcycle]) |
Note that you can have as many |
Seems reasonable. However, this line is causing a problem, and I'm not sure which value it's having a problem with:
None of these worked either:
|
What are you trying to do with |
Oh... did you miss a
(note the parens, necessary because of precedence) |
Oops, my bad. Next issue:
I was kind of hoping that I could define the table of outputs in one place, and the transitions in another, but we can't have two |
I agree. I'll look into relaxing this restriction (I thought it's already relaxed...) but this will take a bit of time (the lazy state definition interacts with unspecified reset state, and should be handled in a nice way), so you should use a workaround for now. |
with m.State("..."):
statements for the same state
Got it, thanks! |
Closing in favor of more general discussion in #206. |
If I have an FSM that has a bunch of named states, I'd like a convenient way to do something like this:
What's the idiomatic way to do this?
The text was updated successfully, but these errors were encountered: