SpinalDoc-RTD
SpinalDoc-RTD copied to clipboard
Add section for idioms
Spinal enables representing the code in a way which is not possible in RTL.
This section would show idioms which are useful in Spinal. For each idiom, it would explain it, how to use it, when and why it is good to use it, and maybe how it works.
Example of idiom:
val doSomethingFlag = False
def doSomething(): Unit = doSomethingFlag := True
I find it useful in fsm.State.whenActive
to express the output logic.
val fsm = new StateMachine {
val IDLE, Rnd0, RndI, RndN, DONE = new State
setEntry(IDLE)
// Transition logic
IDLE.whenIsActive { when(io.start) { goto(Rnd0) } }
Rnd0.whenIsActive { goto(RndI) }
RndI.whenIsActive { when(round.isLast) { goto(RndN) } }
RndN.whenIsActive { goto(DONE) }
DONE.whenIsActive { when(!io.start) { goto(IDLE) } }
// Output logic, using only this idiom
IDLE.whenIsActive { round.resetCount }
Rnd0.whenIsActive { run; useInputs }
RndI.whenIsActive { run }
RndN.whenIsActive { run; withoutMixColumns }
DONE.whenIsActive { enableOutput }
}