/* * veto.c * Creation date: Nov 13 2000 * Author: Y.Nakaune */ #include #include #include #include "vmelib.h" #include "buf.h" #include "intreg.h" /*---------------------------------------------------------- InitVETO ---------------------------------------------------------*/ void InitVETO( void ) { volatile caddr_t vaddr; vaddr = vme_mapopen( VME_A16D16MODE, INTREG_ADDR, INTREG_SIZE ); if( (int)vaddr == -1 ) exit_err( "Intreg cannot open!" ); fprintf( stderr, "IntReg: memory map opened: %p\n", vaddr ); ir = (IntReg *)vaddr; } /*---------------------------------------------------------- CheckTrigger ---------------------------------------------------------*/ int CheckTrigger( void ) { #define COUNT_MAX 1000000 #define WAIT_TIME 1 #define WAIT_MAX 10000 unsigned char c; int count, w_count; w_count = WAIT_MAX; count = COUNT_MAX; c = ir->csr[0]; while ((c & 0x20) ==0) { count -=1; if (count<0) { w_count -=1; if (w_count<0) { return -1; } else if (w_count%10 == 0) { fprintf(stderr,"WAIT trigger \007 \007 \n"); } usleep(WAIT_TIME); count = COUNT_MAX; } c = ir->csr[0]; } return 0; } /*---------------------------------------------------------- ClearVETO ---------------------------------------------------------*/ void ClearVETO( void ) { unsigned char c; c = ir->csr[0]; c |= 0x2; ir->csr[0] = c; } /*---------------------------------------------------------- EndVETO ---------------------------------------------------------*/ void EndVETO(void) { vme_mapclose( INTREG_ADDR, VME_A16D16MODE ); } /*---------------------------------------------------------- OffSpillSleep() ---------------------------------------------------------*/ int OffSpillSleep( void ) { unsigned char c; c = ir->csr[1]; if( c & 0x20) { printf("\007 "); usleep( SLEEP_TIME ); c |= 0x02; ir->csr[1] = c; c |= 0x02; ir->csr[1] = c; } else { return 0; } return 1; }