SpinalDoc-RTD
SpinalDoc-RTD copied to clipboard
Document setWhen and clearWhen
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)
hmm setWhen isn't only for register. It can also be used for signals
val myOutput = out(False)
myOutput setWhen(xxxx)
myOutput clearWhen(yyy)
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
andclearWhen
is like making a "clocked SR latch" XD - For a wire it just builds a comb equation?
- For a latch (https://github.com/SpinalHDL/SpinalHDL/pull/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)
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.
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.
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 :pray: :heart: