The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Added generics

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Phil Tomson

Posts: 16
Nickname: philtomson
Registered: Mar, 2006

Phil Tomson is working on strange (and hopefully wonderful) things often Ruby-related.
Added generics Posted: Mar 21, 2006 2:32 PM
Reply to this message Reply

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

Advertisement
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

Topic: Keeping your apps on the edge without using svn:externals Previous Topic   Next Topic Topic: My initial VPS backup script

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use