Simplified use of runtime's global variable __common_ticktime accross extensions.
authorEdouard Tisserant
Fri, 12 Dec 2014 14:41:53 +0100
changeset 1428 e14003eb4d42
parent 1423 4e33f644f7cf
child 1429 7e00c406d346
Simplified use of runtime's global variable __common_ticktime accross extensions.
canfestival/cf_runtime.c
targets/Linux/plc_Linux_main.c
targets/Win32/plc_Win32_main.c
targets/Xenomai/plc_Xenomai_main.c
targets/plc_main_head.c
targets/plc_main_tail.c
--- a/canfestival/cf_runtime.c	Fri Jun 27 13:56:49 2014 +0200
+++ b/canfestival/cf_runtime.c	Fri Dec 12 14:41:53 2014 +0100
@@ -14,7 +14,7 @@
 /* Keep track of init level to cleanup correctly */
 static int init_level=0;
 /* Retrieve PLC cycle time */
-extern int common_ticktime__;
+extern unsigned long long common_ticktime__;
 
 /* Per master node slavebootup callbacks. Checks that
  * every node have booted before calling Master_post_SlaveBootup */
@@ -34,7 +34,7 @@
     nodename##_Data.CurrentCommunicationState.csSYNC = -1;\
     /* Force sync period to common_ticktime__ so that other node can read it*/\
     *nodename##_Data.COB_ID_Sync = 0x40000080;\
-    *nodename##_Data.Sync_Cycle_Period = common_ticktime__ * 1000;
+    *nodename##_Data.Sync_Cycle_Period = common_ticktime__ / 1000;
 
 static void DeferedInitAlarm(CO_Data* d, UNS32 id){
     /* Node will start beeing active on the network after this */
--- a/targets/Linux/plc_Linux_main.c	Fri Jun 27 13:56:49 2014 +0200
+++ b/targets/Linux/plc_Linux_main.c	Fri Dec 12 14:41:53 2014 +0100
@@ -119,7 +119,7 @@
 
     timer_create (CLOCK_REALTIME, &sigev, &PLC_timer);
     if(  __init(argc,argv) == 0 ){
-        PLC_SetTimer(Ttick,Ttick);
+        PLC_SetTimer(common_ticktime__,common_ticktime__);
 
         /* install signal handler for manual break */
         signal(SIGINT, catch_signal);
--- a/targets/Win32/plc_Win32_main.c	Fri Jun 27 13:56:49 2014 +0200
+++ b/targets/Win32/plc_Win32_main.c	Fri Dec 12 14:41:53 2014 +0100
@@ -136,7 +136,7 @@
     }
     if( __init(argc,argv) == 0 )
     {
-        PLC_SetTimer(Ttick,Ttick);
+        PLC_SetTimer(common_ticktime__,common_ticktime__);
         PLC_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PlcLoop, NULL, 0, &thread_id);
     }
     else{
--- a/targets/Xenomai/plc_Xenomai_main.c	Fri Jun 27 13:56:49 2014 +0200
+++ b/targets/Xenomai/plc_Xenomai_main.c	Fri Dec 12 14:41:53 2014 +0100
@@ -13,7 +13,6 @@
 
 #include <native/task.h>
 #include <native/timer.h>
-#include <native/mutex.h>
 #include <native/sem.h>
 #include <native/pipe.h>
 
@@ -75,7 +74,7 @@
 
 void PLC_task_proc(void *arg)
 {
-    PLC_SetTimer(Ttick, Ttick);
+    PLC_SetTimer(common_ticktime__, common_ticktime__);
 
     while (!PLC_shutdown) {
         PLC_GetTime(&__CURRENT_TIME);
--- a/targets/plc_main_head.c	Fri Jun 27 13:56:49 2014 +0200
+++ b/targets/plc_main_head.c	Fri Dec 12 14:41:53 2014 +0100
@@ -31,9 +31,6 @@
  **/
 extern unsigned long greatest_tick_count__;
 
-/* Effective tick time with 1ms default value */
-static long long Ttick = 1000000;
-
 /* Help to quit cleanly when init fail at a certain level */
 static int init_level = 0;
 
@@ -72,8 +69,9 @@
     int res = 0;
     init_level = 0;
     
-    if(common_ticktime__)
-        Ttick = common_ticktime__;
+    /* Effective tick time with 1ms default value */
+    if(!common_ticktime__)
+        common_ticktime__ = 1000000;
 
     config_init__();
     __init_debug();
--- a/targets/plc_main_tail.c	Fri Jun 27 13:56:49 2014 +0200
+++ b/targets/plc_main_tail.c	Fri Dec 12 14:41:53 2014 +0100
@@ -175,10 +175,10 @@
 			/* compute mean of Tsync, over calibration period */
 			Tsync = ((long long)(cal_end.tv_sec - cal_begin.tv_sec) * (long long)1000000000 +
 					(cal_end.tv_nsec - cal_begin.tv_nsec)) / calibration_count;
-			if( (Nticks = (Tsync / Ttick)) > 0){
-				FreqCorr = (Tsync % Ttick); /* to be divided by Nticks */
+			if( (Nticks = (Tsync / common_ticktime__)) > 0){
+				FreqCorr = (Tsync % common_ticktime__); /* to be divided by Nticks */
 			}else{
-				FreqCorr = Tsync - (Ttick % Tsync);
+				FreqCorr = Tsync - (common_ticktime__ % Tsync);
 			}
 			/*
 			printf("Tsync = %ld\n", Tsync);
@@ -197,19 +197,19 @@
 			PLC_GetTime(&now);
 			elapsed = (now.tv_sec - __CURRENT_TIME.tv_sec) * 1000000000 + now.tv_nsec - __CURRENT_TIME.tv_nsec;
 			if(Nticks > 0){
-				PhaseCorr = elapsed - (Ttick + FreqCorr/Nticks)*sync_align_ratio/100; /* to be divided by Nticks */
-				Tcorr = Ttick + (PhaseCorr + FreqCorr) / Nticks;
+				PhaseCorr = elapsed - (common_ticktime__ + FreqCorr/Nticks)*sync_align_ratio/100; /* to be divided by Nticks */
+				Tcorr = common_ticktime__ + (PhaseCorr + FreqCorr) / Nticks;
 				if(Nticks < 2){
 					/* When Sync source period is near Tick time */
 					/* PhaseCorr may not be applied to Periodic time given to timer */
-					PeriodicTcorr = Ttick + FreqCorr / Nticks;
+					PeriodicTcorr = common_ticktime__ + FreqCorr / Nticks;
 				}else{
 					PeriodicTcorr = Tcorr;
 				}
 			}else if(__tick > last_tick){
 				last_tick = __tick;
 				PhaseCorr = elapsed - (Tsync*sync_align_ratio/100);
-				PeriodicTcorr = Tcorr = Ttick + PhaseCorr + FreqCorr;
+				PeriodicTcorr = Tcorr = common_ticktime__ + PhaseCorr + FreqCorr;
 			}else{
 				/*PLC did not run meanwhile. Nothing to do*/
 				return;