From 3ab40f8b2bb51572a4263ea0821fe27bd1dbc9e0 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 22:27:05 +0900 Subject: [PATCH 01/16] gdbus: add check error in gdbus functions when gdbus request to daemon for open/close, it can receive return value TRUE with ret that it is not PERIPEHRAL_ERROR_NONE. In the case of requesting open to daemon, getting fd from list is meaningless. In the case of requesting close to daemon, proxy deinit function must not be run. Change-Id: I6ca7b1c98a15ca17159123903cd9d8ebe57c353c Signed-off-by: Segwon --- src/gdbus/peripheral_gdbus_gpio.c | 16 +++++++++++----- src/gdbus/peripheral_gdbus_i2c.c | 19 ++++++++++++------- src/gdbus/peripheral_gdbus_pwm.c | 18 ++++++++++++------ src/gdbus/peripheral_gdbus_spi.c | 18 ++++++++++++------ src/gdbus/peripheral_gdbus_uart.c | 19 +++++++++++++------ 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index ca5badd..d03ceda 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -68,8 +68,8 @@ static void __gpio_proxy_deinit() int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) { + int ret; GError *error = NULL; - gint32 ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __gpio_proxy_init(); @@ -85,11 +85,15 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) &fd_list, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to gpio open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + gpio->fd_direction = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_DIRECTION, &error); if (gpio->fd_direction < 0) { _E("Failed to get fd for gpio direction : %s", error->message); @@ -118,8 +122,8 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) { _E("Can't try to gpio close because gpio proxy is NULL."); @@ -132,12 +136,14 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) &ret, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to gpio close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __gpio_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __gpio_proxy_deinit(); return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index b10b10f..5ee8906 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -66,8 +66,8 @@ static void __i2c_proxy_deinit() int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __i2c_proxy_init(); @@ -84,16 +84,19 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) &fd_list, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to i2c open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + i2c->fd = g_unix_fd_list_get(fd_list, I2C_FD_INDEX, &error); if (i2c->fd < 0) { _E("Failed to get fd for i2c : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; } g_object_unref(fd_list); @@ -103,8 +106,8 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (i2c_proxy == NULL) { _E("Can't try to i2c close because i2c proxy is NULL."); @@ -117,12 +120,14 @@ int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) &ret, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to i2c close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __i2c_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __i2c_proxy_deinit(); return ret; -} \ No newline at end of file +} diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 3279d15..eb26bf5 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -69,8 +69,8 @@ static void __pwm_proxy_deinit() int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __pwm_proxy_init(); @@ -87,11 +87,15 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) &fd_list, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to pwm open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + pwm->fd_period = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_PERIOD, &error); if (pwm->fd_period < 0) { _E("Failed to get fd for pwm period : %s", error->message); @@ -127,8 +131,8 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (pwm_proxy == NULL) { _E("Can't try to pwm close because pwm proxy is NULL."); @@ -141,12 +145,14 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) &ret, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to pwm close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __pwm_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __pwm_proxy_deinit(); return ret; -} \ No newline at end of file +} diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index 80e267a..d58edfe 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -66,8 +66,8 @@ static void __spi_proxy_deinit() int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __spi_proxy_init(); @@ -84,11 +84,15 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) &fd_list, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to spi open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + spi->fd = g_unix_fd_list_get(fd_list, SPI_FD_INDEX, &error); if (spi->fd < 0) { _E("Failed to get fd for spi : %s", error->message); @@ -103,8 +107,8 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) int peripheral_gdbus_spi_close(peripheral_spi_h spi) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (spi_proxy == NULL) { _E("Can't try to spi close because spi proxy is NULL."); @@ -117,12 +121,14 @@ int peripheral_gdbus_spi_close(peripheral_spi_h spi) &ret, NULL, &error) == FALSE) { - _E("%s", error->message); + _E("Failed to request daemon to spi close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __spi_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __spi_proxy_deinit(); return ret; -} \ No newline at end of file +} diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 99620b6..985f2b4 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -66,8 +66,8 @@ static void __uart_proxy_deinit() int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; GUnixFDList *fd_list = NULL; ret = __uart_proxy_init(); @@ -83,11 +83,15 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) &fd_list, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to uart open : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } + // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. + if (ret != PERIPHERAL_ERROR_NONE) + return ret; + uart->fd = g_unix_fd_list_get(fd_list, UART_FD_INDEX, &error); if (uart->fd < 0) { _E("Failed to get fd for uart : %s", error->message); @@ -102,25 +106,28 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) int peripheral_gdbus_uart_close(peripheral_uart_h uart) { + int ret; GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) { _E("Can't try to uart close because uart proxy is NULL."); return PERIPHERAL_ERROR_UNKNOWN; } + if (peripheral_io_gdbus_uart_call_close_sync( uart_proxy, uart->handle, &ret, NULL, &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); + _E("Failed to request daemon to uart close : %s", error->message); g_error_free(error); return PERIPHERAL_ERROR_UNKNOWN; } - __uart_proxy_deinit(); + // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. + if (ret == PERIPHERAL_ERROR_NONE) + __uart_proxy_deinit(); return ret; -} \ No newline at end of file +} -- 2.7.4 From 2f57c46d2d36e7de3cfbb4af31b6f1722b753d13 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 10:57:02 +0900 Subject: [PATCH 02/16] gdbus: change 'peripheral_gdbus.h' file name to 'peripheral_gdbus_common.h' - for match with interface Change-Id: Ib6f2ee970976462c4b52d9a028a8ac956d17b80a Signed-off-by: Segwon --- include/gdbus/{peripheral_gdbus.h => peripheral_gdbus_common.h} | 6 +++--- src/gdbus/peripheral_gdbus_gpio.c | 2 +- src/gdbus/peripheral_gdbus_i2c.c | 2 +- src/gdbus/peripheral_gdbus_pwm.c | 2 +- src/gdbus/peripheral_gdbus_spi.c | 2 +- src/gdbus/peripheral_gdbus_uart.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename include/gdbus/{peripheral_gdbus.h => peripheral_gdbus_common.h} (90%) diff --git a/include/gdbus/peripheral_gdbus.h b/include/gdbus/peripheral_gdbus_common.h similarity index 90% rename from include/gdbus/peripheral_gdbus.h rename to include/gdbus/peripheral_gdbus_common.h index ff726de..685efdb 100644 --- a/include/gdbus/peripheral_gdbus.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __PERIPHERAL_GDBUS_H__ -#define __PERIPHERAL_GDBUS_H__ +#ifndef __PERIPHERAL_GDBUS_COMMON_H__ +#define __PERIPHERAL_GDBUS_COMMON_H__ #include @@ -26,4 +26,4 @@ #define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi" #define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io" -#endif /* __PERIPHERAL_GDBUS_H__ */ +#endif /* __PERIPHERAL_GDBUS_COMMON_H__ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index d03ceda..f5e6b0b 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 5ee8906..767332b 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index eb26bf5..e9b501b 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index d58edfe..2d07cd3 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 985f2b4..32d7992 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -19,7 +19,7 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus.h" +#include "peripheral_gdbus_common.h" #include "peripheral_common.h" #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -- 2.7.4 From 26cf17a8048b905ce1ce236fe4cd5294b903df4f Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 11:03:38 +0900 Subject: [PATCH 03/16] including : move the '#include' duplicate written to common file Change-Id: I5926833c5cef4f5d82bcca78164289562b53c2ca Signed-off-by: Segwon --- CMakeLists.txt | 3 +++ include/gdbus/peripheral_gdbus_common.h | 9 +++++++++ include/gdbus/peripheral_gdbus_gpio.h | 2 ++ include/gdbus/peripheral_gdbus_i2c.h | 2 ++ include/gdbus/peripheral_gdbus_pwm.h | 2 ++ include/gdbus/peripheral_gdbus_spi.h | 3 +++ include/gdbus/peripheral_gdbus_uart.h | 3 +++ include/interface/peripheral_interface_common.h | 11 +++++++++++ include/interface/peripheral_interface_gpio.h | 2 +- include/interface/peripheral_interface_i2c.h | 4 +--- include/interface/peripheral_interface_pwm.h | 2 +- include/interface/peripheral_interface_spi.h | 2 +- include/interface/peripheral_interface_uart.h | 4 +--- src/gdbus/peripheral_gdbus_gpio.c | 10 +--------- src/gdbus/peripheral_gdbus_i2c.c | 10 +--------- src/gdbus/peripheral_gdbus_pwm.c | 10 +--------- src/gdbus/peripheral_gdbus_spi.c | 10 +--------- src/gdbus/peripheral_gdbus_uart.c | 10 +--------- src/interface/peripheral_interface_gpio.c | 11 ----------- src/interface/peripheral_interface_i2c.c | 9 --------- src/interface/peripheral_interface_pwm.c | 11 ----------- src/interface/peripheral_interface_spi.c | 9 --------- src/interface/peripheral_interface_uart.c | 11 ----------- 23 files changed, 45 insertions(+), 105 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b17fa7..7fd0979 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,9 @@ INCLUDE_DIRECTORIES(${INC_DIR}) INCLUDE_DIRECTORIES(${INC_DIR}/gdbus) INCLUDE_DIRECTORIES(${INC_DIR}/interface) +SET(SRC_DIR src) +INCLUDE_DIRECTORIES(${SRC_DIR}/gdbus) + INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) FOREACH(flag ${${fw_name}_CFLAGS}) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index 685efdb..9a8450e 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -13,10 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_GDBUS_COMMON_H__ #define __PERIPHERAL_GDBUS_COMMON_H__ #include +#include +#include +#include + +#include "peripheral_io.h" +#include "peripheral_internal.h" +#include "peripheral_common.h" +#include "peripheral_io_gdbus.h" #define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" #define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index 3fd5307..c63aeba 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -17,6 +17,8 @@ #ifndef __PERIPHERAL_GDBUS_GPIO_H__ #define __PERIPHERAL_GDBUS_GPIO_H__ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 0670442..e1b1722 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -17,6 +17,8 @@ #ifndef __PERIPHERAL_GDBUS_I2C_H__ #define __PERIPHERAL_GDBUS_I2C_H__ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index 148e938..70a4b02 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -17,6 +17,8 @@ #ifndef __PERIPHERAL_GDBUS_PWM_H__ #define __PERIPHERAL_GDBUS_PWM_H__ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index 8a6ac61..94b2242 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_GDBUS_SPI_H_ #define __PERIPHERAL_GDBUS_SPI_H_ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); int peripheral_gdbus_spi_close(peripheral_spi_h spi); diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index 175452c..bf7af68 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_GDBUS_UART_H_ #define __PERIPHERAL_GDBUS_UART_H_ +#include "peripheral_gdbus_common.h" + int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); int peripheral_gdbus_uart_close(peripheral_uart_h uart); diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 33a8d39..a69254e 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -17,6 +17,17 @@ #ifndef __PERIPHERAL_INTERFACE_COMMON_H__ #define __PERIPHERAL_INTERFACE_COMMON_H__ +#include +#include +#include +#include +#include +#include + +#include "peripheral_io.h" +#include "peripheral_internal.h" +#include "peripheral_common.h" + #define CHECK_ERROR(val) \ do { \ if (val < 0) { \ diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index cc68e92..ff3a794 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -17,7 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_GPIO_H__ #define __PERIPHERAL_INTERFACE_GPIO_H__ -#include "peripheral_io.h" +#include "peripheral_interface_common.h" #define SYSFS_GPIO_DIR "/sys/class/gpio" #define GPIO_BUFFER_MAX 64 diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 41326d6..6e3dc23 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -17,9 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_I2C_H__ #define __PERIPHERAL_INTERFACE_I2C_H__ -#include - -#include "peripheral_io.h" +#include "peripheral_interface_common.h" #define SYSFS_I2C_DIR "/dev/i2c" #define I2C_BUFFER_MAX 64 diff --git a/include/interface/peripheral_interface_pwm.h b/include/interface/peripheral_interface_pwm.h index 0867663..f37b40d 100644 --- a/include/interface/peripheral_interface_pwm.h +++ b/include/interface/peripheral_interface_pwm.h @@ -17,7 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_PWM_H__ #define __PERIPHERAL_INTERFACE_PWM_H__ -#include "peripheral_io.h" +#include "peripheral_interface_common.h" /** * @brief pwm_close() deinit pwm pin. diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h index d7a471d..801c324 100644 --- a/include/interface/peripheral_interface_spi.h +++ b/include/interface/peripheral_interface_spi.h @@ -17,7 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_SPI_H__ #define __PERIPHERAL_INTERFACE_SPI_H__ -#include "peripheral_io.h" +#include "peripheral_interface_common.h" int peripheral_interface_spi_close(peripheral_spi_h spi); int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h index 4648ae1..c4c82ec 100644 --- a/include/interface/peripheral_interface_uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -17,9 +17,7 @@ #ifndef __PERIPHERAL_INTERFACE_UART_H__ #define __PERIPHERAL_INTERFACE_UART_H__ -#include "peripheral_io.h" - -#include +#include "peripheral_interface_common.h" /** * @brief uart_close() closes uart port. diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index f5e6b0b..c8a6d8c 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_gpio.h" #define GPIO_FD_INDEX_DIRECTION 0 #define GPIO_FD_INDEX_EDGE 1 diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 767332b..29ba888 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_i2c.h" #define I2C_FD_INDEX 0 diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index e9b501b..48ff164 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_pwm.h" #define PWM_FD_INDEX_PERIOD 0 #define PWM_FD_INDEX_DUTY_CYCLE 1 diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index 2d07cd3..fce5a41 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_spi.h" #define SPI_FD_INDEX 0 diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 32d7992..852e244 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -14,15 +14,7 @@ * limitations under the License. */ -#include -#include -#include - -#include "peripheral_io.h" -#include "peripheral_gdbus_common.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" -#include "peripheral_io_gdbus.h" +#include "peripheral_gdbus_uart.h" #define UART_FD_INDEX 0 diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 7d4ef2f..950de19 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -14,18 +14,7 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include - -#include "peripheral_interface_common.h" #include "peripheral_interface_gpio.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define MAX_ERR_LEN 255 diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index fadbf63..87be206 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -14,18 +14,9 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include -#include "peripheral_interface_common.h" #include "peripheral_interface_i2c.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define MAX_ERR_LEN 255 diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index faefc1a..bbfeefb 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -14,18 +14,7 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include -#include - -#include "peripheral_interface_common.h" #include "peripheral_interface_pwm.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define SYSFS_PWM_PATH "/sys/class/pwm" diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index 1c83726..e8a0fc6 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -14,19 +14,10 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include #include -#include "peripheral_interface_common.h" #include "peripheral_interface_spi.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define SYSFS_SPI_DIR "/dev/spidev" #define SYSFS_SPI_BUFSIZ "/sys/module/spidev/parameters/bufsiz" diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index a0f9637..4944bb9 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -14,20 +14,9 @@ * limitations under the License. */ -#include -#include -#include -#include -#include -#include #include -#include -#include -#include "peripheral_interface_common.h" #include "peripheral_interface_uart.h" -#include "peripheral_common.h" -#include "peripheral_internal.h" #define PATH_BUF_MAX 64 #define UART_BUF_MAX 16 -- 2.7.4 From ca21b2731e07b6de6423a591a3c33afba2210f7f Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 11:59:38 +0900 Subject: [PATCH 04/16] handle: change file name 'peripheral_internal.h' to 'peripheral_handle.h' - the word 'internal' does not mean defining a handle structure. Change-Id: Ica3650be46eb2285aaa543b1aadd3ae0a0f822cf Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_common.h | 2 +- include/interface/peripheral_interface_common.h | 2 +- include/{peripheral_internal.h => peripheral_handle.h} | 6 +++--- src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) rename include/{peripheral_internal.h => peripheral_handle.h} (92%) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index 9a8450e..ed8c397 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -23,7 +23,7 @@ #include #include "peripheral_io.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #include "peripheral_common.h" #include "peripheral_io_gdbus.h" diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index a69254e..f0bd657 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -25,7 +25,7 @@ #include #include "peripheral_io.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #include "peripheral_common.h" #define CHECK_ERROR(val) \ diff --git a/include/peripheral_internal.h b/include/peripheral_handle.h similarity index 92% rename from include/peripheral_internal.h rename to include/peripheral_handle.h index 5c62dee..be8a066 100644 --- a/include/peripheral_internal.h +++ b/include/peripheral_handle.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PERIPHERAL_INTERNAL_H__ -#define __PERIPHERAL_INTERNAL_H__ +#ifndef __PERIPHERAL_HANDLE_H__ +#define __PERIPHERAL_HANDLE_H__ /** * @brief Internal struct for gpio context @@ -63,4 +63,4 @@ struct _peripheral_spi_s { int fd; }; -#endif /* __PERIPHERAL_INTERNAL_H__ */ +#endif /* __PERIPHERAL_HANDLE_H__ */ diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 6a03a5a..06806ec 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -24,7 +24,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index d729356..89c1674 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_i2c.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c" diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index e21bcbb..c671ff4 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_pwm.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm" diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 68e9761..0a9e95e 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -24,7 +24,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_spi.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi" diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index ad58c0c..0d67c98 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_gdbus_uart.h" #include "peripheral_common.h" -#include "peripheral_internal.h" +#include "peripheral_handle.h" #define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart" -- 2.7.4 From 53da683cf99b7be5ba4e8bec3d060f6593a59cbe Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 15:52:34 +0900 Subject: [PATCH 05/16] including: remove unnecessary header files Change-Id: Ice8e09e5654bbc2e94d5c41b5e1d5d86e5b78239 Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_common.h | 1 - include/interface/peripheral_interface_common.h | 3 --- include/peripheral_common.h | 2 +- src/peripheral_gpio.c | 4 ---- src/peripheral_i2c.c | 3 --- src/peripheral_pwm.c | 3 --- src/peripheral_spi.c | 4 ---- src/peripheral_uart.c | 3 --- 8 files changed, 1 insertion(+), 22 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index ed8c397..6885a61 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -17,7 +17,6 @@ #ifndef __PERIPHERAL_GDBUS_COMMON_H__ #define __PERIPHERAL_GDBUS_COMMON_H__ -#include #include #include #include diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index f0bd657..8cb2ed8 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -19,9 +19,6 @@ #include #include -#include -#include -#include #include #include "peripheral_io.h" diff --git a/include/peripheral_common.h b/include/peripheral_common.h index 19352be..c5702d3 100644 --- a/include/peripheral_common.h +++ b/include/peripheral_common.h @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef __PERIPHERAL_COMMON_H__ #define __PERIPHERAL_COMMON_H__ -#include #include #undef LOG_TAG diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 06806ec..5992d16 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -14,12 +14,8 @@ * limitations under the License. */ -#include #include -#include -#include #include -#include #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 89c1674..c61374b 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -14,10 +14,7 @@ * limitations under the License. */ -#include #include -#include -#include #include #include "peripheral_io.h" diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index c671ff4..74f807a 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -14,10 +14,7 @@ * limitations under the License. */ -#include #include -#include -#include #include #include "peripheral_io.h" diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 0a9e95e..61d3b79 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -14,11 +14,7 @@ * limitations under the License. */ -#include "peripheral_io.h" - -#include #include -#include #include #include "peripheral_io.h" diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 0d67c98..d63c100 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -14,10 +14,7 @@ * limitations under the License. */ -#include #include -#include -#include #include #include "peripheral_io.h" -- 2.7.4 From 2db5b00566952b5d6fe2cfa42ef386248d5327ff Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:24:33 +0900 Subject: [PATCH 06/16] log: change file name "peripheral_common.h" to "peripheral_log.h" Change-Id: I96c150951c7cb2c5517b305e00909b0bca5cacff Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_common.h | 2 +- include/interface/peripheral_interface_common.h | 2 +- include/{peripheral_common.h => peripheral_log.h} | 0 src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename include/{peripheral_common.h => peripheral_log.h} (100%) diff --git a/include/gdbus/peripheral_gdbus_common.h b/include/gdbus/peripheral_gdbus_common.h index 6885a61..62b0717 100644 --- a/include/gdbus/peripheral_gdbus_common.h +++ b/include/gdbus/peripheral_gdbus_common.h @@ -23,8 +23,8 @@ #include "peripheral_io.h" #include "peripheral_handle.h" -#include "peripheral_common.h" #include "peripheral_io_gdbus.h" +#include "peripheral_log.h" #define PERIPHERAL_GDBUS_INTERFACE "org.tizen.peripheral_io" #define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 8cb2ed8..2646cc6 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -23,7 +23,7 @@ #include "peripheral_io.h" #include "peripheral_handle.h" -#include "peripheral_common.h" +#include "peripheral_log.h" #define CHECK_ERROR(val) \ do { \ diff --git a/include/peripheral_common.h b/include/peripheral_log.h similarity index 100% rename from include/peripheral_common.h rename to include/peripheral_log.h diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 5992d16..040d862 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index c61374b..e89e401 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_i2c.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c" diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 74f807a..fb1ed14 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_pwm.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm" diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 61d3b79..13c2b05 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_spi.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi" diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index d63c100..d7d3577 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -19,8 +19,8 @@ #include "peripheral_io.h" #include "peripheral_gdbus_uart.h" -#include "peripheral_common.h" #include "peripheral_handle.h" +#include "peripheral_log.h" #define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart" -- 2.7.4 From d934f33cca753b515853713c844369ca5e8e6e22 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:40:18 +0900 Subject: [PATCH 07/16] interface: do not check if fd is negative - it is checked by the caller. - the check is meaningless even if handle is not opened. Change-Id: Id22083b04f4e95a0788a32f1cbc2929c08dd8c31 Signed-off-by: Segwon --- src/interface/peripheral_interface_i2c.c | 25 ++-------- src/interface/peripheral_interface_spi.c | 41 ++-------------- src/interface/peripheral_interface_uart.c | 81 ++----------------------------- 3 files changed, 12 insertions(+), 135 deletions(-) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 87be206..d0a9985 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -22,12 +22,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) { - int status; - - _D("fd : %d", i2c->fd); - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); - - status = close(i2c->fd); + int status = close(i2c->fd); CHECK_ERROR(status); return 0; @@ -35,11 +30,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = read(i2c->fd, data, length); + int status = read(i2c->fd, data, length); CHECK_ERROR(status); return 0; @@ -47,11 +38,7 @@ int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = write(i2c->fd, data, length); + int status = write(i2c->fd, data, length); CHECK_ERROR(status); return 0; @@ -59,11 +46,7 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = ioctl(i2c->fd, I2C_SMBUS, data); + int status = ioctl(i2c->fd, I2C_SMBUS, data); CHECK_ERROR(status); return 0; diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index e8a0fc6..bf68c50 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -26,12 +26,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) { - int status; - - _D("fd : %d", spi->fd); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = close(spi->fd); + int status = close(spi->fd); CHECK_ERROR(status); return 0; @@ -39,12 +34,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - int status; - - _D("fd : %d, mode : %d", spi->fd, mode); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); + int status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); CHECK_ERROR(status); return 0; @@ -52,12 +42,7 @@ int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - int status; - - _D("fd : %d, lsb : %d", spi->fd, bit_order); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + int status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); CHECK_ERROR(status); return 0; @@ -65,12 +50,7 @@ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - int status; - - _D("fd : %d, bits : %d", spi->fd, bits); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); + int status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); CHECK_ERROR(status); return 0; @@ -78,12 +58,7 @@ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bit int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) { - int status; - - _D("fd : %d, freq : %d", spi->fd, freq); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); + int status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); CHECK_ERROR(status); return 0; @@ -94,8 +69,6 @@ int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.rx_buf = (unsigned long)rxbuf; xfer.len = length; @@ -111,8 +84,6 @@ int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_ int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.tx_buf = (unsigned long)txbuf; xfer.len = length; @@ -128,8 +99,6 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - if (!txbuf || !rxbuf) return -EINVAL; memset(&xfer, 0, sizeof(xfer)); diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 4944bb9..36131a1 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -47,13 +47,6 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) { int status; - _D("file_hndl : %d", uart->fd); - - if (uart->fd < 0) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - status = peripheral_interface_uart_flush(uart); CHECK_ERROR(status); @@ -65,14 +58,7 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) int peripheral_interface_uart_flush(peripheral_uart_h uart) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = tcflush(uart->fd, TCIOFLUSH); + int ret = tcflush(uart->fd, TCIOFLUSH); CHECK_ERROR(ret); return 0; @@ -83,19 +69,6 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, baud : %d", uart->fd, baud); - - memset(&tio, 0, sizeof(tio)); - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (baud > PERIPHERAL_UART_BAUD_RATE_230400) { - _E("Invalid parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -118,22 +91,9 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, bytesize : %d", uart->fd, byte_size); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT) { - _E("Invalid bytesize parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); - /* set byte size */ tio.c_cflag &= ~CSIZE; tio.c_cflag |= byteinfo[byte_size]; @@ -151,13 +111,6 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart int ret; struct termios tio; - _D("file_hndl : %d, parity : %d", uart->fd, parity); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -190,13 +143,6 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, stopbits : %d", uart->fd, stop_bits); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -225,13 +171,6 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int ret; struct termios tio; - _D("file_hndl : %d, xonxoff : %d, rtscts : %d", uart->fd, xonxoff, rtscts); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -257,14 +196,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = read(uart->fd, (void *)buf, length); + int ret = read(uart->fd, (void *)buf, length); CHECK_ERROR(ret); return ret; @@ -272,14 +204,7 @@ int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_ int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = write(uart->fd, buf, length); + int ret = write(uart->fd, buf, length); CHECK_ERROR(ret); return ret; -- 2.7.4 From 8ea72de00628c59ded9892af841c6395df28d16e Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:55:08 +0900 Subject: [PATCH 08/16] i2c: replace 'i2c_smbus_ioctl()' with another functions. - do not use 'i2c_smbus_ioctl_data' structure in caller. - remove : i2c_smbus_ioctl() - add : peripheral_interface_i2c_read_register_byte() - add : peripheral_interface_i2c_write_register_byte() - add : peripheral_interface_i2c_read_register_word() - add : peripheral_interface_i2c_write_register_word() Change-Id: Ia73f3febcf1412a5101a83b2106a0d7c695a2ce4 Signed-off-by: Segwon --- include/interface/peripheral_interface_i2c.h | 7 ++- src/interface/peripheral_interface_i2c.c | 84 +++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 6e3dc23..b10fc1a 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -58,6 +58,9 @@ struct i2c_smbus_ioctl_data { int peripheral_interface_i2c_close(peripheral_i2c_h i2c); int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length); int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length); -int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data); +int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out); +int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in); +int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out); +int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in); -#endif/* __PERIPHERAL_INTERFACE_I2C_H__ */ +#endif /* __PERIPHERAL_INTERFACE_I2C_H__ */ diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index d0a9985..3fcb083 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -44,10 +44,90 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t return 0; } -int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) +int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out) { - int status = ioctl(i2c->fd, I2C_SMBUS, data); + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_READ; + data_arg.size = I2C_SMBUS_BYTE_DATA; + data_arg.data = &data; + data_arg.command = reg; + + status = ioctl(fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); + *data_out = data.byte; + return 0; } + +int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in) +{ + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_WRITE; + data_arg.size = I2C_SMBUS_BYTE_DATA; + data_arg.data = &data; + data_arg.command = reg; + + data.byte = data_in; + + status = ioctl(fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(status); + + return 0; +} + +int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out) +{ + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_READ; + data_arg.size = I2C_SMBUS_WORD_DATA; + data_arg.data = &data; + data_arg.command = reg; + + status = ioctl(fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(status); + + *data_out = data.word; + + return 0; +} + +int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in) +{ + int status; + + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data data; + + memset(&data, 0x0, sizeof(data.block)); + + data_arg.read_write = I2C_SMBUS_WRITE; + data_arg.size = I2C_SMBUS_WORD_DATA; + data_arg.data = &data; + data_arg.command = reg; + + data.word = data_in; + + statis = ioctl(fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(status); + + return 0; +} \ No newline at end of file -- 2.7.4 From dd481b5bdd30ddea722900ac75b922bcf19219f9 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 13:10:10 +0900 Subject: [PATCH 09/16] spi: fix a build error due to missed before patch Signed-off-by: Segwon Change-Id: I34d0b37fab426cae2cc0210ca7a9a7b8101a5598 --- src/interface/peripheral_interface_i2c.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 3fcb083..0963682 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -58,7 +58,7 @@ int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t re data_arg.data = &data; data_arg.command = reg; - status = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); *data_out = data.byte; @@ -82,7 +82,7 @@ int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t r data.byte = data_in; - status = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); return 0; @@ -102,7 +102,7 @@ int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t re data_arg.data = &data; data_arg.command = reg; - status = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); *data_out = data.word; @@ -126,7 +126,7 @@ int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t r data.word = data_in; - statis = ioctl(fd, I2C_SMBUS, &data_arg); + status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(status); return 0; -- 2.7.4 From 8e3667aa19274b9dc41d3499da4203ee4e186d58 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 13:15:27 +0900 Subject: [PATCH 10/16] interface: remove +1 length when writing a char array Signed-off-by: Segwon Change-Id: I7bbbe2f8698ee1fb90268af6f6ca8c0eaf8edb38 --- src/interface/peripheral_interface_gpio.c | 18 +++++++++--------- src/interface/peripheral_interface_pwm.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 950de19..b8361fb 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -23,11 +23,11 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g int status; if (direction == PERIPHERAL_GPIO_DIRECTION_IN) - status = write(gpio->fd_direction, "in", strlen("in")+1); + status = write(gpio->fd_direction, "in", strlen("in")); else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH) - status = write(gpio->fd_direction, "high", strlen("high")+1); + status = write(gpio->fd_direction, "high", strlen("high")); else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW) - status = write(gpio->fd_direction, "low", strlen("low")+1); + status = write(gpio->fd_direction, "low", strlen("low")); else { _E("Error: gpio direction is wrong\n"); return -EIO; @@ -43,13 +43,13 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g int status; if (edge == PERIPHERAL_GPIO_EDGE_NONE) - status = write(gpio->fd_edge, "none", strlen("none")+1); + status = write(gpio->fd_edge, "none", strlen("none")); else if (edge == PERIPHERAL_GPIO_EDGE_RISING) - status = write(gpio->fd_edge, "rising", strlen("rising")+1); + status = write(gpio->fd_edge, "rising", strlen("rising")); else if (edge == PERIPHERAL_GPIO_EDGE_FALLING) - status = write(gpio->fd_edge, "falling", strlen("falling")+1); + status = write(gpio->fd_edge, "falling", strlen("falling")); else if (edge == PERIPHERAL_GPIO_EDGE_BOTH) - status = write(gpio->fd_edge, "both", strlen("both")+1); + status = write(gpio->fd_edge, "both", strlen("both")); else { _E("Error: gpio edge is wrong\n"); return -EIO; @@ -65,9 +65,9 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) int status; if (value == 1) - status = write(gpio->fd_value, "1", strlen("1")+1); + status = write(gpio->fd_value, "1", strlen("1")); else if (value == 0) - status = write(gpio->fd_value, "0", strlen("0")+1); + status = write(gpio->fd_value, "0", strlen("0")); else { _E("Error: gpio write value error \n"); return -EIO; diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index bbfeefb..d01776d 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -70,9 +70,9 @@ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_p int status; if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) - status = write(pwm->fd_polarity, "normal", strlen("normal")+1); + status = write(pwm->fd_polarity, "normal", strlen("normal")); else if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_LOW) - status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1); + status = write(pwm->fd_polarity, "inversed", strlen("inversed")); else { _E("Invalid pwm polarity : %d", polarity); return -EINVAL; -- 2.7.4 From 79d3c28b1bab7a183d3cf9326a2c66ef3a243bf6 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 14:03:25 +0900 Subject: [PATCH 11/16] interface: do not close request to daemon by gdbus. - daemon will be detect gdbus disconnection by g_bus_watch_name() Signed-off-by: Segwon Change-Id: Id9882a8b576b9110eb21aa66a94b3fa7e9c4b14c --- include/gdbus/peripheral_gdbus_gpio.h | 2 +- include/gdbus/peripheral_gdbus_i2c.h | 2 +- include/gdbus/peripheral_gdbus_pwm.h | 2 +- include/gdbus/peripheral_gdbus_spi.h | 2 +- include/gdbus/peripheral_gdbus_uart.h | 2 +- src/gdbus/peripheral_gdbus_gpio.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_i2c.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_pwm.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_spi.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_uart.c | 41 ++++++++++------------------------- src/gdbus/peripheral_io.xml | 20 ----------------- src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 16 files changed, 70 insertions(+), 175 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index c63aeba..1ffe214 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); +int peripheral_gdbus_gpio_close(); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index e1b1722..9d9f9a5 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); -int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); +int peripheral_gdbus_i2c_close(); #endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index 70a4b02..c0764c6 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); -int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); +int peripheral_gdbus_pwm_close(); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index 94b2242..6f4aaa3 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); -int peripheral_gdbus_spi_close(peripheral_spi_h spi); +int peripheral_gdbus_spi_close(); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index bf7af68..048eed5 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); -int peripheral_gdbus_uart_close(peripheral_uart_h uart); +int peripheral_gdbus_uart_close(); #endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index c8a6d8c..c935a4c 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -49,13 +49,18 @@ static int __gpio_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __gpio_proxy_deinit() +static int __gpio_proxy_deinit() { - if (gpio_proxy != NULL) { - g_object_unref(gpio_proxy); - if (!G_IS_OBJECT(gpio_proxy)) - gpio_proxy = NULL; + if (gpio_proxy == NULL) { + _E("Gpio proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(gpio_proxy); + if (!G_IS_OBJECT(gpio_proxy)) + gpio_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) @@ -112,30 +117,8 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) return ret; } -int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) +int peripheral_gdbus_gpio_close() { - int ret; - GError *error = NULL; - - if (gpio_proxy == NULL) { - _E("Can't try to gpio close because gpio proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_gpio_call_close_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to gpio close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __gpio_proxy_deinit(); - + int ret = __gpio_proxy_deinit(); return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 29ba888..cc5f300 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -47,13 +47,18 @@ static int __i2c_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __i2c_proxy_deinit() +static int __i2c_proxy_deinit() { - if (i2c_proxy) { - g_object_unref(i2c_proxy); - if (!G_IS_OBJECT(i2c_proxy)) - i2c_proxy = NULL; + if (i2c_proxy == NULL) { + _E("I2c proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(i2c_proxy); + if (!G_IS_OBJECT(i2c_proxy)) + i2c_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) @@ -96,30 +101,8 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) return ret; } -int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) +int peripheral_gdbus_i2c_close() { - int ret; - GError *error = NULL; - - if (i2c_proxy == NULL) { - _E("Can't try to i2c close because i2c proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_i2c_call_close_sync( - i2c_proxy, - i2c->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to i2c close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __i2c_proxy_deinit(); - + int ret = __i2c_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 48ff164..4c1d916 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -50,13 +50,18 @@ static int __pwm_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __pwm_proxy_deinit() +static int __pwm_proxy_deinit() { - if (pwm_proxy) { - g_object_unref(pwm_proxy); - if (!G_IS_OBJECT(pwm_proxy)) - pwm_proxy = NULL; + if (pwm_proxy == NULL) { + _E("Pwm proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(pwm_proxy); + if (!G_IS_OBJECT(pwm_proxy)) + pwm_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) @@ -121,30 +126,8 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) return ret; } -int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) +int peripheral_gdbus_pwm_close() { - int ret; - GError *error = NULL; - - if (pwm_proxy == NULL) { - _E("Can't try to pwm close because pwm proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_pwm_call_close_sync( - pwm_proxy, - pwm->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to pwm close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __pwm_proxy_deinit(); - + int ret = __pwm_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index fce5a41..b0653e4 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -47,13 +47,18 @@ static int __spi_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __spi_proxy_deinit() +static int __spi_proxy_deinit() { - if (spi_proxy) { - g_object_unref(spi_proxy); - if (!G_IS_OBJECT(spi_proxy)) - spi_proxy = NULL; + if (spi_proxy == NULL) { + _E("Spi proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(spi_proxy); + if (!G_IS_OBJECT(spi_proxy)) + spi_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) @@ -97,30 +102,8 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) return ret; } -int peripheral_gdbus_spi_close(peripheral_spi_h spi) +int peripheral_gdbus_spi_close() { - int ret; - GError *error = NULL; - - if (spi_proxy == NULL) { - _E("Can't try to spi close because spi proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_spi_call_close_sync( - spi_proxy, - spi->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to spi close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __spi_proxy_deinit(); - + int ret = __spi_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 852e244..a15e566 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -47,13 +47,18 @@ static int __uart_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __uart_proxy_deinit() +static int __uart_proxy_deinit() { - if (uart_proxy) { - g_object_unref(uart_proxy); - if (!G_IS_OBJECT(uart_proxy)) - uart_proxy = NULL; + if (uart_proxy == NULL) { + _E("Uart proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(uart_proxy); + if (!G_IS_OBJECT(uart_proxy)) + uart_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) @@ -96,30 +101,8 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) return ret; } -int peripheral_gdbus_uart_close(peripheral_uart_h uart) +int peripheral_gdbus_uart_close() { - int ret; - GError *error = NULL; - - if (uart_proxy == NULL) { - _E("Can't try to uart close because uart proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_uart_call_close_sync( - uart_proxy, - uart->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to uart close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __uart_proxy_deinit(); - + int ret = __uart_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 00c49e7..6b987a3 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -7,10 +7,6 @@ - - - - @@ -20,10 +16,6 @@ - - - - @@ -33,10 +25,6 @@ - - - - @@ -45,10 +33,6 @@ - - - - @@ -58,9 +42,5 @@ - - - - diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 040d862..1333122 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -90,7 +90,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); /* call gpio_close */ - ret = peripheral_gdbus_gpio_close(gpio); + ret = peripheral_gdbus_gpio_close(); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close the gpio pin, ret : %d", ret); diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index e89e401..44d6052 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -90,7 +90,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_close(i2c); + ret = peripheral_gdbus_i2c_close(); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close i2c communcation, ret : %d", ret); diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index fb1ed14..12e6fc2 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -82,7 +82,7 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0) + if ((ret = peripheral_gdbus_pwm_close()) < 0) _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); free(pwm); diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 13c2b05..9b25a2e 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -81,7 +81,7 @@ int peripheral_spi_close(peripheral_spi_h spi) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_close(spi); + ret = peripheral_gdbus_spi_close(); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to close SPI device, continuing anyway, ret : %d", ret); diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index d7d3577..b18ccff 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -86,7 +86,7 @@ int peripheral_uart_close(peripheral_uart_h uart) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - ret = peripheral_gdbus_uart_close(uart); + ret = peripheral_gdbus_uart_close(); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to close uart communication, continuing anyway, ret : %d", ret); -- 2.7.4 From 94726db5e096420f623c5b49f0291b655133ceff Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 14:19:19 +0900 Subject: [PATCH 12/16] coding style: cannot put parameter in function defined to have no parameter. - function() -> function(void) Signed-off-by: Segwon Change-Id: I896916b02f45bdb84ed8120b3fb7273677ace9e1 --- include/gdbus/peripheral_gdbus_gpio.h | 2 +- include/gdbus/peripheral_gdbus_i2c.h | 2 +- include/gdbus/peripheral_gdbus_pwm.h | 2 +- include/gdbus/peripheral_gdbus_spi.h | 2 +- include/gdbus/peripheral_gdbus_uart.h | 2 +- src/gdbus/peripheral_gdbus_gpio.c | 6 +++--- src/gdbus/peripheral_gdbus_i2c.c | 6 +++--- src/gdbus/peripheral_gdbus_pwm.c | 6 +++--- src/gdbus/peripheral_gdbus_spi.c | 6 +++--- src/gdbus/peripheral_gdbus_uart.c | 6 +++--- src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index 1ffe214..9402a0b 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_close(); +int peripheral_gdbus_gpio_close(void); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 9d9f9a5..099da4e 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); -int peripheral_gdbus_i2c_close(); +int peripheral_gdbus_i2c_close(void); #endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index c0764c6..e5c26c8 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); -int peripheral_gdbus_pwm_close(); +int peripheral_gdbus_pwm_close(void); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index 6f4aaa3..a828c10 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); -int peripheral_gdbus_spi_close(); +int peripheral_gdbus_spi_close(void); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index 048eed5..fc58ee8 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); -int peripheral_gdbus_uart_close(); +int peripheral_gdbus_uart_close(void); #endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index c935a4c..2f2ead6 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -22,7 +22,7 @@ static PeripheralIoGdbusGpio *gpio_proxy = NULL; -static int __gpio_proxy_init() +static int __gpio_proxy_init(void) { GError *error = NULL; @@ -49,7 +49,7 @@ static int __gpio_proxy_init() return PERIPHERAL_ERROR_NONE; } -static int __gpio_proxy_deinit() +static int __gpio_proxy_deinit(void) { if (gpio_proxy == NULL) { _E("Gpio proxy is NULL"); @@ -117,7 +117,7 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) return ret; } -int peripheral_gdbus_gpio_close() +int peripheral_gdbus_gpio_close(void) { int ret = __gpio_proxy_deinit(); return ret; diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index cc5f300..0300fb8 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -20,7 +20,7 @@ static PeripheralIoGdbusI2c *i2c_proxy = NULL; -static int __i2c_proxy_init() +static int __i2c_proxy_init(void) { GError *error = NULL; @@ -47,7 +47,7 @@ static int __i2c_proxy_init() return PERIPHERAL_ERROR_NONE; } -static int __i2c_proxy_deinit() +static int __i2c_proxy_deinit(void) { if (i2c_proxy == NULL) { _E("I2c proxy is NULL"); @@ -101,7 +101,7 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) return ret; } -int peripheral_gdbus_i2c_close() +int peripheral_gdbus_i2c_close(void) { int ret = __i2c_proxy_deinit(); return ret; diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 4c1d916..1274744 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -23,7 +23,7 @@ static PeripheralIoGdbusPwm *pwm_proxy = NULL; -static int __pwm_proxy_init() +static int __pwm_proxy_init(void) { GError *error = NULL; @@ -50,7 +50,7 @@ static int __pwm_proxy_init() return PERIPHERAL_ERROR_NONE; } -static int __pwm_proxy_deinit() +static int __pwm_proxy_deinit(void) { if (pwm_proxy == NULL) { _E("Pwm proxy is NULL"); @@ -126,7 +126,7 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) return ret; } -int peripheral_gdbus_pwm_close() +int peripheral_gdbus_pwm_close(void) { int ret = __pwm_proxy_deinit(); return ret; diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index b0653e4..9cdb0e8 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -20,7 +20,7 @@ static PeripheralIoGdbusSpi *spi_proxy = NULL; -static int __spi_proxy_init() +static int __spi_proxy_init(void) { GError *error = NULL; @@ -47,7 +47,7 @@ static int __spi_proxy_init() return PERIPHERAL_ERROR_NONE; } -static int __spi_proxy_deinit() +static int __spi_proxy_deinit(void) { if (spi_proxy == NULL) { _E("Spi proxy is NULL"); @@ -102,7 +102,7 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) return ret; } -int peripheral_gdbus_spi_close() +int peripheral_gdbus_spi_close(void) { int ret = __spi_proxy_deinit(); return ret; diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index a15e566..539ccf6 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -20,7 +20,7 @@ static PeripheralIoGdbusUart *uart_proxy = NULL; -static int __uart_proxy_init() +static int __uart_proxy_init(void) { GError *error = NULL; @@ -47,7 +47,7 @@ static int __uart_proxy_init() return PERIPHERAL_ERROR_NONE; } -static int __uart_proxy_deinit() +static int __uart_proxy_deinit(void) { if (uart_proxy == NULL) { _E("Uart proxy is NULL"); @@ -101,7 +101,7 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) return ret; } -int peripheral_gdbus_uart_close() +int peripheral_gdbus_uart_close(void) { int ret = __uart_proxy_deinit(); return ret; diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 1333122..b6ea462 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -30,7 +30,7 @@ static int gpio_feature = GPIO_FEATURE_UNKNOWN; -static bool __is_feature_supported() +static bool __is_feature_supported(void) { int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 44d6052..f3a8c5a 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -40,7 +40,7 @@ static int i2c_feature = I2C_FEATURE_UNKNOWN; -static bool __is_feature_supported() +static bool __is_feature_supported(void) { int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 12e6fc2..f418ac5 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -30,7 +30,7 @@ static int pwm_feature = PWM_FEATURE_UNKNOWN; -static bool __is_feature_supported() +static bool __is_feature_supported(void) { int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 9b25a2e..862e4d9 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -30,7 +30,7 @@ static int spi_feature = SPI_FEATURE_UNKNOWN; -static bool __is_feature_supported() +static bool __is_feature_supported(void) { int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index b18ccff..988dd38 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -30,7 +30,7 @@ static int uart_feature = UART_FEATURE_UNKNOWN; -static bool __is_feature_supported() +static bool __is_feature_supported(void) { int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; -- 2.7.4 From 8478cc9a51a95ae8eeb09d80017ed20d5743f423 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 14:25:24 +0900 Subject: [PATCH 13/16] packaging: expose only peripheral_io.h(API) at devel rpm Signed-off-by: Segwon Change-Id: I39f1e6a90bd774a73a2508a43b8dffc8869d86a3 --- CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fd0979..68a4f6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,11 +76,7 @@ SET_TARGET_PROPERTIES(${fw_name} ) INSTALL(TARGETS ${fw_name} DESTINATION ${libdir}) -INSTALL( - DIRECTORY ${INC_DIR}/ DESTINATION include - FILES_MATCHING - PATTERN "${INC_DIR}/*.h" - ) +INSTALL(FILES ${INC_DIR}/peripheral_io.h DESTINATION include) SET(PC_NAME ${fw_name}) SET(PC_REQUIRED ${pc_dependents}) -- 2.7.4 From 1637e1997425d6586219ae43920156018dc8fbe5 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 15:09:39 +0900 Subject: [PATCH 14/16] interface: do not use the 'strlen' and 'strncmp' Signed-off-by: Segwon Change-Id: I5113aff8d544f2e5411dbb3d158313c5e4dece2f --- include/interface/peripheral_interface_common.h | 5 ++ src/interface/peripheral_interface_gpio.c | 65 +++++++++---------------- src/interface/peripheral_interface_pwm.c | 24 ++++----- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 2646cc6..8c10519 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -37,4 +37,9 @@ } \ } while (0) +typedef struct predefined_type { + char *type; + int len; +} predefined_type_s; + #endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/ \ No newline at end of file diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index b8361fb..683b853 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -20,19 +20,13 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { - int status; - - if (direction == PERIPHERAL_GPIO_DIRECTION_IN) - status = write(gpio->fd_direction, "in", strlen("in")); - else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH) - status = write(gpio->fd_direction, "high", strlen("high")); - else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW) - status = write(gpio->fd_direction, "low", strlen("low")); - else { - _E("Error: gpio direction is wrong\n"); - return -EIO; - } + static predefined_type_s types[3] = { + {"in", 2}, + {"high", 4}, + {"low", 3} + }; + int status = write(gpio->fd_direction, types[direction].type, types[direction].len); CHECK_ERROR(status); return 0; @@ -40,21 +34,14 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { - int status; - - if (edge == PERIPHERAL_GPIO_EDGE_NONE) - status = write(gpio->fd_edge, "none", strlen("none")); - else if (edge == PERIPHERAL_GPIO_EDGE_RISING) - status = write(gpio->fd_edge, "rising", strlen("rising")); - else if (edge == PERIPHERAL_GPIO_EDGE_FALLING) - status = write(gpio->fd_edge, "falling", strlen("falling")); - else if (edge == PERIPHERAL_GPIO_EDGE_BOTH) - status = write(gpio->fd_edge, "both", strlen("both")); - else { - _E("Error: gpio edge is wrong\n"); - return -EIO; - } - + static predefined_type_s types[4] = { + {"none", 4}, + {"rising", 6}, + {"falling", 7}, + {"both", 4} + }; + + int status = write(gpio->fd_edge, types[edge].type, types[edge].len); CHECK_ERROR(status); return 0; @@ -62,17 +49,12 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) { - int status; - - if (value == 1) - status = write(gpio->fd_value, "1", strlen("1")); - else if (value == 0) - status = write(gpio->fd_value, "0", strlen("0")); - else { - _E("Error: gpio write value error \n"); - return -EIO; - } + static predefined_type_s types[2] = { + {"0", 1}, + {"1", 1} + }; + int status = write(gpio->fd_value, types[value].type, types[value].len); CHECK_ERROR(status); return 0; @@ -86,14 +68,13 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) len = read(gpio->fd_value, &gpio_buf, 1); CHECK_ERROR(len); - if (0 == strncmp(gpio_buf, "1", strlen("1"))) - *value = 1; - else if (0 == strncmp(gpio_buf, "0", strlen("0"))) + if (gpio_buf[0] == '0') *value = 0; - else { + else if (gpio_buf[0] == '1') + *value = 1; + else _E("Error: gpio value is error \n"); return -EIO; - } return 0; } diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index d01776d..1da7752 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -67,17 +67,12 @@ int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { - int status; - - if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) - status = write(pwm->fd_polarity, "normal", strlen("normal")); - else if (polarity == PERIPHERAL_PWM_POLARITY_ACTIVE_LOW) - status = write(pwm->fd_polarity, "inversed", strlen("inversed")); - else { - _E("Invalid pwm polarity : %d", polarity); - return -EINVAL; - } + static predefined_type_s types[2] = { + {"normal", 6}, + {"inversed", 8} + }; + int status = write(pwm->fd_polarity, types[polarity].type, types[polarity].len); CHECK_ERROR(status); return 0; @@ -85,11 +80,12 @@ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_p int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable) { - int len, status; - char pwm_buf[PWM_BUF_MAX] = {0}; + static predefined_type_s types[2] = { + {"0", 1}, + {"1", 1} + }; - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable); - status = write(pwm->fd_enable, pwm_buf, len); + int status = write(pwm->fd_enable, types[enable].type, types[enable].len); CHECK_ERROR(status); return 0; -- 2.7.4 From 379c7e10e00f3539b71d511ca7de5655b9c05b9c Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 16:15:19 +0900 Subject: [PATCH 15/16] interface: fix the CHECK_ERROR macro to receive various conditions Signed-off-by: Segwon Change-Id: Iac30913f44ba239365a37e0dd9050623ea3f8d91 --- include/interface/peripheral_interface_common.h | 4 +-- src/interface/peripheral_interface_gpio.c | 33 ++++++++++--------- src/interface/peripheral_interface_i2c.c | 36 ++++++++++---------- src/interface/peripheral_interface_pwm.c | 44 +++++++++++++------------ src/interface/peripheral_interface_spi.c | 38 ++++++++++----------- src/interface/peripheral_interface_uart.c | 35 ++++++++++---------- 6 files changed, 96 insertions(+), 94 deletions(-) diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 8c10519..792594a 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -25,9 +25,9 @@ #include "peripheral_handle.h" #include "peripheral_log.h" -#define CHECK_ERROR(val) \ +#define CHECK_ERROR(expr) \ do { \ - if (val < 0) { \ + if (expr) { \ if (errno == EAGAIN) \ return -EAGAIN; \ char errmsg[255]; \ diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 683b853..f0bf6f2 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -26,8 +26,8 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g {"low", 3} }; - int status = write(gpio->fd_direction, types[direction].type, types[direction].len); - CHECK_ERROR(status); + int ret = write(gpio->fd_direction, types[direction].type, types[direction].len); + CHECK_ERROR(ret != types[direction].len); return 0; } @@ -41,8 +41,8 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g {"both", 4} }; - int status = write(gpio->fd_edge, types[edge].type, types[edge].len); - CHECK_ERROR(status); + int ret = write(gpio->fd_edge, types[edge].type, types[edge].len); + CHECK_ERROR(ret != types[edge].len); return 0; } @@ -54,19 +54,20 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) {"1", 1} }; - int status = write(gpio->fd_value, types[value].type, types[value].len); - CHECK_ERROR(status); + int ret = write(gpio->fd_value, types[value].type, types[value].len); + CHECK_ERROR(ret != types[value].len); return 0; } int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) { - int len; + int ret; + int length = 1; char gpio_buf[GPIO_BUFFER_MAX] = {0, }; - len = read(gpio->fd_value, &gpio_buf, 1); - CHECK_ERROR(len); + ret = read(gpio->fd_value, &gpio_buf, length); + CHECK_ERROR(ret != length); if (gpio_buf[0] == '0') *value = 0; @@ -81,16 +82,16 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) int peripheral_interface_gpio_close(peripheral_gpio_h gpio) { - int status; + int ret; - status = close(gpio->fd_direction); - CHECK_ERROR(status); + ret = close(gpio->fd_direction); + CHECK_ERROR(ret != 0); - status = close(gpio->fd_edge); - CHECK_ERROR(status); + ret = close(gpio->fd_edge); + CHECK_ERROR(ret != 0); - status = close(gpio->fd_value); - CHECK_ERROR(status); + ret = close(gpio->fd_value); + CHECK_ERROR(ret != 0); return 0; } diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 0963682..131bbf9 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -22,31 +22,31 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) { - int status = close(i2c->fd); - CHECK_ERROR(status); + int ret = close(i2c->fd); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status = read(i2c->fd, data, length); - CHECK_ERROR(status); + int ret = read(i2c->fd, data, length); + CHECK_ERROR(ret != length); return 0; } int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status = write(i2c->fd, data, length); - CHECK_ERROR(status); + int ret = write(i2c->fd, data, length); + CHECK_ERROR(ret != length); return 0; } int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out) { - int status; + int ret; struct i2c_smbus_ioctl_data data_arg; union i2c_smbus_data data; @@ -58,8 +58,8 @@ int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t re data_arg.data = &data; data_arg.command = reg; - status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); - CHECK_ERROR(status); + ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(ret != 0); *data_out = data.byte; @@ -68,7 +68,7 @@ int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t re int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in) { - int status; + int ret; struct i2c_smbus_ioctl_data data_arg; union i2c_smbus_data data; @@ -82,15 +82,15 @@ int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t r data.byte = data_in; - status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); - CHECK_ERROR(status); + ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out) { - int status; + int ret; struct i2c_smbus_ioctl_data data_arg; union i2c_smbus_data data; @@ -102,8 +102,8 @@ int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t re data_arg.data = &data; data_arg.command = reg; - status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); - CHECK_ERROR(status); + ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(ret != 0); *data_out = data.word; @@ -112,7 +112,7 @@ int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t re int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in) { - int status; + int ret; struct i2c_smbus_ioctl_data data_arg; union i2c_smbus_data data; @@ -126,8 +126,8 @@ int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t r data.word = data_in; - status = ioctl(i2c->fd, I2C_SMBUS, &data_arg); - CHECK_ERROR(status); + ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(ret != 0); return 0; } \ No newline at end of file diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index 1da7752..752db6f 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -24,43 +24,45 @@ int peripheral_interface_pwm_close(peripheral_pwm_h pwm) { - int status; + int ret; - status = close(pwm->fd_period); - CHECK_ERROR(status); + ret = close(pwm->fd_period); + CHECK_ERROR(ret != 0); - status = close(pwm->fd_duty_cycle); - CHECK_ERROR(status); + ret = close(pwm->fd_duty_cycle); + CHECK_ERROR(ret != 0); - status = close(pwm->fd_polarity); - CHECK_ERROR(status); + ret = close(pwm->fd_polarity); + CHECK_ERROR(ret != 0); - status = close(pwm->fd_enable); - CHECK_ERROR(status); + ret = close(pwm->fd_enable); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, uint32_t period) { - int len, status; + int ret; + int length; char pwm_buf[PWM_BUF_MAX] = {0}; - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period); - status = write(pwm->fd_period, pwm_buf, len); - CHECK_ERROR(status); + length = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period); + ret = write(pwm->fd_period, pwm_buf, length); + CHECK_ERROR(ret != length); return 0; } int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle) { - int len, status; + int ret; + int length; char pwm_buf[PWM_BUF_MAX] = {0}; - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle); - status = write(pwm->fd_duty_cycle, pwm_buf, len); - CHECK_ERROR(status); + length = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle); + ret = write(pwm->fd_duty_cycle, pwm_buf, length); + CHECK_ERROR(ret != length); return 0; } @@ -72,8 +74,8 @@ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_p {"inversed", 8} }; - int status = write(pwm->fd_polarity, types[polarity].type, types[polarity].len); - CHECK_ERROR(status); + int ret = write(pwm->fd_polarity, types[polarity].type, types[polarity].len); + CHECK_ERROR(ret != types[polarity].len); return 0; } @@ -85,8 +87,8 @@ int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable) {"1", 1} }; - int status = write(pwm->fd_enable, types[enable].type, types[enable].len); - CHECK_ERROR(status); + int ret = write(pwm->fd_enable, types[enable].type, types[enable].len); + CHECK_ERROR(ret != types[enable].len); return 0; } diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index bf68c50..6928307 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -26,77 +26,77 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) { - int status = close(spi->fd); - CHECK_ERROR(status); + int ret = close(spi->fd); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - int status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); - CHECK_ERROR(status); + int ret = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - int status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); - CHECK_ERROR(status); + int ret = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - int status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); - CHECK_ERROR(status); + int ret = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) { - int status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); - CHECK_ERROR(status); + int ret = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t length) { - int status; + int ret; struct spi_ioc_transfer xfer; memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.rx_buf = (unsigned long)rxbuf; xfer.len = length; - status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - CHECK_ERROR(status); + ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_t length) { - int status; + int ret; struct spi_ioc_transfer xfer; memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.tx_buf = (unsigned long)txbuf; xfer.len = length; - status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - CHECK_ERROR(status); + ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); + CHECK_ERROR(ret != 0); return 0; } int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint8_t *rxbuf, uint32_t length) { - int status; + int ret; struct spi_ioc_transfer xfer; if (!txbuf || !rxbuf) return -EINVAL; @@ -106,8 +106,8 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint xfer.rx_buf = (unsigned long)rxbuf; xfer.len = length; - status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - CHECK_ERROR(status); + ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); + CHECK_ERROR(ret != 0); return 0; } diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 36131a1..1c10027 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -45,13 +45,12 @@ static const int byteinfo[4] = {CS5, CS6, CS7, CS8}; int peripheral_interface_uart_close(peripheral_uart_h uart) { - int status; + int ret; - status = peripheral_interface_uart_flush(uart); - CHECK_ERROR(status); + peripheral_interface_uart_flush(uart); - status = close(uart->fd); - CHECK_ERROR(status); + ret = close(uart->fd); + CHECK_ERROR(ret != 0); return 0; } @@ -59,7 +58,7 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) int peripheral_interface_uart_flush(peripheral_uart_h uart) { int ret = tcflush(uart->fd, TCIOFLUSH); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); return 0; } @@ -70,7 +69,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u struct termios tio; ret = tcgetattr(uart->fd, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); tio.c_cflag = peripheral_uart_br[baud]; tio.c_iflag = IGNPAR; @@ -81,7 +80,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); return 0; } @@ -92,7 +91,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u struct termios tio; ret = tcgetattr(uart->fd, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); /* set byte size */ tio.c_cflag &= ~CSIZE; @@ -101,7 +100,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); return 0; } @@ -112,7 +111,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart struct termios tio; ret = tcgetattr(uart->fd, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); /* set parity info */ switch (parity) { @@ -133,7 +132,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); return 0; } @@ -144,7 +143,7 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u struct termios tio; ret = tcgetattr(uart->fd, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); /* set stop bit */ switch (stop_bits) { @@ -161,7 +160,7 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); return 0; } @@ -172,7 +171,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera struct termios tio; ret = tcgetattr(uart->fd, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); if (rtscts == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) tio.c_cflag |= CRTSCTS; @@ -189,7 +188,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera return -EINVAL; ret = tcsetattr(uart->fd, TCSANOW, &tio); - CHECK_ERROR(ret); + CHECK_ERROR(ret != 0); return 0; } @@ -197,7 +196,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { int ret = read(uart->fd, (void *)buf, length); - CHECK_ERROR(ret); + CHECK_ERROR(ret != length); return ret; } @@ -205,7 +204,7 @@ int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_ int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { int ret = write(uart->fd, buf, length); - CHECK_ERROR(ret); + CHECK_ERROR(ret != length); return ret; } -- 2.7.4 From a058314196d23b4e7d65521873d7f16fe0ddfffe Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 16:46:26 +0900 Subject: [PATCH 16/16] interface: remove unused constants defined from #define Signed-off-by: Segwon Change-Id: Ie8f111ae53ea28e2c013e9e96a829d4d249a87ad --- include/interface/peripheral_interface_common.h | 4 +++- include/interface/peripheral_interface_gpio.h | 1 - include/interface/peripheral_interface_i2c.h | 1 - include/interface/peripheral_interface_pwm.h | 2 ++ src/interface/peripheral_interface_gpio.c | 2 -- src/interface/peripheral_interface_i2c.c | 2 -- src/interface/peripheral_interface_pwm.c | 6 ------ src/interface/peripheral_interface_spi.c | 5 ----- src/interface/peripheral_interface_uart.c | 14 -------------- 9 files changed, 5 insertions(+), 32 deletions(-) diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index 792594a..b7047e4 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -25,12 +25,14 @@ #include "peripheral_handle.h" #include "peripheral_log.h" +#define MAX_ERR_LEN 255 + #define CHECK_ERROR(expr) \ do { \ if (expr) { \ if (errno == EAGAIN) \ return -EAGAIN; \ - char errmsg[255]; \ + char errmsg[MAX_ERR_LEN]; \ strerror_r(errno, errmsg, sizeof(errmsg)); \ _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \ return -EIO; \ diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index ff3a794..e5276e5 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -19,7 +19,6 @@ #include "peripheral_interface_common.h" -#define SYSFS_GPIO_DIR "/sys/class/gpio" #define GPIO_BUFFER_MAX 64 int peripheral_interface_gpio_close(peripheral_gpio_h gpio); diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index b10fc1a..5d5eb45 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -19,7 +19,6 @@ #include "peripheral_interface_common.h" -#define SYSFS_I2C_DIR "/dev/i2c" #define I2C_BUFFER_MAX 64 #define I2C_SLAVE 0x0703 /* Use this slave address */ diff --git a/include/interface/peripheral_interface_pwm.h b/include/interface/peripheral_interface_pwm.h index f37b40d..f8875bf 100644 --- a/include/interface/peripheral_interface_pwm.h +++ b/include/interface/peripheral_interface_pwm.h @@ -19,6 +19,8 @@ #include "peripheral_interface_common.h" +#define PWM_BUF_MAX 16 + /** * @brief pwm_close() deinit pwm pin. * diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index f0bf6f2..3084350 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -16,8 +16,6 @@ #include "peripheral_interface_gpio.h" -#define MAX_ERR_LEN 255 - int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { static predefined_type_s types[3] = { diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 131bbf9..ef4c944 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -18,8 +18,6 @@ #include "peripheral_interface_i2c.h" -#define MAX_ERR_LEN 255 - int peripheral_interface_i2c_close(peripheral_i2c_h i2c) { int ret = close(i2c->fd); diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index 752db6f..a56a701 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -16,12 +16,6 @@ #include "peripheral_interface_pwm.h" -#define SYSFS_PWM_PATH "/sys/class/pwm" - -#define PATH_BUF_MAX 64 -#define PWM_BUF_MAX 16 -#define MAX_ERR_LEN 255 - int peripheral_interface_pwm_close(peripheral_pwm_h pwm) { int ret; diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index 6928307..b3b8fc1 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -19,11 +19,6 @@ #include "peripheral_interface_spi.h" -#define SYSFS_SPI_DIR "/dev/spidev" -#define SYSFS_SPI_BUFSIZ "/sys/module/spidev/parameters/bufsiz" -#define SPI_BUFFER_MAX 64 -#define MAX_ERR_LEN 255 - int peripheral_interface_spi_close(peripheral_spi_h spi) { int ret = close(spi->fd); diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 1c10027..ca37ec4 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -18,22 +18,8 @@ #include "peripheral_interface_uart.h" -#define PATH_BUF_MAX 64 -#define UART_BUF_MAX 16 - #define UART_BAUDRATE_SIZE 19 -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) -#endif -#define MAX_ERR_LEN 128 - -char *sysfs_uart_path[] = { - "/dev/ttyS", - "/dev/ttyAMA", - "/dev/ttySAC", -}; - static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = { B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, -- 2.7.4