/*---------- Subroutines for CAMAC ----------------*/ /* PPI AT-2, K0607 */ // A.N. Kirpotin. 12.01.1996. int inpw (int port); void outpw (int port, int cod); #define ccstat 0x250 #define cccmd 0x252 #define ccdata 0x254 #define ccpipe 0x256 #define ccncr0 0x2000 /* Crate #0 address. */ #define ccncr1 0x2200 /* Crate #1 address. */ #define ccread 0x1000 /* Read bit. */ int ccncr=0x2000, ccnaf=0x3010, ccf=0, ccdtl=0, ccdth=0; void camac_crate_select (int crate) {ccncr = (crate&1) ? ccncr1 : ccncr0;} void camac_cycle (void) { outpw (cccmd, ccncr); outpw (ccpipe, ccf&037); outpw (cccmd, ccncr+2); outpw (ccpipe, ccdth); outpw (cccmd, ccnaf); outpw (ccpipe, ccdtl);} /* Execute C. */ void camac_clear (void) {outpw (cccmd, ccncr); outpw (ccpipe, 0x100);} /* Execute Z. */ void camac_z (void) {outpw (cccmd, ccncr); outpw (ccpipe, 0x200);} void camac_qx (int *q, int *x) { int stat = inpw (ccstat); *q=0; *x=0; if (!(stat&02000)) (*q)++; if (!(stat&04000)) (*x)++;} int camac_naf (int c, int n, int a, int f, int *q) {int x; ccncr=(c&1)?ccncr1:ccncr0; ccnaf=((n&037)<<4)|(a&017)|ccncr; outpw (cccmd, ccncr); outpw (ccpipe, f&037); outpw (cccmd, ccnaf); outpw (ccpipe, 0); ccf=f; camac_qx (q, &x); return x;} int camac_nafw2 (int c, int n, int a, int f, long data, int *q) { int x; ccncr=(c&1)?ccncr1:ccncr0; ccnaf=((n&037)<<4)|(a&017)|ccncr; outpw (cccmd, ccncr); outpw (ccpipe, f&037); ccdtl = (int)data; ccdth = 0; outpw (cccmd, ccnaf); outpw (ccpipe, ccdtl); ccf=f; camac_qx (q, &x); return x;} int camac_nafw3 (int c, int n, int a, int f, long data, int *q) {union li2 {long l; int i[2];} d; int x; ccncr=(c&1)?ccncr1:ccncr0; ccnaf=((n&037)<<4)|(a&017)|ccncr; d.l = data; outpw (cccmd, ccncr); outpw (ccpipe, f&037); outpw (cccmd, ccncr+2); outpw (ccpipe, d.i[1]); outpw (cccmd, ccnaf); outpw (ccpipe, d.i[0]); ccf=f; ccdtl=d.i[0]; ccdth=d.i[1]; camac_qx (q, &x); return x;} int camac_nafr2 (int c, int n, int a, int f, long *data, int *q) { int x; ccncr=(c&1)?ccncr1:ccncr0; ccnaf=(((n&037)<<4)|(a&017)|ccncr)|ccread; outpw (cccmd, ccncr); outpw (ccpipe, f&037); outpw (cccmd, ccnaf); inpw (ccpipe); x = inpw (ccdata); *data = (long)x; ccf=f; camac_qx (q, &x); return x;} int camac_nafr3 (int c, int n, int a, int f, long *data, int *q) {union li2 {long l; int i[2];} d; int x; ccncr=(c&1)?ccncr1:ccncr0; ccnaf=(((n&037)<<4)|(a&017)|ccncr)|ccread; outpw (cccmd, ccncr); outpw (ccpipe, f&037); outpw (cccmd, ccnaf); inpw (ccpipe); d.i[0] = inpw (ccdata); camac_qx (q, &x); outpw (cccmd, ((ccncr+2)|ccread)); inpw (ccpipe); d.i[1] = inpw (ccdata); d.i[1] &= 0377; ccf=f; *data = d.l; return x;}