1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Added support for setting custom baud rates.

If the requested baudrate is not a custom one (i.e. does not match one
of the Bxxx macros), then the cfsetospeed_custom() and
cfsetispeed_custom() are called to configure the "nexttermios" structure
with the requested non-standard baudrate. Same thing for reading the
baudrate: If cfgetospeed() and / or cfgetispeed() return a value that is
not among the Bxxx macros, cfgetospeed_custom() and cfgetispeed_custom()
are called, to read (and decode) the non-standard baudrate from the
"nexttermios" structure.

Currently the cf[set|get][i|o]speed_custom functions are only
implemented for Linux, and work only with non-ancient kernels (>2.6). So
in effect, custom baud-rate support is currently only supported for
Linux.
This commit is contained in:
Nick Patavalis
2015-08-20 12:40:28 +03:00
parent 30a06fd05f
commit fd306077d6
3 changed files with 48 additions and 16 deletions

54
term.c
View File

@ -38,6 +38,11 @@
#include <sys/ioctl.h>
#endif
#ifdef USE_CUSTOM_BAUD
/* only works for linux, recent kernels */
#include "termios2.h"
#endif
#include "term.h"
/***************************************************************************/
@ -721,24 +726,28 @@ term_set_baudrate (int fd, int baudrate)
tio = term.nexttermios[i];
spd = Bcode(baudrate);
if ( spd == BNONE ) {
if ( spd != BNONE ) {
r = cfsetospeed(&tio, spd);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
rval = -1;
break;
}
cfsetispeed(&tio, B0);
} else {
#ifdef USE_CUSTOM_BAUD
r = cfsetospeed_custom(&tio, baudrate);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
rval = -1;
break;
}
cfsetispeed(&tio, B0);
#else /* ! defined USE_CUSTOM_BAUD */
term_errno = TERM_EBAUD;
rval = -1;
break;
}
r = cfsetospeed(&tio, spd);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
rval = -1;
break;
}
r = cfsetispeed(&tio, spd);
if ( r < 0 ) {
term_errno = TERM_ESETISPEED;
rval = -1;
break;
#endif /* of USE_CUSTOM_BAUD */
}
term.nexttermios[i] = tio;
@ -765,11 +774,24 @@ term_get_baudrate (int fd, int *ispeed)
if ( ispeed ) {
code = cfgetispeed(&term.currtermios[i]);
*ispeed = Bspeed(code);
#ifdef USE_CUSTOM_BAUD
if ( *ispeed < 0 ) {
*ispeed = cfgetispeed_custom(&term.currtermios[i]);
}
#endif
}
code = cfgetospeed(&term.currtermios[i]);
ospeed = Bspeed(code);
if ( ospeed < 0 )
if ( ospeed < 0 ) {
#ifdef USE_CUSTOM_BAUD
ospeed = cfgetospeed_custom(&term.currtermios[i]);
if ( ospeed < 0 ) {
term_errno = TERM_EGETSPEED;
}
#else
term_errno = TERM_EGETSPEED;
#endif
}
} while (0);