author | etisserant |
Fri, 22 Aug 2008 15:27:37 +0200 | |
changeset 216 | 11124e129a28 |
parent 209 | 08dc3d064cb5 |
child 235 | a66e150f2888 |
permissions | -rw-r--r-- |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
1 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
2 |
* Prototypes for function provided by arch-specific code (main) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
3 |
* concatained after this template |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
4 |
** / |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
5 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
6 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
7 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
8 |
* Functions and variables provied by generated C softPLC |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
9 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
10 |
extern int common_ticktime__; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
11 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
12 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
13 |
* Functions and variables provied by plc.c |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
14 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
15 |
void run(long int tv_sec, long int tv_nsec); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
16 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
17 |
#define maxval(a,b) ((a>b)?a:b) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
18 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
19 |
#include "iec_types.h" |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
20 |
/*#include "stdio.h" /* For debug */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
21 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
22 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
23 |
* Functions and variables provied by generated C softPLC |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
24 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
25 |
void config_run__(int tick); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
26 |
void config_init__(void); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
27 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
28 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
29 |
* Functions and variables to export to generated C softPLC and plugins |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
30 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
31 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
32 |
IEC_TIME __CURRENT_TIME; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
33 |
int __tick = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
34 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
35 |
static int init_level = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
36 |
static int Debugging = 1; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
37 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
38 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
39 |
* Prototypes of functions exported by plugins |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
40 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
41 |
%(calls_prototypes)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
42 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
43 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
44 |
* Retrieve input variables, run PLC and publish output variables |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
45 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
46 |
void __run() |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
47 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
48 |
%(retrieve_calls)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
49 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
50 |
if(Debugging) __retrieve_debug(); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
51 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
52 |
config_run__(__tick); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
53 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
54 |
if(Debugging) __publish_debug(); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
55 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
56 |
%(publish_calls)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
57 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
58 |
__tick++; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
59 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
60 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
61 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
62 |
* Initialize variables according to PLC's defalut values, |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
63 |
* and then init plugins with that values |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
64 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
65 |
int __init(int argc,char **argv) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
66 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
67 |
int res; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
68 |
config_init__(); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
69 |
%(init_calls)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
70 |
return 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
71 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
72 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
73 |
* Calls plugin cleanup proc. |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
74 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
75 |
void __cleanup() |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
76 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
77 |
%(cleanup_calls)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
78 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
79 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
80 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
81 |
void PLC_GetTime(IEC_TIME *CURRENT_TIME); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
82 |
void PLC_SetTimer(long long next, long long period); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
83 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
84 |
#define CALIBRATED -2 |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
85 |
#define NOT_CALIBRATED -1 |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
86 |
static int calibration_count = NOT_CALIBRATED; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
87 |
static IEC_TIME cal_begin; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
88 |
static long long Tsync = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
89 |
static long long FreqCorr = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
90 |
static int Nticks = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
91 |
static int last_tick = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
92 |
static long long Ttick = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
93 |
#define mod %% |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
94 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
95 |
* Call this on each external sync, |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
96 |
* @param sync_align_ratio 0->100 : align ratio, < 0 : no align, calibrate period |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
97 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
98 |
void align_tick(int sync_align_ratio) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
99 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
100 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
101 |
printf("align_tick(%%d)\n", calibrate); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
102 |
*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
103 |
if(sync_align_ratio < 0){ /* Calibration */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
104 |
if(calibration_count == CALIBRATED) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
105 |
/* Re-calibration*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
106 |
calibration_count = NOT_CALIBRATED; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
107 |
if(calibration_count == NOT_CALIBRATED) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
108 |
/* Calibration start, get time*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
109 |
PLC_GetTime(&cal_begin); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
110 |
calibration_count++; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
111 |
}else{ /* do alignment (if possible) */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
112 |
if(calibration_count >= 0){ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
113 |
/* End of calibration */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
114 |
/* Get final time */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
115 |
IEC_TIME cal_end; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
116 |
PLC_GetTime(&cal_end); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
117 |
/*adjust calibration_count*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
118 |
calibration_count++; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
119 |
/* compute mean of Tsync, over calibration period */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
120 |
Tsync = ((long long)(cal_end.tv_sec - cal_begin.tv_sec) * (long long)1000000000 + |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
121 |
(cal_end.tv_nsec - cal_begin.tv_nsec)) / calibration_count; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
122 |
if( (Nticks = (Tsync / Ttick)) > 0){ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
123 |
FreqCorr = (Tsync mod Ttick); /* to be divided by Nticks */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
124 |
}else{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
125 |
FreqCorr = Tsync - (Ttick mod Tsync); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
126 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
127 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
128 |
printf("Tsync = %%ld\n", Tsync); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
129 |
printf("calibration_count = %%d\n", calibration_count); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
130 |
printf("Nticks = %%d\n", Nticks); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
131 |
*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
132 |
calibration_count = CALIBRATED; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
133 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
134 |
if(calibration_count == CALIBRATED){ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
135 |
/* Get Elapsed time since last PLC tick (__CURRENT_TIME) */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
136 |
IEC_TIME now; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
137 |
long long elapsed; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
138 |
long long Tcorr; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
139 |
long long PhaseCorr; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
140 |
long long PeriodicTcorr; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
141 |
PLC_GetTime(&now); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
142 |
elapsed = (now.tv_sec - __CURRENT_TIME.tv_sec) * 1000000000 + now.tv_nsec - __CURRENT_TIME.tv_nsec; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
143 |
if(Nticks > 0){ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
144 |
PhaseCorr = elapsed - (Ttick + FreqCorr/Nticks)*sync_align_ratio/100; /* to be divided by Nticks */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
145 |
Tcorr = Ttick + (PhaseCorr + FreqCorr) / Nticks; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
146 |
if(Nticks < 2){ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
147 |
/* When Sync source period is near Tick time */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
148 |
/* PhaseCorr may not be applied to Periodic time given to timer */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
149 |
PeriodicTcorr = Ttick + FreqCorr / Nticks; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
150 |
}else{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
151 |
PeriodicTcorr = Tcorr; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
152 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
153 |
}else if(__tick > last_tick){ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
154 |
last_tick = __tick; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
155 |
PhaseCorr = elapsed - (Tsync*sync_align_ratio/100); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
156 |
PeriodicTcorr = Tcorr = Ttick + PhaseCorr + FreqCorr; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
157 |
}else{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
158 |
/*PLC did not run meanwhile. Nothing to do*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
159 |
return; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
160 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
161 |
/* DO ALIGNEMENT */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
162 |
PLC_SetTimer(Tcorr - elapsed, PeriodicTcorr); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
163 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
164 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
165 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
166 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
167 |
int suspendDebug() |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
168 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
169 |
/* Prevent PLC to enter debug code */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
170 |
Debugging = 0; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
171 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
172 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
173 |
int resumeDebug() |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
174 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
175 |
/* Let PLC enter debug code */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
176 |
Debugging = 1; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
177 |
} |