tty: Support unbuffered operation to extend usecase coverage
The whole "tty" concept is conceived around efficient interrupt-driven operation. However, it's beneficial to add non interupt-driven operation under the same API: 1. Wider usecase coverage in general. 2. Allows to use the same familiar API (based on POSIX concepts) even for UART implementations without interrupt support. 3. Allows to switch operation dynamically based on the needs. For example, if the system is in degraded mode and interrupt handling cannot be trusted/disabled, allows to still output diagnostic information to user. This was the original motivation to provide such a mode, to support logging subsystem's "panic" mode. To implement this feature, tty_set_rx_buf() and tty_set_tx_buf() functions are provided, allowing to reconfigure buffers used dynamically. If configured buffer length is 0, the operation switched to unbuffered. Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
parent
fe2f30ad4c
commit
a7df3a1e09
2 changed files with 119 additions and 3 deletions
|
@ -32,10 +32,12 @@ struct tty_serial {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize buffered serial port (classically known as tty).
|
||||
* @brief Initialize serial port object (classically known as tty).
|
||||
*
|
||||
* "tty" device provides buffered, interrupt-driver access to an
|
||||
* underlying UART device.
|
||||
* "tty" device provides support for buffered, interrupt-driven,
|
||||
* timeout-controlled access to an underlying UART device. For
|
||||
* completeness, it also support non-interrupt-driven, busy-polling
|
||||
* access mode.
|
||||
*
|
||||
* @param tty tty device structure to initialize
|
||||
* @param uart_dev underlying UART device to use (should support
|
||||
|
@ -79,6 +81,34 @@ static inline void tty_set_tx_timeout(struct tty_serial *tty, s32_t timeout)
|
|||
tty->tx_timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set receive buffer for tty device.
|
||||
*
|
||||
* Set receive buffer or switch to unbuffered operation for receive.
|
||||
*
|
||||
* @param tty tty device structure
|
||||
* @param buf buffer, or NULL for unbuffered operation
|
||||
* @param size buffer buffer size, 0 for unbuffered operation
|
||||
* @return 0 on success, error code (<0) otherwise:
|
||||
* EINVAL: unsupported buffer (size)
|
||||
*/
|
||||
int tty_set_rx_buf(struct tty_serial *tty, void *buf, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Set transmit buffer for tty device.
|
||||
*
|
||||
* Set transmit buffer or switch to unbuffered operation for transmit.
|
||||
* Note that unbuffered mode is implicitly blocking, i.e. behaves as
|
||||
* if tty_set_tx_timeout(K_FOREVER) was set.
|
||||
*
|
||||
* @param tty tty device structure
|
||||
* @param buf buffer, or NULL for unbuffered operation
|
||||
* @param size buffer buffer size, 0 for unbuffered operation
|
||||
* @return 0 on success, error code (<0) otherwise:
|
||||
* EINVAL: unsupported buffer (size)
|
||||
*/
|
||||
int tty_set_tx_buf(struct tty_serial *tty, void *buf, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Read data from a tty device.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue