SpinalHDL / SpinalHDL

Scala based HDL
Other
1.62k stars 316 forks source link

About convenient anonymous bundle. #1446

Closed Readon closed 3 months ago

Readon commented 3 months ago

I am trying to practice on some full stream design, where need a bunch of interface data type between stream, almost each of the stream stage. So that I want to define some internal data type in anonymous bundle as below, but not case class for all cases.

val chainIn = input.translateWith(new Bundle { val recipe = inRecipe; val totalLen = recipeTotalLen })

However, this code would lead to error "Spinal can't clone class XXXXX datatype". According to some past issues, it is caused by the non clone able of the new bundle which is required by Stream.

Is there any other convenient way to define this?

Dolu1990 commented 3 months ago

new Bundle { val recipe = inRecipe; val totalLen = recipeTotalLen }

This is tricky, Bundle are only made to define new types, with no backed-in connectivity. There is currently no good syntax for all in one type declaration + initialization in SpinalHDL so far. You would need to define the type, then instanciate the type, then connect the type. That is quite a bit verbose. Maybe scala macro could help ?

where need a bunch of interface data type between stream, almost each of the stream stage.

Sound like a job for the lib.misc.pipeline API :) With it you will not have to define any "bundle" anywere.

Readon commented 3 months ago

Sound like a job for the lib.misc.pipeline API :) With it you will not have to define any "bundle" anywere.

Nice, that gives me enough incentive to use it.^^

Readon commented 3 months ago

The problem is that how can I work with existing utilities like StreamShiftChain?

Readon commented 3 months ago

Is it possible to get the input Stream and output Stream of a node, regardless on the cancel and forgot function^^

Dolu1990 commented 3 months ago

The problem is that how can I work with existing utilities like StreamShiftChain?

That's where things get verbose , as you need to reconstruct things to/from bundles. you can use the Node arbitrateFrom arbitrateTo function to help with the arbitration.

Readon commented 3 months ago

The problem is that how can I work with existing utilities like StreamShiftChain?

That's where things get verbose , as you need to reconstruct things to/from bundles. you can use the Node arbitrateFrom arbitrateTo function to help with the arbitration.

Emm, it seems that it is a little bit more sentences to be write. And the type should be written explicitly. Such as the code in Doc, the payload of our up and down Streams is a little bit complex.

val up = slave Stream(UInt(16 bits))
val down = master Stream(UInt(16 bits)) //Note master Stream(OUT) is good aswell

n0.driveFrom(up)((self, payload) => self(IN) := payload)
n2.driveTo(down)((payload, self) => payload := self(OUT))