--- a/targets/Linux/plc_Linux_main.c Mon Sep 21 11:56:55 2009 +0200
+++ b/targets/Linux/plc_Linux_main.c Mon Sep 21 12:00:52 2009 +0200
@@ -64,7 +64,7 @@
-static int __debug_tick;
+static unsigned long __debug_tick; static pthread_mutex_t python_wait_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t python_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -75,8 +75,8 @@
int startPLC(int argc,char **argv)
- /* Translate PLC's microseconds to Ttick nanoseconds */
- Ttick = 1000000 * maxval(common_ticktime__,1);
+ /* Define Ttick to 1ms if common_ticktime not defined */ + Ttick = common_ticktime__?common_ticktime__:1000000; memset (&sigev, 0, sizeof (struct sigevent));
sigev.sigev_value.sival_int = 0;
@@ -97,6 +97,8 @@
/* install signal handler for manual break */
// signal(SIGTERM, catch_signal);
signal(SIGINT, catch_signal);
+ pthread_mutex_trylock(&debug_mutex); @@ -120,6 +122,7 @@
timer_delete (PLC_timer);
+ pthread_mutex_unlock(&debug_mutex); pthread_mutex_unlock(&debug_wait_mutex);
pthread_mutex_destroy(&debug_wait_mutex);
pthread_mutex_unlock(&python_wait_mutex);
@@ -127,9 +130,9 @@
+extern unsigned long __tick; /* from plc_debugger.c */
+unsigned long WaitDebugData() /* Wait signal from PLC thread */
if(pthread_mutex_lock(&debug_wait_mutex)) return -1;
--- a/targets/Win32/plc_Win32_main.c Mon Sep 21 11:56:55 2009 +0200
+++ b/targets/Win32/plc_Win32_main.c Mon Sep 21 12:00:52 2009 +0200
@@ -8,7 +8,7 @@
-extern int common_ticktime__;
+extern unsigned long common_ticktime__; long AtomicCompareExchange(long* atomicvar, long compared, long exchange)
@@ -74,8 +74,8 @@
int startPLC(int argc,char **argv)
unsigned long thread_id = 0;
- /* Translate PLC's microseconds to Ttick nanoseconds */
- Ttick = 1000000 * maxval(common_ticktime__,1);
+ /* Define Ttick to 1ms if common_ticktime not defined */ + Ttick = common_ticktime__?common_ticktime__:1000000; debug_sem = CreateSemaphore(
NULL, // default security attributes
@@ -142,7 +142,7 @@
-static int __debug_tick;
+static unsigned long __debug_tick; int TryEnterDebugSection(void)
@@ -170,7 +170,7 @@
/* from plc_debugger.c */
+unsigned long WaitDebugData() if(WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0) return -1;
--- a/targets/Xenomai/plc_Xenomai_main.c Mon Sep 21 11:56:55 2009 +0200
+++ b/targets/Xenomai/plc_Xenomai_main.c Mon Sep 21 12:00:52 2009 +0200
@@ -29,7 +29,7 @@
#define WAITDEBUG_PIPE_SIZE 500
-extern int common_ticktime__;
+extern unsigned long common_ticktime__; long AtomicCompareExchange(long* atomicvar,long compared, long exchange)
@@ -72,7 +72,7 @@
-static int __debug_tick;
+static unsigned long __debug_tick; @@ -142,8 +142,8 @@
/* ne-memory-swapping for this program */
mlockall(MCL_CURRENT | MCL_FUTURE);
- /* Translate PLC's microseconds to Ttick nanoseconds */
- Ttick = 1000000 * max_val(common_ticktime__,1);
+ /* Define Ttick to 1ms if common_ticktime not defined */ + Ttick = common_ticktime__?common_ticktime__:1000000; /* create python_wait_sem */
ret = rt_sem_create(&python_wait_sem, "python_wait_sem", 0, S_FIFO);
@@ -203,9 +203,9 @@
rt_mutex_release(&debug_mutex);
+extern unsigned long __tick; /* from plc_debugger.c */
+unsigned long WaitDebugData() --- a/targets/plc_common_main.c Mon Sep 21 11:56:55 2009 +0200
+++ b/targets/plc_common_main.c Mon Sep 21 12:00:52 2009 +0200
@@ -5,13 +5,13 @@
- * Prototypes of functions provied by generated C softPLC
+ * Prototypes of functions provided by generated C softPLC -void config_run__(int tick);
+void config_run__(unsigned long tick); void config_init__(void);
- * Prototypes of functions provied by generated target C code
+ * Prototypes of functions provided by generated target C code void __cleanup_debug(void);
@@ -22,8 +22,13 @@
* Variables used by generated C softPLC and plugins
+unsigned long __tick = -1; + * Variable generated by C softPLC and plugins +extern unsigned long greatest_tick_count__; /* Help to quit cleanly when init fail at a certain level */
static int init_level = 0;
@@ -39,6 +44,8 @@
+ if (greatest_tick_count__) + __tick %%= greatest_tick_count__; @@ -53,7 +60,7 @@
- * Initialize variables according to PLC's defalut values,
+ * Initialize variables according to PLC's default values, * and then init plugins with that values
int __init(int argc,char **argv)
@@ -85,7 +92,7 @@
static long long Tsync = 0;
static long long FreqCorr = 0;
-static int last_tick = 0;
+static unsigned long last_tick = 0; static long long Ttick = 0;
--- a/targets/plc_debug.c Mon Sep 21 11:56:55 2009 +0200
+++ b/targets/plc_debug.c Mon Sep 21 12:00:52 2009 +0200
@@ -70,7 +70,7 @@
extern long AtomicCompareExchange(long*, long, long);
extern void InitiateDebugTransfer(void);
+extern unsigned long __tick; /* Check there is no running debugger re-configuration */