Skip to content

Commit

Permalink
Fixed recent issue in making serial port stable caused 10s to 30s blo…
Browse files Browse the repository at this point in the history
…cking call when reading an empty buffer (#217)

* Changed serial port initialisation's VTIME=10 so that if anything goes wrong during serial read from driver, the PiOS will not seem to hang or block for 10s or sometimes 10s to 30s depending on retries. A timeout of 1s is enough. At least comment is there should anyone need to tweak it.
  • Loading branch information
jasonmnemonic authored Oct 17, 2021
1 parent 80c01e7 commit 74e8e68
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/source/bcm2835_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ void Stream::begin(unsigned long baud, int flags)
// See: http://unixwiz.net/techtips/termios-vmin-vtime.html
options.c_cc[VMIN] = 0;
// Cannot set VTIME to 0 as it creates more problems such as cannot read the driver properly.
options.c_cc[VTIME] = 100; // VTIME defined as tenths of a second so 100 is actually 10 seconds
// Also, you do not want to set to 100 because it is a blocking read and timeout in VTIME and can take up to 10 seconds and
// if retries are implemented in caller then it feels like something is blocking for N retries x VTIME.
options.c_cc[ VTIME ] = 10; // VTIME defined as tenths of a second so 100 is actually 10 seconds; and 10 deciseconds is 1 second.

tcflush(fd, TCIOFLUSH); // flush both tx and rx
tcsetattr(fd, TCSANOW, &options);
Expand Down

0 comments on commit 74e8e68

Please sign in to comment.