fpgafs/app/fifo_shift.c

62 lines
1.8 KiB
C

/* *****************************************************************
* (C) Copyright 2007 Benjamin Krill <ben@codiert.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
* *****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <libfpga.h>
int
main(int argv, char **argc)
{
int fd, sta, rnd, i;
char *c, buf[4];
if ((fd = open("tdat", O_RDONLY, 0)) == -1 ) {
printf("ERROR-1: %s\n", strerror(errno));
return -1;
}
if (fpgafs_create_context(fd, "dbg") == -1) {
printf("ERROR-2: Cannot create fpgafs context\n");
close(fd);
return -1;
}
// while (fpgafs_get_stat() < 0x10) {
for(i=0; i < 10; i++) {
rnd = rand();
c = (char *)&rnd;
printf("write data: %x\n",c[0], c[1], c[2], c[3]);
if ((sta=fpgafs_send_data(&c[0], 4)) != 4) {
printf("ERROR-3: Cannot send specified length (%d)\n", sta);
return -1;
}
if ((sta=fpgafs_recv_data(&c[0], 4)) != 4) {
printf("ERROR-3: Cannot send specified length (%d)\n", sta);
return -1;
}
printf("read data: %x\n",buf[0], buf[1], buf[2], buf[3]);
}
return 0;
}