module Origen::IPBlock

Include this module to identify it as an SoC IP Block, this will automatically include common modules such as Pin and Register support

Attributes

controller[R]
ip_name[W]
parent[RW]
version[RW]

Public Instance Methods

==(obj) click to toggle source
Calls superclass method
# File lib/origen/model.rb, line 99
def ==(obj)
  if obj.is_a?(Origen::SubBlocks::Placeholder)
    obj = obj.materialize
  end
  if controller
    super(obj) || controller.send(:==, obj, called_from_model: true)
  else
    super(obj)
  end
end
Also aliased as: equal?
_initialized?() click to toggle source

@api private Returns true after the model’s initialize method has been run

# File lib/origen/model.rb, line 382
def _initialized?
  !!@_initialized
end
_resolve_controller_class() click to toggle source
# File lib/origen/model.rb, line 164
def _resolve_controller_class
  klass = self.class
  while klass != Object
    controller_class = "#{klass}Controller"
    unless controller_class.start_with?('#<Class')
      # klass is an anonymous class. Can't support automatic resolution with anonymous classes
      if eval("defined? #{controller_class}")
        return eval(controller_class)
      elsif eval("defined? ::#{controller_class}")
        return eval("::#{controller_class}")
      end
    end
    klass = klass.superclass
  end
end
add_configuration(id) click to toggle source
# File lib/origen/model.rb, line 195
def add_configuration(id)
  configurations << id unless configurations.include?(id)
end
add_mode(id, options = {}) { |m| ... } click to toggle source
# File lib/origen/model.rb, line 253
def add_mode(id, options = {})
  m = ChipMode.new(id, options)
  m.owner = self
  yield m if block_given?
  _add_mode(m)
  m
end
app() click to toggle source

Returns the application instance that defines the model, often the current app but it could also be one of the plugins. Returns nil if the application cannot be resolved, usually because the model’s class has not been correctly namespaced.

# File lib/origen/model.rb, line 88
def app
  @app ||= Origen::Application.from_namespace(self.class.to_s)
end
attributes() click to toggle source

Returns a frozen hash containing any attributes that were derived from a block definition

# File lib/origen/model.rb, line 48
def attributes
  @attributes ||= {}.freeze
end
clock!() click to toggle source
# File lib/origen/model.rb, line 386
def clock!
  clock_prepare
  clock_apply
end
clock_apply() click to toggle source
# File lib/origen/model.rb, line 397
def clock_apply
  sub_blocks.each do |name, block|
    block.clock_apply if block.respond_to?(:clock_apply)
  end
end
clock_prepare() click to toggle source
# File lib/origen/model.rb, line 391
def clock_prepare
  sub_blocks.each do |name, block|
    block.clock_prepare if block.respond_to?(:clock_prepare)
  end
end
configuration() click to toggle source
# File lib/origen/model.rb, line 191
def configuration
  @configuration
end
configuration=(id) click to toggle source
# File lib/origen/model.rb, line 186
def configuration=(id)
  add_configuration(id)
  @configuration = id
end
configurations() click to toggle source

Returns an array containing the IDs of all known configurations

# File lib/origen/model.rb, line 200
def configurations
  @configurations ||= []
end
current_configuration() click to toggle source
# File lib/origen/model.rb, line 180
def current_configuration
  if respond_to?(:configuration)
    configuration
  end
end
current_mode() click to toggle source

Returns the current mode/configuration of the top level SoC. If no mode has been specified yet this will return nil

$dut = DUT.new
$dut.mode             # => default
$dut.mode.default?    # => true
$dut.mode.ram_bist?   # => false
$dut.mode = :ram_bist
$dut.mode.default?    # => false
$dut.mode.ram_bist?   # => true
# File lib/origen/model.rb, line 224
def current_mode
  if @current_mode
    return _modes[@current_mode] if _modes[@current_mode]

    fail "The mode #{@current_mode} of #{self.class} has not been defined!"
  else
    unless top_level?
      # Need to do this in case a class besides SubBlock includes Origen::Model
      obj_above_self = parent.nil? ? Origen.top_level : parent
      return nil if obj_above_self.nil?

      if obj_above_self.current_mode
        _modes[obj_above_self.current_mode.id] if _modes.include? obj_above_self.current_mode.id
      end
    end
  end
end
Also aliased as: mode
current_mode=(id) click to toggle source

Set the current mode configuration of the current model

# File lib/origen/model.rb, line 244
def current_mode=(id)
  @current_mode = id.is_a?(ChipMode) ? id.id : id
  Origen.app.listeners_for(:on_mode_changed).each do |listener|
    listener.on_mode_changed(mode: @current_mode, instance: self)
  end
  @current_mode     # rubocop:disable Lint/Void
end
Also aliased as: mode=
del_all_modes()
Alias for: delete_all_modes
delete_all_modes() click to toggle source

Sets the modes array to nil. Written so modes created in memory can be erased so modes defined in Ruby files can be loaded

# File lib/origen/model.rb, line 306
def delete_all_modes
  @_modes = nil
end
Also aliased as: del_all_modes
delete_all_specs_and_notes(obj = nil) click to toggle source

Delete all specs and notes for self recursively

# File lib/origen/model.rb, line 341
def delete_all_specs_and_notes(obj = nil)
  obj = self if obj.nil?
  obj.delete_all_specs
  obj.delete_all_notes
  obj.delete_all_exhibits
  obj.children.each do |_name, child|
    next unless child.has_specs?

    delete_all_specs_and_notes(child)
  end
end
each_mode()
Alias for: with_each_mode
equal?(obj)
Alias for: ==
find_specs() click to toggle source

Returns all specs found for the model. if none found it returns an empty array

# File lib/origen/model.rb, line 312
def find_specs
  specs_found = []
  # Check for specs the object owns
  if respond_to? :specs
    object_specs = specs
    unless object_specs.nil?
      if object_specs.class == Origen::Specs::Spec
        specs_found << object_specs
      else
        specs_found.concat(object_specs)
      end
    end
  end
  sub_blocks.each do |_name, sb|
    next unless sb.respond_to? :specs

    child_specs = sb.specs
    unless child_specs.nil?
      if child_specs.class == Origen::Specs::Spec
        specs_found << child_specs
      else
        specs_found.concat(child_specs)
      end
    end
  end
  specs_found
end
has_mode?(id) click to toggle source
# File lib/origen/model.rb, line 261
def has_mode?(id)
  !!(_modes[id.is_a?(ChipMode) ? id.id : id])
end
inspect() click to toggle source
# File lib/origen/model.rb, line 52
def inspect
  if controller
    "<Model/Controller: #{self.class}:#{object_id}/#{controller.class}:#{controller.object_id}>"
  else
    "<Model: #{self.class}:#{object_id}>"
  end
end
ip_name() click to toggle source
# File lib/origen/model.rb, line 127
def ip_name
  @ip_name || self.class.to_s.split('::').last.symbolize
end
is_a_model_and_controller?() click to toggle source

Returns true if the instance is an Origen::Model that is wrapped in a controller

# File lib/origen/model.rb, line 66
def is_a_model_and_controller?
  !!controller
end
is_an_origen_model?() click to toggle source
# File lib/origen/model.rb, line 60
def is_an_origen_model?
  true
end
is_dut?()
Alias for: is_top_level?
is_top_level?() click to toggle source

Returns true if the model is the current DUT/top-level model

# File lib/origen/model.rb, line 71
def is_top_level?
  respond_to?(:includes_origen_top_level?)
end
Also aliased as: is_dut?, top_level?
load_block(path, options = {}) click to toggle source

Load the block definitions from the given path to the model. Returns true if a block is found and loaded, otherwise nil.

# File lib/origen/model.rb, line 94
def load_block(path, options = {})
  options[:path] = path
  Origen::Loader.load_block(self, options)
end
log() click to toggle source
# File lib/origen/model.rb, line 111
def log
  Origen.log
end
method_missing(method, *args, &block) click to toggle source

Used to proxy all method and attribute requests not implemented on the model to the controller.

On first call of a missing method a method is generated to avoid the missing lookup next time, this should be faster for repeated lookups of the same method, e.g. reg

Calls superclass method Origen::Ports#method_missing
# File lib/origen/model.rb, line 369
def method_missing(method, *args, &block)
  if controller.respond_to?(method)
    define_singleton_method(method) do |*args, &block|
      controller.send(method, *args, &block)
    end
    send(method, *args, &block)
  else
    super
  end
end
mode()
Alias for: current_mode
mode=(id)
Alias for: current_mode=
model() click to toggle source

Means that when dealing with a controller/model pair, you can always call obj.model and obj.controller to get the one you want, regardless of the one you currently have.

# File lib/origen/model.rb, line 80
def model
  self
end
modes(id = nil, _options = {}) click to toggle source

Returns an array containing the IDs of all known modes if no ID is supplied, otherwise returns an object representing the given mode ID

# File lib/origen/model.rb, line 267
def modes(id = nil, _options = {})
  id = nil if id.is_a?(Hash)
  if id
    _modes[id]
  else
    _modes.ids
  end
end
read_memory(*args) click to toggle source
Calls superclass method
# File lib/origen/model.rb, line 121
def read_memory(*args)
  return super if defined?(super)

  read_register(*args)
end
respond_to?(*args) click to toggle source
Calls superclass method Origen::Ports#respond_to?
# File lib/origen/model.rb, line 353
def respond_to?(*args)
  super || !!(!@respond_directly && controller && controller.respond_to_directly?(*args))
end
respond_to_directly?(*args) click to toggle source
# File lib/origen/model.rb, line 357
def respond_to_directly?(*args)
  @respond_directly = true
  result = respond_to?(*args)
  @respond_directly = false
  result
end
to_json(*args) click to toggle source
# File lib/origen/model.rb, line 403
def to_json(*args)
  JSON.pretty_generate({
                         name:      name,
                         address:   base_address,
                         path:      path,
                         blocks:    sub_blocks.map do |name, block|
                           {
                             name:    name,
                             address: block.base_address
                           }
                         end,
                         registers: regs.map do |name, reg|
                           reg
                         end
                       }, *args)
end
top_level?()
Alias for: is_top_level?
with_configuration(id, _options = {}) { || ... } click to toggle source

Execute the supplied block within the context of the given configuration, at the end the model’s configuration attribute will be restored to what it was before calling this method.

# File lib/origen/model.rb, line 207
def with_configuration(id, _options = {})
  orig = configuration
  self.configuration = id
  yield
  self.configuration = orig
end
with_each_mode() { |mode| ... } click to toggle source

Executes the given block of code for each known chip mode, inside the block the current mode of the top level block will be set to the given mode.

At the end of the block the current mode will be restored to whatever it was before entering the block.

# File lib/origen/model.rb, line 290
def with_each_mode
  begin
    orig = current_mode
  rescue
    orig = nil
  end
  modes.each do |_id, mode|
    self.current_mode = mode
    yield mode
  end
  self.current_mode = orig
end
Also aliased as: each_mode
with_mode(id, _options = {}) { || ... } click to toggle source

Executes the given block of code within the context of the given mode, at the end the mode will be restored back to what it was on entry

# File lib/origen/model.rb, line 278
def with_mode(id, _options = {})
  orig = mode
  self.mode = id
  yield
  self.mode = orig
end
wrap_in_controller() click to toggle source
# File lib/origen/model.rb, line 131
def wrap_in_controller
  c = Origen.controllers.find do |params|
    is_a?(params[:model_class]) if params[:model_class]
  end
  if c
    c = c[:controller_class].send(:allocate)
    if c.method(:initialize).arity == 0
      c.send(:initialize)
    else
      c.send(:initialize, self)
    end
    c.send('_model=', self)
    @controller = c
    c
  else
    controller_class = _resolve_controller_class
    if controller_class
      c = controller_class.send(:allocate)
      if c.method(:initialize).arity == 0
        c.send(:initialize)
      else
        c.send(:initialize, self)
      end
      c.extend(Origen::Controller)
      c.send('_model=', self)
      @controller = c
      c
    else
      self
    end
  end
end
write_memory(*args) click to toggle source
Calls superclass method
# File lib/origen/model.rb, line 115
def write_memory(*args)
  return super if defined?(super)

  write_register(*args)
end

Private Instance Methods

_add_mode(mode) click to toggle source
# File lib/origen/model.rb, line 434
def _add_mode(mode)
  if _modes[mode.id]
    fail "There is already a mode called #{mode.id}!"
  else
    _modes[mode.id] = mode
  end
end
_controller=(controller) click to toggle source
# File lib/origen/model.rb, line 426
def _controller=(controller)
  @controller = controller
end
_initialized() click to toggle source
# File lib/origen/model.rb, line 422
def _initialized
  @_initialized = true
end
_modes() click to toggle source
# File lib/origen/model.rb, line 430
def _modes
  @_modes ||= {}
end