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 }
}
Yes, such section would be usefull, showing all kind of funny / creative thing
Nice Work! This will be a shining pool of sparks for SpinalHDL.
Maybe we can do a call to discuss about patterns ?
I was thinking that each pattern would be introduced by a PR into the which we could discuss but a call might be good too.
sure.
Note for when I will have created this section:
Function-like components: a companion object with an apply.
object MyComponent {
def apply(i: MyEnum.C): Bits = {
val myComponent = new MyComponent
myComponent.io.i := i
myComponent.io.o
}
}
Once idioms are defined we can provide snippets (for instance providing them in the template) for IDEs. For instance:
"Doing flag": {
"scope": "scala",
"prefix": "doing",
"body": ["val ${2:${1}ing} = False", "def $1(): Unit = $2 := True", ""]
}
We can also provide such snippets for Component etc. Providing this kind of ready-to-use tools can improve the Scala UX XD
With this example snippet in VSCodium with 8 keystrokes:
do<Tab>run<Tab><Tab>
I get:
val runing = False
def run(): Unit = runing := True
(It can require more than the 2 keystrokes do to reach the doing snippet depending on the coding context)