Class: Origen::Pins::Pin

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

Overview

Override the Origen pin model so we can hook into all changes to pin states

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, owner, options = {}) ⇒ Pin

Returns a new instance of Pin.



13
14
15
16
# File 'lib/origen_sim/origen/pins/pin.rb', line 13

def initialize(id, owner, options = {})
  @tie_off = options[:tie_off]
  _orig_initialize(id, owner, options)
end

Instance Attribute Details

#simulation_indexObject

The index number that is used to refer to the pin within the simulation



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

def simulation_index
  @simulation_index
end

#tie_offObject

When generating a testbench the top-level signal will be tied off to the given logic level if this is set to 0 or 1



10
11
12
# File 'lib/origen_sim/origen/pins/pin.rb', line 10

def tie_off
  @tie_off
end

Instance Method Details

#_orig_initializeObject



12
# File 'lib/origen_sim/origen/pins/pin.rb', line 12

alias_method :_orig_initialize, :initialize

#_orig_set_stateObject



33
# File 'lib/origen_sim/origen/pins/pin.rb', line 33

alias_method :_orig_set_state, :set_state

#_orig_set_valueObject



26
# File 'lib/origen_sim/origen/pins/pin.rb', line 26

alias_method :_orig_set_value, :set_value

#_orig_state=Object



40
# File 'lib/origen_sim/origen/pins/pin.rb', line 40

alias_method :_orig_state=, :state=

#reset_simulator_stateObject



61
62
63
64
# File 'lib/origen_sim/origen/pins/pin.rb', line 61

def reset_simulator_state
  @simulator_state = nil
  @simulator_value = nil
end

#rtl_nameObject



18
19
20
21
22
23
24
# File 'lib/origen_sim/origen/pins/pin.rb', line 18

def rtl_name
  if primary_group
    (@rtl_name || primary_group.id).to_s
  else
    (@rtl_name || id).to_s
  end
end

#set_state(val) ⇒ Object



34
35
36
37
38
# File 'lib/origen_sim/origen/pins/pin.rb', line 34

def set_state(val)
  ret = _orig_set_state(val)
  update_simulation if simulation_running?
  ret
end

#set_value(val) ⇒ Object



27
28
29
30
31
# File 'lib/origen_sim/origen/pins/pin.rb', line 27

def set_value(val)
  ret = _orig_set_value(val)
  update_simulation if simulation_running?
  ret
end

#simulation_running?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/origen_sim/origen/pins/pin.rb', line 47

def simulation_running?
  tester && tester.is_a?(OrigenSim::Tester)
end

#simulatorObject



51
52
53
# File 'lib/origen_sim/origen/pins/pin.rb', line 51

def simulator
  OrigenSim.simulator
end

#simulator_needs_update?Boolean

Returns true if the current pin state is different to that last given to the simulator

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/origen_sim/origen/pins/pin.rb', line 56

def simulator_needs_update?
  return false if state == :dont_care && @simulator_state == :dont_care
  state != @simulator_state || value != @simulator_value
end

#state=(val) ⇒ Object



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

def state=(val)
  ret = _orig_state = (val)
  update_simulation if simulation_running?
  ret
end

#update_simulationObject

Applies the current pin state to the simulation, this is triggered everytime the pin state or value changes



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/origen_sim/origen/pins/pin.rb', line 68

def update_simulation
  return if tie_off || !simulation_index || !tester.timeset || !simulator_needs_update?
  case state
    when :drive
      @simulator_state = :drive
      @simulator_value = value
      simulator.put("2^#{simulation_index}^#{value}")
    when :compare
      @simulator_state = :compare
      @simulator_value = value
      simulator.put("4^#{simulation_index}^#{value}")
    when :dont_care
      @simulator_state = :dont_care
      simulator.put("5^#{simulation_index}")
    when :capture
      @simulator_state = :capture
      simulator.put("e^#{simulation_index}")
    when :drive_very_high, :drive_mem, :expect_mem, :compare_midband
      fail "Simulation of pin state #{state} is not implemented yet!"
    else
      fail "Simulation of pin state #{state} is not implemented yet!"
  end
end