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;
}
}
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]
#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;
}
}
[/code]