typedef struct {
int pin;
+ int fd_direction;
+ int fd_edge;
+ int fd_value;
} peripheral_handle_gpio_s;
typedef struct {
typedef struct {
int chip;
int pin;
+ int fd_period;
+ int fd_duty_cycle;
+ int fd_polarity;
+ int fd_enable;
} peripheral_handle_pwm_s;
typedef struct {
#ifndef __PERIPHERAL_HANDLE_GPIO_H__
#define __PERIPHERAL_HANDLE_GPIO_H__
-int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_gpio_create(int pin, peripheral_h *handle, gpointer user_data);
int peripheral_handle_gpio_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_GPIO_H__ */
#ifndef __PERIPHERAL_HANDLE_UART_H__
#define __PERIPHERAL_HANDLE_UART_H__
-int peripheral_handle_uart_open(int port, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_uart_create(int port, peripheral_h *handle, gpointer user_data);
int peripheral_handle_uart_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_UART_H__ */
#ifndef __PERIPHERAL_INTERFACE_GPIO_H__
#define __PERIPHERAL_INTERFACE_GPIO_H__
-int peripheral_interface_gpio_open(int pin);
-int peripheral_interface_gpio_close(int pin);
-int peripheral_interface_gpio_open_file_direction(int pin, int *fd_out);
-int peripheral_interface_gpio_open_file_edge(int pin, int *fd_out);
-int peripheral_interface_gpio_open_file_value(int pin, int *fd_out);
+int peripheral_interface_gpio_export(int pin);
+int peripheral_interface_gpio_unexport(int pin);
+
+int peripheral_interface_gpio_fd_direction_open(int pin, int *fd_out);
+int peripheral_interface_gpio_fd_direction_close(int fd);
+
+int peripheral_interface_gpio_fd_edge_open(int pin, int *fd_out);
+int peripheral_interface_gpio_fd_edge_close(int fd);
+
+int peripheral_interface_gpio_fd_value_open(int pin, int *fd_out);
+int peripheral_interface_gpio_fd_value_close(int fd);
#endif /*__PERIPHERAL_INTERFACE_GPIO_H__*/
#ifndef __PERIPHERAL_INTERFACE_I2C_H__
#define __PERIPHERAL_INTERFACE_I2C_H__
-int peripheral_interface_i2c_open_file(int bus, int address, int *fd_out);
-int peripheral_interface_i2c_close(int fd);
+int peripheral_interface_i2c_fd_open(int bus, int address, int *fd_out);
+int peripheral_interface_i2c_fd_close(int fd);
#endif /* __PERIPHERAL_INTERFACE_I2C_H__ */
#ifndef __PERIPHERAL_INTERFACE_PWM_H__
#define __PERIPHERAL_INTERFACE_PWM_H__
-int peripheral_interface_pwm_open(int chip, int pin);
-int peripheral_interface_pwm_close(int chip, int pin);
-int peripheral_interface_pwm_open_file_period(int chip, int pin, int *fd_out);
-int peripheral_interface_pwm_open_file_duty_cycle(int chip, int pin, int *fd_out);
-int peripheral_interface_pwm_open_file_polarity(int chip, int pin, int *fd_out);
-int peripheral_interface_pwm_open_file_enable(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_export(int chip, int pin);
+int peripheral_interface_pwm_unexport(int chip, int pin);
+
+int peripheral_interface_pwm_fd_period_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_period_close(int fd);
+
+int peripheral_interface_pwm_fd_duty_cycle_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_duty_cycle_close(int fd);
+
+int peripheral_interface_pwm_fd_polarity_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_polarity_close(int fd);
+
+int peripheral_interface_pwm_fd_enable_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_enable_close(int fd);
#endif /* __PERIPHERAL_INTERFACE_PWM_H__ */
#ifndef __PERIPHERAL_INTERFACE_SPI_H__
#define __PERIPHERAL_INTERFACE_SPI_H__
-int peripheral_interface_spi_open_file(int bus, int cs, int *fd_out);
-int peripheral_interface_spi_close(int fd);
+int peripheral_interface_spi_fd_open(int bus, int cs, int *fd_out);
+int peripheral_interface_spi_fd_close(int fd);
#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
#ifndef __PERIPHERAL_INTERFACE_UART_H__
#define __PERIPHERAL_INTERFACE_UART_H__
-int peripheral_interface_uart_open_file(int port, int *fd_out);
-int peripheral_interface_uart_close(int fd);
+int peripheral_interface_uart_fd_open(int port, int *fd_out);
+int peripheral_interface_uart_fd_close(int fd);
#endif /* __PERIPHERAL_INTERFACE_UART_H__ */
goto out;
}
- if ((ret = peripheral_handle_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+ if ((ret = peripheral_handle_uart_create(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
goto out;
uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
return true;
}
-int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data)
+int peripheral_handle_gpio_destroy(peripheral_h handle)
+{
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ ret = peripheral_interface_gpio_fd_direction_close(handle->type.gpio.fd_direction);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to gpio close direction fd");
+
+ ret = peripheral_interface_gpio_fd_edge_close(handle->type.gpio.fd_edge);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to gpio close edge fd");
+
+ peripheral_interface_gpio_fd_value_close(handle->type.gpio.fd_value);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to gpio close value fd");
+
+ ret = peripheral_interface_gpio_unexport(handle->type.gpio.pin);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to gpio unexport");
+
+ ret = peripheral_handle_free(handle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to free gpio handle");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_handle_gpio_create(int pin, peripheral_h *handle, gpointer user_data)
{
+ RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_info_s *info = (peripheral_info_s*)user_data;
- peripheral_h gpio_handle;
- int ret;
- if (!__peripheral_handle_gpio_is_creatable(pin, info)) {
+ peripheral_h gpio_handle = NULL;
+ bool is_handle_creatable = false;
+
+ is_handle_creatable = __peripheral_handle_gpio_is_creatable(pin, info);
+ if (is_handle_creatable == false) {
_E("gpio %d is not available", pin);
return PERIPHERAL_ERROR_RESOURCE_BUSY;
}
- // TODO : make fd list using the interface function
-
gpio_handle = peripheral_handle_new(&info->gpio_list);
- if (!gpio_handle) {
+ if (gpio_handle == NULL) {
_E("peripheral_handle_new error");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err;
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
gpio_handle->list = &info->gpio_list;
gpio_handle->type.gpio.pin = pin;
+ gpio_handle->type.gpio.fd_direction = -1;
+ gpio_handle->type.gpio.fd_edge = -1;
+ gpio_handle->type.gpio.fd_value = -1;
+
+ ret = peripheral_interface_gpio_export(pin);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to gpio export");
+ goto out;
+ }
- *handle = gpio_handle;
-
- return PERIPHERAL_ERROR_NONE;
-
-err:
- return ret;
-}
+ ret = peripheral_interface_gpio_fd_direction_open(pin, &gpio_handle->type.gpio.fd_direction);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to gpio open direction fd");
+ goto out;
+ }
-int peripheral_handle_gpio_destroy(peripheral_h handle)
-{
- int ret = PERIPHERAL_ERROR_NONE;
+ ret = peripheral_interface_gpio_fd_edge_open(pin, &gpio_handle->type.gpio.fd_edge);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to gpio open edge fd");
+ goto out;
+ }
- if (peripheral_handle_free(handle) < 0) {
- _E("Failed to free gpio data");
- ret = PERIPHERAL_ERROR_UNKNOWN;
+ ret = peripheral_interface_gpio_fd_value_open(pin, &gpio_handle->type.gpio.fd_value);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to gpio open value fd");
+ goto out;
}
- return ret;;
-}
+ *handle = gpio_handle;
+ return PERIPHERAL_ERROR_NONE;
+
+out:
+ peripheral_handle_gpio_destroy(gpio_handle);
+ return ret;
+}
\ No newline at end of file
#include "peripheral_interface_i2c.h"
#include "peripheral_handle_common.h"
-#define INITIAL_BUFFER_SIZE 128
-#define MAX_BUFFER_SIZE 8192
-
static bool __peripheral_handle_i2c_is_creatable(int bus, int address, peripheral_info_s *info)
{
pb_board_dev_s *i2c = NULL;
return true;
}
+int peripheral_handle_i2c_destroy(peripheral_h handle)
+{
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ ret = peripheral_interface_i2c_fd_close(handle->type.i2c.fd);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to i2c close fd");
+
+ ret = peripheral_handle_free(handle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to free i2c handle");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
int peripheral_handle_i2c_create(int bus, int address, peripheral_h *handle, gpointer user_data)
{
+ RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
+ RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_info_s *info = (peripheral_info_s*)user_data;
- peripheral_h i2c_handle;
- int ret;
- if (!__peripheral_handle_i2c_is_creatable(bus, address, info)) {
+ peripheral_h i2c_handle = NULL;
+ bool is_handle_creatable = false;
+
+ is_handle_creatable = __peripheral_handle_i2c_is_creatable(bus, address, info);
+ if (is_handle_creatable == false) {
_E("bus : %d, address : 0x%x is not available", bus, address);
return PERIPHERAL_ERROR_RESOURCE_BUSY;
}
- // TODO : make fd list using the interface function
-
i2c_handle = peripheral_handle_new(&info->i2c_list);
- if (!i2c_handle) {
+ if (i2c_handle == NULL) {
_E("peripheral_handle_new error");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err;
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
i2c_handle->list = &info->i2c_list;
i2c_handle->type.i2c.bus = bus;
i2c_handle->type.i2c.address = address;
+ i2c_handle->type.i2c.fd = -1;
- *handle = i2c_handle;
+ ret = peripheral_interface_i2c_fd_open(bus, address, &i2c_handle->type.i2c.fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to i2c fd open");
+ goto out;
+ }
+ *handle = i2c_handle;
return PERIPHERAL_ERROR_NONE;
-err:
+out:
+ peripheral_handle_i2c_destroy(i2c_handle);
return ret;
-}
-
-int peripheral_handle_i2c_destroy(peripheral_h handle)
-{
- int ret = PERIPHERAL_ERROR_NONE;
-
- if (peripheral_handle_free(handle) < 0) {
- _E("Failed to free i2c data");
- ret = PERIPHERAL_ERROR_UNKNOWN;
- }
-
- return ret;
-}
+}
\ No newline at end of file
return true;
}
+int peripheral_handle_pwm_destroy(peripheral_h handle)
+{
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ ret = peripheral_interface_pwm_fd_period_close(handle->type.pwm.fd_period);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to pwm close period fd");
+
+ ret = peripheral_interface_pwm_fd_duty_cycle_close(handle->type.pwm.fd_duty_cycle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to pwm close duty cycle fd");
+
+ ret = peripheral_interface_pwm_fd_polarity_close(handle->type.pwm.fd_polarity);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to pwm close polarity fd");
+
+ ret = peripheral_interface_pwm_fd_enable_close(handle->type.pwm.fd_enable);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to pwm close enable fd");
+
+ ret = peripheral_interface_pwm_unexport(handle->type.pwm.chip, handle->type.pwm.pin);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to pwm unexport");
+
+ ret = peripheral_handle_free(handle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to free pwm handle");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
int peripheral_handle_pwm_create(int chip, int pin, peripheral_h *handle, gpointer user_data)
{
+ RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
+ RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_info_s *info = (peripheral_info_s*)user_data;
- peripheral_h pwm_handle;
- int ret;
- if (!__peripheral_handle_pwm_is_creatable(chip, pin, info)) {
+ peripheral_h pwm_handle = NULL;
+ bool is_handle_creatable = false;
+
+ is_handle_creatable = __peripheral_handle_pwm_is_creatable(chip, pin, info);
+ if (is_handle_creatable == false) {
_E("pwm %d.%d is not available", chip, pin);
return PERIPHERAL_ERROR_RESOURCE_BUSY;
}
- // TODO : make fd list using the interface function
-
pwm_handle = peripheral_handle_new(&info->pwm_list);
- if (!pwm_handle) {
+ if (pwm_handle == NULL) {
_E("peripheral_handle_new error");
ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err;
+ goto out;
}
pwm_handle->list = &info->pwm_list;
pwm_handle->type.pwm.chip = chip;
pwm_handle->type.pwm.pin = pin;
- *handle = pwm_handle;
+ pwm_handle->type.pwm.fd_period = -1;
+ pwm_handle->type.pwm.fd_duty_cycle = -1;
+ pwm_handle->type.pwm.fd_polarity = -1;
+ pwm_handle->type.pwm.fd_enable = -1;
+
+ ret = peripheral_interface_pwm_export(chip, pin);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to pwm export");
+ goto out;
+ }
- return PERIPHERAL_ERROR_NONE;
+ ret = peripheral_interface_pwm_fd_period_open(chip, pin, &pwm_handle->type.pwm.fd_period);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to pwm open period fd");
+ goto out;
+ }
-err:
- return ret;
-}
+ ret = peripheral_interface_pwm_fd_duty_cycle_open(chip, pin, &pwm_handle->type.pwm.fd_duty_cycle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to pwm open duty cycle fd");
+ goto out;
+ }
-int peripheral_handle_pwm_destroy(peripheral_h handle)
-{
- int ret = PERIPHERAL_ERROR_NONE;
+ ret = peripheral_interface_pwm_fd_polarity_open(chip, pin, &pwm_handle->type.pwm.fd_polarity);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to pwm open polarity fd");
+ goto out;
+ }
- if (peripheral_handle_free(handle) < 0) {
- _E("Failed to free i2c data");
- ret = PERIPHERAL_ERROR_UNKNOWN;
+ ret = peripheral_interface_pwm_fd_enable_open(chip, pin, &pwm_handle->type.pwm.fd_enable);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to pwm open enable fd");
+ goto out;
}
+ *handle = pwm_handle;
+ return PERIPHERAL_ERROR_NONE;
+
+out:
+ peripheral_handle_pwm_destroy(pwm_handle);
return ret;
-}
+}
\ No newline at end of file
return true;
}
+int peripheral_handle_spi_destroy(peripheral_h handle)
+{
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ ret = peripheral_interface_spi_fd_close(handle->type.spi.fd);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to spi close fd");
+
+ ret = peripheral_handle_free(handle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to free spi handle");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
int peripheral_handle_spi_create(int bus, int cs, peripheral_h *handle, gpointer user_data)
{
- peripheral_info_s *info = (peripheral_info_s*)user_data;
- peripheral_h spi_handle;
+ RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi bus");
+ RETVM_IF(cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi cs");
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
+
int ret = PERIPHERAL_ERROR_NONE;
- if (!__peripheral_handle_spi_is_creatable(bus, cs, info)) {
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+
+ peripheral_h spi_handle = NULL;
+ bool is_handle_creatable = false;
+
+ is_handle_creatable = __peripheral_handle_spi_is_creatable(bus, cs, info);
+ if (is_handle_creatable == false) {
_E("spi %d.%d is not available", bus, cs);
return PERIPHERAL_ERROR_RESOURCE_BUSY;
}
- // TODO : make fd list using the interface function
-
spi_handle = peripheral_handle_new(&info->spi_list);
- if (!spi_handle) {
+ if (spi_handle == NULL) {
_E("peripheral_handle_new error");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err_spi_data;
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
spi_handle->list = &info->spi_list;
spi_handle->type.spi.bus = bus;
spi_handle->type.spi.cs = cs;
+ spi_handle->type.spi.fd = -1;
- *handle = spi_handle;
+ ret = peripheral_interface_spi_fd_open(bus, cs, &spi_handle->type.spi.fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to spi fd open");
+ goto out;
+ }
+ *handle = spi_handle;
return PERIPHERAL_ERROR_NONE;
-err_spi_data:
- return ret;
-}
-
-int peripheral_handle_spi_destroy(peripheral_h handle)
-{
- int ret = PERIPHERAL_ERROR_NONE;
-
- if (peripheral_handle_free(handle) < 0) {
- _E("Failed to free spi data");
- ret = PERIPHERAL_ERROR_UNKNOWN;
- }
-
+out:
+ peripheral_handle_spi_destroy(spi_handle);
return ret;
}
\ No newline at end of file
#include "peripheral_interface_uart.h"
#include "peripheral_handle_common.h"
-#define INITIAL_BUFFER_SIZE 128
-#define MAX_BUFFER_SIZE 8192
-
static bool __peripheral_handle_uart_is_creatable(int port, peripheral_info_s *info)
{
pb_board_dev_s *uart = NULL;
return true;
}
-int peripheral_handle_uart_open(int port, peripheral_h *handle, gpointer user_data)
+int peripheral_handle_uart_destroy(peripheral_h handle)
{
- peripheral_info_s *info = (peripheral_info_s*)user_data;
- peripheral_h uart_handle;
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
+
int ret = PERIPHERAL_ERROR_NONE;
- if (!__peripheral_handle_uart_is_creatable(port, info)) {
+ ret = peripheral_interface_uart_fd_close(handle->type.uart.fd);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to uart close fd");
+
+ ret = peripheral_handle_free(handle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to free uart handle");
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_handle_uart_create(int port, peripheral_h *handle, gpointer user_data)
+{
+ RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart port");
+ RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
+
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+
+ peripheral_h uart_handle = NULL;
+ bool is_handle_creatable = false;
+
+ is_handle_creatable = __peripheral_handle_uart_is_creatable(port, info);
+ if (is_handle_creatable == false) {
_E("uart %d is not available", port);
return PERIPHERAL_ERROR_RESOURCE_BUSY;
}
- // TODO : make fd list using the interface function
-
uart_handle = peripheral_handle_new(&info->uart_list);
- if (!uart_handle) {
+ if (uart_handle == NULL) {
_E("peripheral_handle_new error");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto err;
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
uart_handle->list = &info->uart_list;
uart_handle->type.uart.port = port;
+ uart_handle->type.uart.fd = -1;
- *handle = uart_handle;
+ ret = peripheral_interface_uart_fd_open(port, &uart_handle->type.uart.fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to uart fd open");
+ goto out;
+ }
+ *handle = uart_handle;
return PERIPHERAL_ERROR_NONE;
-err:
- return ret;
-}
-
-int peripheral_handle_uart_destroy(peripheral_h handle)
-{
- int ret = PERIPHERAL_ERROR_NONE;
-
- if (peripheral_handle_free(handle) < 0) {
- _E("Failed to free uart data");
- ret = PERIPHERAL_ERROR_UNKNOWN;
- }
-
+out:
+ peripheral_handle_uart_destroy(uart_handle);
return ret;
}
\ No newline at end of file
return ret;
}
-int peripheral_interface_gpio_open(int pin)
+int peripheral_interface_gpio_export(int pin)
{
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_gpio_close(int pin)
+int peripheral_interface_gpio_unexport(int pin)
{
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_gpio_open_file_direction(int pin, int *fd_out)
+int peripheral_interface_gpio_fd_direction_open(int pin, int *fd_out)
{
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for gpio direction");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_gpio_open_file_edge(int pin, int *fd_out)
+int peripheral_interface_gpio_fd_direction_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio direction");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_gpio_fd_edge_open(int pin, int *fd_out)
{
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for gpio edge");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_gpio_open_file_value(int pin, int *fd_out)
+int peripheral_interface_gpio_fd_edge_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio edge");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_gpio_fd_value_open(int pin, int *fd_out)
{
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for gpio value");
return PERIPHERAL_ERROR_NONE;
}
+
+int peripheral_interface_gpio_fd_value_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio value");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
#define I2C_SLAVE 0x0703 /* Use this slave address */
-int peripheral_interface_i2c_open_file(int bus, int address, int *fd_out)
+int peripheral_interface_i2c_fd_open(int bus, int address, int *fd_out)
{
RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_i2c_close(int fd)
+int peripheral_interface_i2c_fd_close(int fd)
{
RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for i2c");
#include "peripheral_interface_pwm.h"
#include "peripheral_interface_common.h"
-int peripheral_interface_pwm_open(int chip, int pin)
+int peripheral_interface_pwm_export(int chip, int pin)
{
RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_close(int chip, int pin)
+int peripheral_interface_pwm_unexport(int chip, int pin)
{
RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_open_file_period(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_period_open(int chip, int pin, int *fd_out)
{
RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_open_file_duty_cycle(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_period_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm period");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_duty_cycle_open(int chip, int pin, int *fd_out)
{
RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_open_file_polarity(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_duty_cycle_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm duty cycle");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_polarity_open(int chip, int pin, int *fd_out)
{
RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_open_file_enable(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_polarity_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm polarity");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_enable_open(int chip, int pin, int *fd_out)
{
RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
*fd_out = fd;
+ return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_enable_close(int fd)
+{
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm enable");
+
+ int ret;
+
+ ret = close(fd);
+ IF_ERROR_RETURN(ret != 0);
+
return PERIPHERAL_ERROR_NONE;
}
\ No newline at end of file
#include "peripheral_interface_spi.h"
#include "peripheral_interface_common.h"
-int peripheral_interface_spi_open_file(int bus, int cs, int *fd_out)
+int peripheral_interface_spi_fd_open(int bus, int cs, int *fd_out)
{
RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi bus");
RETVM_IF(cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi cs");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_spi_close(int fd)
+int peripheral_interface_spi_fd_close(int fd)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for spi");
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for spi");
int ret;
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#endif
-int peripheral_interface_uart_open_file(int port, int *fd_out)
+int peripheral_interface_uart_fd_open(int port, int *fd_out)
{
RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart port");
RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for uart");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_uart_close(int fd)
+int peripheral_interface_uart_fd_close(int fd)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for uart");
+ RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for uart");
int ret;
ret = close(fd);
int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection)
{
+ RETVM_IF(!__cynara, -1, "Cynara does not initialized");
+
int ret;
int pid;
const char *sender;
ret = cynara_check(__cynara, client, session, user, PERIPHERAL_PRIVILEGE);
if (ret != 0) {
+ _E("Failed to check privilege");
g_free(session);
g_free(client);
g_free(user);