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.



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

def c_value
  @c_value
end

#f_valueObject

Access the current and future value.



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

def f_value
  @f_value
end

Instance Method Details

#add_anyedge(beh) ⇒ Object

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



520
521
522
523
# File 'lib/HDLRuby/hruby_rsim.rb', line 520

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.



514
515
516
517
# File 'lib/HDLRuby/hruby_rsim.rb', line 514

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.



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

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

#assign(mode, value) ⇒ Object

Assigns +value+ the the reference.



552
553
554
555
556
557
558
559
# File 'lib/HDLRuby/hruby_rsim.rb', line 552

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?("xnor")
    @f_value = value.cast(self.type) # Cast not always inserted by HDLRuby normally
end

#assign_at(mode, value, index) ⇒ Object

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



562
563
564
565
566
567
568
569
570
571
572
# File 'lib/HDLRuby/hruby_rsim.rb', line 562

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.



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

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.



532
533
534
535
# File 'lib/HDLRuby/hruby_rsim.rb', line 532

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.



526
527
528
529
# File 'lib/HDLRuby/hruby_rsim.rb', line 526

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

#execute(mode) ⇒ Object

Execute the expression.



545
546
547
548
549
# File 'lib/HDLRuby/hruby_rsim.rb', line 545

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.



577
578
579
580
# File 'lib/HDLRuby/hruby_rsim.rb', line 577

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

#init_sim(systemT) ⇒ Object

Initialize the simulation for +systemT+



492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/HDLRuby/hruby_rsim.rb', line 492

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