/**********************************************/ /* */ /* Text for CAMAC with PPI */ /* */ /* #include "camlib.h" */ /* */ /**********************************************/ #include #include #define PPIWH 0x241 #define PPIWL 0x242 #define PPIA 0x243 #define PPIF 0x244 #define PPIN 0x245 #define PPII 0x246 #define PPIC 0x247 #define PPIXQ 0x248 #define PPIRH 0x24a #define PPIRL 0x24b #define PPIS 0x24c #define PPICR 0x24f /***** CAMAC functions ****************/ void crate ( int nc ) { /* Camac Initialisation */ outportb ( PPICR, (nc&3)<<4 ); } int naf ( int n, int a, int f, long *d ) { int xq; if ( (f>=16) && (f<24) ) { outportb ( PPIN, 0 ); /* High byte */ outportb ( PPIA, 2 ); outportb ( PPIF, 16 ); outportb ( PPIWL, *d >> 16 ); outportb ( PPIC, 0 ); while ( !(inportb ( PPIS )&1 )); } outportb ( PPIN, n ); outportb ( PPIA, a ); outportb ( PPIF, f ); if ( (f>=16) && (f<24) ) { outportb ( PPIWL, *d ); outportb ( PPIWH, *d >> 8 ); } outportb ( PPIC, 0 ); while ( !(inportb ( PPIS )&1 )); if ( f < 7 ) { /* Read */ *d = (long)inportb ( PPIRL ) & 0xff; *d |= ( (long)inportb ( PPIRH ) & 0xff ) << 8; } xq = inportb ( PPIXQ ) & 3; if ( f < 7 ) { /* Read */ outportb ( PPIN, 0 ); /* High byte */ outportb ( PPIA, 2 ); outportb ( PPIF, 0 ); outportb ( PPIC, 0 ); while ( !(inportb ( PPIS )&1 )); *d |= ( (long)inportb ( PPIRL ) & 0xff ) << 16; } return ( xq ); } int nafw ( int n, int a, int f, long d ) { return ( naf ( n, a, f, &d ) ); } int nafd ( int n, int a, int f ) { long d; return ( naf ( n, a, f, &d ) ); } int testlam ( int n ) { /* Test L po F(8) */ return ( nafd ( n, 0, 8 ) & 1 ); } int waitlam ( int n, int t ) { /* Test L po F(8) */ /* Waiting for LAM Return 0 if LAM, -1 if Timeout */ long ti; ti = clock(); while ( clock() < (ti+ (t*CLK_TCK))) { if ( !testlam (n) ) continue; return (0); } return ( -1 ); } void cam_z ( void ) { nafw ( 0, 0, 16, 0x200 ); } void cam_c ( void ) { nafw ( 0, 0, 16, 0x100 ); } void cam_i ( int i ) { outportb ( PPII, i<<2 ); nafd ( 1, 0, 0 ); } /****** Быстрый NAF **** Only 16 bit !!! **/ static int _f; void nafset ( int n, int a, int f ) { outportb ( PPIN, n ); outportb ( PPIA, a ); outportb ( PPIF, f );_f=f; } void nafdo ( long *d ) { if ( (_f>=16) && (_f<24) ) { outportb ( PPIWL, *d ); outportb ( PPIWH, *d >> 8 ); } outportb ( PPIC, 0 ); while ( !(inportb ( PPIS )&1 )); if ( _f < 7 ) { *d = (long)inportb ( PPIRL ) & 0xff; *d |= ( (long)inportb ( PPIRH ) & 0xff ) << 8; } }