Module: Origen::Model
- Extended by:
- ActiveSupport::Concern
- Included in:
- Component::Default, Origen::Models::Mux, Origen::Models::ScanRegister, SubBlock
- Defined in:
- lib/origen/model.rb,
lib/origen/model/exporter.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, Exporter
Instance Method Summary collapse
- #==(obj) ⇒ Object (also: #equal?)
-
#_initialized? ⇒ Boolean
private
Returns true after the model’s initialize method has been run.
- #_resolve_controller_class ⇒ Object
- #add_configuration(id) ⇒ Object
- #add_mode(id, options = {}) {|m| ... } ⇒ Object
- #clock! ⇒ Object
- #clock_apply ⇒ Object
- #clock_prepare ⇒ Object
- #configuration ⇒ Object
- #configuration=(id) ⇒ Object
-
#configurations ⇒ Object
Returns an array containing the IDs of all known configurations.
- #current_configuration ⇒ Object
-
#current_mode ⇒ Object
(also: #mode)
Returns the current mode/configuration of the top level SoC.
-
#current_mode=(id) ⇒ Object
(also: #mode=)
Set the current mode configuration of the current model.
-
#delete_all_modes ⇒ Object
(also: #del_all_modes)
Sets the modes array to nil.
-
#delete_all_specs_and_notes(obj = nil) ⇒ Object
Delete all specs and notes for self recursively.
-
#find_specs ⇒ Object
Returns all specs found for the model.
- #has_mode?(id) ⇒ Boolean
- #inspect ⇒ Object
- #ip_name ⇒ Object
-
#is_a_model_and_controller? ⇒ Boolean
Returns true if the instance is an Origen::Model that is wrapped in a controller.
- #is_an_origen_model? ⇒ Boolean
-
#is_top_level? ⇒ Boolean
(also: #is_dut?, #top_level?)
Returns true if the model is the current DUT/top-level model.
- #log ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
Used to proxy all method and attribute requests not implemented on the model to the controller.
-
#model ⇒ Object
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.
-
#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.
- #read_memory(*args) ⇒ Object
- #respond_to?(*args) ⇒ Boolean
- #respond_to_directly?(*args) ⇒ Boolean
- #to_json(*args) ⇒ Object
-
#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.
-
#with_each_mode ⇒ Object
(also: #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.
-
#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.
- #wrap_in_controller ⇒ Object
- #write_memory(*args) ⇒ Object
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
336 337 338 339 340 341 342 343 344 345 |
# File 'lib/origen/model.rb', line 336 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
#==(obj) ⇒ Object Also known as: equal?
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/origen/model.rb', line 77 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 |
#_initialized? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true after the model’s initialize method has been run
349 350 351 |
# File 'lib/origen/model.rb', line 349 def _initialized? !!@_initialized end |
#_resolve_controller_class ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/origen/model.rb', line 140 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) ⇒ Object
171 172 173 |
# File 'lib/origen/model.rb', line 171 def add_configuration(id) configurations << id unless configurations.include?(id) end |
#add_mode(id, options = {}) {|m| ... } ⇒ Object
222 223 224 225 226 227 228 |
# File 'lib/origen/model.rb', line 222 def add_mode(id, = {}) m = ChipMode.new(id, ) m.owner = self yield m if block_given? _add_mode(m) m end |
#clock! ⇒ Object
353 354 355 356 |
# File 'lib/origen/model.rb', line 353 def clock! clock_prepare clock_apply end |
#clock_apply ⇒ Object
364 365 366 367 368 |
# File 'lib/origen/model.rb', line 364 def clock_apply sub_blocks.each do |name, block| block.clock_apply if block.respond_to?(:clock_apply) end end |
#clock_prepare ⇒ Object
358 359 360 361 362 |
# File 'lib/origen/model.rb', line 358 def clock_prepare sub_blocks.each do |name, block| block.clock_prepare if block.respond_to?(:clock_prepare) end end |
#configuration ⇒ Object
167 168 169 |
# File 'lib/origen/model.rb', line 167 def configuration @configuration end |
#configuration=(id) ⇒ Object
162 163 164 165 |
# File 'lib/origen/model.rb', line 162 def configuration=(id) add_configuration(id) @configuration = id end |
#configurations ⇒ Object
Returns an array containing the IDs of all known configurations
176 177 178 |
# File 'lib/origen/model.rb', line 176 def configurations @configurations ||= [] end |
#current_configuration ⇒ Object
156 157 158 159 160 |
# File 'lib/origen/model.rb', line 156 def current_configuration if self.respond_to?(:configuration) configuration end end |
#current_mode ⇒ Object 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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/origen/model.rb', line 200 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 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 |
#current_mode=(id) ⇒ Object Also known as: mode=
Set the current mode configuration of the current model
217 218 219 |
# File 'lib/origen/model.rb', line 217 def current_mode=(id) @current_mode = id.is_a?(ChipMode) ? id.id : id end |
#delete_all_modes ⇒ Object 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
275 276 277 |
# File 'lib/origen/model.rb', line 275 def delete_all_modes @_modes = nil end |
#delete_all_specs_and_notes(obj = nil) ⇒ Object
Delete all specs and notes for self recursively
309 310 311 312 313 314 315 316 317 318 |
# File 'lib/origen/model.rb', line 309 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_specs ⇒ Object
Returns all specs found for the model. if none found it returns an empty array
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/origen/model.rb', line 281 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
230 231 232 |
# File 'lib/origen/model.rb', line 230 def has_mode?(id) !!(_modes[id.is_a?(ChipMode) ? id.id : id]) end |
#inspect ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/origen/model.rb', line 45 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 ⇒ Object
103 104 105 |
# File 'lib/origen/model.rb', line 103 def ip_name @ip_name || self.class.to_s.split('::').last.symbolize end |
#is_a_model_and_controller? ⇒ Boolean
Returns true if the instance is an Origen::Model that is wrapped in a controller
59 60 61 |
# File 'lib/origen/model.rb', line 59 def is_a_model_and_controller? !!controller end |
#is_an_origen_model? ⇒ Boolean
53 54 55 |
# File 'lib/origen/model.rb', line 53 def is_an_origen_model? true end |
#is_top_level? ⇒ Boolean Also known as: is_dut?, top_level?
Returns true if the model is the current DUT/top-level model
64 65 66 |
# File 'lib/origen/model.rb', line 64 def is_top_level? Origen.top_level == self end |
#model ⇒ Object
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.
73 74 75 |
# File 'lib/origen/model.rb', line 73 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
236 237 238 239 240 241 242 243 |
# File 'lib/origen/model.rb', line 236 def modes(id = nil, = {}) id = nil if id.is_a?(Hash) if id _modes[id] else _modes.ids end end |
#read_memory(*args) ⇒ Object
98 99 100 101 |
# File 'lib/origen/model.rb', line 98 def read_memory(*args) return super if defined?(super) read_register(*args) end |
#respond_to?(*args) ⇒ Boolean
320 321 322 |
# File 'lib/origen/model.rb', line 320 def respond_to?(*args) super || !!(!@respond_directly && controller && controller.respond_to_directly?(*args)) end |
#respond_to_directly?(*args) ⇒ Boolean
324 325 326 327 328 329 |
# File 'lib/origen/model.rb', line 324 def respond_to_directly?(*args) @respond_directly = true result = respond_to?(*args) @respond_directly = false result end |
#to_json(*args) ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/origen/model.rb', line 370 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 |
#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.
183 184 185 186 187 188 |
# File 'lib/origen/model.rb', line 183 def with_configuration(id, = {}) orig = configuration self.configuration = id yield self.configuration = orig end |
#with_each_mode ⇒ Object 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.
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/origen/model.rb', line 259 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
247 248 249 250 251 252 |
# File 'lib/origen/model.rb', line 247 def with_mode(id, = {}) orig = mode self.mode = id yield self.mode = orig end |
#wrap_in_controller ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/origen/model.rb', line 107 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
93 94 95 96 |
# File 'lib/origen/model.rb', line 93 def write_memory(*args) return super if defined?(super) write_register(*args) end |