Documentation work
This commit is contained in:
parent
99bd54a7a0
commit
4415331f16
@ -1,4 +1,6 @@
|
|||||||
|
## Adder device
|
||||||
class Adder < Device
|
class Adder < Device
|
||||||
|
# @param (see Device#initialize)
|
||||||
def initialize(width, init_args)
|
def initialize(width, init_args)
|
||||||
add_input("a", width)
|
add_input("a", width)
|
||||||
add_input("b", width)
|
add_input("b", width)
|
||||||
@ -7,7 +9,9 @@ class Adder < Device
|
|||||||
@mask=(2**width)-1
|
@mask=(2**width)-1
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_change(data_val)
|
private
|
||||||
|
# Called when there is a change to inputs
|
||||||
|
def on_change()
|
||||||
out.setval((a.val+b.val)&@mask)
|
out.setval((a.val+b.val)&@mask)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Class for devices such as adders and registers
|
## Class for devices such as adders and registers
|
||||||
class Device
|
class Device
|
||||||
# Add an input port
|
# Add an input port
|
||||||
# @param name [String] Name of the port
|
# @param name [String] Name of the port
|
||||||
@ -7,7 +7,7 @@ class Device
|
|||||||
def add_input(name, width=1)
|
def add_input(name, width=1)
|
||||||
port = Port.new(width)
|
port = Port.new(width)
|
||||||
instance_variable_set("@#{name}", port)
|
instance_variable_set("@#{name}", port)
|
||||||
port.add_callback { |val| on_change(val) }
|
port.add_callback { |val| on_change() }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add an output port
|
# Add an output port
|
||||||
|
@ -106,8 +106,9 @@ class Port
|
|||||||
return NotGate.new(self).out
|
return NotGate.new(self).out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
# Used by connect when setting up bidirectional connection.
|
# Used by connect when setting up bidirectional connection.
|
||||||
# @api private
|
|
||||||
# @param (see #connect)
|
# @param (see #connect)
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def connect_back(port)
|
def connect_back(port)
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
# creates VCD file from port states
|
## Creates VCD files from port states
|
||||||
|
|
||||||
require "set"
|
|
||||||
|
|
||||||
class VCD
|
class VCD
|
||||||
|
|
||||||
|
# @param filename [String] The filename to output to
|
||||||
|
# @param timescale [String] The timescale
|
||||||
def initialize(filename, timescale="1ps")
|
def initialize(filename, timescale="1ps")
|
||||||
@fd = File.open(filename, 'w')
|
@fd = File.open(filename, 'w')
|
||||||
@time=0
|
@time=0
|
||||||
@ -11,9 +10,11 @@ class VCD
|
|||||||
@portmap = {}
|
@portmap = {}
|
||||||
@idmap = {}
|
@idmap = {}
|
||||||
@id = "a"
|
@id = "a"
|
||||||
write_header
|
write_metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Start logging
|
||||||
|
# @return [void]
|
||||||
def start
|
def start
|
||||||
@fd.puts "$scope module TOP $end"
|
@fd.puts "$scope module TOP $end"
|
||||||
@portmap.each do |portname,port|
|
@portmap.each do |portname,port|
|
||||||
@ -30,10 +31,16 @@ class VCD
|
|||||||
@fd.puts "\#0"
|
@fd.puts "\#0"
|
||||||
end
|
end
|
||||||
|
|
||||||
def finish
|
# Stop logging
|
||||||
|
# @return [void]
|
||||||
|
def stop
|
||||||
@fd.close
|
@fd.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Attatch a port
|
||||||
|
# @param port [Port] The port to attatch
|
||||||
|
# @param portname [String] The name of the port in the VCD file
|
||||||
|
# @return [void]
|
||||||
def attach(port, portname)
|
def attach(port, portname)
|
||||||
raise ArgumentError.new("Duplicate port name '#{portname}'") if @portmap.has_key?(portname)
|
raise ArgumentError.new("Duplicate port name '#{portname}'") if @portmap.has_key?(portname)
|
||||||
if port.width > 1
|
if port.width > 1
|
||||||
@ -47,6 +54,8 @@ class VCD
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Advance x timesteps
|
||||||
|
# @param timesteps [Integer] The number of timesteps to advance
|
||||||
def advance(timesteps)
|
def advance(timesteps)
|
||||||
@time += timesteps
|
@time += timesteps
|
||||||
@fd.puts "\##{@time.to_s}"
|
@fd.puts "\##{@time.to_s}"
|
||||||
@ -54,14 +63,17 @@ class VCD
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def write_header
|
# Write the VCD file metadata
|
||||||
|
def write_metadata
|
||||||
@fd.puts "$version\nRCircuit VCD Generator Version 0.0\n$end"
|
@fd.puts "$version\nRCircuit VCD Generator Version 0.0\n$end"
|
||||||
@fd.puts "$date\n#{Time.now.asctime}\n$end"
|
@fd.puts "$date\n#{Time.now.asctime}\n$end"
|
||||||
@fd.puts "$timescale #{@timescale} $end"
|
@fd.puts "$timescale #{@timescale} $end"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Writes VCD line for state of port, using id
|
||||||
|
# @param portname [String] the name of port to write out state
|
||||||
def write_port_state(portname)
|
def write_port_state(portname)
|
||||||
#writes VCD line for state of port, using id
|
|
||||||
port = @portmap[portname]
|
port = @portmap[portname]
|
||||||
if port.width == 1
|
if port.width == 1
|
||||||
state = port.val.to_s
|
state = port.val.to_s
|
||||||
|
Loading…
Reference in New Issue
Block a user