17 gettimeofday(&now, NULL);
18 return (uint32_t) ( now.tv_usec / 1000 );
30 fd = open(port, flags);
32 printf(
"[ERROR] UART open(%s)\n", port);
35 fcntl(fd, F_SETFL, O_RDWR);
42 case 9600: myBaud = B9600;
break;
43 case 19200: myBaud = B19200;
break;
44 case 38400: myBaud = B38400;
break;
45 case 57600: myBaud = B57600;
break;
46 case 115200: myBaud = B115200;
break;
47 case 230400: myBaud = B230400;
break;
48 case 460800: myBaud = B460800;
break;
49 case 500000: myBaud = B500000;
break;
50 case 576000: myBaud = B576000;
break;
55 printf(
"[ERROR] UART invalid baud: %ld for port: %s\n", baud, port);
59 tcgetattr(fd, &options);
61 cfmakeraw( &options );
62 cfsetispeed( &options, myBaud );
63 cfsetospeed( &options, myBaud );
68 options.c_cflag |= ( CREAD | CLOCAL ) ;
71 options.c_cflag &= ~PARENB;
72 options.c_cflag &= ~CSTOPB;
73 options.c_cflag &= ~CSIZE;
74 options.c_cflag |= CS8;
75 options.c_cflag &= ~CRTSCTS;
77 options.c_iflag &= ~(IXON | IXOFF | IXANY);
78 options.c_iflag |= IGNPAR;
80 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ;
82 options.c_oflag &= ~OPOST;
85 options.c_cc[VMIN] = 0;
89 options.c_cc[ VTIME ] = 10;
91 tcflush(fd, TCIOFLUSH);
96 tcgetattr(fd, &options);
97 options.c_cflag = CS8 | CLOCAL | CREAD | CBAUDEX;
98 options.c_cflag &= ~CBAUD;
99 options.c_cflag &= ~PARENB;
100 options.c_cflag &= ~CSTOPB;
101 options.c_iflag = IGNPAR;
102 options.c_oflag = baud;
103 options.c_lflag = baud;
105 tcflush(fd, TCIFLUSH);
109 tcsetattr(fd, TCSANOW, &options);
112 const int DELAY_MS_10 = 10;
113 usleep( 1000 * DELAY_MS_10 );
124 if (ioctl(fd, FIONREAD, &result) == -1)
131 return (uint8_t)
::write(fd, &data, 1);
137 if (
::read(fd, &data, 1) == -1)
void begin(unsigned long baud)
uint8_t write(const uint8_t data)