CAENVME_API parse_and_call_CAENVME_BLTReadCycle( char* arguments ){ // parse string, call CAENVMElib function CAENVME_API caen_api_return_value; uint32_t address; int size; // printf("Got arguments:\n%s\n", arguments); // sscanf (arguments, "%x", &address); // printf("Got address:\n%x\n", address); // parse address and the size of block char * pch; pch = strtok(arguments, " "); // blank space is the only delimeter in out case sscanf (pch, "%x", &address); sscanf (strtok(NULL, " "), "%d", &size); unsigned char * block_buffer; block_buffer = (unsigned char*)malloc(size); // size bytes in the buffer // memset(block_buffer, 0, sizeof(uint32_t)); int block_size = size; int count = 0; printf("Reading block @ %x address on VME of the size %x bytes\n(bridge handle ID = %d)\n", address, size, bridge_handler); caen_api_return_value = CAENVME_BLTReadCycle( bridge_handler, address, block_buffer, size, cvA32_U_BLT, cvD32, &count ); printf("Block read. %d bytes transfered\n", count); // for now, with -- cvD32 -- let's output to stdout four-byte lines for (int i = 0; i < count; i+=4) { // probably better to reverse the bytes: printf("%02x %02x %02x %02x\n", block_buffer[i+3], block_buffer[i+2], block_buffer[i+1], block_buffer[i]); } return caen_api_return_value; }
int main(int argc, char *argv[]) { /* if (argc!=2) return 1; else{ //uint16_t register_address = atoi(argv[1]); uint16_t register_address; sscanf(argv[1], "%x", ®ister_address); printf("Got register address: 0x%04x (decimal -- %d)\nStatus register:0x%04x\n", register_address, register_address, kStatus); */ VME::BridgeVx718 * fBridge = new VME::BridgeVx718("/dev/a2818_0", VME::CAEN_V2718); int32_t bridge_handle = fBridge->GetHandle(); printf("VME Bridge handle ID: %08x\n", bridge_handle); uint32_t tdcboard_base_address = 0x00aa0000; printf("CAEN TDC board baseaddress: %08x\n", tdcboard_base_address); // READING OutputBuffer uint32_t* fBuffer; fBuffer = (uint32_t *)malloc(16*1024*1024); // 16Mb of buffer! memset(fBuffer, 0, sizeof(uint32_t)); // fill the buffer with 0 const int blts = 1024; int count=0; CVErrorCodes ret; // am_blt = cvA32_U_BLT // while (1) { ret = CAENVME_BLTReadCycle(bridge_handle, tdcboard_base_address + kOutputBuffer, (char*)fBuffer, blts, cvA32_U_BLT, cvD32, &count); // ret printf("Output block:\n"); for (int i=0; i<count/4; i++) { // FIXME need to use the knowledge of the TDCEvent behaviour there... //TDCEvent ev(fBuffer[i]); //if (ev.GetType()==TDCEvent::Filler) continue; // Filter out filler data //ec.push_back(ev); printf("%08x\n", fBuffer[i]); } } // } }
void CaenVmeReadBlt(int32_t BHandle, man_par_t *man) { int nb; uint32_t i,j ; CVAddressModifier am; CVErrorCodes ret,old_ret=cvSuccess; if(man->am == cvA16_U) { con_printf(" Can't execute a A16 BLT Read Cycle"); return ; } if(man->am == cvCR_CSR) { con_printf(" Can't execute a CR/CSR BLT Read Cycle"); return ; } if (man->dtsize == cvD64) { if (man->am == cvA24_U_DATA) am = cvA24_U_MBLT; else am = cvA32_U_MBLT; } else { if (man->am == cvA24_U_DATA) am = cvA24_U_BLT; else am = cvA32_U_BLT; } if(man->ncyc == 0) // Infinite Loop con_printf_xy(X_COMM,Y_COMM+2," Running ... Press any key to stop."); for (i=0; ((man->ncyc==0) || (i<man->ncyc)) && !con_kbhit(); i++) { for (j=0;j<(man->blts/4);j++) man->buff[j]=0; ret = CAENVME_BLTReadCycle(BHandle,man->addr,(char *)man->buff,man->blts,am,man->dtsize,&nb); if((i==0) || (ret != old_ret)) { gotoxy(X_COMM,Y_COMM) ; switch (ret) { case cvSuccess : con_printf(" Cycle(s) completed normally\n"); con_printf(" Read %u bytes",nb); break ; case cvBusError : con_printf(" Bus Error !!!\n"); con_printf(" Read %u bytes",nb); break ; case cvCommError : con_printf(" Communication Error !!!"); break ; default : con_printf(" Unknown Error !!!"); break ; } } old_ret = ret; } if(man->ncyc == 0) clear_line(Y_COMM+2); }