Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PC to FPGA C++ connection

Status
Not open for further replies.

madalin1990

Full Member level 2
Joined
Apr 4, 2012
Messages
124
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,090
Hi!
I have a program that is supossed to send bits from a file saved in computer to a memory implemented on FPGA. There are two Depp functions used:DeppPutReg is used to specify the start address and DeppPutRegRepeat to copy the data from the file to the memory.
The logic implemented on the FPGA automatically increases the address after a bite is copied at a address. The problem is when i try 2 send 2 bytes the memory address increases by two instead of 16.

My question is what should i modify in the code below to make my HW read the bites correctly:
Code:
void DoPutRegs() {

	BYTE	idStartMemAddress;
	char *	szStop;
	long	cb;
	BYTE	rgbLd[cbBlockSize];
	int		cbSend, cbSendTotal, cbSendCheck;

	cb		=  strtol(szCount, &szStop, 10);
	idStartMemAddress = (BYTE) strtol(szAddressStart, &szStop, 10);
		
	
	if(!DeppPutReg(hif, HW_REG_MEM_ADDRESS, idStartMemAddress, fFalse)) {
		printf("DeppPutReg failed\n");
		return;
	}

	 fopen_s(&fhin, szFile, "r+b");
	if (fhin == NULL) {
		printf("Cannot open file\n");
		ErrorExit();
	}
	
// write the file into the data register
cbSendTotal = cb;
	cbSend = 0;

	while (cbSendTotal > 0) {

		if ((cbSendTotal - cbBlockSize) <= 0) {
			cbSend = cbSendTotal;
			cbSendTotal = 0;
		}
		else {
			cbSend = cbBlockSize;
			cbSendTotal -= cbBlockSize;
		}

		cbSendCheck = fread(rgbLd, sizeof(BYTE), cbSend, fhin);

		if (cbSendCheck != cbSend) {
			printf("Cannot read specified number of bytes from file.\n");
			ErrorExit();
		}

		// DEPP API Call: DeppPutRegRepeat
		if(!DeppPutRegRepeat(hif, HW_REG_MEM_DATA, rgbLd, cbSend, fFalse)){
			printf("DeppPutRegRepeat failed.\n");
			ErrorExit();
		}
				
	}
		printf("Stream to memory complete!\n");

	if( fhin != NULL ) {
		fclose(fhin);
	}

	return;
}
 

I have managed to find the error. It seems the .txt file save its elements in ASCII code.
My question now is: what type of file saves it's elements binary coded?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top