Module: HDLRuby::High::SimSignal

Included in:
SignalC, SignalI
Defined in:
lib/HDLRuby/hruby_rsim.rb

Overview

Module for extending signal classes with Ruby-level simulation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#c_valueObject

Access the current and future value.



451
452
453
# File 'lib/HDLRuby/hruby_rsim.rb', line 451

def c_value
  @c_value
end

#f_valueObject

Access the current and future value.



451
452
453
# File 'lib/HDLRuby/hruby_rsim.rb', line 451

def f_value
  @f_value
end

Instance Method Details

#add_anyedge(beh) ⇒ Object

Adds behavior +beh+ activated on a any edge of the signal.



482
483
484
485
# File 'lib/HDLRuby/hruby_rsim.rb', line 482

def add_anyedge(beh)
    @anyedge_behaviors ||= []
    @anyedge_behaviors << beh
end

#add_negedge(beh) ⇒ Object

Adds behavior +beh+ activated on a negative edge of the signal.



476
477
478
479
# File 'lib/HDLRuby/hruby_rsim.rb', line 476

def add_negedge(beh)
    @negedge_behaviors ||= []
    @negedge_behaviors << beh
end

#add_posedge(beh) ⇒ Object

Adds behavior +beh+ activated on a positive edge of the signal.



470
471
472
473
# File 'lib/HDLRuby/hruby_rsim.rb', line 470

def add_posedge(beh)
    @posedge_behaviors ||= []
    @posedge_behaviors << beh
end

#assign(mode, value) ⇒ Object

Assigns +value+ the the reference.



514
515
516
517
518
519
520
521
# File 'lib/HDLRuby/hruby_rsim.rb', line 514

def assign(mode,value)
    # Set the next value.
    @f_value = value
    # Set the mode.
    @mode = mode
    # puts "assign #{value.content} (#{value.content.class}) with self.type.width=#{self.type.width} while value.type.width=#{value.type.width}" if self.name.to_s.include?("idx")
    # @f_value = value.cast(self.type) # Cast inserted by HDLRuby normally
end

#assign_at(mode, value, index) ⇒ Object

Assigns +value+ at +index+ (integer or range).



524
525
526
527
528
529
530
531
532
533
534
# File 'lib/HDLRuby/hruby_rsim.rb', line 524

def assign_at(mode,value,index)
    # @f_value = @f_value.assign_at(mode,value,index)
    # Sets the next value.
    if (@f_value.equal?(@c_value)) then
        # Need to duplicate @f_value to avoid side effect.
        @f_value = Value.new(@f_value.type,@f_value.content.clone)
    end
    @f_value[index] = value
    # Sets the mode
    @mode = mode
end

#each_anyedge(&ruby_block) ⇒ Object

Iterates over the behaviors activated on any edge.



500
501
502
503
# File 'lib/HDLRuby/hruby_rsim.rb', line 500

def each_anyedge(&ruby_block)
    @anyedge_behaviors ||= []
    @anyedge_behaviors.each(&ruby_block)
end

#each_negedge(&ruby_block) ⇒ Object

Iterates over the behaviors activated on a negative edge.



494
495
496
497
# File 'lib/HDLRuby/hruby_rsim.rb', line 494

def each_negedge(&ruby_block)
    @negedge_behaviors ||= []
    @negedge_behaviors.each(&ruby_block)
end

#each_posedge(&ruby_block) ⇒ Object

Iterates over the behaviors activated on a positive edge.



488
489
490
491
# File 'lib/HDLRuby/hruby_rsim.rb', line 488

def each_posedge(&ruby_block)
    @posedge_behaviors ||= []
    @posedge_behaviors.each(&ruby_block)
end

#execute(mode) ⇒ Object

Execute the expression.



507
508
509
510
511
# File 'lib/HDLRuby/hruby_rsim.rb', line 507

def execute(mode)
    # puts "Executing signal=#{self.fullname}"
    # return mode == :par ? self.c_value : self.f_value
    return @mode == :seq ? self.f_value : self.c_value
end

#fullnameObject

Returns the name of the signal with its hierarchy.



539
540
541
542
# File 'lib/HDLRuby/hruby_rsim.rb', line 539

def fullname
    @fullname ||= self.parent.fullname + ":" + self.name.to_s
    return @fullname
end

#init_sim(systemT) ⇒ Object

Initialize the simulation for +systemT+



454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/HDLRuby/hruby_rsim.rb', line 454

def init_sim(systemT)
    if self.value then
        @c_value = self.value.execute(:par).to_value
        @f_value = @c_value.to_value
        # puts "init signal value at=#{@c_value.to_bstr}"
        # The signal is considered active.
        systemT.add_sig_active(self)
    else
        # @c_value = Value.new(self.type,"x" * self.type.width)
        # @f_value = Value.new(self.type,"x" * self.type.width)
        @c_value = Value.new(self.type,"x")
        @f_value = Value.new(self.type,"x")
    end
end