mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 18:06:39 +08:00
Baud definitions (B9600 for example) are again encoded; Now supports the BOTHER settings which allows specifying the baud via c_ispeed and c_ospeed termios fields
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4970 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -24,15 +24,6 @@ config MB_TCP_ENABLED
|
|||||||
depends on MODBUS
|
depends on MODBUS
|
||||||
default y
|
default y
|
||||||
|
|
||||||
config MB_TERMIOS
|
|
||||||
bool "Driver TERMIOS supported"
|
|
||||||
depends on MB_ASCII_ENABLED || MB_RTU_ENABLED
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
|
|
||||||
If this is not defined, then the terminal settings (baud, parity, etc).
|
|
||||||
are not configurable at runtime; serial streams will not be flushed when closed.
|
|
||||||
|
|
||||||
config MB_ASCII_TIMEOUT_SEC
|
config MB_ASCII_TIMEOUT_SEC
|
||||||
int "Character timeout"
|
int "Character timeout"
|
||||||
depends on MB_ASCII_ENABLED
|
depends on MB_ASCII_ENABLED
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ The NuttX-named configuration options that are available include:
|
|||||||
CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
|
CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
|
||||||
CONFIG_MB_RTU_ENABLED - Modbus RTU support
|
CONFIG_MB_RTU_ENABLED - Modbus RTU support
|
||||||
CONFIG_MB_TCP_ENABLED - Modbus TCP support
|
CONFIG_MB_TCP_ENABLED - Modbus TCP support
|
||||||
CONFIG_MB_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
|
|
||||||
tcflush, etc.). If this is not defined, then the terminal settings (baud,
|
|
||||||
parity, etc.) are not configurable at runtime; serial streams will not be
|
|
||||||
flushed when closed.
|
|
||||||
CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
|
CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
|
||||||
character timeout value is not fixed for Modbus ASCII and is therefore
|
character timeout value is not fixed for Modbus ASCII and is therefore
|
||||||
a configuration option. It should be set to the maximum expected delay
|
a configuration option. It should be set to the maximum expected delay
|
||||||
@@ -106,6 +102,13 @@ The NuttX-named configuration options that are available include:
|
|||||||
CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED - If the Read/Write Multiple
|
CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED - If the Read/Write Multiple
|
||||||
Registers function should be enabled.
|
Registers function should be enabled.
|
||||||
|
|
||||||
|
See also other serial settings, in particular:
|
||||||
|
|
||||||
|
CONFIG_SERIAL_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
|
||||||
|
tcflush, etc.). If this is not defined, then the terminal settings (baud,
|
||||||
|
parity, etc.) are not configurable at runtime; serial streams will not be
|
||||||
|
flushed when closed.
|
||||||
|
|
||||||
Note
|
Note
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
# include <termios.h>
|
# include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ static uint8_t ucBuffer[BUF_SIZE];
|
|||||||
static int uiRxBufferPos;
|
static int uiRxBufferPos;
|
||||||
static int uiTxBufferPos;
|
static int uiTxBufferPos;
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
static struct termios xOldTIO;
|
static struct termios xOldTIO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ void vMBPortSerialEnable(bool bEnableRx, bool bEnableTx)
|
|||||||
|
|
||||||
if (bEnableRx)
|
if (bEnableRx)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
(void)tcflush(iSerialFd, TCIFLUSH);
|
(void)tcflush(iSerialFd, TCIFLUSH);
|
||||||
#endif
|
#endif
|
||||||
uiRxBufferPos = 0;
|
uiRxBufferPos = 0;
|
||||||
@@ -112,9 +112,8 @@ bool xMBPortSerialInit(uint8_t ucPort, uint32_t ulBaudRate,
|
|||||||
char szDevice[16];
|
char szDevice[16];
|
||||||
bool bStatus = true;
|
bool bStatus = true;
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
struct termios xNewTIO;
|
struct termios xNewTIO;
|
||||||
speed_t xNewSpeed;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(szDevice, 16, "/dev/ttyS%d", ucPort);
|
snprintf(szDevice, 16, "/dev/ttyS%d", ucPort);
|
||||||
@@ -125,7 +124,7 @@ bool xMBPortSerialInit(uint8_t ucPort, uint32_t ulBaudRate,
|
|||||||
szDevice, errno);
|
szDevice, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
else if (tcgetattr(iSerialFd, &xOldTIO) != 0)
|
else if (tcgetattr(iSerialFd, &xOldTIO) != 0)
|
||||||
{
|
{
|
||||||
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n",
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n",
|
||||||
@@ -163,35 +162,20 @@ bool xMBPortSerialInit(uint8_t ucPort, uint32_t ulBaudRate,
|
|||||||
bStatus = false;
|
bStatus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ulBaudRate)
|
|
||||||
{
|
|
||||||
case 9600:
|
|
||||||
xNewSpeed = B9600;
|
|
||||||
break;
|
|
||||||
case 19200:
|
|
||||||
xNewSpeed = B19200;
|
|
||||||
break;
|
|
||||||
case 38400:
|
|
||||||
xNewSpeed = B38400;
|
|
||||||
break;
|
|
||||||
case 57600:
|
|
||||||
xNewSpeed = B57600;
|
|
||||||
break;
|
|
||||||
case 115200:
|
|
||||||
xNewSpeed = B115200;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bStatus = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bStatus)
|
if (bStatus)
|
||||||
{
|
{
|
||||||
if (cfsetispeed(&xNewTIO, xNewSpeed) != 0)
|
/* Set the new baud using the (non-standard) BOTHER mechanism
|
||||||
{
|
* supported by NuttX.
|
||||||
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
*/
|
||||||
ulBaudRate, errno);
|
|
||||||
}
|
xNewTIO.c_ispeed = (speed_t)ulBaudRate;
|
||||||
else if (cfsetospeed(&xNewTIO, xNewSpeed) != 0)
|
xNewTIO.c_ospeed = (speed_t)ulBaudRate;
|
||||||
|
|
||||||
|
/* NOTE: In NuttX, cfset[i|o]speed always return OK. Failures will
|
||||||
|
* only be reported when tcsetattr() is called.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (cfsetispeed(&xNewTIO, BOTHER) != 0 || cfsetospeed(&xNewTIO, BOTHER) != 0)
|
||||||
{
|
{
|
||||||
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
||||||
ulBaudRate, szDevice, errno);
|
ulBaudRate, szDevice, errno);
|
||||||
@@ -231,7 +215,7 @@ void vMBPortClose(void)
|
|||||||
{
|
{
|
||||||
if (iSerialFd != -1)
|
if (iSerialFd != -1)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
(void)tcsetattr(iSerialFd, TCSANOW, &xOldTIO);
|
(void)tcsetattr(iSerialFd, TCSANOW, &xOldTIO);
|
||||||
#endif
|
#endif
|
||||||
(void)close(iSerialFd);
|
(void)close(iSerialFd);
|
||||||
|
|||||||
+8
-1
@@ -3040,11 +3040,18 @@
|
|||||||
termios. These are non-standard interfaces but have a precedence: There are
|
termios. These are non-standard interfaces but have a precedence: There are
|
||||||
similar interfaces in AIX.
|
similar interfaces in AIX.
|
||||||
* include/sys/str_tty.h, lib/lib_setspeed.c, lib_getspeed.c, and lib_resetspeed.c:
|
* include/sys/str_tty.h, lib/lib_setspeed.c, lib_getspeed.c, and lib_resetspeed.c:
|
||||||
Sigh... removed. We don't need any more almost standard interfaces.
|
Sigh... removed. We don't need any more almost standard interfaces! (SVN
|
||||||
|
revision 4968 if you want the short-lived code).
|
||||||
* include/termios.h and lib/termios/*: Open the existing, standard termios
|
* include/termios.h and lib/termios/*: Open the existing, standard termios
|
||||||
interfaces to permit some non-standard baud settings. The new termios definitions
|
interfaces to permit some non-standard baud settings. The new termios definitions
|
||||||
still supports the POSIX standard except that it does not strictly enforce
|
still supports the POSIX standard except that it does not strictly enforce
|
||||||
baud rate settings, permitting some non-portable, but useful baud rate settings
|
baud rate settings, permitting some non-portable, but useful baud rate settings
|
||||||
(this is what the short-lived AIX-like interfaces would have accomplished as well).
|
(this is what the short-lived AIX-like interfaces would have accomplished as well).
|
||||||
|
* include/termios.h and lib/termios/*: Redesigned yet again (this is getting
|
||||||
|
painful. NuttX now supports the BOTHER baud setting just as Linux does. termios
|
||||||
|
Bxxx definitions are again encoded; cf[set|get][o|i]speed now deal with only the
|
||||||
|
encoded values. If the encoed baud is set to BOTHER, then the values in the (non-
|
||||||
|
standard) c_ispeed and c_ospeed baud values may be accessed directly.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -485,5 +485,11 @@ config USART3_2STOP
|
|||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
config SERIAL_TERMIOS
|
||||||
|
bool "Serial driver TERMIOS supported"
|
||||||
|
depends on LPC43_USART0 || LPC43_UART1 || LPC43_USART2 || LPC43_USART3
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
|
||||||
|
If this is not defined, then the terminal settings (baud, parity, etc).
|
||||||
|
are not configurable at runtime; serial streams cannot be flushed, etc..
|
||||||
|
|||||||
@@ -1756,6 +1756,15 @@ config USART6_RXDMA
|
|||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
config SERIAL_TERMIOS
|
||||||
|
bool "Serial driver TERMIOS supported"
|
||||||
|
depends on STM32_USART1 || STM32_USART2 || STM32_USART3 || STM32_UART4 || STM32_UART5 || STM32_USART6
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
|
||||||
|
If this is not defined, then the terminal settings (baud, parity, etc).
|
||||||
|
are not configurable at runtime; serial streams cannot be flushed, etc..
|
||||||
|
|
||||||
menu "SPI Configuration"
|
menu "SPI Configuration"
|
||||||
depends on STM32_SPI
|
depends on STM32_SPI
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@
|
|||||||
#include <nuttx/serial/serial.h>
|
#include <nuttx/serial/serial.h>
|
||||||
#include <nuttx/power/pm.h>
|
#include <nuttx/power/pm.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
|
# include <termios.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <arch/serial.h>
|
#include <arch/serial.h>
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
@@ -149,11 +153,23 @@ struct up_dev_s
|
|||||||
uint16_t ie; /* Saved interrupt mask bits value */
|
uint16_t ie; /* Saved interrupt mask bits value */
|
||||||
uint16_t sr; /* Saved status bits */
|
uint16_t sr; /* Saved status bits */
|
||||||
|
|
||||||
const uint8_t irq; /* IRQ associated with this USART */
|
/* If termios are supported, then the following fields may vary at
|
||||||
|
* runtime.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
|
uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||||
|
uint8_t bits; /* Number of bits (7 or 8) */
|
||||||
|
bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */
|
||||||
|
uint32_t baud; /* Configured baud */
|
||||||
|
#else
|
||||||
const uint8_t parity; /* 0=none, 1=odd, 2=even */
|
const uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||||
const uint8_t bits; /* Number of bits (7 or 8) */
|
const uint8_t bits; /* Number of bits (7 or 8) */
|
||||||
const bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */
|
const bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */
|
||||||
const uint32_t baud; /* Configured baud */
|
const uint32_t baud; /* Configured baud */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint8_t irq; /* IRQ associated with this USART */
|
||||||
const uint32_t apbclock; /* PCLK 1 or 2 frequency */
|
const uint32_t apbclock; /* PCLK 1 or 2 frequency */
|
||||||
const uint32_t usartbase; /* Base address of USART registers */
|
const uint32_t usartbase; /* Base address of USART registers */
|
||||||
const uint32_t tx_gpio; /* U[S]ART TX GPIO pin configuration */
|
const uint32_t tx_gpio; /* U[S]ART TX GPIO pin configuration */
|
||||||
@@ -181,6 +197,7 @@ struct up_dev_s
|
|||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void up_setspeed(struct uart_dev_s *dev);
|
||||||
static int up_setup(struct uart_dev_s *dev);
|
static int up_setup(struct uart_dev_s *dev);
|
||||||
static void up_shutdown(struct uart_dev_s *dev);
|
static void up_shutdown(struct uart_dev_s *dev);
|
||||||
static int up_attach(struct uart_dev_s *dev);
|
static int up_attach(struct uart_dev_s *dev);
|
||||||
@@ -770,6 +787,54 @@ static int up_dma_nextrx(struct up_dev_s *priv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_setspeed
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the serial line speed.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_SUPPRESS_UART_CONFIG
|
||||||
|
static void up_setspeed(struct uart_dev_s *dev)
|
||||||
|
{
|
||||||
|
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
||||||
|
uint32_t usartdiv32;
|
||||||
|
uint32_t mantissa;
|
||||||
|
uint32_t fraction;
|
||||||
|
uint32_t brr;
|
||||||
|
|
||||||
|
/* Configure the USART Baud Rate. The baud rate for the receiver and
|
||||||
|
* transmitter (Rx and Tx) are both set to the same value as programmed
|
||||||
|
* in the Mantissa and Fraction values of USARTDIV.
|
||||||
|
*
|
||||||
|
* baud = fCK / (16 * usartdiv)
|
||||||
|
* usartdiv = fCK / (16 * baud)
|
||||||
|
*
|
||||||
|
* Where fCK is the input clock to the peripheral (PCLK1 for USART2, 3, 4, 5
|
||||||
|
* or PCLK2 for USART1)
|
||||||
|
*
|
||||||
|
* First calculate (NOTE: all stand baud values are even so dividing by two
|
||||||
|
* does not lose precision):
|
||||||
|
*
|
||||||
|
* usartdiv32 = 32 * usartdiv = fCK / (baud/2)
|
||||||
|
*/
|
||||||
|
|
||||||
|
usartdiv32 = priv->apbclock / (priv->baud >> 1);
|
||||||
|
|
||||||
|
/* The mantissa part is then */
|
||||||
|
|
||||||
|
mantissa = usartdiv32 >> 5;
|
||||||
|
brr = mantissa << USART_BRR_MANT_SHIFT;
|
||||||
|
|
||||||
|
/* The fractional remainder (with rounding) */
|
||||||
|
|
||||||
|
fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
|
||||||
|
brr |= fraction << USART_BRR_FRAC_SHIFT;
|
||||||
|
up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_setup
|
* Name: up_setup
|
||||||
*
|
*
|
||||||
@@ -783,10 +848,6 @@ static int up_setup(struct uart_dev_s *dev)
|
|||||||
{
|
{
|
||||||
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
||||||
#ifndef CONFIG_SUPPRESS_UART_CONFIG
|
#ifndef CONFIG_SUPPRESS_UART_CONFIG
|
||||||
uint32_t usartdiv32;
|
|
||||||
uint32_t mantissa;
|
|
||||||
uint32_t fraction;
|
|
||||||
uint32_t brr;
|
|
||||||
uint32_t regval;
|
uint32_t regval;
|
||||||
|
|
||||||
/* Note: The logic here depends on the fact that that the USART module
|
/* Note: The logic here depends on the fact that that the USART module
|
||||||
@@ -858,34 +919,9 @@ static int up_setup(struct uart_dev_s *dev)
|
|||||||
|
|
||||||
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
|
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
|
||||||
|
|
||||||
/* Configure the USART Baud Rate. The baud rate for the receiver and
|
/* Configure the USART Baud Rate. */
|
||||||
* transmitter (Rx and Tx) are both set to the same value as programmed
|
|
||||||
* in the Mantissa and Fraction values of USARTDIV.
|
|
||||||
*
|
|
||||||
* baud = fCK / (16 * usartdiv)
|
|
||||||
* usartdiv = fCK / (16 * baud)
|
|
||||||
*
|
|
||||||
* Where fCK is the input clock to the peripheral (PCLK1 for USART2, 3, 4, 5
|
|
||||||
* or PCLK2 for USART1)
|
|
||||||
*
|
|
||||||
* First calculate (NOTE: all stand baud values are even so dividing by two
|
|
||||||
* does not lose precision):
|
|
||||||
*
|
|
||||||
* usartdiv32 = 32 * usartdiv = fCK / (baud/2)
|
|
||||||
*/
|
|
||||||
|
|
||||||
usartdiv32 = priv->apbclock / (priv->baud >> 1);
|
up_setspeed(dev);
|
||||||
|
|
||||||
/* The mantissa part is then */
|
|
||||||
|
|
||||||
mantissa = usartdiv32 >> 5;
|
|
||||||
brr = mantissa << USART_BRR_MANT_SHIFT;
|
|
||||||
|
|
||||||
/* The fractional remainder (with rounding) */
|
|
||||||
|
|
||||||
fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
|
|
||||||
brr |= fraction << USART_BRR_FRAC_SHIFT;
|
|
||||||
up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
|
|
||||||
|
|
||||||
/* Enable Rx, Tx, and the USART */
|
/* Enable Rx, Tx, and the USART */
|
||||||
|
|
||||||
@@ -1182,26 +1218,75 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
|
|||||||
{
|
{
|
||||||
struct inode *inode = filep->f_inode;
|
struct inode *inode = filep->f_inode;
|
||||||
struct uart_dev_s *dev = inode->i_private;
|
struct uart_dev_s *dev = inode->i_private;
|
||||||
#ifdef CONFIG_USART_BREAKS
|
|
||||||
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
||||||
#endif
|
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case TIOCSERGSTRUCT:
|
case TIOCSERGSTRUCT:
|
||||||
{
|
{
|
||||||
struct up_dev_s *user = (struct up_dev_s*)arg;
|
struct up_dev_s *user = (struct up_dev_s*)arg;
|
||||||
if (!user)
|
if (!user)
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(user, dev, sizeof(struct up_dev_s));
|
memcpy(user, dev, sizeof(struct up_dev_s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
|
case TCGETS:
|
||||||
|
{
|
||||||
|
struct termios *termiosp = (struct termios*)arg;
|
||||||
|
|
||||||
|
if (!termiosp)
|
||||||
|
{
|
||||||
|
ret = -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: (1) Note that only the BOTHER baud is returned; (2) Other
|
||||||
|
* termios fields are not yet initialized. Here we also exploit the
|
||||||
|
* internal knowledge that ctfsetospeed() is equivalent to
|
||||||
|
* cfsetispeed().
|
||||||
|
*/
|
||||||
|
|
||||||
|
cfsetispeed(termiosp, BOTHER);
|
||||||
|
termiosp->c_ispeed = priv->baud;
|
||||||
|
termiosp->c_ospeed = priv->baud;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TCSETS:
|
||||||
|
{
|
||||||
|
struct termios *termiosp = (struct termios*)arg;
|
||||||
|
|
||||||
|
if (!termiosp)
|
||||||
|
{
|
||||||
|
ret = -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Only the BOTHER speed setting is supported. Here we
|
||||||
|
* also exploit the internal knowledge that ctfgetospeed() is
|
||||||
|
* equivalent to cfgetispeed().
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (cfgetospeed(termiosp) != BOTHER ||
|
||||||
|
termiosp->c_ispeed != termiosp->c_ospeed)
|
||||||
|
{
|
||||||
|
ret = -ENOSYS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->baud = termiosp->c_ispeed;
|
||||||
|
up_setspeed(dev);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_USART_BREAKS
|
#ifdef CONFIG_USART_BREAKS
|
||||||
case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */
|
case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */
|
||||||
|
|||||||
@@ -1188,6 +1188,15 @@ config UART6_2STOP
|
|||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
config SERIAL_TERMIOS
|
||||||
|
bool "Serial driver TERMIOS supported"
|
||||||
|
depends on PIC32MX_UART1 || PIC32MX_UART2 || PIC32MX_UART3 || PIC32MX_UART4 || PIC32MX_UART5 || PIC32MX_UART6
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
|
||||||
|
If this is not defined, then the terminal settings (baud, parity, etc).
|
||||||
|
are not configurable at runtime; serial streams cannot be flushed, etc..
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "PIC32MX PHY Selection"
|
prompt "PIC32MX PHY Selection"
|
||||||
depends on PIC32MX_ETHERNET
|
depends on PIC32MX_ETHERNET
|
||||||
|
|||||||
@@ -181,6 +181,11 @@ CONFIG_LPC43_WWDT=n
|
|||||||
#
|
#
|
||||||
# LPC43xx specific serial device driver settings
|
# LPC43xx specific serial device driver settings
|
||||||
#
|
#
|
||||||
|
# CONFIG_SERIAL_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
|
||||||
|
# tcflush, etc.). If this is not defined, then the terminal settings (baud,
|
||||||
|
# parity, etc.) are not configurable at runtime; serial streams cannot be
|
||||||
|
# flushed, etc.
|
||||||
|
#
|
||||||
# CONFIG_U[S]ARTn_SERIAL_CONSOLE - selects the UARTn for the
|
# CONFIG_U[S]ARTn_SERIAL_CONSOLE - selects the UARTn for the
|
||||||
# console and ttys0 (default is the UART1).
|
# console and ttys0 (default is the UART1).
|
||||||
# CONFIG_U[S]ARTn_RXBUFSIZE - Characters are buffered as received.
|
# CONFIG_U[S]ARTn_RXBUFSIZE - Characters are buffered as received.
|
||||||
@@ -192,6 +197,8 @@ CONFIG_LPC43_WWDT=n
|
|||||||
# CONFIG_U[S]ARTn_PARTIY - 0=no parity, 1=odd parity, 2=even parity
|
# CONFIG_U[S]ARTn_PARTIY - 0=no parity, 1=odd parity, 2=even parity
|
||||||
# CONFIG_U[S]ARTn_2STOP - Two stop bits
|
# CONFIG_U[S]ARTn_2STOP - Two stop bits
|
||||||
#
|
#
|
||||||
|
CONFIG_SERIAL_TERMIOS=n
|
||||||
|
|
||||||
CONFIG_USART0_SERIAL_CONSOLE=y
|
CONFIG_USART0_SERIAL_CONSOLE=y
|
||||||
CONFIG_UART1_SERIAL_CONSOLE=n
|
CONFIG_UART1_SERIAL_CONSOLE=n
|
||||||
CONFIG_USART2_SERIAL_CONSOLE=n
|
CONFIG_USART2_SERIAL_CONSOLE=n
|
||||||
@@ -776,10 +783,6 @@ CONFIG_FTPD_CMDBUFFERSIZE=2048
|
|||||||
# CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
|
# CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
|
||||||
# CONFIG_MB_RTU_ENABLED - Modbus RTU support
|
# CONFIG_MB_RTU_ENABLED - Modbus RTU support
|
||||||
# CONFIG_MB_TCP_ENABLED - Modbus TCP support
|
# CONFIG_MB_TCP_ENABLED - Modbus TCP support
|
||||||
# CONFIG_MB_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
|
|
||||||
# tcflush, etc.). If this is not defined, then the terminal settings (baud,
|
|
||||||
# parity, etc.) are not configurable at runtime; serial streams will not be
|
|
||||||
# flushed when closed.
|
|
||||||
# CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
|
# CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
|
||||||
# character timeout value is not fixed for Modbus ASCII and is therefore
|
# character timeout value is not fixed for Modbus ASCII and is therefore
|
||||||
# a configuration option. It should be set to the maximum expected delay
|
# a configuration option. It should be set to the maximum expected delay
|
||||||
@@ -826,7 +829,6 @@ CONFIG_MODBUS=n
|
|||||||
CONFIG_MB_ASCII_ENABLED=y
|
CONFIG_MB_ASCII_ENABLED=y
|
||||||
CONFIG_MB_RTU_ENABLED=y
|
CONFIG_MB_RTU_ENABLED=y
|
||||||
CONFIG_MB_TCP_ENABLED=n
|
CONFIG_MB_TCP_ENABLED=n
|
||||||
CONFIG_MB_TERMIOS=n
|
|
||||||
CONFIG_MB_ASCII_TIMEOUT_SEC=1
|
CONFIG_MB_ASCII_TIMEOUT_SEC=1
|
||||||
CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS=0
|
CONFIG_MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS=0
|
||||||
CONFIG_MB_FUNC_HANDLERS_MAX=16
|
CONFIG_MB_FUNC_HANDLERS_MAX=16
|
||||||
|
|||||||
+115
-116
@@ -50,131 +50,133 @@
|
|||||||
|
|
||||||
/* Terminal input modes (c_iflag in the termios structure) */
|
/* Terminal input modes (c_iflag in the termios structure) */
|
||||||
|
|
||||||
#define BRKINT (1 << 0) /* Signal interrupt on break */
|
#define BRKINT (1 << 0) /* Bit 0: Signal interrupt on break */
|
||||||
#define ICRNL (1 << 1) /* Map CR to NL on input */
|
#define ICRNL (1 << 1) /* Bit 1: Map CR to NL on input */
|
||||||
#define IGNBRK (1 << 2) /* Ignore break condition */
|
#define IGNBRK (1 << 2) /* Bit 2: Ignore break condition */
|
||||||
#define IGNCR (1 << 3) /* Ignore CR */
|
#define IGNCR (1 << 3) /* Bit 3: Ignore CR */
|
||||||
#define IGNPAR (1 << 4) /* Ignore characters with parity errors */
|
#define IGNPAR (1 << 4) /* Bit 4: Ignore characters with parity errors */
|
||||||
#define INLCR (1 << 5) /* Map NL to CR on input */
|
#define INLCR (1 << 5) /* Bit 5: Map NL to CR on input */
|
||||||
#define INPCK (1 << 6) /* Enable input parity check */
|
#define INPCK (1 << 6) /* Bit 6: Enable input parity check */
|
||||||
#define ISTRIP (1 << 7) /* Strip character */
|
#define ISTRIP (1 << 7) /* Bit 7: Strip character */
|
||||||
#define IUCLC (1 << 8) /* Map upper-case to lower-case on input (LEGACY) */
|
#define IUCLC (1 << 8) /* Bit 8: Map upper-case to lower-case on input (LEGACY) */
|
||||||
#define IXANY (1 << 9) /* Enable any character to restart output */
|
#define IXANY (1 << 9) /* Bit 9: Enable any character to restart output */
|
||||||
#define IXOFF (1 << 10) /* Enable start/stop input control */
|
#define IXOFF (1 << 10) /* Bit 10: Enable start/stop input control */
|
||||||
#define IXON (1 << 11) /* Enable start/stop output control */
|
#define IXON (1 << 11) /* Bit 11: Enable start/stop output control */
|
||||||
#define PARMRK (1 << 12) /* Mark parity errors */
|
#define PARMRK (1 << 12) /* Bit 12: Mark parity errors */
|
||||||
|
|
||||||
/* Terminal output modes (c_oflag in the termios structure) */
|
/* Terminal output modes (c_oflag in the termios structure) */
|
||||||
|
|
||||||
#define OPOST (1 << 0) /* Post-process output */
|
#define OPOST (1 << 0) /* Bit 0: Post-process output */
|
||||||
#define OLCUC (1 << 1) /* Map lower-case to upper-case on output (LEGACY) */
|
#define OLCUC (1 << 1) /* Bit 1: Map lower-case to upper-case on output (LEGACY) */
|
||||||
#define ONLCR (1 << 2) /* Map NL to CR-NL on output */
|
#define ONLCR (1 << 2) /* Bit 2: Map NL to CR-NL on output */
|
||||||
#define OCRNL (1 << 3) /* Map CR to NL on output */
|
#define OCRNL (1 << 3) /* Bit 3: Map CR to NL on output */
|
||||||
#define ONOCR (1 << 4) /* No CR output at column 0 */
|
#define ONOCR (1 << 4) /* Bit 4: No CR output at column 0 */
|
||||||
#define ONLRET (1 << 5) /* NL performs CR function */
|
#define ONLRET (1 << 5) /* Bit 5: NL performs CR function */
|
||||||
#define OFILL (1 << 6) /* Use fill characters for delay */
|
#define OFILL (1 << 6) /* Bit 6: Use fill characters for delay */
|
||||||
#define NLDLY (1 << 7) /* Select newline delays: */
|
#define NLDLY (1 << 7) /* Bit 7: Select newline delays: */
|
||||||
# define NL0 (0 << 7) /* Newline character type 0 */
|
# define NL0 (0 << 7) /* Newline character type 0 */
|
||||||
# define NL1 (1 << 7) /* Newline character type 1 */
|
# define NL1 (1 << 7) /* Newline character type 1 */
|
||||||
#define CRDLY (3 << 8) /* Select carriage-return delays: */
|
#define CRDLY (3 << 8) /* Bits 8-9: Select carriage-return delays: */
|
||||||
# define CR0 (0 << 8) /* Carriage-return delay type 0 */
|
# define CR0 (0 << 8) /* Carriage-return delay type 0 */
|
||||||
# define CR1 (1 << 8) /* Carriage-return delay type 1 */
|
# define CR1 (1 << 8) /* Carriage-return delay type 1 */
|
||||||
# define CR2 (2 << 8) /* Carriage-return delay type 2 */
|
# define CR2 (2 << 8) /* Carriage-return delay type 2 */
|
||||||
# define CR3 (3 << 8) /* Carriage-return delay type 3 */
|
# define CR3 (3 << 8) /* Carriage-return delay type 3 */
|
||||||
#define TABDLY (3 << 10) /* Select horizontal-tab delays: */
|
#define TABDLY (3 << 10) /* Bit 10-11: Select horizontal-tab delays: */
|
||||||
# define TAB0 (0 << 10) /* Horizontal-tab delay type 0 */
|
# define TAB0 (0 << 10) /* Horizontal-tab delay type 0 */
|
||||||
# define TAB1 (1 << 10) /* Horizontal-tab delay type 1 */
|
# define TAB1 (1 << 10) /* Horizontal-tab delay type 1 */
|
||||||
# define TAB2 (2 << 10) /* Horizontal-tab delay type 2 */
|
# define TAB2 (2 << 10) /* Horizontal-tab delay type 2 */
|
||||||
# define TAB3 (3 << 10) /* Expand tabs to spaces */
|
# define TAB3 (3 << 10) /* Expand tabs to spaces */
|
||||||
#define BSDLY (1 << 12) /* Select backspace delays: */
|
#define BSDLY (1 << 12) /* Bit 12: Select backspace delays: */
|
||||||
# define BS0 (0 << 12) /* Backspace-delay type 0 */
|
# define BS0 (0 << 12) /* Backspace-delay type 0 */
|
||||||
# define BS1 (1 << 12) /* Backspace-delay type 1 */
|
# define BS1 (1 << 12) /* Backspace-delay type 1 */
|
||||||
#define VTDLY (1 << 13) /* Select vertical-tab delays: */
|
#define VTDLY (1 << 13) /* Bit 13: Select vertical-tab delays: */
|
||||||
# define VT0 (0 << 13) /* Vertical-tab delay type 0 */
|
# define VT0 (0 << 13) /* Vertical-tab delay type 0 */
|
||||||
# define VT1 (1 << 13) /* Vertical-tab delay type 1 */
|
# define VT1 (1 << 13) /* Vertical-tab delay type 1 */
|
||||||
#define FFDLY (1 << 14) /* Select form-feed delays: */
|
#define FFDLY (1 << 14) /* Bit 14: Select form-feed delays: */
|
||||||
# define FF0 (0 << 14) /* Form-feed delay type 0 */
|
# define FF0 (0 << 14) /* Form-feed delay type 0 */
|
||||||
# define FF1 (1 << 14) /* Form-feed delay type 1 */
|
# define FF1 (1 << 14) /* Form-feed delay type 1 */
|
||||||
|
|
||||||
/* Control Modes (c_cflag in the termios structure) */
|
/* Control Modes (c_cflag in the termios structure) */
|
||||||
|
|
||||||
#define CSIZE (3 << 0) /* Character size: */
|
#define CBAUD (0x0f) /* Bits 0-3: baud */
|
||||||
# define CS5 (0 << 0) /* 5 bits */
|
#define CBAUDEX (1 << 4) /* Bit 4: Extended baud */
|
||||||
# define CS6 (1 << 0) /* 6 bits */
|
#define CSIZE (3 << 5) /* Bits 5-6: Character size: */
|
||||||
# define CS7 (2 << 0) /* 7 bits */
|
# define CS5 (0 << 5) /* 5 bits */
|
||||||
# define CS8 (3 << 0) /* 8 bits */
|
# define CS6 (1 << 5) /* 6 bits */
|
||||||
#define CSTOPB (1 << 2) /* Send two stop bits, else one */
|
# define CS7 (2 << 5) /* 7 bits */
|
||||||
#define CREAD (1 << 3) /* Enable receiver */
|
# define CS8 (3 << 5) /* 8 bits */
|
||||||
#define PARENB (1 << 4) /* Parity enable */
|
#define CSTOPB (1 << 7) /* Bit 7: Send two stop bits, else one */
|
||||||
#define PARODD (1 << 5) /* Odd parity, else even */
|
#define CREAD (1 << 8) /* Bit 8: Enable receiver */
|
||||||
#define HUPCL (1 << 6) /* Hang up on last close */
|
#define PARENB (1 << 9) /* Bit 9: Parity enable */
|
||||||
#define CLOCAL (1 << 7) /* Ignore modem status lines */
|
#define PARODD (1 << 10) /* Bit 10: Odd parity, else even */
|
||||||
|
#define HUPCL (1 << 11) /* Bit 11: Hang up on last close */
|
||||||
|
#define CLOCAL (1 << 12) /* Bit 12: Ignore modem status lines */
|
||||||
|
|
||||||
/* Local Modes (c_lflag in the termios structure) */
|
/* Local Modes (c_lflag in the termios structure) */
|
||||||
|
|
||||||
#define ECHO (1 << 0) /* Enable echo */
|
#define ECHO (1 << 0) /* Bit 0: Enable echo */
|
||||||
#define ECHOE (1 << 1) /* Echo erase character as error-correcting backspace */
|
#define ECHOE (1 << 1) /* Bit 1: Echo erase character as error-correcting backspace */
|
||||||
#define ECHOK (1 << 2) /* Echo KILL */
|
#define ECHOK (1 << 2) /* Bit 2: Echo KILL */
|
||||||
#define ECHONL (1 << 3) /* Echo NL */
|
#define ECHONL (1 << 3) /* Bit 3: Echo NL */
|
||||||
#define ICANON (1 << 4) /* Canonical input (erase and kill processing) */
|
#define ICANON (1 << 4) /* Bit 4: Canonical input (erase and kill processing) */
|
||||||
#define IEXTEN (1 << 5) /* Enable extended input character processing */
|
#define IEXTEN (1 << 5) /* Bit 5: Enable extended input character processing */
|
||||||
#define ISIG (1 << 6) /* Enable signals */
|
#define ISIG (1 << 6) /* Bit 6: Enable signals */
|
||||||
#define NOFLSH (1 << 7) /* Disable flush after interrupt or quit */
|
#define NOFLSH (1 << 7) /* Bit 7: Disable flush after interrupt or quit */
|
||||||
#define TOSTOP (1 << 8) /* Send SIGTTOU for background output */
|
#define TOSTOP (1 << 8) /* Bit 8: Send SIGTTOU for background output */
|
||||||
#define XCASE (1 << 9) /* Canonical upper/lower presentation (LEGACY) */
|
#define XCASE (1 << 9) /* Bit 9: Canonical upper/lower presentation (LEGACY) */
|
||||||
|
|
||||||
/* The following are subscript names for the termios c_cc array */
|
/* The following are subscript names for the termios c_cc array */
|
||||||
|
|
||||||
#define VEOF 0 /* EOF character (canonical mode) */
|
#define VEOF 0 /* Bit 0: EOF character (canonical mode) */
|
||||||
#define VMIN VEOF /* MIN value (Non-canonical mode) */
|
#define VMIN VEOF /* Bit 0: MIN value (Non-canonical mode) */
|
||||||
#define VEOL 1 /* EOL character (canonical mode) */
|
#define VEOL 1 /* Bit 1: EOL character (canonical mode) */
|
||||||
#define VTIME VEOL /* TIME value (Non-canonical mode) */
|
#define VTIME VEOL /* Bit 1: TIME value (Non-canonical mode) */
|
||||||
#define VERASE 2 /* ERASE character (canonical mode) */
|
#define VERASE 2 /* Bit 2: ERASE character (canonical mode) */
|
||||||
#define VINTR 3 /* INTR character */
|
#define VINTR 3 /* Bit 3: INTR character */
|
||||||
#define VKILL 4 /* KILL character (canonical mode) */
|
#define VKILL 4 /* Bit 4: KILL character (canonical mode) */
|
||||||
#define VQUIT 5 /* QUIT character */
|
#define VQUIT 5 /* Bit 5: QUIT character */
|
||||||
#define VSTART 6 /* START character */
|
#define VSTART 6 /* Bit 6: START character */
|
||||||
#define VSTOP 7 /* STOP character */
|
#define VSTOP 7 /* Bit 7: STOP character */
|
||||||
#define VSUSP 8 /* SUSP character */
|
#define VSUSP 8 /* Bit 8: SUSP character */
|
||||||
#define NCCS 9 /* Size of the array c_cc for control characters */
|
#define NCCS 9 /* Bit 9: Size of the array c_cc for control characters */
|
||||||
|
|
||||||
/* Baud Rate Selection (objects of type speed_t). NOTE that as a simplification
|
/* Baud Rate Selection. */
|
||||||
* in NuttX, the value of the baud symbol is the buad rate itself; not an encoded
|
|
||||||
* value as you will see in most implementations of termios.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define B0 0 /* Hang up */
|
#define B0 (0x00) /* Hang up */
|
||||||
#define B50 50 /* 50 baud */
|
#define B50 (0x01) /* 50 baud */
|
||||||
#define B75 75 /* 75 baud */
|
#define B75 (0x02) /* 75 baud */
|
||||||
#define B110 110 /* 110 baud */
|
#define B110 (0x03) /* 110 baud */
|
||||||
#define B134 134 /* 134.5 baud */
|
#define B134 (0x04) /* 134.5 baud */
|
||||||
#define B150 150 /* 150 baud */
|
#define B150 (0x05) /* 150 baud */
|
||||||
#define B200 200 /* 200 baud */
|
#define B200 (0x06) /* 200 baud */
|
||||||
#define B300 300 /* 300 baud */
|
#define B300 (0x07) /* 300 baud */
|
||||||
#define B600 600 /* 600 baud */
|
#define B600 (0x08) /* 600 baud */
|
||||||
#define B1200 1200 /* 1,200 baud */
|
#define B1200 (0x09) /* 1,200 baud */
|
||||||
#define B1800 1800 /* 1,800 baud */
|
#define B1800 (0x0a) /* 1,800 baud */
|
||||||
#define B2400 2400 /* 2,400 baud */
|
#define B2400 (0x0b) /* 2,400 baud */
|
||||||
#define B4800 4800 /* 4,800 baud */
|
#define B4800 (0x0c) /* 4,800 baud */
|
||||||
#define B9600 9600 /* 9,600 baud */
|
#define B9600 (0x0d) /* 9,600 baud */
|
||||||
#define B19200 19200 /* 19,200 baud */
|
#define B19200 (0x0e) /* 19,200 baud */
|
||||||
#define B38400 38400 /* 38,400 baud */
|
#define B38400 (0x0f) /* 38,400 baud */
|
||||||
|
|
||||||
#define B57600 57600 /* 57,600 baud */
|
/* "Extended" baud rates above 37K include the CBAUDEX bit */
|
||||||
#define B115200 115200 /* 115,200 baud */
|
|
||||||
#define B128000 128000 /* 128,000 baud */
|
#define BOTHER (CBAUDEX | 0x00) /* Use baud values in c_ispeed and c_ospeed */
|
||||||
#define B230400 230400 /* 230,400 baud */
|
#define B57600 (CBAUDEX | 0x01) /* 57,600 baud */
|
||||||
#define B256000 256000 /* 256,000 baud */
|
#define B115200 (CBAUDEX | 0x02) /* 115,200 baud */
|
||||||
#define B460800 460800 /* 460,800 baud */
|
#define B128000 (CBAUDEX | 0x03) /* 128,000 baud */
|
||||||
#define B500000 500000 /* 500,000 baud */
|
#define B230400 (CBAUDEX | 0x04) /* 230,400 baud */
|
||||||
#define B576000 576000 /* 576,000 baud */
|
#define B256000 (CBAUDEX | 0x05) /* 256,000 baud */
|
||||||
#define B921600 921600 /* 921,600 baud */
|
#define B460800 (CBAUDEX | 0x06) /* 460,800 baud */
|
||||||
#define B1000000 1000000 /* 1,000,000 baud */
|
#define B500000 (CBAUDEX | 0x07) /* 500,000 baud */
|
||||||
#define B1152000 1152000 /* 1,152,000 baud */
|
#define B576000 (CBAUDEX | 0x08) /* 576,000 baud */
|
||||||
#define B1500000 1500000 /* 1,500,000 baud */
|
#define B921600 (CBAUDEX | 0x09) /* 921,600 baud */
|
||||||
#define B2000000 2000000 /* 2,000,000 baud */
|
#define B1000000 (CBAUDEX | 0x0a) /* 1,000,000 baud */
|
||||||
#define B2500000 2500000 /* 2,500,000 baud */
|
#define B1152000 (CBAUDEX | 0x0b) /* 1,152,000 baud */
|
||||||
#define B3000000 3000000 /* 3,000,000 baud */
|
#define B1500000 (CBAUDEX | 0x0c) /* 1,500,000 baud */
|
||||||
|
#define B2000000 (CBAUDEX | 0x0d) /* 2,000,000 baud */
|
||||||
|
#define B2500000 (CBAUDEX | 0x0e) /* 2,500,000 baud */
|
||||||
|
#define B3000000 (CBAUDEX | 0x0f) /* 3,000,000 baud */
|
||||||
|
|
||||||
/* Attribute Selection (used with tcsetattr()) */
|
/* Attribute Selection (used with tcsetattr()) */
|
||||||
|
|
||||||
@@ -220,13 +222,10 @@ struct termios
|
|||||||
tcflag_t c_lflag; /* Local modes */
|
tcflag_t c_lflag; /* Local modes */
|
||||||
cc_t c_cc[NCCS]; /* Control chars */
|
cc_t c_cc[NCCS]; /* Control chars */
|
||||||
|
|
||||||
/* Implementation specific fields. For portability reasons, these fields
|
/* If CBAUD == BOTHER, then these fields hold the input/output BAUD. */
|
||||||
* should not be accessed directly, but rather through only through the
|
|
||||||
* cf[set|get][o|i]speed() POSIX interfaces.
|
|
||||||
*/
|
|
||||||
|
|
||||||
speed_t c_ispeed; /* Input speed */
|
speed_t c_ispeed; /* Input speed (non-POSIX)*/
|
||||||
speed_t c_ospeed; /* Output speed */
|
speed_t c_ospeed; /* Output speed (non-POSIX) */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -70,24 +70,21 @@
|
|||||||
* This function shall return exactly the value in the termios data
|
* This function shall return exactly the value in the termios data
|
||||||
* structure, without interpretation.
|
* structure, without interpretation.
|
||||||
*
|
*
|
||||||
* NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
|
* NOTE 1: NuttX does not not control input/output baud rates independently
|
||||||
* and the baud encodings of termios.h are the actual baud values
|
* Hense, this function is *identical* to cfgetospeed.
|
||||||
* themselves. Therefore, any baud value can be provided as the speed
|
* NOTE 2: If this function returns BOTHER and the more flexible input
|
||||||
* argument here. However, if you do so, your code will *NOT* be portable
|
* speed can be obtained from the Linux-like c_ispeed field.
|
||||||
* to other environments where speed_t is smaller and where the termios.h
|
|
||||||
* baud values are encoded! To avoid portability issues, use the baud
|
|
||||||
* definitions in termios.h!
|
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* termiosp - The termiosp argument is a pointer to a termios structure.
|
* termiosp - The termiosp argument is a pointer to a termios structure.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Baud value in the termios structure (not verified).
|
* Encoded baud value from the termios structure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
speed_t cfgetispeed(const struct termios *termios_p)
|
speed_t cfgetispeed(const struct termios *termios_p)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(termios_p);
|
DEBUGASSERT(termios_p);
|
||||||
return termios_p->c_ispeed;
|
return (termios_p->c_cflag & (CBAUD | CBAUDEX));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,24 +70,21 @@
|
|||||||
* This function shall return exactly the value in the termios data
|
* This function shall return exactly the value in the termios data
|
||||||
* structure, without interpretation.
|
* structure, without interpretation.
|
||||||
*
|
*
|
||||||
* NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
|
* NOTE 1: NuttX does not not control input/output baud rates independently
|
||||||
* and the baud encodings of termios.h are the actual baud values
|
* Hense, this function is *identical* to cfgetispeed.
|
||||||
* themselves. Therefore, any baud value can be provided as the speed
|
* NOTE 2: If this function returns BOTHER and the more flexible input
|
||||||
* argument here. However, if you do so, your code will *NOT* be portable
|
* speed can be obtained from the Linux-like c_ospeed field.
|
||||||
* to other environments where speed_t is smaller and where the termios.h
|
|
||||||
* baud values are encoded! To avoid portability issues, use the baud
|
|
||||||
* definitions in termios.h!
|
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* termiosp - The termiosp argument is a pointer to a termios structure.
|
* termiosp - The termiosp argument is a pointer to a termios structure.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Baud value in the termios structure (not verified).
|
* Encoded baud value from the termios structure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
speed_t cfgetospeed(const struct termios *termios_p)
|
speed_t cfgetospeed(const struct termios *termios_p)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(termios_p);
|
DEBUGASSERT(termios_p);
|
||||||
return termios_p->c_ospeed;
|
return (termios_p->c_cflag & (CBAUD | CBAUDEX));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,26 +71,26 @@
|
|||||||
* There is no effect on the baud rates set in the hardware until a
|
* There is no effect on the baud rates set in the hardware until a
|
||||||
* subsequent successful call to tcsetattr() on the same termios structure.
|
* subsequent successful call to tcsetattr() on the same termios structure.
|
||||||
*
|
*
|
||||||
* NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
|
* NOTE 1: NuttX does not not control input/output baud rates independently
|
||||||
* and the baud encodings of termios.h are the actual baud values
|
* Hense, this function is *identical* to cfsetospeed.
|
||||||
* themselves. Therefore, any baud value can be provided as the speed
|
* NOTE 2: If the specia value BOTHER is used, then the actual input baud
|
||||||
* argument here. However, if you do so, your code will *NOT* be portable
|
* must also be provided in the (non-standard) c_ispeed field.
|
||||||
* to other environments where speed_t is smaller and where the termios.h
|
|
||||||
* baud values are encoded! To avoid portability issues, use the baud
|
|
||||||
* definitions in termios.h!
|
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* termiosp - The termiosp argument is a pointer to a termios structure.
|
* termiosp - The termiosp argument is a pointer to a termios structure.
|
||||||
* speed - The new input speed
|
* speed - The new input speed
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Baud is not checked... OK is always returned.
|
* Baud is not checked... OK is always returned (this is non-standard
|
||||||
|
* behavior).
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int cfsetispeed(struct termios *termios_p, speed_t speed)
|
int cfsetispeed(struct termios *termios_p, speed_t speed)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(termios_p);
|
DEBUGASSERT(termios_p);
|
||||||
termios_p->c_ispeed = speed;
|
speed &= (CBAUD | CBAUDEX);
|
||||||
|
termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
|
||||||
|
termios_p->c_cflag |= speed;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,26 +71,26 @@
|
|||||||
* There is no effect on the baud rates set in the hardware until a
|
* There is no effect on the baud rates set in the hardware until a
|
||||||
* subsequent successful call to tcsetattr() on the same termios structure.
|
* subsequent successful call to tcsetattr() on the same termios structure.
|
||||||
*
|
*
|
||||||
* NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
|
* NOTE 1: NuttX does not not control input/output baud rates independently
|
||||||
* and the baud encodings of termios.h are the actual baud values
|
* Hense, this function is *identical* to cfsetispeed.
|
||||||
* themselves. Therefore, any baud value can be provided as the speed
|
* NOTE 2: If the specia value BOTHER is used, then the actual input baud
|
||||||
* argument here. However, if you do so, your code will *NOT* be portable
|
* must also be provided in the (non-standard) c_ospeed field.
|
||||||
* to other environments where speed_t is smaller and where the termios.h
|
|
||||||
* baud values are encoded! To avoid portability issues, use the baud
|
|
||||||
* definitions in termios.h!
|
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* termiosp - The termiosp argument is a pointer to a termios structure.
|
* termiosp - The termiosp argument is a pointer to a termios structure.
|
||||||
* speed - The new output speed
|
* speed - The new output speed
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Baud is not checked... OK is always returned.
|
* Baud is not checked... OK is always returned (this is non-standard
|
||||||
|
* behavior).
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int cfsetospeed(struct termios *termios_p, speed_t speed)
|
int cfsetospeed(struct termios *termios_p, speed_t speed)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(termios_p);
|
DEBUGASSERT(termios_p);
|
||||||
termios_p->c_ospeed = speed;
|
speed &= (CBAUD | CBAUDEX);
|
||||||
|
termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
|
||||||
|
termios_p->c_cflag |= speed;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user