- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
int fpga_read(char *dev, unsigned int base_addr, unsigned int offset, int len, unsigned char *buf)
{
unsigned long long pci_raddr;
int actual;
FILE *fi;
fi = fopen(dev, "r");
if (fi == NULL) {
printf("Failed to read from FPGA - Error opening device\n");
return 1;
}
pci_raddr = (unsigned long long) 2 << 32 | (base_addr + offset);
setvbuf(fi, NULL, _IONBF, 0); // disable file buffering
fseeko(fi, pci_raddr, SEEK_SET); // go to the address
actual = fread(buf, 1, len, fi); // read the data
fclose(fi);
if (actual <= 0) {
printf("Error %d reading from device (dev %s, base addr 0x%x, offset 0x%x, len %i)\n", errno, dev, base_addr, offset, len);
return 2;
}
return 0;
}
По многочисленным просьбам говнокодеров, выделил в отдельный пост.