lpcmanager

Parents cc9ba2a5840e
Children
WIP, facing growing complexity, park RightBus as a library approach in favor of kernel module as it was already
--- 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
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")
+RightPath = paths.ThirdPartyPath("RightBus")
+
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 +286,22 @@
"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()
+ 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
+
+ assert(bus_code is not None)
+
+ print(bus_code)
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
--- /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 @@
+i2c_smt_cleanup();
+
--- /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 "beremiz.h"
+#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)
+{
+ pthread_exit(NULL);
+}
+
+void bus_update_loop(void *arg);
+void RightBus_thread_proc(void *arg)
+{
+ bus_update_loop(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");
+
+if(!rightbus_handle)
+ return 1;
+
+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);
+if (ret) {
+ _LogError("create pthread failed\n");
+ return ret;
+}
+
+
+#define rightI2CMod (rightBusInit.rightI2CMod)
+%(init_code)s
+
+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())
+{
+ %(publish_code)s
+ 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())
+{
+ %(retrieve_code)s
+ 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)
return res