Class: HDLRuby::High::SignalI

Inherits:
Low::SignalI show all
Includes:
HRef, SimSignal, WithFullname
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb,
lib/HDLRuby/hruby_high_fullname.rb

Overview

Describes a signal.

Constant Summary collapse

High =
HDLRuby::High
DIRS =

The valid bounding directions.

[ :no, :input, :output, :inout, :inner ]

Constants included from Low::Low2Symbol

Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable

Instance Attribute Summary collapse

Attributes included from SimSignal

#c_value, #f_value

Attributes inherited from Low::SignalI

#name, #type, #value

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from WithFullname

#fullname

Methods included from SimSignal

#add_anyedge, #add_negedge, #add_posedge, #assign, #assign_at, #each_anyedge, #each_negedge, #each_posedge, #execute, #fullname, #get_vars_with_fullname, #get_vars_with_idstr, #init_sim, #show_hierarchy

Methods included from HRef

#each, included, #objects, #to_event

Methods included from Enumerable

#seach

Methods inherited from Low::SignalI

#add_signal, #clone, #each_deep, #each_signal, #explicit_types!, #get_by_name, #get_signal, #immutable?, #replace_names!, #set_name!, #set_type!, #set_value!, #to_c, #to_c_alias, #to_c_signal, #to_ch, #to_hdr, #to_high, #to_verilog, #to_vhdl, #width

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#absolute_ref, #hierarchy, #no_parent!, #scope

Constructor Details

#initialize(name, type, dir, value = nil) ⇒ SignalI

Creates a new signal named +name+ typed as +type+ with +dir+ as bounding direction and possible +value+.

NOTE: +dir+ can be :input, :output, :inout or :inner



4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
# File 'lib/HDLRuby/hruby_high.rb', line 4028

def initialize(name,type,dir,value =  nil)
    # Check the value.
    value = value.to_expr.match_type(type) if value
    # Initialize the type structure.
    super(name,type,value)

    unless name.empty? then
        # Named signal, set the hdl-like access to the signal.
        obj = self # For using the right self within the proc
        High.space_reg(name) { obj }
    end

    # Hierarchical type allows access to sub references, so generate
    # the corresponding methods.
    # For that first get the real type.
    type = type.def while type.is_a?(TypeDef)
    # Now process it if it is a structured type.
    if type.struct? then
        type.each_name do |name|
            sig = SignalI.new(name,type.get_type(name),dir)
            self.add_signal(sig)
            self.define_singleton_method(name) do
                RefObject.new(self.to_ref,sig)
            end
        end
    end

    # Check and set the bound.
    self.dir = dir

    # Set the read and write authorisations.
    @can_read = 1.to_expr
    @can_write = 1.to_expr
end

Instance Attribute Details

#can_readObject

Tells if the signal can be read.



4019
4020
4021
# File 'lib/HDLRuby/hruby_high.rb', line 4019

def can_read
  @can_read
end

#can_writeObject

Tells if the signal can be written.



4022
4023
4024
# File 'lib/HDLRuby/hruby_high.rb', line 4022

def can_write
  @can_write
end

#dirObject

The bounding direction.



4016
4017
4018
# File 'lib/HDLRuby/hruby_high.rb', line 4016

def dir
  @dir
end

#rcsignalIObject (readonly)

Extends the SignalI class for hybrid Ruby-C simulation.



428
429
430
# File 'lib/HDLRuby/hruby_rcsim.rb', line 428

def rcsignalI
  @rcsignalI
end

Instance Method Details

#anyedgeObject

Creates an edge event from the signal.



4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
# File 'lib/HDLRuby/hruby_high.rb', line 4108

def anyedge
    # return Event.new(:edge,self.to_ref)
    # Is there any sub signals?
    if self.each_signal.any? then
        # Yes, make events with them instead.
        return self.each_signal.map { |sig| sig.anyedge }
    else
        # No, create a single event.
        return Event.new(:anyedge,self.to_ref)
    end
end

#coerce(obj) ⇒ Object

Coerce by converting signal to an expression.



4131
4132
4133
# File 'lib/HDLRuby/hruby_high.rb', line 4131

def coerce(obj)
    return [obj,self.to_expr]
end

#low_objectObject

Get the low version off the object. NOTE: only useful for Signals and SystemIs since they can be accessed from outside the module they have been defined in.



4138
4139
4140
# File 'lib/HDLRuby/hruby_high.rb', line 4138

def low_object
    return @low_object
end

#negedgeObject

Creates a negative edge event from the signal.



4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
# File 'lib/HDLRuby/hruby_high.rb', line 4095

def negedge
    # return Event.new(:negedge,self.to_ref)
    # Is there any sub signals?
    if self.each_signal.any? then
        # Yes, make events with them instead.
        return self.each_signal.map { |sig| sig.negedge }
    else
        # No, create a single event.
        return Event.new(:negedge,self.to_ref)
    end
end

#posedgeObject

Creates a positive edge event from the signal.



4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
# File 'lib/HDLRuby/hruby_high.rb', line 4082

def posedge
    # return Event.new(:posedge,self.to_ref)
    # Is there any sub signals?
    if self.each_signal.any? then
        # Yes, make events with them instead.
        return self.each_signal.map { |sig| sig.posedge }
    else
        # No, create a single event.
        return Event.new(:posedge,self.to_ref)
    end
end

#to_exprObject

Converts to a new expression.



4126
4127
4128
# File 'lib/HDLRuby/hruby_high.rb', line 4126

def to_expr
    return self.to_ref
end

#to_low(name = self.name) ⇒ Object

Converts the system to HDLRuby::Low and set its +name+.



4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
# File 'lib/HDLRuby/hruby_high.rb', line 4143

def to_low(name = self.name)
    # return HDLRuby::Low::SignalI.new(name,self.type.to_low)
    valueL = self.value ? self.value.to_low : nil
    signalIL = HDLRuby::Low::SignalI.new(name,self.type.to_low,valueL)
    @low_object = signalIL
    # Recurse on the sub signals if any.
    self.each_signal do |sig|
        signalIL.add_signal(sig.to_low)
    end
    # # For debugging: set the source high object 
    # signalIL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = signalIL
    return signalIL
end

#to_rcsim(rcowner) ⇒ Object

Generate the C description of the signal comming from object whose C description is +rcowner+



432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/HDLRuby/hruby_rcsim.rb', line 432

def to_rcsim(rcowner)
    # Create the signal C object.
    @rcsignalI = RCSim.rcsim_make_signal(self.name.to_s,
                                   self.type.to_rcsim)
    # puts "to_rcsim for signal=(#{self.name})#{self}, @rcsignalI=#{@rcsignalI}"

    # Set the owner.
    RCSim.rcsim_set_owner(@rcsignalI,rcowner)

    # Create and add the sub signals if any.
    RCSim.rcsim_add_signal_signals(@rcsignalI,
                                   self.each_signal.each.map do |sig|
        sig.to_rcsim(@rcsignalI)
    end)

    # Set the initial value if any.
    if self.value then
        RCSim.rcsim_set_signal_value(@rcsignalI,self.value.to_rcsim)
    end

    return @rcsignalI
end

#to_refObject

Converts to a new reference.



4121
4122
4123
# File 'lib/HDLRuby/hruby_high.rb', line 4121

def to_ref
    return RefObject.new(this,self)
end