* Personnal line discipline difficulties
@ 2003-08-25 8:18 Laurent Hugé
2003-08-25 8:42 ` Russell King
[not found] ` <200308251054.48574.laurent.huge@wanadoo.fr>
0 siblings, 2 replies; 4+ messages in thread
From: Laurent Hugé @ 2003-08-25 8:18 UTC (permalink / raw)
To: linux-kernel
Hi,
Please be kind to advise me if I don't post on the right mailing-list.
I'm trying to implement a driver to a specific network peripherial (not
commercial) ; this peripherial uses both parallel and serial ports to connect
to one PC. I've succeeded in managing the parallel port, but the serial one
still raises some difficulties (yet, I've used Linux Device Drivers book from
Rubini, I've looked sources of bluetooth and n_tty drivers, searched Internet
and eventually asked on kernelnewbies mailing-list with no solution).
My serial involved module code is :
int ccsds_sport_ldisc_attach(struct tty_struct *tty) {
return 0;
}
void ccsds_sport_ldisc_detach(struct tty_struct *tty) {
return;
}
void ccsds_sport_receive_buf(struct tty_struct *tty, const unsigned
char *cp, char *fp, int count) {
struct sk_buff *skb;
int i;
skb = dev_alloc_skb(count);
if (!skb) {
printk("<4>low memory\n");
return;
}
memcpy(skb_put(skb, count), cp, count);
printk("<7>Size = %i\n", count);
printk("<7>Data : ");
for (i=0; i<count; i++)
printk(" %.2X(%2X)",*(cp+i), *(fp+i));
printk("\n");
return;
}
int ccsds_sport_ldisc_receive_room(struct tty_struct *tty) {
return 248; /* Hardware property */
}
struct tty_ldisc sport_ldisc= {
magic : TTY_LDISC_MAGIC,
name : "ccsds_sport_ldisc",
flags : 0,
open : ccsds_sport_ldisc_attach,
close : ccsds_sport_ldisc_detach,
receive_buf : ccsds_sport_receive_buf,
receive_room : ccsds_sport_ldisc_receive_room,
};
and call of
result=tty_register_ldisc(N_TTY, &sport_ldisc);
in module_init (which returns no error).
To activate the line discipline, I use a modified version of the kirkrun from
Rubini :
int configure(int fd, int toggle)
{
struct termios newTermIo;
unsigned int bits;
if (toggle) {
/* First of all, toggle RTS and DTR */
if (ioctl(fd,TIOCMGET,&bits)) return -1;
bits &= ~(TIOCM_RTS | TIOCM_DTR);
if (ioctl(fd,TIOCMSET,&bits)) return -1;
usleep(300*1000); bits |= (TIOCM_RTS | TIOCM_DTR);
if (ioctl(fd,TIOCMSET,&bits)) return -1;
usleep(300*1000);
}
memset(&newTermIo, 0, sizeof(struct termios));
newTermIo.c_iflag = IGNBRK |IGNPAR;
newTermIo.c_oflag = 0;
newTermIo.c_cflag = CS8 | CREAD | HUPCL | CLOCAL | CRTSCTS;
newTermIo.c_lflag = 0;
newTermIo.c_cc[VMIN] = 1;
newTermIo.c_cc[VTIME] = 0;
if (cfsetispeed(&newTermIo, B115200) < 0)
return -1;
if (tcsetattr(fd, TCSANOW, &newTermIo) < 0)
return -1;
tcflush(fd, TCIOFLUSH);
fcntl(fd, F_SETFL, 0); /* clear ndelay */
return 0;
}
int main(int argc, char **argv)
{
int fd, i;
if (argc != 2) {
fprintf(stderr, "%s: Use \"%s <dev>\"\n", argv[0], argv[0]);
exit(1);
}
if( (fd=open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY)) == -1){
fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1],
strerror(errno));
exit(1);
}
configure(fd,0);
close(fd);
if ((fd=open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY)) == -1){
fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1],
strerror(errno));
exit(1);
}
configure(fd,1);
i = N_TTY;
ioctl(fd, TIOCSETD, &i);
while (1) sleep(INT_MAX);
exit(0);
}
I tried my driver with
echo 123456789 > /dev/ttyS0
from another PC (with the same line parameters according to setserial), but
the result is not constant : sometimes, the line discipline receive the 11
caracters (including the 0D and 0A termination), but most of the time, it
receive firstly 8 the 3 caracters. The *fp value is always 0 (so there's no
error !).
Following a piece of advice from kernelnewbies mailing-list, I've used minicom
for testing, but the result is worst : I receiva each time only 1 caracter
(99% of time FF), and there's still a zero value of *fp.
The fact is that I do need to receive an accurate count of emitted caracters
(since the protocol used doesn't carry the size of PDU).
Does anyone know what I've fogotten in the line discipline ?
Thanks in advance,
--
Laurent Hugé.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Personnal line discipline difficulties
@ 2003-08-25 8:57 Laurent Hugé
0 siblings, 0 replies; 4+ messages in thread
From: Laurent Hugé @ 2003-08-25 8:57 UTC (permalink / raw)
To: linux-kernel
Le Lundi 25 Août 2003 10:42, vous avez écrit :
> > the result is not constant : sometimes, the line discipline receive the
> > 11 caracters (including the 0D and 0A termination), but most of the time,
> > it receive firstly 8 the 3 caracters. The *fp value is always 0 (so
> > there's no error !).
> That's not correct. fp is an array of error characters, length "count".
> Each entry corresponds directly with each received character.
Yes. What I've meant by "always" is "at each caracter received". It equals
zero for everyone of them.
> In other words, it doesn't have any framing on the group of characters it
> may hand you.
Do you mean that it's impossible for the tty_ldisc to know the size of what
the serial port received ? As I've told before, I've got no other way to know
it, so it's necessary to me (moreover, I'm trying to port an existing driver
from Windows to Linux, and the Windows serial driver gives accurately the
size of each PDU, so there must be a way).
--
Laurent Hugé.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-08-25 10:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-25 8:18 Personnal line discipline difficulties Laurent Hugé
2003-08-25 8:42 ` Russell King
[not found] ` <200308251054.48574.laurent.huge@wanadoo.fr>
[not found] ` <20030825102923.A30952@flint.arm.linux.org.uk>
2003-08-25 10:27 ` Laurent Hugé
2003-08-25 8:57 Laurent Hugé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome