Comments (5)
Well, please ignore my my proposal: I realized that if that was possible, we would be able to set parameters with nets -> bad
from spinalhdl.
Now, let me rephrase my problem. Here is the BlackBox model of an hypothetical Verilog module:
case class bboxedm (io_width : Int, default_value : Int) extends BlackBox {
val generic = new Generic {
val io_width = U(bboxedm.this.io_width, 32 bit)
val default_value = B(bboxedm.this.default_value, bboxedm.this.io_width bit)
}
val io = new Bundle {
val clk = in Bool
val a = in Bits(io_width bit)
val z = out Bits(io_width bit)
}.setName("")
mapClockDomain(clock=io.clk)
}
This model guarantees that the parameter values fit the parameters width.
The blackboxed module can be instantiated as follows
val bboxedm_inst = bboxedm (io_width = 256, default_value = 2)
Now, my problem is: how can I pass a 256-bit value to the "default_value" parameter?
To solve this problem, I tried to use strings:
case class bboxedm (io_width : Int, default_value : String) extends BlackBox {
val generic = new Generic {
val io_width = U(bboxedm.this.io_width, 32 bit)
val default_value = B(bboxedm.this.io_width.toString.concat("'").concat(bboxedm.this.default_value))
}
val io = new Bundle {
val clk = in Bool
val a = in Bits(io_width bit)
val z = out Bits(io_width bit)
}.setName("")
mapClockDomain(clock=io.clk)
}
// Instance
val bboxedm_inst = bboxedm (io_width = 256, default_value = "xFFFFFFFFFFFFFFFFFFFFFFF")
This way I was able to set a parameter with with a value which does not fit 32 bits.
Now, for the sake of consistency, I would like to pass also the io_width parameter as a string.
To do so, I would need to be able to convert a UInt to an Int, so that I can set the width of the IOs:
val io = new Bundle {
val clk = in Bool
val a = in Bits(generic.io_width.toInt() bit)
val z = out Bits(generic.io_width.toInt() bit)
}.setName("")
Is there a way to cast UInt (SInt and Bits) to Int?
If this was possible, we probably could even do this:
case class bboxedm (io_width : UInt, default_value : Bits) extends BlackBox {
val generic = new Generic {
val io_width = U(bboxedm.this.io_width.toInt, 32 bit)
val default_value = B(bboxedm.this.default_value.toInt, io_width.toInt)
}
val io = new Bundle {
val clk = in Bool
val a = in Bits(generic.io_width.toInt bit)
val z = out Bits(generic.io_width.toInt bit)
}.setName("")
mapClockDomain(clock=io.clk)
}
// Instance
val bboxedm_inst = bboxedm (io_width = U(256), default_value = U"xFFFFFFFFFFFFFFFFFFFFFFF")
which looks to me more elegant than the string solution.
from spinalhdl.
Hi,
What's about :
case class bboxedm (io_width : Int, default_value : BigInt) extends BlackBox {
val generic = new Generic {
val io_width = U(bboxedm.this.io_width, 32 bit)
val default_value = U(bboxedm.this.default_value, bboxedm.this.io_width bits)
}
val io = new Bundle {
val clk = in Bool
val a = in Bits(io_width bits)
val z = out Bits(io_width bits)
}
mapClockDomain(clock=io.clk)
noIoPrefix()
}
// Instance
class TopLevel extends Component {
val bboxedm_inst = bboxedm (io_width = 256, default_value = BigInt("FFFFFFFFFFFFFFF",16))
}
from spinalhdl.
Also i'm thinking about adding this syntax to avoid the boilerplate :
case class bboxedm (io_width : Int, default_value : BigInt) extends BlackBox {
addGeneric("io_width", U(io_width, 32 bits))
addGeneric("default_value", U(default_value, io_width bits))
val io = new Bundle {
val clk = in Bool
val a = in Bits(io_width bits)
val z = out Bits(io_width bits)
}
mapClockDomain(clock=io.clk)
noIoPrefix()
}
from spinalhdl.
Brilliant! I didn't know about the BigInt (I am a newbie to Scala), looks exactly what I need.
Also the addGeneric() looks like a nice enhancement.
Thanks!!
from spinalhdl.
Related Issues (20)
- SpinalSim: onSamplings can't work properly with clock from a blackbox HOT 8
- When to override `clone`? HOT 7
- How to use Union in IO port HOT 1
- `assignDontCare` on Bundle element inside Union does not work HOT 14
- StateMachines inside Plugins that have multiple instances have naming clash HOT 2
- `Union` elements cannot be accessed inside SpinalSim properly HOT 1
- [question] Trying to understand simulator wait apis (newbie) HOT 3
- SimMutex locked repeatly crashes the simulation HOT 5
- Checking for unknown values in simulation HOT 1
- JTAG VPI Simulation gets blocked by IO HOT 2
- Dump ports of `Mem` in FST waveforms? HOT 3
- HDElkDiagram generated html could not be convert ed to image using wkhtmltoimage correctly HOT 1
- Qsysify and Axi4: incorrect _hw.tcl generation HOT 1
- Could not load XSI simulation shared library HOT 1
- Blackboxing RAM with one read and one readWrite port HOT 2
- Performance of PriorityMux HOT 18
- Redundant Flow API Calls. HOT 4
- Parallel test execution in SpinalSim? HOT 5
- Are there some bugs in clockDomain.waitSampling() API? HOT 10
- Is there a "DONT_TOUCH" attribute for Components in Spinal ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spinalhdl.