Skip to content

Commit ae39f79

Browse files
committed
Primarily added documentation
1 parent 4351a9a commit ae39f79

23 files changed

+375
-263
lines changed

autogen.m

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
%% Execute the Autogen process
2+
3+
modelName = bdroot;
4+
15
% Kill existing compile
2-
if bdroot ~= "" && strcmp(get_param(bdroot,'SimulationStatus'), 'stopped') == 0
6+
if modelName ~= "" && strcmp(get_param(modelName,'SimulationStatus'), 'stopped') == 0
37
set_param(gcs, 'SimulationCommand', 'stop')
4-
cmd = [bdroot,'([],[],[],''term'');'];
8+
cmd = [modelName,'([],[],[],''term'');'];
59
try
610
eval(cmd)
711
catch
812
end
913
end
14+
15+
% If workspace has been cleared, attempts to run sm_run_me_first to initialize mp
1016
if exist('mp','var') == 0
1117
sm_run_me_first;
12-
%pause(3)
1318
end
14-
cmd = [bdroot,'([],[],[],''compile'');'];
15-
try
16-
eval(cmd)
17-
catch
18-
end
19-
%end
20-
pause(5)
21-
get_param(bdroot,'SimulationStatus')
19+
% Attempts to compile the model
20+
cmd = [modelName,'([],[],[],''compile'');'];
21+
22+
eval(cmd)
23+
24+
% Run through rest of Autogen process
2225
vgen_process_simulink_model

autogen_quartus.py

+34-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,46 @@
66
from quartus.workflow import execute_quartus_workflow
77

88

9-
def main(inputFilename, working_dir, log_to_file=False):
9+
def main(config_filepath, working_dir, log_to_file=False):
10+
"""Execute the Quartus workflow using the config file given, in the given working directory.
11+
12+
Parameters
13+
----------
14+
config_filepath : str
15+
Path to config file
16+
working_dir : str
17+
Path to working directory for Quartus workflow
18+
log_to_file : bool, optional
19+
If true logs to a file in addition to stdout, by default False
20+
"""
1021
if not(working_dir.endswith("/")):
1122
working_dir += "/"
1223
logger = init_logging(logging.INFO, log_to_file)
1324
try:
14-
config = WorkflowConfig.parse_json(inputFilename)
25+
config = WorkflowConfig.parse_json(config_filepath)
1526
execute_quartus_workflow(
1627
config.target_system, config.custom_components, config.clock_rate, working_dir)
1728
finally:
29+
# Is logged to tell anything reading the log that the workflow is over.
30+
# Is used by Matlab side when streaming the log to the Matlab command window
1831
logger.info("exit")
1932

2033

2134
def init_logging(debugLevel, log_to_file=False):
35+
"""Initialize quartus module logging to given debug level and whether to also log to a file.
36+
37+
Parameters
38+
----------
39+
debugLevel : int
40+
The level required to trigger logging, where higher levels only show things like errors
41+
log_to_file : bool, optional
42+
If true logs to a file in addition to stdout, by default False
43+
44+
Returns
45+
-------
46+
Logger
47+
Returns a Logger object with the given configuration
48+
"""
2249
logger = logging.getLogger('autogen_quartus')
2350

2451
if log_to_file:
@@ -40,17 +67,17 @@ def parseargs():
4067
"""Parse commandline input arguments."""
4168
parser = argparse.ArgumentParser(
4269
description="Executes the quartus workflow, from creating a system to compiling the project made around that system")
43-
parser.add_argument('-j', '--json',
44-
help="JSON file containing autogen configuration")
70+
parser.add_argument('-c', '--config',
71+
help="Config file containing autogen configuration in JSON format")
4572
parser.add_argument('-w', '--working-dir',
4673
help="Working directory to execute the quartus workflow in")
4774
parser.add_argument('-l', '--logging', required=False, action="store_true",
4875
help="Enable logging to autogen_quartus.log")
4976
args = parser.parse_args()
50-
return (args.json, args.working_dir, args.logging)
77+
return (args.config, args.working_dir, args.logging)
5178

5279

5380
if __name__ == "__main__":
54-
(json_filename, working_dir, log_to_file) = parseargs()
81+
(config_filepath, working_dir, log_to_file) = parseargs()
5582

56-
main(json_filename, working_dir, log_to_file)
83+
main(config_filepath, working_dir, log_to_file)

device_drivers/AvalonJsonParser.py

-30
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
11
from InputStructureFile import InputStructure
22
import json
3-
def AvalonJsonParse(jsonFileName):
4-
file = open(jsonFileName, "r")
5-
fileStr = file.read()
6-
jsonDict = json.loads(fileStr)
7-
inputStruct = InputStructure()
83

9-
inputStruct.deviceName = jsonDict['linux_device_name']
10-
inputStruct.deviceType = 2
11-
inputStruct.deviceNameAbbrev = jsonDict['model_abbreviation']
12-
inputStruct.compatibleFlag = 'dev,fe-' + inputStruct.deviceName
13-
attributes = jsonDict['avalon_memorymapped']['register']
14-
inputStruct.deviceAttributes = []
15-
inputStruct.attributePerms = []
16-
inputStruct.attributeWriteIsNormal = []
17-
inputStruct.attributeReadIsNormal = []
18-
inputStruct.attributeWriteOffsets = []
19-
inputStruct.attributeDataTypes = []
20-
inputStruct.attributeDataTypeSigned = []
21-
inputStruct.attributeDataTypeWidth = []
22-
inputStruct.attributeDataTypeFraction = []
23-
for attr in attributes:
24-
inputStruct.deviceAttributes.append(attr['name'])
25-
inputStruct.attributeDataTypes.append(attr['data_type'])
26-
inputStruct.attributeDataTypeSigned.append(attr['data_type']['signed'])
27-
inputStruct.attributeDataTypeWidth.append(attr['data_type']['width'])
28-
inputStruct.attributeDataTypeFraction.append(attr['data_type']['fractional_bits'])
29-
inputStruct.attributePerms.append('0664')
30-
inputStruct.attributeWriteIsNormal.append(True)
31-
inputStruct.attributeReadIsNormal.append(True)
32-
inputStruct.attributeWriteOffsets.append([str(attr['reg_num'])])
33-
return inputStruct

device_drivers/CreateCFunctionStubs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def CreateCFunctionStubs(inputParams):
2-
devName = inputParams.deviceName
2+
devName = inputParams.device_name
33
functionString = "/*****************************************\n"
44
functionString += " Generated by CreateCFunctionStubs\n"
55
functionString += "*****************************************/\n"

device_drivers/CreateCustomFunctions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def CreateCustomFunctions(inputParams):
55
if inputParams.needsVolumeTable:
66
file = open("FindVolumeLevelTable", "r")
77
functionString += file.read()
8-
elif inputParams.deviceType != 2: #FPGAS don't need find_volume?
8+
elif inputParams.device_type != 2: #FPGAS don't need find_volume?
99
file = open("FindVolumeLevelNoTable", "r")
1010
functionString += file.read()
1111
functionString += "/* End CreateCustomFunctions */\n\n\n"

device_drivers/CreateDeviceAttrMacros.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ def WriteDeviceAttributes(inputParams):
22
functionString = "/*************************************************\n"
33
functionString += "Generated in WriteDeviceAttributes\n"
44
functionString += "*************************************************/\n"
5-
for i in range(len(inputParams.deviceAttributes)):
6-
functionString += ("DEVICE_ATTR(" + inputParams.deviceAttributes[i] + ", " + inputParams.attributePerms[i]
7-
+ ", " + inputParams.deviceAttributes[i] + "_read, " + inputParams.deviceAttributes[i]
5+
for attr in inputParams.device_attributes:
6+
functionString += ("DEVICE_ATTR(" + attr.name + ", " + attr.permissions
7+
+ ", " + attr.name + "_read, " + attr.name
88
+ "_write);\n")
99
functionString += "DEVICE_ATTR(name, 0444, name_read, NULL);\n"
1010
functionString += "/* End WriteDeviceAttributes */\n\n\n"

device_drivers/CreateDriverStuff.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ def CreateDriverStuff(inputParams):
22
functionString = "/****************************************************\n"
33
functionString += "Generated in CreateDriverStuff\n"
44
functionString += "****************************************************/\n"
5-
devName = inputParams.deviceName
5+
devName = inputParams.device_name
66
functionString += CreateDevStruct(inputParams)
77
functionString += "typedef struct fe_" + devName + "_dev fe_" + devName + "_dev_t;\n"
88
functionString += CreateIDMatchingStruct(inputParams)
9-
if inputParams.deviceType == 1: # if I2C device it needs the next thing
9+
if inputParams.device_type == 1: # if I2C device it needs the next thing
1010
functionString += CreateI2CDriverStructs(inputParams)
1111
functionString += "MODULE_DEVICE_TABLE(of, fe_" + devName + "_dt_ids);\n"
1212
functionString += CreatePlatformDriverStruct(inputParams)
@@ -17,25 +17,25 @@ def CreateDriverStuff(inputParams):
1717

1818
def CreateDevStruct(inputParams):
1919
functionString = "\n/* Device struct */\n"
20-
functionString += "struct fe_" + inputParams.deviceName + "_dev {\n"
20+
functionString += "struct fe_" + inputParams.device_name + "_dev {\n"
2121
functionString += " struct cdev cdev;\n"
2222
functionString += " char *name;\n"
2323
functionString += " void __iomem *regs;\n"
24-
for i in range(len(inputParams.deviceAttributes)):
24+
for attr in inputParams.device_attributes:
2525
try: # try to get the type of the attribute from input params, otherwise just assume its int;
26-
functionString += " " + inputParams.attributeType[i]
26+
functionString += " " + attr.data_type.name
2727
except:
2828
functionString += " int"
29-
functionString += " " + inputParams.deviceAttributes[i] + ";\n"
29+
functionString += " " + inputParams.device_attributes.name + ";\n"
3030
functionString += "};\n\n"
3131
return functionString
3232

3333

3434
def CreateIDMatchingStruct(inputParams):
3535
functionString = "/* ID Matching struct */\n"
36-
functionString += "static struct of_device_id fe_" + inputParams.deviceName + "_dt_ids[] = {\n"
36+
functionString += "static struct of_device_id fe_" + inputParams.device_name + "_dt_ids[] = {\n"
3737
functionString += " {\n"
38-
functionString += " .compatible = \"" + inputParams.compatibleFlag + "\"\n"
38+
functionString += " .compatible = \"" + inputParams.compatible_flag + "\"\n"
3939
functionString += " },\n"
4040
functionString += " { }\n"
4141
functionString += "};\n\n"
@@ -44,41 +44,41 @@ def CreateIDMatchingStruct(inputParams):
4444

4545
def CreatePlatformDriverStruct(inputParams):
4646
functionString = "/* Platform driver struct */\n"
47-
functionString += "static struct platform_driver " + inputParams.deviceName + "_platform = {\n"
48-
functionString += " .probe = " + inputParams.deviceName + "_probe,\n"
49-
functionString += " .remove = " + inputParams.deviceName + "_remove,\n"
47+
functionString += "static struct platform_driver " + inputParams.device_name + "_platform = {\n"
48+
functionString += " .probe = " + inputParams.device_name + "_probe,\n"
49+
functionString += " .remove = " + inputParams.device_name + "_remove,\n"
5050
functionString += " .driver = {\n"
51-
functionString += " .name = \"Flat Earth " + inputParams.deviceName + " Driver\",\n"
51+
functionString += " .name = \"Flat Earth " + inputParams.device_name + " Driver\",\n"
5252
functionString += " .owner = THIS_MODULE,\n"
53-
functionString += " .of_match_table = fe_" + inputParams.deviceName + "_dt_ids\n"
53+
functionString += " .of_match_table = fe_" + inputParams.device_name + "_dt_ids\n"
5454
functionString += " }\n"
5555
functionString += "};\n\n"
5656
return functionString
5757

5858

5959
def CreateFileOpsStruct(inputParams):
6060
functionString = "/* File ops struct */\n"
61-
functionString += "static const struct file_operations fe_" + inputParams.deviceName + "_fops = {\n"
61+
functionString += "static const struct file_operations fe_" + inputParams.device_name + "_fops = {\n"
6262
functionString += " .owner = THIS_MODULE,\n"
63-
functionString += " .read = " + inputParams.deviceName + "_read,\n"
64-
functionString += " .write = " + inputParams.deviceName + "_write,\n"
65-
functionString += " .open = " + inputParams.deviceName + "_open,\n"
66-
functionString += " .release = " + inputParams.deviceName + "_release,\n"
63+
functionString += " .read = " + inputParams.device_name + "_read,\n"
64+
functionString += " .write = " + inputParams.device_name + "_write,\n"
65+
functionString += " .open = " + inputParams.device_name + "_open,\n"
66+
functionString += " .release = " + inputParams.device_name + "_release,\n"
6767
functionString += "};\n\n"
6868
return functionString
6969

7070

7171
def CreateI2CDriverStructs(inputParams):
72-
devNameAbbrev = inputParams.deviceNameAbbrev
72+
devNameAbbrev = inputParams.device_name_abbrev
7373
functionString = "/* I2C Driver stuff */\n"
7474
functionString += "static struct i2c_device_id " + devNameAbbrev + "_id[] = {\n"
7575
functionString += " {\n"
76-
functionString += " \"" + devNameAbbrev + "_i2c\"," + inputParams.deviceID + "\n"
76+
functionString += " \"" + devNameAbbrev + "_i2c\"," + inputParams.device_i2c_address + "\n"
7777
functionString += " },\n"
7878
functionString += " { }\n"
7979
functionString += "};\n\n"
8080
functionString += "static struct i2c_board_info " + devNameAbbrev + "_i2c_info = {\n"
81-
functionString += " I2C_BOARD_INFO(\"" + devNameAbbrev + "_i2c\"," + inputParams.deviceID + "),\n"
81+
functionString += " I2C_BOARD_INFO(\"" + devNameAbbrev + "_i2c\"," + inputParams.device_i2c_address + "),\n"
8282
functionString += "};\n\n"
8383
functionString += "static int " + devNameAbbrev + "_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {\n"
8484
functionString += " return 0;\n"

device_drivers/CreateEndOfFileStuff.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def CreateEndOfFileStuff(inputParams):
22
functionString = "/********************************************\n"
33
functionString += "Generated by CreateEndOfFileStuff\n"
44
functionString += "********************************************/\n"
5-
functionString += "module_init(" + inputParams.deviceName + "_init);\n"
6-
functionString += "module_exit(" + inputParams.deviceName + "_exit);\n"
5+
functionString += "module_init(" + inputParams.device_name + "_init);\n"
6+
functionString += "module_exit(" + inputParams.device_name + "_exit);\n"
77
functionString += "/* End CreateEndOfFileStuff */\n"
88
return functionString

device_drivers/CreateExitFunction.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ def CreateExitFunction(inputParams):
22
functionString = "/***********************************************\n"
33
functionString += "Generated by CreateExitFunction\n"
44
functionString += "************************************************/\n"
5-
functionString += "static void " + inputParams.deviceName + "_exit(void) {\n"
6-
functionString += " pr_info(\"Flat Earth " + inputParams.deviceName + " module exit\\n\");\n"
7-
functionString += " platform_driver_unregister(&" + inputParams.deviceName + "_platform);\n"
8-
if inputParams.deviceType == 0: # SPI device
5+
functionString += "static void " + inputParams.device_name + "_exit(void) {\n"
6+
functionString += " pr_info(\"Flat Earth " + inputParams.device_name + " module exit\\n\");\n"
7+
functionString += " platform_driver_unregister(&" + inputParams.device_name + "_platform);\n"
8+
if inputParams.device_type == 0: # SPI device
99
functionString += " if (spi_device) {\n"
1010
functionString += " spi_unregister_device(spi_device);\n"
1111
functionString += " }\n"
12-
functionString += " pr_info(\"Flat Earth " + inputParams.deviceName + " module successfully unregistered\\n\");\n"
12+
functionString += " pr_info(\"Flat Earth " + inputParams.device_name + " module successfully unregistered\\n\");\n"
1313
functionString += "}\n"
1414
functionString += "/* End CreateExitFunction */\n\n\n"
1515
return functionString

device_drivers/CreateFileHeaderInfo.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ def CreateFileHeaderInfo(inputParams):
1111
functionString += "#include <linux/init.h>\n"
1212
functionString += "#include <linux/cdev.h>\n"
1313
functionString += "#include <linux/regmap.h>\n"
14-
if inputParams.deviceType == 0: # SPI Device, fpga needs struct of_device_id from here
14+
if inputParams.device_type == 0: # SPI Device, fpga needs struct of_device_id from here
1515
functionString += "#include <linux/spi/spi.h>\n"
16-
elif inputParams.deviceType == 1: # I2C Device
16+
elif inputParams.device_type == 1: # I2C Device
1717
functionString += "#include <linux/i2c.h>\n"
18-
elif inputParams.deviceType == 2:
18+
elif inputParams.device_type == 2:
1919
functionString += "#include <linux/of.h>\n"
2020
functionString += "#include \"custom_functions.h\"\n"
2121
functionString += "\nMODULE_LICENSE(\"GPL\");\n"
2222
functionString += "MODULE_AUTHOR(\"Tyler Davis <[email protected]\");\n"
23-
functionString += "MODULE_DESCRIPTION(\"Loadable kernel module for the " + inputParams.deviceName + "\");\n"
23+
functionString += "MODULE_DESCRIPTION(\"Loadable kernel module for the " + inputParams.device_name + "\");\n"
2424
functionString += "MODULE_VERSION(\"1.0\");\n"
2525
functionString += "/* End CreateFileHeaderInfo */\n\n\n"
2626
return functionString

0 commit comments

Comments
 (0)