Module: OrigenTesters::Timing

Extended by:
ActiveSupport::Concern
Includes:
TimingAPI
Defined in:
lib/origen_testers/timing.rb,
lib/origen_testers/timing/timeset.rb,
lib/origen_testers/timing/timing_api.rb

Defined Under Namespace

Modules: TimingAPI Classes: InvalidModification, Timeset, TopLevelWatcher

Class Method Summary collapse

Methods included from TimingAPI

#before_timeset_change, #called_timesets, #called_timesets_by_name, #count, #current_period_in_ns, #current_timeset, #cycles_to_time, #delay, #max_repeat_loop, #min_period_timeset, #min_repeat_loop, #period_in_ns, #period_in_secs, #set_timeset, #timeset?, #timesets, #timing_toggled_pins, #wait

Class Method Details

._set_timeset_(timeset, period_in_ns = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/origen_testers/timing.rb', line 59

def self._set_timeset_(timeset, period_in_ns = nil)
  # If the period_in_ns was given, use that.
  # Alternatively, the period_in_ns may have been set on the Timeset object
  # already.
  # If not, then complain that we need a period_in_ns before proceeding.
  if period_in_ns
    timeset._period_in_ns_ = period_in_ns
    # elsif !timeset.period_in_ns?
    # fail 'You must supply a period_in_ns argument to set_timeset'
  end

  if @timeset
    timeset_changed(timeset)
  else
    @timeset = timeset
  end
  timeset.called = true
  @timeset = timeset
  timeset
end

.called_timesetsArray

Returns any timesets that have been called during this execution.

Returns:

  • (Array)

    Array of OrigenTesters::Timing::Timeset objects that have been used so far.



179
180
181
# File 'lib/origen_testers/timing.rb', line 179

def self.called_timesets
  timesets.select { |n, t| t.called? }.values
end

.called_timesets_by_nameArray

Similar to OrigenTesters::Timing::TimingAPI#called_timesets, but returns the name of the timesets instead.

Returns:

  • (Array)

    Array of names corresponding to the timesets that have been used so far.



186
187
188
# File 'lib/origen_testers/timing.rb', line 186

def self.called_timesets_by_name
  timesets.select { |n, t| t.called? }.keys
end

.current_period_in_nsObject



161
162
163
164
165
# File 'lib/origen_testers/timing.rb', line 161

def self.current_period_in_ns
  if timeset
    timeset.period_in_ns
  end
end

.current_timesetObject



138
139
140
# File 'lib/origen_testers/timing.rb', line 138

def self.current_timeset
  @timeset
end

.lookup_or_register_timeset(t, period_in_ns: nil) ⇒ Object

Given a timeset name or object, either returns it, if it exists, or creates it, and returns the newly created timeset.



117
118
119
120
121
122
123
# File 'lib/origen_testers/timing.rb', line 117

def self.lookup_or_register_timeset(t, period_in_ns: nil)
  if t.is_a?(Origen::Pins::Timing::Timeset)
    timesets[t.id] ||= Timeset.new(name: t.id, period_in_ns: period_in_ns)
  else
    timesets[t] ||= Timeset.new(name: t, period_in_ns: period_in_ns)
  end
end

.min_period_timesetObject



107
108
109
# File 'lib/origen_testers/timing.rb', line 107

def self.min_period_timeset
  @min_period_timeset
end

.period_in_nsObject



142
143
144
145
146
# File 'lib/origen_testers/timing.rb', line 142

def self.period_in_ns
  if timeset
    timeset.period_in_ns
  end
end

.period_in_secsObject



170
171
172
173
174
# File 'lib/origen_testers/timing.rb', line 170

def self.period_in_secs
  if timeset
    timeset.period_in_secs
  end
end

.reset!Object



51
52
53
54
55
56
# File 'lib/origen_testers/timing.rb', line 51

def self.reset!
  timesets!
  @timeset = nil
  @_last_timeset_change = nil
  @min_period_timeset = nil
end

.set_timeset(timeset, period_in_ns = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/origen_testers/timing.rb', line 58

def self.set_timeset(timeset, period_in_ns = nil)
  def self._set_timeset_(timeset, period_in_ns = nil)
    # If the period_in_ns was given, use that.
    # Alternatively, the period_in_ns may have been set on the Timeset object
    # already.
    # If not, then complain that we need a period_in_ns before proceeding.
    if period_in_ns
      timeset._period_in_ns_ = period_in_ns
      # elsif !timeset.period_in_ns?
      # fail 'You must supply a period_in_ns argument to set_timeset'
    end

    if @timeset
      timeset_changed(timeset)
    else
      @timeset = timeset
    end
    timeset.called = true
    @timeset = timeset
    timeset
  end

  if timeset.is_a?(Array)
    timeset, period_in_ns = timeset[0], timeset[1]
  end
  timeset ||= @timeset
  if timeset.is_a?(Origen::Pins::Timing::Timeset) || timeset.is_a?(OrigenTesters::Timing::Timeset)
    timeset = timeset.id.to_sym
  end
  timeset = (timesets[timeset] || lookup_or_register_timeset(timeset.to_s.chomp, period_in_ns: period_in_ns))

  if block_given?
    original = @timeset
    _set_timeset_(timeset, period_in_ns)
    yield
    timeset = original
    period_in_ns = timeset.period_in_ns
  end
  _set_timeset_(timeset, period_in_ns)

  if @min_period_timeset && period_in_ns
    @min_period_timeset = timeset if timeset.shorter_period_than?(@min_period_timeset)
  else
    @min_period_timeset = timeset
  end
  timeset
end

.timesetObject



134
135
136
# File 'lib/origen_testers/timing.rb', line 134

def self.timeset
  @timeset
end

.timeset?(t) ⇒ Boolean

Returns true if the current timeset is defined. False otherwise.

Returns:

  • (Boolean)


126
127
128
129
130
131
132
# File 'lib/origen_testers/timing.rb', line 126

def self.timeset?(t)
  if t.respond_to?(:name)
    timesets.key?(t.name)
  else
    timesets.key?(t)
  end
end

.timeset_changed(timeset) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/origen_testers/timing.rb', line 148

def self.timeset_changed(timeset)
  if tester && tester.last_vector && tester.last_vector.timeset != timeset
    change = { old: tester.last_vector.timeset, new: timeset }
    # Suppress any duplicate calls
    if !@_last_timeset_change ||
       (@_last_timeset_change[:new] != change[:new] &&
         @_last_timeset_change[:old] != change[:old])
      tester.before_timeset_change(change)
    end
    @_last_timeset_change = change
  end
end

.timesetsObject



111
112
113
# File 'lib/origen_testers/timing.rb', line 111

def self.timesets
  @timesets || timesets!
end

.timesets!Object



47
48
49
# File 'lib/origen_testers/timing.rb', line 47

def self.timesets!
  @timesets = {}.with_indifferent_access
end