Thanks! I will give it a try once I get a device driver major number conflict resolved.
----- Original Message ----
From: Dr. Johann Pfefferl <j.pfefferl@xxxxxxxxx>
To: microblaze-uclinux@xxxxxxxxxxxxxx
Sent: Monday, January 28, 2008 1:21:01 AM
Subject: Re: [microblaze-uclinux] FSLFIFO driver usage examples
Hello,
some time ago I have written a "fslcat" application. It takes a file or
read from stdin and outputs the data to the fsl link.
Hope this helps,
Hans
Simon Tam <
simontam1234@xxxxxxxxx> wrote:
> Hi,
>
> Does anyone have usage examples of the FSLFIFO driver or
documentation?
>
> Thanks,
>
> Simon
>
--
Dr. Johann Pfefferl ------------ mailto j.pfefferl at eubus dot net
Eubus GmbH
http://www.eubus.net ++++
http://www.ebmhydraxc.comGollierstr. 70
D-80339 Muenchen
Phone: +49 (0)89 45 22 578-67 Fax: +49 (0)89 45 22 578-55
Registergericht Muenchen HRB 145 336, Ust-Id Nr. DE 225 783 933
Geschaeftsfuehrer: Volker Ulrich, Peter Sibities
==
-o) A computer program does what you tell it to do,
/\\ not what you want it to do.
_\_v-
-----Inline Attachment Follows-----
#include <stdio.h>
#include <unistd.h> /* close() */
#include <stdlib.h> /* EXIT_FAILURE */
#include <fcntl.h>
#include <asm/fslfifo_ioctl.h>
#include <sys/ioctl.h>
#define FIFO_DEVICE "/dev/fslfifo0"
#define BUF_SIZE 256
static void usage(char *prgname)
{
fprintf(stderr, "Usage: %s [options] filename\n"
"Following options are recognized:\n"
"\t-d fsl_dev\tFSL device which should be handled (default:
%s)\n"
"\t-w width\tSet width of the FSL link: Valid values are 1,
2, 4\n"
"\t-r\tReset the FSL device\n"
"\t-s msecs\tSleep for the given number of milliseconds
after transmitting %d bytes\n"
"\t-h\tShow this help text\n"
,prgname, FIFO_DEVICE, BUF_SIZE);
exit(1);
}
int main(int argc, char *argv[])
{
unsigned long arg;
int fsl_fd, rv, inp_fd;
char *fsl_dev = FIFO_DEVICE;
unsigned fsl_width = 4, fsl_reset = 0, send_delay = 0;
while(0 <= (rv = getopt(argc, argv, "d:rs:w:h"))) {
switch(rv) {
case 'd':
fsl_dev = optarg;
break;
case 'r':
++fsl_reset;
break;
case 's':
send_delay = 1000 * strtoul(optarg, NULL, 0);
break;
case 'w':
fsl_width = strtoul(optarg, NULL, 0);
break;
case 'h':
default:
usage(argv[0]);
break;
}
}
if(!(1 == fsl_width || 2 == fsl_width || 4 == fsl_width)) {
fprintf(stderr, "Wrong FSL link width %d\n", fsl_width);
usage(argv[0]);
}
fsl_fd = open(fsl_dev, O_RDWR);
if(0 > fsl_fd) {
perror(fsl_dev);
return fsl_fd;
}
if(optind < argc) {
inp_fd = open(argv[optind], O_RDONLY);
if(0 > inp_fd) {
perror(argv[optind]);
return EXIT_FAILURE;
}
}
else
inp_fd = STDIN_FILENO;
++optind;
// Set the
FIFO width (1, 2, 4 bytes)
arg = fsl_width;
rv = ioctl(fsl_fd, FSLFIFO_IOCTWIDTH, arg);
if(rv < 0) {
perror("FSLFIFO_IOCTWIDTH");
close(fsl_fd);
return rv;
}
// Read back the FIFO width. "arg" is only dummy
rv = 0;
rv = ioctl(fsl_fd, FSLFIFO_IOCQWIDTH, arg);
if(0 > rv || fsl_width != rv) {
perror("FSLFIFO_IOCQWIDTH");
close(fsl_fd);
return rv;
}
// Reset FSL link
if(fsl_reset) {
fprintf(stderr, "Resetting device\n");
arg = 0;
rv = ioctl(fsl_fd, FSLFIFO_IOCRESET, arg);
if(rv < 0) {
perror("FSLFIFO_IOCRESET");
close(fsl_fd);
return rv;
}
}
fprintf(stderr, "FSL link %s initialised successfully with width
%d\n", fsl_dev, fsl_width);
{
static unsigned char buf[BUF_SIZE];
while(1) {
int n = read(inp_fd, buf, sizeof(buf));
if(0 < n) {
unsigned char *wdata = buf;
do {
rv = write(fsl_fd, wdata, n);
if(0 <= rv) {
//fprintf(stderr, "Written % 4d bytes to fsl link\n", rv);
wdata += rv;
n -= rv;
}
else {
perror("FSL write");
n = 0;
}
} while(n);
if(send_delay)
usleep(send_delay);
}
else if(!n)
break;
else {
perror("STDIN_FILENO");
return EXIT_FAILURE;
}
}
}
return EXIT_SUCCESS;
}