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.
3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3791 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.
3786 3787 3788 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3786 def clk @clk end |
#source ⇒ Object (readonly)
The source code (in ruby).
3783 3784 3785 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3783 def source @source end |
Instance Method Details
#add_sfunction(name, sfunction) ⇒ Object
Add a sfunction.
3813 3814 3815 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3813 def add_sfunction(name,sfunction) @sfunctions[name.to_sym] = sfunction end |
#alive? ⇒ Boolean
Check is the sequencer can still be resumed.
3906 3907 3908 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3906 def alive? @code.alive? end |
#build_ruby ⇒ Object
Build the ruby code.
3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3828 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 : "nil"}]" : 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.
3873 3874 3875 3876 3877 3878 3879 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3873 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.
3882 3883 3884 3885 3886 3887 3888 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3882 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.
3901 3902 3903 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3901 def reset! @code = TOPLEVEL_BINDING.eval(@source) end |
#resume ⇒ Object Also known as: call
Executes the sequencer.
3894 3895 3896 3897 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3894 def resume # @code.call @code.resume end |
#sfunction(name) ⇒ Object
Get a sfunction by name.
3823 3824 3825 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3823 def sfunction(name) return @sfunctions[name.to_sym] end |
#sfunction?(name) ⇒ Boolean
Check if a sfunction is present.
3818 3819 3820 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3818 def sfunction?(name) return @sfunctions.key?(name.to_sym) end |
#to_c ⇒ Object
Convert to C code.
3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3858 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.
3853 3854 3855 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3853 def to_ruby return @code end |