lpcmanager

Parents cc9ba2a5840e
Children 2bf67e608136
Revamp product definition to make it simpler and extensible, preparing support for RightBus on MM1.
  • +115 -69
    LPCBus.py
  • --- 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
    import os
    -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()
    -arch = GetLPCArch()
    +modpath = os.path.split(__file__)[0]
    LPCBusSourcePath = os.path.join(modpath,"LPCBus")
    def GetLocalCode(fname):
    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
    -headernames = {
    - "MC9":"MC9",
    - "MW1":"MC9",
    - "GOT":"GOT",
    - "GOT_131":"GOT100",
    - "GOT_111":"GOT100",
    - "LHC2_GOT_111":"LHC2_GOT100",
    - "GOT_012":"MC10",
    - "LHC2_GOT_012":"MC10",
    - "MM1":"MC10"
    +product_descriptions = {
    + "MC8": {
    + "type": "uC",
    + "header": "MC8",
    + "features":[
    + ("Right", "uC_Right"),
    + ("On Board", "uC_OnBoard"),
    + ("Devices", "uC_Devices")]
    + },
    + "MC9": {
    + "type": "SOM",
    + "header": "MC9",
    + "features":[
    + ("Right", "SOM28_Right"),
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "MW1" :{
    + "type": "SOM",
    + "header": "MC9",
    + "features":[
    + ("Right", "SOM28_Right"),
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "GOT" :{
    + "type": "SOM",
    + "header": "GOT",
    + "features":[
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "GOT_131" :{
    + "type": "SOM",
    + "header": "GOT100",
    + "features":[
    + ("Right", "SOM28_Right"),
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "GOT_111" :{
    + "type": "SOM",
    + "header": "GOT100",
    + "features":[
    + ("Right", "SOM28_Right"), #TODO check if True
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "LHC2_GOT_111" :{
    + "type": "SOM",
    + "header": "LHC2_GOT100",
    + "features":[
    + ("Right", "SOM28_Right"), #TODO check if True
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "GOT_012" :{
    + "type": "SOM",
    + "header": "MC10",
    + "features":[
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "LHC2_GOT_012" :{
    + "type": "SOM",
    + "header": "MC10",
    + "features":[
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + },
    + "MM1" :{
    + "type": "SOM",
    + "header": "MC10",
    + # "LDFLAGS": '"' + os.path.join(RightPath, "i2c_smt_lib.a") + '"',
    + "features":[
    + ("Right", "SOM6_Right"),
    + ("On Board", "SOM_OnBoard"),
    + ("Devices", "SOM_Devices")]
    + }
    }
    -
    -bus_template_code = { plc: GetLocalCode(
    - {"MC8": "uC",
    - "MC9": "SOM",
    - "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" }
    -
    -import os
    -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 @@
    "publish_code": "",
    }
    - bus_code = { "%s:%s"%(arch, bus_name) :
    - { section :
    - header + GetLocalCode("%s_%s.c"%(bus_template,section))
    - for section, header in [
    - ("decl",GetLocalCode("%s.h" % headernames[product])),
    - ("init", ""),
    - ("retrieve", ""),
    - ("publish", ""),
    - ("cleanup", "")]}
    - for bus_name, bus_template in Busses[arch]}
    + BusName = self.BaseParams.getName()
    + bus_code = None
    + for bus_name, bus_template in product_desc["features"]:
    + if bus_name == BusName:
    + bus_code = { section :
    + header + GetLocalCode("%s_%s.c"%(bus_template,section))
    + for section, header in [
    + ("decl",GetLocalCode("%s.h" % product_desc["header"])),
    + ("init", ""),
    + ("retrieve", ""),
    + ("publish", ""),
    + ("cleanup", "")]}
    + break
    +
    + if bus_code is None:
    + # Silently ignored, for example MC9 has no Left Bus, but composer always adds one.
    + print("No LPCBus named "+BusName+" for "+product)
    + return [], "", False
    for module in GetModuleChildren(self):
    if module["init"] != "":
    @@ -291,35 +348,24 @@
    if var["Publish"] != "":
    code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n"
    - BusName = arch + ":" + self.BaseParams.getName()
    -
    -
    - def bcode(section):
    - return bus_code.get(BusName,{"decl":"",
    - "init":"%(init_code)s",
    - "retrieve":"%(retrieve_code)s",
    - "publish":"%(publish_code)s",
    - "cleanup":"",
    - })[section] % code_str
    + def bcode(section, default):
    + return bus_code.get(section, default) % code_str
    code_str.update({
    - "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)
    module.close()
    cflags = '"-I%s" "-I%s" -Wno-unused-function'%(
    os.path.abspath(self.GetCTRoot().GetIECLibPath()), # is it still necessary ?
    LPCBusSourcePath
    )
    - return [(Gen_Module_path, cflags)], LPCBusLDFLAGS.get(BusName, ""), True
    + return [(Gen_Module_path, cflags)], product_desc.get("LDFLAGS", ""), True