mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
Merge pull request #79 from JoeMerten/bsd-custom-baudrate
Bsd custom baudrate
This commit is contained in:
@ -54,9 +54,10 @@ comments:
|
||||
- Cody Planteen (https://github.com/planteen) contributed the
|
||||
implementation of the toggle-RTS command.
|
||||
|
||||
- Joe Merten (https://github.com/Joe-Merten) contributed the
|
||||
- Joe Merten (https://github.com/JoeMerten) contributed the
|
||||
--lower-rts and --lower-dtr options, custom baudrate support for
|
||||
OSX, the --logfile option implementation, and several bug-fixes.
|
||||
FreeBSD and macOS, the --logfile option implementation, and several
|
||||
bug-fixes.
|
||||
|
||||
- Maciej Grela (https://github.com/mgrela) contributed the initial
|
||||
--initstring option implementation.
|
||||
|
8
Makefile
8
Makefile
@ -38,14 +38,14 @@ OBJS += linenoise-1.0/linenoise.o
|
||||
linenoise-1.0/linenoise.o : linenoise-1.0/linenoise.c linenoise-1.0/linenoise.h
|
||||
|
||||
## Comment this in to enable custom baudrate support.
|
||||
## Works with: Linux (kernels > 2.6), OSX (Tiger and above)
|
||||
## Works with: Linux (kernels > 2.6), FreeBSD, macOS (Tiger and above)
|
||||
#CPPFLAGS += -DUSE_CUSTOM_BAUD
|
||||
|
||||
## Comment this IN to remove help strings (saves ~ 4-6 Kb).
|
||||
#CPPFLAGS += -DNO_HELP
|
||||
|
||||
|
||||
OBJS += picocom.o term.o fdio.o split.o termios2.o custbaud_osx.o
|
||||
OBJS += picocom.o term.o fdio.o split.o termios2.o custbaud_bsd.o
|
||||
picocom : $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
|
||||
|
||||
@ -54,7 +54,7 @@ term.o : term.c term.h
|
||||
split.o : split.c split.h
|
||||
fdio.o : fdio.c fdio.h
|
||||
termios2.o : termios2.c termios2.h termbits2.h
|
||||
custbaud_osx.o : custbaud_osx.c custbaud_osx.h
|
||||
custbaud_bsd.o : custbaud_bsd.c custbaud_bsd.h
|
||||
|
||||
.c.o :
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
|
||||
@ -86,7 +86,7 @@ picocom.1.pdf : picocom.1
|
||||
clean:
|
||||
rm -f picocom.o term.o fdio.o split.o
|
||||
rm -f linenoise-1.0/linenoise.o
|
||||
rm -f termios2.o custbaud_osx.o
|
||||
rm -f termios2.o custbaud_bsd.o
|
||||
rm -f *~
|
||||
rm -f \#*\#
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
* custbaud_osx.c
|
||||
* custbaud_bsd.c
|
||||
*
|
||||
* Custom baud rate support for OSX.
|
||||
* Custom baud rate support for BSD and macOS.
|
||||
*
|
||||
* by Joe Merten (https://github.com/Joe-Merten www.jme.de)
|
||||
* by Joe Merten (https://github.com/JoeMerten www.jme.de)
|
||||
*
|
||||
* ATTENTION: OSX specific stuff!
|
||||
* ATTENTION: BSD and macOS specific stuff!
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
@ -35,28 +35,28 @@
|
||||
* looks that this is a bug or limitation in OSX and/or Ftdi driver.
|
||||
* Trying with PL2303 (driver version PL2303_MacOSX_1.6.1_20160309.zip),
|
||||
* baudrates up to 6MBaud were accepted.
|
||||
* - Have not tested with more recent macOS or Ftdi driver until now.
|
||||
*/
|
||||
|
||||
#if defined(__APPLE__) && defined(USE_CUSTOM_BAUD)
|
||||
/* Note that this code might also work with OpenBSD, NetBSD et cetera, but I have not tested.
|
||||
* That's why I only check for `defined (__FreeBSD__)` here.
|
||||
*/
|
||||
#if (defined (__FreeBSD__) || defined(__APPLE__)) && defined(USE_CUSTOM_BAUD)
|
||||
|
||||
#include "custbaud_osx.h"
|
||||
#include "custbaud_bsd.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef __APPLE__
|
||||
#include <IOKit/serial/ioss.h>
|
||||
#endif
|
||||
#include "term.h"
|
||||
|
||||
/***************************************************************************/
|
||||
/* Need to undef tcsetattr to get access to the original tcsetattr()
|
||||
* function inside our module.
|
||||
*/
|
||||
#undef tcsetattr
|
||||
|
||||
/***************************************************************************/
|
||||
/* As we can see in OSX termios.h all the baudrate constants are transparent,
|
||||
/* As we can see in FreeBSD and macOS termios.h all the baudrate constants are transparent,
|
||||
* like B115200=115200. There is no need for any integer <-> code translation.
|
||||
* So we can pass any baudrate we want directly cfsetospeed() & co.
|
||||
* So we can pass any baudrate we want directly to / from cfsetospeed() & co.
|
||||
*/
|
||||
int cfsetospeed_custom(struct termios *tiop, int speed) {
|
||||
return cfsetospeed(tiop, speed);
|
||||
@ -74,11 +74,18 @@ int cfgetispeed_custom(struct termios *tiop) {
|
||||
return cfgetispeed(tiop);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
/***************************************************************************/
|
||||
/* Need to undef tcsetattr to get access to the original tcsetattr()
|
||||
* function inside our module.
|
||||
*/
|
||||
#undef tcsetattr
|
||||
|
||||
/***************************************************************************/
|
||||
/* The strategy of picocom's terminal handling library is to hold all the
|
||||
* terminal settings (including baudrate) using termios struct.
|
||||
* Problem on OSX is, that tcsetattr() will fail if termios contains an
|
||||
* unusual baudrate (like e.g. 12345 of 12M), The official OSX way to apply
|
||||
* Problem on macOS is, that tcsetattr() will fail if termios contains an
|
||||
* unusual baudrate (like e.g. 12345 of 12M), The official macOS way to apply
|
||||
* those baudrates is to use ioctl(IOSSIOSPEED) instead.
|
||||
* Our workaround strategy is:
|
||||
* - set the baudrate stored in termios back to a standard value (e.g. 9600)
|
||||
@ -131,7 +138,8 @@ int tcsetattr_custom(int fd, int optional_actions, const struct termios *tiop) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /*__APPLE__ */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#endif /* __APPLE__ && USE_CUSTOM_BAUD */
|
||||
#endif /* FreeBSD || __APPLE__ && USE_CUSTOM_BAUD */
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
* custbaud_osx.h
|
||||
* custbaud_bsd.h
|
||||
*
|
||||
* Custom baud rate support for OSX.
|
||||
* Custom baud rate support for BSD and macOS.
|
||||
*
|
||||
* by Joe Merten (https://github.com/Joe-Merten www.jme.de)
|
||||
* by Joe Merten (https://github.com/JoeMerten www.jme.de)
|
||||
*
|
||||
* ATTENTION: OSX specific stuff!
|
||||
* ATTENTION: BSD and macOS specific stuff!
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
@ -23,18 +23,20 @@
|
||||
* USA
|
||||
*/
|
||||
|
||||
#ifndef CUSTBAUD_OSX_H
|
||||
#define CUSTBAUD_OSX_H
|
||||
#ifndef CUSTBAUD_BSD_H
|
||||
#define CUSTBAUD_BSD_H
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* OSX termios.h unfortunately just provides constants for baudrates
|
||||
/* macOS termios.h unfortunately just provides constants for baudrates
|
||||
* up to 230k, so we add the missing constants here. Regardless, that
|
||||
* most of the high baudrates needs special handling (implementation in
|
||||
* tcsetattr_custom()), we want to provide the values here to have them
|
||||
* available for term_baud_up()/down().
|
||||
*
|
||||
* FreeBSD termios.h has 460k and 921k but misses e.g. 500k and >=1M.
|
||||
*/
|
||||
|
||||
#if defined(HIGH_BAUD)
|
||||
@ -87,10 +89,12 @@ int cfgetispeed_custom(struct termios *tiop);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Replace tcsetattr function with our osx specific one */
|
||||
#ifdef __APPLE__
|
||||
/* Replace tcsetattr function with our macOS specific one */
|
||||
#define tcsetattr tcsetattr_custom
|
||||
int tcsetattr_custom(int fd, int optional_actions, const struct termios *tiop);
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#endif /* CUSTBAUD_OSX_H */
|
||||
#endif /* CUSTBAUD_BSD_H */
|
@ -17,7 +17,7 @@ itself inverted) to the microcontroller's reset input pin.
|
||||
Problem at open
|
||||
---------------
|
||||
|
||||
In both Linux and OSX, we observe that the RTS handshake line will be
|
||||
In both Linux and macOS, we observe that the RTS handshake line will be
|
||||
driven high (TTL-level output low) when `open()` is called, even when
|
||||
the port is used without hardware handshake.
|
||||
|
||||
@ -35,7 +35,7 @@ microcontroller.
|
||||
|
||||
Using the picocom `--lower-rts` command line option, I measured about
|
||||
50µs-70µs on my Linux machine and 250µs-450µs on my old Macbook Pro
|
||||
running OSX (both tested with an FTDI FT2232H USB-to-Serial adapter).
|
||||
running macOS (both tested with an FTDI FT2232H USB-to-Serial adapter).
|
||||
But note that there is no hard guarantee for these times; the OS may
|
||||
preempt picocom between the `open()` and the "lower-rts" calls.
|
||||
|
||||
|
10
picocom.1.md
10
picocom.1.md
@ -96,7 +96,7 @@ here.
|
||||
|
||||
: Toggle the RTS line. If RTS is up, then lower it. If it is down,
|
||||
then raise it. Not supported if the flow control mode is RTS/CTS.
|
||||
Only supported in Linux and OSX.
|
||||
Only supported in Linux and macOS.
|
||||
|
||||
**C-backslash**
|
||||
|
||||
@ -369,13 +369,13 @@ Picocom accepts the following command-line options.
|
||||
: Lower the RTS control signal after opening the serial port (by
|
||||
default RTS is raised after open). Only supported when
|
||||
flow-control mode is not set to RTS/CTS, ignored otherwise. Only
|
||||
supported in Linux and OSX.
|
||||
supported in Linux and macOS.
|
||||
|
||||
**--lower-dtr**
|
||||
|
||||
: Lower the DTR control signal after opening the serial port (by
|
||||
default DTR is raised after open). Only supported in Linux and
|
||||
OSX.
|
||||
default DTR is raised after open). Only supported in Linux and
|
||||
macOS.
|
||||
|
||||
**--exit-aftrer** | **-x**
|
||||
|
||||
@ -584,7 +584,7 @@ operation and what happens in each such condition:
|
||||
original settings, and the modem-control lines are cleared signaling
|
||||
a modem reset, subject to the **--noreset** and the **--hangup**
|
||||
options. After that picocom exits with a success status.
|
||||
|
||||
|
||||
- The quit command is seen in the standard input. That is, the escape
|
||||
character is seen (default **C-a**), followed by the quit command
|
||||
character (default **C-q**). The behavior in this case is similar to
|
||||
|
22
term.c
22
term.c
@ -61,9 +61,9 @@
|
||||
#include "termios2.h"
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(USE_CUSTOM_BAUD)
|
||||
/* only for OSX, Tiger and above */
|
||||
#include "custbaud_osx.h"
|
||||
#if (defined (__FreeBSD__) || defined(__APPLE__)) && defined(USE_CUSTOM_BAUD)
|
||||
/* only for FreeBSD and macOS (Tiger and above) */
|
||||
#include "custbaud_bsd.h"
|
||||
#endif
|
||||
|
||||
/* Time to wait for UART to clear after a drain (in usec). */
|
||||
@ -170,22 +170,6 @@ term_perror (const char *prefix)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* OSX termios.h unfortunately just provides constants for baudrates
|
||||
up to 230k, so we add the missing constants here. */
|
||||
|
||||
#if defined(__APPLE__) && defined(HIGH_BAUD)
|
||||
|
||||
#ifndef B460800
|
||||
#define B460800 460800
|
||||
#endif
|
||||
#ifndef B921600
|
||||
#define B921600 921600
|
||||
#endif
|
||||
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define BNONE 0xFFFFFFFF
|
||||
|
||||
struct baud_codes {
|
||||
|
Reference in New Issue
Block a user