Documentation work

This commit is contained in:
pjht 2018-07-15 16:39:31 -05:00
parent 99bd54a7a0
commit 4415331f16
6 changed files with 30 additions and 14 deletions

View File

@ -1 +1 @@
--private --exclude old/*
--private --protected --exclude old/*

View File

@ -1,4 +1,6 @@
## Adder device
class Adder < Device
# @param (see Device#initialize)
def initialize(width, init_args)
add_input("a", width)
add_input("b", width)
@ -7,7 +9,9 @@ class Adder < Device
@mask=(2**width)-1
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)
end
end

View File

@ -1,4 +1,4 @@
# Class for devices such as adders and registers
## Class for devices such as adders and registers
class Device
# Add an input port
# @param name [String] Name of the port
@ -7,7 +7,7 @@ class Device
def add_input(name, width=1)
port = Port.new(width)
instance_variable_set("@#{name}", port)
port.add_callback { |val| on_change(val) }
port.add_callback { |val| on_change() }
end
# Add an output port

View File

@ -106,8 +106,9 @@ class Port
return NotGate.new(self).out
end
protected
# Used by connect when setting up bidirectional connection.
# @api private
# @param (see #connect)
# @return [void]
def connect_back(port)

View File

@ -1,9 +1,8 @@
# creates VCD file from port states
require "set"
## Creates VCD files from port states
class VCD
# @param filename [String] The filename to output to
# @param timescale [String] The timescale
def initialize(filename, timescale="1ps")
@fd = File.open(filename, 'w')
@time=0
@ -11,9 +10,11 @@ class VCD
@portmap = {}
@idmap = {}
@id = "a"
write_header
write_metadata
end
# Start logging
# @return [void]
def start
@fd.puts "$scope module TOP $end"
@portmap.each do |portname,port|
@ -30,10 +31,16 @@ class VCD
@fd.puts "\#0"
end
def finish
# Stop logging
# @return [void]
def stop
@fd.close
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)
raise ArgumentError.new("Duplicate port name '#{portname}'") if @portmap.has_key?(portname)
if port.width > 1
@ -47,6 +54,8 @@ class VCD
end
end
# Advance x timesteps
# @param timesteps [Integer] The number of timesteps to advance
def advance(timesteps)
@time += timesteps
@fd.puts "\##{@time.to_s}"
@ -54,14 +63,17 @@ class VCD
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 "$date\n#{Time.now.asctime}\n$end"
@fd.puts "$timescale #{@timescale} $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)
#writes VCD line for state of port, using id
port = @portmap[portname]
if port.width == 1
state = port.val.to_s

View File

@ -1,2 +1 @@
Must document VCD and Adder
Must add tests for VCD and Device