class Origen::Pins::PinClock

Attributes

cycles_per_duty[R]
last_edge[R]
next_edge[R]

Public Class Methods

new(owner, options = {}) click to toggle source
# File lib/origen/pins/pin_clock.rb, line 6
def initialize(owner, options = {})
  @owner = owner
  @running = false

  @clock_period_in_ns = 0
  @tester_period_in_ns = 0

  update_clock_period(options)
  update_tester_period_local
  update_clock_parameters
end

Public Instance Methods

cycles_per_half_period() click to toggle source

The only caller to this should be legacy support so just force 50% duty cycle

# File lib/origen/pins/pin_clock.rb, line 66
def cycles_per_half_period
  @cycles_per_duty.min
end
restart_clock() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 42
def restart_clock
  stop_clock
  update_clock
  start_clock
end
running?() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 56
def running?
  @running
end
start_clock(options = {}) click to toggle source
# File lib/origen/pins/pin_clock.rb, line 18
def start_clock(options = {})
  # Throw error if this pin is already a running clock
  if running?
    fail "PIN CLOCK ERROR: Clock on #{@owner.name} already running."
  end

  clock_updated = update_clock_period(options)
  tester_updated = update_tester_period_local
  if clock_updated || tester_updated
    update_clock_parameters
  end

  cc "[PinClock] Start #{@owner.name}.clock at #{Origen.tester.cycle_count}: period=#{@clock_period_in_ns}ns, cycles=#{cycles_per_period}, duty=#{duty_str}"
  update_edges
  Origen.tester.push_running_clock(@owner) unless running?
  @running = true
end
stop_clock(options = {}) click to toggle source
# File lib/origen/pins/pin_clock.rb, line 36
def stop_clock(options = {})
  cc "[PinClock] Stop #{@owner.name}.clock: stop_cycle=#{Origen.tester.cycle_count}" if running?
  Origen.tester.pop_running_clock(@owner) if running?
  @running = false
end
toggle() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 60
def toggle
  @owner.toggle
  update_edges
end
update_clock() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 48
def update_clock
  if update_tester_period_local
    update_clock_parameters
    cc "[PinClock] Update #{@owner.name}.clock at #{Origen.tester.cycle_count}: period=#{@clock_period_in_ns}ns, cycles=#{cycles_per_period}, duty=#{duty_str}"
    update_edges
  end
end

Private Instance Methods

cycles_per_period() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 76
def cycles_per_period
  (@clock_period_in_ns / @tester_period_in_ns).to_int
end
duty_str() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 134
def duty_str
  "#{@cycles_per_duty[0]}/#{@cycles_per_duty[1]}"
end
get_clock_period(options = {}) click to toggle source
# File lib/origen/pins/pin_clock.rb, line 106
def get_clock_period(options = {})
  return @clock_period_in_ns if options.empty?

  p = []

  # Passed in as time
  p << (options[:period_in_s] * 1_000_000_000) if options[:period_in_s]
  p << (options[:period_in_ms] * 1_000_000) if options[:period_in_ms]
  p << (options[:period_in_us] * 1_000) if options[:period_in_us]
  p << (options[:period_in_ns] * 1) if options[:period_in_ns]

  # Passed in as frequency (or freq.)
  p << ((1.0 / options[:frequency_in_hz]) * 1_000_000_000) if options[:frequency_in_hz]
  p << ((1.0 / options[:freq_in_hz]) * 1_000_000_000) if options[:freq_in_hz]
  p << ((1.0 / options[:frequency_in_khz]) * 1_000_000) if options[:frequency_in_khz]
  p << ((1.0 / options[:freq_in_khz]) * 1_000_000) if options[:freq_in_khz]
  p << ((1.0 / options[:frequency_in_mhz]) * 1_000) if options[:frequency_in_mhz]
  p << ((1.0 / options[:freq_in_mhz]) * 1_000) if options[:freq_in_mhz]

  # Passed in as cycles (not advised)
  p << (options[:cycles] * Origen.tester.period_in_ns) if options[:cycles]

  return @clock_period_in_ns if p.empty?
  fail "[Pin Clock] ERROR: Multiple unit declarations for #{@owner.name}.clock" if p.size > 1

  p[0].to_int
end
update_clock_parameters() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 72
def update_clock_parameters
  @cycles_per_duty = [(cycles_per_period / 2.0).floor, (cycles_per_period / 2.0).ceil]
end
update_clock_period(options = {}) click to toggle source
# File lib/origen/pins/pin_clock.rb, line 95
def update_clock_period(options = {})
  new = get_clock_period(options)

  if new == @clock_period_in_ns
    false
  else
    @clock_period_in_ns = new
    true
  end
end
update_edges() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 80
def update_edges
  @last_edge = Origen.tester.cycle_count
  @next_edge = Origen.tester.cycle_count + @cycles_per_duty[0]
  @cycles_per_duty.reverse!
end
update_tester_period_local() click to toggle source
# File lib/origen/pins/pin_clock.rb, line 86
def update_tester_period_local
  if Origen.tester.current_period_in_ns == @tester_period_in_ns
    false
  else
    @tester_period_in_ns = Origen.tester.current_period_in_ns
    true
  end
end