1 | #include "diabolo.h"
|
---|
2 | #include "bolo.h"
|
---|
3 | #include "acqui.h"
|
---|
4 | #include "fichier.h"
|
---|
5 | #include "tm.h"
|
---|
6 | #include "tache.h"
|
---|
7 | #include "regul.h"
|
---|
8 | #include "auto.h"
|
---|
9 | #include "config_transputer.h"
|
---|
10 | #include "bit_block.h"
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | void init_struct(int PCI_actif)
|
---|
16 | {
|
---|
17 | int i,j;
|
---|
18 | def_long_block
|
---|
19 | def_nom_block
|
---|
20 | printf("memoire pour stglob: %d K \nmemoire pour tmtc : %d K \n",
|
---|
21 | (sizeof(stglob)>>10),(sizeof(tmtc)>>10));
|
---|
22 |
|
---|
23 | gg=malloc(sizeof(stglob));
|
---|
24 |
|
---|
25 | random(-1);
|
---|
26 |
|
---|
27 | if(parametr.numero_version!=version_num) {erreur("erreur numero de version\n");return;}
|
---|
28 | if(parametr.n_max_bolo!=nb_max_bolo) {erreur("erreur nb_max_bolo \n");return;}
|
---|
29 | if(parametr.n_per_block!=nb_per_block) {erreur("erreur nb_per_block\n");return;}
|
---|
30 | if(parametr.n_max_mes_per!=nb_max_mes_per) {erreur("erreur nb_max_mes_per\n");return;}
|
---|
31 | if(parametr.nb_bolo!=nb_bolo_util) {erreur("erreur nb_bolo_util\n");return;}
|
---|
32 |
|
---|
33 | gg->reglage=reglage_standard[0];
|
---|
34 |
|
---|
35 | for(j=0;j<nb_max_bolo;j++)
|
---|
36 | {
|
---|
37 | // parametr.bolo[j].bolo_code_util=0;
|
---|
38 | // strcpy(parametr.nom_coef[parametr.bolo[j].numero_nom_coef].bolo_nom,"");
|
---|
39 | // parametr.bolo[j].bolo_bebo=0;
|
---|
40 | // parametr.bolo[j].bolo_num=0;
|
---|
41 | // parametr.bolo[j].bolo_gain=1000;
|
---|
42 | // parametr.bolo[j].bolo_capa=0;
|
---|
43 | // parametr.bolo[j].bolo_diviseur=0;
|
---|
44 | // parametr.presence_bebo=0;
|
---|
45 | // parametr.coef[nb_max_bolo][7] non initialisé
|
---|
46 |
|
---|
47 | gg->reglage.bolo[j].mot1=0;
|
---|
48 | gg->reglage.bolo[j].mot2=0;
|
---|
49 | // gg->reglage.gainbrut[j]=0;
|
---|
50 | // gg->reglage.gain[j]=1;
|
---|
51 | }
|
---|
52 | gg->temps_cntl=0;
|
---|
53 | gg->depou_en_cours=0;
|
---|
54 | gg->trace_ouvert=0;
|
---|
55 | for(j=0;j<8;j++) gg->trace_tout[j]=0;
|
---|
56 | gg->scan_en_cours=0;
|
---|
57 | gg->flag_corel=0;
|
---|
58 | gg->flag_tc_reduite=0;
|
---|
59 | gg->fichier_dia2_ouvert=0;
|
---|
60 | gg->fichier_arch_ouvert=0;
|
---|
61 | gg->flag_fou=0;
|
---|
62 | gg->temps_origine=0;
|
---|
63 |
|
---|
64 | //---------- initialise les structures de la tache -------------
|
---|
65 | tt=malloc(sizeof(tmtc));
|
---|
66 |
|
---|
67 | tt->PCI_actif=PCI_actif;
|
---|
68 | printf("tt->PCI_actif=%d \n",tt->PCI_actif);
|
---|
69 |
|
---|
70 | tt->reglage=gg->reglage;
|
---|
71 |
|
---|
72 | tt->vi.temps_cntl=0;
|
---|
73 |
|
---|
74 | tt->signal_scan_immediat=0;
|
---|
75 | // donc toujours zero pour archeops
|
---|
76 |
|
---|
77 | for(j=0;j<nb_max_bolo;j++)
|
---|
78 | {
|
---|
79 | tt->ds.ii[j]=0;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | tt->te.pos_ecrit=0;tt->te.pos_lit=0;
|
---|
84 | tt->tc.pos_ecrit=0;tt->tc.pos_lit=0;
|
---|
85 | tt->tm.pos_ecrit=0;tt->tm.pos_lit=0;
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | j=0;
|
---|
90 | for(i=0;i<nb_type_blocks;i++)
|
---|
91 | {
|
---|
92 | printf(" - size=%5d block : %s\n",long_block[i],nom_block[i]);
|
---|
93 | if (long_block[i]> j ) j=long_block[i];
|
---|
94 | }
|
---|
95 | printf(" taille maxi du block de telemesure = %d // on reserve %d octets par block \n",
|
---|
96 | j,sizeof(block_type_modele));
|
---|
97 | if(j>sizeof(block_type_modele)) erreur("block_type_modele trops petit");
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | init_tache(); // init dependant des taches
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | //_________________________________________________________________________________________________________________
|
---|
109 | int test_erreur(void)
|
---|
110 | {
|
---|
111 | int err,i;
|
---|
112 | DateTimeRec date;
|
---|
113 | err=tt->te.pos_ecrit-tt->te.pos_lit; if (err<0) err+=long_table_err;
|
---|
114 | if(err>0)
|
---|
115 | {
|
---|
116 | GetTime(&date);
|
---|
117 | printf("%dh%d:%d : %d erreurs table: ",date.hour,date.minute,date.second,err);
|
---|
118 | for(i=0;(i<err);i++) {
|
---|
119 | if(i<5) switch(tt->te.err[tt->te.pos_lit])
|
---|
120 | {
|
---|
121 | case 900+err_sync_repart : printf(" sync_repart");break;
|
---|
122 | // case 900+err_fifo_demi : printf(" fifo_demi");break;
|
---|
123 | case 900+err_fifo_pleine : printf(" fifo_pleine");break;
|
---|
124 | case 900+err_sync_bebo : printf(" sync-bebo");break;
|
---|
125 | case 900+err_sync_ctrl : printf(" sync-ctrl");break;
|
---|
126 | case 900+err_lect_pci : printf(" lect_pci");break;
|
---|
127 | case 900+err_lect_ctrl : printf(" lect_ctrl");break;
|
---|
128 | case 900+err_synchro_block : printf(" synchro_block");break;
|
---|
129 | case 900+err_recut_un_block_ok: printf(" err_recut_un_block_ok");break;
|
---|
130 | case 900+err_longueur_block : printf(" err_longueur_block");break;
|
---|
131 | case 900+err_sauve_block : printf(" err_sauve_block");break;
|
---|
132 | case 900+err_pile_pleine : printf(" err_pile_pleine");son(133);break;
|
---|
133 |
|
---|
134 | case 920+erreur_bit_erreur : printf(" bit_erreur");break;
|
---|
135 | case 920+erreur_bit_vide : printf(" bit_vide");break;
|
---|
136 | case 920+erreur_type : printf(" bit_type_erreur");break;
|
---|
137 | case 920+erreur_longueur : printf(" bit_erreur_longueur");break;
|
---|
138 | case 920+erreur_somme : printf(" bit_erreur_somme");break;
|
---|
139 | case 920+erreur_fin : printf(" bit_erreur_fin");break;
|
---|
140 | case 920+cherche_debut : printf(" bit_cherche_debut");break;
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 | case 8 : printf(" +");break;
|
---|
145 | case 9 : printf(" -");break;
|
---|
146 | default :
|
---|
147 | if(tt->te.err[tt->te.pos_lit]>=920)
|
---|
148 | printf("bit_%d ",tt->te.err[tt->te.pos_lit]-920);
|
---|
149 | else printf(" %d",tt->te.err[tt->te.pos_lit]);
|
---|
150 | break;
|
---|
151 | }
|
---|
152 | tt->te.pos_lit++; if( tt->te.pos_lit>=long_table_err) tt->te.pos_lit=0;
|
---|
153 | }
|
---|
154 | printf("\n");
|
---|
155 | }
|
---|
156 | return(err);
|
---|
157 | }
|
---|
158 | //_________________________________________________________________________________________________________________
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 | // appel des bolo pour tracé des courbes individuelles
|
---|
163 | void affi_bolo(void)
|
---|
164 | {
|
---|
165 | static int affi1=0,affi2=0;
|
---|
166 | int j;
|
---|
167 | static long t=0;
|
---|
168 | if(!t) t=TickCount();
|
---|
169 | if(t>TickCount()) return;
|
---|
170 | t=TickCount()+60; //attente au minimum 1 sec entre 2 appels
|
---|
171 |
|
---|
172 | for(j=0;j<nb_max_bolo;j++) if(parametr.bolo[j].bolo_code_util) exec_bolo(j+1,tache_de_fond,0);
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 | //*****************************************************************************************
|
---|
181 | // ***
|
---|
182 | #ifdef _archeops //--------- pour Archeops ------------------------------ ***
|
---|
183 | // ***
|
---|
184 | //*****************************************************************************************
|
---|
185 |
|
---|
186 |
|
---|
187 |
|
---|
188 | //_________________________________________________________________________________________________________________
|
---|
189 | void reset_epld(void)
|
---|
190 | {
|
---|
191 | char mot_tc[10];
|
---|
192 | printf("reset epld");
|
---|
193 | emission_tc_reduite(tc2_reset,tc3_reset,tc4_reset);
|
---|
194 | emission_telecommande(tc_dir_reset_epld,mot_tc);
|
---|
195 |
|
---|
196 | }
|
---|
197 |
|
---|
198 | void reset_trp(void)
|
---|
199 | {
|
---|
200 | char mot_tc[10];
|
---|
201 | printf("reset trp");
|
---|
202 | emission_tc_reduite(tc2_reset,tc3_reset,tc4_reset);
|
---|
203 | emission_telecommande(tc_dir_reset_trp,mot_tc);
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|
207 | void calfreq(int flag_on) // fabrique l'etat.bolo gg->reglage.horloge et gg->periode_echantillonage
|
---|
208 | // le flag_on dit s'il faut commander la sortie des data
|
---|
209 | {
|
---|
210 | double p,f1,f2,f3;
|
---|
211 | int pp,b,tm,flag;
|
---|
212 | char mot_tc[10];
|
---|
213 |
|
---|
214 | p=litD(fenetre_acquisition,e_periode,0L);
|
---|
215 | if(p<4) p=4; if(p>16) p=16; // butée sur la periode
|
---|
216 | pp=p*5.; p=(double)pp / 5.;
|
---|
217 | ecritD(fenetre_acquisition,e_periode,"%6.1f",p); // reconstruit p
|
---|
218 |
|
---|
219 | b=litD(fenetre_acquisition,e_nb_mes,0L);
|
---|
220 | if(b<18) {b=18;ecritD(fenetre_acquisition,e_nb_mes,b);}
|
---|
221 | if(b>44) {b=44;ecritD(fenetre_acquisition,e_nb_mes,b);}
|
---|
222 | b=b*2;
|
---|
223 |
|
---|
224 |
|
---|
225 | tm=litD(fenetre_acquisition,e_temp_mort,0L); // temps mort = 1 .. nbmes par 1/4 per
|
---|
226 | if(tm<2) {tm=2;ecritD(fenetre_acquisition,e_temp_mort,tm);}
|
---|
227 | if(tm>13) {tm=13;ecritD(fenetre_acquisition,e_temp_mort,tm);}
|
---|
228 |
|
---|
229 |
|
---|
230 | flag=flag_on;
|
---|
231 | if(litD(fenetre_acquisition,e_flag1,0L)) flag +=2;
|
---|
232 | if(litD(fenetre_acquisition,e_flag2,0L)) flag +=4;
|
---|
233 |
|
---|
234 | //printf(" b=%d tm=%d a=%d h=%d \n",b,tm,a,h);
|
---|
235 |
|
---|
236 | if(gg->flag_tc_reduite)
|
---|
237 | {
|
---|
238 |
|
---|
239 | if((pp!=gg->reglage.horloge.periode) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_periode,pp);
|
---|
240 | if((b!=gg->reglage.horloge.nb_mesures) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_nb_mesures,b);
|
---|
241 | if((tm!=gg->reglage.horloge.temp_mort) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_temp_mort,tm);
|
---|
242 | if(flag ou (flag!=gg->reglage.horloge.flag) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_flag,flag);
|
---|
243 | }
|
---|
244 |
|
---|
245 | else
|
---|
246 | {
|
---|
247 | mot_tc[0]=tc_horloge; // commande valeur des horloges
|
---|
248 | mot_tc[1]=pp; // periode en multiple de 0.2µsec : de 20 a 80 soit 4 a 16 µsec
|
---|
249 | mot_tc[2]=b/2 ; // nb pts/demi periode de 23 a 44
|
---|
250 | mot_tc[3]=tm;
|
---|
251 | mot_tc[4]=flag; // c'est le flag qui met en route la sortie des mesures
|
---|
252 | emission_telecommande(tc_dir_transputer,mot_tc);
|
---|
253 |
|
---|
254 | gg->reglage.horloge.periode=pp;
|
---|
255 | gg->reglage.horloge.nb_mesures=b; // nombre de mesures dans une periode complete
|
---|
256 | gg->reglage.horloge.temp_mort=tm;
|
---|
257 | gg->reglage.horloge.flag=flag;
|
---|
258 |
|
---|
259 | }
|
---|
260 | // affichage de toutes les fréquences
|
---|
261 | f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(gg->reglage.horloge.nb_mesures);
|
---|
262 | ecritD(fenetre_acquisition,e_freq,"freq: %5.1f kHz -- %5.2f kHz, modulation: %5.1f Hz",f1,f2,f3);
|
---|
263 | printf("freq --> : %5.1f kHz -- %5.2f kHz, modulation: %5.1f Hz\n",f1,f2,f3);
|
---|
264 | gg->periode_echantillonage=0.5/f3; // 2 fois la frequence de modulation
|
---|
265 | printf(" periode d'échantillonage= %g \n",gg->periode_echantillonage);
|
---|
266 |
|
---|
267 | tt->reglage=gg->reglage;
|
---|
268 | fich_save_partiel(1);
|
---|
269 | }
|
---|
270 |
|
---|
271 |
|
---|
272 | #endif
|
---|
273 | //*****************************************************************************************
|
---|
274 | // ***
|
---|
275 | #ifdef _diabolo //--------- pour Diabolo ------------------------------ ***
|
---|
276 | // ***
|
---|
277 | //*****************************************************************************************
|
---|
278 |
|
---|
279 | void reset_epld(void)
|
---|
280 | {
|
---|
281 | }
|
---|
282 |
|
---|
283 | void calfreq(int flag_on) // fabrique l'etat.bolo gg->reglage.horloge.nb_mesures et gg->periode_echantillonage
|
---|
284 | {
|
---|
285 | double p,f1,f2,f3;
|
---|
286 | int a,h,pp,b,tm;
|
---|
287 | int j;
|
---|
288 | char mot_tc[10];
|
---|
289 |
|
---|
290 | p=litD(fenetre_acquisition,e_periode,0L);
|
---|
291 | b=litD(fenetre_acquisition,e_nb_mes,0L);
|
---|
292 | tm=litD(fenetre_acquisition,e_temp_mort,0L); // temps mort = 1 .. nbmes par 1/4 per
|
---|
293 | if(tm<1) {tm=1;ecritD(fenetre_acquisition,e_temp_mort,tm);}
|
---|
294 | if(tm>b) {tm=b;ecritD(fenetre_acquisition,e_temp_mort,b);}
|
---|
295 | // lecture externe ou local
|
---|
296 | h=litD(fenetre_acquisition,e_horloge_ext_,0L);
|
---|
297 |
|
---|
298 | //if(p<5) p=5; // butée en periode minimum pour éviter de planter le Mac
|
---|
299 |
|
---|
300 |
|
---|
301 | //---------------------------------------- nombre de mesures
|
---|
302 |
|
---|
303 | if(b<4) b=4; if(b>44) b=44;
|
---|
304 | gg->reglage.horloge.nb_mesures=(b/2)*4;
|
---|
305 |
|
---|
306 | //---------------------------------------- periode de l'horloge de base
|
---|
307 | if (h&1) p=p*frequ_horloge_externe;
|
---|
308 | else p=p*frequ_horloge_interne;
|
---|
309 |
|
---|
310 | a=(p/frequ_divise)-ofset_periode ;
|
---|
311 |
|
---|
312 | if(a<0) a=0;
|
---|
313 | if(a>1020) a=1020; // 10 bits maxi attention a l'ofset
|
---|
314 |
|
---|
315 | pp=a+ofset_periode;
|
---|
316 | p=(double)(pp)*frequ_divise;
|
---|
317 | if (h&1) p=p/frequ_horloge_externe;
|
---|
318 | else p=p/frequ_horloge_interne;
|
---|
319 |
|
---|
320 | ecritD(fenetre_acquisition,e_periode,"%6.1f",p); // reconstruit p et pp
|
---|
321 |
|
---|
322 |
|
---|
323 | //printf(" b=%d tm=%d a=%d h=%d \n",b,tm,a,h);
|
---|
324 |
|
---|
325 | mot_tc[0]=tc_horloge; //79..72
|
---|
326 | mot_tc[1]=(tm%7)+ ((b/2)<<3) ; //71..64 3 bit temps mort et 5 bit mb (nombre de coups par 1/4 de periode = b/2)
|
---|
327 | mot_tc[2]=(a>>8); //63..56 poid fort (2 bits)
|
---|
328 | mot_tc[3]=a; //55..48 poid faible (8 bits)
|
---|
329 | mot_tc[4]=h&3; //47..40 horloge externe et bolo-iram
|
---|
330 | emission_telecommande(0,mot_tc);
|
---|
331 |
|
---|
332 |
|
---|
333 | // affichage de toutes les fréquences
|
---|
334 | f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(gg->reglage.horloge.nb_mesures);
|
---|
335 | gg->periode_echantillonage=0.5/f3; // 2 fois la frequence de modulation
|
---|
336 | // periode * 16 * nbdemesure / 2
|
---|
337 | //printf(" durée= %ld \n",gg->periode_echantillonage);
|
---|
338 |
|
---|
339 | ecritD(fenetre_acquisition,e_freq,"freq: %5.1f kHz -- %5.2f kHz, modulation: %5.1f Hz",f1,f2,f3);
|
---|
340 |
|
---|
341 |
|
---|
342 |
|
---|
343 | {//_______________ fabrique les detections synchrones de la modulation électrique
|
---|
344 | int i,v,tm;
|
---|
345 | tm=litD(fenetre_acquisition,e_temp_mort,0L);
|
---|
346 | gg->reglage.temp_mort=tm;
|
---|
347 | // detection plus/moins avec tm points supprimé
|
---|
348 | // ds[0] == plus / moins
|
---|
349 | // ds[1] == plus / plus
|
---|
350 | // ds[2] == + - 0 / - + 0
|
---|
351 |
|
---|
352 | tt->ds.dsnorme=0;
|
---|
353 | i=0;
|
---|
354 | for(v=0 ;v<gg->reglage.horloge.nb_mesures/2 ;v++)
|
---|
355 | {
|
---|
356 | if(v<tm) tt->ds.dstable[i]=0;
|
---|
357 | else {tt->ds.dstable[i]=1; tt->ds.dsnorme++;}
|
---|
358 | i++;
|
---|
359 | }
|
---|
360 | for(v=0;v<gg->reglage.horloge.nb_mesures/2 ;v++)
|
---|
361 | {
|
---|
362 | if(v<tm) tt->ds.dstable[i]=0;
|
---|
363 | else {tt->ds.dstable[i]=-1; tt->ds.dsnorme++;}
|
---|
364 | i++;
|
---|
365 | }
|
---|
366 | }
|
---|
367 | //printf(" normes = %d %d \n",tt->ds.dsnorme[0],tt->ds.dsnorme[1]);
|
---|
368 | tt->reglage=gg->reglage;
|
---|
369 | fich_save_partiel(1);
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | //*****************************************************************************************
|
---|
374 | // ***
|
---|
375 | #endif //-------------------------------------------------------------------- ***
|
---|
376 | // ***
|
---|
377 | //*****************************************************************************************
|
---|
378 |
|
---|
379 |
|
---|
380 |
|
---|
381 |
|
---|
382 | void deglitch(void)
|
---|
383 | {
|
---|
384 | int j;
|
---|
385 | double x,dx;
|
---|
386 | static int debut=1;
|
---|
387 | static double X[nb_max_bolo];
|
---|
388 | static double DX[nb_max_bolo];
|
---|
389 | if(debut)
|
---|
390 | {
|
---|
391 | for(j=0;j<nb_max_bolo;j++)
|
---|
392 | {
|
---|
393 | X[j]=0;DX[j]=1000;
|
---|
394 | }
|
---|
395 | debut=0;
|
---|
396 | }
|
---|
397 |
|
---|
398 | for(j=0;j<nb_max_bolo;j++)
|
---|
399 | {
|
---|
400 | x=gg->don.don_bolo[j];
|
---|
401 | dx=x-X[j]; if(dx<0) dx=-dx;
|
---|
402 | if( dx > DX[j] )
|
---|
403 | {
|
---|
404 | printf("glitch bolo %d ancien X=%g nouveau x=%g DX=%g \n",j+1,X[j],x,DX[j]);
|
---|
405 | gg->don.don_bolo[j]=X[j];
|
---|
406 | DX[j] *=1.1;
|
---|
407 | }
|
---|
408 | else {
|
---|
409 | DX[j]=0.9 * DX[j] + 0.5 * dx +1 ;
|
---|
410 | X[j]=x;
|
---|
411 | } // en moyenne, 5 fois l'interval moyen
|
---|
412 | }
|
---|
413 |
|
---|
414 | }
|
---|
415 |
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|