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.
3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3836 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.
3831 3832 3833 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3831 def clk @clk end |
#source ⇒ Object (readonly)
The source code (in ruby).
3828 3829 3830 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3828 def source @source end |
Instance Method Details
#add_sfunction(name, sfunction) ⇒ Object
Add a sfunction.
3858 3859 3860 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3858 def add_sfunction(name,sfunction) @sfunctions[name.to_sym] = sfunction end |
#alive? ⇒ Boolean
Check is the sequencer can still be resumed.
3969 3970 3971 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3969 def alive? @code.alive? end |
#build_ruby ⇒ Object
Build the ruby code.
3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3873 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.
3936 3937 3938 3939 3940 3941 3942 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3936 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.
3945 3946 3947 3948 3949 3950 3951 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3945 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.
3964 3965 3966 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3964 def reset! @code = TOPLEVEL_BINDING.eval(@source) end |
#resume ⇒ Object Also known as: call
Executes the sequencer.
3957 3958 3959 3960 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3957 def resume # @code.call @code.resume end |
#sfunction(name) ⇒ Object
Get a sfunction by name.
3868 3869 3870 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3868 def sfunction(name) return @sfunctions[name.to_sym] end |
#sfunction?(name) ⇒ Boolean
Check if a sfunction is present.
3863 3864 3865 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3863 def sfunction?(name) return @sfunctions.key?(name.to_sym) end |
#to_c ⇒ Object
Convert to C code.
3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3903 def to_c typ = nil res = <<-BUILDC #include <stdio.h> #{RubyHDL::High.global_sblock.each_signal.map do |signal| typ = signal.type if signal.value? then if signal.array? then typ.base.to_c + " " + signal.to_c + "[#{typ.size}]" " = {" + signal.value.inspect[1..-2] + "};" else typ.to_c + " " + signal.to_c + "=" + signal.value.inspect + ";" end else if signal.array? then typ.base.to_c + " " + signal.to_c + "[#{typ.size}]" + " =" + typ.to_c_init + ";" else typ.to_c + " " + signal.to_c + "=" + typ.to_c_init + ";" end end end.join("\n")} #{@sfunctions.map {|n,f| f.to_c }.join("\n\n")} void sequencer() #{@blk.to_c} BUILDC return res end |
#to_ruby ⇒ Object
Get the Ruby code.
3898 3899 3900 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3898 def to_ruby return @code end |