Example #1
0
int main(int argc, char** argv) {

    int id = 0;
	fpga_t * fpga = fpga_open(0);
    const int chnl = 0;
    if (fpga == NULL) {
        fprintf(stderr, "ERROR: can't open fpga with id:%d\n", id);
        exit(-1);
    }

    int arg0[128] = {};
    int size = 8;

    char * buf = (char *)(arg0 + 1);
    printf("User base address: %p\n", buf);

    unsigned int rh[] = {
        0x20000000,
        size,
        0x0000ffff,
        0x30000000
    };

    // Send Request Header to initiate TX transfer
    int sent = fpga_send(fpga, chnl, &rh, sizeof(rh) / sizeof(int), -1, 1, 25000);
    assert(sent == 4);

    // Copy Data to user buffer
    int recv = fpga_recv(fpga, chnl, buf, size, 25000);

    print(buf, recv);

    return 0;
}
Example #2
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);
}
Example #3
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;
}
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;
}
Example #5
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;
}
Example #6
0
int main(void)
{
	int i, fp_id, num_bytes, pagesize, buf_size, memali;
	const char *loadfile = "top.bin.ufp";
	err_e err, e;
	void * bp;
	u_64 val;
	long long data[2][1024];
	char line_in[256];
	FILE* file;
	char* filename;  
	int k;

	printf("Start program\n");

	filename="mas_input_int32.New.txt";
	file = fopen(filename, "r");
	if (file == NULL)
	{
		printf ("ERROR: Could not open input file %s for reading.\n", filename);
		return(-1);
	}

	k=0;
	while(fgets(line_in, 255, file) != NULL)
	{
		sscanf(line_in,"%ld %ld", &data[0][k],&data[1][k]);
		if(data[0][k]<0) data[0][k]=-1*data[0][k];
		if(data[1][k]<0) data[1][k]=-1*data[1][k];
		if(k<5) printf("Data read = %d %d %d\n", k, data[0][k], data[1][k]);
		k++;
	}

	// Set FPGA ready
	fp_id = fpga_open("/dev/ufp0", O_RDWR|O_SYNC, &e);
	num_bytes = fpga_load(fp_id, loadfile, &err);
	fpga_reset(fp_id, &e);
	fpga_start(fp_id, &e);

	// Set RAMS ready
	rams[0] = fpga_memmap(fp_id, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, MEM_OFFSET + 0*MEM_DISTANCE, &e);
	rams[1] = fpga_memmap(fp_id, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, MEM_OFFSET + 1*MEM_DISTANCE, &e);
	rams[2] = fpga_memmap(fp_id, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, MEM_OFFSET + 2*MEM_DISTANCE, &e);
	rams[3] = fpga_memmap(fp_id, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, MEM_OFFSET + 3*MEM_DISTANCE, &e);
  
	// Initalize vectors and input data on rams
	u_64 word0 = (u_64) data[0][0];
	u_64 word1 = (u_64) data[1][0];
	u_64 word2 = 0;
	u_64 *word_0 = rams[0];
	u_64 *word_1 = rams[1];
	u_64 *word_2 = rams[2];
	for( i = 0; i < 128; i++)
    {
		*word_0 ++= (u_64) data[0][i];
		*word_1 ++= (u_64) data[1][i];
		*word_2 ++= 0;
	}

	// Set memory for FPGA use
	pagesize = getpagesize();
	buf_size = ((128*1024*1024 + (pagesize - 1)) / pagesize) * pagesize;
	memali   = posix_memalign(&bp, pagesize, buf_size);
	fpga_register_ftrmem(fp_id, bp, buf_size, &e);
	ftr_mem = bp;

	// Setup Mitrion run
	void * addr = ftr_mem;
	fpga_wrt_appif_val(fp_id, 0x00000000000000001UL, (0x01*sizeof(u_64)) + 0, TYPE_VAL, &e);
	fpga_wrt_appif_val(fp_id, 88, ((0x40+1)*sizeof(u_64)), TYPE_VAL, &e);
	fpga_wrt_appif_val(fp_id, (u_64)addr, (0x40*sizeof(u_64)), TYPE_ADDR, &e);
	fpga_wrt_appif_val(fp_id, 0x000000000000000000UL, (0x02 * sizeof(u_64)), TYPE_VAL, &e);
	fpga_wrt_appif_val(fp_id, 0x000000000000000000UL, (0x01 * sizeof(u_64)), TYPE_VAL, &e);

	// Loop and wait until FPGA calculation is done
	do
	{
		fpga_rd_appif_val(fp_id, (void*)&val, (0x02 * sizeof(u_64)), &e);
	} while((val&1) == 0);

	// Print the final result 
	u_64 * word_dst = rams[3];
	u_64 wordp = *word_dst;
	for(i = 0;i < 128; i++)
	{
		wordp = *word_dst;
		word_dst++;
		printf("FPGA %d: %d + %d = %ld\n", i, data[0][i], data[1][i], wordp);
	}

	printf("End of program ");
	return 0;
}