Dev driver - cant read from it

Hello,

I’m working on my Dev driver and I can’t seem to dev_read() from it. I don’t
have the h/w yet so I’m trying to fake getting data from it. Every time I
write() to the driver the proxy for the output buffer is triggered and the
example driver just writes this to stdout - no problem here. So after thats
done I trigger the proxy for the input buffer and just strcpy() some data
into the buffer and then feed it to Dev. Eventually this will of course be
done with an interrupt handler when data is available from the h/w. The
problem is that after I feed the data to Dev’s input buffer I expect that I
will be able to read() the data from my driver. But all that happens is that
Dev Kick’s again right away and the data that I fed to Dev’s input buffer
seems to be copied to the output buffer and written to stdout. Is the sample
driver supposed to do this? I can’t see where this is happening in the code.
I only copy the fake data into the buffer once so this isn’t going on
forever.

In my test program I do the following. The proxy does get triggered and my
Recieve reports the # bytes avail is 0 and the dev_read() fails with
“resource temporarily unavailable”. Thanks for any help.

// Open the driver
int fd = open("/dev/ip500", O_RDWR | O_NONBLOCK);
if (fd == -1)
{
perror(“open”);
exit(1);
}

// Write data to the driver that will get sent to h/w. Currently
// the driver just writes this to stdout.
char* str = “im sorry Dev, im afraid i cant do that”;
write (fd, str, strlen(str)+1);

pid_t proxy = qnx_proxy_attach(0, 0, 0, -1);
if (proxy == -1)
{
perror(“qnx_proxy_attach:”);
exit(1);
}

dev_state(fd, 0, _DEV_EVENT_INPUT);
if (dev_arm (fd, proxy, _DEV_EVENT_INPUT) == -1)
{
perror(“dev_arm”);
exit(1);
}

char buf[100];
while(1)
{
pid_t pid = Receive(0, &buf, sizeof(buf));

if (pid == proxy) // ok to read now
{
printf (“proxy triggered\n”);

int numBytesAvail = dev_ischars(fd);
printf (“num bytes avail: %d\n”, numBytesAvail);

char dbuf[100];
memset(dbuf, ‘\0’, 100);
int nBytes = dev_read (fd, dbuf, 0, 0, 0, 0, 0, 0);
if (nBytes == -1)
{
perror(“dev_read”);
}
printf (“buf = %s, bytes = %d\n”, dbuf, nBytes);
}
}

Just after I posted this I figured out part of it. The fake data that I copy
into the input buffer in the driver didn’t have a newline and that seems to
matter. Is this a requirement for the data being injected to Dev? So after I
do this I can dev_read() from it in my test program and get the data but the
driver is still Kick’ing again and sending this to stdout. So that narrows
it down quite a bit. The sample driver must be doing this on purpose
somewhere…

Jon

Jonathan Richardson <jrichard@nospam.ise.bc.ca> wrote:

Just after I posted this I figured out part of it. The fake data that I copy
into the input buffer in the driver didn’t have a newline and that seems to
matter. Is this a requirement for the data being injected to Dev? So after I
do this I can dev_read() from it in my test program and get the data but the
driver is still Kick’ing again and sending this to stdout. So that narrows
it down quite a bit. The sample driver must be doing this on purpose
somewhere…

A wild guess… but it might (at least partially) have something
to do with terminal settings. Try doing an “stty -a” from your device.
Is it in edited or raw mode? Look at tcsetattr() for code methods for
changing this.

-David

QNX Training Services
dagibbs@qnx.com

Good guess. It was in edited mode. I just assumed it was in raw mode but
doing an stty on it showed that not to be true. Merci beaucoup.

Jon

A wild guess… but it might (at least partially) have something
to do with terminal settings. Try doing an “stty -a” from your device.
Is it in edited or raw mode? Look at tcsetattr() for code methods for
changing this.

-David

QNX Training Services
dagibbs@qnx.com