From a2ada4a71a7e1a328016b393e5c6f363421468f9 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 23:35:59 +0900 Subject: [PATCH 01/16] uart: flush the uart buffer when setting the flow control Change-Id: Ie1c2609a243242ded2ecc1e4411ca07231a784b9 Signed-off-by: Segwon --- include/interface/peripheral_interface_uart.h | 3 +-- src/interface/peripheral_interface_uart.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h index fb44638..75748ce 100644 --- a/include/interface/peripheral_interface_uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -31,9 +31,8 @@ void peripheral_interface_uart_close(peripheral_uart_h uart); * @brief uart_flush() flushes uart buffer. * * @param[in] file_hndl handle of uart_context -* @return On success, 0 is returned. On failure, a negative value is returned. */ -int peripheral_interface_uart_flush(peripheral_uart_h uart); +void peripheral_interface_uart_flush(peripheral_uart_h uart); /** * @brief uart_set_baudrate() sets uart baud rate. diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index eadef4a..45e0690 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -35,12 +35,9 @@ void peripheral_interface_uart_close(peripheral_uart_h uart) close(uart->fd); } -int peripheral_interface_uart_flush(peripheral_uart_h uart) +void peripheral_interface_uart_flush(peripheral_uart_h uart) { - int ret = tcflush(uart->fd, TCIOFLUSH); - CHECK_ERROR(ret != 0); - - return PERIPHERAL_ERROR_NONE; + tcflush(uart->fd, TCIOFLUSH); } int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) @@ -59,6 +56,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u tio.c_cc[VTIME] = 0; peripheral_interface_uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); @@ -79,6 +77,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u tio.c_cflag |= (CLOCAL | CREAD); peripheral_interface_uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); @@ -111,6 +110,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 != 0); @@ -139,6 +139,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 != 0); @@ -167,6 +168,8 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera else return PERIPHERAL_ERROR_INVALID_PARAMETER; + peripheral_interface_uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); -- 2.7.4 From 7ebfdd07f7b499051d979465e862d15af36d877f Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 4 Dec 2017 15:56:09 +0900 Subject: [PATCH 02/16] test: fix to wrong number of i2c bus Change-Id: Ifcd09204d585070d303eff86e73738772fbf2ab2 Signed-off-by: Segwon --- test/src/test_peripheral_i2c.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/src/test_peripheral_i2c.c b/test/src/test_peripheral_i2c.c index bb1de7f..58f1ae0 100644 --- a/test/src/test_peripheral_i2c.c +++ b/test/src/test_peripheral_i2c.c @@ -19,7 +19,8 @@ #include #include "test_peripheral_i2c.h" -#define I2C_BUS 4 +#define I2C_BUS_RPI3 4 +#define I2C_BUS_ARTIK530 11 #define I2C_BUS_INVALID -99 #define I2C_ADDRESS 0x39 #define I2C_ADDRESS_INVALID -99 @@ -35,8 +36,10 @@ int test_peripheral_io_i2c_initialize(char *model, bool feature) { g_feature = feature; - if ((!strcmp(model, "rpi3")) || (!strcmp(model, "artik"))) - bus = I2C_BUS; + if (!strcmp(model, "rpi3")) + bus = I2C_BUS_RPI3; + else if (!strcmp(model, "artik")) + bus = I2C_BUS_ARTIK530; else return PERIPHERAL_ERROR_NO_DEVICE; -- 2.7.4 From 2fbe04726be903fc76e2d4ff68ccf47200058be5 Mon Sep 17 00:00:00 2001 From: Segwon Date: Fri, 8 Dec 2017 14:57:20 +0900 Subject: [PATCH 03/16] gdbus: communicate via gdbus when close Change-Id: Ieae106a611e8409c50996b68c08fcdbd3506d70b Signed-off-by: Segwon --- 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 | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_i2c.c | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_pwm.c | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_spi.c | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_uart.c | 26 ++++++++++++++++++++------ 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, 130 insertions(+), 40 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index edef2ea..7ccc4a3 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 pin); -int peripheral_gdbus_gpio_close(void); +int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 099da4e..e1b1722 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(void); +int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); #endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index e5c26c8..70a4b02 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(void); +int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index a828c10..94b2242 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(void); +int peripheral_gdbus_spi_close(peripheral_spi_h spi); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index fc58ee8..bf7af68 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(void); +int peripheral_gdbus_uart_close(peripheral_uart_h uart); #endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 5400429..dcc9ff2 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -51,10 +51,7 @@ static int __gpio_proxy_init(void) static int __gpio_proxy_deinit(void) { - if (gpio_proxy == NULL) { - _E("Gpio proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(gpio_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Gpio proxy is NULL"); g_object_unref(gpio_proxy); if (!G_IS_OBJECT(gpio_proxy)) @@ -117,8 +114,25 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio, int pin) return ret; } -int peripheral_gdbus_gpio_close(void) +int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) { - int ret = __gpio_proxy_deinit(); + RETVM_IF(gpio_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Gpio proxy is NULL"); + + int ret; + GError *error = NULL; + + 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_IO_ERROR; + } + + __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 e85f21b..c2fb06f 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -49,10 +49,7 @@ static int __i2c_proxy_init(void) static int __i2c_proxy_deinit(void) { - if (i2c_proxy == NULL) { - _E("I2c proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(i2c_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "I2c proxy is NULL"); g_object_unref(i2c_proxy); if (!G_IS_OBJECT(i2c_proxy)) @@ -102,8 +99,25 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) return ret; } -int peripheral_gdbus_i2c_close(void) +int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) { - int ret = __i2c_proxy_deinit(); + RETVM_IF(i2c_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "I2c proxy is NULL"); + + int ret; + GError *error = NULL; + + 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_IO_ERROR; + } + + __i2c_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 4b76866..71a7344 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -52,10 +52,7 @@ static int __pwm_proxy_init(void) static int __pwm_proxy_deinit(void) { - if (pwm_proxy == NULL) { - _E("Pwm proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(pwm_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Pwm proxy is NULL"); g_object_unref(pwm_proxy); if (!G_IS_OBJECT(pwm_proxy)) @@ -126,8 +123,25 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) return ret; } -int peripheral_gdbus_pwm_close(void) +int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) { - int ret = __pwm_proxy_deinit(); + RETVM_IF(pwm_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Pwm proxy is NULL"); + + int ret; + GError *error = NULL; + + if (peripheral_io_gdbus_pwm_call_close_sync( + pwm_proxy, + pwm->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Failed to request daemon to gpio pwm : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_IO_ERROR; + } + + __pwm_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index d518d85..2861d52 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -49,10 +49,7 @@ static int __spi_proxy_init(void) static int __spi_proxy_deinit(void) { - if (spi_proxy == NULL) { - _E("Spi proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(spi_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Spi proxy is NULL"); g_object_unref(spi_proxy); if (!G_IS_OBJECT(spi_proxy)) @@ -102,8 +99,25 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) return ret; } -int peripheral_gdbus_spi_close(void) +int peripheral_gdbus_spi_close(peripheral_spi_h spi) { - int ret = __spi_proxy_deinit(); + RETVM_IF(spi_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Spi proxy is NULL"); + + int ret; + GError *error = NULL; + + if (peripheral_io_gdbus_spi_call_close_sync( + spi_proxy, + spi->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Failed to request daemon to gpio spi : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_IO_ERROR; + } + + __spi_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 671f7da..3376dff 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -49,10 +49,7 @@ static int __uart_proxy_init(void) static int __uart_proxy_deinit(void) { - if (uart_proxy == NULL) { - _E("Uart proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(uart_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Uart proxy is NULL"); g_object_unref(uart_proxy); if (!G_IS_OBJECT(uart_proxy)) @@ -101,8 +98,25 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) return ret; } -int peripheral_gdbus_uart_close(void) +int peripheral_gdbus_uart_close(peripheral_uart_h uart) { - int ret = __uart_proxy_deinit(); + RETVM_IF(uart_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Uart proxy is NULL"); + + int ret; + GError *error = NULL; + + if (peripheral_io_gdbus_uart_call_close_sync( + uart_proxy, + uart->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Failed to request daemon to gpio uart : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_IO_ERROR; + } + + __uart_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 6b987a3..00c49e7 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -7,6 +7,10 @@ + + + + @@ -16,6 +20,10 @@ + + + + @@ -25,6 +33,10 @@ + + + + @@ -33,6 +45,10 @@ + + + + @@ -42,5 +58,9 @@ + + + + diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 229c831..4d0579b 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -88,7 +88,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(); + ret = peripheral_gdbus_gpio_close(gpio); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close the gpio pin, ret : %d", ret); return ret; diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 3d9b908..c36d72f 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(); + ret = peripheral_gdbus_i2c_close(i2c); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close i2c communcation, ret : %d", ret); return ret; diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 51ad72b..ee0e829 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"); - ret = peripheral_gdbus_pwm_close(); + ret = peripheral_gdbus_pwm_close(pwm); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); return ret; diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 0014893..10faddb 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(); + ret = peripheral_gdbus_spi_close(spi); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close SPI device, continuing anyway, ret : %d", ret); return ret; diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index e66856c..2b48f85 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(); + ret = peripheral_gdbus_uart_close(uart); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close uart communication, continuing anyway, ret : %d", ret); return ret; -- 2.7.4 From f2b38db50344ce5a9c240b352435614f676bc6b1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 14 Dec 2017 20:05:12 +0900 Subject: [PATCH 04/16] gpio: set initially edge_mode and direction in handle Change-Id: Ie9c50a3d680562c9f573ee006b816a3960096c46 Signed-off-by: Segwon --- include/interface/peripheral_interface_gpio.h | 5 +++ include/peripheral_handle.h | 2 + src/interface/peripheral_interface_gpio.c | 53 +++++++++++++++++++++++++++ src/peripheral_gpio.c | 16 +++++++- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index 140edea..d4ca75d 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -22,8 +22,13 @@ #define GPIO_BUFFER_MAX 64 void peripheral_interface_gpio_close(peripheral_gpio_h gpio); + +int peripheral_interface_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpio); int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); + +int peripheral_interface_gpio_set_initial_direction_into_handle(peripheral_gpio_h gpio); int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); + int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value); int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value); diff --git a/include/peripheral_handle.h b/include/peripheral_handle.h index 0fc1b25..b834d06 100644 --- a/include/peripheral_handle.h +++ b/include/peripheral_handle.h @@ -25,6 +25,8 @@ struct _peripheral_gpio_s { int fd_direction; int fd_edge; int fd_value; + peripheral_gpio_direction_e direction; + peripheral_gpio_edge_e edge; }; /** diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 00b911b..4ca79e4 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -16,6 +16,30 @@ #include "peripheral_interface_gpio.h" +int peripheral_interface_gpio_set_initial_direction_into_handle(peripheral_gpio_h gpio) +{ + static predefined_type_s types[2] = { + {"in", 2}, + {"out", 3}, + }; + + int index; + char gpio_buf[GPIO_BUFFER_MAX] = {0, }; + + int ret = read(gpio->fd_direction, &gpio_buf, GPIO_BUFFER_MAX); + CHECK_ERROR(ret <= 0); + + for (index = 0; index < 2; index++) { + if (!strncmp(gpio_buf, types[index].type, types[index].len)) { + // PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH and PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW : out type + gpio->direction = (peripheral_gpio_direction_e)index; + return PERIPHERAL_ERROR_NONE; + } + } + + return PERIPHERAL_ERROR_IO_ERROR; +} + int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { static predefined_type_s types[3] = { @@ -27,9 +51,36 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g int ret = write(gpio->fd_direction, types[direction].type, types[direction].len); CHECK_ERROR(ret != types[direction].len); + gpio->direction = direction; + return PERIPHERAL_ERROR_NONE; } +int peripheral_interface_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpio) +{ + static predefined_type_s types[4] = { + {"none", 4}, + {"rising", 6}, + {"falling", 7}, + {"both", 4} + }; + + int index; + char gpio_buf[GPIO_BUFFER_MAX] = {0, }; + + int ret = read(gpio->fd_edge, &gpio_buf, GPIO_BUFFER_MAX); + CHECK_ERROR(ret <= 0); + + for (index = 0; index < 4; index++) { + if (!strncmp(gpio_buf, types[index].type, types[index].len)) { + gpio->edge = (peripheral_gpio_edge_e)index; + return PERIPHERAL_ERROR_NONE; + } + } + + return PERIPHERAL_ERROR_IO_ERROR; +} + int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { static predefined_type_s types[4] = { @@ -42,6 +93,8 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g int ret = write(gpio->fd_edge, types[edge].type, types[edge].len); CHECK_ERROR(ret != types[edge].len); + gpio->edge = edge; + return PERIPHERAL_ERROR_NONE; } diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 4d0579b..4cd0290 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -71,9 +71,23 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) handle = NULL; } + ret = peripheral_interface_gpio_set_initial_direction_into_handle(handle); + if (ret != PERIPHERAL_ERROR_NONE) { + _E("Failed to peripheral_interface_gpio_set_initial_direction_into_handle()"); + peripheral_gpio_close(handle); + return ret; + } + + ret = peripheral_interface_gpio_set_initial_edge_into_handle(handle); + if (ret != PERIPHERAL_ERROR_NONE) { + _E("Failed to peripheral_interface_gpio_set_initial_edge_into_handle()"); + peripheral_gpio_close(handle); + return ret; + } + *gpio = handle; - return ret; + return PERIPHERAL_ERROR_NONE; } /** -- 2.7.4 From 4e217917479bccac3d79b1312c249cbf72ae9593 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 14 Dec 2017 20:13:04 +0900 Subject: [PATCH 05/16] gpio: enhance exception handling in interface function - GPIO set type functions require prerequisites 1) [edge_mode] [direction] none ----------------------> in, out (O) rising, falling, both -----> in (O) \ ---> out (X) 2) [direction] [edge_mode] in ------------------------> none, rising, falling, both (O) out -----------------------> none (O) \ ----------------> rising, falling, both (X) 3) [direction] [value] in ------------------------> read (O) \ ----------------> write (X) out -----------------------> read, write (O) Change-Id: I72f8557568916b01c1e2e9edef79ed79f5bb20e6 Signed-off-by: Segwon --- src/interface/peripheral_interface_gpio.c | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 4ca79e4..119230d 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -40,8 +40,20 @@ int peripheral_interface_gpio_set_initial_direction_into_handle(peripheral_gpio_ return PERIPHERAL_ERROR_IO_ERROR; } +/* + * [edge_mode] [direction] + * + * none -----------------> in, out (O) + * + * rising, falling, both ---------> in (O) + * \ + * -----> out (X) + */ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { + RETV_IF(gpio->direction == direction, PERIPHERAL_ERROR_NONE); + RETV_IF(gpio->edge != PERIPHERAL_GPIO_EDGE_NONE, PERIPHERAL_ERROR_IO_ERROR); + static predefined_type_s types[3] = { {"in", 2}, {"high", 4}, @@ -81,8 +93,20 @@ int peripheral_interface_gpio_set_initial_edge_into_handle(peripheral_gpio_h gpi return PERIPHERAL_ERROR_IO_ERROR; } +/* + * [direction] [edge_mode] + * + * in ---------> none, rising, falling, both (O) + * + * out --------> none (O) + * \ + * -----> rising, falling, both (X) + */ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { + RETV_IF(gpio->edge == edge, PERIPHERAL_ERROR_NONE); + RETV_IF(gpio->direction != PERIPHERAL_GPIO_DIRECTION_IN, PERIPHERAL_ERROR_IO_ERROR); + static predefined_type_s types[4] = { {"none", 4}, {"rising", 6}, @@ -98,8 +122,16 @@ int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_g return PERIPHERAL_ERROR_NONE; } +/* + * [direction] [value] + * + * in ---------> write (X) + * out --------> write (O) + */ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) { + RETV_IF(gpio->direction == PERIPHERAL_GPIO_DIRECTION_IN, PERIPHERAL_ERROR_IO_ERROR); + static predefined_type_s types[2] = { {"0", 1}, {"1", 1} @@ -111,6 +143,12 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) return PERIPHERAL_ERROR_NONE; } +/* + * [direction] [value] + * + * in ---------> read (O) + * out --------> read (O) + */ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) { int ret; @@ -151,4 +189,4 @@ int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio) // TODO: unset interrupted callback function return PERIPHERAL_ERROR_NONE; -} \ No newline at end of file +} -- 2.7.4 From bc484e6c4e3e105d23079bf7f29a274214a60ca1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 18 Dec 2017 11:42:48 +0900 Subject: [PATCH 06/16] gpio: add interrupted callback Change-Id: I6d8d2b3e6382e3ecc2ebbc7cee8747fc2290fae9 Signed-off-by: Segwon --- include/interface/peripheral_interface_gpio.h | 4 +- include/peripheral_handle.h | 11 ++++ src/interface/peripheral_interface_gpio.c | 83 +++++++++++++++++++++++++-- src/peripheral_gpio.c | 4 +- 4 files changed, 93 insertions(+), 9 deletions(-) diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index d4ca75d..bfc7b09 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -32,7 +32,7 @@ int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, peripheral_g int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value); int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value); -int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio); -int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio); +int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); +int peripheral_interface_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); #endif/*__PERIPHERAL_INTERFACE_GPIO_H__*/ \ No newline at end of file diff --git a/include/peripheral_handle.h b/include/peripheral_handle.h index b834d06..e07c4f1 100644 --- a/include/peripheral_handle.h +++ b/include/peripheral_handle.h @@ -17,6 +17,16 @@ #ifndef __PERIPHERAL_HANDLE_H__ #define __PERIPHERAL_HANDLE_H__ +#include + +typedef struct _peripheral_gpio_interrupted_cb_info_s { + GThread *thread; + peripheral_gpio_interrupted_cb cb; + peripheral_error_e error; + void *user_data; + int status; +} interrupted_cb_info_s; + /** * @brief Internal struct for gpio context */ @@ -27,6 +37,7 @@ struct _peripheral_gpio_s { int fd_value; peripheral_gpio_direction_e direction; peripheral_gpio_edge_e edge; + interrupted_cb_info_s cb_info; }; /** diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 119230d..c8dd33b 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -14,8 +14,12 @@ * limitations under the License. */ +#include #include "peripheral_interface_gpio.h" +#define GPIO_INTERRUPTED_CALLBACK_UNSET 0 +#define GPIO_INTERRUPTED_CALLBACK_SET 1 + int peripheral_interface_gpio_set_initial_direction_into_handle(peripheral_gpio_h gpio) { static predefined_type_s types[2] = { @@ -155,6 +159,7 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) int length = 1; char gpio_buf[GPIO_BUFFER_MAX] = {0, }; + lseek(gpio->fd_value, 0, SEEK_SET); ret = read(gpio->fd_value, &gpio_buf, length); CHECK_ERROR(ret != length); @@ -172,21 +177,89 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) void peripheral_interface_gpio_close(peripheral_gpio_h gpio) { + peripheral_interface_gpio_unset_interrupted_cb(gpio); + close(gpio->fd_direction); close(gpio->fd_edge); close(gpio->fd_value); } -int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio) +static gboolean __peripheral_interface_gpio_interrupted_cb_invoke(gpointer data) { - // TODO: set interrupted callback function + peripheral_gpio_h gpio = (peripheral_gpio_h)data; + gpio->cb_info.cb(gpio, gpio->cb_info.error, NULL); + return FALSE; +} - return PERIPHERAL_ERROR_NONE; +static gpointer __peripheral_interface_gpio_poll(void *data) +{ + peripheral_gpio_h gpio = (peripheral_gpio_h)data; + + int ret; + int poll_state = 0; + struct pollfd poll_fd; + + poll_fd.fd = gpio->fd_value; + poll_fd.events = POLLPRI; + + uint32_t value; + + while (gpio->cb_info.status == GPIO_INTERRUPTED_CALLBACK_SET) { + + poll_state = poll(&poll_fd, 1, 3000); + + if (poll_state == 0) + continue; + + if (poll_state < 0) { + _E("poll failed!"); + gpio->cb_info.error = PERIPHERAL_ERROR_IO_ERROR; + g_idle_add_full(G_PRIORITY_HIGH_IDLE, __peripheral_interface_gpio_interrupted_cb_invoke, gpio, NULL); + break; + } + + if (poll_fd.revents & POLLPRI) { + ret = peripheral_interface_gpio_read(gpio, &value); + if (ret != PERIPHERAL_ERROR_NONE) + continue; + } else { + continue; + } + + if (gpio->edge == PERIPHERAL_GPIO_EDGE_NONE) + continue; + + if (gpio->edge == PERIPHERAL_GPIO_EDGE_RISING && value == 0) + continue; + + if (gpio->edge == PERIPHERAL_GPIO_EDGE_FALLING && value == 1) + continue; + + gpio->cb_info.error = PERIPHERAL_ERROR_NONE; + g_idle_add_full(G_PRIORITY_HIGH_IDLE, __peripheral_interface_gpio_interrupted_cb_invoke, gpio, NULL); + } + + return NULL; } -int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio) +int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { - // TODO: unset interrupted callback function + RETV_IF(gpio->direction != PERIPHERAL_GPIO_DIRECTION_IN, PERIPHERAL_ERROR_IO_ERROR); + + peripheral_interface_gpio_unset_interrupted_cb(gpio); + + gpio->cb_info.cb = callback; + gpio->cb_info.user_data = user_data; + gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_SET; + gpio->cb_info.thread = g_thread_new(NULL, __peripheral_interface_gpio_poll, gpio); return PERIPHERAL_ERROR_NONE; } + +int peripheral_interface_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) +{ + gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_UNSET; + g_thread_join(gpio->cb_info.thread); + + return PERIPHERAL_ERROR_NONE; +} \ No newline at end of file diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 4cd0290..b51c577 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -151,7 +151,7 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL"); - // TODO : replace interface function + peripheral_interface_gpio_set_interrupted_cb(gpio, callback, user_data); return ret; } @@ -166,7 +166,7 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - // TODO : replace interface function + peripheral_interface_gpio_unset_interrupted_cb(gpio); return ret; } -- 2.7.4 From 24403e78dd985555bf2e35a04d9c9ed3e41eaa45 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 19 Dec 2017 15:31:25 +0900 Subject: [PATCH 07/16] spi: exclude the positive value in the ioctl error check, becasue of the ioctl return length Change-Id: If7d4d517c519f6d41c6bde7a7716edda4cd6a25a Signed-off-by: Segwon --- src/interface/peripheral_interface_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index 15baf4b..b38436b 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -66,7 +66,7 @@ int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t xfer.len = length; ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - CHECK_ERROR(ret != 0); + CHECK_ERROR(ret < 0); return PERIPHERAL_ERROR_NONE; } @@ -81,7 +81,7 @@ int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_ xfer.len = length; ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - CHECK_ERROR(ret != 0); + CHECK_ERROR(ret < 0); return PERIPHERAL_ERROR_NONE; } @@ -99,7 +99,7 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint xfer.len = length; ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); - CHECK_ERROR(ret != 0); + CHECK_ERROR(ret < 0); return PERIPHERAL_ERROR_NONE; } -- 2.7.4 From 68a6482231f0e0d827e071568a785054d6c74dd0 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 19 Dec 2017 15:38:30 +0900 Subject: [PATCH 08/16] interface: add return type EINVAL in CHECK_ERROR Change-Id: I7dfb65fb371c428a7ef2f030cb5711bfb9d221af Signed-off-by: Segwon --- include/interface/peripheral_interface_common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index f51a4c2..d6137ce 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -32,6 +32,8 @@ if (expr) { \ if (errno == EAGAIN) \ return PERIPHERAL_ERROR_TRY_AGAIN; \ + if (errno == EINVAL) \ + return PERIPHERAL_ERROR_INVALID_PARAMETER; \ char errmsg[MAX_ERR_LEN]; \ strerror_r(errno, errmsg, sizeof(errmsg)); \ _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \ -- 2.7.4 From 65cfcb0c4618d9ef6f91669f8e28e5bcfb342ea8 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 27 Dec 2017 17:13:59 +0900 Subject: [PATCH 09/16] doxygen: give additional prerequisites information for set APIs Change-Id: If1a69bdfb93ef06f1f1c6734850dbafe75ff5c20 Signed-off-by: Segwon --- include/peripheral_io.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/peripheral_io.h b/include/peripheral_io.h index bb11f34..93e7e67 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -141,6 +141,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio); * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio + * @remarks To set the direction to PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, the edge mode must be set to PERIPHERAL_GPIO_EDGE_NONE. * * @param[in] gpio The GPIO handle * @param[in] direction The direction of the GPIO pin @@ -155,6 +156,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio); * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * * @see peripheral_gpio_direction_e + * @see peripheral_gpio_set_edge_mode() */ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); @@ -164,6 +166,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio + * @remarks To set the edge mode to PERIPHERAL_GPIO_EDGE_RISING, PERIPHERAL_GPIO_EDGE_FALLING, PERIPHERAL_GPIO_EDGE_BOTH, the data direction must be set to the PERIPHERAL_GPIO_DIRECTION_IN. * * @param[in] gpio The GPIO handle * @param[in] edge The edge mode of the GPIO pin @@ -178,6 +181,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * * @see peripheral_gpio_edge_e + * @see peripheral_gpio_set_direction() */ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); @@ -200,6 +204,7 @@ typedef void(*peripheral_gpio_interrupted_cb)(peripheral_gpio_h gpio, peripheral * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio + * @remarks The interrupted callback is unset when called peripheral_gpio_unset_interrupted_cb() or callback receives an error value other than PERIPHERAL_ERROR_NONE. * * @param[in] gpio The GPIO handle * @param[in] callback The GPIO interrupted callback function to set @@ -264,6 +269,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value); * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio + * @remarks To write binary data, the direction must be set to PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW. * * @param[in] gpio The GPIO handle * @param[in] value The value to set (must be 0 or 1) @@ -278,6 +284,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value); * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * * @see peripheral_gpio_read() + * @see peripheral_gpio_set_direction() */ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value); @@ -1055,6 +1062,7 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio + * @remarks ARTIK530 and Raspberry Pi 3 do not support LSB first bit order. * * @param[in] spi The SPI slave device handle * @param[in] bit_order The transfer bit order -- 2.7.4 From 76af428c6b7c3320670ec88347b332d4e8aa7412 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 2 Jan 2018 17:16:54 +0900 Subject: [PATCH 10/16] pio: return error when open is failed - to prevent explicite null dereferenced, error should be returned when open is failed. Change-Id: I645dec3879d54d43edec1ba52ace84af6c86b180 Signed-off-by: kibak.yoon --- src/peripheral_gpio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index b51c577..e5a3d8c 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -69,6 +69,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) _E("Failed to open the gpio pin, ret : %d", ret); free(handle); handle = NULL; + return ret; } ret = peripheral_interface_gpio_set_initial_direction_into_handle(handle); -- 2.7.4 From 536ad7a2e101d3e3264565f0810cf27da990c5ae Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 2 Jan 2018 18:17:53 +0900 Subject: [PATCH 11/16] pio: free the memory allocated by system_info_get_platform_string() Change-Id: Ibccb1798db42ac207ecb5f9d95858919b40371c6 Signed-off-by: kibak.yoon --- test/peripheral-io-test.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index d8a103b..23b118d 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -16,6 +16,7 @@ */ #include +#include #include #include "peripheral_io.h" @@ -81,39 +82,41 @@ static int __test_peripheral_init() ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_GPIO, &feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = test_peripheral_io_gpio_initialize(model_name, feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_I2C, &feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = test_peripheral_io_i2c_initialize(model_name, feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_PWM, &feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = test_peripheral_io_pwm_initialize(model_name, feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_UART, &feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = test_peripheral_io_uart_initialize(model_name, feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_SPI, &feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; ret = test_peripheral_io_spi_initialize(model_name, feature); if (ret != PERIPHERAL_ERROR_NONE) - return ret; + goto ERR; +ERR: + free(model_name); return ret; } @@ -536,4 +539,4 @@ int main(int argc, char **argv) } return -1; -} \ No newline at end of file +} -- 2.7.4 From 9c754a6e87dc23a1958a84acac4f7beff82f43ca Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 3 Jan 2018 12:00:19 +0900 Subject: [PATCH 12/16] gpio: do not join if the thread is null Change-Id: Ib1dafd777acaa7da520ac7aae050a05b1d607dca Signed-off-by: Segwon --- src/interface/peripheral_interface_gpio.c | 6 +++++- src/peripheral_gpio.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index c8dd33b..2695a86 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -259,7 +259,11 @@ int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, periphe int peripheral_interface_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_UNSET; - g_thread_join(gpio->cb_info.thread); + + if (gpio->cb_info.thread != NULL) { + g_thread_join(gpio->cb_info.thread); + gpio->cb_info.thread = NULL; + } return PERIPHERAL_ERROR_NONE; } \ No newline at end of file diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index e5a3d8c..0b4252c 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -86,6 +86,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) return ret; } + handle->cb_info.thread = NULL; *gpio = handle; return PERIPHERAL_ERROR_NONE; -- 2.7.4 From ccce883e3b46aa5a949751723bc7da9e211a7227 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 3 Jan 2018 12:10:20 +0900 Subject: [PATCH 13/16] gpio: enhance the interrupted callback thread safty Change-Id: Ib9374b0a62bdf7d8d71604365637d0dfacab69b6 Signed-off-by: Segwon --- include/peripheral_handle.h | 2 +- src/interface/peripheral_interface_gpio.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/peripheral_handle.h b/include/peripheral_handle.h index e07c4f1..18f260d 100644 --- a/include/peripheral_handle.h +++ b/include/peripheral_handle.h @@ -24,7 +24,7 @@ typedef struct _peripheral_gpio_interrupted_cb_info_s { peripheral_gpio_interrupted_cb cb; peripheral_error_e error; void *user_data; - int status; + gint status; } interrupted_cb_info_s; /** diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 2695a86..90c2a21 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -204,7 +204,7 @@ static gpointer __peripheral_interface_gpio_poll(void *data) uint32_t value; - while (gpio->cb_info.status == GPIO_INTERRUPTED_CALLBACK_SET) { + while (g_atomic_int_get(&gpio->cb_info.status) == GPIO_INTERRUPTED_CALLBACK_SET) { poll_state = poll(&poll_fd, 1, 3000); @@ -250,7 +250,7 @@ int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, periphe gpio->cb_info.cb = callback; gpio->cb_info.user_data = user_data; - gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_SET; + g_atomic_int_set(&gpio->cb_info.status, GPIO_INTERRUPTED_CALLBACK_SET); gpio->cb_info.thread = g_thread_new(NULL, __peripheral_interface_gpio_poll, gpio); return PERIPHERAL_ERROR_NONE; @@ -258,7 +258,7 @@ int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, periphe int peripheral_interface_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { - gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_UNSET; + g_atomic_int_set(&gpio->cb_info.status, GPIO_INTERRUPTED_CALLBACK_UNSET); if (gpio->cb_info.thread != NULL) { g_thread_join(gpio->cb_info.thread); -- 2.7.4 From 516040688ce9ba95224091d75b826c38a7a890e8 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 3 Jan 2018 13:22:51 +0900 Subject: [PATCH 14/16] gpio: fix to free a handle when peripheral_gdbus_gpio_close() is failed Change-Id: Ibab4d38a57e91b11f2c5a6e1b21e94d2c6e40eed Signed-off-by: Segwon --- src/peripheral_gpio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 0b4252c..eb2c999 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -105,10 +105,8 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) /* call gpio_close */ ret = peripheral_gdbus_gpio_close(gpio); - if (ret != PERIPHERAL_ERROR_NONE) { + if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close the gpio pin, ret : %d", ret); - return ret; - } peripheral_interface_gpio_close(gpio); -- 2.7.4 From 9cff397cac3768d73a90cb768eb217431ec45b0e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 19 Feb 2018 12:42:04 +0900 Subject: [PATCH 15/16] pio: deliver user data to gpio interrupted callback function Change-Id: Ib0048d8031a5799e0a495adafdbc4f824e117801 Signed-off-by: kibak.yoon --- src/interface/peripheral_interface_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 90c2a21..ce9dbf4 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -187,7 +187,7 @@ void peripheral_interface_gpio_close(peripheral_gpio_h gpio) static gboolean __peripheral_interface_gpio_interrupted_cb_invoke(gpointer data) { peripheral_gpio_h gpio = (peripheral_gpio_h)data; - gpio->cb_info.cb(gpio, gpio->cb_info.error, NULL); + gpio->cb_info.cb(gpio, gpio->cb_info.error, gpio->cb_info.user_data); return FALSE; } @@ -266,4 +266,4 @@ int peripheral_interface_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) } return PERIPHERAL_ERROR_NONE; -} \ No newline at end of file +} -- 2.7.4 From 145a47a47da2d3e2da2a59341f2810f70f21c249 Mon Sep 17 00:00:00 2001 From: Konrad Kuchciak Date: Mon, 13 Aug 2018 08:18:00 +0200 Subject: [PATCH 16/16] gpio: fix documentation errors * Added '#' before enums to automatically create links in the HTML documentation. * Added description of errors received in GPIO interrupted callback Change-Id: Idb818c52708b1e73de594f1b7ac77c09cda71534 Signed-off-by: Konrad Kuchciak --- include/peripheral_io.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/include/peripheral_io.h b/include/peripheral_io.h index 93e7e67..f652186 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -141,7 +141,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio); * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio - * @remarks To set the direction to PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, the edge mode must be set to PERIPHERAL_GPIO_EDGE_NONE. + * @remarks To set the direction to #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, the edge mode must be set to #PERIPHERAL_GPIO_EDGE_NONE. * * @param[in] gpio The GPIO handle * @param[in] direction The direction of the GPIO pin @@ -166,7 +166,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio - * @remarks To set the edge mode to PERIPHERAL_GPIO_EDGE_RISING, PERIPHERAL_GPIO_EDGE_FALLING, PERIPHERAL_GPIO_EDGE_BOTH, the data direction must be set to the PERIPHERAL_GPIO_DIRECTION_IN. + * @remarks To set the edge mode to #PERIPHERAL_GPIO_EDGE_RISING, #PERIPHERAL_GPIO_EDGE_FALLING, #PERIPHERAL_GPIO_EDGE_BOTH, the data direction must be set to the #PERIPHERAL_GPIO_DIRECTION_IN. * * @param[in] gpio The GPIO handle * @param[in] edge The edge mode of the GPIO pin @@ -188,6 +188,17 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e /** * @platform * @brief The GPIO interrupted callback called when the GPIO interrupt is triggered. + * @details The following errors can be received: \n + * #PERIPHERAL_ERROR_NONE Successful \n + * #PERIPHERAL_ERROR_IO_ERROR I/O operation failed \n + * #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed \n + * #PERIPHERAL_ERROR_TRY_AGAIN Try again \n + * #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed \n + * #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied \n + * #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use \n + * #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter \n + * #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported \n + * #PERIPHERAL_ERROR_UNKNOWN Unknown internal error \n * @since_tizen 4.0 * * @param[in] gpio The GPIO handle @@ -204,7 +215,7 @@ typedef void(*peripheral_gpio_interrupted_cb)(peripheral_gpio_h gpio, peripheral * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio - * @remarks The interrupted callback is unset when called peripheral_gpio_unset_interrupted_cb() or callback receives an error value other than PERIPHERAL_ERROR_NONE. + * @remarks The interrupted callback is unset when called peripheral_gpio_unset_interrupted_cb() or callback receives an error value other than #PERIPHERAL_ERROR_NONE. * * @param[in] gpio The GPIO handle * @param[in] callback The GPIO interrupted callback function to set @@ -269,7 +280,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value); * @since_tizen 4.0 * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio - * @remarks To write binary data, the direction must be set to PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW. + * @remarks To write binary data, the direction must be set to #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW. * * @param[in] gpio The GPIO handle * @param[in] value The value to set (must be 0 or 1) -- 2.7.4