Class: Origen::Clocks::Clock
Instance Attribute Summary collapse
-
#frequency_range ⇒ Object
(also: #freq_range, #range)
Acceptable frequency range.
-
#id ⇒ Object
Returns the value of attribute id.
-
#nominal_freq ⇒ Object
Returns the value of attribute nominal_freq.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#setpoint ⇒ Object
(also: #curr_value, #value)
Current setpoint, defaults top nil on init.
-
#startup_freq ⇒ Object
Returns the value of attribute startup_freq.
-
#users ⇒ Object
(also: #ips, #sub_blocks)
Returns an Array of IPs that use a clock.
Instance Method Summary collapse
-
#initialize(id, owner, options = {}, &block) ⇒ Clock
constructor
A new instance of Clock.
- #method_missing(m, *args, &block) ⇒ Object
- #name ⇒ Object
-
#nominal_frequency ⇒ Object
(also: #nominal, #nom)
Nominal frequency.
- #setpoint_ok?(val = nil) ⇒ Boolean (also: #value_ok?, #val_ok?)
-
#setpoint_to_nominal ⇒ Object
Set the clock to the nominal frequency.
-
#users_defined? ⇒ Boolean
Check if the clock users are defined anywhere in the DUT.
Constructor Details
#initialize(id, owner, options = {}, &block) ⇒ Clock
Returns a new instance of Clock.
6 7 8 9 10 11 12 13 14 |
# File 'lib/origen/clocks/clock.rb', line 6 def initialize(id, owner, = {}, &block) @id = id @owner = owner @id = @id.symbolize unless id.is_a? Symbol .each { |k, v| instance_variable_set("@#{k}", v) } (block.arity < 1 ? (instance_eval(&block)) : block.call(self)) if block_given? @users = [@users] unless @users.is_a? Array instantiate_users end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/origen/clocks/clock.rb', line 91 def method_missing(m, *args, &block) ivar = "@#{m.to_s.gsub('=', '')}" ivar_sym = ":#{ivar}" if m.to_s =~ /=$/ define_singleton_method(m) do |val| instance_variable_set(ivar, val) end elsif instance_variables.include? ivar_sym instance_variable_get(ivar) else define_singleton_method(m) do instance_variable_get(ivar) end end send(m, *args, &block) end |
Instance Attribute Details
#frequency_range ⇒ Object Also known as: freq_range, range
Acceptable frequency range
74 75 76 |
# File 'lib/origen/clocks/clock.rb', line 74 def frequency_range @frequency_range end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/origen/clocks/clock.rb', line 4 def id @id end |
#nominal_freq ⇒ Object
Returns the value of attribute nominal_freq.
4 5 6 |
# File 'lib/origen/clocks/clock.rb', line 4 def nominal_freq @nominal_freq end |
#owner ⇒ Object
Returns the value of attribute owner.
4 5 6 |
# File 'lib/origen/clocks/clock.rb', line 4 def owner @owner end |
#setpoint ⇒ Object Also known as: curr_value, value
Current setpoint, defaults top nil on init
67 68 69 |
# File 'lib/origen/clocks/clock.rb', line 67 def setpoint @setpoint end |
#startup_freq ⇒ Object
Returns the value of attribute startup_freq.
4 5 6 |
# File 'lib/origen/clocks/clock.rb', line 4 def startup_freq @startup_freq end |
#users ⇒ Object Also known as: ips, sub_blocks
Returns an Array of IPs that use a clock
21 22 23 |
# File 'lib/origen/clocks/clock.rb', line 21 def users @users end |
Instance Method Details
#name ⇒ Object
16 17 18 |
# File 'lib/origen/clocks/clock.rb', line 16 def name @id end |
#nominal_frequency ⇒ Object Also known as: nominal, nom
Nominal frequency
60 61 62 |
# File 'lib/origen/clocks/clock.rb', line 60 def nominal_frequency @nominal_frequency end |
#setpoint_ok?(val = nil) ⇒ Boolean Also known as: value_ok?, val_ok?
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/origen/clocks/clock.rb', line 32 def setpoint_ok?(val = nil) return nil if val.nil? && setpoint.nil? if freq_range == :fixed if val.nil? || val == nominal_frequency return true else Origen.log.warn("Clock '#{id}' is a fixed clock with a nominal frequency of #{nominal_frequency.as_Hz}, setting it to #{val.as_Hz}") return false end else val = setpoint if val.nil? if freq_range.include?(val) return true else Origen.log.warn("Setpoint (#{setpoint_string(val)}) for clock '#{id}' is not within the frequency range (#{freq_range_string}), setting it to #{val.as_Hz}") return false end end end |
#setpoint_to_nominal ⇒ Object
Set the clock to the nominal frequency
55 56 57 |
# File 'lib/origen/clocks/clock.rb', line 55 def setpoint_to_nominal @setpoint = nominal_frequency end |
#users_defined? ⇒ Boolean
Check if the clock users are defined anywhere in the DUT
81 82 83 84 85 86 87 88 89 |
# File 'lib/origen/clocks/clock.rb', line 81 def users_defined? undefined_ips = ips - Origen.all_sub_blocks if undefined_ips.empty? return true else Origen.log.warn("Clock '#{id}' has the following IP undefined: #{undefined_ips}") return false end end |