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.
-
#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 ⇒ Object
(also: #curr_value, #value)
Current setpoint, defaults top nil on init.
- #setpoint=(val) ⇒ 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.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/origen/clocks/clock.rb', line 7 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
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/origen/clocks/clock.rb', line 111 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
71 72 73 |
# File 'lib/origen/clocks/clock.rb', line 71 def freq_range @freq_range end |
#freq_target ⇒ Object Also known as: target
Acceptable frequency range
77 78 79 |
# File 'lib/origen/clocks/clock.rb', line 77 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 |
#users ⇒ Object
Returns an Array of IPs that use a clock
24 25 26 |
# File 'lib/origen/clocks/clock.rb', line 24 def users @users end |
Instance Method Details
#max ⇒ Object
max method
92 93 94 95 96 97 98 |
# File 'lib/origen/clocks/clock.rb', line 92 def max if @freq_range == :fixed @freq_target else @freq_range.last end end |
#min ⇒ Object
min method
83 84 85 86 87 88 89 |
# File 'lib/origen/clocks/clock.rb', line 83 def min if @freq_range == :fixed @freq_target else @freq_range.first end end |
#name ⇒ Object
19 20 21 |
# File 'lib/origen/clocks/clock.rb', line 19 def name @id end |
#setpoint ⇒ Object Also known as: curr_value, value
Current setpoint, defaults top nil on init
64 65 66 |
# File 'lib/origen/clocks/clock.rb', line 64 def setpoint @setpoint end |
#setpoint=(val) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/origen/clocks/clock.rb', line 28 def setpoint=(val) if val == :gated || val == 'gated' @setpoint = :gated else setpoint_ok?(val) # This just warns if the clock is set out of range @setpoint = val end end |
#setpoint_ok?(val = nil) ⇒ Boolean Also known as: value_ok?, val_ok?
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/origen/clocks/clock.rb', line 37 def setpoint_ok?(val = nil) val = @setpoint if val.nil? if @freq_range == :fixed if val == @freq_target true else Origen.log.warn("Clock '#{id}' is a fixed clock with a target frequency of #{@freq_target.as_Hz}") false end else if @freq_range.include?(val) true else Origen.log.warn("Setpoint (#{setpoint_string(val)}) for clock '#{id}' is not within the frequency range (#{freq_range_string})") false end end end |
#setpoint_to_target ⇒ Object
Set the clock to the target frequency
59 60 61 |
# File 'lib/origen/clocks/clock.rb', line 59 def setpoint_to_target @setpoint = @freq_target end |
#users_defined? ⇒ Boolean
Check if the clock users are defined anywhere in the DUT
101 102 103 104 105 106 107 108 109 |
# File 'lib/origen/clocks/clock.rb', line 101 def users_defined? undefined_ips = ips - Origen.all_sub_blocks if undefined_ips.empty? true else Origen.log.warn("Clock '#{id}' has the following IP undefined: #{undefined_ips}") false end end |