--- a/LPCBus.py Mon Feb 27 12:12:18 2023 +0100
+++ b/LPCBus.py Wed May 17 11:01:54 2023 +0200
@@ -1,54 +1,103 @@
from __future__ import absolute_import
-modpath = os.path.split(__file__)[0]
+from LPCArch import GetLPCArch, GetLPCProduct, SOM28_modules +import util.paths as paths -from LPCArch import GetLPCArch, GetLPCProduct, SOM28_modules
+from plcopen.structures import LOCATIONDATATYPES +from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP,\ + LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY product = GetLPCProduct()
+modpath = os.path.split(__file__)[0] LPCBusSourcePath = os.path.join(modpath,"LPCBus")
return open(os.path.join(LPCBusSourcePath,fname)).read()
-# busses available per architecture
-Busses = {"MC8" :[ ("Right", "uC_Right"),
- ("On Board", "uC_OnBoard"),
- ("Devices", "uC_Devices")],
- "MC9" :[ ("Right", "SOM28_Right"),
- ("On Board", "SOM_OnBoard"),
- ("Devices", "SOM_Devices")],
- "MC10" :[("On Board", "SOM_OnBoard"),
- ("Devices", "SOM_Devices")]}
-# This matches names of .h files in LPCBus with product from LPCArch
- "LHC2_GOT_111":"LHC2_GOT100",
+product_descriptions = { + ("On Board", "uC_OnBoard"), + ("Devices", "uC_Devices")] + ("Right", "SOM28_Right"), + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + ("Right", "SOM28_Right"), + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + ("Right", "SOM28_Right"), + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + ("Right", "SOM28_Right"), #TODO check if True + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + "header": "LHC2_GOT100", + ("Right", "SOM28_Right"), #TODO check if True + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")] + # "LDFLAGS": '"' + os.path.join(RightPath, "i2c_smt_lib.a") + '"', + ("Right", "SOM6_Right"), + ("On Board", "SOM_OnBoard"), + ("Devices", "SOM_Devices")]
-bus_template_code = { plc: GetLocalCode(
- "MC10": "SOM"}[plc]+".c") for plc in Busses.keys()}
-# This is in case some bus has some special LDFLAGS
-LPCBusLDFLAGS = {} # ex: { "MC9:On Board" : "-lonboard" }
-from plcopen.structures import LOCATIONDATATYPES
-from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP,\
- LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
+product_desc = product_descriptions[product] LOCATION_TYPES = {"I": LOCATION_VAR_INPUT,
"Q": LOCATION_VAR_OUTPUT,
"M": LOCATION_VAR_MEMORY}
@@ -235,16 +284,24 @@
- bus_code = { "%s:%s"%(arch, bus_name) :
- header + GetLocalCode("%s_%s.c"%(bus_template,section))
- for section, header in [
- ("decl",GetLocalCode("%s.h" % headernames[product])),
- for bus_name, bus_template in Busses[arch]}
+ BusName = self.BaseParams.getName() + for bus_name, bus_template in product_desc["features"]: + if bus_name == BusName: + header + GetLocalCode("%s_%s.c"%(bus_template,section)) + for section, header in [ + ("decl",GetLocalCode("%s.h" % product_desc["header"])), + # Silently ignored, for example MC9 has no Left Bus, but composer always adds one. + print("No LPCBus named "+BusName+" for "+product) for module in GetModuleChildren(self):
@@ -291,35 +348,24 @@
code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n"
- BusName = arch + ":" + self.BaseParams.getName()
- return bus_code.get(BusName,{"decl":"",
- "init":"%(init_code)s",
- "retrieve":"%(retrieve_code)s",
- "publish":"%(publish_code)s",
+ def bcode(section, default): + return bus_code.get(section, default) % code_str - "bus_decl":bcode("decl"),
- "bus_init_code": bcode("init"),
- "bus_cleanup_code": bcode("cleanup"),
- "bus_retrieve_code": bcode("retrieve"),
- "bus_publish_code": bcode("publish"),
+ "bus_decl": bcode("decl", ""), + "bus_init_code": bcode("init", "%(init_code)s"), + "bus_cleanup_code": bcode("cleanup", ""), + "bus_retrieve_code": bcode("retrieve", "%(retrieve_code)s"), + "bus_publish_code": bcode("publish", "%(publish_code)s"), - if arch not in bus_template_code:
- raise Exception, "Unknown product %s. Please use %s"%(
- arch,repr(bus_template_code.keys()))
Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
module = open(Gen_Module_path,'w')
- module.write(bus_template_code[arch] % code_str)
+ module.write(GetLocalCode(product_desc["type"]+".c") % code_str) cflags = '"-I%s" "-I%s" -Wno-unused-function'%(
os.path.abspath(self.GetCTRoot().GetIECLibPath()), # is it still necessary ?
- return [(Gen_Module_path, cflags)], LPCBusLDFLAGS.get(BusName, ""), True
+ return [(Gen_Module_path, cflags)], product_desc.get("LDFLAGS", ""), True