Problems with read_32

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Problems with read_32

Re: Problems with read_32

Post by Guest »

Hello,
Thank you for your answer. If the C code is correct, I clearly made a mistake somewhere in the logic design.
Sorry if it was somehow a silly question, but I've been left alone on this project and I needed to be sure where to look for errors.

Re: Problems with read_32

Post by support »

Hello,

It seems like the problem is in the logic. It's not completely clear to me how you get 1000 values back when you send four of them. You should put a FIFO between your own logic and the Xillybus IP core, and read/write with the FIFOs rd_en and wr_en ports.

Anyhow, there is no Endianess issue with Xillybus. If you use ints on read_32 and write_32 they get fine as 32-bit words on the logic side.

Regards,
Eli

Re: Problems with read_32

Post by serenac »

Update: now I get some values other than nan, but they don't make much sense. Could this be a problem of big/little endian? Like, I'm sending a 0x3f03dfde and a 0xedfd30f3 gets processed?
(sorry for posting as a guest earlier, I had not realized I wasn't logged in)

Re: Problems with read_32

Post by Guest »

Hello,
my code looks like this now:

Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

void allwrite(int fo, int *buf, int len);
void allread(int fi, int *buf, int len);

int main(int argc, char * argv[])
{

   int file_read, file_write;

   int data[4];
   data[0] = 0x3f03dfde;
   data[1] = 0x3ee8e732;
   data[2] = 0x3e0195a8;
   data[3] = 0x00000000;

   int out[1000];
   
   if(!(file_write = open("/dev/xillybus_write_32", O_WRONLY)))
   {
      fprintf(stderr, "\nError in opening /dev/xillybus_write_32\n");
      exit(0);
   }

   if(!(file_read = open("/dev/xillybus_read_32", O_RDONLY)))
   {
      fprintf(stderr, "Error in opening /dev/xillybus_read_32\n");
      exit(0);
   }

   allwrite(file_write, data, 4*sizeof(int));

   allread(file_read, out, 1000*sizeof(int));

   int i;
   for(i=0; i<1000; i++)
   {
      printf(" %08x ", out[i]);
   }

   return 0;
}


void allwrite(int fo, int *buf, int len)
{
   int sent = 0;
   int wc;

   while(sent < len)
   {
      wc = write(fo, buf + sent, len - sent);

      if(wc == 0)
      {
         fprintf(stderr, "Reached write EOF (?!)\n");
         exit(1);
      }
      sent += wc;
   }
}

void allread(int fi, int *buf, int len)
{
   int read_data = 0;
   int rc;

   while(read_data < len)
   {
      rc = read(fi, buf + read_data, len - read_data);

      if(rc == 0)
      {
         fprintf(stderr, "Reached read EOF (?!)\n");
         exit(1);
      }
      read_data += rc;
   }
}


But I still get only 0x7fc0000 values (nan). The application on the FPGA has a certain latency, so I didn't expect the first values to be right. Nevertheless, there should be something among the first 1000, so I still think there's a mistake I don't see right now.

Re: Problems with read_32

Post by support »

Hello,

I'm not so familiar with floating point representation of numbers, but either way I would look at the hexadecimal format of the floating point values to figure out what went wrong.

As a side note, fread() and fwrite() are not recommended, as they may add an extra layer of buffering. In particular, an fwrite() may be delayed. It's warmly suggested to use read() and write() instead (and open() instead of fopen() ).

Regards,
Eli

Re: Problems with read_32

Post by Guest »

Hello,
Thank you for your advice. The code now executes until the end, but I only get "NaN" values (at least when I print them on the console output).
could it be an error in the way I am passing the input values?

Re: Problems with read_32

Post by support »

Hello,

The problem seems to be that you open the file for read after writing. I don't know how the logic is set up, but it's common to hold the FIFO(s) reset while the respective *_open signal indicates that the file is closed.

Try opening both files at the beginning.

It seems like you're heading towards a coprocessing application. If so, I suggest looking at section 6.6 of the Xillybus host application programming guide for Linux, which may save you some trouble in your next steps:

http://xillybus.com/downloads/doc/xilly ... _linux.pdf

Regards,
Eli

Problems with read_32

Post by serenac »

Hi,
I am trying to develop an application that relies on Xillybus and Xillinux, but the part where I read data from the FPGA doesn't seem to work. I am not 100% sure the error is in the software part, it could be that the code implemented in the FPGA has some errors, but the simulations in Vivado were correct, so can anyone have a look at my code to see if it's right?

When I run it, it gets stuck after printing "rc = 0, len = 4 ....", so apparently the writing part is ok.

Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

void allwrite(FILE *fo, float *buf, int len);

void allread(FILE *fi, float *buf, int len);

int main(int argc, char * argv[])
{
   FILE *file_read, *file_write;
   float data[4];
   data[0] = data[1] = data[2] = data[3] = 0.5;
   float out[1000];

   if(!(file_write = fopen("/dev/xillybus_write_32", "wb")))
   {
      fprintf(stderr, "\nError\n");
      exit(0)
   }

   allwrite(file_write, data, (size_t)(4));

   if(!(file_read = fopen("/dev/xillybus_read_32", "rb")))
   {
      fprintf(stderr, "\nError\n");
      exit(0)
   }

   allread(file_read, out, (size_t)(4);

   return 0;
}

void allwrite(FILE *fo, float *buf, int len)
{
   int sent = 0;
   int wc;

   while(sent<len)
   {
      wc = fwrite(buf+sent, sizeof(float), (size_t)(len-sent), fo);
      sent += wc;
   }
}

void allread(FILE *fi, float *buf, int len)
{
   int read = 0;
   int rc;

   while(read<len)
   {
      rc = fread(buf+read, sizeof(float), (size_t)(len-read), fi);
      read += rc;
   }
}




Top