Class: Origen::Clocks::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/clocks/clock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {}, &block)
  @id = id
  @owner = owner
  @id = @id.symbolize unless id.is_a? Symbol
  options.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_rangeObject 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

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/origen/clocks/clock.rb', line 4

def id
  @id
end

#nominal_freqObject

Returns the value of attribute nominal_freq.



4
5
6
# File 'lib/origen/clocks/clock.rb', line 4

def nominal_freq
  @nominal_freq
end

#ownerObject

Returns the value of attribute owner.



4
5
6
# File 'lib/origen/clocks/clock.rb', line 4

def owner
  @owner
end

#setpointObject 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_freqObject

Returns the value of attribute startup_freq.



4
5
6
# File 'lib/origen/clocks/clock.rb', line 4

def startup_freq
  @startup_freq
end

#usersObject 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

#nameObject



16
17
18
# File 'lib/origen/clocks/clock.rb', line 16

def name
  @id
end

#nominal_frequencyObject 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?

Returns:

  • (Boolean)


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_nominalObject

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

Returns:

  • (Boolean)


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