In another move that makes RHDL look a lot like VHDL (and I'm not sure that's always a good thing ;-) I've introduced generics into RHDL. A generic is a piece of data passed into the construction (or instantiation) of a design element/circuit to customize it. Generics are distinct from Signals. A generic always has a default value.
To illustrate how a generic is used, here's an example of a modulo-N counter implemented in RHDL:
Counter = model {
MODULO = 8
inputs clk, reset
outputs count
generics mod=>MODULO
init {
c = 0
define_behavior {
puts "in behavior... clk: #{clk} clk.event is: #{clk.event}"
process(clk) {
puts "in process"
if clk.event and clk == '1'
puts "rising edge of clk"
if reset == '1' || c== (mod-1)
c = 0
else
c = c+1
end
count <= c
end
}
}
}
}
Now you could instantiate a modulo-4 Counter object like so:
...that would make it a lot easier for the user so they don't have to remember argument order in cases where a component has lots of inputs and outputs. [No (safe) way to get around symbols for this feature]