Class: RubyHDL::High::SequencerT

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implmentation of a sequencer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clk = nil, start = nil, &ruby_block) ⇒ SequencerT

Create a new sequencer block, with clock counter +clk+ and run control +start+. Note: if +clk+ is not provided no clock counter will be generate.



2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2721

def initialize(clk = nil, start = nil, &ruby_block)
  # Sets the clock counter and start control.
  @clk = clk
  @start = start
  if @start then
    this = self
    # Make @start a controlling signal.
    @start.define_singleton_method(:<=,val) do
      this.resume if val.to_i == 1
    end
  end
  # # Create the set of signals to update.
  # @to_updates = []
  # Create the main block.
  @sblock = RubyHDL::High::Sblock.new(self,&ruby_block)
  # Build the Ruby code.
  @source = ""
  @code = nil
  self.build
end

Instance Attribute Details

#clkObject (readonly)

The clock counter.



2716
2717
2718
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2716

def clk
  @clk
end

#sourceObject (readonly)

The source code (in ruby).



2713
2714
2715
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2713

def source
  @source
end

Instance Method Details

#alive?Boolean

Check is the sequencer can still be resumed.

Returns:

  • (Boolean)


2793
2794
2795
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2793

def alive?
  @code.alive?
end

#buildObject

Build the ruby code.



2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2757

def build
  this = self
  @source = <<-BUILD
#{RubyHDL::High.global_sblock.each_signal.map do |signal|
  signal.to_ruby + " = " + (signal.array? ? "[]" : "nil") + " unless defined?(" + signal.to_ruby + ")"
end.join("\n")}
Fiber.new do
#{@sblock.to_ruby}
end
BUILD
  # puts "building code_txt=" + @source
  @code = TOPLEVEL_BINDING.eval(@source)
end

#clk_up(count = 1) ⇒ Object

Generate a clock up of +count+ cycles if any clock.



2774
2775
2776
2777
2778
2779
2780
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2774

def clk_up(count = 1)
  if @clk then
    return "#{clk.to_ruby} += #{count.to_i}"
  else
    return ""
  end
end

#resumeObject Also known as: call

Executes the sequencer.



2786
2787
2788
2789
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2786

def resume
  # @code.call
  @code.resume
end