Class: RubyHDL::High::SequencerT

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

Overview

Describes a SW implementation 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.



3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3453

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 a set of sfunction used in the sequencer.
  @sfunctions = {}
  # Create the main block.
  @sblock = RubyHDL::High::Sblock.new(self,&ruby_block)
  # Build the Ruby code.
  @source = ""
  @code = nil
  self.build_ruby
end

Instance Attribute Details

#clkObject (readonly)

The clock counter.



3448
3449
3450
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3448

def clk
  @clk
end

#sourceObject (readonly)

The source code (in ruby).



3445
3446
3447
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3445

def source
  @source
end

Instance Method Details

#add_sfunction(name, sfunction) ⇒ Object

Add a sfunction.



3475
3476
3477
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3475

def add_sfunction(name,sfunction)
  @sfunctions[name.to_sym] = sfunction
end

#alive?Boolean

Check is the sequencer can still be resumed.

Returns:

  • (Boolean)


3559
3560
3561
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3559

def alive?
  @code.alive?
end

#build_rubyObject

Build the ruby code.



3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3490

def build_ruby
  this = self
  @source = "\#{RubyHDL::High.global_sblock.each_signal.map do |signal|\n  signal.to_ruby + \" ||= \" + \n    (signal.array? ? \"[]\" : signal.value? ? signal.value.inspect : \"nil\")\nend.join(\"\\n\")}\nFiber.new do\n\#{@sblock.to_ruby}\nend\n"
  # puts "building code_txt=" + @source
  self.reset!
end

#clk_up(count = 1) ⇒ Object

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



3526
3527
3528
3529
3530
3531
3532
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3526

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

#clk_up_c(count = 1) ⇒ Object

Generate a clock up of +count+ cycles if any clock for C code.



3535
3536
3537
3538
3539
3540
3541
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3535

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

#reset!Object

Resets the sequencer.



3554
3555
3556
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3554

def reset!
  @code = TOPLEVEL_BINDING.eval(@source)
end

#resumeObject Also known as: call

Executes the sequencer.



3547
3548
3549
3550
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3547

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

#sfunction(name) ⇒ Object

Get a sfunction by name.



3485
3486
3487
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3485

def sfunction(name)
  return @sfunctions[name.to_sym]
end

#sfunction?(name) ⇒ Boolean

Check if a sfunction is present.

Returns:

  • (Boolean)


3480
3481
3482
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3480

def sfunction?(name)
  return @sfunctions.key?(name.to_sym)
end

#to_cObject

Convert to C code.



3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3511

def to_c
  typ = nil
  res = "\#{RubyHDL::High.global_sblock.each_signal.map do |signal|\n  typ = signal.type\n  typ.to_c + \" \" + signal.to_c + \"=\" + typ.to_c_init + \";\"\nend.join(\"\\n\")}\n\#{sblock.to_c}\n"
  return res
end

#to_rubyObject

Get the Ruby code.



3506
3507
3508
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3506

def to_ruby
  return @code
end