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.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/origen/clocks/clock.rb', line 7

def initialize(id, owner, options = {}, &block)
  @id = id
  @owner = owner
  @id = @id.symbolize unless id.is_a? Symbol
  @instantiate_users = true
  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
  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_rangeObject 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_targetObject Also known as: target

Acceptable frequency range



77
78
79
# File 'lib/origen/clocks/clock.rb', line 77

def freq_target
  @freq_target
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#instantiate_usersObject

Returns the value of attribute instantiate_users.



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

def instantiate_users
  @instantiate_users
end

#ownerObject

Returns the value of attribute owner.



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

def owner
  @owner
end

#usersObject

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

#maxObject

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

#minObject

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

#nameObject



19
20
21
# File 'lib/origen/clocks/clock.rb', line 19

def name
  @id
end

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

Returns:

  • (Boolean)


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_targetObject

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

Returns:

  • (Boolean)


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