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
15
16
# 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
  @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


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_rangeObject 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_targetObject Also known as: target

Acceptable frequency range


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

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

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

#usersObject

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

#maxObject

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

#minObject

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

#nameObject


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?

Returns:

  • (Boolean)

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_targetObject

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

Returns:

  • (Boolean)

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