Exemplo n.º 1
0
int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        fprintf(stderr, "Supply data record file \n");
        return(1);
    }
    long *QRSdelay;
    QRSdelay = (long *) malloc(sizeof(long));
    FILE* frec = fopen(argv[1], "r");
    FILE* fout = fopen("delay.txt", "w");
    if (frec == NULL)
    {
        fprintf(stderr, "could not open the record file %s\n", argv[1]);
        return(1);
    }
    fpga = fpga_open(0);
    fpga_reset(fpga);
    long *datum;
    datum = (long *) malloc(sizeof(long));
    int sampleSent, recv;
    sampleSent = fpga_send(fpga, 0, datum, 2, 0, 1, 0);
    recv = fpga_recv(fpga, 0, QRSdelay, 2, 0);
    fscanf(frec, "%ld", datum);
    long count = 1;
    while(!feof(frec))
    {
        count++;
        sampleSent = fpga_send(fpga,0,datum,1, 0, 1, 1000);
        if (sampleSent < 1)
        {
            printf("in loop # %ld, the data sample was not sent", count);
            break;
        }
        recv  = fpga_recv(fpga, 0, QRSdelay, 1, 1000);
        if (recv < 1)
        {
            printf("in loop # %ld, the delay output was not received", count);
            break;
        }
        if (*QRSdelay != 0)
        {
            fprintf(fout, "%ld, ", *QRSdelay);
            fprintf(fout, "%ld\n", count);
        }
        fscanf(frec, "%ld", datum);
    }
    fclose(frec);
    fclose(fout);
    fpga_close(fpga);
    return (0);
}
Exemplo n.º 2
0
int main(int argc, char** argv) {
	fpga_t * fpga;
	fpga_info_list info;
	int option;
	int i;
	int id;
	int chnl;
	size_t numWords;
	int sent;
	int recvd;
	unsigned int * sendBuffer;
	unsigned int * recvBuffer;
	GET_TIME_INIT(3);

	if (argc < 2) {
		printf("Usage: %s <option>\n", argv[0]);
		return -1;
	}

	option = atoi(argv[1]);

	if (option == 0) {	// List FPGA info
		// Populate the fpga_info_list struct
		if (fpga_list(&info) != 0) {
			printf("Error populating fpga_info_list\n");
			return -1;
		}
		printf("Number of devices: %d\n", info.num_fpgas);
		for (i = 0; i < info.num_fpgas; i++) {
			printf("%d: id:%d\n", i, info.id[i]);
			printf("%d: num_chnls:%d\n", i, info.num_chnls[i]);
			printf("%d: name:%s\n", i, info.name[i]);
			printf("%d: vendor id:%04X\n", i, info.vendor_id[i]);
			printf("%d: device id:%04X\n", i, info.device_id[i]);
		}
	}
	else if (option == 1) { // Reset FPGA
		if (argc < 3) {
			printf("Usage: %s %d <fpga id>\n", argv[0], option);
			return -1;
		}

		id = atoi(argv[2]);

		// Get the device with id
		fpga = fpga_open(id);
		if (fpga == NULL) {
			printf("Could not get FPGA %d\n", id);
			return -1;
	    }

		// Reset
		fpga_reset(fpga);

		// Done with device
        fpga_close(fpga);
	}
	else if (option == 2) { // Send data, receive data
		if (argc < 5) {
			printf("Usage: %s %d <fpga id> <chnl> <num words to transfer>\n", argv[0], option);
			return -1;
		}

		id = atoi(argv[2]);
		chnl = atoi(argv[3]);
		numWords = atoi(argv[4]);

		// Get the device with id
		fpga = fpga_open(id);
		if (fpga == NULL) {
			printf("Could not get FPGA %d\n", id);
			return -1;
	    }

		// Malloc the arrays
		sendBuffer = (unsigned int *)malloc(numWords<<2);
		if (sendBuffer == NULL) {
			printf("Could not malloc memory for sendBuffer\n");
			fpga_close(fpga);
			return -1;
	    }
		recvBuffer = (unsigned int *)malloc(numWords<<2);
		if (recvBuffer == NULL) {
			printf("Could not malloc memory for recvBuffer\n");
			free(sendBuffer);
			fpga_close(fpga);
			return -1;
	    }

		// Initialize the data
		for (i = 0; i < numWords; i++) {
			sendBuffer[i] = i+1;
			recvBuffer[i] = 0;
		}

		GET_TIME_VAL(0);

		// Send the data
		sent = fpga_send(fpga, chnl, sendBuffer, numWords, 0, 1, 25000);
		printf("words sent: %d\n", sent);

		GET_TIME_VAL(1);

		if (sent != 0) {
			// Recv the data
			recvd = fpga_recv(fpga, chnl, recvBuffer, numWords, 25000);
			printf("words recv: %d\n", recvd);
		}

		GET_TIME_VAL(2);

		// Done with device
        fpga_close(fpga);

		// Display some data
		for (i = 0; i < 20; i++) {
			printf("recvBuffer[%d]: %d\n", i, recvBuffer[i]);
		}

		// Check the data
		if (recvd != 0) {
			for (i = 4; i < recvd; i++) {
				if (recvBuffer[i] != sendBuffer[i]) {
					printf("recvBuffer[%d]: %d, expected %d\n", i, recvBuffer[i], sendBuffer[i]);
					break;
				}
			}

			printf("send bw: %f MB/s %fms\n",
				sent*4.0/1024/1024/((TIME_VAL_TO_MS(1) - TIME_VAL_TO_MS(0))/1000.0),
				(TIME_VAL_TO_MS(1) - TIME_VAL_TO_MS(0)) );

			printf("recv bw: %f MB/s %fms\n",
				recvd*4.0/1024/1024/((TIME_VAL_TO_MS(2) - TIME_VAL_TO_MS(1))/1000.0),
				(TIME_VAL_TO_MS(2) - TIME_VAL_TO_MS(1)) );
		}
	}

	return 0;
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
	struct timeval start, end;
	long secs_used,micros_used;
	int channel=1;
	int boardNo=0;
	int rounds=0;
	struct boardHandle board;

	char bufferPath[128];
	void* buffer;
	int filepointer;
	int bufferNo = 0;

	struct packetInfo packetInfo;
	struct memoryInfo memoryInfo;

	int error;

	//for(int i=0;i<1024;i++)
	//	senddata[i] = i;

	if(argc>1) {
		channel = atoi(argv[1]);
	}

	if(argc>2) {
		boardNo = atoi(argv[2]);
	}

	if(argc>3) {
		rounds = atoi(argv[3]);
	}

	if(argc==1) {
		printf("Usage: %s[ channel[ board[ rounds]]]\n\n", argv[0]);
		//sleep(5);
	}

	printf("BOARD[CHANNEL]: %d[%d] @ %d Rounds\n\n", boardNo, channel, rounds);

	if(error = posix_memalign(&buffer, 4096, DATA_POINTS)) {
		//std::cout << "Could not get a page." << std::endl;
		return error;
	}

	memoryInfo.start = buffer;
	memoryInfo.size  = DATA_POINTS;

	board = fpga_open(boardNo);

	fpga_dma_pin(board, &memoryInfo);
	fpga_dma_map(board, (struct dmaPage*)memoryInfo.pageHandle);

	packetInfo.pageHandle = memoryInfo.pageHandle;
	packetInfo.size = DATA_POINTS;
	packetInfo.channel = channel;

	while(argc<4 || rounds--) {
		gettimeofday(&start, NULL);
		//fpga_send_data(board, channel,(unsigned char *) senddata,DATA_POINTS);
		fpga_dma_receive(board, &packetInfo);
		fpga_wait_page(board, (struct dmaPage*)packetInfo.pageHandle);
		gettimeofday(&end, NULL);
		secs_used=(end.tv_sec - start.tv_sec); //avoid overflow by subtracting first
		micros_used= ((secs_used*1000000) + end.tv_usec) - (start.tv_usec);
		printf("micros_used: %ld\n",micros_used);
		printf("Throughput %f MBytes/sec\n",DATA_POINTS*1.0/micros_used);
	}

	fpga_close(board);

	fpga_dma_unmap(board, (struct dmaPage*)memoryInfo.pageHandle);
	fpga_dma_unpin(board, (struct dmaPage*)memoryInfo.pageHandle);

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char** argv) {
	fpga_t * fpga;
	fpga_info_list info;
	int option;
	int i;
	int id;
	int chnl;
	int ch_size;
	size_t numWords, numLoops, remWords;
	int sent;
	int recvd;
	int failure = 0;
	//unsigned int * sendBuffer;
	//unsigned int * recvBuffer;
	int err;
	int idx,jdx,k;
	GET_TIME_INIT(3);

	if (argc < 2) {
		printf("Usage: %s <option>\n", argv[0]);
		return -1;
	}

	option = atoi(argv[1]);

	if (option == 0) {
		// List FPGA info
		// Populate the fpga_info_list struct
		if (fpga_list(&info) != 0) {
			printf("Error populating fpga_info_list\n");
			return -1;
		}
		printf("Number of devices: %d\n", info.num_fpgas);
		for (i = 0; i < info.num_fpgas; i++) {
			printf("%d: id:%d\n", i, info.id[i]);
			printf("%d: num_chnls:%d\n", i, info.num_chnls[i]);
			printf("%d: name:%s\n", i, info.name[i]);
			printf("%d: vendor id:%04X\n", i, info.vendor_id[i]);
			printf("%d: device id:%04X\n", i, info.device_id[i]);
		}
	}
	else if (option == 1) { // Reset FPGA
		if (argc < 3) {
			printf("Usage: %s %d <fpga id>\n", argv[0], option);
			return -1;
		}

		id = atoi(argv[2]);

		// Get the device with id
		fpga = fpga_open(id);
		if (fpga == NULL) {
			printf("Could not get FPGA %d\n", id);
			return -1;
		}

		// Reset
		fpga_reset(fpga);

		// Done with device
		fpga_close(fpga);
	}
	else if (option == 2) { // Send data, receive data
		if (argc < 5) {
			printf("Usage: %s %d <fpga id> <chnl> <channel size in channel tester in bytes> <num words to transfer>\n", argv[0], option);
			return -1;
		}

		//size_t maxWords, minWords;
		id = atoi(argv[2]);
		chnl = atoi(argv[3]);
		//numWords = atoi(argv[5]);
		ch_size = atoi(argv[4]);
		numLoops = 1;
		//remWords = numWords%ch_size;
		// Get the device with id
		fpga = fpga_open(id);
		//uint64_t result[ch_size];
		if (fpga == NULL) {
			printf("Could not get FPGA %d\n", id);
			return -1;
		}

		
		
		k=0;
		sent_values[0] = 0x8000000000000000;
		sent_values[1] = 0x0000000000000000;
		for (idx =2; idx<256; idx=idx+2){
			sent_values[idx]=sent_values[idx-2];
			sent_values[idx+1]=sent_values[idx-1]; 
			if(sent_values[idx+k-2]==0xffffffffffffffff){
				k++;
				sent_values[idx+k]= 0x8000000000000000;
			}
			else
				sent_values[idx+k] = sent_values[idx+k]|(sent_values[idx+k]/2);
		}
		for (idx =0; idx<1024; idx++)
			sent_values[idx+256]=sent_values[idx]; 
		
		//for (idx =0; idx<chsize/2; idx=idx+2)
		//	printf("\n%d: %16llx%16llx",idx,sent_values[idx],sent_values[idx+1]);
		
		//printf("loops = %d",numLoops);
		
			GET_TIME_VAL(0);
			sent = fpga_send(fpga, chnl, sent_values, ch_size, 0, 1, 25000);
			recvd = fpga_recv(fpga, chnl, result, ch_size, 25000);
			GET_TIME_VAL(1);
			
			for (k =0; k<ch_size/2; k=k+2)
				printf("\n%16llx%16llx",result[k],result[k+1]);
			
		
			
		
		//for (idx =0; idx<256; idx=idx+2)
		//	printf("\n%16llx%16llx",result[idx],result[idx+1]);
		
		printf("\ntime taken (latency) : %f ms, N= %d \n",(TIME_VAL_TO_MS(1) - TIME_VAL_TO_MS(0)),numWords);
		//printf("avg time taken by 1 set of data : %f ms\n",((TIME_VAL_TO_MS(1) - TIME_VAL_TO_MS(0)))/numWords);
		// Done with device
	        fpga_close(fpga);
	}
	else if (option == 3) { // Send data, receive data
		if (argc < 6) {
			printf("Usage: %s %d <fpga id> <chnl> <out channel size in channel tester in bytes> <num inputs to transfer>\n", argv[0], option);
			return -1;
		}

		//size_t maxWords, minWords;
		id = atoi(argv[2]);
		chnl = atoi(argv[3]);
		/////numWords: no. words of size 32 bits.
		////numInputs: no. of inputs of length 128 bits. 
		int numInputs = atoi(argv[5]);
		numWords = numInputs*4;
		ch_size = atoi(argv[4]);
		numLoops = numWords/ch_size;
		//remWords = numWords%ch_size;
		// Get the device with id
		fpga = fpga_open(id);
		//uint64_t result[ch_size];
		if (fpga == NULL) {
			printf("Could not get FPGA %d\n", id);
			return -1;
		}

		
		
		k=0;
		sent_values[0] = 0x8000000000000000;
		sent_values[1] = 0x0000000000000000;
		for (idx =2; idx<256; idx=idx+2){
			sent_values[idx]=sent_values[idx-2];
			sent_values[idx+1]=sent_values[idx-1]; 
			if(sent_values[idx+k-2]==0xffffffffffffffff){
				k++;
				sent_values[idx+k]= 0x8000000000000000;
			}
			else
				sent_values[idx+k] = sent_values[idx+k]|(sent_values[idx+k]/2);
		}
		for (idx =0; idx<1024; idx++)
			sent_values[idx+256]=sent_values[idx]; 
		
		//for (idx =0; idx<128; idx=idx+2)
		//	printf("\n%d: %16llx%16llx",idx,sent_values[idx],sent_values[idx+1]);
		
		//printf("loops = %d",numLoops);
		
		GET_TIME_VAL(0);
		for(idx = 0; idx < numLoops; idx++)
		{	
			sent = fpga_send(fpga, chnl, sent_values, ch_size, 0, 1, 25000);
			recvd = fpga_recv(fpga, chnl, result, ch_size, 25000);
			//for (k =0; k<128; k=k+2)
			//	printf("\n%d: %16llx%16llx",k,result[k],result[k+1]);
			
		}
			
		GET_TIME_VAL(1);
		//for (idx =0; idx<256; idx=idx+2)
		//	printf("\n%16llx%16llx",result[idx],result[idx+1]);
		
		printf("\ntime taken : %f ms, N= %d \n",(TIME_VAL_TO_MS(1) - TIME_VAL_TO_MS(0)),numInputs);
		printf("avg time taken by 1 set of data : %f ms\n",((TIME_VAL_TO_MS(1) - TIME_VAL_TO_MS(0)))/numInputs);
		// Done with device
	        fpga_close(fpga);
	}
	return 0;
}