/* this test program demonstrates the problem with Linux-3.10.12 * (I tested 3.10.2 also, had the problem too) * It shows the time between writing and signalling TX empty * for standard serial port (/dev/ttyS0) (8250) * * * With older kernels (at least 3.5.0) it works as expected * * writing 26 chars at 1200 baud to the PORT should take some 216 mS * with the newer kernels it takes only 19mS * */ #include #include #include #include #include struct termios tio; char teststring[]="abcdefghijklmnopqrstuvwxyz"; int main (int argc, char **argv) { int fdn = -1; int parm = 0; struct timeval t1, t2; double spendtime; if((fdn = open ("/dev/ttyS0", O_RDWR)) < 0){ fprintf(stderr,"Can open port \n"); exit(-1); } tcgetattr(fdn, &tio); tio.c_cflag = CS8 | PARODD | B1200 | PARENB | CREAD | CLOCAL; // parity, baudrate tio.c_iflag = IGNBRK | INPCK; tio.c_lflag = 0; tio.c_oflag = 0; tio.c_cc[VMIN] = 1; // no input buffering tio.c_cc[VTIME] = 0; tcsetattr(fdn, TCSANOW, &tio); // set start time gettimeofday((struct timeval*)&t1, NULL); // write some data (216mS) write(fdn, &teststring, sizeof(teststring)); // get first interval, internal kernel handling gettimeofday((struct timeval*)&t2, NULL); spendtime = (t2.tv_sec - t1.tv_sec) * 1000.0; spendtime += (t2.tv_usec - t1.tv_usec) / 1000.0; printf("mark 1 offset = %lf ms \n", spendtime); // check TX_EMT while(!parm) ioctl(fdn, TIOCSERGETLSR, &parm); // get second interval, all data should be written gettimeofday((struct timeval*)&t2, NULL); spendtime = (t2.tv_sec - t1.tv_sec) * 1000.0; spendtime += (t2.tv_usec - t1.tv_usec) / 1000.0; printf("mark 2 offset = %lf ms \n", spendtime); return(0); }