Class: OrigenSim::Simulator
- Inherits:
-
Object
- Object
- OrigenSim::Simulator
- Includes:
- Origen::PersistentCallbacks, Artifacts
- Defined in:
- lib/origen_sim/simulator.rb,
lib/origen_sim/simulator/user_details.rb,
lib/origen_sim/simulator/snapshot_details.rb
Overview
Responsible for managing and communicating with the simulator process, a single instance of this class is instantiated as OrigenSim.simulator
Defined Under Namespace
Classes: SnapshotDetails, UserDetails
Constant Summary collapse
- VENDORS =
[:icarus, :cadence, :synopsys, :generic]
- LOG_CODES =
{ debug: 0, info: 1, warn: 2, warning: 2, success: 3, error: 4, deprecate: 5, deprecated: 5 }
- LOG_CODES_ =
{ 0 => :debug, 1 => :info, 2 => :warn, 3 => :success, 4 => :error, 5 => :deprecated }
- LOGGER_COLLATERAL_SIZE =
Sending logs over VPI has a maximum size, some of which are collateral, leaving the difference for the actual message.
11
- MULTIPART_LOGGER_TOKEN =
'!k+!'
- NON_DATA_CONFIG_ATTRIBUTES =
These config attributes are accepted by OrigenSim, but cannot be ‘Marshal-ed’.
[:post_process_run_cmd]
- TIMESCALES =
{ -15 => '1fs', -14 => '10fs', -13 => '100fs', -12 => '1ps', -11 => '10ps', -10 => '100ps', -9 => '1ns', -8 => '10ns', -7 => '100ns', -6 => '1us', -5 => '10us', -4 => '100us', -3 => '1ms', -2 => '10ms', -1 => '100ms', 0 => '1s', 1 => '10s', 2 => '100s' }
Instance Attribute Summary collapse
-
#configuration ⇒ Object
(also: #config)
readonly
Returns the value of attribute configuration.
-
#pins_by_rtl_name ⇒ Object
readonly
Returns a hash of pins where the key is the RTL name, used to quickly retrieve the pin object from the pin name returned by the simulator.
-
#simulation ⇒ Object
readonly
The instance of OrigenSim::Simulation for the current simulation.
-
#simulations ⇒ Object
readonly
Returns an array containing all instances of OrigenSim::Simulation that were created in the order that they were created.
Instance Method Summary collapse
-
#_snapshot_details ⇒ Object
Add the following methods to the simulator ###.
- #artifact_populate_method ⇒ Object
- #artifact_run_dir ⇒ Object
-
#before_pattern(name) ⇒ Object
(also: #setup_simulation)
Called before every pattern is generated, but we only use it the first time it is called to kick off the simulator process if the current tester is an OrigenSim::Tester.
- #commit_simulation_objects(options = {}) ⇒ Object
-
#compiled_dir ⇒ Object
Returns the directory where the compiled simulation object lives, this should be checked into your Origen app’s repository.
-
#config_changed? ⇒ Boolean
Returns true if the config has been changed since the last time we called save_config_signature.
- #configure(options, &block) ⇒ Object
- #cycle(number_of_cycles) ⇒ Object
-
#cycle_count ⇒ Object
Returns the simulator cycle count, this should be the same as tester.cycle_count but this gives the simulators count instead of Origen’s.
- #default_artifact_dir ⇒ Object
-
#define_pins ⇒ Object
Tells the simulator about the pins in the current device so that it can set up internal handles to efficiently access them.
- #define_waves ⇒ Object
-
#dut_version ⇒ Object
Returns the version of Origen Sim that the current DUT object was compiled with.
- #end_simulation ⇒ Object
- #error(message) ⇒ Object
-
#error_count ⇒ Object
Returns the current simulation error count.
- #fetch_simulation_objects(options = {}) ⇒ Object
-
#flush(options = {}) ⇒ Object
Flush any buffered simulation output, this should cause live wave viewers to reflect the latest state.
- #force(net, value) ⇒ Object
- #generic_run_cmd ⇒ Object
-
#get ⇒ Object
Get a message from the simulator, will block until one is received.
-
#id ⇒ Object
The ID assigned to the current simulation target, falls back to to the Origen target name if an :id option is not supplied when instantiating the tester.
-
#initialize ⇒ Simulator
constructor
A new instance of Simulator.
- #interactive_shutdown ⇒ Object
-
#log(msg, type = :info, multipart: false) ⇒ Object
Any messages passed in here will be output to the console log by making a round trip through the simulator.
-
#log_messages=(val) ⇒ Object
When set to true the simulator will log all messages it receives, note that this must be run in conjunction with -d supplied to the Origen command to actually see the messages.
- #marker=(val) ⇒ Object
- #match_errors ⇒ Object
-
#match_loop ⇒ Object
Any vectors executed within the given block will increment the match_errors counter rather than the errors counter.
-
#max_errors ⇒ Object
Returns the number of errors that are allowed before a aborting a simulation.
-
#on_flow_end(options) ⇒ Object
At the end of a test program flow generation/simulation.
-
#on_flow_start(options) ⇒ Object
At the start of a test program flow generation/simulation.
- #on_origen_shutdown ⇒ Object
-
#on_timeset_changed ⇒ Object
This will be called automatically whenever tester.set_timeset has been called.
-
#pattern_generated(path) ⇒ Object
(also: #complete_simulation)
This will be called at the end of every pattern, make sure the simulator is not running behind before potentially moving onto another pattern.
-
#peek(net, real = false) ⇒ Object
Returns the current value of the given net, or nil if the given path does not resolve to a valid node.
- #peek_real(net) ⇒ Object
- #peek_str(signal) ⇒ Object (also: #str_peek, #peek_string, #string_peek)
-
#poke(net, value) ⇒ Object
Forces the given value to the given net.
- #post_process_run_cmd ⇒ Object
-
#put(msg) ⇒ Object
Send the given message string to the simulator.
-
#put_all_pin_states ⇒ Object
Applies the current state of all pins to the simulation.
- #release(net) ⇒ Object
- #rtl_top ⇒ Object
- #run_cmd ⇒ Object
- #run_dir ⇒ Object
- #running? ⇒ Boolean
-
#save_config_signature ⇒ Object
Locally saves a signature for the current config, this will cause config_changed? to return false until its contents change.
- #set_period(period_in_ns) ⇒ Object
- #simulation_open? ⇒ Boolean
- #simulation_tester? ⇒ Boolean
- #snapshot_detail(d) ⇒ Object
- #snapshot_details(d = nil) ⇒ Object
- #socket_id ⇒ Object
-
#start ⇒ Object
Starts up the simulator process.
- #start_read_reg_transaction ⇒ Object
-
#stop ⇒ Object
Stop the simulator.
- #stop_read_reg_transaction ⇒ Object
- #sync ⇒ Object
- #sync_active? ⇒ Boolean
-
#sync_up ⇒ Object
Blocks the Origen process until the simulator indicates that it has processed all operations up to this point.
- #target_artifact_dir ⇒ Object
- #testbench_top ⇒ Object
-
#timescale ⇒ Object
Get the timescale of the current simulation, returns a number that maps as follows: -15 - fs -14 - 10fs -13 - 100fs -12 - ps -11 - 10ps -10 - 100ps -9 - ns -8 - 10ns -7 - 100ns -6 - us -5 - 10us -4 - 100us -3 - ms -2 - 10ms -1 - 100ms 0 - s 1 - 10s 2 - 100s.
- #tmp_dir ⇒ Object
- #user_artifact_dirs ⇒ Object
- #user_artifact_dirs? ⇒ Boolean
- #view_wave_command ⇒ Object
- #wave_config_dir ⇒ Object
- #wave_config_ext ⇒ Object
- #wave_config_file ⇒ Object
- #wave_dir(subdir = nil) ⇒ Object
- #wave_file_basename ⇒ Object
- #wave_to_str(wave) ⇒ Object
-
#wreal? ⇒ Boolean
(also: #wreal_enabled?)
Returns true if the snapshot has been compiled with WREAL support.
- #write_comment(line, comment) ⇒ Object
Constructor Details
#initialize ⇒ Simulator
Returns a new instance of Simulator.
57 58 59 60 |
# File 'lib/origen_sim/simulator.rb', line 57 def initialize @simulations = [] @simulation_open = false end |
Instance Attribute Details
#configuration ⇒ Object (readonly) Also known as: config
Returns the value of attribute configuration.
46 47 48 |
# File 'lib/origen_sim/simulator.rb', line 46 def configuration @configuration end |
#pins_by_rtl_name ⇒ Object (readonly)
Returns a hash of pins where the key is the RTL name, used to quickly retrieve the pin object from the pin name returned by the simulator
55 56 57 |
# File 'lib/origen_sim/simulator.rb', line 55 def pins_by_rtl_name @pins_by_rtl_name end |
#simulation ⇒ Object (readonly)
The instance of OrigenSim::Simulation for the current simulation
49 50 51 |
# File 'lib/origen_sim/simulator.rb', line 49 def simulation @simulation end |
#simulations ⇒ Object (readonly)
Returns an array containing all instances of OrigenSim::Simulation that were created in the order that they were created
52 53 54 |
# File 'lib/origen_sim/simulator.rb', line 52 def simulations @simulations end |
Instance Method Details
#_snapshot_details ⇒ Object
Add the following methods to the simulator ###
43 44 45 |
# File 'lib/origen_sim/simulator/snapshot_details.rb', line 43 def _snapshot_details @_snapshot_details ||= SnapshotDetails.new(simulator: self, **@configuration[:snapshot_details_options]) end |
#artifact_populate_method ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'lib/origen_sim/simulator.rb', line 227 def artifact_populate_method @configuration[:artifact_populate_method] || begin if Origen.running_on_windows? :copy else :symlink end end end |
#artifact_run_dir ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/origen_sim/simulator.rb', line 218 def artifact_run_dir p = Pathname(@configuration[:artifact_run_dir] || './application/artifacts') if p.absolute? p else Pathname(run_dir).join(p) end end |
#before_pattern(name) ⇒ Object Also known as: setup_simulation
Called before every pattern is generated, but we only use it the first time it is called to kick off the simulator process if the current tester is an OrigenSim::Tester
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/origen_sim/simulator.rb', line 704 def before_pattern(name) if simulation_tester? if OrigenSim.flow || !simulation # When running patterns back-to-back, only want to launch the simulator the first time start unless simulation else simulation.completed_cleanly = true stop start end # Set the current pattern name in the simulation name = name.sub(/\..*/, '') put("a^#{name}") log '#' * 100 log '#' * 100 log '##' log "## START OF PATTERN: #{name}" log '##' log '#' * 100 log '#' * 100 @running_pattern_name = name @pattern_starting_error_count = @pattern_starting_error_count ? error_count : 0 @pattern_count ||= 0 # If running a flow, give the user some feedback about pass/fail status after # each individual pattern has completed if @pattern_count > 0 && OrigenSim.flow simulation.error_count = error_count simulation.log_results(true) # Require each pattern to set this upon successful completion simulation.completed_cleanly = false unless @flow_running end @pattern_count += 1 end end |
#commit_simulation_objects(options = {}) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/origen_sim/simulator.rb', line 128 def commit_simulation_objects( = {}) sid = [:id] || id ldir = "#{Origen.root}/simulation/#{sid}" tmp_dir = "#{Origen.root}/tmp/origen_sim/tmp" unless File.exist?(ldir) fail "The simulation directory to check in does not exist: #{ldir}" end Dir.chdir "#{Origen.root}/simulation/" do system "tar -cvzf #{sid}.tar.gz #{sid}" end FileUtils.rm_rf(tmp_dir) if File.exist?(tmp_dir) FileUtils.mkdir_p(tmp_dir) FileUtils.cp "#{ldir}.tar.gz", tmp_dir rc = Origen::RevisionControl.new remote: config[:rc_dir_url], local: tmp_dir rc.checkin "#{sid}.tar.gz", unmanaged: true, force: true, comment: 'Checked in via sim:rc command' ensure FileUtils.rm_f "#{ldir}.tar.gz" if File.exist?("#{ldir}.tar.gz") FileUtils.rm_rf tmp_dir if File.exist?(tmp_dir) end |
#compiled_dir ⇒ Object
Returns the directory where the compiled simulation object lives, this should be checked into your Origen app’s repository
254 255 256 257 258 259 260 |
# File 'lib/origen_sim/simulator.rb', line 254 def compiled_dir @compiled_dir ||= begin d = "#{Origen.root}/simulation/#{id}/#{config[:vendor]}" FileUtils.mkdir_p(d) d end end |
#config_changed? ⇒ Boolean
Returns true if the config has been changed since the last time we called save_config_signature
1081 1082 1083 |
# File 'lib/origen_sim/simulator.rb', line 1081 def config_changed? Origen.app.session.origen_sim["#{id}_config"] != config.except(*NON_DATA_CONFIG_ATTRIBUTES) end |
#configure(options, &block) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/origen_sim/simulator.rb', line 150 def configure(, &block) fail 'A vendor must be supplied, e.g. OrigenSim::Tester.new(vendor: :icarus)' unless [:vendor] unless VENDORS.include?([:vendor]) fail "Unknown vendor #{[:vendor]}, valid values are: #{VENDORS.map { |v| ':' + v.to_s }.join(', ')}" end @configuration = { snapshot_details_options: {}, # The maximum message size the VPI can accept. # Have this as a configuration parameter since this is VPI-implementation specific. max_log_size: 1024 }.merge() @tmp_dir = nil # Temporary workaround for bug in componentable, which is making the container a class object, instead of an # instance object. clear_artifacts # Add any artifacts in the given artifact path if Dir.exist?(default_artifact_dir) default_artifact_dir.children.each { |a| artifact(a.basename.to_s, target: a) } end # Add any artifacts from the target-specific path (simulation/<target>/artifacts). Files of the same name # will override artifacts residing in the default directory. if Dir.exist?(target_artifact_dir) target_artifact_dir.children.each do |a| remove_artifact(a.basename.to_s) if has_artifact?(a.basename.to_s) add_artifact(a.basename.to_s, target: a) end end # If a user artifact path was given, add those artifacts as well, overriding any of the default and target artifacts if user_artifact_dirs? user_artifact_dirs.each do |d| if Dir.exist?(d) # Add any artifacts from any user-given paths. Files of the same name will override artifacts residing in the default directory. d.children.each do |a| remove_artifact(a.basename.to_s) if has_artifact?(a.basename.to_s) add_artifact(a.basename.to_s, target: a) end else Origen.app.fail! message: "Simulator configuration specified a user artifact dir at #{d} but this directory could not be found!" end end end self end |
#cycle(number_of_cycles) ⇒ Object
852 853 854 855 |
# File 'lib/origen_sim/simulator.rb', line 852 def cycle(number_of_cycles) put("3^#{number_of_cycles}") simulation.cycle(number_of_cycles) end |
#cycle_count ⇒ Object
Returns the simulator cycle count, this should be the same as tester.cycle_count but this gives the simulators count instead of Origen’s
1194 1195 1196 1197 |
# File 'lib/origen_sim/simulator.rb', line 1194 def cycle_count put('o^') get.strip.to_i end |
#default_artifact_dir ⇒ Object
200 201 202 203 204 |
# File 'lib/origen_sim/simulator.rb', line 200 def default_artifact_dir # Removed this from a constant at the top of the file since it gave boot errors when the file was # being required while Origen.app was still loading Pathname("#{Origen.app.root}/simulation/application/artifacts") end |
#define_pins ⇒ Object
Tells the simulator about the pins in the current device so that it can set up internal handles to efficiently access them
808 809 810 811 812 813 814 815 816 817 818 |
# File 'lib/origen_sim/simulator.rb', line 808 def define_pins @pins_by_rtl_name = {} dut.rtl_pins(type: :digital).each_with_index do |(name, pin), i| @pins_by_rtl_name[pin.rtl_name] = pin pin.simulation_index = i put("0^#{pin.rtl_name}^#{i}^#{pin.drive_wave.index}^#{pin.compare_wave.index}") end dut.rtl_pins.each do |name, pin| pin.apply_force end end |
#define_waves ⇒ Object
835 836 837 838 839 840 841 842 |
# File 'lib/origen_sim/simulator.rb', line 835 def define_waves dut.timeset.drive_waves.each_with_index do |wave, i| put("6^#{i}^0^#{wave_to_str(wave)}") end dut.timeset.compare_waves.each_with_index do |wave, i| put("6^#{i}^1^#{wave_to_str(wave)}") end end |
#dut_version ⇒ Object
Returns the version of Origen Sim that the current DUT object was compiled with
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
# File 'lib/origen_sim/simulator.rb', line 1092 def dut_version @dut_version ||= begin # Allow configs to force a dut version, this is to allow backwards compatibility with very early # compiled duts which do not support the command to get it from the compiled object config[:dut_version] || begin put('i^') Origen::VersionString.new(get.strip) end end end |
#end_simulation ⇒ Object
844 845 846 |
# File 'lib/origen_sim/simulator.rb', line 844 def end_simulation put('8^') end |
#error(message) ⇒ Object
895 896 897 898 899 |
# File 'lib/origen_sim/simulator.rb', line 895 def error() simulation.logged_errors = true poke "#{testbench_top}.debug.errors", error_count + 1 log , :error end |
#error_count ⇒ Object
Returns the current simulation error count
902 903 904 |
# File 'lib/origen_sim/simulator.rb', line 902 def error_count peek("#{testbench_top}.debug.errors").to_i end |
#fetch_simulation_objects(options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/origen_sim/simulator.rb', line 89 def fetch_simulation_objects( = {}) sid = [:id] || id ldir = "#{Origen.root}/simulation/#{sid}" tmp_dir = "#{Origen.root}/tmp/origen_sim/tmp" if config[:rc_dir_url] unless config[:rc_version] puts "You must supply an :rc_version option when using :rc_dir_url (you can set this to something like 'Trunk' or 'master' if you want)" exit 1 end if !File.exist?(compiled_dir) || (File.exist?(compiled_dir) && Dir.entries(compiled_dir).size <= 2) || (Origen.app.session.origen_sim[sid] != config[:rc_version]) || [:force] Origen.log.info "Fetching the simulation object for #{sid}..." Origen.app.session.origen_sim[sid] = nil # Clear this up front, if the checkout fails we won't know what we have FileUtils.rm_rf(tmp_dir) if File.exist?(tmp_dir) FileUtils.mkdir_p(tmp_dir) FileUtils.mkdir_p("#{Origen.root}/simulation") rc = Origen::RevisionControl.new remote: config[:rc_dir_url], local: tmp_dir rc.checkout "#{sid}.tar.gz", force: true, version: config[:rc_version] FileUtils.mv "#{tmp_dir}/#{sid}.tar.gz", "#{Origen.root}/simulation" FileUtils.rm_rf(ldir) if File.exist?(ldir) Dir.chdir "#{Origen.root}/simulation/" do system "tar -xvf #{sid}.tar.gz" end Origen.app.session.origen_sim[sid] = config[:rc_version] end else if !File.exist?(compiled_dir) || (File.exist?(compiled_dir) && Dir.entries(compiled_dir).size <= 2) puts "There is no previously compiled simulation object in: #{compiled_dir}" exit 1 end end ensure FileUtils.rm_f "#{ldir}.tar.gz" if File.exist?("#{ldir}.tar.gz") FileUtils.rm_rf tmp_dir if File.exist?(tmp_dir) end |
#flush(options = {}) ⇒ Object
Flush any buffered simulation output, this should cause live wave viewers to reflect the latest state.
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
# File 'lib/origen_sim/simulator.rb', line 869 def flush( = {}) if dut_version > '0.12.0' sync_up put('j^') sync_up # By now, the simulator has generated all log output up to this point and flushed it out, # however it may not be in the Origen log output yet because the main Origen thread has not # given the stdout/err reader threads a chance to process it. # This will now sleep the main Origen thread to allow that to get a chance to happen and we # will proceed once it has been > 100ms since a log message was processed, at that point we # can safely assume that they are all done and nothing is left in the buffer. w = false while !w || simulation.time_since_last_log < 0.1 w = true sleep 0.1 end # Finally, make sure the messages are not now sitting in an IO buffer Origen.log.flush nil # Keep the console clean if this is called interactively else unless [:quiet] OrigenSim.error "Use of flush requires a DUT model compiled with OrigenSim version > 0.12.0, the current dut was compiled with #{dut_version}" end end end |
#force(net, value) ⇒ Object
966 967 968 969 970 971 972 973 974 975 976 977 |
# File 'lib/origen_sim/simulator.rb', line 966 def force(net, value) sync_up if dut_version > '0.19.0' if value.is_a?(Integer) put("r^#{clean(net)}^i^#{value}") else put("r^#{clean(net)}^f^#{value}") end else OrigenSim.error 'Your DUT needs to be recompiled with OrigenSim >= 0.20.0 to support forcing, force not applied!' end end |
#generic_run_cmd ⇒ Object
81 82 83 |
# File 'lib/origen_sim/simulator.rb', line 81 def generic_run_cmd config[:generic_run_cmd] end |
#get ⇒ Object
Get a message from the simulator, will block until one is received
678 679 680 |
# File 'lib/origen_sim/simulator.rb', line 678 def get simulation.socket.readline end |
#id ⇒ Object
The ID assigned to the current simulation target, falls back to to the Origen target name if an :id option is not supplied when instantiating the tester
240 241 242 |
# File 'lib/origen_sim/simulator.rb', line 240 def id config[:id] || Origen.target.name end |
#interactive_shutdown ⇒ Object
988 989 990 |
# File 'lib/origen_sim/simulator.rb', line 988 def interactive_shutdown @interactive_mode = true end |
#log(msg, type = :info, multipart: false) ⇒ Object
Any messages passed in here will be output to the console log by making a round trip through the simulator. This ensures that the given log messages will be in sync with output from the simulator rather than potentially being ahead of the simulator if Origen were to output them immediately.
777 778 779 780 781 782 783 |
# File 'lib/origen_sim/simulator.rb', line 777 def log(msg, type = :info, multipart: false) if dut_version > '0.15.0' put("k^#{LOG_CODES[type]}^#{msg}") else Origen.log.send(type, msg) end end |
#log_messages=(val) ⇒ Object
When set to true the simulator will log all messages it receives, note that this must be run in conjunction with -d supplied to the Origen command to actually see the messages
65 66 67 68 69 70 71 |
# File 'lib/origen_sim/simulator.rb', line 65 def (val) if val put('d^1') else put('d^0') end end |
#marker=(val) ⇒ Object
1169 1170 1171 |
# File 'lib/origen_sim/simulator.rb', line 1169 def marker=(val) poke("#{testbench_top}.debug.marker", val) end |
#match_errors ⇒ Object
1143 1144 1145 1146 1147 1148 1149 |
# File 'lib/origen_sim/simulator.rb', line 1143 def match_errors if dut_version > '0.15.0' peek("#{testbench_top}.debug.match_errors").to_i else peek("#{testbench_top}.pins.match_errors").to_i end end |
#match_loop ⇒ Object
Any vectors executed within the given block will increment the match_errors counter rather than the errors counter. The match_errors counter will be returned to 0 at the end.
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/origen_sim/simulator.rb', line 1130 def match_loop if dut_version > '0.15.0' put('q^1') yield put('q^0') else poke("#{testbench_top}.pins.match_loop", 1) yield poke("#{testbench_top}.pins.match_loop", 0) poke("#{testbench_top}.pins.match_errors", 0) end end |
#max_errors ⇒ Object
Returns the number of errors that are allowed before a aborting a simulation
1165 1166 1167 |
# File 'lib/origen_sim/simulator.rb', line 1165 def max_errors OrigenSim.max_errors || config[:max_errors] || 100 end |
#on_flow_end(options) ⇒ Object
At the end of a test program flow generation/simulation
693 694 695 696 697 698 699 |
# File 'lib/origen_sim/simulator.rb', line 693 def on_flow_end() if simulation_tester? && [:top_level] @flow_running = false simulation.completed_cleanly = true stop end end |
#on_flow_start(options) ⇒ Object
At the start of a test program flow generation/simulation
683 684 685 686 687 688 689 690 |
# File 'lib/origen_sim/simulator.rb', line 683 def on_flow_start() if simulation_tester? && [:top_level] @flow_running = true OrigenSim.flow = Origen.interface.flow.name start @pattern_count = 0 end end |
#on_origen_shutdown ⇒ Object
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/origen_sim/simulator.rb', line 1009 def on_origen_shutdown unless simulations.empty? failed = false stop if simulation_open? unless @interactive_mode if simulations.size == 1 failed = simulation.failed? else failed_simulation_count = simulations.count(&:failed?) if failed_simulation_count > 0 Origen.log.error "#{failed_simulation_count} of #{simulations.size} simulations failed!" failed = true end end if failed Origen.app.stats.report_fail else Origen.app.stats.report_pass end end puts puts 'The following log files have been created:' puts simulations.each do |simulation| simulation.log_files.each do |f| puts " #{f}" end end puts if simulations.size == 1 puts 'To view the simulation run the following command:' puts puts " #{simulation.view_wave_command}" else puts 'To view the simulations run the following commands:' puts simulations.each do |simulation| if simulation.failed? puts " #{simulation.view_wave_command}".red else puts " #{simulation.view_wave_command}" end end end puts unless @interactive_mode failed ? exit(1) : exit(0) end end end |
#on_timeset_changed ⇒ Object
This will be called automatically whenever tester.set_timeset has been called
795 796 797 798 799 800 801 802 803 804 |
# File 'lib/origen_sim/simulator.rb', line 795 def on_timeset_changed # Important that this is done first, since it is used to clear the pin # and wave definitions in the bridge set_period(dut.current_timeset_period) # Clear pins and waves define_pins define_waves # Apply the pin reset values / re-apply the existing states put_all_pin_states end |
#pattern_generated(path) ⇒ Object Also known as: complete_simulation
This will be called at the end of every pattern, make sure the simulator is not running behind before potentially moving onto another pattern
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/origen_sim/simulator.rb', line 743 def pattern_generated(path) if simulation_tester? sync_up log '#' * 100 log '#' * 100 log '##' log "## END OF PATTERN: #{@running_pattern_name}" log "## Errors: #{error_count - @pattern_starting_error_count}" log '##' log '#' * 100 log '#' * 100 simulation.completed_cleanly = true unless @flow_running # Ensure that everything is flushed to the log before it is closed flush quiet: true end end |
#peek(net, real = false) ⇒ Object
Returns the current value of the given net, or nil if the given path does not resolve to a valid node
The value is returned as an instance of Origen::Value
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'lib/origen_sim/simulator.rb', line 910 def peek(net, real = false) sync_up if dut_version > '0.19.0' if real put("9^#{clean(net)}^f") m = get.strip if m == 'FAIL' return nil else m.to_f end else put("9^#{clean(net)}^i") m = get.strip if m == 'FAIL' Origen.log.warning "Peek of net #{net} failed to return any data!" return nil else Origen::Value.new('b' + m) end end else put("9^#{clean(net)}") m = get.strip if m == 'FAIL' Origen.log.warning "Peek of net #{net} failed to return any data!" return nil else Origen::Value.new('b' + m) end end end |
#peek_real(net) ⇒ Object
945 946 947 |
# File 'lib/origen_sim/simulator.rb', line 945 def peek_real(net) peek(net, true) end |
#peek_str(signal) ⇒ Object Also known as: str_peek, peek_string, string_peek
1151 1152 1153 1154 1155 1156 1157 1158 1159 |
# File 'lib/origen_sim/simulator.rb', line 1151 def peek_str(signal) val = peek(signal) unless val.nil? # All zeros seems to be what an empty string is returned from the VPI, # Otherwise, break the string up into 8-bit chunks and decode the ASCII> val = (val.to_s == 'b00000000' ? '' : val.to_s[1..-1].scan(/.{1,8}/).collect { |char| char.to_i(2).chr }.join) end val end |
#poke(net, value) ⇒ Object
Forces the given value to the given net. Note that no error checking is done and no error will be communicated if an illegal net is supplied. The user should follow up with a peek if they want to verify that the poke was applied.
953 954 955 956 957 958 959 960 961 962 963 964 |
# File 'lib/origen_sim/simulator.rb', line 953 def poke(net, value) sync_up if dut_version > '0.19.0' if value.is_a?(Integer) put("b^#{clean(net)}^i^#{value}") else put("b^#{clean(net)}^f^#{value}") end else put("b^#{clean(net)}^#{value}") end end |
#post_process_run_cmd ⇒ Object
85 86 87 |
# File 'lib/origen_sim/simulator.rb', line 85 def post_process_run_cmd config[:post_process_run_cmd] end |
#put(msg) ⇒ Object
Send the given message string to the simulator
662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/origen_sim/simulator.rb', line 662 def put(msg) simulation.socket.write(msg + "\n") rescue Errno::EPIPE => e # :from_origen_sim is added here to ensure this goes straight to the Origen console logger # and does not get sent via the simulator since it is clearly having problems if simulation.running? Origen.log.error 'Communication with the simulator has been lost (though it seems to still be running)!', from_origen_sim: true else Origen.log.error 'The simulator has stopped unexpectedly!', from_origen_sim: true end sleep 2 # To make sure that any log output from the simulator is captured before we pull the plug exit 1 end |
#put_all_pin_states ⇒ Object
Applies the current state of all pins to the simulation
786 787 788 789 790 791 |
# File 'lib/origen_sim/simulator.rb', line 786 def put_all_pin_states dut.rtl_pins.each do |name, pin| pin.reset_simulator_state pin.update_simulation end end |
#release(net) ⇒ Object
979 980 981 982 983 984 985 986 |
# File 'lib/origen_sim/simulator.rb', line 979 def release(net) sync_up if dut_version > '0.19.0' put("s^#{clean(net)}") else OrigenSim.error 'Your DUT needs to be recompiled with OrigenSim >= 0.20.0 to support releasing, force not released!' end end |
#rtl_top ⇒ Object
77 78 79 |
# File 'lib/origen_sim/simulator.rb', line 77 def rtl_top config[:rtl_top] || 'dut' end |
#run_cmd ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/origen_sim/simulator.rb', line 317 def run_cmd case config[:vendor] when :icarus cmd = configuration[:vvp] || 'vvp' cmd += " -M#{compiled_dir} -morigen #{compiled_dir}/origen.vvp +socket+#{socket_id}" when :cadence input_file = "#{tmp_dir}/#{wave_file_basename}.tcl" if !File.exist?(input_file) || config_changed? Origen.app.runner.launch action: :compile, files: "#{Origen.root!}/templates/probe.tcl.erb", output: tmp_dir, check_for_changes: false, quiet: true, options: { dir: wave_dir, wave_file: wave_file_basename, force: config[:force], setup: config[:setup], depth: :all }, output_file_name: "#{wave_file_basename}.tcl", preserve_target: true end input_file_fast = "#{tmp_dir}/#{wave_file_basename}_fast.tcl" if !File.exist?(input_file_fast) || config_changed? fast_probe_depth = config[:fast_probe_depth] || 1 Origen.app.runner.launch action: :compile, files: "#{Origen.root!}/templates/probe.tcl.erb", output: tmp_dir, check_for_changes: false, quiet: true, options: { dir: wave_dir, wave_file: wave_file_basename, force: config[:force], setup: config[:setup], depth: fast_probe_depth }, output_file_name: "#{wave_file_basename}_fast.tcl", preserve_target: true end save_config_signature wave_dir # Ensure this exists since it won't be referenced above if the input file is already generated cmd = configuration[:irun] || 'irun' cmd += " -r origen -snapshot origen +socket+#{socket_id}" cmd += $use_fast_probe_depth ? " -input #{input_file_fast}" : " -input #{input_file}" cmd += " -nclibdirpath #{compiled_dir}" when :synopsys if configuration[:verdi] cmd = "#{compiled_dir}/simv +socket+#{socket_id} +FSDB_ON +fsdbfile+#{Origen.root}/waves/#{id}/#{wave_file_basename}.fsdb +memcbk +vcsd" else cmd = "#{compiled_dir}/simv +socket+#{socket_id} -vpd_file #{wave_file_basename}.vpd" end when :generic # Generic tester requires that a generic_run_command option/block be provided. # This should either be a string, an array (which will be joined here), or a block that needs to return either # a string or array. In the event of a block, the block will be given the simulator. if generic_run_cmd cmd = generic_run_cmd if cmd.is_a?(Proc) cmd = cmd.call(self) end if cmd.is_a?(Array) # We'll join this together with the '; ' string. This means that each array element will be run # sequentially. cmd = cmd.join(' && ') elsif !cmd.is_a?(String) # If its Proc, it was already run, and if its a Array if would have gone into the other case. # So, this is either another proc, not an array and not a string, so not sure what to do with this. # Complain about the cmd. fail "OrigenSim :generic_run_cmd is of class #{generic_run_cmd.class}. It must be either an Array, String, or a Proc that returns an Array or String." end else fail 'OrigenSim Generic Toolchain/Vendor requires a :generic_run_cmd option/block to be provided. No options/block provided!' end else fail "Run cmd not defined yet for simulator #{config[:vendor]}" end # Allow the user to post-process the command. This should be a block which will be given two parameters: # 1. the command, and 2. the simulation object (self). # In the event of a generic tester, this *could* replace the launch command, but that's not the real intention, # since a simulator could be made that inherits from a generic simulator setup and still post process the command. cmd = post_process_run_cmd.call(cmd, self) if post_process_run_cmd fail "OrigenSim: :post_process_run_cmd returned object of class #{cmd.class}. Must return a String." unless cmd.is_a?(String) # Print the command if debug is enabled Origen.log.debug 'OrigenSim Run Command:' Origen.log.debug cmd cmd end |
#run_dir ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/origen_sim/simulator.rb', line 484 def run_dir case config[:vendor] when :icarus d = File.join(wave_dir, wave_file_basename) FileUtils.mkdir_p(d) d when :synopsys wave_dir else tmp_dir end end |
#running? ⇒ Boolean
1199 1200 1201 1202 1203 1204 1205 |
# File 'lib/origen_sim/simulator.rb', line 1199 def running? if simulation simulation.running? else false end end |
#save_config_signature ⇒ Object
Locally saves a signature for the current config, this will cause config_changed? to return false until its contents change
1087 1088 1089 |
# File 'lib/origen_sim/simulator.rb', line 1087 def save_config_signature Origen.app.session.origen_sim["#{id}_config"] = config.except(*NON_DATA_CONFIG_ATTRIBUTES) end |
#set_period(period_in_ns) ⇒ Object
848 849 850 |
# File 'lib/origen_sim/simulator.rb', line 848 def set_period(period_in_ns) put("1^#{ns_to_simtime_units(period_in_ns)}") end |
#simulation_open? ⇒ Boolean
497 498 499 |
# File 'lib/origen_sim/simulator.rb', line 497 def simulation_open? @simulation_open end |
#simulation_tester? ⇒ Boolean
1064 1065 1066 |
# File 'lib/origen_sim/simulator.rb', line 1064 def simulation_tester? (tester && tester.is_a?(OrigenSim::Tester)) end |
#snapshot_detail(d) ⇒ Object
55 56 57 |
# File 'lib/origen_sim/simulator/snapshot_details.rb', line 55 def snapshot_detail(d) snapshot_details(d) end |
#snapshot_details(d = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/origen_sim/simulator/snapshot_details.rb', line 47 def snapshot_details(d = nil) if d _snapshot_details[d] else _snapshot_details end end |
#socket_id ⇒ Object
1060 1061 1062 |
# File 'lib/origen_sim/simulator.rb', line 1060 def socket_id simulation.socket_id end |
#start ⇒ Object
Starts up the simulator process
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/origen_sim/simulator.rb', line 502 def start @simulation_open = true @pattern_starting_error_count = nil @simulation = Simulation.new(wave_file_basename, view_wave_command) simulations << @simulation fetch_simulation_objects artifact.clean artifact.populate cmd = run_cmd + ' & echo \$!' launch_simulator = %( require 'open3' require 'socket' require 'io/wait' require 'origen' pid = nil def kill_simulation(pid) begin # If the process already finished, then we will see an Errno exception. # It does not harm anything, but looks ugly, so catch it here and ignore. Process.kill('KILL', pid) rescue Errno::ESRCH => e end exit! end status = UNIXSocket.new('#{simulation.socket_id(:status)}') stdout_socket = UNIXSocket.new('#{simulation.socket_id(:stdout)}') stderr_socket = UNIXSocket.new('#{simulation.socket_id(:stderr)}') heartbeat = UNIXSocket.new('#{simulation.socket_id(:heartbeat)}') begin status.puts('Starting the simulator...') Dir.chdir '#{run_dir}' do Open3.popen3('#{cmd}') do |stdin, stdout, stderr, thread| status.puts('The simulator has started') pid = stdout.gets.strip.to_i status.puts(pid.to_s) # Listen for a heartbeat from the main Origen process every 5 seconds, kill the # simulator after two missed heartbeats Thread.new do missed_heartbeats = 0 loop do sleep 5 # If the socket read hangs, count that as a reason to shutdown socket_read = false Thread.new do sleep 1 kill_simulation(pid) unless socket_read end if heartbeat.ready? while heartbeat.ready? do heartbeat.gets end missed_heartbeats = 0 else missed_heartbeats += 1 end socket_read = true if missed_heartbeats > 1 kill_simulation(pid) end end end threads = [] threads << Thread.new do until (line = stdout.gets).nil? stdout_socket.puts line end end threads << Thread.new do until (line = stderr.gets).nil? stderr_socket.puts line end end threads.each(&:join) end end status.puts 'The simulator has finished' ensure # Make sure this process never finishes and leaves the simulator running kill_simulation(pid) if pid end ) Origen.log.debug 'Starting the simulation monitor...' Origen.log.flush # Required to stop any existing buffered log data being copied into this new process monitor_pid = spawn("ruby -e \"#{launch_simulator}\"") Process.detach(monitor_pid) simulation.open(monitor_pid, config[:startup_timeout] || 60) # This will block until the simulation process has started # The VPI extension will send 'READY!' when it starts, make sure we get it before proceeding data = get unless data.strip == 'READY!' simulation.failed_to_start = true simulation.log_results exit # Assume it is not worth trying another pattern in this case, some kind of environment/config issue end Origen.log.info "OrigenSim version #{Origen.app!.version}" Origen.log.info "OrigenSim DUT version #{dut_version}" unless dut_version > '0.15.0' Origen.log.warning 'Progress comments may be out of sync with simulator output.' Origen.log.warning 'Recompile your DUT with a newer version of OrigenSim to resolve this.' end # Tick the simulation on, this seems to be required since any VPI puts operations before # the simulation has started are not applied. # Note that this is not setting a tester timeset, so the application will still have to # do that before generating any vectors. put('1^0') # Set period to 0 so that time does not advance cycle(1) if dut_version > '0.15.0' # Put cycle counter back to 0 put('p^0') simulation.cycle(-1) put("m^#{max_errors}") # Intercept all log messages until the end of the simulation so that they can be synced to # simulation time @log_intercept_id = Origen.log.start_intercepting do |msg, type, , original| if [:from_origen_sim] original.call(msg, type, ) else # If the message would fit without the multi-line collateral, send it as normal. # Note: this also avoids the pitfall of a message whose size is exactly # config[:max_log_size] - LOGGER_COLLATERAL_SIZE getting stuck until # something else is pushed. if msg.size > config[:max_log_size] - (LOGGER_COLLATERAL_SIZE - MULTIPART_LOGGER_TOKEN.size) msg.chars.each_slice(config[:max_log_size] - LOGGER_COLLATERAL_SIZE) do |m| if m.size == config[:max_log_size] - LOGGER_COLLATERAL_SIZE log(m.join + MULTIPART_LOGGER_TOKEN, type, multipart: true) else log(m.join, type, multipart: false) end end else log(msg, type, multipart: false) end end end end sync_up # Make sure the simulation is underway before proceeding Origen.listeners_for(:simulation_startup).each(&:simulation_startup) end |
#start_read_reg_transaction ⇒ Object
1173 1174 1175 |
# File 'lib/origen_sim/simulator.rb', line 1173 def start_read_reg_transaction put('n^1') end |
#stop ⇒ Object
Stop the simulator
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 |
# File 'lib/origen_sim/simulator.rb', line 993 def stop @simulation_open = false simulation.error_count = error_count Origen.listeners_for(:simulation_shutdown).each(&:simulation_shutdown) sync_up Origen.log.stop_intercepting @log_intercept_id simulation.ended = true end_simulation # Give the simulator time to shut down sleep 0.1 while simulation.running? simulation.close simulation.log_results unless Origen.current_command == 'interactive' rescue simulation.completed_cleanly = false end |
#stop_read_reg_transaction ⇒ Object
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 |
# File 'lib/origen_sim/simulator.rb', line 1177 def stop_read_reg_transaction put('n^0') data = get error_count, max_errors = *(data.strip.split(',').map(&:to_i)) if error_count > 0 errors = [] error_count.times do |i| data = get # => "tdo,648,1,0\n" pin_name, cycle, expected, received = *(data.strip.split(',')) errors << { pin_name: pin_name, cycle: cycle.to_i, expected: expected.to_i, received: received.to_i } end [true, error_count > max_errors, errors] end end |
#sync ⇒ Object
1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/origen_sim/simulator.rb', line 1068 def sync put('f') @sync_active = true yield put('g') @sync_active = false end |
#sync_active? ⇒ Boolean
1076 1077 1078 |
# File 'lib/origen_sim/simulator.rb', line 1076 def sync_active? @sync_active end |
#sync_up ⇒ Object
Blocks the Origen process until the simulator indicates that it has processed all operations up to this point
859 860 861 862 863 864 865 |
# File 'lib/origen_sim/simulator.rb', line 859 def sync_up put('7^') data = get unless data.strip == 'OK!' fail 'Origen and the simulator are out of sync!' end end |
#target_artifact_dir ⇒ Object
214 215 216 |
# File 'lib/origen_sim/simulator.rb', line 214 def target_artifact_dir Pathname(@configuration[:target_artifact_dir] || "#{Origen.app.root}/simulation/#{id}/artifacts") end |
#testbench_top ⇒ Object
73 74 75 |
# File 'lib/origen_sim/simulator.rb', line 73 def testbench_top config[:testbench_top] || 'origen' end |
#timescale ⇒ Object
Get the timescale of the current simulation, returns a number that maps as follows:
-15 - fs
-14 - 10fs
-13 - 100fs
-12 - ps
-11 - 10ps
-10 - 100ps
-9 - ns
-8 - 10ns
-7 - 100ns
-6 - us
-5 - 10us
-4 - 100us
-3 - ms
-2 - 10ms
-1 - 100ms
0 - s
1 - 10s
2 - 100s
1122 1123 1124 1125 |
# File 'lib/origen_sim/simulator.rb', line 1122 def timescale put('l^') get.strip.to_i end |
#tmp_dir ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/origen_sim/simulator.rb', line 244 def tmp_dir @tmp_dir ||= begin d = "#{Origen.root}/tmp/origen_sim/#{id}/#{config[:vendor]}" FileUtils.mkdir_p(d) d end end |
#user_artifact_dirs ⇒ Object
210 211 212 |
# File 'lib/origen_sim/simulator.rb', line 210 def user_artifact_dirs @configuration.key?(:user_artifact_dirs) ? @configuration[:user_artifact_dirs].map { |d| Pathname(d) } : nil end |
#user_artifact_dirs? ⇒ Boolean
206 207 208 |
# File 'lib/origen_sim/simulator.rb', line 206 def user_artifact_dirs? @configuration.key?(:user_artifact_dirs) end |
#view_wave_command ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/origen_sim/simulator.rb', line 421 def view_wave_command cmd = nil case config[:vendor] when :icarus edir = Pathname.new(wave_config_dir).relative_path_from(Pathname.pwd) cmd = "cd #{edir} && " cmd += configuration[:gtkwave] || 'gtkwave' dir = Pathname.new(wave_dir).relative_path_from(edir.) cmd += " #{dir}/#{wave_file_basename}/dump.vcd " f = Pathname.new(wave_config_file).relative_path_from(edir.) cmd += " --save #{f} &" when :cadence edir = Pathname.new(wave_config_dir).relative_path_from(Pathname.pwd) cmd = "cd #{edir} && " cmd += configuration[:simvision] || 'simvision' dir = Pathname.new(wave_dir).relative_path_from(edir.) cmd += " #{dir}/#{wave_file_basename}/#{wave_file_basename}.dsn #{dir}/#{wave_file_basename}/#{wave_file_basename}.trn" f = Pathname.new(wave_config_file).relative_path_from(edir.) cmd += " -input #{f} &" when :synopsys edir = Pathname.new(wave_config_dir).relative_path_from(Pathname.pwd) cmd = "cd #{edir} && " if configuration[:verdi] unless ENV['VCS_HOME'] Origen.log.warning "Your environment doesn't define VCS_HOME, you will probably need that to run Verdi" end edir = Pathname.new(wave_config_dir).relative_path_from(Pathname.pwd) cmd = "cd #{edir} && " cmd += configuration[:verdi] || 'verdi' dir = Pathname.new(wave_dir).relative_path_from(edir.) cmd += " -ssz -dbdir #{Origen.root}/simulation/#{id}/synopsys/simv.daidir/ -ssf #{dir}/#{wave_file_basename}.fsdb" f = Pathname.new(wave_config_file).relative_path_from(edir.) cmd += " -sswr #{f}" cmd += ' &' else cmd += configuration[:dve] || 'dve' dir = Pathname.new(wave_dir).relative_path_from(edir.) cmd += " -vpd #{dir}/#{wave_file_basename}.vpd" f = Pathname.new(wave_config_file).relative_path_from(edir.) cmd += " -session #{f}" cmd += ' &' end when :generic # Since this could be anything, the simulator will need to set this up. But, once it is, we can print it here. if config[:view_waveform_cmd] cmd = config[:view_waveform_cmd] else Origen.log.warn 'OrigenSim cannot provide a view-waveform command for a :generic vendor.' Origen.log.warn 'Please supply a view-waveform command though the :view_waveform_cmd option during the OrigenSim::Generic instantiation.' end else # Print a warning stating an unknown vendor was reached here. # This shouldn't happen, but just in case. Origen.log.warn "OrigenSim does not know the command to view waveforms for vendor :#{config[:vendor]}!" end cmd end |
#wave_config_dir ⇒ Object
270 271 272 273 274 275 276 |
# File 'lib/origen_sim/simulator.rb', line 270 def wave_config_dir @wave_config_dir ||= begin d = "#{Origen.root}/config/waves/#{id}" FileUtils.mkdir_p(d) d end end |
#wave_config_ext ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/origen_sim/simulator.rb', line 302 def wave_config_ext case config[:vendor] when :icarus 'gtkw' when :cadence 'svcf' when :synopsys if configuration[:verdi] 'rc' else 'tcl' end end end |
#wave_config_file ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/origen_sim/simulator.rb', line 278 def wave_config_file @wave_config_file ||= configuration[:wave_config_file] || begin f = "#{wave_config_dir}/#{User.current.id}.#{wave_config_ext}" unless File.exist?(f) # Take a default wave if one has been set up d = "#{wave_config_dir}/default.#{wave_config_ext}" if File.exist?(d) FileUtils.cp(d, f) else # Otherwise seed it with the latest existing setup by someone else d = Dir.glob("#{wave_config_dir}/*.#{wave_config_ext}").max { |a, b| File.ctime(a) <=> File.ctime(b) } if d FileUtils.cp(d, f) else # We tried our best, start from scratch d = "#{Origen.root!}/templates/empty.#{wave_config_ext}" FileUtils.cp(d, f) if File.exist?(d) end end end f end end |
#wave_dir(subdir = nil) ⇒ Object
262 263 264 265 266 267 268 |
# File 'lib/origen_sim/simulator.rb', line 262 def wave_dir(subdir = nil) @wave_dir ||= begin d = "#{Origen.root}/waves/#{id}" FileUtils.mkdir_p(d) d end end |
#wave_file_basename ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/origen_sim/simulator.rb', line 405 def wave_file_basename if OrigenSim.flow OrigenSim.flow.to_s else if Origen.app.current_job @last_wave_file_basename = Pathname.new(Origen.app.current_job.output_file).basename('.*').to_s else if Origen.interactive? 'interactive' else @last_wave_file_basename || 'unnamed_pattern' end end end end |
#wave_to_str(wave) ⇒ Object
820 821 822 823 824 825 826 827 828 829 830 831 832 833 |
# File 'lib/origen_sim/simulator.rb', line 820 def wave_to_str(wave) wave.evaluated_events.map do |time, data| if data == :x data = 'X' elsif data == :data data = wave.drive? ? 'D' : 'C' end if data == 'C' "#{ns_to_simtime_units(time)}_#{data}_#{ns_to_simtime_units(time + 1)}_X" else "#{ns_to_simtime_units(time)}_#{data}" end end.join('_') end |
#wreal? ⇒ Boolean Also known as: wreal_enabled?
Returns true if the snapshot has been compiled with WREAL support
1208 1209 1210 1211 1212 |
# File 'lib/origen_sim/simulator.rb', line 1208 def wreal? return @wreal if defined?(@wreal) @wreal = (dut_version > '0.19.0' && peek("#{testbench_top}.debug.wreal_enabled").to_i == 1) end |
#write_comment(line, comment) ⇒ Object
761 762 763 764 765 766 767 768 769 770 771 |
# File 'lib/origen_sim/simulator.rb', line 761 def write_comment(line, comment) return if line >= OrigenSim::NUMBER_OF_COMMENT_LINES # Not sure what the limiting factor here is, the comment memory in the test bench should # be able to handle 1024 / 8 length strings, but any bigger than this hangs the simulation comment = comment ? comment[0..96] : '' if dut_version > '0.12.1' put("c^#{line}^#{comment} ") # Space at the end is important so that an empty comment is communicated properly else put("c^#{comment} ") end end |