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

Add section for idioms

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

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 }
  }

numero-744 avatar Oct 24 '22 13:10 numero-744