Class: RubyHDL::High::SequencerT
- Inherits:
-
Object
- Object
- RubyHDL::High::SequencerT
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a sequencer.
Instance Attribute Summary collapse
-
#clk ⇒ Object
readonly
The clock counter.
-
#source ⇒ Object
readonly
The source code (in ruby).
Instance Method Summary collapse
-
#add_sfunction(name, sfunction) ⇒ Object
Add a sfunction.
-
#alive? ⇒ Boolean
Check is the sequencer can still be resumed.
-
#build_ruby ⇒ Object
Build the ruby code.
-
#clk_up(count = 1) ⇒ Object
Generate a clock up of +count+ cycles if any clock.
-
#clk_up_c(count = 1) ⇒ Object
Generate a clock up of +count+ cycles if any clock for C code.
-
#initialize(clk = nil, start = nil, &ruby_block) ⇒ SequencerT
constructor
Create a new sequencer block, with clock counter +clk+ and run control +start+.
-
#reset! ⇒ Object
Resets the sequencer.
-
#resume ⇒ Object
(also: #call)
Executes the sequencer.
-
#sfunction(name) ⇒ Object
Get a sfunction by name.
-
#sfunction?(name) ⇒ Boolean
Check if a sfunction is present.
-
#to_c ⇒ Object
Convert to C code.
-
#to_ruby ⇒ Object
Get the Ruby code.
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.
3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3714 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. @blk = RubyHDL::High::Sblock.new(self,&ruby_block) # Build the Ruby code. @source = "" @code = nil self.build_ruby end |
Instance Attribute Details
#clk ⇒ Object (readonly)
The clock counter.
3709 3710 3711 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3709 def clk @clk end |
#source ⇒ Object (readonly)
The source code (in ruby).
3706 3707 3708 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3706 def source @source end |
Instance Method Details
#add_sfunction(name, sfunction) ⇒ Object
Add a sfunction.
3736 3737 3738 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3736 def add_sfunction(name,sfunction) @sfunctions[name.to_sym] = sfunction end |
#alive? ⇒ Boolean
Check is the sequencer can still be resumed.
3829 3830 3831 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3829 def alive? @code.alive? end |
#build_ruby ⇒ Object
Build the ruby code.
3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3751 def build_ruby this = self @source = <<-BUILD #{RubyHDL::High.global_sblock.each_signal.map do |signal| # puts "for signal=#{signal.name} with type=#{signal.type}" case signal.dir when :input signal.to_ruby + " = RubyHDL.#{signal.name}" else signal.to_ruby + " ||= " + (signal.array? ? "[]" : signal.value? ? signal.value.inspect : "0") end end.join("\n")} #{@sfunctions.map {|n,f| f.to_ruby }.join("\n\n")} Fiber.new do #{@blk.to_ruby} end BUILD # puts "building code_txt=" + @source self.reset! end |
#clk_up(count = 1) ⇒ Object
Generate a clock up of +count+ cycles if any clock.
3796 3797 3798 3799 3800 3801 3802 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3796 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.
3805 3806 3807 3808 3809 3810 3811 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3805 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.
3824 3825 3826 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3824 def reset! @code = TOPLEVEL_BINDING.eval(@source) end |
#resume ⇒ Object Also known as: call
Executes the sequencer.
3817 3818 3819 3820 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3817 def resume # @code.call @code.resume end |
#sfunction(name) ⇒ Object
Get a sfunction by name.
3746 3747 3748 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3746 def sfunction(name) return @sfunctions[name.to_sym] end |
#sfunction?(name) ⇒ Boolean
Check if a sfunction is present.
3741 3742 3743 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3741 def sfunction?(name) return @sfunctions.key?(name.to_sym) end |
#to_c ⇒ Object
Convert to C code.
3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3781 def to_c typ = nil res = <<-BUILDC #{RubyHDL::High.global_sblock.each_signal.map do |signal| typ = signal.type typ.to_c + " " + signal.to_c + "=" + typ.to_c_init + ";" end.join("\n")} #{sblock.to_c} BUILDC return res end |
#to_ruby ⇒ Object
Get the Ruby code.
3776 3777 3778 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3776 def to_ruby return @code end |