/********************************************************************* @file Name: v792.c Created by: Pierre-Andre Amaudruz Contributors: Sergio Ballestrero Contents: V792 32ch. QDC V785 32ch. Peak ADC include V792 and V785 are mostly identical; v792_ identifies commands supported by both v792_ identifies commands supported by V792 only v785_ identifies commands supported by V785 only $Id$ *********************************************************************/ #include #include #include #if defined(OS_LINUX) #include #endif #include "v792.h" WORD v792_Read16(MVME_INTERFACE *mvme, DWORD base, int offset) { mvme_set_dmode(mvme, MVME_DMODE_D16); return mvme_read_value(mvme, base+offset); } void v792_Write16(MVME_INTERFACE *mvme, DWORD base, int offset, WORD value) { mvme_set_dmode(mvme, MVME_DMODE_D16); mvme_write_value(mvme, base+offset, value); } /*****************************************************************/ /* Read single event, return event length (number of entries) Uses single vme access! (1us/D32) */ int v792_EventRead(MVME_INTERFACE *mvme, DWORD base, DWORD *pdest, int *nentry) { DWORD hdata; int cmode; mvme_get_dmode(mvme, &cmode); mvme_set_dmode(mvme, MVME_DMODE_D32); *nentry = 0; if (v792_DataReady(mvme, base)) { do { hdata = mvme_read_value(mvme, base); } while (!(hdata & 0x02000000)); // skip up to the header pdest[*nentry] = hdata; *nentry += 1; do { pdest[*nentry] = mvme_read_value(mvme, base); *nentry += 1; } while (!(pdest[*nentry-1] & 0x04000000)); // copy until the trailer nentry--; } mvme_set_dmode(mvme, cmode); return *nentry; } /*****************************************************************/ /* Read nentry of data from the data buffer. Will use the DMA engine if size is larger than 127 bytes. */ int v792_DataRead(MVME_INTERFACE *mvme, DWORD base, DWORD *pdest, int *nentry) { int cmode; mvme_get_dmode(mvme, &cmode); mvme_set_dmode(mvme, MVME_DMODE_D32); *nentry = 128; if (v792_DataReady(mvme, base)) { mvme_read(mvme, pdest, base, *nentry*4); } mvme_set_dmode(mvme, cmode); return *nentry; } /*****************************************************************/ /** * Write Thresholds and read them back */ int v792_ThresholdWrite(MVME_INTERFACE *mvme, DWORD base, WORD *threshold) { int k, cmode; mvme_get_dmode(mvme, &cmode); mvme_set_dmode(mvme, MVME_DMODE_D16); for (k=0; k> 4; printf("Daughter card type (CSEL/DSEL) :%d%d%d%d (0x%x) ", status & 0x80 ? 1 : 0, status & 0x40 ? 1 : 0, status & 0x20 ? 1 : 0, status & 0x10 ? 1 : 0, dtype); switch (dtype) { default: printf("\n"); break; case 2: printf("V792 32ch QDC\n"); break; } status = v792_BitSet2Read(mvme, base); printf("BitSet2: 0x%x\n", status); printf("Test Mem :%s\t", status & 0x1 ? "Y" : "N"); printf(" - Offline :%s\t", status & 0x2 ? "Y" : "N"); printf(" - Clear Data :%s\n", status & 0x4 ? "Y" : "N"); printf("Over Range En:%s\t", status & 0x8 ? "Y" : "N"); printf(" - Low Thres En :%s\t", status & 0x10 ? "Y" : "N"); printf(" - Auto Incr :%s\n", status & 0x20 ? "Y" : "N"); printf("Empty Enable :%s\t", status & 0x1000 ? "Y" : "N"); printf(" - Slide sub En :%s\t", status & 0x2000 ? "Y" : "N"); printf(" - All Triggers :%s\n", status & 0x4000 ? "Y" : "N"); v792_EvtCntRead(mvme, base, &status); printf("Event counter: %d\n", status); printf("Iped value: %d\n", v792_Read16(mvme, base, V792_IPED_RW)); v792_ThresholdRead(mvme, base, threshold); for (i=0;idata.type) { case v792_typeMeasurement: printf("Data=0x%08x Measurement ch=%3d v=%6d over=%1d under=%1d\n", (int)v->raw,v->data.channel,v->data.adc,v->data.ov,v->data.un); break; case v792_typeHeader: printf("Data=0x%08x Header geo=%2x crate=%2x cnt=%2d\n", (int)v->raw,v->header.geo,v->header.crate,v->header.cnt); break; case v792_typeFooter: printf("Data=0x%08x Footer geo=%2x evtCnt=%7d\n", (int)v->raw,v->footer.geo,v->footer.evtCnt); break; case v792_typeFiller: printf("Data=0x%08x Filler\n",(int)v->raw); break; default: printf("Data=0x%08x Unknown %04x\n",(int)v->raw,v->data.type); break; } } /*****************************************************************/ int v792_isPresent(MVME_INTERFACE *mvme, DWORD base) { int status, cmode; mvme_get_dmode(mvme, &cmode); mvme_set_dmode(mvme, MVME_DMODE_D16); status = mvme_read_value(mvme, base+V792_FIRM_REV); mvme_set_dmode(mvme, cmode); if (status == 0xFFFF) return 0; else return 1; } /*****************************************************************/ /*-PAA- For test purpose only */ #ifdef MAIN_ENABLE int main (int argc, char* argv[]) { DWORD VMEIO_BASE = 0x780000; DWORD V792_BASE = 0x500000; MVME_INTERFACE *myvme; int status, csr, i; DWORD cnt; DWORD dest[1000]; WORD threshold[32]; if (argc>1) { sscanf(argv[1],"%lx",&V792_BASE); } // Test under vmic status = mvme_open(&myvme, 0); // Set am to A24 non-privileged Data mvme_set_am(myvme, MVME_AM_A24_ND); // Set dmode to D32 mvme_set_dmode(myvme, MVME_DMODE_D32); v792_SingleShotReset(myvme, V792_BASE); for (i=0;i