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+.
-
#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.
3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3365 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
#clk ⇒ Object (readonly)
The clock counter.
3360 3361 3362 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3360 def clk @clk end |
#source ⇒ Object (readonly)
The source code (in ruby).
3357 3358 3359 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3357 def source @source end |
Instance Method Details
#add_sfunction(name, sfunction) ⇒ Object
Add a sfunction.
3387 3388 3389 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3387 def add_sfunction(name,sfunction) @sfunctions[name.to_sym] = sfunction end |
#alive? ⇒ Boolean
Check is the sequencer can still be resumed.
3466 3467 3468 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3466 def alive? @code.alive? end |
#build_ruby ⇒ Object
Build the ruby code.
3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3402 def build_ruby this = self @source = <<-BUILD #{RubyHDL::High.global_sblock.each_signal.map do |signal| signal.to_ruby + " ||= " + (signal.array? ? "[]" : signal.value? ? signal.value.inspect : "nil") end.join("\n")} Fiber.new do #{@sblock.to_ruby} end BUILD # puts "building code_txt=" + @source @code = TOPLEVEL_BINDING.eval(@source) end |
#clk_up(count = 1) ⇒ Object
Generate a clock up of +count+ cycles if any clock.
3438 3439 3440 3441 3442 3443 3444 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3438 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.
3447 3448 3449 3450 3451 3452 3453 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3447 def clk_up_c(count = 1) if @clk then return "#{clk.to_c} += #{count.to_i};" else return "" end end |
#resume ⇒ Object Also known as: call
Executes the sequencer.
3459 3460 3461 3462 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3459 def resume # @code.call @code.resume end |
#sfunction(name) ⇒ Object
Get a sfunction by name.
3397 3398 3399 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3397 def sfunction(name) return @sfunctions[name.to_sym] end |
#sfunction?(name) ⇒ Boolean
Check if a sfunction is present.
3392 3393 3394 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3392 def sfunction?(name) return @sfunctions.key?(name.to_sym) end |
#to_c ⇒ Object
Convert to C code.
3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3423 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.
3418 3419 3420 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3418 def to_ruby return @code end |