Class: Origen::Pins::PinClock

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/pins/pin_clock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, options = {}) ⇒ PinClock

Returns a new instance of PinClock.



9
10
11
12
13
14
15
# File 'lib/origen/pins/pin_clock.rb', line 9

def initialize(owner, options = {})
  @owner = owner
  @running = false
  @cycles_per_half_period = 0
  @ns_per_half_period = 0
  update_half_period(options)
end

Instance Attribute Details

#cycles_per_half_periodObject

Returns the value of attribute cycles_per_half_period.



5
6
7
# File 'lib/origen/pins/pin_clock.rb', line 5

def cycles_per_half_period
  @cycles_per_half_period
end

#last_edgeObject

Returns the value of attribute last_edge.



6
7
8
# File 'lib/origen/pins/pin_clock.rb', line 6

def last_edge
  @last_edge
end

#next_edgeObject

Returns the value of attribute next_edge.



7
8
9
# File 'lib/origen/pins/pin_clock.rb', line 7

def next_edge
  @next_edge
end

#runningObject

Returns the value of attribute running.



4
5
6
# File 'lib/origen/pins/pin_clock.rb', line 4

def running
  @running
end

Instance Method Details

#restart_clock(_options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/origen/pins/pin_clock.rb', line 35

def restart_clock(_options = {})
  stop_clock
  update_clock
  start_clock
end

#running?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/origen/pins/pin_clock.rb', line 17

def running?
  @running
end

#start_clock(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/origen/pins/pin_clock.rb', line 21

def start_clock(options = {})
  fail "ERROR: Clock on #{@owner.name} already running." if running?

  if update_required?(options)
    update_half_period(options)
  end

  @last_edge = Origen.tester.cycle_count
  @next_edge = Origen.tester.cycle_count + @cycles_per_half_period
  cc "Start clock on #{@owner.name}: cycles_per_half_period=#{@cycles_per_half_period}, start cycle=#{@last_edge}"
  Origen.tester.push_running_clock(@owner) unless running?
  @running = true
end

#stop_clock(_options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/origen/pins/pin_clock.rb', line 41

def stop_clock(_options = {})
  cc "Stop clock on #{@owner.name}: stop cycle=#{Origen.tester.cycle_count}" if running?
  Origen.tester.pop_running_clock(@owner) if running?
  @running = false
end

#toggleObject



54
55
56
57
58
# File 'lib/origen/pins/pin_clock.rb', line 54

def toggle
  @owner.toggle
  @last_edge = Origen.tester.cycle_count
  @next_edge = Origen.tester.cycle_count + @cycles_per_half_period
end

#update_clockObject



47
48
49
50
51
52
# File 'lib/origen/pins/pin_clock.rb', line 47

def update_clock
  unless update_half_period(period_in_ns: @ns_per_half_period)
    @last_edge = Origen.tester.cycle_count
    @next_edge = Origen.tester.cycle_count + @cycles_per_half_period
  end
end