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.
3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3727 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.
3722 3723 3724 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3722 def clk @clk end |
#source ⇒ Object (readonly)
The source code (in ruby).
3719 3720 3721 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3719 def source @source end |
Instance Method Details
#add_sfunction(name, sfunction) ⇒ Object
Add a sfunction.
3749 3750 3751 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3749 def add_sfunction(name,sfunction) @sfunctions[name.to_sym] = sfunction end |
#alive? ⇒ Boolean
Check is the sequencer can still be resumed.
3842 3843 3844 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3842 def alive? @code.alive? end |
#build_ruby ⇒ Object
Build the ruby code.
3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3764 def build_ruby this = self @source = "\#{RubyHDL::High.global_sblock.each_signal.map do |signal|\n # puts \"for signal=\#{signal.name} with type=\#{signal.type}\"\n case signal.dir\n when :input\n signal.to_ruby + \" = RubyHDL.\#{signal.name}\"\n else\n signal.to_ruby + \" ||= \" + \n (signal.array? ? \"[]\" : signal.value? ? signal.value.inspect : \"0\")\n end\nend.join(\"\\n\")}\n\n\#{@sfunctions.map {|n,f| f.to_ruby }.join(\"\\n\\n\")}\n\nFiber.new do\n\#{@blk.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.
3809 3810 3811 3812 3813 3814 3815 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3809 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.
3818 3819 3820 3821 3822 3823 3824 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3818 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.
3837 3838 3839 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3837 def reset! @code = TOPLEVEL_BINDING.eval(@source) end |
#resume ⇒ Object Also known as: call
Executes the sequencer.
3830 3831 3832 3833 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3830 def resume # @code.call @code.resume end |
#sfunction(name) ⇒ Object
Get a sfunction by name.
3759 3760 3761 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3759 def sfunction(name) return @sfunctions[name.to_sym] end |
#sfunction?(name) ⇒ Boolean
Check if a sfunction is present.
3754 3755 3756 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3754 def sfunction?(name) return @sfunctions.key?(name.to_sym) end |
#to_c ⇒ Object
Convert to C code.
3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3794 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_ruby ⇒ Object
Get the Ruby code.
3789 3790 3791 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3789 def to_ruby return @code end |