Skip to content
Snippets Groups Projects
Commit a89b407e authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Added command line parser and __main__. Added class description docstrings

parent 8c6a3944
No related branches found
No related tags found
No related merge requests found
...@@ -29,11 +29,14 @@ ...@@ -29,11 +29,14 @@
import os import os
import copy import copy
import yaml import yaml
import argparse
import common as cm import common as cm
field_modes = ["RO", "WO", "RW", "WP", "RR"] field_modes = ["RO", "WO", "RW", "WP", "RR"]
class Field: class Field:
""" A field defines data at certain address or an array of addresses
"""
def __init__(self, name, width, mode, offset, default, descr, repeat=None): def __init__(self, name, width, mode, offset, default, descr, repeat=None):
self.name = name self.name = name
self.width = width self.width = width
...@@ -47,7 +50,10 @@ class Field: ...@@ -47,7 +50,10 @@ class Field:
self.descr = descr self.descr = descr
self.repeat = repeat self.repeat = repeat
class Register: class Register:
""" A register consists of Fields
"""
def __init__(self, name, fields = [], nof_inst = 1): def __init__(self, name, fields = [], nof_inst = 1):
self.name = name self.name = name
self.fields = fields self.fields = fields
...@@ -64,13 +70,19 @@ class Register: ...@@ -64,13 +70,19 @@ class Register:
def setNof_inst(self, nof_inst): def setNof_inst(self, nof_inst):
self.nof_inst = nof_inst self.nof_inst = nof_inst
class RAM(Field): class RAM(Field):
""" A RAM is a Field that is repeated depth times
"""
def __init__(self, name, width, mode, depth, nof_inst, descr): def __init__(self, name, width, mode, depth, nof_inst, descr):
Field.__init__(self, name, width, mode, 0x0, 0, descr) Field.__init__(self, name, width, mode, 0x0, 0, descr)
self.depth = depth self.depth = depth
self.nof_inst = nof_inst self.nof_inst = nof_inst
class FIFO(Field): class FIFO(Field):
""" A FIFO is a specific set of Fields
"""
def __init__(self, name, width, mode, default, depth): def __init__(self, name, width, mode, default, depth):
Field.__init__(self, name, width, mode, 0, default) Field.__init__(self, name, width, mode, 0, default)
fifo_fields = [] fifo_fields = []
...@@ -81,45 +93,67 @@ class FIFO(Field): ...@@ -81,45 +93,67 @@ class FIFO(Field):
self.Register = Register("FIFO Register", fifo_fields) self.Register = Register("FIFO Register", fifo_fields)
self.depth = depth self.depth = depth
class Parameter: class Parameter:
""" A Parameter defines a name and value
"""
def __init__(self, name, value): def __init__(self, name, value):
self.name = name self.name = name
self.value = value self.value = value
class Peripheral: class Peripheral:
""" A Peripheral consists of 1 or more MM slaves. The slave can be a
Register, RAM or FIFO.
The Peripheral has parameters to configure the MM slaves.
A Peripheral has two levels of supporting multiple instances:
1) At system level a peripheral can be used more than once. The individual
peripherals are then distinghuised by defining a unique label per
instance.
2) At peripheral level internally in the peripheral if the peripheral
support an array of instances. The size of the array is then specified
via nof_inst. Dependent on the specific definition of the peripheral,
the nof_inst then either replicates some fields in a register or it
replicates some or all MM slaves nof_inst times.
The Peripheral evaluates the nof_inst and parameters to set the
dimensions of the MM slaves.
"""
def __init__(self, name, nof_inst, descr, label = ""): def __init__(self, name, nof_inst, descr, label = ""):
self.name = name self.name = name
self.postfix = ""
self.label = label # the label is used to make it unique in case multiple instances are required in a system
self.nof_inst = nof_inst self.nof_inst = nof_inst
self.descr = descr self.descr = descr
self.label = label # the label is used to make it unique in case multiple instances are required in a system self.parameters = {}
self.postfix = ""
self.registers = [] self.registers = []
self.rams = [] self.rams = []
self.fifos = [] self.fifos = []
self.parameters = {}
def addRegister(self, name, fields): def setName(self, name):
self.registers.append(Register(name, fields, self.nof_inst)) self.name = name
def addRAM(self, name, width, mode, depth, descr): def setNof_inst(self, nof_inst):
self.rams.append(RAM(name, width, mode, depth, self.nof_inst, descr)) self.nof_inst = nof_inst
def setLabel(self, label):
self.label = label
def addParameter(self, name, value): def addParameter(self, name, value):
self.parameters.append(Parameter(name, value)) self.parameters.append(Parameter(name, value))
def setLabel(self, label): def addRegister(self, name, fields):
self.label = label self.registers.append(Register(name, fields, self.nof_inst))
def setName(self, name): def addRAM(self, name, width, mode, depth, descr):
self.name = name self.rams.append(RAM(name, width, mode, depth, self.nof_inst, descr))
def setNof_inst(self, nof_inst):
self.nof_inst = nof_inst
def evalRAM(self): def evalRAM(self):
"""Evaluate the parameters and the nof_inst of the peripheral in order to define the real depth and width of the RAM. """Evaluate the parameters and the nof_inst of the peripheral in order to define the real depth and width of the RAM.
For instance: depth = c_nof_weights*c_nof_signal_paths For example: depth = c_nof_weights*c_nof_signal_paths
witdh = c_weights_w*c_nof_complex """ witdh = c_weights_w*c_nof_complex """
for parameter in self.parameters: for parameter in self.parameters:
exec("%s = %d" % (parameter, self.parameters[parameter])) # Here the parameters of the peripheral are promoted to real python variables exec("%s = %d" % (parameter, self.parameters[parameter])) # Here the parameters of the peripheral are promoted to real python variables
for ram in self.rams: for ram in self.rams:
...@@ -165,8 +199,10 @@ class Peripheral: ...@@ -165,8 +199,10 @@ class Peripheral:
self.evalRAM() self.evalRAM()
self.evalRegister() self.evalRegister()
class PeripheralLibrary: class PeripheralLibrary:
""" List of all information for peripheral config files in the root dir
"""
def __init__(self, rootDir, fileName='peripheral.yaml'): def __init__(self, rootDir, fileName='peripheral.yaml'):
"""Store the dictionaries from all fileName files in rootDir.""" """Store the dictionaries from all fileName files in rootDir."""
self.rootDir = rootDir self.rootDir = rootDir
...@@ -243,12 +279,14 @@ class PeripheralLibrary: ...@@ -243,12 +279,14 @@ class PeripheralLibrary:
return return_peripheral return return_peripheral
class System(Peripheral):
class System:
""" A System consist of a set of one or more Peripherals.
"""
def __init__(self, filePathName=None): def __init__(self, filePathName=None):
Peripheral.__init__(self, None, 1, None)
self.filePathName = filePathName self.filePathName = filePathName
self.rootDir = os.environ['RADIOHDL'] + "/tools/oneclick/prestudy/YAML" self.rootDir = os.environ['RADIOHDL'] + "/tools/oneclick/prestudy/YAML"
self.peri_lib = PeripheralLibrary( self.rootDir, "peripheral.yaml") self.peri_lib = PeripheralLibrary(self.rootDir, "peripheral.yaml")
self.peripherals = [] self.peripherals = []
if filePathName==None: if filePathName==None:
...@@ -324,16 +362,55 @@ class System(Peripheral): ...@@ -324,16 +362,55 @@ class System(Peripheral):
for param in peripheral.parameters: for param in peripheral.parameters:
print " " + param + " " + str(peripheral.parameters[param]) print " " + param + " " + str(peripheral.parameters[param])
print "" print ""
class SystemParseArgs:
""" Parse command line arguments
"""
def __init__(self):
# Parse command line arguments
argparser = argparse.ArgumentParser(description='System and peripheral config command line parser arguments')
argparser.add_argument('-p','--peripheral', default=None, required=False, help='peripheral names separated by commas')
argparser.add_argument('-s','--system', default=None, required=False, help='system names separated by commas')
argparser.add_argument('-r','--run', required=False, action='store_true', default=False, help='run command')
argparser.add_argument('-v','--verbosity', required=False, type=int, default=0, help='verbosity >= 0 for more info')
args = vars(argparser.parse_args())
# Keep the argparser for external access of e.g. print_help
self.argparser = argparser
# Keep arguments in class record
self.peripheral_names = []
if args['peripheral']!=None:
self.peripheral_names = args['peripheral'].split(',')
self.system_names = []
if args['system']!=None:
self.system_names = args['system'].split(',')
self.run = args['run']
self.verbosity = args['verbosity']
if __name__ == '__main__':
# Mode
# 0 = Read YAML info from one system configuration file
# 1 = Read YAML info from all system and peripheral configuration files in the root directory
mode = 0
# Parse command line arguments
system_args = SystemParseArgs()
# Read the peripheral configuration files from the root in the current directory and the sub directories
#hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools/oneclick/prestudy/YAML'), libFileName='hdllib.cfg', toolFileName=cli_args.toolFileName)
if mode==0:
rootDir = os.path.expandvars('$RADIOHDL/tools/oneclick/prestudy/YAML')
peri_lib = PeripheralLibrary(rootDir, "peripheral.yaml")
system = System(rootDir + "/system.yaml")
system.display_system()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment