Add comments for AddressEncoder and associated tests
authorDaniel Benusovich <flyingmonkeys1996@gmail.com>
Sat, 9 Mar 2019 04:04:10 +0000 (20:04 -0800)
committerDaniel Benusovich <flyingmonkeys1996@gmail.com>
Sat, 9 Mar 2019 04:04:10 +0000 (20:04 -0800)
TLB/src/AddressEncoder.py
TLB/test/test_address_encoder.py

index 53e2479e6655c5d33023b3c27076fc41e5840750..59e92f951e35419f6d75ffddabe082067af30fbc 100644 (file)
@@ -2,7 +2,23 @@ from nmigen import Module, Signal
 from nmigen.lib.coding import Encoder, PriorityEncoder
 
 class AddressEncoder():
+    """Address Encoder
+    
+       The purpose of this module is to take in a vector and 
+       encode the bits that are one hot into an address. This module
+       combines both nmigen's Encoder and PriorityEncoder and will state
+       whether the input line has a single bit hot, multiple bits hot,
+       or no bits hot. The output line will always have the lowest value 
+       address output.
+       
+       Usage:
+       The output is valid when either single or multiple match is high.
+       Otherwise output is 0.
+    """
     def __init__(self, width):
+        """ Arguments:
+            * width: The desired length of the input vector
+        """
         # Internal
         self.encoder = Encoder(width)
         self.p_encoder = PriorityEncoder(width)
index db555e127b6e1faefdfb0c074f762dbbfd4b60bd..8c3b6ad70a006f3274032c203c61dbd838707ccf 100644 (file)
@@ -12,18 +12,42 @@ def set_encoder(dut, i):
     yield dut.i.eq(i)
     yield
     
+# Checks the single match of the AddressEncoder
+# Arguments:
+#   dut: The AddressEncoder being tested
+#   sm (Single Match): The expected match result
+#   op (Operation): (0 => ==), (1 => !=)
 def check_single_match(dut, sm, op):
     out_sm = yield dut.single_match
     assert_op("Single Match", out_sm, sm, op)
     
+# Checks the multiple match of the AddressEncoder
+# Arguments:
+#   dut: The AddressEncoder being tested
+#   mm (Multiple Match): The expected match result
+#   op (Operation): (0 => ==), (1 => !=)    
 def check_multiple_match(dut, mm, op):
     out_mm = yield dut.multiple_match
     assert_op("Multiple Match", out_mm, mm, op)
     
+# Checks the output of the AddressEncoder
+# Arguments:
+#   dut: The AddressEncoder being tested
+#   o (Output): The expected output
+#   op (Operation): (0 => ==), (1 => !=)
 def check_output(dut, o, op):
     out_o = yield dut.o
     assert_op("Output", out_o, o, op)
-    
+
+# Checks the state of the AddressEncoder
+# Arguments:
+#   dut: The AddressEncoder being tested
+#   sm (Single Match): The expected match result
+#   mm (Multiple Match): The expected match result
+#   o (Output): The expected output
+#   ss_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
+#   mm_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
+#   o_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
 def check_all(dut, sm, mm, o, sm_op, mm_op, o_op):
     yield from check_single_match(dut, sm, sm_op)
     yield from check_multiple_match(dut, mm, mm_op)