Module: Origen::Model
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
- #_resolve_controller_class ⇒ Object
- #add_configuration(id) ⇒ Object
- #add_mode(id, options = {}) {|m| ... } ⇒ 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
- #ip_name ⇒ Object
- #log ⇒ Object
-
#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
-
#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
Instance Method Details
#_resolve_controller_class ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/origen/model.rb', line 81 def _resolve_controller_class klass = self.class while klass != Object model_class = klass.to_s.split('::').last controller_class = "#{model_class}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
110 111 112 |
# File 'lib/origen/model.rb', line 110 def add_configuration(id) configurations << id unless configurations.include?(id) end |
#add_mode(id, options = {}) {|m| ... } ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/origen/model.rb', line 153 def add_mode(id, = {}) m = ChipMode.new(id, ) m.owner = self yield m if block_given? _add_mode(m) m end |
#configuration ⇒ Object
106 107 108 |
# File 'lib/origen/model.rb', line 106 def configuration @configuration end |
#configuration=(id) ⇒ Object
101 102 103 104 |
# File 'lib/origen/model.rb', line 101 def configuration=(id) add_configuration(id) @configuration = id end |
#configurations ⇒ Object
Returns an array containing the IDs of all known configurations
115 116 117 |
# File 'lib/origen/model.rb', line 115 def configurations @configurations ||= [] end |
#current_configuration ⇒ Object
95 96 97 98 99 |
# File 'lib/origen/model.rb', line 95 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
139 140 141 142 143 144 |
# File 'lib/origen/model.rb', line 139 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
148 149 150 |
# File 'lib/origen/model.rb', line 148 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
206 207 208 |
# File 'lib/origen/model.rb', line 206 def delete_all_modes @_modes = nil end |
#delete_all_specs_and_notes(obj = nil) ⇒ Object
Delete all specs and notes for self recursively
240 241 242 243 244 245 246 247 248 249 |
# File 'lib/origen/model.rb', line 240 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
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/origen/model.rb', line 212 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
161 162 163 |
# File 'lib/origen/model.rb', line 161 def has_mode?(id) !!(_modes[id.is_a?(ChipMode) ? id.id : id]) end |
#ip_name ⇒ Object
44 45 46 |
# File 'lib/origen/model.rb', line 44 def ip_name @ip_name || self.class.to_s.split('::').last.symbolize 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
167 168 169 170 171 172 173 174 |
# File 'lib/origen/model.rb', line 167 def modes(id = nil, = {}) id = nil if id.is_a?(Hash) if id _modes[id] else _modes.ids end end |
#read_memory(*args) ⇒ Object
39 40 41 42 |
# File 'lib/origen/model.rb', line 39 def read_memory(*args) return super if defined?(super) read_register(*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.
122 123 124 125 126 127 |
# File 'lib/origen/model.rb', line 122 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.
190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/origen/model.rb', line 190 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
178 179 180 181 182 183 |
# File 'lib/origen/model.rb', line 178 def with_mode(id, = {}) orig = mode self.mode = id yield self.mode = orig end |
#wrap_in_controller ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/origen/model.rb', line 48 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
34 35 36 37 |
# File 'lib/origen/model.rb', line 34 def write_memory(*args) return super if defined?(super) write_register(*args) end |