SpinalDoc-RTD icon indicating copy to clipboard operation
SpinalDoc-RTD copied to clipboard

Document setWhen and clearWhen

Open numero-744 opened this issue 1 year ago • 5 comments

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 avatar Nov 03 '22 15:11 numero-744

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

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

Dolu1990 avatar Nov 03 '22 16:11 Dolu1990

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 (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)

numero-744 avatar Nov 04 '22 17:11 numero-744

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.

Readon avatar Nov 05 '22 12:11 Readon

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.

Dolu1990 avatar Nov 06 '22 10:11 Dolu1990

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:

numero-744 avatar Nov 07 '22 20:11 numero-744