[637] | 1 | #include "manip.h"
|
---|
| 2 | #include "choix_acquisition.h"
|
---|
| 3 | #include "archeops.h"
|
---|
| 4 | #include "choix_param.h"
|
---|
| 5 | #include "structure.h"
|
---|
| 6 | #include "tm.h"
|
---|
| 7 | #include "tache.h"
|
---|
| 8 | #include "bolo.h"
|
---|
| 9 | #include "carte_acqui.h"
|
---|
| 10 | #include "carte_pci.h"
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | //*****************************************************************************************
|
---|
| 19 | // ***
|
---|
| 20 | #ifdef _diabolo //--------- pour Diabolo ------------------------------ ***
|
---|
| 21 | // ***
|
---|
| 22 | //*****************************************************************************************
|
---|
| 23 |
|
---|
| 24 | //#define test_erreur_complet
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | #define avance_erreur {tt->te.pos_ecrit++; if(tt->te.pos_ecrit>=long_table_err) tt->te.pos_ecrit=0;}
|
---|
| 29 | #define ecrit_erreur(xx) {avance_erreur;tt->te.err[tt->te.pos_ecrit]=900+(xx);}
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | #define SYNCHRO fifo0
|
---|
| 33 | #define EPLD_occupe fifo12
|
---|
| 34 | #define top_debut fifo13
|
---|
| 35 |
|
---|
| 36 | #define ADC_BEBO fifo(10)
|
---|
| 37 | #define DS_BEBO fifo(11)
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | void depou_un_bit(tmtc* tt,long RR);
|
---|
| 42 | void depou_un_mot_24_bit(tmtc* tt);
|
---|
| 43 |
|
---|
| 44 | void sauvedata(tmtc* tt,long * somme_ds);
|
---|
| 45 |
|
---|
| 46 | // i= position dans la periode j=numero de bolo k=numero de detection
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | void init_tache(void)
|
---|
| 50 | {
|
---|
| 51 |
|
---|
| 52 | tt->vi.flag_ecriture_data=0;
|
---|
| 53 |
|
---|
| 54 | tt->vi.i=0;
|
---|
| 55 | tt->vi.pos_block_tm=0;
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | tt->vi.reg.pid.nb_mes=0;
|
---|
| 59 | tt->vi.reg.pid.code=0;
|
---|
| 60 | tt->vi.reg.pid.num_bolo=0;
|
---|
| 61 | tt->vi.reg.pid.nb_mes=0;
|
---|
| 62 | tt->vi.reg.pid.chauf=0;
|
---|
| 63 | tt->vi.reg.pid.p=0;
|
---|
| 64 | tt->vi.reg.pid.i=0;
|
---|
| 65 | tt->vi.reg.pid.d=0;
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | tt->vi.reg.compteur=0;
|
---|
| 69 |
|
---|
| 70 | tt->vi.reg.valeur=0;
|
---|
| 71 | tt->vi.reg.anc_ecart=0;
|
---|
| 72 | tt->vi.reg.tint=0;
|
---|
| 73 | tt->vi.reg.cc=0;
|
---|
| 74 |
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | void lecture_fifo(void* tx) // appellé directement pour acquisition en interuptions
|
---|
| 80 | {
|
---|
| 81 | register unsigned long RR;
|
---|
| 82 | tmtc* tt=(tmtc*)tx;
|
---|
| 83 | long lec_fifo=0;
|
---|
| 84 | int max_fifo;
|
---|
| 85 |
|
---|
[649] | 86 | if(acquisition_PCI) max_fifo=3000; // 3000 points maxi par interruption (10ms) soit (3.3µs)
|
---|
[637] | 87 | else max_fifo=200; // ((1000)faux ) points maxi par interruption (10ms) soit (20µs)
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | while(1)
|
---|
| 91 | {
|
---|
[649] | 92 | if(acquisition_PCI) {lit_carte; if(rien_a_lire) break;}// fifo vide -> retour -> sort du while
|
---|
[637] | 93 | lec_fifo++;
|
---|
| 94 | if (EPLD_occupe) tt->vi.flag_ecriture_data=0;
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | //---------------------- test des erreurs PCI a mettre ou a enlever pour aller plus vite -------------
|
---|
| 98 | #ifdef test_erreur_complet
|
---|
| 99 | {
|
---|
| 100 | int j;
|
---|
| 101 | /* j= (RR>>30) & 3; // ***** test bonne lecture PCI (seulement carte fife ) ******
|
---|
| 102 | while (j!=5) {
|
---|
| 103 | ecrit_erreur(err_lect_pci);
|
---|
| 104 | lit_carte; if(rien_a_lire) break;
|
---|
| 105 | j= (RR>>29) & 7;
|
---|
| 106 | tt->vi.aa=0;
|
---|
| 107 | }
|
---|
| 108 | if(j!=5) break; // parceque il faut sortir des deux while
|
---|
| 109 | */
|
---|
| 110 | tt->vi.aa++; // le aa du test d'erreur n'est pas le meme que le a du compteur de temps
|
---|
| 111 |
|
---|
| 112 | j= ((RR>>26) - tt->vi.aa ) & 7; // ***** test compteur dans carte PCI ******
|
---|
| 113 | if(j) {
|
---|
| 114 | tt->vi.aa= (RR>>26) & 7;
|
---|
| 115 | avance_erreur;tt->te.err[tt->te.pos_ecrit]=j;
|
---|
| 116 | ecrit_erreur(err_lect_pci);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // j= ((RR>>15) - tt->vi.a ) & 7 ; // ****** test compteur dans controleur *******
|
---|
| 120 | // if(j) {
|
---|
| 121 | // avance_erreur;tt->te.err[tt->te.pos_ecrit]=j;
|
---|
| 122 | // ecrit_erreur(err_lect_ctrl);
|
---|
| 123 | // }
|
---|
| 124 | } // autre erreur de synchro fifo
|
---|
| 125 | #endif
|
---|
| 126 | //_____________________ fin du test des erreurs facultatif _____________________________________________
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | // if(parametr.presence_bebo && (tt->vi.a==5) && ADC_BEBO ) ecrit_erreur(err_sync_bebo); // erreur synchro de la BEBO
|
---|
| 130 |
|
---|
| 131 | depou_un_bit(tt,RR);
|
---|
| 132 |
|
---|
| 133 | tt->vi.a++;
|
---|
| 134 |
|
---|
| 135 | // -------------------- avance les compteurs a (position dans le mot de 24 bits) et i (position dans la periode)
|
---|
| 136 | if (tt->vi.a>(bitmot-1))
|
---|
| 137 | {
|
---|
| 138 | tt->vi.a=0;tt->vi.i++;
|
---|
| 139 | if(tt->vi.i>(tt->reglage.horloge.nb_mesures-1)) tt->vi.i=0; // normal : fin de periode complete
|
---|
| 140 | if(SYNCHRO) ecrit_erreur(err_sync_repart); // erreur synchro du repartiteur
|
---|
| 141 | if( RR&FLAG_FIFO_FULL ) {ecrit_erreur(err_fifo_pleine);read_flags();reset_fifo();} // la fifo a débordée
|
---|
| 142 | if(lec_fifo > tt->nb_lec_fofo_int) tt->nb_lec_fofo_int=lec_fifo;
|
---|
[649] | 143 | if(!tt->val_con_fifo) {tt->val_con_fifo=tt->nb_lec_fofo_int;tt->nb_lec_fofo_int=0;}
|
---|
[637] | 144 | if(lec_fifo>max_fifo)
|
---|
| 145 | {
|
---|
| 146 | if(!(RR&FLAG_NFIFOHF)) tt->nb_lec_fofo_int=2*max_fifo; // fifo plus qu'à moitié pleine
|
---|
| 147 | break;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | // ------------------- test topdebut en même temps que le dernier bit du mot --------------
|
---|
| 151 | // si pas de top debut: les compteurs tournent normalement et pas de diagnostique d'erreur
|
---|
| 152 | if(top_debut && ( tt->vi.a ou tt->vi.i) )
|
---|
| 153 | {
|
---|
| 154 | ecrit_erreur(err_sync_ctrl); // erreur synchro controlleur-mac
|
---|
| 155 | tt->vi.a=0;tt->vi.i=0;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | //_________________________________________________________________________________________________________________
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | void depou_un_bit(tmtc* tt,long RR)
|
---|
| 168 | {
|
---|
| 169 | int j,n,t,s;
|
---|
| 170 | n=tt->reglage.horloge.nb_mesures;
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | //___________________ calcul detection synchrone et remplissage table courante
|
---|
| 175 |
|
---|
| 176 | if(tt->vi.a ==0)
|
---|
| 177 | {
|
---|
| 178 | depou_un_mot_24_bit(tt); // appel du programme qui somme les points pour calcul de la D.S.
|
---|
| 179 | // c'est aussi le programme qui rempli la table pour affichage d'une periode
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | //___________________ B.E.B.O. Lecture de numbol : numero du bolo de la bebo a lire
|
---|
| 183 | if(tt->vi.a==2) tt->vi.numbol=0;
|
---|
| 184 |
|
---|
| 185 | if( (tt->vi.a>=2) && (tt->vi.a<=4) ) tt->vi.numbol= tt->vi.numbol | ( ADC_BEBO << (4-tt->vi.a)) ; // a==2, 3 et 4 -> numero du bolo en cours de mesure
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 189 | {
|
---|
| 190 | t=parametr.bolo[j].bolo_bebo;
|
---|
| 191 | switch(t)
|
---|
| 192 | {
|
---|
| 193 | case 0 : // lecture MLPA direct sur fifo numero t
|
---|
| 194 | if (tt->vi.a==2) tt->vi.mot[j]=tt->vi.mot[j] | ( fifo(parametr.bolo[j].bolo_num) << 12 ); // a=2 : bit de phase (ecrit pour a=0 : 2 temps de retard)
|
---|
| 195 | if( (tt->vi.a>=4) && (tt->vi.a<=15) ) tt->vi.mot[j]=tt->vi.mot[j] | ( fifo(parametr.bolo[j].bolo_num) << (15-tt->vi.a));
|
---|
| 196 | break;
|
---|
| 197 |
|
---|
| 198 | case 2 : // lecture beboA : bolo 17 à 22
|
---|
| 199 |
|
---|
| 200 | t=parametr.bolo[j].bolo_num;
|
---|
| 201 | if( !t ou ( t == tt->vi.numbol ) )
|
---|
| 202 | {
|
---|
| 203 | if(tt->vi.a==6) tt->vi.mot[j]=tt->vi.mot[j] | ( ADC_BEBO << 12 ); // a=6 : bit de phase
|
---|
| 204 | if( (tt->vi.a>6) && (tt->vi.a<=18) ) // a==7 -> poid fort de l'ADC
|
---|
| 205 | tt->vi.mot[j]=tt->vi.mot[j] | ( ADC_BEBO << (18-tt->vi.a)); // données de chaque bolo individuels de la bebo
|
---|
| 206 | }
|
---|
| 207 | if( ( t == (7-tt->vi.i) ) && (tt->vi.a>0) && (tt->vi.a<=22) ) // a==1 -> premier bit de poid fort -- 22 bits en tout
|
---|
| 208 | tt->ds.sommeA[j]=tt->ds.sommeA[j] | ( DS_BEBO << (22-tt->vi.a)); // valeur DS de chaque bolo individuels de la bebo
|
---|
| 209 | if( ( t == (7 + n/2 -tt->vi.i) ) && (tt->vi.a>0) && (tt->vi.a<=22) ) // a==1 -> premier bit de poid fort -- 22 bits en tout
|
---|
| 210 | tt->ds.sommeB[j]=tt->ds.sommeB[j] | ( DS_BEBO << (22-tt->vi.a)); // valeur DS de chaque bolo individuels de la bebo
|
---|
| 211 |
|
---|
| 212 | break;
|
---|
| 213 | default : break;
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | // ------------------- calcul des signaux de synchro (sur chaque bit de chaque mot) ------------------
|
---|
| 217 |
|
---|
| 218 | s=tt->vi.a-5;
|
---|
| 219 | if( (s>=0) && (s<nb_sync) && !SYNCHRO ) tt->vi.synchro[s]++;
|
---|
| 220 |
|
---|
| 221 | if(tt->PCI_actif==2)
|
---|
| 222 | //if(tt->vi.a ==0)
|
---|
| 223 | {
|
---|
| 224 | if(((tt->vi.temps_cntl>>19)&1)) tt->vi.synchro[0]=10;else tt->vi.synchro[0]=0;
|
---|
| 225 | if(((tt->vi.temps_cntl>>25)&1)) tt->vi.synchro[1]=20;else tt->vi.synchro[1]=0; // scan
|
---|
| 226 | if(((tt->vi.temps_cntl>>21)&1)) tt->vi.synchro[2]=30;else tt->vi.synchro[2]=0; // subscan
|
---|
| 227 | if(((tt->vi.temps_cntl>>22)&1)) tt->vi.synchro[3]=40;else tt->vi.synchro[3]=0;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 | void depou_un_mot_24_bit(tmtc* tt)
|
---|
| 237 | {
|
---|
| 238 | // ----------------- traitement d'une valeur ADC lue (typique 10 kHz) --------------------------------
|
---|
| 239 | //------------------ appellé pour tt->vi.a==0 avant lecture du bit correspondant --------------
|
---|
| 240 | register long R1;
|
---|
| 241 | int j,n,p;
|
---|
| 242 | n=tt->reglage.horloge.nb_mesures;
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | if(tt->PCI_actif==2)
|
---|
| 246 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 247 | {
|
---|
| 248 | int q;
|
---|
| 249 | q=tt->vi.i-1;if(q<0) q=n-1; // parceque tt->vi.i vaut 0 pour le dernier point
|
---|
| 250 | // tt->vi.mot[j]= 0x800 - (q-(n/2)) * (((double)j+10.) * 0.1 * (double)((tt->vi.temps_cntl>>15)&0x1f)) ; // sans carte : mot fini sans erreur
|
---|
| 251 | tt->vi.mot[j]= 0x800 - (q-(n/2)) * (int)(5.*((double)j+5.) * cos(0.01*(double)(tt->vi.temps_cntl>>8))) ; // sans carte : mot fini sans erreur
|
---|
| 252 | tt->vi.mot[j]+= ((int)(random(0)*256.)&0xff) ; // bruit aléatoire 8 bits
|
---|
| 253 | // tt->vi.mot[j]= 0x800 + ((int)(random(0)*3.)&0x3f) ; // bruit aléatoire 3 bits
|
---|
| 254 | if(q>=n/2) tt->vi.mot[j]+=0x1000; // phase
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 260 | {
|
---|
| 261 | // --------------- pour MLPA ou BEBO voie zero: je calcule la detection synchrone par soft: ------------
|
---|
| 262 | if ( ( !parametr.bolo[j].bolo_bebo ) ou ( !parametr.bolo[j].bolo_num ) )
|
---|
| 263 | {
|
---|
| 264 | if( ( (tt->ds.ii[j]>n/2) && (!(tt->vi.mot[j]&0x1000)) ) ou (tt->ds.ii[j]>n) )
|
---|
| 265 | tt->ds.ii[j]=0; // calage de la phase sur la phase mesurée
|
---|
| 266 |
|
---|
| 267 | R1=( tt->vi.mot[j]&0xfff ) * ( tt->ds.dstable[tt->ds.ii[j]] ); // calcul de la D.S.
|
---|
| 268 | tt->ds.sommeA[j]+=R1; tt->ds.sommeB[j]+=R1; // somme dans les deux tables
|
---|
| 269 | tt->ds.ii[j]++; // avance la phase propre de chaque bolometre ii avance de 0 à n-1
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | //--------------------------- remplissage table affichage une periode dans block tm --------------------
|
---|
| 275 |
|
---|
| 276 | p=tt->vi.i-1;if ( p<0) p=n-1;
|
---|
| 277 | if( ( !parametr.bolo[j].bolo_bebo ) ou ( !parametr.bolo[j].bolo_num ) ou ( parametr.bolo[j].bolo_num==tt->vi.numbol) )
|
---|
| 278 | {
|
---|
| 279 | tt->tm.btm[tt->tm.pos_ecrit].bol_per[j][p]=tt->vi.mot[j]<<3; // je lit le dernier point pour i=0, que j'ecrit en p=n-1
|
---|
| 280 | tt->tm.btm[tt->tm.pos_ecrit].flag_bolo[j]=1;
|
---|
| 281 | }
|
---|
| 282 | //--------------------------- reset du mot avant mesure point suivant --------------------
|
---|
| 283 |
|
---|
| 284 | tt->vi.mot[j]=0;
|
---|
| 285 |
|
---|
| 286 | //--------------------------- pour BEBO : somme et changement de signe pour calcul D.S. --------------------
|
---|
| 287 |
|
---|
| 288 | if( (tt->vi.i==0) && parametr.bolo[j].bolo_bebo && parametr.bolo[j].bolo_num )
|
---|
| 289 | { tt->ds.sommeB[j] = -tt->ds.sommeB[j];tt->ds.sommeA[j] += tt->ds.sommeB[j];}
|
---|
| 290 |
|
---|
| 291 | if( (tt->vi.i==(n/2)) && parametr.bolo[j].bolo_bebo && parametr.bolo[j].bolo_num )
|
---|
| 292 | tt->ds.sommeB[j] += tt->ds.sommeA[j];
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | if(tt->vi.i==0) sauvedata(tt,tt->ds.sommeA); // apres lecture et sommation du dernier point
|
---|
| 297 | if(tt->vi.i==(n/2)) sauvedata(tt,tt->ds.sommeB);
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 |
|
---|
| 301 | void sauvedata(tmtc* tt,long * somme_ds)
|
---|
| 302 | {
|
---|
| 303 | int j,u;
|
---|
| 304 |
|
---|
| 305 | tt->vi.temps_cntl ++;
|
---|
| 306 |
|
---|
| 307 |
|
---|
| 308 | //------------------ ecrit table telemesure tm
|
---|
| 309 | u=tt->tm.pos_ecrit;
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | tt->tm.btm[u].temps_cntl[tt->vi.pos_block_tm]=tt->vi.temps_cntl;
|
---|
| 313 | GetDateTime(&tt->tm.btm[u].temps_mac[tt->vi.pos_block_tm]);
|
---|
| 314 |
|
---|
| 315 | tt->tm.btm[u].chauf_regul=tt->vi.reg.cc;
|
---|
| 316 |
|
---|
| 317 |
|
---|
| 318 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 319 | {
|
---|
| 320 | if( (!parametr.bolo[j].bolo_bebo) ou !parametr.bolo[j].bolo_num )
|
---|
| 321 | { // pour une MLPA ou voie 0 d'une BEBO
|
---|
| 322 | tt->tm.btm[u].don[tt->vi.pos_block_tm].don_bolo[j] = (somme_ds[j]<<4) / (long)tt->ds.dsnorme;
|
---|
| 323 | }
|
---|
| 324 | else
|
---|
| 325 | { // pour une BEBO
|
---|
| 326 | // données dans tt->tb.x -> +-22 bits au maxi pour dsnorme= 128 ( nb total de points / periode )
|
---|
| 327 | // apres division (128=7bits), reste +-15 bit soit un entier short signé
|
---|
| 328 | tt->tm.btm[u].don[tt->vi.pos_block_tm].don_bolo[j] = somme_ds[j] / (long)tt->ds.dsnorme;
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | for(j=0;j<nb_sync;j++) tt->tm.btm[u].don[tt->vi.pos_block_tm].sync[j]=tt->vi.synchro[j];
|
---|
| 333 |
|
---|
| 334 | tt->signal_scan_immediat=tt->vi.synchro[sync_scan];
|
---|
| 335 | tt->vi.pos_block_tm++;
|
---|
| 336 |
|
---|
| 337 | if(tt->vi.pos_block_tm>=nb_per_block*2) // a la fin d'un block de telemesure
|
---|
| 338 | {
|
---|
| 339 | tt->tm.btm[u].reglage=tt->reglage; // copie l'etat bolo courant
|
---|
| 340 |
|
---|
| 341 | tt->vi.pos_block_tm=0;
|
---|
| 342 |
|
---|
| 343 |
|
---|
| 344 |
|
---|
| 345 | u++; if(u>=longueur_table_tm) u=0;
|
---|
| 346 | tt->tm.pos_ecrit=u;
|
---|
| 347 |
|
---|
| 348 | if(tt->tm.pos_ecrit==tt->tm.pos_lit) ecrit_erreur(err_pile_pleine);
|
---|
| 349 |
|
---|
| 350 | }
|
---|
| 351 | //------------------ fin ecriture table telemesure tm
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 | tt->vi.reg.valeur+=somme_ds[tt->vi.reg.pid.num_bolo-1]; // integration de la valeur pour la regul
|
---|
| 355 |
|
---|
| 356 |
|
---|
| 357 | for(j=0;j<nb_max_bolo;j++) somme_ds[j]=0; // raz table données pour la suite
|
---|
| 358 | for(j=0;j<nb_sync;j++) tt->vi.synchro[j]=0; // raz table des synchro pour la suite
|
---|
| 359 | for(j=0;j<nb_max_bolo;j++) tt->tm.btm[u].flag_bolo[j]=0;
|
---|
| 360 |
|
---|
| 361 |
|
---|
| 362 |
|
---|
| 363 | raz_periodique(tt);
|
---|
| 364 | regul(tt);
|
---|
| 365 | decode_telecommande(tt);
|
---|
| 366 |
|
---|
| 367 | tt->vi.flag_ecriture_data++; // bon pour envoi
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 |
|
---|
| 371 | //*****************************************************************************************
|
---|
| 372 | // ***
|
---|
| 373 | #endif //-------------------------------------------------------------------- ***
|
---|
| 374 | // ***
|
---|
| 375 | //*****************************************************************************************
|
---|
| 376 |
|
---|