Skip to content
Snippets Groups Projects
Commit 6cda8e02 authored by Neil Gershenfeld (test)'s avatar Neil Gershenfeld (test)
Browse files

add termios

parent f6c24066
No related branches found
No related tags found
No related merge requests found
Pipeline #11116 passed
//
// ring.termios.c
//
// termios communication ring test
//
// Neil Gershenfeld 4/4/21
//
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
//
#define nloop 100
//
int main(int argc,char *argv[]) {
if (argc != 3) {
printf("command line: ring.termios serial_port port_speed\n");
return -1;
}
int speed = atoi(argv[2]);
int port = open(argv[1],O_RDWR|O_NOCTTY|O_NDELAY);
fcntl(port,F_SETFL,0);
struct termios term;
tcgetattr(port,&term);
term.c_cflag &= ~(PARENB|CSTOPB|CSIZE|CRTSCTS);
term.c_cflag |= (CS8|CREAD|CLOCAL);
term.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHONL|ISIG);
term.c_iflag &= ~(IXON|IXOFF|IXANY|IGNBRK|BRKINT
|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL);
term.c_oflag &= ~(OPOST|ONLCR);
term.c_cc[VTIME] = 0;
term.c_cc[VMIN] = 1;
cfsetispeed(&term,speed);
cfsetospeed(&term,speed);
tcsetattr(port,TCSANOW,&term);
unsigned char chr = 0;
struct timeval start,end;
tcflush(port,TCIOFLUSH);
gettimeofday(&start,NULL);
for (int i = 0; i < nloop; ++i) {
while (1) {
write(port,&chr,1);
read(port,&chr,1);
if (chr == 0)
break;
}
}
gettimeofday(&end,NULL);
printf("byte ring cycles per second: %6.3g\n",nloop*256/((end.tv_sec+end.tv_usec/1e6)-(start.tv_sec+start.tv_usec/1e6)));
close(port);
return 0;
}
...@@ -189,6 +189,14 @@ The communication test measures how quickly two nodes can exchange messages; thi ...@@ -189,6 +189,14 @@ The communication test measures how quickly two nodes can exchange messages; thi
<th>date</th> <th>date</th>
</tr> </tr>
<tr>
<td>0.010</td>
<td><a href=comm/termios/ring.termios.c>i7-8700T, C, termios</a></td>
<td>USB 2.1</td>
<td><a href=comm/SerialUSB/ring.SerialUSB.ino>ATSAMD11C, Arduino, SerialUSB</a></td>
<td>April2021</td>
</tr>
<tr> <tr>
<td>0.007</td> <td>0.007</td>
<td><a href=comm/pySerial/ring.pySerial.py>i7-8700T, Python, pySerial</a></td> <td><a href=comm/pySerial/ring.pySerial.py>i7-8700T, Python, pySerial</a></td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment