--- a/targets/Linux/XSD Tue Feb 21 11:38:45 2023 +0100
+++ b/targets/Linux/XSD Tue Feb 21 11:47:11 2023 +0100
@@ -1,6 +1,7 @@
<xsd:element name="Linux">
+ <xsd:attribute name="RealTime" type="xsd:boolean" use="optional" default="false"/>
\ No newline at end of file
--- a/targets/Linux/__init__.py Tue Feb 21 11:38:45 2023 +0100
+++ b/targets/Linux/__init__.py Tue Feb 21 11:47:11 2023 +0100
@@ -32,7 +32,11 @@
def getBuilderCFLAGS(self):
- return toolchain_gcc.getBuilderCFLAGS(self) + ["-fPIC"]
+ additional_cflags = ["-fPIC"] + build_for_realtime = self.CTRInstance.GetTarget().getcontent().getRealTime() + additional_cflags.append("-DREALTIME_LINUX") + return toolchain_gcc.getBuilderCFLAGS(self) + additional_cflags def getBuilderLDFLAGS(self):
return toolchain_gcc.getBuilderLDFLAGS(self) + ["-shared", "-lrt"]
--- a/targets/Linux/plc_Linux_main.c Tue Feb 21 11:38:45 2023 +0100
+++ b/targets/Linux/plc_Linux_main.c Tue Feb 21 11:47:11 2023 +0100
@@ -11,6 +11,9 @@
static unsigned long __debug_tick;
@@ -105,10 +108,60 @@
+#define _LogError(text,...) \ + snprintf(mstr, 255, text, ##__VA_ARGS__);\ + LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\ #define maxval(a,b) ((a>b)?a:b)
int startPLC(int argc,char **argv)
+ pthread_attr_t *pattr = NULL; + struct sched_param param; + ret = mlockall(MCL_CURRENT|MCL_FUTURE); + _LogError("mlockall failed: %m\n"); + /* Initialize pthread attributes (default values) */ + ret = pthread_attr_init(&attr); + _LogError("init pthread attributes failed\n"); + /* Set scheduler policy and priority of pthread */ + ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO); + _LogError("pthread setschedpolicy failed\n"); + param.sched_priority = PLC_THREAD_PRIORITY; + ret = pthread_attr_setschedparam(&attr, ¶m); + _LogError("pthread setschedparam failed\n"); + /* Use scheduling parameters of attr */ + ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + _LogError("pthread setinheritsched failed\n"); pthread_mutex_init(&debug_wait_mutex, NULL);
@@ -119,7 +172,7 @@
pthread_mutex_lock(&debug_wait_mutex);
pthread_mutex_lock(&python_wait_mutex);
- if( __init(argc,argv) == 0 ){
+ if((ret = __init(argc,argv)) == 0 ){ /* Signal to wakeup PLC thread when period changes */
signal(SIGUSR1, PLCThreadSignalHandler);
@@ -132,9 +185,13 @@
period_ns = common_ticktime__;
clock_gettime(CLOCK_MONOTONIC, &next_abs_time);
- pthread_create(&PLC_thread, NULL, (void*) &PLC_thread_proc, NULL);
+ ret = pthread_create(&PLC_thread, pattr, (void*) &PLC_thread_proc, NULL); + _LogError("create pthread failed\n");
--- a/targets/beremiz.h Tue Feb 21 11:38:45 2023 +0100
+++ b/targets/beremiz.h Tue Feb 21 11:47:11 2023 +0100
@@ -32,4 +32,13 @@
int unblock_RT_to_nRT_signal(void* handle);
void nRT_reschedule(void);
+#ifndef PLC_THREAD_PRIORITY +#define PLC_THREAD_PRIORITY 80