Module: Origen::Model

Extended by:
ActiveSupport::Concern
Included in:
Origen::Models::Mux, Origen::Models::ScanRegister, SubBlock
Defined in:
lib/origen/model.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

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



287
288
289
290
291
292
293
294
295
296
# File 'lib/origen/model.rb', line 287

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

Instance Method Details

#_resolve_controller_classObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/origen/model.rb', line 102

def _resolve_controller_class
  klass = self.class
  while klass != Object
    controller_class = "#{klass}Controller"
    if eval("defined? #{controller_class}")
      return eval(controller_class)
    elsif eval("defined? ::#{controller_class}")
      return eval("::#{controller_class}")
    end
    klass = klass.superclass
  end
end

#add_configuration(id) ⇒ Object



130
131
132
# File 'lib/origen/model.rb', line 130

def add_configuration(id)
  configurations << id unless configurations.include?(id)
end

#add_mode(id, options = {}) {|m| ... } ⇒ Object

Yields:

  • (m)


173
174
175
176
177
178
179
# File 'lib/origen/model.rb', line 173

def add_mode(id, options = {})
  m = ChipMode.new(id, options)
  m.owner = self
  yield m if block_given?
  _add_mode(m)
  m
end

#clock!Object



303
304
305
306
# File 'lib/origen/model.rb', line 303

def clock!
  clock_prepare
  clock_apply
end

#clock_applyObject



314
315
316
317
318
# File 'lib/origen/model.rb', line 314

def clock_apply
  sub_blocks.each do |name, block|
    block.clock_apply if block.respond_to?(:clock_apply)
  end
end

#clock_prepareObject



308
309
310
311
312
# File 'lib/origen/model.rb', line 308

def clock_prepare
  sub_blocks.each do |name, block|
    block.clock_prepare if block.respond_to?(:clock_prepare)
  end
end

#configurationObject



126
127
128
# File 'lib/origen/model.rb', line 126

def configuration
  @configuration
end

#configuration=(id) ⇒ Object



121
122
123
124
# File 'lib/origen/model.rb', line 121

def configuration=(id)
  add_configuration(id)
  @configuration = id
end

#configurationsObject

Returns an array containing the IDs of all known configurations



135
136
137
# File 'lib/origen/model.rb', line 135

def configurations
  @configurations ||= []
end

#current_configurationObject



115
116
117
118
119
# File 'lib/origen/model.rb', line 115

def current_configuration
  if self.respond_to?(:configuration)
    configuration
  end
end

#current_modeObject Also known as: mode

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


159
160
161
162
163
164
# File 'lib/origen/model.rb', line 159

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!"
  end
end

#current_mode=(id) ⇒ Object Also known as: mode=

Set the current mode configuration of the current model



168
169
170
# File 'lib/origen/model.rb', line 168

def current_mode=(id)
  @current_mode = id.is_a?(ChipMode) ? id.id : id
end

#delete_all_modesObject Also known as: del_all_modes

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



226
227
228
# File 'lib/origen/model.rb', line 226

def delete_all_modes
  @_modes = nil
end

#delete_all_specs_and_notes(obj = nil) ⇒ Object

Delete all specs and notes for self recursively



260
261
262
263
264
265
266
267
268
269
# File 'lib/origen/model.rb', line 260

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

#find_specsObject

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



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/origen/model.rb', line 232

def find_specs
  specs_found = []
  # Check for specs the object owns
  if self.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) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/origen/model.rb', line 181

def has_mode?(id)
  !!(_modes[id.is_a?(ChipMode) ? id.id : id])
end

#initialized?Boolean

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

Returns:

  • (Boolean)


299
300
301
# File 'lib/origen/model.rb', line 299

def initialized?
  !!@initialized
end

#inspectObject



32
33
34
35
36
37
38
# File 'lib/origen/model.rb', line 32

def inspect
  if controller
    "<Model/Controller: #{self.class}:#{object_id}/#{controller.class}:#{controller.object_id}>"
  else
    "<Model: #{self.class}:#{object_id}>"
  end
end

#ip_nameObject



65
66
67
# File 'lib/origen/model.rb', line 65

def ip_name
  @ip_name || self.class.to_s.split('::').last.symbolize
end

#is_an_origen_model?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/origen/model.rb', line 40

def is_an_origen_model?
  true
end

#logObject



51
52
53
# File 'lib/origen/model.rb', line 51

def log
  Origen.log
end

#modelObject

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.



47
48
49
# File 'lib/origen/model.rb', line 47

def model
  self
end

#modes(id = nil, _options = {}) ⇒ Object

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



187
188
189
190
191
192
193
194
# File 'lib/origen/model.rb', line 187

def modes(id = nil, _options = {})
  id = nil if id.is_a?(Hash)
  if id
    _modes[id]
  else
    _modes.ids
  end
end

#read_memory(*args) ⇒ Object



60
61
62
63
# File 'lib/origen/model.rb', line 60

def read_memory(*args)
  return super if defined?(super)
  read_register(*args)
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


271
272
273
# File 'lib/origen/model.rb', line 271

def respond_to?(*args)
  super || !!(!@respond_directly && controller && controller.respond_to_directly?(*args))
end

#respond_to_directly?(*args) ⇒ Boolean

Returns:

  • (Boolean)


275
276
277
278
279
280
# File 'lib/origen/model.rb', line 275

def respond_to_directly?(*args)
  @respond_directly = true
  result = respond_to?(*args)
  @respond_directly = false
  result
end

#with_configuration(id, _options = {}) ⇒ Object

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.



142
143
144
145
146
147
# File 'lib/origen/model.rb', line 142

def with_configuration(id, _options = {})
  orig = configuration
  self.configuration = id
  yield
  self.configuration = orig
end

#with_each_modeObject Also known as: each_mode

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.



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/origen/model.rb', line 210

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

#with_mode(id, _options = {}) ⇒ Object

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



198
199
200
201
202
203
# File 'lib/origen/model.rb', line 198

def with_mode(id, _options = {})
  orig = mode
  self.mode = id
  yield
  self.mode = orig
end

#wrap_in_controllerObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/origen/model.rb', line 69

def wrap_in_controller
  c = Origen.controllers.find do |params|
    self.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) ⇒ Object



55
56
57
58
# File 'lib/origen/model.rb', line 55

def write_memory(*args)
  return super if defined?(super)
  write_register(*args)
end