Class: Origen::Clocks::Clock
Instance Attribute Summary collapse
-
#freq_range ⇒ Object
(also: #range)
Acceptable frequency range.
-
#freq_target ⇒ Object
(also: #target)
Acceptable frequency range.
-
#id ⇒ Object
Returns the value of attribute id.
-
#instantiate_users ⇒ Object
Returns the value of attribute instantiate_users.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#setpoint ⇒ Object
(also: #curr_value, #value)
Current setpoint, defaults top nil on init.
-
#users ⇒ Object
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.
-
#max ⇒ Object
max method.
- #method_missing(m, *args, &block) ⇒ Object
-
#min ⇒ Object
min method.
- #name ⇒ Object
- #setpoint_ok?(val = nil) ⇒ Boolean (also: #value_ok?, #val_ok?)
-
#setpoint_to_target ⇒ Object
Set the clock to the target 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 15 16 |
# 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 @instantiate_users = true .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 add_users_sub_blocks if @instantiate_users @setpoint = @freq_target end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/origen/clocks/clock.rb', line 110 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
#freq_range ⇒ Object Also known as: range
Acceptable frequency range
70 71 72 |
# File 'lib/origen/clocks/clock.rb', line 70 def freq_range @freq_range end |
#freq_target ⇒ Object Also known as: target
Acceptable frequency range
76 77 78 |
# File 'lib/origen/clocks/clock.rb', line 76 def freq_target @freq_target end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/origen/clocks/clock.rb', line 4 def id @id end |
#instantiate_users ⇒ Object
Returns the value of attribute instantiate_users.
4 5 6 |
# File 'lib/origen/clocks/clock.rb', line 4 def instantiate_users @instantiate_users 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
63 64 65 |
# File 'lib/origen/clocks/clock.rb', line 63 def setpoint @setpoint end |
#users ⇒ Object
Returns an Array of IPs that use a clock
23 24 25 |
# File 'lib/origen/clocks/clock.rb', line 23 def users @users end |
Instance Method Details
#max ⇒ Object
max method
91 92 93 94 95 96 97 |
# File 'lib/origen/clocks/clock.rb', line 91 def max if @freq_range == :fixed @freq_target else @freq_range.last end end |
#min ⇒ Object
min method
82 83 84 85 86 87 88 |
# File 'lib/origen/clocks/clock.rb', line 82 def min if @freq_range == :fixed @freq_target else @freq_range.first end end |
#name ⇒ Object
18 19 20 |
# File 'lib/origen/clocks/clock.rb', line 18 def name @id end |
#setpoint_ok?(val = nil) ⇒ Boolean Also known as: value_ok?, val_ok?
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/origen/clocks/clock.rb', line 36 def setpoint_ok?(val = nil) val = @setpoint if val.nil? if @freq_range == :fixed if val == @freq_target return true else Origen.log.warn("Clock '#{id}' is a fixed clock with a target frequency of #{@freq_target.as_Hz}") return false end else 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})") return false end end end |
#setpoint_to_target ⇒ Object
Set the clock to the target frequency
58 59 60 |
# File 'lib/origen/clocks/clock.rb', line 58 def setpoint_to_target @setpoint = @freq_target end |
#users_defined? ⇒ Boolean
Check if the clock users are defined anywhere in the DUT
100 101 102 103 104 105 106 107 108 |
# File 'lib/origen/clocks/clock.rb', line 100 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 |