Extract translation from peripheral_open_flags to flock()'s lock type.
Change-Id: Ifcb933a70c30f077b55facd3f78ea5c3c47298e9
/**
* @platform
+ * @brief Opens the UART slave device.
+ * @since_tizen 6.5
+ * @privlevel platform
+ * @privilege http://tizen.org/privilege/peripheralio
+ * @remarks @a uart should be released with peripheral_uart_close()
+ *
+ * @param[in] port The UART port number that the slave device is connected
+ * @param[in] flags The flags to open call
+ * @param[out] uart The UART handle is created on success
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
+ * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
+ * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ *
+ * @post peripheral_uart_close()
+ */
+int peripheral_uart_open_flags(int port, peripheral_open_flags_e flags, peripheral_uart_h *uart);
+
+/**
+ * @platform
* @brief Closes the UART slave device.
* @since_tizen 4.0
* @privlevel platform
#include <unistd.h>
#include "log.h"
+#include "peripheral_io.h"
#define MAX_ERR_LEN 255
int peripheral_wait_for_udev(struct udev_monitor *monitor, UdevCompareFunc func, void *func_data);
int peripheral_write_pin_to_file(const char *file_name, int pin);
+
+static inline int peripheral_get_lock_type(peripheral_open_flags_e flags)
+{
+ if (flags == PERIPHERAL_OPEN_FLAGS_SHARED)
+ return LOCK_SH;
+ return LOCK_EX;
+}
int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flags, peripheral_i2c_h *i2c)
{
int ret;
- int lock_type = LOCK_EX;
-
char path[DEV_PATH_FMT_MAX_SIZE] = {0, }; /* space for /dev/i2c-%d */
RETVM_IF(!__is_feature_supported(), PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported");
ret = ioctl(handle->fd, I2C_SLAVE, address);
CHECK_ERROR(ret);
- if (flags == PERIPHERAL_OPEN_FLAGS_SHARED)
- lock_type = LOCK_SH;
-
ret = PERIPHERAL_ERROR_NONE;
- TRY_FLOCK(ret, handle->fd, lock_type | LOCK_NB, "bus : %d, address : 0x%x", bus, address);
+ TRY_FLOCK(ret, handle->fd, peripheral_get_lock_type(flags) | LOCK_NB,
+ "bus : %d, address : 0x%x", bus, address);
CHECK_ERROR(ret != PERIPHERAL_ERROR_NONE);
*i2c = handle;
/**
* @brief Initializes uart communication and creates uart handle.
*/
-int peripheral_uart_open(int port, peripheral_uart_h *uart)
+int peripheral_uart_open_flags(int port, peripheral_open_flags_e flags, 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, "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");
__attribute__ ((cleanup(cleanup_handlep))) peripheral_uart_h handle = NULL;
handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s));
CHECK_ERROR(handle->fd < 0);
int ret = PERIPHERAL_ERROR_NONE;
- TRY_FLOCK(ret, handle->fd, LOCK_EX | LOCK_NB, "uart port: %d, path: %s", port, path);
+ TRY_FLOCK(ret, handle->fd, peripheral_get_lock_type(flags) | LOCK_NB,
+ "uart port: %d, path: %s", port, path);
CHECK_ERROR(ret != PERIPHERAL_ERROR_NONE);
*uart = handle;
return PERIPHERAL_ERROR_NONE;
}
+/**
+ * @brief Initializes uart communication and creates uart handle.
+ */
+int peripheral_uart_open(int port, peripheral_uart_h *uart)
+{
+ return peripheral_uart_open_flags(port, PERIPHERAL_OPEN_FLAGS_PRIVATE, uart);
+}
+
static void peripheral_uart_flush(peripheral_uart_h uart)
{
tcflush(uart->fd, TCIOFLUSH);