From 2db5b00566952b5d6fe2cfa42ef386248d5327ff Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 15 Nov 2017 16:24:33 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 From 45e1c0feca7b87aa800f30b52b465f8829673c94 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 18:09:07 +0900 Subject: [PATCH 12/16] error: return a recongnizable error value - unclear PERIPHERAL_ERROR_UNKNOWN error is returning too much - change linux error type usage to error value defined by peripheral_io Signed-off-by: Segwon Change-Id: I3196ed16afafa3a83ba5362287d7281dcd255192 --- include/interface/peripheral_interface_common.h | 4 +- src/gdbus/peripheral_gdbus_gpio.c | 12 +- src/gdbus/peripheral_gdbus_i2c.c | 7 +- src/gdbus/peripheral_gdbus_pwm.c | 14 +- src/gdbus/peripheral_gdbus_spi.c | 8 +- src/gdbus/peripheral_gdbus_uart.c | 8 +- src/interface/peripheral_interface_gpio.c | 23 +- src/interface/peripheral_interface_i2c.c | 14 +- src/interface/peripheral_interface_pwm.c | 10 +- src/interface/peripheral_interface_spi.c | 18 +- src/interface/peripheral_interface_uart.c | 24 +- test/peripheral-io-test.c | 45 +- test/src/test_peripheral_gpio.c | 307 +++++++----- test/src/test_peripheral_i2c.c | 192 +++++--- test/src/test_peripheral_pwm.c | 158 ++++--- test/src/test_peripheral_spi.c | 317 ++++++++----- test/src/test_peripheral_uart.c | 599 +++++++++++++++--------- 17 files changed, 1106 insertions(+), 654 deletions(-) diff --git a/include/interface/peripheral_interface_common.h b/include/interface/peripheral_interface_common.h index b7047e4..f51a4c2 100644 --- a/include/interface/peripheral_interface_common.h +++ b/include/interface/peripheral_interface_common.h @@ -31,11 +31,11 @@ do { \ if (expr) { \ if (errno == EAGAIN) \ - return -EAGAIN; \ + return PERIPHERAL_ERROR_TRY_AGAIN; \ char errmsg[MAX_ERR_LEN]; \ strerror_r(errno, errmsg, sizeof(errmsg)); \ _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \ - return -EIO; \ + return PERIPHERAL_ERROR_IO_ERROR; \ } \ } while (0) diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 2f2ead6..43ee5b7 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -43,7 +43,7 @@ static int __gpio_proxy_init(void) if (gpio_proxy == NULL) { _E("Failed to create gpio proxy : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } return PERIPHERAL_ERROR_NONE; @@ -53,7 +53,7 @@ static int __gpio_proxy_deinit(void) { if (gpio_proxy == NULL) { _E("Gpio proxy is NULL"); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(gpio_proxy); @@ -84,7 +84,7 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) &error) == FALSE) { _E("Failed to request daemon to gpio open : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. @@ -95,21 +95,21 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) if (gpio->fd_direction < 0) { _E("Failed to get fd for gpio direction : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } gpio->fd_edge = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_EDGE, &error); if (gpio->fd_edge < 0) { _E("Failed to get fd for gpio edge : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } gpio->fd_value = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_VALUE, &error); if (gpio->fd_value < 0) { _E("Failed to get fd for gpio value : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(fd_list); diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 0300fb8..e85f21b 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -41,7 +41,7 @@ static int __i2c_proxy_init(void) if (i2c_proxy == NULL) { _E("Failed to create i2c proxy : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } return PERIPHERAL_ERROR_NONE; @@ -51,7 +51,7 @@ static int __i2c_proxy_deinit(void) { if (i2c_proxy == NULL) { _E("I2c proxy is NULL"); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(i2c_proxy); @@ -83,7 +83,7 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) &error) == FALSE) { _E("Failed to request daemon to i2c open : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. @@ -94,6 +94,7 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) if (i2c->fd < 0) { _E("Failed to get fd for i2c : %s", error->message); g_error_free(error); + ret = PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(fd_list); diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 1274744..4b76866 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -44,7 +44,7 @@ static int __pwm_proxy_init(void) if (pwm_proxy == NULL) { _E("Failed to create pwm proxy : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } return PERIPHERAL_ERROR_NONE; @@ -54,7 +54,7 @@ static int __pwm_proxy_deinit(void) { if (pwm_proxy == NULL) { _E("Pwm proxy is NULL"); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(pwm_proxy); @@ -86,7 +86,7 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) &error) == FALSE) { _E("Failed to request daemon to pwm open : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. @@ -97,28 +97,28 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) if (pwm->fd_period < 0) { _E("Failed to get fd for pwm period : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } pwm->fd_duty_cycle = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_DUTY_CYCLE, &error); if (pwm->fd_duty_cycle < 0) { _E("Failed to get fd for pwm duty cycle : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } pwm->fd_polarity = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_POLARITY, &error); if (pwm->fd_polarity < 0) { _E("Failed to get fd for pwm polarity : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } pwm->fd_enable = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_ENABLE, &error); if (pwm->fd_enable < 0) { _E("Failed to get fd for pwm enable : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(fd_list); diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index 9cdb0e8..d518d85 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -41,7 +41,7 @@ static int __spi_proxy_init(void) if (spi_proxy == NULL) { _E("Failed to create spi proxy : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } return PERIPHERAL_ERROR_NONE; @@ -51,7 +51,7 @@ static int __spi_proxy_deinit(void) { if (spi_proxy == NULL) { _E("Spi proxy is NULL"); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(spi_proxy); @@ -83,7 +83,7 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) &error) == FALSE) { _E("Failed to request daemon to spi open : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. @@ -94,7 +94,7 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) if (spi->fd < 0) { _E("Failed to get fd for spi : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(fd_list); diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 539ccf6..671f7da 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -41,7 +41,7 @@ static int __uart_proxy_init(void) if (uart_proxy == NULL) { _E("Failed to create uart proxy : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } return PERIPHERAL_ERROR_NONE; @@ -51,7 +51,7 @@ static int __uart_proxy_deinit(void) { if (uart_proxy == NULL) { _E("Uart proxy is NULL"); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(uart_proxy); @@ -82,7 +82,7 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) &error) == FALSE) { _E("Failed to request daemon to uart open : %s", error->message); g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; + return PERIPHERAL_ERROR_IO_ERROR; } // TODO : If ret is not PERIPHERAL_ERROR_NONE, fd list it NULL from daemon. @@ -93,7 +93,7 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) if (uart->fd < 0) { _E("Failed to get fd for uart : %s", error->message); g_error_free(error); - ret = PERIPHERAL_ERROR_UNKNOWN; + ret = PERIPHERAL_ERROR_IO_ERROR; } g_object_unref(fd_list); diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 3084350..fc677b6 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -27,7 +27,7 @@ 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); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) @@ -42,7 +42,7 @@ 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); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) @@ -55,7 +55,7 @@ int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value) int ret = write(gpio->fd_value, types[value].type, types[value].len); CHECK_ERROR(ret != types[value].len); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) @@ -67,15 +67,16 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) ret = read(gpio->fd_value, &gpio_buf, length); CHECK_ERROR(ret != length); - if (gpio_buf[0] == '0') + if (gpio_buf[0] == '0') { *value = 0; - else if (gpio_buf[0] == '1') + } else if (gpio_buf[0] == '1') { *value = 1; - else + } else { _E("Error: gpio value is error \n"); - return -EIO; + return PERIPHERAL_ERROR_IO_ERROR; + } - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_gpio_close(peripheral_gpio_h gpio) @@ -91,19 +92,19 @@ int peripheral_interface_gpio_close(peripheral_gpio_h gpio) ret = close(gpio->fd_value); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio) { // TODO: set interrupted callback function - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio) { // TODO: unset interrupted callback function - return 0; + return PERIPHERAL_ERROR_NONE; } \ No newline at end of file diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index ef4c944..b90ee4d 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -23,7 +23,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) int ret = close(i2c->fd); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) @@ -31,7 +31,7 @@ int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t int ret = read(i2c->fd, data, length); CHECK_ERROR(ret != length); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) @@ -39,7 +39,7 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t int ret = write(i2c->fd, data, length); CHECK_ERROR(ret != length); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out) @@ -61,7 +61,7 @@ int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t re *data_out = data.byte; - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in) @@ -83,7 +83,7 @@ int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t r ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out) @@ -105,7 +105,7 @@ int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t re *data_out = data.word; - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in) @@ -127,5 +127,5 @@ int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t r ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } \ No newline at end of file diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index a56a701..96d3dce 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -32,7 +32,7 @@ int peripheral_interface_pwm_close(peripheral_pwm_h pwm) ret = close(pwm->fd_enable); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, uint32_t period) @@ -45,7 +45,7 @@ int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, uint32_t period) ret = write(pwm->fd_period, pwm_buf, length); CHECK_ERROR(ret != length); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle) @@ -58,7 +58,7 @@ int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_ ret = write(pwm->fd_duty_cycle, pwm_buf, length); CHECK_ERROR(ret != length); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) @@ -71,7 +71,7 @@ int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_p int ret = write(pwm->fd_polarity, types[polarity].type, types[polarity].len); CHECK_ERROR(ret != types[polarity].len); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable) @@ -84,5 +84,5 @@ int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable) int ret = write(pwm->fd_enable, types[enable].type, types[enable].len); CHECK_ERROR(ret != types[enable].len); - return 0; + return PERIPHERAL_ERROR_NONE; } diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index b3b8fc1..d59f45e 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -24,7 +24,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) int ret = close(spi->fd); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) @@ -32,7 +32,7 @@ int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_ int ret = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) @@ -40,7 +40,7 @@ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_ int ret = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) @@ -48,7 +48,7 @@ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bit int ret = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) @@ -56,7 +56,7 @@ int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) int ret = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t length) @@ -71,7 +71,7 @@ int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_t length) @@ -86,7 +86,7 @@ int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_ ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint8_t *rxbuf, uint32_t length) @@ -94,7 +94,7 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint int ret; struct spi_ioc_transfer xfer; - if (!txbuf || !rxbuf) return -EINVAL; + if (!txbuf || !rxbuf) return PERIPHERAL_ERROR_INVALID_PARAMETER; memset(&xfer, 0, sizeof(xfer)); xfer.tx_buf = (unsigned long)txbuf; @@ -104,5 +104,5 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint ret = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index ca37ec4..e3f1814 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -38,7 +38,7 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) ret = close(uart->fd); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_flush(peripheral_uart_h uart) @@ -46,7 +46,7 @@ int peripheral_interface_uart_flush(peripheral_uart_h uart) int ret = tcflush(uart->fd, TCIOFLUSH); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) @@ -68,7 +68,7 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) @@ -88,7 +88,7 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) @@ -120,7 +120,7 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) @@ -141,14 +141,14 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u break; default: _E("Invalid parameter stop_bits"); - return -EINVAL; + return PERIPHERAL_ERROR_INVALID_PARAMETER; } peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e xonxoff, peripheral_uart_hardware_flow_control_e rtscts) @@ -164,19 +164,19 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera else if (rtscts == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) tio.c_cflag &= ~CRTSCTS; else - return -EINVAL; + return PERIPHERAL_ERROR_INVALID_PARAMETER; if (xonxoff == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF) tio.c_iflag |= (IXON | IXOFF | IXANY); else if (xonxoff == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) tio.c_iflag &= ~(IXON | IXOFF | IXANY); else - return -EINVAL; + return PERIPHERAL_ERROR_INVALID_PARAMETER; ret = tcsetattr(uart->fd, TCSANOW, &tio); CHECK_ERROR(ret != 0); - return 0; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_t length) @@ -184,7 +184,7 @@ int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_ int ret = read(uart->fd, (void *)buf, length); CHECK_ERROR(ret != length); - return ret; + return PERIPHERAL_ERROR_NONE; } int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32_t length) @@ -192,5 +192,5 @@ int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32 int ret = write(uart->fd, buf, length); CHECK_ERROR(ret != length); - return ret; + return PERIPHERAL_ERROR_NONE; } diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c index 21062a1..d8a103b 100644 --- a/test/peripheral-io-test.c +++ b/test/peripheral-io-test.c @@ -52,9 +52,9 @@ static int __get_model_name(char **model_name) ret = system_info_get_platform_string(KEY_SYSTEM_MODEL_NAME, model_name); if (ret != SYSTEM_INFO_ERROR_NONE) { printf("[Message] Failed to get model name.\n\n"); - return -1; + return PERIPHERAL_ERROR_NOT_SUPPORTED; } - return 0; + return PERIPHERAL_ERROR_NONE; } static int __get_feature(const char *key, bool *feature) @@ -63,45 +63,56 @@ static int __get_feature(const char *key, bool *feature) ret = system_info_get_platform_bool(key, feature); if (ret != SYSTEM_INFO_ERROR_NONE) { printf("[Message] Failed to feature (%s).\n\n", key); - return -1; + return PERIPHERAL_ERROR_NOT_SUPPORTED; } - return 0; + return PERIPHERAL_ERROR_NONE; } static int __test_peripheral_init() { - int ret = 0; + int ret = PERIPHERAL_ERROR_NONE; char *model_name = NULL; bool feature = false; ret = __get_model_name(&model_name); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_GPIO, &feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = test_peripheral_io_gpio_initialize(model_name, feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_I2C, &feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = test_peripheral_io_i2c_initialize(model_name, feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_PWM, &feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = test_peripheral_io_pwm_initialize(model_name, feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_UART, &feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = test_peripheral_io_uart_initialize(model_name, feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_SPI, &feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = test_peripheral_io_spi_initialize(model_name, feature); - if (ret != 0) return ret; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; return ret; } @@ -485,7 +496,7 @@ int main(int argc, char **argv) pass_count = 0; ret = __test_peripheral_init(); - if (ret != 0) { + if (ret != PERIPHERAL_ERROR_NONE) { printf("[Message] Failed test init...\n\n"); return -1; } diff --git a/test/src/test_peripheral_gpio.c b/test/src/test_peripheral_gpio.c index 9c594ff..70b139d 100644 --- a/test/src/test_peripheral_gpio.c +++ b/test/src/test_peripheral_gpio.c @@ -35,8 +35,8 @@ int test_peripheral_io_gpio_initialize(char *model, bool feature) else if (!strcmp(model, "artik")) pin = GPIO_PIN_ARTIK530; else - return -1; - return 0; + return PERIPHERAL_ERROR_NO_DEVICE; + return PERIPHERAL_ERROR_NONE; } int test_peripheral_io_gpio_peripheral_gpio_open_p(void) @@ -47,14 +47,17 @@ int test_peripheral_io_gpio_peripheral_gpio_open_p(void) if (g_feature == false) { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -66,11 +69,13 @@ int test_peripheral_io_gpio_peripheral_gpio_open_n1(void) if (g_feature == false) { ret = peripheral_gpio_open(pin, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -84,11 +89,13 @@ int test_peripheral_io_gpio_peripheral_gpio_open_n2(void) if (g_feature == false) { ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -102,14 +109,17 @@ int test_peripheral_io_gpio_peripheral_gpio_close_p(void) if (g_feature == false) { ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -121,11 +131,13 @@ int test_peripheral_io_gpio_peripheral_gpio_close_n(void) if (g_feature == false) { ret = peripheral_gpio_close(NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_close(NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -139,20 +151,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_direction_p1(void) if (g_feature == false) { ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -166,20 +181,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_direction_p2(void) if (g_feature == false) { ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -193,20 +211,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_direction_p3(void) if (g_feature == false) { ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -218,11 +239,13 @@ int test_peripheral_io_gpio_peripheral_gpio_set_direction_n1(void) if (g_feature == false) { ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -236,20 +259,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_direction_n2(void) if (g_feature == false) { ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -263,20 +289,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_direction_n3(void) if (g_feature == false) { ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -290,26 +319,29 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -323,26 +355,29 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING); if (ret != PERIPHERAL_ERROR_NONE && ret != PERIPHERAL_ERROR_TRY_AGAIN) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -356,26 +391,29 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_FALLING); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_FALLING); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -389,20 +427,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -414,11 +455,13 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -432,20 +475,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -459,20 +505,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3(void) if (g_feature == false) { ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -493,38 +542,41 @@ int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p(void) if (g_feature == false) { ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_unset_interrupted_cb(gpio_h); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -536,11 +588,13 @@ int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1(void) if (g_feature == false) { ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -554,20 +608,23 @@ int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2(void) if (g_feature == false) { ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -581,26 +638,29 @@ int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1(void) if (g_feature == false) { ret = peripheral_gpio_unset_interrupted_cb(gpio_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_unset_interrupted_cb(gpio_h); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -614,20 +674,23 @@ int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2(void) if (g_feature == false) { ret = peripheral_gpio_unset_interrupted_cb(gpio_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_unset_interrupted_cb(gpio_h); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -639,11 +702,13 @@ int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n(void) if (g_feature == false) { ret = peripheral_gpio_unset_interrupted_cb(NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_unset_interrupted_cb(NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -659,26 +724,29 @@ int test_peripheral_io_gpio_peripheral_gpio_read_p(void) if (g_feature == false) { ret = peripheral_gpio_read(gpio_h, &value); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_read(gpio_h, &value); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -692,11 +760,13 @@ int test_peripheral_io_gpio_peripheral_gpio_read_n1(void) if (g_feature == false) { ret = peripheral_gpio_read(NULL, &value); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_read(NULL, &value); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -710,26 +780,29 @@ int test_peripheral_io_gpio_peripheral_gpio_read_n2(void) if (g_feature == false) { ret = peripheral_gpio_read(gpio_h, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_read(gpio_h, NULL); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -745,26 +818,29 @@ int test_peripheral_io_gpio_peripheral_gpio_write_p(void) if (g_feature == false) { ret = peripheral_gpio_write(gpio_h, value); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_write(gpio_h, value); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -778,11 +854,13 @@ int test_peripheral_io_gpio_peripheral_gpio_write_n1(void) if (g_feature == false) { ret = peripheral_gpio_write(NULL, value); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_write(NULL, value); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -798,26 +876,29 @@ int test_peripheral_io_gpio_peripheral_gpio_write_n2(void) if (g_feature == false) { ret = peripheral_gpio_write(gpio_h, value); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_gpio_open(pin, &gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_write(gpio_h, value); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_gpio_close(gpio_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_gpio_close(gpio_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; diff --git a/test/src/test_peripheral_i2c.c b/test/src/test_peripheral_i2c.c index a9a81ee..bb1de7f 100644 --- a/test/src/test_peripheral_i2c.c +++ b/test/src/test_peripheral_i2c.c @@ -38,11 +38,11 @@ int test_peripheral_io_i2c_initialize(char *model, bool feature) if ((!strcmp(model, "rpi3")) || (!strcmp(model, "artik"))) bus = I2C_BUS; else - return -1; + return PERIPHERAL_ERROR_NO_DEVICE; address = I2C_ADDRESS; - return 0; + return PERIPHERAL_ERROR_NONE; } int test_peripheral_io_i2c_peripheral_i2c_open_p(void) @@ -53,14 +53,17 @@ int test_peripheral_io_i2c_peripheral_i2c_open_p(void) if (g_feature == false) { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -72,11 +75,13 @@ int test_peripheral_io_i2c_peripheral_i2c_open_n1(void) if (g_feature == false) { ret = peripheral_i2c_open(bus, address, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -90,11 +95,13 @@ int test_peripheral_io_i2c_peripheral_i2c_open_n2(void) if (g_feature == false) { ret = peripheral_i2c_open(I2C_BUS_INVALID, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(I2C_BUS_INVALID, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -108,11 +115,13 @@ int test_peripheral_io_i2c_peripheral_i2c_open_n3(void) if (g_feature == false) { ret = peripheral_i2c_open(bus, I2C_ADDRESS_INVALID, &i2c_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, I2C_ADDRESS_INVALID, &i2c_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -126,14 +135,17 @@ int test_peripheral_io_i2c_peripheral_i2c_close_p(void) if (g_feature == false) { ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -145,11 +157,13 @@ int test_peripheral_io_i2c_peripheral_i2c_close_n(void) if (g_feature == false) { ret = peripheral_i2c_close(NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_close(NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -165,20 +179,23 @@ int test_peripheral_io_i2c_peripheral_i2c_read_p(void) if (g_feature == false) { ret = peripheral_i2c_read(i2c_h, buf, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_read(i2c_h, buf, I2C_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -192,11 +209,13 @@ int test_peripheral_io_i2c_peripheral_i2c_read_n1(void) if (g_feature == false) { ret = peripheral_i2c_read(NULL, buf, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_read(NULL, buf, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -210,20 +229,23 @@ int test_peripheral_io_i2c_peripheral_i2c_read_n2(void) if (g_feature == false) { ret = peripheral_i2c_read(i2c_h, NULL, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_read(i2c_h, NULL, I2C_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -239,20 +261,23 @@ int test_peripheral_io_i2c_peripheral_i2c_write_p(void) if (g_feature == false) { ret = peripheral_i2c_write(i2c_h, buf, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_write(i2c_h, buf, I2C_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -266,11 +291,13 @@ int test_peripheral_io_i2c_peripheral_i2c_write_n1(void) if (g_feature == false) { ret = peripheral_i2c_write(NULL, buf, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_write(NULL, buf, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -284,20 +311,23 @@ int test_peripheral_io_i2c_peripheral_i2c_write_n2(void) if (g_feature == false) { ret = peripheral_i2c_write(i2c_h, NULL, I2C_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_write(i2c_h, NULL, I2C_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -313,20 +343,23 @@ int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_p(void) if (g_feature == false) { ret = peripheral_i2c_read_register_byte(i2c_h, I2C_REGISTER, &data); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_read_register_byte(i2c_h, I2C_REGISTER, &data); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -340,11 +373,13 @@ int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n1(void) if (g_feature == false) { ret = peripheral_i2c_read_register_byte(NULL, I2C_REGISTER, &data); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_read_register_byte(NULL, I2C_REGISTER, &data); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -359,20 +394,23 @@ int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n2(void) if (g_feature == false) { ret = peripheral_i2c_read_register_byte(i2c_h, I2C_REGISTER, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_read_register_byte(i2c_h, I2C_REGISTER, NULL); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -386,20 +424,23 @@ int test_peripheral_io_i2c_peripheral_i2c_write_register_byte_p(void) if (g_feature == false) { ret = peripheral_i2c_write_register_byte(i2c_h, I2C_REGISTER, I2C_BUFFER_VALUE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_write_register_byte(i2c_h, I2C_REGISTER, I2C_BUFFER_VALUE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -411,11 +452,13 @@ int test_peripheral_io_i2c_peripheral_i2c_write_register_byte_n(void) if (g_feature == false) { ret = peripheral_i2c_write_register_byte(NULL, I2C_REGISTER, I2C_BUFFER_VALUE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_write_register_byte(NULL, I2C_REGISTER, I2C_BUFFER_VALUE); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -431,20 +474,23 @@ int test_peripheral_io_i2c_peripheral_i2c_read_register_word_p(void) if (g_feature == false) { ret = peripheral_i2c_read_register_word(i2c_h, I2C_REGISTER, &data); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_read_register_word(i2c_h, I2C_REGISTER, &data); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -458,11 +504,13 @@ int test_peripheral_io_i2c_peripheral_i2c_read_register_word_n1(void) if (g_feature == false) { ret = peripheral_i2c_read_register_word(NULL, I2C_REGISTER, &data); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_read_register_word(NULL, I2C_REGISTER, &data); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -477,20 +525,23 @@ int test_peripheral_io_i2c_peripheral_i2c_read_register_word_n2(void) if (g_feature == false) { ret = peripheral_i2c_read_register_word(i2c_h, I2C_REGISTER, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_read_register_word(i2c_h, I2C_REGISTER, NULL); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -505,20 +556,23 @@ int test_peripheral_io_i2c_peripheral_i2c_write_register_word_p(void) if (g_feature == false) { ret = peripheral_i2c_write_register_word(i2c_h, I2C_REGISTER, I2C_BUFFER_VALUE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_open(bus, address, &i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_i2c_write_register_word(i2c_h, I2C_REGISTER, I2C_BUFFER_VALUE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_i2c_close(i2c_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_i2c_close(i2c_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -530,11 +584,13 @@ int test_peripheral_io_i2c_peripheral_i2c_write_register_word_n(void) if (g_feature == false) { ret = peripheral_i2c_write_register_word(NULL, I2C_REGISTER, I2C_BUFFER_VALUE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_i2c_write_register_word(NULL, I2C_REGISTER, I2C_BUFFER_VALUE); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; diff --git a/test/src/test_peripheral_pwm.c b/test/src/test_peripheral_pwm.c index 7b88d5e..32dd422 100644 --- a/test/src/test_peripheral_pwm.c +++ b/test/src/test_peripheral_pwm.c @@ -38,9 +38,9 @@ int test_peripheral_io_pwm_initialize(char *model, bool feature) chip = PWM_CHIP; pin = PWM_PIN; } else { - return -1; + return PERIPHERAL_ERROR_NO_DEVICE; } - return 0; + return PERIPHERAL_ERROR_NONE; } int test_peripheral_io_pwm_peripheral_pwm_open_p(void) @@ -51,14 +51,17 @@ int test_peripheral_io_pwm_peripheral_pwm_open_p(void) if (g_feature == false) { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -72,11 +75,13 @@ int test_peripheral_io_pwm_peripheral_pwm_open_n1(void) if (g_feature == false) { ret = peripheral_pwm_open(PWM_CHIP_INVALID, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(PWM_CHIP_INVALID, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -90,11 +95,13 @@ int test_peripheral_io_pwm_peripheral_pwm_open_n2(void) if (g_feature == false) { ret = peripheral_pwm_open(chip, PWM_PIN_INVALID, &pwm_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, PWM_PIN_INVALID, &pwm_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -106,11 +113,13 @@ int test_peripheral_io_pwm_peripheral_pwm_open_n3(void) if (g_feature == false) { ret = peripheral_pwm_open(chip, pin, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -124,14 +133,17 @@ int test_peripheral_io_pwm_peripheral_pwm_close_p(void) if (g_feature == false) { ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -143,11 +155,13 @@ int test_peripheral_io_pwm_peripheral_pwm_close_n(void) if (g_feature == false) { ret = peripheral_pwm_close(NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_close(NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -161,20 +175,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_period_p(void) if (g_feature == false) { ret = peripheral_pwm_set_period(pwm_h, PWM_PERIOD); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_period(pwm_h, PWM_PERIOD); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -186,11 +203,13 @@ int test_peripheral_io_pwm_peripheral_pwm_set_period_n(void) if (g_feature == false) { ret = peripheral_pwm_set_period(NULL, PWM_PERIOD); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_set_period(NULL, PWM_PERIOD); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -204,20 +223,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_p(void) if (g_feature == false) { ret = peripheral_pwm_set_duty_cycle(pwm_h, PWM_DUTY_CYCLE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_duty_cycle(pwm_h, PWM_DUTY_CYCLE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -229,11 +251,13 @@ int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_n(void) if (g_feature == false) { ret = peripheral_pwm_set_duty_cycle(NULL, PWM_DUTY_CYCLE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_set_duty_cycle(NULL, PWM_DUTY_CYCLE); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -247,20 +271,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p1(void) if (g_feature == false) { ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -274,20 +301,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p2(void) if (g_feature == false) { ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -299,11 +329,13 @@ int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n1(void) if (g_feature == false) { ret = peripheral_pwm_set_polarity(NULL, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_set_polarity(NULL, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -317,20 +349,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n2(void) if (g_feature == false) { ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -344,20 +379,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n3(void) if (g_feature == false) { ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -373,20 +411,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p1(void) if (g_feature == false) { ret = peripheral_pwm_set_enabled(pwm_h, enable); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_enabled(pwm_h, enable); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -402,20 +443,23 @@ int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p2(void) if (g_feature == false) { ret = peripheral_pwm_set_enabled(pwm_h, enable); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_open(chip, pin, &pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_pwm_set_enabled(pwm_h, enable); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_pwm_close(pwm_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_pwm_close(pwm_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -429,11 +473,13 @@ int test_peripheral_io_pwm_peripheral_pwm_set_enabled_n(void) if (g_feature == false) { ret = peripheral_pwm_set_enabled(NULL, enable); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_pwm_set_enabled(NULL, enable); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; diff --git a/test/src/test_peripheral_spi.c b/test/src/test_peripheral_spi.c index 41576c2..1969138 100644 --- a/test/src/test_peripheral_spi.c +++ b/test/src/test_peripheral_spi.c @@ -43,11 +43,11 @@ int test_peripheral_io_spi_initialize(char *model, bool feature) else if (!strcmp(model, "artik")) bus = SPI_BUS_ARTIK530; else - return -1; + return PERIPHERAL_ERROR_NO_DEVICE; cs = SPI_CS; - return 0; + return PERIPHERAL_ERROR_NONE; } int test_peripheral_io_spi_peripheral_spi_open_p(void) @@ -58,14 +58,17 @@ int test_peripheral_io_spi_peripheral_spi_open_p(void) if (g_feature == false) { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -79,11 +82,13 @@ int test_peripheral_io_spi_peripheral_spi_open_n1(void) if (g_feature == false) { ret = peripheral_spi_open(SPI_BUS_INVALID, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(SPI_BUS_INVALID, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -97,11 +102,13 @@ int test_peripheral_io_spi_peripheral_spi_open_n2(void) if (g_feature == false) { ret = peripheral_spi_open(bus, SPI_CS_INVALID, &spi_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, SPI_CS_INVALID, &spi_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -113,11 +120,13 @@ int test_peripheral_io_spi_peripheral_spi_open_n3(void) if (g_feature == false) { ret = peripheral_spi_open(bus, cs, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -131,14 +140,17 @@ int test_peripheral_io_spi_peripheral_spi_close_p(void) if (g_feature == false) { ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -150,11 +162,13 @@ int test_peripheral_io_spi_peripheral_spi_close_n(void) if (g_feature == false) { ret = peripheral_spi_close(NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_close(NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -168,20 +182,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_p1(void) if (g_feature == false) { ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_0); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_0); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -195,20 +212,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_p2(void) if (g_feature == false) { ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_1); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -222,20 +242,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_p3(void) if (g_feature == false) { ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_2); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_2); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -249,20 +272,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_p4(void) if (g_feature == false) { ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_3); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_3); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -276,20 +302,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_n1(void) if (g_feature == false) { ret = peripheral_spi_set_mode(NULL, PERIPHERAL_SPI_MODE_0); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(NULL, PERIPHERAL_SPI_MODE_0); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -303,20 +332,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_n2(void) if (g_feature == false) { ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_0 - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_0 - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -330,20 +362,23 @@ int test_peripheral_io_spi_peripheral_spi_set_mode_n3(void) if (g_feature == false) { ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_3 + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_3 + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -357,20 +392,23 @@ int test_peripheral_io_spi_peripheral_spi_set_bit_order_p1(void) if (g_feature == false) { ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_MSB); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_MSB); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -384,20 +422,23 @@ int test_peripheral_io_spi_peripheral_spi_set_bit_order_p2(void) if (g_feature == false) { ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_LSB); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_LSB); if (ret != PERIPHERAL_ERROR_IO_ERROR) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -409,11 +450,13 @@ int test_peripheral_io_spi_peripheral_spi_set_bit_order_n1(void) if (g_feature == false) { ret = peripheral_spi_set_bit_order(NULL, PERIPHERAL_SPI_BIT_ORDER_MSB); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_set_bit_order(NULL, PERIPHERAL_SPI_BIT_ORDER_MSB); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -427,20 +470,23 @@ int test_peripheral_io_spi_peripheral_spi_set_bit_order_n2(void) if (g_feature == false) { ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_MSB - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_MSB - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -454,20 +500,23 @@ int test_peripheral_io_spi_peripheral_spi_set_bit_order_n3(void) if (g_feature == false) { ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_LSB + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_bit_order(spi_h, PERIPHERAL_SPI_BIT_ORDER_LSB + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -481,20 +530,23 @@ int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_p(void) if (g_feature == false) { ret = peripheral_spi_set_bits_per_word(spi_h, SPI_BITS_PER_WORD); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_bits_per_word(spi_h, SPI_BITS_PER_WORD); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -506,11 +558,13 @@ int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n1(void) if (g_feature == false) { ret = peripheral_spi_set_bits_per_word(NULL, SPI_BITS_PER_WORD); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_set_bits_per_word(NULL, SPI_BITS_PER_WORD); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -524,20 +578,23 @@ int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n2(void) if (g_feature == false) { ret = peripheral_spi_set_bits_per_word(spi_h, SPI_BITS_PER_WORD_INVALID); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_bits_per_word(spi_h, SPI_BITS_PER_WORD_INVALID); if (ret != PERIPHERAL_ERROR_IO_ERROR) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -551,32 +608,35 @@ int test_peripheral_io_spi_peripheral_spi_set_frequency_p(void) if (g_feature == false) { ret = peripheral_spi_set_frequency(spi_h, SPI_FREQUENCY); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_set_mode(spi_h, PERIPHERAL_SPI_MODE_0); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_set_bits_per_word(spi_h, SPI_BITS_PER_WORD); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_set_frequency(spi_h, SPI_FREQUENCY); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -588,11 +648,13 @@ int test_peripheral_io_spi_peripheral_spi_set_frequency_n(void) if (g_feature == false) { ret = peripheral_spi_set_frequency(NULL, SPI_FREQUENCY); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_set_frequency(NULL, SPI_FREQUENCY); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -608,20 +670,23 @@ int test_peripheral_io_spi_peripheral_spi_read_p(void) if (g_feature == false) { ret = peripheral_spi_read(spi_h, &data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_read(spi_h, &data, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -635,11 +700,13 @@ int test_peripheral_io_spi_peripheral_spi_read_n1(void) if (g_feature == false) { ret = peripheral_spi_read(NULL, &data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_read(NULL, &data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -653,20 +720,23 @@ int test_peripheral_io_spi_peripheral_spi_read_n2(void) if (g_feature == false) { ret = peripheral_spi_read(spi_h, NULL, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_read(spi_h, NULL, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -682,20 +752,23 @@ int test_peripheral_io_spi_peripheral_spi_write_p(void) if (g_feature == false) { ret = peripheral_spi_write(spi_h, &data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_write(spi_h, &data, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -709,11 +782,13 @@ int test_peripheral_io_spi_peripheral_spi_write_n1(void) if (g_feature == false) { ret = peripheral_spi_write(NULL, &data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_write(NULL, &data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -728,20 +803,23 @@ int test_peripheral_io_spi_peripheral_spi_write_n2(void) if (g_feature == false) { ret = peripheral_spi_write(spi_h, NULL, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_write(spi_h, NULL, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -758,20 +836,23 @@ int test_peripheral_io_spi_peripheral_spi_transfer_p(void) if (g_feature == false) { ret = peripheral_spi_transfer(spi_h, &tx_data, &rx_data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_transfer(spi_h, &tx_data, &rx_data, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -786,11 +867,13 @@ int test_peripheral_io_spi_peripheral_spi_transfer_n1(void) if (g_feature == false) { ret = peripheral_spi_transfer(NULL, &tx_data, &rx_data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_transfer(NULL, &tx_data, &rx_data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -806,20 +889,23 @@ int test_peripheral_io_spi_peripheral_spi_transfer_n2(void) if (g_feature == false) { ret = peripheral_spi_transfer(spi_h, NULL, &rx_data, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_transfer(spi_h, NULL, &rx_data, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -835,20 +921,23 @@ int test_peripheral_io_spi_peripheral_spi_transfer_n3(void) if (g_feature == false) { ret = peripheral_spi_transfer(spi_h, &tx_data, NULL, SPI_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_spi_open(bus, cs, &spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_spi_transfer(spi_h, &tx_data, NULL, SPI_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_spi_close(spi_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_spi_close(spi_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; diff --git a/test/src/test_peripheral_uart.c b/test/src/test_peripheral_uart.c index 442961a..801afb8 100644 --- a/test/src/test_peripheral_uart.c +++ b/test/src/test_peripheral_uart.c @@ -37,9 +37,9 @@ int test_peripheral_io_uart_initialize(char *model, bool feature) else if (!strcmp(model, "artik")) port = UART_PORT_ARTIK530; else - return -1; + return PERIPHERAL_ERROR_NO_DEVICE; - return 0; + return PERIPHERAL_ERROR_NONE; } int test_peripheral_io_uart_peripheral_uart_open_p(void) @@ -50,14 +50,17 @@ int test_peripheral_io_uart_peripheral_uart_open_p(void) if (g_feature == false) { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -71,11 +74,13 @@ int test_peripheral_io_uart_peripheral_uart_open_n1(void) if (g_feature == false) { ret = peripheral_uart_open(UART_PORT_INVALID, &uart_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(UART_PORT_INVALID, &uart_h); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -87,11 +92,13 @@ int test_peripheral_io_uart_peripheral_uart_open_n2(void) if (g_feature == false) { ret = peripheral_uart_open(port, NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -105,14 +112,17 @@ int test_peripheral_io_uart_peripheral_uart_close_p(void) if (g_feature == false) { ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -124,11 +134,13 @@ int test_peripheral_io_uart_peripheral_uart_close_n(void) if (g_feature == false) { ret = peripheral_uart_close(NULL); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_close(NULL); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -142,20 +154,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p1(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_0); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_0); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -169,20 +184,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p2(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_50); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_50); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -196,20 +214,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p3(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_110); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_110); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -223,20 +244,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p4(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_134); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_134); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -250,20 +274,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p5(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_150); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_150); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -277,20 +304,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p6(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_200); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_200); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -304,20 +334,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p7(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_300); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_300); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -331,20 +364,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p8(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_600); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_600); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -358,20 +394,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p9(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_1200); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_1200); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -385,20 +424,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p10(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_1800); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_1800); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -412,20 +454,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p11(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_2400); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_2400); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -439,20 +484,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p12(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_4800); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_4800); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -466,20 +514,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p13(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_9600); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_9600); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -493,20 +544,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p14(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_19200); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_19200); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -520,20 +574,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p15(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_38400); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_38400); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -547,20 +604,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p16(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_57600); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_57600); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -574,20 +634,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p17(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_115200); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_115200); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -601,20 +664,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p18(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_230400); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_230400); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -626,11 +692,13 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n1(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(NULL, PERIPHERAL_UART_BAUD_RATE_1200); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_set_baud_rate(NULL, PERIPHERAL_UART_BAUD_RATE_1200); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -644,20 +712,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n2(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_0 - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_0 - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -671,20 +742,23 @@ int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n3(void) if (g_feature == false) { ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_230400 + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_baud_rate(uart_h, PERIPHERAL_UART_BAUD_RATE_230400 + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -698,20 +772,23 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_p1(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_5BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_5BIT); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -725,20 +802,23 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_p2(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_6BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_6BIT); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -752,20 +832,23 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_p3(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_7BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_7BIT); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -779,20 +862,23 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_p4(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_8BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_8BIT); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -804,11 +890,13 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_n1(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(NULL, PERIPHERAL_UART_BYTE_SIZE_5BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_set_byte_size(NULL, PERIPHERAL_UART_BYTE_SIZE_5BIT); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -822,20 +910,23 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_n2(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_5BIT - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_5BIT - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -849,20 +940,23 @@ int test_peripheral_io_uart_peripheral_uart_set_byte_size_n3(void) if (g_feature == false) { ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_8BIT + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_byte_size(uart_h, PERIPHERAL_UART_BYTE_SIZE_8BIT + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -876,20 +970,23 @@ int test_peripheral_io_uart_peripheral_uart_set_parity_p1(void) if (g_feature == false) { ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_NONE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -903,20 +1000,23 @@ int test_peripheral_io_uart_peripheral_uart_set_parity_p2(void) if (g_feature == false) { ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_EVEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_EVEN); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -930,20 +1030,23 @@ int test_peripheral_io_uart_peripheral_uart_set_parity_p3(void) if (g_feature == false) { ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_ODD); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_ODD); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -955,11 +1058,13 @@ int test_peripheral_io_uart_peripheral_uart_set_parity_n1(void) if (g_feature == false) { ret = peripheral_uart_set_parity(NULL, PERIPHERAL_UART_PARITY_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_set_parity(NULL, PERIPHERAL_UART_PARITY_NONE); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -973,20 +1078,23 @@ int test_peripheral_io_uart_peripheral_uart_set_parity_n2(void) if (g_feature == false) { ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_NONE - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_NONE - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1000,20 +1108,23 @@ int test_peripheral_io_uart_peripheral_uart_set_parity_n3(void) if (g_feature == false) { ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_ODD + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_parity(uart_h, PERIPHERAL_UART_PARITY_ODD + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1027,20 +1138,23 @@ int test_peripheral_io_uart_peripheral_uart_set_stop_bits_p1(void) if (g_feature == false) { ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_1BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_1BIT); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1054,20 +1168,23 @@ int test_peripheral_io_uart_peripheral_uart_set_stop_bits_p2(void) if (g_feature == false) { ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_2BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_2BIT); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1079,11 +1196,13 @@ int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n1(void) if (g_feature == false) { ret = peripheral_uart_set_stop_bits(NULL, PERIPHERAL_UART_STOP_BITS_1BIT); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_set_stop_bits(NULL, PERIPHERAL_UART_STOP_BITS_1BIT); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1097,20 +1216,23 @@ int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n2(void) if (g_feature == false) { ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_1BIT - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_1BIT - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1124,20 +1246,23 @@ int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n3(void) if (g_feature == false) { ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_2BIT + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_stop_bits(uart_h, PERIPHERAL_UART_STOP_BITS_2BIT + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1151,20 +1276,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_p1(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1178,20 +1306,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_p2(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1205,20 +1336,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_p3(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1232,20 +1366,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_p4(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS); if (ret != PERIPHERAL_ERROR_NONE) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1257,11 +1394,13 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_n1(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(NULL, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_set_flow_control(NULL, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1275,20 +1414,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_n2(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE - 1, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE - 1, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1302,20 +1444,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_n3(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF + 1, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF + 1, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1329,20 +1474,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_n4(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE - 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE - 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1356,20 +1504,23 @@ int test_peripheral_io_uart_peripheral_uart_set_flow_control_n5(void) if (g_feature == false) { ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF + 1); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_set_flow_control(uart_h, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE, PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF + 1); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1385,20 +1536,23 @@ int test_peripheral_io_uart_peripheral_uart_read_p(void) if (g_feature == false) { ret = peripheral_uart_read(uart_h, data, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_read(uart_h, data, UART_BUFFER_LEN); if (ret <= 0 && ret != PERIPHERAL_ERROR_TRY_AGAIN) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1412,11 +1566,13 @@ int test_peripheral_io_uart_peripheral_uart_read_n1(void) if (g_feature == false) { ret = peripheral_uart_read(NULL, data, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_read(NULL, data, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1430,20 +1586,23 @@ int test_peripheral_io_uart_peripheral_uart_read_n2(void) if (g_feature == false) { ret = peripheral_uart_read(uart_h, NULL, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_read(uart_h, NULL, UART_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1459,20 +1618,23 @@ int test_peripheral_io_uart_peripheral_uart_write_p(void) if (g_feature == false) { ret = peripheral_uart_write(uart_h, data, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_write(uart_h, data, UART_BUFFER_LEN); if (ret <= 0 && ret != PERIPHERAL_ERROR_TRY_AGAIN) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1486,11 +1648,13 @@ int test_peripheral_io_uart_peripheral_uart_write_n1(void) if (g_feature == false) { ret = peripheral_uart_write(NULL, data, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_write(NULL, data, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) + return ret; } return PERIPHERAL_ERROR_NONE; @@ -1505,20 +1669,23 @@ int test_peripheral_io_uart_peripheral_uart_write_n2(void) if (g_feature == false) { ret = peripheral_uart_write(uart_h, NULL, UART_BUFFER_LEN); - if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) + return ret; } else { ret = peripheral_uart_open(port, &uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; ret = peripheral_uart_write(uart_h, NULL, UART_BUFFER_LEN); if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { peripheral_uart_close(uart_h); - return PERIPHERAL_ERROR_UNKNOWN; + return ret; } ret = peripheral_uart_close(uart_h); - if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + if (ret != PERIPHERAL_ERROR_NONE) + return ret; } return PERIPHERAL_ERROR_NONE; -- 2.7.4 From ceca2c8400fd790a0ceb1b1c7c37578810217a4f Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 20:24:21 +0900 Subject: [PATCH 13/16] gpio: unuse pin in gpio handle Change-Id: I13df7070d2647a36752d46966bdb2fc71a2facfe Signed-off-by: Segwon --- include/gdbus/peripheral_gdbus_gpio.h | 2 +- include/peripheral_handle.h | 1 - src/gdbus/peripheral_gdbus_gpio.c | 4 ++-- src/peripheral_gpio.c | 5 +---- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index 9402a0b..edef2ea 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -19,7 +19,7 @@ #include "peripheral_gdbus_common.h" -int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); +int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio, int pin); int peripheral_gdbus_gpio_close(void); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/peripheral_handle.h b/include/peripheral_handle.h index be8a066..0fc1b25 100644 --- a/include/peripheral_handle.h +++ b/include/peripheral_handle.h @@ -21,7 +21,6 @@ * @brief Internal struct for gpio context */ struct _peripheral_gpio_s { - int pin; uint handle; int fd_direction; int fd_edge; diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 43ee5b7..5400429 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -63,7 +63,7 @@ static int __gpio_proxy_deinit(void) return PERIPHERAL_ERROR_NONE; } -int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) +int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio, int pin) { int ret; GError *error = NULL; @@ -75,7 +75,7 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) if (peripheral_io_gdbus_gpio_call_open_sync( gpio_proxy, - gpio->pin, + pin, NULL, &gpio->handle, &ret, diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index b6ea462..152be9a 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -58,15 +58,12 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) /* Initialize */ handle = (peripheral_gpio_h)calloc(1, sizeof(struct _peripheral_gpio_s)); - if (handle == NULL) { _E("Failed to allocate peripheral_gpio_h"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - handle->pin = gpio_pin; - - ret = peripheral_gdbus_gpio_open(handle); + ret = peripheral_gdbus_gpio_open(handle, gpio_pin); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to open the gpio pin, ret : %d", ret); free(handle); -- 2.7.4 From c12e3337d4be71bfd3618bdfc4e27a1c614b8fac Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 21:23:40 +0900 Subject: [PATCH 14/16] [6/6] fd passing: replace to interface functions - since return value of close interface function is meaningless, return type is modified to void. Change-Id: I3ef4298ac5a47db29697bdbbca97ecfbc0e20a57 Signed-off-by: Segwon --- include/interface/peripheral_interface_gpio.h | 2 +- include/interface/peripheral_interface_i2c.h | 2 +- include/interface/peripheral_interface_pwm.h | 2 +- include/interface/peripheral_interface_spi.h | 2 +- include/interface/peripheral_interface_uart.h | 2 +- src/interface/peripheral_interface_gpio.c | 17 ++------- src/interface/peripheral_interface_i2c.c | 7 +--- src/interface/peripheral_interface_pwm.c | 21 +++------- src/interface/peripheral_interface_spi.c | 7 +--- src/interface/peripheral_interface_uart.c | 10 +---- src/peripheral_gpio.c | 37 ++++++------------ src/peripheral_i2c.c | 48 +++++++---------------- src/peripheral_pwm.c | 38 +++++++----------- src/peripheral_spi.c | 55 ++++++++------------------- src/peripheral_uart.c | 55 ++++++++------------------- 15 files changed, 90 insertions(+), 215 deletions(-) diff --git a/include/interface/peripheral_interface_gpio.h b/include/interface/peripheral_interface_gpio.h index e5276e5..140edea 100644 --- a/include/interface/peripheral_interface_gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -21,7 +21,7 @@ #define GPIO_BUFFER_MAX 64 -int peripheral_interface_gpio_close(peripheral_gpio_h gpio); +void peripheral_interface_gpio_close(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_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); int peripheral_interface_gpio_write(peripheral_gpio_h gpio, uint32_t value); diff --git a/include/interface/peripheral_interface_i2c.h b/include/interface/peripheral_interface_i2c.h index 5d5eb45..b9a47c6 100644 --- a/include/interface/peripheral_interface_i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -54,7 +54,7 @@ struct i2c_smbus_ioctl_data { union i2c_smbus_data *data; }; -int peripheral_interface_i2c_close(peripheral_i2c_h i2c); +void 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_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out); diff --git a/include/interface/peripheral_interface_pwm.h b/include/interface/peripheral_interface_pwm.h index f8875bf..2e26223 100644 --- a/include/interface/peripheral_interface_pwm.h +++ b/include/interface/peripheral_interface_pwm.h @@ -28,7 +28,7 @@ * @param[in] pin pwm pin number * @return On success, 0 is returned. On failure, a negative value is returned. */ -int peripheral_interface_pwm_close(peripheral_pwm_h pwm); +void peripheral_interface_pwm_close(peripheral_pwm_h pwm); /** * @brief pwm_set_period() sets the pwm period. diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h index 801c324..7667bd2 100644 --- a/include/interface/peripheral_interface_spi.h +++ b/include/interface/peripheral_interface_spi.h @@ -19,7 +19,7 @@ #include "peripheral_interface_common.h" -int peripheral_interface_spi_close(peripheral_spi_h spi); +void peripheral_interface_spi_close(peripheral_spi_h spi); int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order); int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits); diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h index c4c82ec..fb44638 100644 --- a/include/interface/peripheral_interface_uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -25,7 +25,7 @@ * @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_close(peripheral_uart_h uart); +void peripheral_interface_uart_close(peripheral_uart_h uart); /** * @brief uart_flush() flushes uart buffer. diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index fc677b6..00b911b 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -79,20 +79,11 @@ int peripheral_interface_gpio_read(peripheral_gpio_h gpio, uint32_t *value) return PERIPHERAL_ERROR_NONE; } -int peripheral_interface_gpio_close(peripheral_gpio_h gpio) +void peripheral_interface_gpio_close(peripheral_gpio_h gpio) { - int ret; - - ret = close(gpio->fd_direction); - CHECK_ERROR(ret != 0); - - ret = close(gpio->fd_edge); - CHECK_ERROR(ret != 0); - - ret = close(gpio->fd_value); - CHECK_ERROR(ret != 0); - - return PERIPHERAL_ERROR_NONE; + close(gpio->fd_direction); + close(gpio->fd_edge); + close(gpio->fd_value); } int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index b90ee4d..e887a37 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -18,12 +18,9 @@ #include "peripheral_interface_i2c.h" -int peripheral_interface_i2c_close(peripheral_i2c_h i2c) +void peripheral_interface_i2c_close(peripheral_i2c_h i2c) { - int ret = close(i2c->fd); - CHECK_ERROR(ret != 0); - - return PERIPHERAL_ERROR_NONE; + close(i2c->fd); } int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) diff --git a/src/interface/peripheral_interface_pwm.c b/src/interface/peripheral_interface_pwm.c index 96d3dce..35fdc69 100644 --- a/src/interface/peripheral_interface_pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -16,23 +16,12 @@ #include "peripheral_interface_pwm.h" -int peripheral_interface_pwm_close(peripheral_pwm_h pwm) +void peripheral_interface_pwm_close(peripheral_pwm_h pwm) { - int ret; - - ret = close(pwm->fd_period); - CHECK_ERROR(ret != 0); - - ret = close(pwm->fd_duty_cycle); - CHECK_ERROR(ret != 0); - - ret = close(pwm->fd_polarity); - CHECK_ERROR(ret != 0); - - ret = close(pwm->fd_enable); - CHECK_ERROR(ret != 0); - - return PERIPHERAL_ERROR_NONE; + close(pwm->fd_period); + close(pwm->fd_duty_cycle); + close(pwm->fd_polarity); + close(pwm->fd_enable); } int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, uint32_t period) diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index d59f45e..15baf4b 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -19,12 +19,9 @@ #include "peripheral_interface_spi.h" -int peripheral_interface_spi_close(peripheral_spi_h spi) +void peripheral_interface_spi_close(peripheral_spi_h spi) { - int ret = close(spi->fd); - CHECK_ERROR(ret != 0); - - return PERIPHERAL_ERROR_NONE; + close(spi->fd); } int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index e3f1814..eadef4a 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -29,16 +29,10 @@ static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = { static const int byteinfo[4] = {CS5, CS6, CS7, CS8}; -int peripheral_interface_uart_close(peripheral_uart_h uart) +void peripheral_interface_uart_close(peripheral_uart_h uart) { - int ret; - peripheral_interface_uart_flush(uart); - - ret = close(uart->fd); - CHECK_ERROR(ret != 0); - - return PERIPHERAL_ERROR_NONE; + close(uart->fd); } int peripheral_interface_uart_flush(peripheral_uart_h uart) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 152be9a..229c831 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -18,8 +18,9 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus_gpio.h" #include "peripheral_handle.h" +#include "peripheral_gdbus_gpio.h" +#include "peripheral_interface_gpio.h" #include "peripheral_log.h" #define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" @@ -88,8 +89,12 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) /* call gpio_close */ ret = peripheral_gdbus_gpio_close(); - 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); free(gpio); gpio = NULL; @@ -102,16 +107,11 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) */ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((direction < PERIPHERAL_GPIO_DIRECTION_IN) || (direction > PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid direction input"); - /* call gpio_set_direction */ - // TODO : replace interface function - - return ret; + return peripheral_interface_gpio_set_direction(gpio, direction); } /** @@ -119,16 +119,11 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct */ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((edge < PERIPHERAL_GPIO_EDGE_NONE) || (edge > PERIPHERAL_GPIO_EDGE_BOTH), PERIPHERAL_ERROR_INVALID_PARAMETER, "edge input is invalid"); - /* call gpio_set_edge_mode */ - // TODO : replace interface function - - return ret; + return peripheral_interface_gpio_set_edge_mode(gpio, edge); } /** @@ -167,16 +162,11 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) */ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid"); - /* call gpio_read */ - // TODO : replace interface function - - return ret; + return peripheral_interface_gpio_read(gpio, value); } /** @@ -184,14 +174,9 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) */ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid"); - /* call gpio_write */ - // TODO : replace interface function - - return ret; + return peripheral_interface_gpio_write(gpio, value); } diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index f3a8c5a..3d9b908 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -18,8 +18,9 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus_i2c.h" #include "peripheral_handle.h" +#include "peripheral_gdbus_i2c.h" +#include "peripheral_interface_i2c.h" #include "peripheral_log.h" #define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c" @@ -65,19 +66,18 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s)); - if (handle == NULL) { _E("Failed to allocate peripheral_i2c_h"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } ret = peripheral_gdbus_i2c_open(handle, bus, address); - if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to open i2c communication, ret : %d", ret); free(handle); handle = NULL; } + *i2c = handle; return ret; @@ -91,8 +91,12 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); ret = peripheral_gdbus_i2c_close(); - if (ret != PERIPHERAL_ERROR_NONE) + if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close i2c communcation, ret : %d", ret); + return ret; + } + + peripheral_interface_i2c_close(i2c); free(i2c); i2c = NULL; @@ -102,76 +106,52 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_i2c_read(i2c, data, length); } int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_i2c_write(i2c, data, length); } int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_i2c_read_register_byte(i2c, reg, data); } int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_i2c_write_register_byte(i2c, reg, data); } int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_i2c_read_register_word(i2c, reg, data); } int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_i2c_write_register_word(i2c, reg, data); } diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index f418ac5..51ad72b 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -18,8 +18,9 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus_pwm.h" #include "peripheral_handle.h" +#include "peripheral_gdbus_pwm.h" +#include "peripheral_interface_pwm.h" #include "peripheral_log.h" #define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm" @@ -57,19 +58,18 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) /* Initialize */ handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s)); - if (handle == NULL) { _E("Failed to allocate peripheral_pwm_h"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } ret = peripheral_gdbus_pwm_open(handle, chip, pin); - if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to open PWM chip : %d, pin : %d", chip, pin); free(handle); handle = NULL; } + *pwm = handle; return ret; @@ -82,59 +82,49 @@ 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()) < 0) + ret = peripheral_gdbus_pwm_close(); + if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); + return ret; + } + + peripheral_interface_pwm_close(pwm); free(pwm); + pwm = NULL; return ret; } int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_pwm_set_period(pwm, period_ns); } int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_pwm_set_duty_cycle(pwm, duty_cycle_ns); } int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((polarity < PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) || (polarity > PERIPHERAL_PWM_POLARITY_ACTIVE_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid polarity parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_pwm_set_polarity(pwm, polarity); } int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_pwm_set_enable(pwm, enable); } diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 862e4d9..0014893 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -18,8 +18,9 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus_spi.h" #include "peripheral_handle.h" +#include "peripheral_gdbus_spi.h" +#include "peripheral_interface_spi.h" #include "peripheral_log.h" #define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi" @@ -56,19 +57,18 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi) /* Initialize */ handle = (peripheral_spi_h)calloc(1, sizeof(struct _peripheral_spi_s)); - if (handle == NULL) { _E("Failed to allocate peripheral_spi_h"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } ret = peripheral_gdbus_spi_open(handle, bus, cs); - if (ret != PERIPHERAL_ERROR_NONE) { _E("SPI open error (%d, %d)", bus, cs); free(handle); handle = NULL; } + *spi = handle; return ret; @@ -82,99 +82,76 @@ int peripheral_spi_close(peripheral_spi_h spi) RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); ret = peripheral_gdbus_spi_close(); - if (ret < PERIPHERAL_ERROR_NONE) + if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close SPI device, continuing anyway, ret : %d", ret); + return ret; + } + + peripheral_interface_spi_close(spi); free(spi); + spi = NULL; return ret; } int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_set_mode(spi, mode); } int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((bit_order < PERIPHERAL_SPI_BIT_ORDER_MSB) || (bit_order > PERIPHERAL_SPI_BIT_ORDER_LSB), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid bit order parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_set_bit_order(spi, bit_order); } int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_set_bits_per_word(spi, bits); } int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_set_frequency(spi, freq_hz); } int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_read(spi, data, length); } int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_write(spi, data, length); } int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_spi_transfer(spi, txdata, rxdata, length); } diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 988dd38..e66856c 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -18,8 +18,9 @@ #include #include "peripheral_io.h" -#include "peripheral_gdbus_uart.h" #include "peripheral_handle.h" +#include "peripheral_gdbus_uart.h" +#include "peripheral_interface_uart.h" #include "peripheral_log.h" #define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart" @@ -58,19 +59,18 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart) RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number"); handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s)); - if (handle == NULL) { _E("Failed to allocate peripheral_uart_h"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } ret = peripheral_gdbus_uart_open(handle, port); - if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to open uart port, ret : %d", ret); free(handle); handle = NULL; } + *uart = handle; return ret; @@ -87,8 +87,12 @@ int peripheral_uart_close(peripheral_uart_h uart) RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); ret = peripheral_gdbus_uart_close(); - if (ret < PERIPHERAL_ERROR_NONE) + if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close uart communication, continuing anyway, ret : %d", ret); + return ret; + } + + peripheral_interface_uart_close(uart); free(uart); uart = NULL; @@ -101,72 +105,51 @@ int peripheral_uart_close(peripheral_uart_h uart) */ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_set_baud_rate(uart, baud); } int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_set_byte_size(uart, byte_size); } int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_set_parity(uart, parity); } int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((stop_bits < PERIPHERAL_UART_STOP_BITS_1BIT) || (stop_bits > PERIPHERAL_UART_STOP_BITS_2BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_set_stop_bits(uart, stop_bits); } - /** * @brief Sets baudrate of the uart device. */ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF((sw_flow_control < PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) || (sw_flow_control > PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid sw_flow_control parameter"); RETVM_IF((hw_flow_control < PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) || (hw_flow_control > PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid hw_flow_control parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_set_flow_control(uart, sw_flow_control, hw_flow_control); } /** @@ -174,15 +157,11 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof */ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_read(uart, data, length); } /** @@ -190,13 +169,9 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) */ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length) { - int ret = PERIPHERAL_ERROR_NONE; - 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"); RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - // TODO : replace interface function - - return ret; + return peripheral_interface_uart_write(uart, data, length); } -- 2.7.4 From 00444b0dd913aa9f60ffc66d335bcaf6f0bf2507 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 23:20:55 +0900 Subject: [PATCH 15/16] i2c: try to call ioctl() to test i2c-stub when read()/write() is failed Change-Id: I71688ff99689de8b73d74166f0b8ef9cf1ebde67 Signed-off-by: Segwon --- src/interface/peripheral_interface_i2c.c | 58 ++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index e887a37..7c793e3 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -23,18 +23,64 @@ void peripheral_interface_i2c_close(peripheral_i2c_h i2c) close(i2c->fd); } -int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) +/* It was developed temporarily because of the I2C Stub. */ +static int peripheral_interface_i2c_read_buffer(peripheral_i2c_h i2c, uint8_t *data_out, uint32_t length) { - int ret = read(i2c->fd, data, length); - CHECK_ERROR(ret != length); + int ret; + + 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_arg.data = &data; + data_arg.command = *data_out; + + ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(ret != 0); + + *data_out = data.byte; + + return PERIPHERAL_ERROR_NONE; +} + +int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data_out, uint32_t length) +{ + int ret = read(i2c->fd, data_out, length); + if (ret != length) + return peripheral_interface_i2c_read_buffer(i2c, data_out, length); + + return PERIPHERAL_ERROR_NONE; +} + +/* It was developed temporarily because of the I2C Stub. */ +static int peripheral_interface_i2c_write_buffer(peripheral_i2c_h i2c, uint8_t *data_in, uint32_t length) +{ + int ret; + + 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_arg.data = &data; + data_arg.command = *data_in; + + ret = ioctl(i2c->fd, I2C_SMBUS, &data_arg); + CHECK_ERROR(ret != 0); return PERIPHERAL_ERROR_NONE; } -int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) +int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data_in, uint32_t length) { - int ret = write(i2c->fd, data, length); - CHECK_ERROR(ret != length); + int ret = write(i2c->fd, data_in, length); + if (ret != length) + return peripheral_interface_i2c_write_buffer(i2c, data_in, length); return PERIPHERAL_ERROR_NONE; } -- 2.7.4 From a2ada4a71a7e1a328016b393e5c6f363421468f9 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 23:35:59 +0900 Subject: [PATCH 16/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