Date: Mon, 19 Mar 2001 21:30:55 +0100 From: Volker Jahns <Volker.Jahns@thalreit.de> To: hackers@freebsd.org Cc: Volker.Jahns@dpma.de Subject: Serial port open Message-ID: <20010319213055.A881@ikarus.thalreit>
next in thread | raw e-mail | index | archive | help
I do have a small problem w/ serial IO. I have attached code to 1. open a serial line, 2. set terminal attributes, 3. close the serial port, 4. iterate thru 1.-3. a second time. <snip> /* serial test */ /* FreeBSD 3 second */ #include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include <sys/ioctl.h> #define BENCHMARK 2 int main (int argc, char **argv) { int err, rfd, tset, i, j; struct termios tp, op; /* test loop to check how long it takes to open/close the port */ for ( j = 0; j < BENCHMARK; j++) { rfd = open("/dev/ttyd0", O_RDWR | O_NOCTTY | O_NONBLOCK | O_NDELAY); printf("open\t\t: errno %d\n", errno); if (rfd == -1) { perror("open: couldn't open /dev/ttyd0"); } else { fcntl(rfd, F_SETFL, 0); } /* get terminal attributes */ tcgetattr(rfd, &op); tcgetattr(rfd, &tp); /* set terminal attr */ cfsetispeed(&tp, 9600); cfsetospeed(&tp, 9600); tp.c_iflag = 0; tp.c_oflag = 0; tp.c_cflag = 0; tp.c_lflag = 0; for ( i = 0; i < NCCS; i++) { tp.c_cc[i] = 0; } tp.c_iflag &= (IXON | IXOFF | IXANY); tp.c_cflag |= PARENB; tp.c_cflag &= ~PARODD; tp.c_cflag |= CLOCAL; tp.c_cflag |= CREAD; tp.c_cflag |= CS8; tp.c_cflag |= CSTOPB; tp.c_cflag |= CSIZE; tp.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); tp.c_cc[VMIN]=0; tp.c_cc[VTIME]=1; /* set terminal attributes */ tcsetattr(rfd, TCSANOW, &tp); /* reset terminal attributes */ tcsetattr(rfd, TCSANOW, &op); close(rfd); /* 2nd service */ } } <snap> between the 1st call to close and the 2nd call to open the system spends some 3 (three !) seconds. <snip> volker@nemo testing > time ./io_fbsd-2 open : errno 0 open : errno 0 real 0m2.998s user 0m0.000s sys 0m0.004s <snap> I am running <snip> FreeBSD nemo.zvr.dpma.de 4.2-RELEASE FreeBSD 4.2-RELEASE #0: Thu Mar 15 12:58:51 CET 2001 <snap> but happens also w/ 4.1. What is actually wrong about the code? What is it I am missing? If this is the incorrect list to consider the problem, could you please redirect? for case anybody wants to know, here is the relevant output of kdump <snip> 21753 io_fbsd-2 985009390.419433 RET close 0 21753 io_fbsd-2 985009390.419451 CALL open(0x80488a0,0x8006,0xbfbff6a0) 21753 io_fbsd-2 985009390.419467 NAMI "/dev/ttyd0" 21753 io_fbsd-2 985009393.411359 RET open 3 21753 io_fbsd-2 985009393.411426 CALL write(0x1,0x804b000,0x10) <snap> It shows, that it takes approx 3 seconds between the call to open and the return of the call. This is actually is striped down version of code to read out data of a serially connected weatherstation. -- Volker Jahns, Thalreit/DE, +49 80 35 69 25, mailto:Volker.Jahns@thalreit.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010319213055.A881>