From: Segwon Date: Thu, 16 Nov 2017 07:15:19 +0000 (+0900) Subject: interface: fix the CHECK_ERROR macro to receive various conditions X-Git-Tag: accepted/tizen/unified/20171221.071344~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=379c7e10e00f3539b71d511ca7de5655b9c05b9c;p=platform%2Fcore%2Fapi%2Fperipheral-io.git interface: fix the CHECK_ERROR macro to receive various conditions Signed-off-by: Segwon Change-Id: Iac30913f44ba239365a37e0dd9050623ea3f8d91 --- 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; }