Class: OrigenSim::Simulator
- Inherits:
-
Object
- Object
- OrigenSim::Simulator
- Includes:
- Origen::PersistentCallbacks
- Defined in:
- lib/origen_sim/simulator.rb
Overview
Responsible for managing and communicating with the simulator process, a single instance of this class is instantiated as OrigenSim.simulator
Constant Summary collapse
- VENDORS =
[:icarus, :cadence, :synopsys]
Instance Attribute Summary collapse
-
#configuration ⇒ Object
(also: #config)
readonly
Returns the value of attribute configuration.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#before_pattern(name) ⇒ Object
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) ⇒ Object
- #cycle(number_of_cycles) ⇒ 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_count ⇒ Object
Returns the current simulation error count.
- #fetch_simulation_objects(options = {}) ⇒ 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.
- #interactive_shutdown ⇒ Object
-
#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.
- #on_origen_shutdown ⇒ Object
-
#on_timeset_changed ⇒ Object
This will be called automatically whenever tester.set_timeset has been called.
-
#pattern_generated(path) ⇒ Object
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) ⇒ Object
Returns the current value of the given net, or nil if the given path does not resolve to a valid node.
-
#pid ⇒ Object
Returns the pid of the simulator process.
- #pid_dir ⇒ Object
- #pid_file ⇒ Object
-
#poke(net, value) ⇒ Object
Forces the given value to the given net.
-
#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.
- #run_cmd ⇒ Object
- #run_dir ⇒ Object
-
#running? ⇒ Boolean
Returns true if the simulator process is running.
-
#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_tester? ⇒ Boolean
- #socket_id ⇒ Object
- #socket_number ⇒ Object
-
#start ⇒ Object
Starts up the simulator process.
-
#stop ⇒ Object
Stop the simulator.
- #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.
- #timeout_connection(wait_in_s) ⇒ Object
- #tmp_dir ⇒ Object
- #view_wave_command ⇒ Object
- #wave_config_dir ⇒ Object
- #wave_config_ext ⇒ Object
- #wave_config_file ⇒ Object
- #wave_dir ⇒ Object
- #wave_to_str(wave) ⇒ Object
- #write_comment(comment) ⇒ Object
Instance Attribute Details
#configuration ⇒ Object (readonly) Also known as: config
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/origen_sim/simulator.rb', line 11 def configuration @configuration end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
11 12 13 |
# File 'lib/origen_sim/simulator.rb', line 11 def failed @failed end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
11 12 13 |
# File 'lib/origen_sim/simulator.rb', line 11 def socket @socket end |
Instance Method Details
#before_pattern(name) ⇒ Object
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
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/origen_sim/simulator.rb', line 376 def before_pattern(name) @simulation_completed_cleanly = false if simulation_tester? unless @enabled # When running pattern back-to-back, only want to launch the simulator the # first time unless socket start end end # Set the current pattern name in the simulation put("a^#{name.sub(/\..*/, '')}") @pattern_count ||= 0 if @pattern_count > 0 c = error_count if c > 0 Origen.log.error "The simulation currently has #{c} error(s)!" else Origen.log.success 'There are no simulation errors yet!' end end @pattern_count += 1 end end |
#commit_simulation_objects(options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/origen_sim/simulator.rb', line 64 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
112 113 114 115 116 117 118 |
# File 'lib/origen_sim/simulator.rb', line 112 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
676 677 678 |
# File 'lib/origen_sim/simulator.rb', line 676 def config_changed? Origen.app.session.origen_sim["#{id}_config"] != config end |
#configure(options) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/origen_sim/simulator.rb', line 86 def configure() fail 'A vendor must be supplied, e.g. OrigenSim::Tester.new(vendor: :icarus)' unless [:vendor] unless VENDORS.include?([:vendor]) fail "Unknown vendor #{options[:vendor]}, valid values are: #{VENDORS.map { |v| ':' + v.to_s }.join(', ')}" end @configuration = @tmp_dir = nil end |
#cycle(number_of_cycles) ⇒ Object
475 476 477 |
# File 'lib/origen_sim/simulator.rb', line 475 def cycle(number_of_cycles) put("3^#{number_of_cycles}") 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
431 432 433 434 435 436 437 438 439 |
# File 'lib/origen_sim/simulator.rb', line 431 def define_pins dut.rtl_pins.each_with_index do |(name, pin), i| 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
457 458 459 460 461 462 463 464 |
# File 'lib/origen_sim/simulator.rb', line 457 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
687 688 689 690 691 692 |
# File 'lib/origen_sim/simulator.rb', line 687 def dut_version @dut_version ||= begin put('i^') Origen::VersionString.new(get.strip) end end |
#end_simulation ⇒ Object
466 467 468 |
# File 'lib/origen_sim/simulator.rb', line 466 def end_simulation put('8^') end |
#error_count ⇒ Object
Returns the current simulation error count
490 491 492 |
# File 'lib/origen_sim/simulator.rb', line 490 def error_count peek('origen.debug.errors').to_i end |
#fetch_simulation_objects(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/origen_sim/simulator.rb', line 25 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 |
#get ⇒ Object
Get a message from the simulator, will block until one is received
361 362 363 |
# File 'lib/origen_sim/simulator.rb', line 361 def get 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
98 99 100 |
# File 'lib/origen_sim/simulator.rb', line 98 def id config[:id] || Origen.target.name end |
#interactive_shutdown ⇒ Object
582 583 584 |
# File 'lib/origen_sim/simulator.rb', line 582 def interactive_shutdown @interactive_mode = true 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
17 18 19 20 21 22 23 |
# File 'lib/origen_sim/simulator.rb', line 17 def (val) if val put('d^1') else put('d^0') end end |
#on_origen_shutdown ⇒ Object
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 |
# File 'lib/origen_sim/simulator.rb', line 602 def on_origen_shutdown if @enabled unless @interactive_mode Origen.log.debug 'Shutting down simulator...' unless @failed_to_start c = error_count if c > 0 @failed = true Origen.log.error "The simulation failed with #{c} errors!" elsif !@simulation_completed_cleanly @failed = true Origen.log.error 'The simulation exited early!' end end end stop unless @interactive_mode if failed Origen.app.stats.report_fail else Origen.app.stats.report_pass end end if view_wave_command puts puts 'To view the simulation run the following command:' puts puts " #{view_wave_command}" puts end end ensure Process.kill(15, pid) if @enabled && running? end |
#on_timeset_changed ⇒ Object
This will be called automatically whenever tester.set_timeset has been called
418 419 420 421 422 423 424 425 426 427 |
# File 'lib/origen_sim/simulator.rb', line 418 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
This will be called at the end of every pattern, make sure the simulator is not running behind before potentially moving onto another pattern
368 369 370 371 |
# File 'lib/origen_sim/simulator.rb', line 368 def pattern_generated(path) sync_up if simulation_tester? @simulation_completed_cleanly = true end |
#peek(net) ⇒ 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
498 499 500 501 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 |
# File 'lib/origen_sim/simulator.rb', line 498 def peek(net) # The Verilog spec does not specify that underlying VPI put method should # handle a part select, so some simulators do not handle it. Therefore we # deal with it here to ensure cross simulator compatibility. # http://rubular.com/r/eTVGzrYmXQ if net =~ /(.*)\[(\d+):?(\.\.)?(\d*)\]$/ net = Regexp.last_match(1) msb = Regexp.last_match(2).to_i lsb = Regexp.last_match(4) lsb = lsb.empty? ? nil : lsb.to_i end sync_up put("9^#{clean(net)}") m = get.strip if m == 'FAIL' return nil else if msb # Setting a range of bits if lsb Origen::Value.new('b' + m[(m.size - 1 - msb)..(m.size - 1 - lsb)]) else Origen::Value.new('b' + m[m.size - 1 - msb]) end else Origen::Value.new('b' + m) end end end |
#pid ⇒ Object
Returns the pid of the simulator process
331 332 333 334 335 336 337 |
# File 'lib/origen_sim/simulator.rb', line 331 def pid return @pid if @pid_set @pid = File.readlines(pid_file).first.strip.to_i if File.exist?(pid_file) @pid ||= 0 @pid_set = true @pid end |
#pid_dir ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/origen_sim/simulator.rb', line 128 def pid_dir @pid_dir ||= begin d = "#{Origen.root}/tmp/origen_sim/pids" FileUtils.mkdir_p(d) d end end |
#pid_file ⇒ Object
339 340 341 |
# File 'lib/origen_sim/simulator.rb', line 339 def pid_file "#{Origen.root}/tmp/origen_sim/pids/#{socket_number}" 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.
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 |
# File 'lib/origen_sim/simulator.rb', line 535 def poke(net, value) # The Verilog spec does not specify that underlying VPI put method should # handle a part select, so some simulators do not handle it. Therefore we # deal with it here to ensure cross simulator compatibility. # http://rubular.com/r/eTVGzrYmXQ if !config[:vendor] == :synopsys && net =~ /(.*)\[(\d+):?(\.\.)?(\d*)\]$/ path = Regexp.last_match(1) msb = Regexp.last_match(2).to_i lsb = Regexp.last_match(4) lsb = lsb.empty? ? nil : lsb.to_i v = peek(path) return nil unless v # Setting a range of bits if lsb upper = v >> (msb + 1) # Make sure value does not overflow value = value[(msb - lsb)..0] if lsb == 0 value = (upper << (msb + 1)) | value else lower = v[(lsb - 1)..0] value = (upper << (msb + 1)) | (value << lsb) | lower end # Setting a single bit else if msb == 0 upper = v >> 1 value = (upper << 1) | value[0] else lower = v[(msb - 1)..0] upper = v >> (msb + 1) value = (upper << (msb + 1)) | (value[0] << msb) | lower end end net = path end sync_up put("b^#{clean(net)}^#{value}") end |
#put(msg) ⇒ Object
Send the given message string to the simulator
355 356 357 |
# File 'lib/origen_sim/simulator.rb', line 355 def put(msg) socket.write(msg + "\n") if socket end |
#put_all_pin_states ⇒ Object
Applies the current state of all pins to the simulation
409 410 411 412 413 414 |
# File 'lib/origen_sim/simulator.rb', line 409 def put_all_pin_states dut.rtl_pins.each do |name, pin| pin.reset_simulator_state pin.update_simulation end end |
#run_cmd ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/origen_sim/simulator.rb', line 179 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}/#{id}.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, force: config[:force], setup: config[:setup], depth: :all }, output_file_name: "#{id}.tcl" end input_file_fast = "#{tmp_dir}/#{id}_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, force: config[:force], setup: config[:setup], depth: fast_probe_depth }, output_file_name: "#{id}_fast.tcl" 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 cmd = "#{compiled_dir}/simv +socket+#{socket_id} -vpd_file origen.vpd" else fail "Run cmd not defined yet for simulator #{config[:vendor]}" end cmd end |
#run_dir ⇒ Object
260 261 262 263 264 265 266 267 |
# File 'lib/origen_sim/simulator.rb', line 260 def run_dir case config[:vendor] when :icarus, :synopsys wave_dir else tmp_dir end end |
#running? ⇒ Boolean
Returns true if the simulator process is running
344 345 346 347 348 349 350 351 352 |
# File 'lib/origen_sim/simulator.rb', line 344 def running? return false if pid == 0 begin Process.getpgid(pid) true rescue Errno::ESRCH 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
682 683 684 |
# File 'lib/origen_sim/simulator.rb', line 682 def save_config_signature Origen.app.session.origen_sim["#{id}_config"] = config end |
#set_period(period_in_ns) ⇒ Object
470 471 472 473 |
# File 'lib/origen_sim/simulator.rb', line 470 def set_period(period_in_ns) period_in_ps = period_in_ns * time_conversion_factor * (config[:time_factor] || 1) put("1^#{period_in_ps}") end |
#simulation_tester? ⇒ Boolean
645 646 647 |
# File 'lib/origen_sim/simulator.rb', line 645 def simulation_tester? (tester && tester.is_a?(OrigenSim::Tester)) end |
#socket_id ⇒ Object
637 638 639 |
# File 'lib/origen_sim/simulator.rb', line 637 def socket_id @socket_id ||= "/tmp/#{socket_number}.sock" end |
#socket_number ⇒ Object
641 642 643 |
# File 'lib/origen_sim/simulator.rb', line 641 def socket_number @socket_number ||= (Process.pid.to_s + Time.now.to_f.to_s).sub('.', '') end |
#start ⇒ Object
Starts up the simulator process
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/origen_sim/simulator.rb', line 270 def start fetch_simulation_objects server = UNIXServer.new(socket_id) verbose = Origen.debugger_enabled? cmd = run_cmd + ' & echo \$!' launch_simulator = %( require 'open3' Dir.chdir '#{run_dir}' do Open3.popen3('#{cmd}') do |stdin, stdout, stderr, thread| pid = stdout.gets.strip File.open '#{pid_dir}/#{socket_number}', 'w' do |f| f.puts pid end threads = [] threads << Thread.new do until (line = stdout.gets).nil? puts line if #{verbose ? 'true' : 'false'} end end threads << Thread.new do until (line = stderr.gets).nil? puts line end end threads.each(&:join) end end ) simulator_parent_process = spawn("ruby -e \"#{launch_simulator}\"") Process.detach(simulator_parent_process) timeout_connection(config[:startup_timeout] || 60) do @socket = server.accept @connection_established = true if @connection_timed_out @failed_to_start = true Origen.log.error 'Simulator failed to respond' @failed = true exit end end data = get unless data.strip == 'READY!' @failed_to_start = true fail "The simulator didn't start properly!" end @enabled = true # 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. set_period(100) cycle(1) Origen.listeners_for(:simulation_startup).each(&:simulation_startup) end |
#stop ⇒ Object
Stop the simulator
587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
# File 'lib/origen_sim/simulator.rb', line 587 def stop Origen.listeners_for(:simulation_shutdown).each(&:simulation_shutdown) ended = Time.now end_simulation # Give the simulator a few seconds to shut down, otherwise kill it sleep 1 while running? && (Time.now - ended) < 10 Process.kill(15, pid) if running? sleep 0.1 # Leave the pid file around if we couldn't verify the simulator # has stopped FileUtils.rm_f(pid_file) if File.exist?(pid_file) && !running? @socket.close if @socket File.unlink(socket_id) if File.exist?(socket_id) end |
#sync ⇒ Object
663 664 665 666 667 668 669 |
# File 'lib/origen_sim/simulator.rb', line 663 def sync put('f') @sync_active = true yield put('g') @sync_active = false end |
#sync_active? ⇒ Boolean
671 672 673 |
# File 'lib/origen_sim/simulator.rb', line 671 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
481 482 483 484 485 486 487 |
# File 'lib/origen_sim/simulator.rb', line 481 def sync_up put('7^') data = get unless data.strip == 'OK!' fail 'Origen and the simulator are out of sync!' end end |
#timeout_connection(wait_in_s) ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/origen_sim/simulator.rb', line 649 def timeout_connection(wait_in_s) @connection_timed_out = false t = Thread.new do sleep wait_in_s # If the Verilog process has not established a connection yet, then make one to # release our process and then exit unless @connection_established @connection_timed_out = true UNIXSocket.new(socket_id).puts() end end yield end |
#tmp_dir ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/origen_sim/simulator.rb', line 102 def tmp_dir @tmp_dir ||= begin d = "#{Origen.root}/tmp/origen_sim/#{id}/#{config[:vendor]}" FileUtils.mkdir_p(d) d end end |
#view_wave_command ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/origen_sim/simulator.rb', line 225 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}/origen.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}/#{id}.dsn #{dir}/#{id}.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} && " cmd += configuration[:dve] || 'dve' dir = Pathname.new(wave_dir).relative_path_from(edir.) cmd += " -vpd #{dir}/origen.vpd" f = Pathname.new(wave_config_file).relative_path_from(edir.) cmd += " -session #{f}" cmd += ' &' end cmd end |
#wave_config_dir ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/origen_sim/simulator.rb', line 136 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
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/origen_sim/simulator.rb', line 168 def wave_config_ext case config[:vendor] when :icarus 'gtkw' when :cadence 'svcf' when :synopsys 'tcl' end end |
#wave_config_file ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/origen_sim/simulator.rb', line 144 def wave_config_file @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 ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/origen_sim/simulator.rb', line 120 def wave_dir @wave_dir ||= begin d = "#{Origen.root}/waves/#{id}" FileUtils.mkdir_p(d) d end end |
#wave_to_str(wave) ⇒ Object
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/origen_sim/simulator.rb', line 441 def wave_to_str(wave) wave.evaluated_events.map do |time, data| time = time * time_conversion_factor * (config[:time_factor] || 1) if data == :x data = 'X' elsif data == :data data = wave.drive? ? 'D' : 'C' end if data == 'C' "#{time}_#{data}_#{time + (time_conversion_factor * (config[:time_factor] || 1))}_X" else "#{time}_#{data}" end end.join('_') end |
#write_comment(comment) ⇒ Object
401 402 403 404 405 406 |
# File 'lib/origen_sim/simulator.rb', line 401 def write_comment(comment) # 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[0..96] put("c^#{comment}") end |