--- a/LPCBus.py Mon Feb 27 12:12:18 2023 +0100
+++ b/LPCBus.py Thu May 11 11:24:13 2023 +0200
@@ -1,54 +1,105 @@
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")
+RightPath = paths.ThirdPartyPath("RightBus") 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 +286,22 @@
- 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"])), + assert(bus_code is not None) 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 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM6_Right_cleanup.c Thu May 11 11:24:13 2023 +0200
@@ -0,0 +1,2 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM6_Right_decl.c Thu May 11 11:24:13 2023 +0200
@@ -0,0 +1,37 @@
+#include "i2c_smt_lib.h" +static void *rightbus_handle; +static pthread_t RightBus_thread; +static readBuf_t *rightReadBuf_p; +static writeBuf_t *rightWriteBuf_p; +static busInit_t rightBusInit; +int wait_rightbus_task_wakeup(){ + return wait_RT_to_nRT_signal(rightbus_handle); +int rightbus_task_wakeup(){ + return unblock_RT_to_nRT_signal(rightbus_handle); +void rightbus_task_kill(){ + /* Order RightBusThread to exit */ + pthread_kill(RightBus_thread, SIGUSR2); + pthread_join(RightBus_thread, NULL); +void RightBusThreadSignalHandler(int sig) +void bus_update_loop(void *arg); +void RightBus_thread_proc(void *arg) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM6_Right_init.c Thu May 11 11:24:13 2023 +0200
@@ -0,0 +1,28 @@
+#define DEVICEFILENAME "/dev/i2c-1" +rightbus_handle = create_RT_to_nRT_signal("RightBus"); +bzero(&rightReadBuf, sizeof(readBuf_t)); +bzero(&rightWriteBuf, sizeof(writeBuf_t)); +bzero(&rightBusInit, sizeof(busInit_t)); +rightBusInit.common_ticktime__ = common_ticktime__; +/* Signal to end RightBus thread */ +signal(SIGUSR2, RightBusThreadSignalHandler); +ret = pthread_create(&RightBus_thread, pattr, (void*) &RightBus_thread_proc, NULL); + _LogError("create pthread failed\n"); +#define rightI2CMod (rightBusInit.rightI2CMod) +return i2c_smt_init(&rightBusInit); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM6_Right_publish.c Thu May 11 11:24:13 2023 +0200
@@ -0,0 +1,6 @@
+#define rightWriteBuf (*rightWriteBuf_p) +if(rightWriteBuf_p = i2c_smt_publish_buf_take()) + i2c_smt_publish_buf_put(); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBus/SOM6_Right_retrieve.c Thu May 11 11:24:13 2023 +0200
@@ -0,0 +1,6 @@
+#define rightReadBuf (*rightReadBuf_p) +if(rightReadBuf_p = i2c_smt_retrieve_buf_take()) + i2c_smt_retrieve_buf_put(); --- a/LPCExtension.py Mon Feb 27 12:12:18 2023 +0100
+++ b/LPCExtension.py Thu May 11 11:24:13 2023 +0200
@@ -137,7 +137,7 @@
old_ThirdPartyPath = paths.ThirdPartyPath
def ThirdPartyPath(name):
res = old_ThirdPartyPath(name)
- if name in ["BACnet", "Modbus", "CanFestival-3"]:
+ if name in ["BACnet", "Modbus", "CanFestival-3", "Right"]: res = os.path.join(res, arch)