Writing data to FPGA FIFO from host program

Questions and discussions about the Xillybus IP core and drivers

Writing data to FPGA FIFO from host program

Postby Cristian8 »

We are having issues with transferring our program data to the FIFO on the FPGA. The FIFO is not receiving the correct data from the program. We tested our Verilog code by hard coding the data into the FIFO and we received the correct data output results. However, when we replace the hard coded data input to the FIFO with the host program data wire, user_w_write_32_data, we get a seemingly random output. For testing purposes, we made are host program data a 32bit 1's in a couple of different forms as shown below in our code. We expect our output to be a 32bit sequence of all 1's on the FPGA but our output sequence is 00110110001110010011010000111001.

Code: Select all
std::ofstream FIFO;
FIFO.open("/dev/xillybus_write_32");
uint32_t output32 = 0; //Linux unsigned 32bit number

while(1){
            //output32 = 4294967295;  //decimal equivalent of 32bit binary 1's. This is the format that we would like to put into the FIFO  //First attempt
            //output32 = 0b11111111111111111111111111111111; //32bit binary 1's. (Same as above statement) //Second Attempt
            //FIFO << output32; //push output32 to FIFO
            FIFO << 0b11111111111111111111111111111111; //pushing 32bit 1's straight into FIFO// Third Attempt
}

if (FIFO.is_open()){
                        FIFO.close();
}


Thank you very much for your assistance.
Cristian8
 
Posts: 5
Joined:

Re: Writing data to FPGA FIFO from host program

Postby support »

Hi,

I tried a similar program, but instead of sending the data to a Xillybus stream, it went just to a file, so I can see what I got. My try.cc goes

Code: Select all
#include <fstream>
int main()
{
    unsigned int output32 = 0b11111111111111111111111111111111;

    std::ofstream file;
    file.open("file.txt");
    file << output32;
    file.close();
    return 0;
}


So I compiled, ran it, and looked what's inside:
Code: Select all
$ g++ -Wall -O3 try.cc -o try
$ ./try
$ hexdump -C file.txt
00000000  34 32 39 34 39 36 37 32  39 35                    |4294967295|
0000000a
$ cat file.txt
4294967295


So there you have it. C++ converted the integer into a string before sending it to the standard input, so instead of sending all ones, you got the string "4294967295". Isn't it wonderful that C++ does all those nice things automatically?

Is there any reason in particular why you use C++ as opposed to plain C? My opinion about C++ is that it's for C programmers who want to entertain themselves with cool software concepts, but in the end they get bugs exactly of this type.

Regards,
Eli
support
 
Posts: 802
Joined:


Return to Xillybus