# HG changeset patch # User Edouard Tisserant # Date 1418391713 -3600 # Node ID e14003eb4d42c9bcc9fbcf7188332c79b2b2c56f # Parent 4e33f644f7cf1f431deaacbd8a053592e4511e42 Simplified use of runtime's global variable __common_ticktime accross extensions. diff -r 4e33f644f7cf -r e14003eb4d42 canfestival/cf_runtime.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 */ diff -r 4e33f644f7cf -r e14003eb4d42 targets/Linux/plc_Linux_main.c --- 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); diff -r 4e33f644f7cf -r e14003eb4d42 targets/Win32/plc_Win32_main.c --- 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{ diff -r 4e33f644f7cf -r e14003eb4d42 targets/Xenomai/plc_Xenomai_main.c --- 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 #include -#include #include #include @@ -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); diff -r 4e33f644f7cf -r e14003eb4d42 targets/plc_main_head.c --- 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(); diff -r 4e33f644f7cf -r e14003eb4d42 targets/plc_main_tail.c --- 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;