Sha256: aed2bb191e6ed1942b7a7b18ce34b802bc0222d53e68cdb8a6a5172d9783fa1f

Contents?: true

Size: 1011 Bytes

Versions: 2

Compression:

Stored size: 1011 Bytes

Contents

# Defines methods for transferring control between Ruby and Verilog.
#--
# Copyright 2008 Suraj N. Kurapati
# See the file named LICENSE for details.

begin
  module RubyVPI
    require 'thread'

    @@userRun = Queue.new
    @@hostRun = Queue.new

    # Allows the simulator to resume this Ruby code.
    def resume aCallback
      @@userRun.enq aCallback
      attach
    end

    module_function :resume

    # Pauses this Ruby code and waits for the simulator to resume it.
    def pause
      detach
      @@userRun.deq
    end

    module_function :pause

    # Unblocks the simulator, which is waiting for this Ruby code to pause.
    def detach
      @@hostRun.enq nil
    end

    module_function :detach

    # Allows the simulator to wait for this Ruby code to pause.
    def attach
      @@hostRun.deq
    end

    module_function :attach
  end

rescue Exception => e
  # mimic how Ruby internally prints exceptions
  STDERR.puts "#{e.class}: #{e.message}", e.backtrace.map {|s| "\tfrom #{s}" }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-vpi-21.0.0 lib/ruby-vpi/boot/relay.rb
ruby-vpi-21.1.0 lib/ruby-vpi/boot/relay.rb