|
This post originated from an RSS feed registered with Ruby Buzz
by Phil Tomson.
|
Original Post: Added generics
Feed Title: Thoughtfiz
Feed URL: http://wiki.railsplayground.net//xml/rss/feed.xml
Feed Description: Thoughtfiz: lots of tiny thought bubbles, mostly Ruby-related.
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Phil Tomson
Latest Posts From Thoughtfiz
|
|
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:
clk = Signal(Bit.new('0'))
rst = Signal(Bit.new('1'))
cout= Signal(0)
fsm = Counter.new(clk,rst,cout,4)
Or if you just wanted the default modulo-8 counter you could just do:
fsm = Counter.new(clk,rst,cout)
TODO next: introduce named associations so that the user could instantiate a component like so:
Circuit.new_named_assoc(:clk=>clock,:rst=>reset,:out=>output)
...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]
Read: Added generics