Skip to content
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

Document setWhen and clearWhen #137

Open
numero-744 opened this issue Nov 3, 2022 · 5 comments
Open

Document setWhen and clearWhen #137

numero-744 opened this issue Nov 3, 2022 · 5 comments
Labels
good first issue Good for newcomers

Comments

@numero-744
Copy link
Collaborator

Should be in: https://spinalhdl.github.io/SpinalDoc-RTD/master/SpinalHDL/Sequential%20logic/registers.html
(source: https://github.com/SpinalHDL/SpinalDoc-RTD/blob/master/source/SpinalHDL/Sequential%20logic/registers.rst)

Simplified example:

val inFrameLate = Reg(Bool) setWhen(!sclRead) clearWhen(!inFrame)
@numero-744 numero-744 added the good first issue Good for newcomers label Nov 3, 2022
@Dolu1990
Copy link
Member

Dolu1990 commented Nov 3, 2022

hmm setWhen isn't only for register. It can also be used for signals

val myOutput = out(False)
myOutput setWhen(xxxx)
myOutput clearWhen(yyy)

@numero-744
Copy link
Collaborator Author

numero-744 commented Nov 4, 2022

Hmm, if I understand correctly, in your example for a simple wire, the clearWhen is not needed? Or it is to counter the setWhen?

Is it equivalent to the line below?

val myOutput = xxxx && !yyy

To me it is a different use for a register and a wire. So in Scaladoc it would be the same documentation, but in RTD (which is more tutorial-like) it would be good to explain how it is useful in different contexts.

  • For a register there is the "keep current value by default" which is nice, so the setWhen and clearWhen is like making a "clocked SR latch" XD
  • For a wire it just builds a comb equation?
  • For a latch (feat: add Latch and LatchWhen SpinalHDL#944) it is really like an SR latch, but allowing both S and R to be high, with a priority to the last one specified (last-assignment-wins rule of SpinalHDL)

@Readon
Copy link
Collaborator

Readon commented Nov 5, 2022

For the priority, as it is coded

def setWhen(cond: Bool)(implicit loc: Location): Bool   = { when(cond){ this := True }; this }
def clearWhen(cond: Bool)(implicit loc: Location): Bool = { when(cond){ this := False }; this }

Then according to the last win policy, for "setWhen(cond1) clearWhen(cond2)", clearWhen have high priority, as I understand.

@Dolu1990
Copy link
Member

Dolu1990 commented Nov 6, 2022

Or it is to counter the setWhen?

Right

Is it equivalent to the line below?

Yes

To me it is a different use for a register and a wire. So in Scaladoc it would be the same documentation, but in RTD (which is more tutorial-like) it would be good to explain how it is useful in different contexts.

Sure, no problem with it ^^

For a wire it just builds a comb equation?

Not realy equiation, but more as Readon said, a priority based logic.

@numero-744
Copy link
Collaborator Author

Great, yakafokon (fr, phonetic expression « (il n')y a qu'à…, (il) faut qu'on… » (en: "one just has to…, one has to…") to tell that we defined what to do but there is nobody yet to do it).

Contributions appreciated 🙏 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants