Module Parameter and Constants
parammod.py
import ucdp as u
class ParamMod(u.AMod):
"""Example Module With Parameters."""
def _build(self):
parser = self.parser
# a module parameter which can be set at instantiation
param_p = self.add_param(u.IntegerType(default=10), "param_p")
# a parameter which is derived by a formula from a previous parameter
width_p = self.add_param(u.IntegerType(default=parser.log2(param_p + 1)), "width_p")
# just another parameter
default_p = self.add_param(u.IntegerType(default=param_p), "default_p")
# ports which depend on the parameter above
self.add_port(u.UintType(param_p), "data_i")
self.add_port(u.UintType(width_p), "cnt_o")
# an internal constant
self.add_const(u.UintType(param_p, default=default_p), "const_c")