int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c);
/**
- * @brief Enumeration for open flags.
+ * @brief Enumeration for open flags (bitmask).
* @since_tizen 6.5
+ *
+ * @remarks Enum values are supposed to be used as bitmask, where only one
+ * value can be specified for following flag groups:
+ * - locking mode - either #PERIPHERAL_OPEN_FLAGS_PRIVATE or #PERIPHERAL_OPEN_FLAGS_SHARED can be used
+ *
+ * The #PERIPHERAL_OPEN_FLAGS_NONBLOCK can be used with all other available flags.
*/
typedef enum {
- PERIPHERAL_OPEN_FLAGS_PRIVATE = 0, /**< Exclusive access to device */
- PERIPHERAL_OPEN_FLAGS_SHARED = 1, /**< Shared access to device */
+ PERIPHERAL_OPEN_FLAGS_PRIVATE = 0, /**< Exclusive access to device */
+ PERIPHERAL_OPEN_FLAGS_SHARED = 1, /**< Shared access to device */
+ PERIPHERAL_OPEN_FLAGS_NONBLOCK = 2, /**< (Since 7.5) Nonblocking read/write flag */
} peripheral_open_flags_e;
/**
*/
int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length);
+
+/**
+ * @platform
+ * @brief Discards data queued for writing to UART slave device, but not yet transmitted.
+ * @since_tizen 7.5
+ * @privlevel platform
+ * @privilege http://tizen.org/privilege/peripheralio
+ *
+ * @param[in] uart The UART handle
+ *
+ * @return #PERIPHERAL_ERROR_NONE on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again
+ * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ *
+ */
+int peripheral_uart_flush(peripheral_uart_h uart);
+
+/**
+ * @platform
+ * @brief Waits for all data queued for UART to be transmitted.
+ * @since_tizen 7.5
+ * @privlevel platform
+ * @privilege http://tizen.org/privilege/peripheralio
+ *
+ * @param[in] uart The UART handle
+ *
+ * @return #PERIPHERAL_ERROR_NONE on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again
+ * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ *
+ */
+int peripheral_uart_drain(peripheral_uart_h uart);
+
/**
* @platform
* @brief Writes data to the UART slave device.
RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number");
- RETVM_IF(flags != PERIPHERAL_OPEN_FLAGS_PRIVATE && flags != PERIPHERAL_OPEN_FLAGS_SHARED,
- PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid flags");
+
+ /* The PRIVATE flag is actually 0 and doesn't represent any bit,
+ * it's just there so people don't have to write a magic 0 constant
+ * for shared access. This means some care needs to be taken when
+ * manipulating it as a bitflag (in particular it is skipped here). */
+ static const int ALL_OPEN_FLAGS
+ = PERIPHERAL_OPEN_FLAGS_NONBLOCK
+ | PERIPHERAL_OPEN_FLAGS_SHARED;
+ RETVM_IF(flags & ~ALL_OPEN_FLAGS, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid flags");
__attribute__ ((cleanup(cleanup_handlep))) peripheral_uart_h handle = (peripheral_uart_h)calloc(1, sizeof *handle);
if (handle == NULL) {
};
char path[DEV_PATH_FMT_MAX_SIZE] = {0, }; /* space for /dev/ttyXXX%d */
- const int FLAGS = O_RDWR | O_NOCTTY | O_CLOEXEC;
+ const int FLAGS = O_RDWR | O_NOCTTY | O_CLOEXEC | peripheral_get_nonblock_flag(flags);
int fd = -1;
int retval = peripheral_uart_find_devpath(port, path, DEV_PATH_FMT_MAX_SIZE);
return peripheral_uart_open_flags(port, PERIPHERAL_OPEN_FLAGS_PRIVATE, uart);
}
-static void peripheral_uart_flush(peripheral_uart_h uart)
+int peripheral_uart_flush(peripheral_uart_h uart)
{
- tcflush(uart->fd, TCIOFLUSH);
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+
+ int ret = tcflush(uart->fd, TCIOFLUSH);
+ CHECK_ERROR(ret < 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_uart_drain(peripheral_uart_h uart)
+{
+ RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported");
+ RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+
+ int ret = tcdrain(uart->fd);
+ CHECK_ERROR(ret < 0);
+
+ return PERIPHERAL_ERROR_NONE;
}
/**
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
- peripheral_uart_flush(uart);
+ (void)peripheral_uart_flush(uart);
ret = tcsetattr(uart->fd, TCSANOW, &tio);
CHECK_ERROR(ret != 0);
tio.c_cflag |= byteinfo[byte_size];
tio.c_cflag |= (CLOCAL | CREAD);
- peripheral_uart_flush(uart);
+ (void)peripheral_uart_flush(uart);
ret = tcsetattr(uart->fd, TCSANOW, &tio);
CHECK_ERROR(ret != 0);
break;
}
- peripheral_uart_flush(uart);
+ (void)peripheral_uart_flush(uart);
ret = tcsetattr(uart->fd, TCSANOW, &tio);
CHECK_ERROR(ret != 0);
else // PERIPHERAL_UART_STOP_BITS_2BIT
tio.c_cflag |= CSTOPB;
- peripheral_uart_flush(uart);
+ (void)peripheral_uart_flush(uart);
ret = tcsetattr(uart->fd, TCSANOW, &tio);
CHECK_ERROR(ret != 0);
else // PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE
tio.c_iflag &= ~(IXON | IXOFF | IXANY);
- peripheral_uart_flush(uart);
+ (void)peripheral_uart_flush(uart);
ret = tcsetattr(uart->fd, TCSANOW, &tio);
CHECK_ERROR(ret != 0);