From 1acdf7369bb787e121481f34dbfc16276e1d1876 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 16:37:46 +0900 Subject: [PATCH 01/16] api: added parameter check statement. Signed-off-by: Segwon Change-Id: I610bba87b751637c1443e7cd6b1ba83a25b8f246 --- src/peripheral_gpio.c | 8 ++++++-- src/peripheral_i2c.c | 7 +++++-- src/peripheral_pwm.c | 2 ++ src/peripheral_spi.c | 8 ++++++-- src/peripheral_uart.c | 10 ++++++---- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index f7b68ee..afb09f3 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -114,6 +114,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) int ret = PERIPHERAL_ERROR_NONE; peripheral_gpio_h handle; + RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle"); RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number"); /* Initialize */ @@ -170,6 +171,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct int ret = PERIPHERAL_ERROR_NONE; 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 */ ret = peripheral_gdbus_gpio_set_direction(gpio, direction); @@ -188,8 +190,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - RETVM_IF(edge > PERIPHERAL_GPIO_EDGE_BOTH, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid edge input"); + 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 */ ret = peripheral_gdbus_gpio_set_edge_mode(gpio, edge); @@ -207,6 +208,7 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); + RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL"); ret = peripheral_gdbus_gpio_set_interrupted_cb(gpio, callback, user_data); if (ret != PERIPHERAL_ERROR_NONE) { @@ -252,6 +254,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value) int ret = PERIPHERAL_ERROR_NONE; 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 */ ret = peripheral_gdbus_gpio_read(gpio, (int *)value); @@ -269,6 +272,7 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value) int ret = PERIPHERAL_ERROR_NONE; 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 */ ret = peripheral_gdbus_gpio_write(gpio, (int)value); diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index f52b9b4..6393494 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -39,6 +39,7 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) peripheral_i2c_h handle; int ret = PERIPHERAL_ERROR_NONE; + RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle"); RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s)); @@ -84,7 +85,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) int ret; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_i2c_read(i2c, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) @@ -98,7 +99,7 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) int ret; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_i2c_write(i2c, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) @@ -113,6 +114,7 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t uint16_t w_data, dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, dummy, &w_data); if (ret != PERIPHERAL_ERROR_NONE) @@ -143,6 +145,7 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_ uint16_t dummy = 0, data_out; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, dummy, &data_out); if (ret != PERIPHERAL_ERROR_NONE) diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index be18d45..3ea42e0 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -29,6 +29,7 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) peripheral_pwm_h handle; int ret = PERIPHERAL_ERROR_NONE; + RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle"); RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); /* Initialize */ @@ -99,6 +100,7 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e int ret; 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"); ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity); if (ret != PERIPHERAL_ERROR_NONE) diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 7b2baf7..07fefdf 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -30,6 +30,7 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi) peripheral_spi_h handle; int ret = PERIPHERAL_ERROR_NONE; + RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle"); RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); /* Initialize */ @@ -75,8 +76,7 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - RETVM_IF(mode > PERIPHERAL_SPI_MODE_3, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid spi mode parameter"); + RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter"); ret = peripheral_gdbus_spi_set_mode(spi, mode); if (ret != PERIPHERAL_ERROR_NONE) @@ -90,6 +90,7 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_ int ret; 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"); bool lsb = (bit_order == PERIPHERAL_SPI_BIT_ORDER_LSB) ? true : false; ret = peripheral_gdbus_spi_set_bit_order(spi, lsb); @@ -130,6 +131,7 @@ int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_spi_read(spi, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) @@ -143,6 +145,7 @@ int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_spi_write(spi, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) @@ -156,6 +159,7 @@ int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxda int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); + RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_spi_transfer(spi, txdata, rxdata, (int)length); if (ret != PERIPHERAL_ERROR_NONE) diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index cb62b52..f90d433 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -32,6 +32,7 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart) peripheral_uart_h handle; int ret; + RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle"); RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number"); handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s)); @@ -83,8 +84,7 @@ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_r int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(baud > PERIPHERAL_UART_BAUD_RATE_230400, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid baud input"); + RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input"); ret = peripheral_gdbus_uart_set_baud_rate(uart, baud); if (ret != PERIPHERAL_ERROR_NONE) @@ -144,6 +144,8 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof int ret; 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"); bool xonxoff = (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF) ? true : false; bool rtscts = (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) ? true : false; @@ -163,7 +165,7 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_uart_read(uart, data, (int)length); if (ret < PERIPHERAL_ERROR_NONE) @@ -180,7 +182,7 @@ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); ret = peripheral_gdbus_uart_write(uart, data, (int)length); if (ret < PERIPHERAL_ERROR_NONE) -- 2.7.4 From 9aad6d71ed47fbab256dfceb490f6b913fb43d64 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 26 Sep 2017 10:59:53 +0900 Subject: [PATCH 02/16] version up 0.1.0 Change-Id: I9fa1f3932c383ebe33951123a47c025b9e3ac57b Signed-off-by: kibak.yoon --- packaging/capi-system-peripheral-io.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-system-peripheral-io.spec b/packaging/capi-system-peripheral-io.spec index 130bd54..93ce366 100644 --- a/packaging/capi-system-peripheral-io.spec +++ b/packaging/capi-system-peripheral-io.spec @@ -1,6 +1,6 @@ Name: capi-system-peripheral-io Summary: Tizen Peripheral Input & Output library -Version: 0.0.5 +Version: 0.1.0 Release: 0 Group: System & System Tools License: Apache-2.0 -- 2.7.4 From 8872887249edaecc3fecab972941512e4cb9db4b Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 27 Sep 2017 18:31:42 +0900 Subject: [PATCH 03/16] api: add feature invalid check. - add dependency the system info package. - almost api return the PERIPHERAL_ERROR_NOT_SUPPORTED Signed-off-by: Segwon Change-Id: I1c3cc4a8575cf18eec0d0338cca862555b02070c --- CMakeLists.txt | 2 +- packaging/capi-system-peripheral-io.spec | 1 + src/peripheral_gpio.c | 28 ++++++++++++++++++++++++++++ src/peripheral_i2c.c | 29 +++++++++++++++++++++++++++++ src/peripheral_pwm.c | 28 ++++++++++++++++++++++++++++ src/peripheral_spi.c | 30 ++++++++++++++++++++++++++++++ src/peripheral_uart.c | 30 ++++++++++++++++++++++++++++++ 7 files changed, 147 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 931ace5..c7ae260 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(fw_name "${project_prefix}-${service}-${submodule}") PROJECT(${fw_name}) -SET(dependents "dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common") +SET(dependents "dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common capi-system-info") SET(pc_dependents "capi-base-common") SET(CMAKE_INSTALL_PREFIX ${prefix}) diff --git a/packaging/capi-system-peripheral-io.spec b/packaging/capi-system-peripheral-io.spec index 93ce366..2f105bc 100644 --- a/packaging/capi-system-peripheral-io.spec +++ b/packaging/capi-system-peripheral-io.spec @@ -12,6 +12,7 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index afb09f3..93d1231 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_gpio.h" @@ -25,6 +26,25 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" +#define PERIPHERAL_IO_GPIO_FEATURE "http://tizen.org/feature/peripheral_io.gpio" + +#define GPIO_FEATURE_UNKNOWN -1 +#define GPIO_FEATURE_FALSE 0 +#define GPIO_FEATURE_TRUE 1 + +static int gpio_feature = GPIO_FEATURE_UNKNOWN; + +static bool __is_feature_supported() +{ + bool feature = false; + + if (gpio_feature == GPIO_FEATURE_UNKNOWN) { + system_info_get_platform_bool(PERIPHERAL_IO_GPIO_FEATURE, &feature); + gpio_feature = (feature ? GPIO_FEATURE_TRUE : GPIO_FEATURE_FALSE); + } + return (gpio_feature == GPIO_FEATURE_TRUE ? true : false); +} + typedef struct { peripheral_gpio_h handle; peripheral_gpio_interrupted_cb callback; @@ -114,6 +134,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio) int ret = PERIPHERAL_ERROR_NONE; peripheral_gpio_h handle; + RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "GPIO feature is not supported"); RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle"); RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number"); @@ -149,6 +170,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) { 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"); /* call gpio_close */ @@ -170,6 +192,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct { 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"); @@ -189,6 +212,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e { 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"); @@ -207,6 +231,7 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i { 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(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL"); @@ -231,6 +256,7 @@ int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { 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"); ret = peripheral_gdbus_gpio_unset_interrupted_cb(gpio); @@ -253,6 +279,7 @@ 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"); @@ -271,6 +298,7 @@ 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"); diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 6393494..dc3cbee 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -18,12 +18,19 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_i2c.h" #include "peripheral_common.h" #include "peripheral_internal.h" +#define PERIPHERAL_IO_I2C_FEATURE "http://tizen.org/feature/peripheral_io.i2c" + +#define I2C_FEATURE_UNKNOWN -1 +#define I2C_FEATURE_FALSE 0 +#define I2C_FEATURE_TRUE 1 + /* i2c_smbus_xfer read or write markers */ #define I2C_SMBUS_READ 1 #define I2C_SMBUS_WRITE 0 @@ -34,11 +41,26 @@ #define I2C_SMBUS_BYTE_DATA 2 #define I2C_SMBUS_WORD_DATA 3 +static int i2c_feature = I2C_FEATURE_UNKNOWN; + +static bool __is_feature_supported() +{ + bool feature = false; + + if (i2c_feature == I2C_FEATURE_UNKNOWN) { + system_info_get_platform_bool(PERIPHERAL_IO_I2C_FEATURE, &feature); + i2c_feature = (feature ? I2C_FEATURE_TRUE : I2C_FEATURE_FALSE); + } + + return (i2c_feature == I2C_FEATURE_TRUE ? true : false); +} + int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c) { peripheral_i2c_h handle; 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, "Invalid i2c handle"); RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -67,6 +89,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) { int ret; + 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); @@ -84,6 +107,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { int ret; + 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"); @@ -98,6 +122,7 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { int ret; + 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"); @@ -113,6 +138,7 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t int ret; uint16_t w_data, dummy = 0; + 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"); @@ -130,6 +156,7 @@ int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_ int ret; uint16_t dummy = 0; + 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_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy); @@ -144,6 +171,7 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_ int ret; uint16_t dummy = 0, data_out; + 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"); @@ -161,6 +189,7 @@ int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16 int ret; uint16_t dummy = 0; + 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_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, data, &dummy); diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 3ea42e0..70c0992 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -18,17 +18,40 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_pwm.h" #include "peripheral_common.h" #include "peripheral_internal.h" +#define PERIPHERAL_IO_PWM_FEATURE "http://tizen.org/feature/peripheral_io.pwm" + +#define PWM_FEATURE_UNKNOWN -1 +#define PWM_FEATURE_FALSE 0 +#define PWM_FEATURE_TRUE 1 + +static int pwm_feature = PWM_FEATURE_UNKNOWN; + +static bool __is_feature_supported() +{ + bool feature = false; + + if (pwm_feature == PWM_FEATURE_UNKNOWN) { + system_info_get_platform_bool(PERIPHERAL_IO_PWM_FEATURE, &feature); + pwm_feature = (feature ? PWM_FEATURE_TRUE : PWM_FEATURE_FALSE); + } + + return (pwm_feature == PWM_FEATURE_TRUE ? true : false); +} + + int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) { peripheral_pwm_h handle; 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, "Invalid pwm handle"); RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -58,6 +81,7 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) { 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"); if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0) @@ -73,6 +97,7 @@ int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) { int ret; + RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); ret = peripheral_gdbus_pwm_set_period(pwm, (int)period_ns); @@ -86,6 +111,7 @@ int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) { int ret; + RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, (int)duty_cycle_ns); @@ -99,6 +125,7 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e { int ret; + 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"); @@ -113,6 +140,7 @@ int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable) { int ret; + RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); ret = peripheral_gdbus_pwm_set_enable(pwm, enable); diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 07fefdf..f5ac28e 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -19,17 +19,39 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_spi.h" #include "peripheral_common.h" #include "peripheral_internal.h" +#define PERIPHERAL_IO_SPI_FEATURE "http://tizen.org/feature/peripheral_io.spi" + +#define SPI_FEATURE_UNKNOWN -1 +#define SPI_FEATURE_FALSE 0 +#define SPI_FEATURE_TRUE 1 + +static int spi_feature = SPI_FEATURE_UNKNOWN; + +static bool __is_feature_supported() +{ + bool feature = false; + + if (spi_feature == SPI_FEATURE_UNKNOWN) { + system_info_get_platform_bool(PERIPHERAL_IO_SPI_FEATURE, &feature); + spi_feature = (feature ? SPI_FEATURE_TRUE : SPI_FEATURE_FALSE); + } + + return (spi_feature == SPI_FEATURE_TRUE ? true : false); +} + int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi) { peripheral_spi_h handle; 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, "Invalid spi handle"); RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); @@ -59,6 +81,7 @@ int peripheral_spi_close(peripheral_spi_h spi) { 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"); ret = peripheral_gdbus_spi_close(spi); @@ -75,6 +98,7 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { int ret; + 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"); @@ -89,6 +113,7 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_ { int ret; + 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"); @@ -104,6 +129,7 @@ int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { int ret; + 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_set_bits_per_word(spi, (unsigned char)bits); @@ -117,6 +143,7 @@ int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) { int ret; + 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_set_frequency(spi, (unsigned int)freq_hz); @@ -130,6 +157,7 @@ int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length) { int ret; + 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"); @@ -144,6 +172,7 @@ int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length) { int ret; + 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"); @@ -158,6 +187,7 @@ int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxda { int ret; + 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"); diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index f90d433..7c7d4da 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -18,12 +18,33 @@ #include #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus_uart.h" #include "peripheral_common.h" #include "peripheral_internal.h" +#define PERIPHERAL_IO_UART_FEATURE "http://tizen.org/feature/peripheral_io.uart" + +#define UART_FEATURE_UNKNOWN -1 +#define UART_FEATURE_FALSE 0 +#define UART_FEATURE_TRUE 1 + +static int uart_feature = UART_FEATURE_UNKNOWN; + +static bool __is_feature_supported() +{ + bool feature = false; + + if (uart_feature == UART_FEATURE_UNKNOWN) { + system_info_get_platform_bool(PERIPHERAL_IO_UART_FEATURE, &feature); + uart_feature = (feature ? UART_FEATURE_TRUE : UART_FEATURE_FALSE); + } + + return (uart_feature == UART_FEATURE_TRUE ? true : false); +} + /** * @brief Initializes uart communication and creates uart handle. */ @@ -32,6 +53,7 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart) peripheral_uart_h handle; int ret; + RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle"); RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number"); @@ -63,6 +85,7 @@ int peripheral_uart_close(peripheral_uart_h uart) { int ret; + 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); @@ -83,6 +106,7 @@ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_r { int ret; + 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"); @@ -97,6 +121,7 @@ int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_s { int ret; + 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"); @@ -111,6 +136,7 @@ int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e { int ret; + 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"); @@ -125,6 +151,7 @@ int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_b { int ret; + 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"); @@ -143,6 +170,7 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof { int ret; + 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"); @@ -164,6 +192,7 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length) { int ret; + 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"); @@ -181,6 +210,7 @@ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length { int ret; + 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"); -- 2.7.4 From c6fb7365864887ccf0e0e2c456c3d57ff031e9bd Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 27 Sep 2017 20:43:41 +0900 Subject: [PATCH 04/16] doc: fixed an invalid feature key name. Signed-off-by: Segwon Change-Id: Ib4873df2fd591df2c6eac4bb7cca0562222bdbe0 --- doc/peripheral_io_doc.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/peripheral_io_doc.h b/doc/peripheral_io_doc.h index 8c373bf..bad2569 100644 --- a/doc/peripheral_io_doc.h +++ b/doc/peripheral_io_doc.h @@ -43,7 +43,7 @@ * @section CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE_FEATURE Realted Features * * This API is related with the following feature:\n - * - http://tizen.org/feature/peripheralio.gpio\n + * - http://tizen.org/feature/peripheral_io.gpio\n * * It is recommended to use features in your application for reliability.\n * @@ -72,7 +72,7 @@ * @section CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE_FEATURE Realted Features * * This API is related with the following feature:\n - * - http://tizen.org/feature/peripheralio.i2c\n + * - http://tizen.org/feature/peripheral_io.i2c\n * * It is recommended to use features in your application for reliability.\n * @@ -101,7 +101,7 @@ * @section CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE_FEATURE Realted Features * * This API is related with the following feature:\n - * - http://tizen.org/feature/peripheralio.spi\n + * - http://tizen.org/feature/peripheral_io.spi\n * * It is recommended to use features in your application for reliability.\n * @@ -130,7 +130,7 @@ * @section CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE_FEATURE Realted Features * * This API is related with the following feature:\n - * - http://tizen.org/feature/peripheralio.uart\n + * - http://tizen.org/feature/peripheral_io.uart\n * * It is recommended to use features in your application for reliability.\n * @@ -159,7 +159,7 @@ * @section CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE_FEATURE Realted Features * * This API is related with the following feature:\n - * - http://tizen.org/feature/peripheralio.pwm\n + * - http://tizen.org/feature/peripheral_io.pwm\n * * It is recommended to use features in your application for reliability.\n * -- 2.7.4 From 59eb4ca48a82865ea9fbeb51572f750ac15d8f6e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 10 Oct 2017 20:28:43 +0900 Subject: [PATCH 05/16] gpio: fix the bug that interrupted callback is not called - because "link" is just only the temporary iterator, it should be changed to interrupt_cb_in_list pointer. Change-Id: Ifa0f39c6e963f022fefec80f4fc1f64ffc8ad805 Signed-off-by: kibak.yoon --- src/peripheral_gpio.c | 2 +- src/peripheral_io.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 93d1231..a93bd54 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -95,7 +95,7 @@ static int __interrupted_cb_info_list_append(peripheral_gpio_h gpio, peripheral_ return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - link = g_list_append(link, cb_info); + interrupted_cb_info_list = g_list_append(interrupted_cb_info_list, cb_info); } cb_info->handle = gpio; diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml index 9b556d6..466efac 100644 --- a/src/peripheral_io.xml +++ b/src/peripheral_io.xml @@ -28,10 +28,10 @@ - - - - + + + + -- 2.7.4 From 543435fb7e505e2afb739a4d2b2f064fb508a129 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 16 Oct 2017 17:59:30 +0900 Subject: [PATCH 06/16] pio: check if return value of system_info_get_platform_bool is SYSTEM_INFO_ERROR_NONE or not Change-Id: I6515fa369ed5201af520e5956bd0a8716a0ee168 Signed-off-by: kibak.yoon --- src/peripheral_gpio.c | 5 ++++- src/peripheral_i2c.c | 5 ++++- src/peripheral_pwm.c | 5 ++++- src/peripheral_spi.c | 5 ++++- src/peripheral_uart.c | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index a93bd54..408ed0a 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -36,10 +36,13 @@ static int gpio_feature = GPIO_FEATURE_UNKNOWN; static bool __is_feature_supported() { + int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; if (gpio_feature == GPIO_FEATURE_UNKNOWN) { - system_info_get_platform_bool(PERIPHERAL_IO_GPIO_FEATURE, &feature); + ret = system_info_get_platform_bool(PERIPHERAL_IO_GPIO_FEATURE, &feature); + RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info"); + gpio_feature = (feature ? GPIO_FEATURE_TRUE : GPIO_FEATURE_FALSE); } return (gpio_feature == GPIO_FEATURE_TRUE ? true : false); diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index dc3cbee..5d32bf3 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -45,10 +45,13 @@ static int i2c_feature = I2C_FEATURE_UNKNOWN; static bool __is_feature_supported() { + int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; if (i2c_feature == I2C_FEATURE_UNKNOWN) { - system_info_get_platform_bool(PERIPHERAL_IO_I2C_FEATURE, &feature); + ret = system_info_get_platform_bool(PERIPHERAL_IO_I2C_FEATURE, &feature); + RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info"); + i2c_feature = (feature ? I2C_FEATURE_TRUE : I2C_FEATURE_FALSE); } diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 70c0992..fdd0de7 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -35,10 +35,13 @@ static int pwm_feature = PWM_FEATURE_UNKNOWN; static bool __is_feature_supported() { + int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; if (pwm_feature == PWM_FEATURE_UNKNOWN) { - system_info_get_platform_bool(PERIPHERAL_IO_PWM_FEATURE, &feature); + ret = system_info_get_platform_bool(PERIPHERAL_IO_PWM_FEATURE, &feature); + RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info"); + pwm_feature = (feature ? PWM_FEATURE_TRUE : PWM_FEATURE_FALSE); } diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index f5ac28e..34e777c 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -36,10 +36,13 @@ static int spi_feature = SPI_FEATURE_UNKNOWN; static bool __is_feature_supported() { + int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; if (spi_feature == SPI_FEATURE_UNKNOWN) { - system_info_get_platform_bool(PERIPHERAL_IO_SPI_FEATURE, &feature); + ret = system_info_get_platform_bool(PERIPHERAL_IO_SPI_FEATURE, &feature); + RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info"); + spi_feature = (feature ? SPI_FEATURE_TRUE : SPI_FEATURE_FALSE); } diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 7c7d4da..10ef561 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -35,10 +35,13 @@ static int uart_feature = UART_FEATURE_UNKNOWN; static bool __is_feature_supported() { + int ret = SYSTEM_INFO_ERROR_NONE; bool feature = false; if (uart_feature == UART_FEATURE_UNKNOWN) { - system_info_get_platform_bool(PERIPHERAL_IO_UART_FEATURE, &feature); + ret = system_info_get_platform_bool(PERIPHERAL_IO_UART_FEATURE, &feature); + RETVM_IF(ret != SYSTEM_INFO_ERROR_NONE, false, "Failed to get system info"); + uart_feature = (feature ? UART_FEATURE_TRUE : UART_FEATURE_FALSE); } -- 2.7.4 From 9ca0cbee549562738ac79c21b1470d568e5cab09 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 25 Oct 2017 15:49:54 +0900 Subject: [PATCH 07/16] doc: changed the word 'device' to the correct meaning. Change-Id: I770f16fee6e36e17c285632d5b5c8e5ef4f9bde5 Signed-off-by: Segwon --- doc/peripheral_io_doc.h | 42 +++++++++++++++++++++--------------------- include/peripheral_io.h | 32 ++++++++++++++++---------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/doc/peripheral_io_doc.h b/doc/peripheral_io_doc.h index bad2569..6741d54 100644 --- a/doc/peripheral_io_doc.h +++ b/doc/peripheral_io_doc.h @@ -17,7 +17,7 @@ /** * @ingroup CAPI_SYSTEM_FRAMEWORK * @defgroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE Peripheral IO - * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_MODULE API provides functions to make use of peripherals in the device. + * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_MODULE API provides functions to make use of peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_MODULE_HEADER Required Header * \#include @@ -31,14 +31,14 @@ /** * @ingroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE * @defgroup CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE GPIO - * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE API provides functions to control GPIO in the device. + * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE API provides functions to control GPIO peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE_HEADER Required Header * \#include * * @section CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE_OVERVIEW Overview * - * This @ref CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE API provides functions to control GPIO in the device. + * This @ref CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE API provides functions to control GPIO peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE_FEATURE Realted Features * @@ -47,10 +47,10 @@ * * It is recommended to use features in your application for reliability.\n * - * You can check if a device supports the related features for this API \n + * You can check if a IoT device supports the related features for this API \n * by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n * - * To ensure your application is only running on the device with specific features, \n + * To ensure your application is only running on the IoT device with specific features, \n * please define the features in your manifest file using the manifest editor in the SDK.\n * * More details on featuring your application can be found from Feature Element. @@ -60,14 +60,14 @@ /** * @ingroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE * @defgroup CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE I2C - * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE API provides functions to control I2C in the device. + * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE API provides functions to control I2C peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE_HEADER Required Header * \#include * * @section CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE_OVERVIEW Overview * - * This @ref CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE API provides functions to control I2C in the device. + * This @ref CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE API provides functions to control I2C peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE_FEATURE Realted Features * @@ -76,10 +76,10 @@ * * It is recommended to use features in your application for reliability.\n * - * You can check if a device supports the related features for this API \n + * You can check if a IoT device supports the related features for this API \n * by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n * - * To ensure your application is only running on the device with specific features, \n + * To ensure your application is only running on the IoT device with specific features, \n * please define the features in your manifest file using the manifest editor in the SDK.\n * * More details on featuring your application can be found from Feature Element. @@ -89,14 +89,14 @@ /** * @ingroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE * @defgroup CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE SPI - * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE API provides functions to control SPI in the device. + * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE API provides functions to control SPI peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE_HEADER Required Header * \#include * * @section CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE_OVERVIEW Overview * - * This @ref CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE API provides functions to control SPI in the device. + * This @ref CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE API provides functions to control SPI peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE_FEATURE Realted Features * @@ -105,10 +105,10 @@ * * It is recommended to use features in your application for reliability.\n * - * You can check if a device supports the related features for this API \n + * You can check if a IoT device supports the related features for this API \n * by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n * - * To ensure your application is only running on the device with specific features, \n + * To ensure your application is only running on the IoT device with specific features, \n * please define the features in your manifest file using the manifest editor in the SDK.\n * * More details on featuring your application can be found from Feature Element. @@ -118,14 +118,14 @@ /** * @ingroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE * @defgroup CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE UART - * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE API provides functions to control UART in the device. + * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE API provides functions to control UART peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE_HEADER Required Header * \#include * * @section CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE_OVERVIEW Overview * - * This @ref CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE API provides functions to control UART in the device. + * This @ref CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE API provides functions to control UART peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE_FEATURE Realted Features * @@ -134,10 +134,10 @@ * * It is recommended to use features in your application for reliability.\n * - * You can check if a device supports the related features for this API \n + * You can check if a IoT device supports the related features for this API \n * by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n * - * To ensure your application is only running on the device with specific features, \n + * To ensure your application is only running on the IoT device with specific features, \n * please define the features in your manifest file using the manifest editor in the SDK.\n * * More details on featuring your application can be found from Feature Element. @@ -147,14 +147,14 @@ /** * @ingroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE * @defgroup CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE PWM - * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE API provides functions to control PWM in the device. + * @brief The @ref CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE API provides functions to control PWM peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE_HEADER Required Header * \#include * * @section CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE_OVERVIEW Overview * - * This @ref CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE API provides functions to control PWM in the device. + * This @ref CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE API provides functions to control PWM peripherals connected to the IoT device. * * @section CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE_FEATURE Realted Features * @@ -163,10 +163,10 @@ * * It is recommended to use features in your application for reliability.\n * - * You can check if a device supports the related features for this API \n + * You can check if a IoT device supports the related features for this API \n * by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n * - * To ensure your application is only running on the device with specific features, \n + * To ensure your application is only running on the IoT device with specific features, \n * please define the features in your manifest file using the manifest editor in the SDK.\n * * More details on featuring your application can be found from Feature Element. diff --git a/include/peripheral_io.h b/include/peripheral_io.h index 7ff48d4..bb11f34 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -491,7 +491,7 @@ int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16 */ /** - * @brief The handle of the PWM device. + * @brief The handle of the PWM peripherals. * @since_tizen 4.0 */ typedef struct _peripheral_pwm_s *peripheral_pwm_h; @@ -650,7 +650,7 @@ int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enabled); */ /** - * @brief The handle to the UART device. + * @brief The handle to the UART peripherals. * @since_tizen 4.0 */ typedef struct _peripheral_uart_s *peripheral_uart_h; @@ -783,7 +783,7 @@ int peripheral_uart_close(peripheral_uart_h uart); * @privilege http://tizen.org/privilege/peripheralio * * @param[in] uart The UART handle - * @param[in] baud Baud rate of the UART device + * @param[in] baud Baud rate of the UART slave device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -806,7 +806,7 @@ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_r * @privilege http://tizen.org/privilege/peripheralio * * @param[in] uart The UART handle - * @param[in] byte_size Byte size of the UART device + * @param[in] byte_size Byte size of the UART slave device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -829,7 +829,7 @@ int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_s * @privilege http://tizen.org/privilege/peripheralio * * @param[in] uart The UART handle - * @param[in] parity Parity bit of the UART device + * @param[in] parity Parity bit of the UART slave device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -852,7 +852,7 @@ int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e * @privilege http://tizen.org/privilege/peripheralio * * @param[in] uart The UART handle - * @param[in] stop_bits Stop bits of the UART device + * @param[in] stop_bits Stop bits of the UART slave device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -952,7 +952,7 @@ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length */ /** - * @brief The handle of a SPI device. + * @brief The handle of a SPI peripherals. * @since_tizen 4.0 */ typedef struct _peripheral_spi_s *peripheral_spi_h; @@ -987,7 +987,7 @@ typedef enum { * * @param[in] bus The SPI bus number * @param[in] cs The SPI chip select number - * @param[out] spi The SPI device handle + * @param[out] spi The SPI slave device handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -1011,7 +1011,7 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi); * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful @@ -1033,7 +1033,7 @@ int peripheral_spi_close(peripheral_spi_h spi); * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[in] mode The SPI transfer mode * * @return 0 on success, otherwise a negative error value @@ -1056,7 +1056,7 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[in] bit_order The transfer bit order * * @return 0 on success, otherwise a negative error value @@ -1079,7 +1079,7 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_ * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[in] bits The number of bits per word (in bits) * * @return 0 on success, otherwise a negative error value @@ -1101,7 +1101,7 @@ int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits); * @privilege http://tizen.org/privilege/peripheralio * @remarks The frequencies supported are board dependent. * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[in] freq_hz Frequency to set (in Hz) * * @return 0 on success, otherwise a negative error value @@ -1122,7 +1122,7 @@ int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz); * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[out] data The data buffer to read * @param[in] length The size of data buffer (in bytes) * @@ -1146,7 +1146,7 @@ int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length); * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[in] data The data buffer to write * @param[in] length The size of data buffer (in bytes) * @@ -1170,7 +1170,7 @@ int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length); * @privlevel platform * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The SPI device handle + * @param[in] spi The SPI slave device handle * @param[in] txdata The data buffer to write * @param[out] rxdata The data buffer to read * @param[in] length The size of txdata and rxdata buffer (in bytes) -- 2.7.4 From 82f0d4234bc1b29c6929ef7a68b27bd6b63022b1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Fri, 27 Oct 2017 00:01:36 +0900 Subject: [PATCH 08/16] utc: added the local utc module. - generated with the new 'capi-system-peripheral-io-test' rpm. Signed-off-by: Segwon Change-Id: Ie0e310e0ee0b6a3ac1574181b4d41e34e458e3c2 --- CMakeLists.txt | 2 + packaging/capi-system-peripheral-io.spec | 14 + test/CMakeLists.txt | 29 + test/include/test_peripheral_gpio.h | 53 ++ test/include/test_peripheral_i2c.h | 45 + test/include/test_peripheral_pwm.h | 41 + test/include/test_peripheral_spi.h | 56 ++ test/include/test_peripheral_uart.h | 82 ++ test/peripheral-io-test.c | 528 +++++++++++ test/src/test_peripheral_gpio.c | 824 ++++++++++++++++ test/src/test_peripheral_i2c.c | 541 +++++++++++ test/src/test_peripheral_pwm.c | 440 +++++++++ test/src/test_peripheral_spi.c | 855 +++++++++++++++++ test/src/test_peripheral_uart.c | 1525 ++++++++++++++++++++++++++++++ 14 files changed, 5035 insertions(+) create mode 100644 test/CMakeLists.txt create mode 100644 test/include/test_peripheral_gpio.h create mode 100644 test/include/test_peripheral_i2c.h create mode 100644 test/include/test_peripheral_pwm.h create mode 100644 test/include/test_peripheral_spi.h create mode 100644 test/include/test_peripheral_uart.h create mode 100644 test/peripheral-io-test.c create mode 100644 test/src/test_peripheral_gpio.c create mode 100644 test/src/test_peripheral_i2c.c create mode 100644 test/src/test_peripheral_pwm.c create mode 100644 test/src/test_peripheral_spi.c create mode 100644 test/src/test_peripheral_uart.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c7ae260..55ed4af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,3 +83,5 @@ CONFIGURE_FILE( @ONLY ) INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${libdir}/pkgconfig) + +ADD_SUBDIRECTORY(test) diff --git a/packaging/capi-system-peripheral-io.spec b/packaging/capi-system-peripheral-io.spec index 2f105bc..4a062ee 100644 --- a/packaging/capi-system-peripheral-io.spec +++ b/packaging/capi-system-peripheral-io.spec @@ -28,6 +28,14 @@ Requires: %{name} = %{version}-%{release} %description devel Tizen Peripheral Input & Output library (devel) +%package test +Summary: Tizen Peripheral Input & Output Test Programs (test) +Group: System & System Tools/Testing +Requires: %{name} = %{version}-%{release} + +%description test +Tizen Peripheral Input & Output Test Programs (test) + %prep %setup -q cp %{SOURCE1} ./%{name}.manifest @@ -55,3 +63,9 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %{_includedir}/*.h %{_libdir}/lib%{name}.so %{_libdir}/pkgconfig/%{name}.pc + +%files test +%manifest %{name}.manifest +%defattr(-,root,root,-) +%{_bindir}/peripheral-io-test +%license LICENSE.APLv2 \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..48799da --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,29 @@ +PROJECT(peripheral-io-test C) +SET(fw_test "${fw_name}-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED capi-system-info) + +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH() + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +SET(UTC_INCLUDE_DIR ./include) +INCLUDE_DIRECTORIES(${UTC_INCLUDE_DIR}) + +AUX_SOURCE_DIRECTORY(src test_sources) +FOREACH(src ${test_sources}) + SET(test_src ${test_src} ${src}) +ENDFOREACH() + +AUX_SOURCE_DIRECTORY(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + ADD_EXECUTABLE(${src_name} ${src} ${test_src}) + TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) +ENDFOREACH() + +INSTALL(TARGETS peripheral-io-test RUNTIME DESTINATION bin/) \ No newline at end of file diff --git a/test/include/test_peripheral_gpio.h b/test/include/test_peripheral_gpio.h new file mode 100644 index 0000000..dc747fb --- /dev/null +++ b/test/include/test_peripheral_gpio.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TEST_PERIPHERAL_GPIO_H__ +#define __TEST_PERIPHERAL_GPIO_H__ + +int test_peripheral_io_gpio_initialize(char *model, bool feature); + +int test_peripheral_io_gpio_peripheral_gpio_open_p(void); +int test_peripheral_io_gpio_peripheral_gpio_open_n1(void); +int test_peripheral_io_gpio_peripheral_gpio_open_n2(void); +int test_peripheral_io_gpio_peripheral_gpio_close_p(void); +int test_peripheral_io_gpio_peripheral_gpio_close_n(void); +int test_peripheral_io_gpio_peripheral_gpio_set_direction_p1(void); +int test_peripheral_io_gpio_peripheral_gpio_set_direction_p2(void); +int test_peripheral_io_gpio_peripheral_gpio_set_direction_p3(void); +int test_peripheral_io_gpio_peripheral_gpio_set_direction_n1(void); +int test_peripheral_io_gpio_peripheral_gpio_set_direction_n2(void); +int test_peripheral_io_gpio_peripheral_gpio_set_direction_n3(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2(void); +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3(void); +int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p(void); +int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1(void); +int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2(void); +int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1(void); +int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2(void); +int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n(void); +int test_peripheral_io_gpio_peripheral_gpio_read_p(void); +int test_peripheral_io_gpio_peripheral_gpio_read_n1(void); +int test_peripheral_io_gpio_peripheral_gpio_read_n2(void); +int test_peripheral_io_gpio_peripheral_gpio_write_p(void); +int test_peripheral_io_gpio_peripheral_gpio_write_n1(void); +int test_peripheral_io_gpio_peripheral_gpio_write_n2(void); + +#endif /* __TEST_PERIPHERAL_GPIO_H__ */ \ No newline at end of file diff --git a/test/include/test_peripheral_i2c.h b/test/include/test_peripheral_i2c.h new file mode 100644 index 0000000..0c032ae --- /dev/null +++ b/test/include/test_peripheral_i2c.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TEST_PERIPHERAL_I2C_H__ +#define __TEST_PERIPHERAL_I2C_H__ + +int test_peripheral_io_i2c_initialize(char *model, bool feature); + +int test_peripheral_io_i2c_peripheral_i2c_open_p(void); +int test_peripheral_io_i2c_peripheral_i2c_open_n1(void); +int test_peripheral_io_i2c_peripheral_i2c_open_n2(void); +int test_peripheral_io_i2c_peripheral_i2c_open_n3(void); +int test_peripheral_io_i2c_peripheral_i2c_close_p(void); +int test_peripheral_io_i2c_peripheral_i2c_close_n(void); +int test_peripheral_io_i2c_peripheral_i2c_read_p(void); +int test_peripheral_io_i2c_peripheral_i2c_read_n1(void); +int test_peripheral_io_i2c_peripheral_i2c_read_n2(void); +int test_peripheral_io_i2c_peripheral_i2c_write_p(void); +int test_peripheral_io_i2c_peripheral_i2c_write_n1(void); +int test_peripheral_io_i2c_peripheral_i2c_write_n2(void); +int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_p(void); +int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n1(void); +int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n2(void); +int test_peripheral_io_i2c_peripheral_i2c_write_register_byte_p(void); +int test_peripheral_io_i2c_peripheral_i2c_write_register_byte_n(void); +int test_peripheral_io_i2c_peripheral_i2c_read_register_word_p(void); +int test_peripheral_io_i2c_peripheral_i2c_read_register_word_n1(void); +int test_peripheral_io_i2c_peripheral_i2c_read_register_word_n2(void); +int test_peripheral_io_i2c_peripheral_i2c_write_register_word_p(void); +int test_peripheral_io_i2c_peripheral_i2c_write_register_word_n(void); + +#endif /* __TEST_PERIPHERAL_I2C_H__ */ \ No newline at end of file diff --git a/test/include/test_peripheral_pwm.h b/test/include/test_peripheral_pwm.h new file mode 100644 index 0000000..a7113e9 --- /dev/null +++ b/test/include/test_peripheral_pwm.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TEST_PERIPHERAL_PWM_H__ +#define __TEST_PERIPHERAL_PWM_H__ + +int test_peripheral_io_pwm_initialize(char *model, bool feature); + +int test_peripheral_io_pwm_peripheral_pwm_open_p(void); +int test_peripheral_io_pwm_peripheral_pwm_open_n1(void); +int test_peripheral_io_pwm_peripheral_pwm_open_n2(void); +int test_peripheral_io_pwm_peripheral_pwm_open_n3(void); +int test_peripheral_io_pwm_peripheral_pwm_close_p(void); +int test_peripheral_io_pwm_peripheral_pwm_close_n(void); +int test_peripheral_io_pwm_peripheral_pwm_set_period_p(void); +int test_peripheral_io_pwm_peripheral_pwm_set_period_n(void); +int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_p(void); +int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_n(void); +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p1(void); +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p2(void); +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n1(void); +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n2(void); +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n3(void); +int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p1(void); +int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p2(void); +int test_peripheral_io_pwm_peripheral_pwm_set_enabled_n(void); + +#endif /* __TEST_PERIPHERAL_PWM_H__ */ \ No newline at end of file diff --git a/test/include/test_peripheral_spi.h b/test/include/test_peripheral_spi.h new file mode 100644 index 0000000..c69826f --- /dev/null +++ b/test/include/test_peripheral_spi.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TEST_PERIPHERAL_SPI_H__ +#define __TEST_PERIPHERAL_SPI_H__ + +int test_peripheral_io_spi_initialize(char *model, bool feature); + +int test_peripheral_io_spi_peripheral_spi_open_p(void); +int test_peripheral_io_spi_peripheral_spi_open_n1(void); +int test_peripheral_io_spi_peripheral_spi_open_n2(void); +int test_peripheral_io_spi_peripheral_spi_open_n3(void); +int test_peripheral_io_spi_peripheral_spi_close_p(void); +int test_peripheral_io_spi_peripheral_spi_close_n(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_p1(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_p2(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_p3(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_p4(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_n1(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_n2(void); +int test_peripheral_io_spi_peripheral_spi_set_mode_n3(void); +int test_peripheral_io_spi_peripheral_spi_set_bit_order_p1(void); +int test_peripheral_io_spi_peripheral_spi_set_bit_order_p2(void); +int test_peripheral_io_spi_peripheral_spi_set_bit_order_n1(void); +int test_peripheral_io_spi_peripheral_spi_set_bit_order_n2(void); +int test_peripheral_io_spi_peripheral_spi_set_bit_order_n3(void); +int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_p(void); +int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n1(void); +int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n2(void); +int test_peripheral_io_spi_peripheral_spi_set_frequency_p(void); +int test_peripheral_io_spi_peripheral_spi_set_frequency_n(void); +int test_peripheral_io_spi_peripheral_spi_read_p(void); +int test_peripheral_io_spi_peripheral_spi_read_n1(void); +int test_peripheral_io_spi_peripheral_spi_read_n2(void); +int test_peripheral_io_spi_peripheral_spi_write_p(void); +int test_peripheral_io_spi_peripheral_spi_write_n1(void); +int test_peripheral_io_spi_peripheral_spi_write_n2(void); +int test_peripheral_io_spi_peripheral_spi_transfer_p(void); +int test_peripheral_io_spi_peripheral_spi_transfer_n1(void); +int test_peripheral_io_spi_peripheral_spi_transfer_n2(void); +int test_peripheral_io_spi_peripheral_spi_transfer_n3(void); + +#endif /* __TEST_PERIPHERAL_SPI_H__ */ \ No newline at end of file diff --git a/test/include/test_peripheral_uart.h b/test/include/test_peripheral_uart.h new file mode 100644 index 0000000..89e2b33 --- /dev/null +++ b/test/include/test_peripheral_uart.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TEST_PERIPHERAL_UART_H__ +#define __TEST_PERIPHERAL_UART_H__ + +int test_peripheral_io_uart_initialize(char *model, bool feature); + +int test_peripheral_io_uart_peripheral_uart_open_p(void); +int test_peripheral_io_uart_peripheral_uart_open_n1(void); +int test_peripheral_io_uart_peripheral_uart_open_n2(void); +int test_peripheral_io_uart_peripheral_uart_close_p(void); +int test_peripheral_io_uart_peripheral_uart_close_n(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p1(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p2(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p3(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p4(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p5(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p6(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p7(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p8(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p9(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p10(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p11(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p12(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p13(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p14(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p15(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p16(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p17(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p18(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n1(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n2(void); +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n3(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p1(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p2(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p3(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p4(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_n1(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_n2(void); +int test_peripheral_io_uart_peripheral_uart_set_byte_size_n3(void); +int test_peripheral_io_uart_peripheral_uart_set_parity_p1(void); +int test_peripheral_io_uart_peripheral_uart_set_parity_p2(void); +int test_peripheral_io_uart_peripheral_uart_set_parity_p3(void); +int test_peripheral_io_uart_peripheral_uart_set_parity_n1(void); +int test_peripheral_io_uart_peripheral_uart_set_parity_n2(void); +int test_peripheral_io_uart_peripheral_uart_set_parity_n3(void); +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_p1(void); +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_p2(void); +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n1(void); +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n2(void); +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n3(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p1(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p2(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p3(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p4(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n1(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n2(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n3(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n4(void); +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n5(void); +int test_peripheral_io_uart_peripheral_uart_read_p(void); +int test_peripheral_io_uart_peripheral_uart_read_n1(void); +int test_peripheral_io_uart_peripheral_uart_read_n2(void); +int test_peripheral_io_uart_peripheral_uart_write_p(void); +int test_peripheral_io_uart_peripheral_uart_write_n1(void); +int test_peripheral_io_uart_peripheral_uart_write_n2(void); + +#endif /* __TEST_PERIPHERAL_UART_H__ */ \ No newline at end of file diff --git a/test/peripheral-io-test.c b/test/peripheral-io-test.c new file mode 100644 index 0000000..21062a1 --- /dev/null +++ b/test/peripheral-io-test.c @@ -0,0 +1,528 @@ + +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "peripheral_io.h" +#include "test_peripheral_gpio.h" +#include "test_peripheral_i2c.h" +#include "test_peripheral_pwm.h" +#include "test_peripheral_uart.h" +#include "test_peripheral_spi.h" + +#define KEY_SYSTEM_MODEL_NAME "http://tizen.org/system/model_name" +#define KEY_FEATURE_PERIPHERAL_IO_GPIO "http://tizen.org/feature/peripheral_io.gpio" +#define KEY_FEATURE_PERIPHERAL_IO_I2C "http://tizen.org/feature/peripheral_io.i2c" +#define KEY_FEATURE_PERIPHERAL_IO_PWM "http://tizen.org/feature/peripheral_io.pwm" +#define KEY_FEATURE_PERIPHERAL_IO_UART "http://tizen.org/feature/peripheral_io.uart" +#define KEY_FEATURE_PERIPHERAL_IO_SPI "http://tizen.org/feature/peripheral_io.spi" + +static int fail_count = 0; +static int pass_count = 0; + +static void __error_check(int ret, char *name) +{ + if (ret != PERIPHERAL_ERROR_NONE) { + printf("[FAIL] %s\n", name); + fail_count++; + } else { + printf("[PASS] %s\n", name); + pass_count++; + } +} + +static int __get_model_name(char **model_name) +{ + int ret = SYSTEM_INFO_ERROR_NONE; + 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 0; +} + +static int __get_feature(const char *key, bool *feature) +{ + int ret = SYSTEM_INFO_ERROR_NONE; + 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 0; +} + +static int __test_peripheral_init() +{ + int ret = 0; + + char *model_name = NULL; + bool feature = false; + + ret = __get_model_name(&model_name); + if (ret != 0) return ret; + + ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_GPIO, &feature); + if (ret != 0) return ret; + ret = test_peripheral_io_gpio_initialize(model_name, feature); + if (ret != 0) return ret; + + ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_I2C, &feature); + if (ret != 0) return ret; + ret = test_peripheral_io_i2c_initialize(model_name, feature); + if (ret != 0) return ret; + + ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_PWM, &feature); + if (ret != 0) return ret; + ret = test_peripheral_io_pwm_initialize(model_name, feature); + if (ret != 0) return ret; + + ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_UART, &feature); + if (ret != 0) return ret; + ret = test_peripheral_io_uart_initialize(model_name, feature); + if (ret != 0) return ret; + + ret = __get_feature(KEY_FEATURE_PERIPHERAL_IO_SPI, &feature); + if (ret != 0) return ret; + ret = test_peripheral_io_spi_initialize(model_name, feature); + if (ret != 0) return ret; + + return ret; +} + +static void __test_peripheral_gpio_run() +{ + int ret = PERIPHERAL_ERROR_NONE; + + ret = test_peripheral_io_gpio_peripheral_gpio_open_p(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_open_p"); + ret = test_peripheral_io_gpio_peripheral_gpio_open_n1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_open_n1"); + ret = test_peripheral_io_gpio_peripheral_gpio_open_n2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_open_n2"); + ret = test_peripheral_io_gpio_peripheral_gpio_close_p(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_close_p"); + ret = test_peripheral_io_gpio_peripheral_gpio_close_n(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_close_n"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_direction_p1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_direction_p1"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_direction_p2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_direction_p2"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_direction_p3(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_direction_p3"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_direction_n1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_direction_n1"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_direction_n2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_direction_n2"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_direction_n3(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_direction_n3"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1"); + ret = test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2"); + ret = test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1"); + ret = test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2"); + ret = test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n"); + ret = test_peripheral_io_gpio_peripheral_gpio_read_p(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_read_p"); + ret = test_peripheral_io_gpio_peripheral_gpio_read_n1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_read_n1"); + ret = test_peripheral_io_gpio_peripheral_gpio_read_n2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_read_n2"); + ret = test_peripheral_io_gpio_peripheral_gpio_write_p(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_write_p"); + ret = test_peripheral_io_gpio_peripheral_gpio_write_n1(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_write_n1"); + ret = test_peripheral_io_gpio_peripheral_gpio_write_n2(); + __error_check(ret, "test_peripheral_io_gpio_peripheral_gpio_write_n2"); +} + +static void __test_peripheral_i2c_run() +{ + int ret = PERIPHERAL_ERROR_NONE; + + ret = test_peripheral_io_i2c_peripheral_i2c_open_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_open_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_open_n1(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_open_n1"); + ret = test_peripheral_io_i2c_peripheral_i2c_open_n2(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_open_n2"); + ret = test_peripheral_io_i2c_peripheral_i2c_open_n3(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_open_n3"); + ret = test_peripheral_io_i2c_peripheral_i2c_close_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_close_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_close_n(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_close_n"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_n1(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_n1"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_n2(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_n2"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_n1(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_n1"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_n2(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_n2"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_register_byte_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_register_byte_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n1(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n1"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n2(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n2"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_register_byte_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_register_byte_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_register_byte_n(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_register_byte_n"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_register_word_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_register_word_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_register_word_n1(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_register_word_n1"); + ret = test_peripheral_io_i2c_peripheral_i2c_read_register_word_n2(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_read_register_word_n2"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_register_word_p(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_register_word_p"); + ret = test_peripheral_io_i2c_peripheral_i2c_write_register_word_n(); + __error_check(ret, "test_peripheral_io_i2c_peripheral_i2c_write_register_word_n"); +} + +static void __test_peripheral_pwm_run() +{ + int ret = PERIPHERAL_ERROR_NONE; + + ret = test_peripheral_io_pwm_peripheral_pwm_open_p(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_open_p"); + ret = test_peripheral_io_pwm_peripheral_pwm_open_n1(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_open_n1"); + ret = test_peripheral_io_pwm_peripheral_pwm_open_n2(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_open_n2"); + ret = test_peripheral_io_pwm_peripheral_pwm_open_n3(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_open_n3"); + ret = test_peripheral_io_pwm_peripheral_pwm_close_p(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_close_p"); + ret = test_peripheral_io_pwm_peripheral_pwm_close_n(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_close_n"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_period_p(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_period_p"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_period_n(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_period_n"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_p(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_p"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_n(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_n"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_polarity_p1(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_polarity_p1"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_polarity_p2(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_polarity_p2"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_polarity_n1(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_polarity_n1"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_polarity_n2(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_polarity_n2"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_polarity_n3(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_polarity_n3"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_enabled_p1(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_enabled_p1"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_enabled_p2(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_enabled_p2"); + ret = test_peripheral_io_pwm_peripheral_pwm_set_enabled_n(); + __error_check(ret, "test_peripheral_io_pwm_peripheral_pwm_set_enabled_n"); +} + +static void __test_peripheral_uart_run() +{ + int ret = PERIPHERAL_ERROR_NONE; + + ret = test_peripheral_io_uart_peripheral_uart_open_p(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_open_p"); + ret = test_peripheral_io_uart_peripheral_uart_open_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_open_n1"); + ret = test_peripheral_io_uart_peripheral_uart_open_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_open_n2"); + ret = test_peripheral_io_uart_peripheral_uart_close_p(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_close_p"); + ret = test_peripheral_io_uart_peripheral_uart_close_n(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_close_n"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p1"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p2"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p3"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p4(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p4"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p5(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p5"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p6(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p6"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p7(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p7"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p8(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p8"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p9(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p9"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p10(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p10"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p11(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p11"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p12(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p12"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p13(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p13"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p14(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p14"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p15(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p15"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p16(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p16"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p17(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p17"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_p18(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_p18"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_n1"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_n2"); + ret = test_peripheral_io_uart_peripheral_uart_set_baud_rate_n3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_baud_rate_n3"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_p1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_p1"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_p2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_p2"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_p3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_p3"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_p4(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_p4"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_n1"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_n2"); + ret = test_peripheral_io_uart_peripheral_uart_set_byte_size_n3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_byte_size_n3"); + ret = test_peripheral_io_uart_peripheral_uart_set_parity_p1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_parity_p1"); + ret = test_peripheral_io_uart_peripheral_uart_set_parity_p2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_parity_p2"); + ret = test_peripheral_io_uart_peripheral_uart_set_parity_p3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_parity_p3"); + ret = test_peripheral_io_uart_peripheral_uart_set_parity_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_parity_n1"); + ret = test_peripheral_io_uart_peripheral_uart_set_parity_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_parity_n2"); + ret = test_peripheral_io_uart_peripheral_uart_set_parity_n3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_parity_n3"); + ret = test_peripheral_io_uart_peripheral_uart_set_stop_bits_p1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_stop_bits_p1"); + ret = test_peripheral_io_uart_peripheral_uart_set_stop_bits_p2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_stop_bits_p2"); + ret = test_peripheral_io_uart_peripheral_uart_set_stop_bits_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_stop_bits_n1"); + ret = test_peripheral_io_uart_peripheral_uart_set_stop_bits_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_stop_bits_n2"); + ret = test_peripheral_io_uart_peripheral_uart_set_stop_bits_n3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_stop_bits_n3"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_p1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_p1"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_p2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_p2"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_p3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_p3"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_p4(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_p4"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_n1"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_n2"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_n3(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_n3"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_n4(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_n4"); + ret = test_peripheral_io_uart_peripheral_uart_set_flow_control_n5(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_set_flow_control_n5"); + ret = test_peripheral_io_uart_peripheral_uart_read_p(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_read_p"); + ret = test_peripheral_io_uart_peripheral_uart_read_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_read_n1"); + ret = test_peripheral_io_uart_peripheral_uart_read_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_read_n2"); + ret = test_peripheral_io_uart_peripheral_uart_write_p(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_write_p"); + ret = test_peripheral_io_uart_peripheral_uart_write_n1(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_write_n1"); + ret = test_peripheral_io_uart_peripheral_uart_write_n2(); + __error_check(ret, "test_peripheral_io_uart_peripheral_uart_write_n2"); +} + +static void __test_peripheral_spi_run() +{ + int ret = PERIPHERAL_ERROR_NONE; + + ret = test_peripheral_io_spi_peripheral_spi_open_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_open_p"); + ret = test_peripheral_io_spi_peripheral_spi_open_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_open_n1"); + ret = test_peripheral_io_spi_peripheral_spi_open_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_open_n2"); + ret = test_peripheral_io_spi_peripheral_spi_open_n3(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_open_n3"); + ret = test_peripheral_io_spi_peripheral_spi_close_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_close_p"); + ret = test_peripheral_io_spi_peripheral_spi_close_n(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_close_n"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_p1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_p1"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_p2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_p2"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_p3(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_p3"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_p4(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_p4"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_n1"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_n2"); + ret = test_peripheral_io_spi_peripheral_spi_set_mode_n3(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_mode_n3"); + ret = test_peripheral_io_spi_peripheral_spi_set_bit_order_p1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bit_order_p1"); + ret = test_peripheral_io_spi_peripheral_spi_set_bit_order_p2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bit_order_p2"); + ret = test_peripheral_io_spi_peripheral_spi_set_bit_order_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bit_order_n1"); + ret = test_peripheral_io_spi_peripheral_spi_set_bit_order_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bit_order_n2"); + ret = test_peripheral_io_spi_peripheral_spi_set_bit_order_n3(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bit_order_n3"); + ret = test_peripheral_io_spi_peripheral_spi_set_bits_per_word_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bits_per_word_p"); + ret = test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n1"); + ret = test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n2"); + ret = test_peripheral_io_spi_peripheral_spi_set_frequency_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_frequency_p"); + ret = test_peripheral_io_spi_peripheral_spi_set_frequency_n(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_set_frequency_n"); + ret = test_peripheral_io_spi_peripheral_spi_read_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_read_p"); + ret = test_peripheral_io_spi_peripheral_spi_read_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_read_n1"); + ret = test_peripheral_io_spi_peripheral_spi_read_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_read_n2"); + ret = test_peripheral_io_spi_peripheral_spi_write_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_write_p"); + ret = test_peripheral_io_spi_peripheral_spi_write_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_write_n1"); + ret = test_peripheral_io_spi_peripheral_spi_write_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_write_n2"); + ret = test_peripheral_io_spi_peripheral_spi_transfer_p(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_transfer_p"); + ret = test_peripheral_io_spi_peripheral_spi_transfer_n1(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_transfer_n1"); + ret = test_peripheral_io_spi_peripheral_spi_transfer_n2(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_transfer_n2"); + ret = test_peripheral_io_spi_peripheral_spi_transfer_n3(); + __error_check(ret, "test_peripheral_io_spi_peripheral_spi_transfer_n3"); +} + +int main(int argc, char **argv) +{ + int ret; + + int menu; + + printf("\n\n\n*** Peripheral-IO API Test (UTC) ***"); + + while (1) { + + printf("\n\n******************************************************************\n"); + printf("* *\n"); + printf("* MENU: 1.All 2.GPIO 3.I2C 4.PWM 5.UART 6.SPI 7.Exit *\n"); + printf("* *\n"); + printf("******************************************************************\n"); + printf(" Input Menu : "); + + if (scanf("%d", &menu) < 0) return -1; + + printf("\n\n"); + + fail_count = 0; + pass_count = 0; + + ret = __test_peripheral_init(); + if (ret != 0) { + printf("[Message] Failed test init...\n\n"); + return -1; + } + + switch (menu) { + case 1: + __test_peripheral_gpio_run(); + __test_peripheral_i2c_run(); + __test_peripheral_pwm_run(); + __test_peripheral_uart_run(); + break; + case 2: + __test_peripheral_gpio_run(); + break; + case 3: + __test_peripheral_i2c_run(); + break; + case 4: + __test_peripheral_pwm_run(); + break; + case 5: + __test_peripheral_uart_run(); + break; + case 6: + __test_peripheral_spi_run(); + break; + case 7: + printf("[Message] Close the Peripheral-IO API local Test...\n\n"); + return 0; + default: + printf("[Message] Input is wrong...\n\n"); + return -1; + } + + printf("\n\nTotal : %d, Pass : %d, Fail : %d\n", pass_count + fail_count, pass_count, fail_count); + + } + + return -1; +} \ No newline at end of file diff --git a/test/src/test_peripheral_gpio.c b/test/src/test_peripheral_gpio.c new file mode 100644 index 0000000..9c594ff --- /dev/null +++ b/test/src/test_peripheral_gpio.c @@ -0,0 +1,824 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test_peripheral_gpio.h" + +#define GPIO_PIN_RPI3 26 +#define GPIO_PIN_ARTIK530 128 +#define GPIO_PIN_INVALID -99 + +static bool g_feature = false; +static int pin; + +int test_peripheral_io_gpio_initialize(char *model, bool feature) +{ + g_feature = feature; + + if (!strcmp(model, "rpi3")) + pin = GPIO_PIN_RPI3; + else if (!strcmp(model, "artik")) + pin = GPIO_PIN_ARTIK530; + else + return -1; + return 0; +} + +int test_peripheral_io_gpio_peripheral_gpio_open_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_open_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_gpio_open(pin, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_open_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_close_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_close_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_gpio_close(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_close(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_direction_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_direction_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_direction_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_direction_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_direction_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_direction_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +static void gpio_interrupted_cb(peripheral_gpio_h gpio_h, peripheral_error_e error, void *user_data) +{ + // interrupted callback +} + +int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p(void) +{ + // see the gpio_interrupted_cb(); + + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + 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; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + 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; + } + + 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; + } + + ret = peripheral_gpio_unset_interrupted_cb(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_unset_interrupted_cb(gpio_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_unset_interrupted_cb(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_unset_interrupted_cb(gpio_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_gpio_unset_interrupted_cb(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_gpio_unset_interrupted_cb(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_unset_interrupted_cb(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_read_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + uint32_t value; + + if (g_feature == false) { + ret = peripheral_gpio_read(gpio_h, &value); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_read(gpio_h, &value); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_read_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint32_t value; + + if (g_feature == false) { + ret = peripheral_gpio_read(NULL, &value); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_read(NULL, &value); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_read_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + if (g_feature == false) { + ret = peripheral_gpio_read(gpio_h, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_read(gpio_h, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_write_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + uint32_t value = 1; + + if (g_feature == false) { + ret = peripheral_gpio_write(gpio_h, value); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_write(gpio_h, value); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_write_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint32_t value = 1; + + if (g_feature == false) { + ret = peripheral_gpio_write(NULL, value); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_write(NULL, value); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_gpio_peripheral_gpio_write_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_gpio_h gpio_h = NULL; + + uint32_t value = 2; + + if (g_feature == false) { + ret = peripheral_gpio_write(gpio_h, value); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_gpio_open(pin, &gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_gpio_write(gpio_h, value); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) { + peripheral_gpio_close(gpio_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_gpio_close(gpio_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} diff --git a/test/src/test_peripheral_i2c.c b/test/src/test_peripheral_i2c.c new file mode 100644 index 0000000..a9a81ee --- /dev/null +++ b/test/src/test_peripheral_i2c.c @@ -0,0 +1,541 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test_peripheral_i2c.h" + +#define I2C_BUS 4 +#define I2C_BUS_INVALID -99 +#define I2C_ADDRESS 0x39 +#define I2C_ADDRESS_INVALID -99 +#define I2C_BUFFER_LEN 10 +#define I2C_BUFFER_VALUE 0x00 +#define I2C_REGISTER 0x00 + +static bool g_feature = true; +static int bus; +static int address; + +int test_peripheral_io_i2c_initialize(char *model, bool feature) +{ + g_feature = feature; + + if ((!strcmp(model, "rpi3")) || (!strcmp(model, "artik"))) + bus = I2C_BUS; + else + return -1; + + address = I2C_ADDRESS; + + return 0; +} + +int test_peripheral_io_i2c_peripheral_i2c_open_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + if (g_feature == false) { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_open_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_i2c_open(bus, address, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_open_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + if (g_feature == false) { + ret = peripheral_i2c_open(I2C_BUS_INVALID, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(I2C_BUS_INVALID, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_open_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + if (g_feature == false) { + ret = peripheral_i2c_open(bus, I2C_ADDRESS_INVALID, &i2c_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, I2C_ADDRESS_INVALID, &i2c_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_close_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + if (g_feature == false) { + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_close_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_i2c_close(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_close(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + uint8_t buf[I2C_BUFFER_LEN]; + + if (g_feature == false) { + ret = peripheral_i2c_read(i2c_h, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_i2c_read(i2c_h, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_i2c_close(i2c_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t buf[I2C_BUFFER_LEN]; + + if (g_feature == false) { + ret = peripheral_i2c_read(NULL, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_read(NULL, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + if (g_feature == false) { + ret = peripheral_i2c_read(i2c_h, NULL, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_write_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + unsigned char buf[I2C_BUFFER_LEN] = {I2C_BUFFER_VALUE, }; + + if (g_feature == false) { + ret = peripheral_i2c_write(i2c_h, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_i2c_write(i2c_h, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_i2c_close(i2c_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_write_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + unsigned char buf[I2C_BUFFER_LEN] = {I2C_BUFFER_VALUE, }; + + if (g_feature == false) { + ret = peripheral_i2c_write(NULL, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_write(NULL, buf, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_write_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + if (g_feature == false) { + ret = peripheral_i2c_write(i2c_h, NULL, I2C_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + uint8_t data; + + 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; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t data; + + if (g_feature == false) { + ret = peripheral_i2c_read_register_byte(NULL, I2C_REGISTER, &data); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_read_register_byte(NULL, I2C_REGISTER, &data); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + + +int test_peripheral_io_i2c_peripheral_i2c_read_register_byte_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + 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; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_write_register_byte_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + 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; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_write_register_byte_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_i2c_write_register_byte(NULL, I2C_REGISTER, I2C_BUFFER_VALUE); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_register_word_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + uint16_t data; + + 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; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_read_register_word_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint16_t data; + + if (g_feature == false) { + ret = peripheral_i2c_read_register_word(NULL, I2C_REGISTER, &data); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_i2c_read_register_word(NULL, I2C_REGISTER, &data); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + + +int test_peripheral_io_i2c_peripheral_i2c_read_register_word_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + 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; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + + +int test_peripheral_io_i2c_peripheral_i2c_write_register_word_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_i2c_h i2c_h = NULL; + + 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; + + } else { + ret = peripheral_i2c_open(bus, address, &i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_i2c_close(i2c_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_i2c_peripheral_i2c_write_register_word_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_i2c_write_register_word(NULL, I2C_REGISTER, I2C_BUFFER_VALUE); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} diff --git a/test/src/test_peripheral_pwm.c b/test/src/test_peripheral_pwm.c new file mode 100644 index 0000000..7b88d5e --- /dev/null +++ b/test/src/test_peripheral_pwm.c @@ -0,0 +1,440 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test_peripheral_pwm.h" + +#define PWM_CHIP 0 +#define PWM_CHIP_INVALID -99 +#define PWM_PIN 2 +#define PWM_PIN_INVALID -99 +#define PWM_PERIOD 1000 +#define PWM_DUTY_CYCLE 100 + +static bool g_feature = true; +static int chip; +static int pin; + +int test_peripheral_io_pwm_initialize(char *model, bool feature) +{ + g_feature = feature; + + if ((!strcmp(model, "rpi3")) || (!strcmp(model, "artik"))) { + chip = PWM_CHIP; + pin = PWM_PIN; + } else { + return -1; + } + return 0; +} + +int test_peripheral_io_pwm_peripheral_pwm_open_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + if (g_feature == false) { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_open_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + if (g_feature == false) { + ret = peripheral_pwm_open(PWM_CHIP_INVALID, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(PWM_CHIP_INVALID, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_open_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + if (g_feature == false) { + ret = peripheral_pwm_open(chip, PWM_PIN_INVALID, &pwm_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, PWM_PIN_INVALID, &pwm_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_open_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_pwm_open(chip, pin, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, pin, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_close_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + if (g_feature == false) { + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_close_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_pwm_close(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_close(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_period_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + if (g_feature == false) { + ret = peripheral_pwm_set_period(pwm_h, PWM_PERIOD); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_pwm_set_period(pwm_h, PWM_PERIOD); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_pwm_close(pwm_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_period_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_pwm_set_period(NULL, PWM_PERIOD); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_set_period(NULL, PWM_PERIOD); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + 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; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_pwm_set_duty_cycle(NULL, PWM_DUTY_CYCLE); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_set_duty_cycle(NULL, PWM_DUTY_CYCLE); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + 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; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + 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; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_pwm_set_polarity(NULL, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + 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; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + 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; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + bool enable = true; + + if (g_feature == false) { + ret = peripheral_pwm_set_enabled(pwm_h, enable); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_pwm_set_enabled(pwm_h, enable); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_pwm_close(pwm_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_pwm_h pwm_h = NULL; + + bool enable = false; + + if (g_feature == false) { + ret = peripheral_pwm_set_enabled(pwm_h, enable); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_open(chip, pin, &pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_pwm_set_enabled(pwm_h, enable); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_pwm_close(pwm_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_pwm_close(pwm_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_pwm_peripheral_pwm_set_enabled_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + bool enable = true; + + if (g_feature == false) { + ret = peripheral_pwm_set_enabled(NULL, enable); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_pwm_set_enabled(NULL, enable); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} diff --git a/test/src/test_peripheral_spi.c b/test/src/test_peripheral_spi.c new file mode 100644 index 0000000..41576c2 --- /dev/null +++ b/test/src/test_peripheral_spi.c @@ -0,0 +1,855 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test_peripheral_spi.h" + +#define SPI_BUS_RPI3 0 +#define SPI_BUS_ARTIK530 2 +#define SPI_BUS_INVALID -99 +#define SPI_CS 0 +#define SPI_CS_INVALID -99 +#define SPI_BITS_PER_WORD 8 +#define SPI_BITS_PER_WORD_INVALID 1 +#define SPI_FREQUENCY 15000 +#define SPI_BUFFER_LEN 1 +#define SPI_WRITE_DATA 0x00 + +static bool g_feature = true; +static int bus; +static int cs; + +int test_peripheral_io_spi_initialize(char *model, bool feature) +{ + g_feature = feature; + + if (!strcmp(model, "rpi3")) + bus = SPI_BUS_RPI3; + else if (!strcmp(model, "artik")) + bus = SPI_BUS_ARTIK530; + else + return -1; + + cs = SPI_CS; + + return 0; +} + +int test_peripheral_io_spi_peripheral_spi_open_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_open_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_open(SPI_BUS_INVALID, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(SPI_BUS_INVALID, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_open_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_open(bus, SPI_CS_INVALID, &spi_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, SPI_CS_INVALID, &spi_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_open_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_spi_open(bus, cs, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_close_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_close_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_spi_close(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_close(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_p4(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_set_mode(NULL, PERIPHERAL_SPI_MODE_0); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_mode_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bit_order_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bit_order_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bit_order_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_spi_set_bit_order(NULL, PERIPHERAL_SPI_BIT_ORDER_MSB); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bit_order_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bit_order_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_spi_set_bits_per_word(NULL, SPI_BITS_PER_WORD); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_bits_per_word_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_frequency_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_set_frequency(spi_h, SPI_FREQUENCY); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + 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; + } + + ret = peripheral_spi_set_frequency(spi_h, SPI_FREQUENCY); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_spi_close(spi_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_set_frequency_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_spi_set_frequency(NULL, SPI_FREQUENCY); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_set_frequency(NULL, SPI_FREQUENCY); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_read_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + uint8_t data; + + if (g_feature == false) { + ret = peripheral_spi_read(spi_h, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_spi_read(spi_h, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_spi_close(spi_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_read_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t data; + + if (g_feature == false) { + ret = peripheral_spi_read(NULL, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_read(NULL, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_read_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_read(spi_h, NULL, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_write_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + uint8_t data = SPI_WRITE_DATA; + + if (g_feature == false) { + ret = peripheral_spi_write(spi_h, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_spi_write(spi_h, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NONE) { + peripheral_spi_close(spi_h); + return PERIPHERAL_ERROR_UNKNOWN; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_write_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t data = SPI_WRITE_DATA; + + if (g_feature == false) { + ret = peripheral_spi_write(NULL, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_write(NULL, &data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + + +int test_peripheral_io_spi_peripheral_spi_write_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + if (g_feature == false) { + ret = peripheral_spi_write(spi_h, NULL, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_transfer_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + uint8_t tx_data = SPI_WRITE_DATA; + uint8_t rx_data; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_transfer_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t tx_data = SPI_WRITE_DATA; + uint8_t rx_data; + + 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; + + } else { + ret = peripheral_spi_transfer(NULL, &tx_data, &rx_data, SPI_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_transfer_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + uint8_t rx_data; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_spi_peripheral_spi_transfer_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_spi_h spi_h = NULL; + + uint8_t tx_data = SPI_WRITE_DATA; + + 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; + + } else { + ret = peripheral_spi_open(bus, cs, &spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_spi_close(spi_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} diff --git a/test/src/test_peripheral_uart.c b/test/src/test_peripheral_uart.c new file mode 100644 index 0000000..442961a --- /dev/null +++ b/test/src/test_peripheral_uart.c @@ -0,0 +1,1525 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "test_peripheral_uart.h" + +#define UART_PORT_RPI3 0 +#define UART_PORT_ARTIK530 4 +#define UART_PORT_INVALID -99 +#define UART_BUFFER_LEN 10 +#define UART_WRITE_DATA 0x00 + +static bool g_feature = true; +static int port; + +int test_peripheral_io_uart_initialize(char *model, bool feature) +{ + g_feature = feature; + + if (!strcmp(model, "rpi3")) + port = UART_PORT_RPI3; + else if (!strcmp(model, "artik")) + port = UART_PORT_ARTIK530; + else + return -1; + + return 0; +} + +int test_peripheral_io_uart_peripheral_uart_open_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_open_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_open(UART_PORT_INVALID, &uart_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(UART_PORT_INVALID, &uart_h); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_open_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_uart_open(port, NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_close_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_close_n(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_uart_close(NULL); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_close(NULL); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p4(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p5(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p6(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p7(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p8(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p9(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p10(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p11(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p12(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p13(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p14(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p15(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p16(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p17(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_p18(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_uart_set_baud_rate(NULL, PERIPHERAL_UART_BAUD_RATE_1200); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_baud_rate_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_p4(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_uart_set_byte_size(NULL, PERIPHERAL_UART_BYTE_SIZE_5BIT); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_byte_size_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_parity_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_parity_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_parity_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_parity_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + if (g_feature == false) { + ret = peripheral_uart_set_parity(NULL, PERIPHERAL_UART_PARITY_NONE); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_set_parity(NULL, PERIPHERAL_UART_PARITY_NONE); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_parity_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_parity_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } else { + ret = peripheral_uart_set_stop_bits(NULL, PERIPHERAL_UART_STOP_BITS_1BIT); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_stop_bits_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_p4(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + 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; + + } 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; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n3(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n4(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_set_flow_control_n5(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + 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; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_read_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + uint8_t data[UART_BUFFER_LEN]; + + if (g_feature == false) { + ret = peripheral_uart_read(uart_h, data, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_read_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t data[UART_BUFFER_LEN]; + + if (g_feature == false) { + ret = peripheral_uart_read(NULL, data, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_read(NULL, data, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_read_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_read(uart_h, NULL, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_write_p(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + uint8_t data[UART_BUFFER_LEN] = {UART_WRITE_DATA, }; + + if (g_feature == false) { + ret = peripheral_uart_write(uart_h, data, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + +int test_peripheral_io_uart_peripheral_uart_write_n1(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + uint8_t data[UART_BUFFER_LEN] = {UART_WRITE_DATA, }; + + if (g_feature == false) { + ret = peripheral_uart_write(NULL, data, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_write(NULL, data, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} + + +int test_peripheral_io_uart_peripheral_uart_write_n2(void) +{ + int ret = PERIPHERAL_ERROR_NONE; + + peripheral_uart_h uart_h = NULL; + + if (g_feature == false) { + ret = peripheral_uart_write(uart_h, NULL, UART_BUFFER_LEN); + if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN; + + } else { + ret = peripheral_uart_open(port, &uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + + 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; + } + + ret = peripheral_uart_close(uart_h); + if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN; + } + + return PERIPHERAL_ERROR_NONE; +} -- 2.7.4 From 2d4b5403cd00e808324def97a8d56800e3a9b4c2 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 7 Nov 2017 16:04:04 +0900 Subject: [PATCH 09/16] cmake: fixed to refer to duplicate source files. Change-Id: I076ee08f8af2f1ad4445cbb5fc0bc8e089c182b1 Signed-off-by: Segwon --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55ed4af..29d9721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,7 @@ SET(SOURCES src/peripheral_gpio.c src/peripheral_gdbus_pwm.c src/peripheral_gdbus_uart.c src/peripheral_gdbus_spi.c - src/peripheral_io_gdbus.c - src/peripheral_spi.c) + src/peripheral_io_gdbus.c) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) -- 2.7.4 From dc0be3157a3a53c82f5a0c5008baf14521196d91 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 7 Nov 2017 16:06:19 +0900 Subject: [PATCH 10/16] cmake: fixed to wrong variable name for include file. Change-Id: I570a465fc2972e3ca2fb0d0039a7232874ba1aa5 Signed-off-by: Segwon --- test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 48799da..5135302 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,8 +11,8 @@ ENDFOREACH() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") -SET(UTC_INCLUDE_DIR ./include) -INCLUDE_DIRECTORIES(${UTC_INCLUDE_DIR}) +SET(TEST_INCLUDE_DIR ./include) +INCLUDE_DIRECTORIES(${TEST_INCLUDE_DIR}) AUX_SOURCE_DIRECTORY(src test_sources) FOREACH(src ${test_sources}) -- 2.7.4 From c606f0ab36778e64b5da531bf1e2704195dfb38e Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 13:30:38 +0900 Subject: [PATCH 11/16] [1/6] fd passing: move interface code from daemon. - move from "peripheral-bus/src/interface/" - in order to improve performance, the lib area has direct access to the kernel. - not yet include in the build. Signed-off-by: Segwon Change-Id: Id3a047968f7018ef352b01aa93cb0450ecda1f4d --- src/interface/gpio.c | 373 ++++++++++++++++++++++++++++++++++ src/interface/i2c.c | 136 +++++++++++++ src/interface/include/gpio.h | 48 +++++ src/interface/include/i2c.h | 65 ++++++ src/interface/include/pwm.h | 125 ++++++++++++ src/interface/include/spi.h | 31 +++ src/interface/include/uart.h | 185 +++++++++++++++++ src/interface/pwm.c | 334 +++++++++++++++++++++++++++++++ src/interface/spi.c | 239 ++++++++++++++++++++++ src/interface/uart.c | 465 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 2001 insertions(+) create mode 100644 src/interface/gpio.c create mode 100644 src/interface/i2c.c create mode 100644 src/interface/include/gpio.h create mode 100644 src/interface/include/i2c.h create mode 100644 src/interface/include/pwm.h create mode 100644 src/interface/include/spi.h create mode 100644 src/interface/include/uart.h create mode 100644 src/interface/pwm.c create mode 100644 src/interface/spi.c create mode 100644 src/interface/uart.c diff --git a/src/interface/gpio.c b/src/interface/gpio.c new file mode 100644 index 0000000..77c73c8 --- /dev/null +++ b/src/interface/gpio.c @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "gpio.h" +#include "peripheral_common.h" + +#define MAX_ERR_LEN 255 + +int gpio_open(int gpiopin) +{ + int fd, len, status; + char gpio_export[GPIO_BUFFER_MAX] = {0, }; + + _D("gpiopin : %d", gpiopin); + + fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/export :%s\n", errmsg); + return -ENXIO; + } + + len = snprintf(gpio_export, GPIO_BUFFER_MAX, "%d", gpiopin); + status = write(fd, gpio_export, len); + + if (status != len) { + close(fd); + _E("Error: gpio open error \n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_set_direction(int gpiopin, gpio_direction_e dir) +{ + int fd, status; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + + _D("gpiopin : %d, dir : %d", gpiopin, dir); + + snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/direction", gpiopin); + fd = open(gpio_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d/direction: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + if (dir == GPIO_DIRECTION_IN) + status = write(fd, "in", strlen("in")+1); + else if (dir == GPIO_DIRECTION_OUT_HIGH) + status = write(fd, "high", strlen("high")+1); + else if (dir == GPIO_DIRECTION_OUT_LOW) + status = write(fd, "low", strlen("low")+1); + else { + close(fd); + _E("Error: gpio direction is wrong\n"); + return -EIO; + } + + if (status <= 0) { + close(fd); + _E("Error: gpio direction set error\n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_get_direction(int gpiopin, gpio_direction_e *dir) +{ + int fd, len; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + char gpio_buf[GPIO_BUFFER_MAX] = {0, }; + + snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/direction", gpiopin); + fd = open(gpio_dev, O_RDONLY); + + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d/direction: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + len = read(fd, &gpio_buf, GPIO_BUFFER_MAX); + if (len <= 0) { + close(fd); + _E("Error: gpio direction read error\n"); + return -EIO; + } + + if (0 == strncmp(gpio_buf, "in", strlen("in"))) + *dir = GPIO_DIRECTION_IN; + else if (0 == strncmp(gpio_buf, "out", strlen("out"))) + *dir = GPIO_DIRECTION_OUT_LOW; + else { + close(fd); + _E("Error: gpio direction is wrong\n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_set_edge_mode(int gpiopin, gpio_edge_e edge) +{ + int fd, status; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + + _D("gpiopin : %d, edge : %d", gpiopin, edge); + + snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/edge", gpiopin); + fd = open(gpio_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d/edge: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + if (edge == GPIO_EDGE_NONE) + status = write(fd, "none", strlen("none")+1); + else if (edge == GPIO_EDGE_RISING) + status = write(fd, "rising", strlen("rising")+1); + else if (edge == GPIO_EDGE_FALLING) + status = write(fd, "falling", strlen("falling")+1); + else if (edge == GPIO_EDGE_BOTH) + status = write(fd, "both", strlen("both")+1); + else { + close(fd); + _E("Error: gpio edge is wrong\n"); + return -EIO; + } + + if (status <= 0) { + close(fd); + _E("Error: gpio edge set error\n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_get_edge_mode(int gpiopin, gpio_edge_e *edge) +{ + int fd, len; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + char gpio_buf[GPIO_BUFFER_MAX] = {0, }; + + snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/edge", gpiopin); + fd = open(gpio_dev, O_RDONLY); + + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d/edge: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + len = read(fd, &gpio_buf, GPIO_BUFFER_MAX); + if (len <= 0) { + close(fd); + _E("Error: gpio edge read error\n"); + return -EIO; + } + + if (0 == strncmp(gpio_buf, "none", strlen("none"))) + *edge = GPIO_EDGE_NONE; + else if (0 == strncmp(gpio_buf, "both", strlen("both"))) + *edge = GPIO_EDGE_BOTH; + else if (0 == strncmp(gpio_buf, "rising", strlen("rising"))) + *edge = GPIO_EDGE_RISING; + else if (0 == strncmp(gpio_buf, "falling", strlen("falling"))) + *edge = GPIO_EDGE_FALLING; + else { + close(fd); + _E("Error: gpio edge is wrong\n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_write(int gpiopin, int value) +{ + int fd, status; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + + snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); + fd = open(gpio_dev, O_WRONLY); + + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d/value: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + if (value == 1) + status = write(fd, "1", strlen("1")+1); + else if (value == 0) + status = write(fd, "0", strlen("0")+1); + else { + close(fd); + _E("Error: gpio write value error \n"); + return -EIO; + } + + if (status <= 0) { + close(fd); + _E("Error: gpio write error\n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_read(int gpiopin, int *value) +{ + int fd, len; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + char gpio_buf[GPIO_BUFFER_MAX] = {0, }; + + snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); + fd = open(gpio_dev, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + len = read(fd, &gpio_buf, 1); + close(fd); + + if (len <= 0) { + _E("Error: gpio read error \n"); + return -EIO; + } + + if (0 == strncmp(gpio_buf, "1", strlen("1"))) + *value = 1; + else if (0 == strncmp(gpio_buf, "0", strlen("0"))) + *value = 0; + else { + _E("Error: gpio value is error \n"); + return -EIO; + } + + return 0; +} + +int gpio_close(int gpiopin) +{ + int fd, len, status; + char gpio_unexport[GPIO_BUFFER_MAX] = {0, }; + + _D("gpiopin : %d", gpiopin); + + fd = open(SYSFS_GPIO_DIR "/unexport", O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/unexport %s\n", errmsg); + return -ENXIO; + } + + len = snprintf(gpio_unexport, GPIO_BUFFER_MAX, "%d", gpiopin); + status = write(fd, gpio_unexport, len); + + if (status != len) { + close(fd); + _E("Error: gpio close error \n"); + return -EIO; + } + + close(fd); + + return 0; +} + +int gpio_open_isr(int gpiopin) +{ + int fd; + char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + + snprintf(gpio_dev, sizeof(gpio_dev)-1, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); + + _D("open isr string [%s]", gpio_dev); + + fd = open(gpio_dev, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg); + return -ENXIO; + } + + return fd; +} + +int gpio_close_isr(int fd) +{ + if (fd <= 0) return -EINVAL; + + close(fd); + + return 0; +} + +int gpio_read_isr(void *fdset, char *rev_buf, int length) +{ + int poll_state = 0; + int len; + struct pollfd poll_events; + + poll_events.fd = ((struct pollfd*)fdset)->fd; + poll_events.events = POLLPRI; + poll_events.revents = ((struct pollfd*)fdset)->revents; + + poll_state = poll((struct pollfd*)&poll_events, 1, -1); // 0 is going to return directly. + + if (poll_state < 0) { + _E("poll() failed!\n"); + return -EIO; + } + + if (poll_events.revents & POLLPRI) { + lseek(poll_events.fd, 0, SEEK_SET); + len = read(poll_events.fd, rev_buf, length); + if (len == -1) + return -EIO; + } + + return poll_state; +} diff --git a/src/interface/i2c.c b/src/interface/i2c.c new file mode 100644 index 0000000..0907cce --- /dev/null +++ b/src/interface/i2c.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "i2c.h" +#include "peripheral_common.h" + +#define MAX_ERR_LEN 255 + +int i2c_open(int bus, int *fd) +{ + int new_fd; + char i2c_dev[I2C_BUFFER_MAX] = {0,}; + + _D("bus : %d", bus); + + snprintf(i2c_dev, sizeof(i2c_dev)-1, SYSFS_I2C_DIR"-%d", bus); + new_fd = open(i2c_dev, O_RDWR); + if (new_fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s : %s", i2c_dev, errmsg); + return -ENXIO; + } + _D("fd : %d", new_fd); + *fd = new_fd; + + return 0; +} + +int i2c_close(int fd) +{ + int status; + + _D("fd : %d", fd); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = close(fd); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to close fd : %d", fd); + return -EIO; + } + + return 0; +} + +int i2c_set_address(int fd, int address) +{ + int status; + + _D("fd : %d, slave address : 0x%x", fd, address); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = ioctl(fd, I2C_SLAVE, address); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to set slave address(%x), fd : %d, errmsg : %s", address, fd, errmsg); + return status; + } + + return 0; +} + +int i2c_read(int fd, unsigned char *data, int length) +{ + int status; + + RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + + status = read(fd, data, length); + if (status != length) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("i2c read failed, fd : %d, errmsg : %s", fd, errmsg); + return -EIO; + } + + return 0; +} + +int i2c_write(int fd, const unsigned char *data, int length) +{ + int status; + + RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + + status = write(fd, data, length); + if (status != length) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("i2c write failed fd : %d, errmsg : %s", fd, errmsg); + return -EIO; + } + + return 0; +} + +int i2c_smbus_ioctl(int fd, struct i2c_smbus_ioctl_data *data) +{ + int status; + + RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + + status = ioctl(fd, I2C_SMBUS, data); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("i2c transaction failed fd : %d, errmsg : %s", fd, errmsg); + return -EIO; + } + + return 0; +} diff --git a/src/interface/include/gpio.h b/src/interface/include/gpio.h new file mode 100644 index 0000000..b0b7c5b --- /dev/null +++ b/src/interface/include/gpio.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#define SYSFS_GPIO_DIR "/sys/class/gpio" +#define GPIO_BUFFER_MAX 64 + +typedef enum { + GPIO_DIRECTION_IN = 0, + GPIO_DIRECTION_OUT_HIGH = 1, + GPIO_DIRECTION_OUT_LOW = 2, +} gpio_direction_e; + +typedef enum { + GPIO_EDGE_NONE = 0, + GPIO_EDGE_RISING = 1, + GPIO_EDGE_FALLING = 2, + GPIO_EDGE_BOTH = 3, +} gpio_edge_e; + +int gpio_open(int gpiopin); +int gpio_close(int gpiopin); +int gpio_set_edge_mode(int gpiopin, gpio_edge_e edge); +int gpio_get_edge_mode(int gpiopin, gpio_edge_e *edge); +int gpio_set_direction(int gpiopin, gpio_direction_e dir); +int gpio_get_direction(int gpiopin, gpio_direction_e *dir); +int gpio_write(int gpiopin, int value); +int gpio_read(int gpiopin, int *value); + +int gpio_open_isr(int gpiopin); +int gpio_close_isr(int file_hndl); +int gpio_read_isr(void *fdset, char *rev_buf, int length); +#endif/*__GPIO_H__*/ diff --git a/src/interface/include/i2c.h b/src/interface/include/i2c.h new file mode 100644 index 0000000..f0d4668 --- /dev/null +++ b/src/interface/include/i2c.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __I2C_H__ +#define __I2C_H__ + +#include + +#define SYSFS_I2C_DIR "/dev/i2c" +#define I2C_BUFFER_MAX 64 + +#define I2C_SLAVE 0x0703 /* Use this slave address */ +#define I2C_SMBUS 0x0720 /* SMBus transfer */ + +/* i2c_smbus_xfer read or write markers */ +#define I2C_SMBUS_READ 1 +#define I2C_SMBUS_WRITE 0 + +/* SMBus transaction types */ +#define I2C_SMBUS_QUICK 0 +#define I2C_SMBUS_BYTE 1 +#define I2C_SMBUS_BYTE_DATA 2 +#define I2C_SMBUS_WORD_DATA 3 + +/* + * Data for SMBus Messages + */ +#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */ + +union i2c_smbus_data { + uint8_t byte; + uint16_t word; + uint8_t block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */ + /* and one more for user-space compatibility */ +}; + +/* This is the structure as used in the I2C_SMBUS ioctl call */ +struct i2c_smbus_ioctl_data { + uint8_t read_write; + uint8_t command; + uint32_t size; + union i2c_smbus_data *data; +}; + +int i2c_open(int bus, int *fd); +int i2c_close(int fd); +int i2c_set_address(int fd, int address); +int i2c_read(int fd, unsigned char *data, int length); +int i2c_write(int fd, const unsigned char *data, int length); +int i2c_smbus_ioctl(int fd, struct i2c_smbus_ioctl_data *data); + +#endif/* __I2C_H__ */ diff --git a/src/interface/include/pwm.h b/src/interface/include/pwm.h new file mode 100644 index 0000000..26243d3 --- /dev/null +++ b/src/interface/include/pwm.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __PWM_H__ +#define __PWM_H__ + +/** + * @brief Enumeration for Polarity + */ +typedef enum { + PWM_POLARITY_NORMAL = 0, + PWM_POLARITY_INVERSED, +} pwm_polarity_e; + +/** +* @brief pwm_open() init pwm pin. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_open(int chip, int pin); + +/** +* @brief pwm_close() deinit pwm pin. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_close(int chip, int pin); + +/** +* @brief pwm_set_period() sets the pwm period. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[in] period pwm period +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_set_period(int chip, int pin, int period); + +/** +* @brief pwm_get_period() gets the pwm period. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[out] period pwm period +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_get_period(int chip, int pin, int *period); + +/** +* @brief pwm_set_duty_cycle() sets the pwm duty cycle. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[in] duty_cycle pwm duty cycle +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_set_duty_cycle(int chip, int pin, int duty_cycle); + +/** +* @brief pwm_get_duty_cycle() gets the pwm duty cycle. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[out] duty_cycle pwm duty cycle +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle); + +/** +* @brief pwm_set_polarity() sets the pwm polarity. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[in] polarity pwm polarity +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_set_polarity(int chip, int pin, pwm_polarity_e polarity); +/** +* @brief pwm_get_polarity() gets the pwm polarity. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[out] polarity pwm polarity +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity); + +/** +* @brief pwm_set_enable() sets the pwm state. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[in] enable pwm enable/disabled state value +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_set_enable(int chip, int pin, bool enable); + +/** +* @brief pwm_get_enable() checks if pwm state is enabled. +* +* @param[in] chip pwm chip number +* @param[in] pin pwm pin number +* @param[out] enable pwm enable/disabled state value +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int pwm_get_enable(int chip, int pin, bool *enable); + +#endif /* __PWM_H__ */ diff --git a/src/interface/include/spi.h b/src/interface/include/spi.h new file mode 100644 index 0000000..9937c41 --- /dev/null +++ b/src/interface/include/spi.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SPI_H__ +#define __SPI_H__ + +int spi_open(int bus, int cs, int *fd); +int spi_close(int fd); +int spi_set_mode(int fd, unsigned char mode); +int spi_set_bit_order(int fd, unsigned char lsb); +int spi_set_bits_per_word(int fd, unsigned char bits); +int spi_set_frequency(int fd, unsigned int freq); +int spi_get_buffer_size(int *bufsiz); +int spi_read(int fd, unsigned char *rxbuf, int length); +int spi_write(int fd, unsigned char *txbuf, int length); +int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length); + +#endif /* __SPI_H__ */ diff --git a/src/interface/include/uart.h b/src/interface/include/uart.h new file mode 100644 index 0000000..413b23e --- /dev/null +++ b/src/interface/include/uart.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UART_H__ +#define __UART_H__ + +#include + +/** + * @brief Enumeration for Baud Rate + */ +typedef enum { + UART_BAUD_RATE_0 = 0, + UART_BAUD_RATE_50, + UART_BAUD_RATE_75, + UART_BAUD_RATE_110, + UART_BAUD_RATE_134, + UART_BAUD_RATE_150, + UART_BAUD_RATE_200, + UART_BAUD_RATE_300, + UART_BAUD_RATE_600, + UART_BAUD_RATE_1200, + UART_BAUD_RATE_1800, + UART_BAUD_RATE_2400, + UART_BAUD_RATE_4800, + UART_BAUD_RATE_9600, + UART_BAUD_RATE_19200, + UART_BAUD_RATE_38400, + UART_BAUD_RATE_57600, + UART_BAUD_RATE_115200, + UART_BAUD_RATE_230400 +} uart_baud_rate_e; + +/** + * @brief Enumeration for Byte Size + */ +typedef enum { + UART_BYTE_SIZE_5BIT = 0, + UART_BYTE_SIZE_6BIT, + UART_BYTE_SIZE_7BIT, + UART_BYTE_SIZE_8BIT +} uart_byte_size_e; + +/** + * @brief Enumeration of Parity Bit + */ +typedef enum { + UART_PARITY_NONE = 0, + UART_PARITY_EVEN, + UART_PARITY_ODD +} uart_parity_e; + +/** + * @brief Enumeration for Stop Bits + */ +typedef enum { + UART_STOP_BITS_1BIT = 0, + UART_STOP_BITS_2BIT +} uart_stop_bits_e; + +/** +* @brief uart_valid_baudrate() validation check of input baudrate +* +* @param[in] baudrate baudrate for uart +* @return On success, valid input. On failure, NULL is returned. +*/ +int uart_valid_baud_rate(unsigned int baud_rate); + +/** +* @brief uart_open() initializes uart port. +* +* @param[in] port uart port +* @param[in] file_hndl handle of uart port +* @return On success, handle of uart_context is returned. On failure, NULL is returned. +*/ +int uart_open(int port, int *file_hndl); + +/** +* @brief uart_close() closes uart port. +* +* @param[in] file_hndl handle of uart_context +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_close(int file_hndl); + +/** +* @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 uart_flush(int file_hndl); + +/** +* @brief uart_set_baudrate() sets uart baud rate. +* +* @param[in] file_hndl handle of uart_context +* @param[in] baud uart baud rate +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud); + +/** +* @brief uart_set_mode() sets byte size, parity bit and stop bits. +* +* @param[in] file_hndl handle of uart_context +* @param[in] byte_size uart byte size +* @param[in] parity uart parity type (even/odd/none) +* @param[in] stop_bits uart stop bits +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); + +/** +* @brief peripheral_bus_uart_set_byte_size() set byte size. +* +* @param[in] file_hndl handle of uart_context +* @param[in] byte_size uart byte size +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size); + +/** +* @brief peripheral_bus_uart_set_parity() set parity bit. +* +* @param[in] file_hndl handle of uart_context +* @param[in] parity uart parity type (even/odd/none) +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_parity(int file_hndl, uart_parity_e parity); + +/** +* @brief peripheral_bus_uart_set_stop_bits() set stop bits. +* +* @param[in] file_hndl handle of uart_context +* @param[in] stop_bits uart stop bits +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits); + +/** +* @brief uart_set_flow_control() set flow control settings. +* +* @param[in] file_hndl handle of uart_context +* @param[in] xonxoff ixon/ixoff +* @param[in] rtscts rts/cts +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts); + +/** +* @brief uart_read() reads data over uart bus. +* +* @param[in] file_hndl handle of uart_context +* @param[in] buf the pointer of data buffer +* @param[in] length size to read +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_read(int file_hndl, uint8_t *buf, unsigned int length); + +/** +* @brief uart_write() writes data over uart bus. +* +* @param[in] file_hndl handle of uart_context +* @param[in] buf the pointer of data buffer +* @param[in] length size to write +* @return On success, 0 is returned. On failure, a negative value is returned. +*/ +int uart_write(int file_hndl, uint8_t *buf, unsigned int length); + +#endif /* __UART_H__ */ + diff --git a/src/interface/pwm.c b/src/interface/pwm.c new file mode 100644 index 0000000..2b6ebd8 --- /dev/null +++ b/src/interface/pwm.c @@ -0,0 +1,334 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "pwm.h" +#include "peripheral_common.h" + +#define SYSFS_PWM_PATH "/sys/class/pwm" + +#define PATH_BUF_MAX 64 +#define PWM_BUF_MAX 16 +#define MAX_ERR_LEN 255 + +int pwm_open(int chip, int pin) +{ + int fd, len, status; + char pwm_dev[PATH_BUF_MAX] = {0}; + char pwm_buf[PWM_BUF_MAX] = {0}; + + _D("chip : %d, pin : %d", chip, pin); + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/export", chip); + fd = open(pwm_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", pin); + status = write(fd, pwm_buf, len); + if (status < 0) { + _E("Failed to export pwmchip%d, pwm%d", chip, pin); + close(fd); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_close(int chip, int pin) +{ + int fd, len, status; + char pwm_dev[PATH_BUF_MAX] = {0}; + char pwm_buf[PWM_BUF_MAX] = {0}; + + _D("chip : %d, pin : %d", chip, pin); + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/unexport", chip); + fd = open(pwm_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", pin); + status = write(fd, pwm_buf, len); + if (status < 0) { + _E("Failed to unexport pwmchip%d, pwm%", chip, pin); + close(fd); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_set_period(int chip, int pin, int period) +{ + int fd, len, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + _D("chip : %d, pin : %d, period : %d", chip, pin, period); + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", chip, pin); + fd = open(pwm_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period); + status = write(fd, pwm_buf, len); + if (status < 0) { + close(fd); + _E("Failed to set period, path : %s", pwm_dev); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_get_period(int chip, int pin, int *period) +{ + int fd, result, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", chip, pin); + fd = open(pwm_dev, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + status = read(fd, pwm_buf, PWM_BUF_MAX); + if (status < 0) { + close(fd); + _E("Failed to get period, path : %s", pwm_dev); + return -EIO; + } + result = atoi(pwm_buf); + *period = result; + close(fd); + + return 0; +} + +int pwm_set_duty_cycle(int chip, int pin, int duty_cycle) +{ + int fd, len, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + _D("chip : %d, pin : %d, duty_cycle : %d", chip, pin, duty_cycle); + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", chip, pin); + fd = open(pwm_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle); + status = write(fd, pwm_buf, len); + if (status < 0) { + close(fd); + _E("Failed to set duty cycle, path : %s", pwm_dev); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle) +{ + int fd, result, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", chip, pin); + fd = open(pwm_dev, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + status = read(fd, pwm_buf, PWM_BUF_MAX); + if (status < 0) { + close(fd); + _E("Failed to get duty cycle, path : %s", pwm_dev); + return -EIO; + } + result = atoi(pwm_buf); + *duty_cycle = result; + close(fd); + + return 0; +} + +int pwm_set_polarity(int chip, int pin, pwm_polarity_e polarity) +{ + int fd, status; + char pwm_dev[PATH_BUF_MAX] = {0}; + + _D("chip : %d, pin : %d, polarity : %d", chip, pin, polarity); + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", chip, pin); + fd = open(pwm_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + if (polarity == PWM_POLARITY_NORMAL) + status = write(fd, "normal", strlen("normal")+1); + else if (polarity == PWM_POLARITY_INVERSED) + status = write(fd, "inversed", strlen("inversed")+1); + else { + _E("Invalid pwm polarity : %d", polarity); + close(fd); + return -EINVAL; + } + + if (status <= 0) { + close(fd); + _E("Failed to set polarity, path : %s", pwm_dev); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity) +{ + int fd, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", chip, pin); + fd = open(pwm_dev, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + status = read(fd, pwm_buf, PWM_BUF_MAX); + if (status < 0) { + _E("Failed to get polarity, path : %s", pwm_dev); + close(fd); + return -EIO; + } + + if (0 == strncmp(pwm_buf, "normal", strlen("normal"))) + *polarity = PWM_POLARITY_NORMAL; + else if (0 == strncmp(pwm_buf, "inversed", strlen("inversed"))) + *polarity = PWM_POLARITY_INVERSED; + else { + close(fd); + _E("Invalid pwm polarity : %d", pwm_buf); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_set_enable(int chip, int pin, bool enable) +{ + int fd, len, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + _D("chip : %d, pin : %d, enable : %d", chip, pin, enable); + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", chip, pin); + fd = open(pwm_dev, O_WRONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable); + status = write(fd, pwm_buf, len); + if (status < 0) { + close(fd); + _E("Failed to set enable, path : %s", pwm_dev); + return -EIO; + } + close(fd); + + return 0; +} + +int pwm_get_enable(int chip, int pin, bool *enable) +{ + int fd, result, status; + char pwm_buf[PWM_BUF_MAX] = {0}; + char pwm_dev[PATH_BUF_MAX] = {0}; + + snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", chip, pin); + fd = open(pwm_dev, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); + return -ENXIO; + } + + status = read(fd, pwm_buf, PWM_BUF_MAX); + if (status < 0) { + close(fd); + _E("Failed to get enable, path : %s", pwm_dev); + return -EIO; + } + result = atoi(pwm_buf); + *enable = !!result; + close(fd); + + return 0; +} + diff --git a/src/interface/spi.c b/src/interface/spi.c new file mode 100644 index 0000000..1016a9e --- /dev/null +++ b/src/interface/spi.c @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "spi.h" +#include "peripheral_common.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 spi_open(int bus, int cs, int *fd) +{ + int new_fd = 0; + char spi_dev[SPI_BUFFER_MAX] = {0,}; + + _D("bus : %d, cs : %d", bus, cs); + + snprintf(spi_dev, sizeof(spi_dev)-1, SYSFS_SPI_DIR"%d.%d", bus, cs); + + new_fd = open(spi_dev, O_RDWR); + if (new_fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", spi_dev, errmsg); + return -ENXIO; + } + _D("fd : %d", new_fd); + *fd = new_fd; + + return 0; +} + +int spi_close(int fd) +{ + int status; + + _D("fd : %d", fd); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = close(fd); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to close fd : %d", fd); + return -EIO; + } + + return 0; +} + +int spi_set_mode(int fd, unsigned char mode) +{ + int status; + + _D("fd : %d, mode : %d", fd, mode); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = ioctl(fd, SPI_IOC_WR_MODE, &mode); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to set mode(%d) : %s", mode, errmsg); + return -EIO; + } + + return 0; +} + +int spi_set_bit_order(int fd, unsigned char lsb) +{ + int status; + + _D("fd : %d, lsb : %d", fd, lsb); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", lsb, fd, errmsg); + return -EIO; + } + + return 0; +} + +int spi_set_bits_per_word(int fd, unsigned char bits) +{ + int status; + + _D("fd : %d, bits : %d", fd, bits); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to set bits(%d), fd : %d, errmsg : %s", bits, fd, errmsg); + return -EIO; + } + + return 0; +} + +int spi_set_frequency(int fd, unsigned int freq) +{ + int status; + + _D("fd : %d, freq : %d", fd, freq); + RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + + status = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to set frequency(%d), fd : %d, errmsg : %s", freq, fd, errmsg); + return -EIO; + } + + return 0; +} + +int spi_get_buffer_size(int *bufsiz) +{ + int fd, result, status; + char spi_buf[SPI_BUFFER_MAX] = {0,}; + + fd = open(SYSFS_SPI_BUFSIZ, O_RDONLY); + if (fd < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Can't Open %s, errmsg : %s", SYSFS_SPI_BUFSIZ, errmsg); + return -ENXIO; + } + + status = read(fd, spi_buf, SPI_BUFFER_MAX); + if (status < 0) { + _E("Failed to get buffer size, path : %s", SYSFS_SPI_BUFSIZ); + close(fd); + return -EIO; + } + result = atoi(spi_buf); + *bufsiz = result; + close(fd); + + return 0; +} + +int spi_read(int fd, unsigned char *rxbuf, int length) +{ + int status; + struct spi_ioc_transfer xfer; + + RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + + memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); + xfer.rx_buf = (unsigned long)rxbuf; + xfer.len = length; + + status = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to read data, fd : %d, length : %d, errmsg : %s", fd, length, errmsg); + return -EIO; + } + + return 0; +} + +int spi_write(int fd, unsigned char *txbuf, int length) +{ + int status; + struct spi_ioc_transfer xfer; + + RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + + memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); + xfer.tx_buf = (unsigned long)txbuf; + xfer.len = length; + + status = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to write data(%d) : %s", length, errmsg); + return -EIO; + } + + return 0; +} + +int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length) +{ + int status; + struct spi_ioc_transfer xfer; + + RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + + if (!txbuf || !rxbuf || length < 0) return -EINVAL; + + memset(&xfer, 0, sizeof(xfer)); + xfer.tx_buf = (unsigned long)txbuf; + xfer.rx_buf = (unsigned long)rxbuf; + xfer.len = length; + + status = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to exchange data(%d) : %s", length, errmsg); + return -EIO; + } + + return 0; +} diff --git a/src/interface/uart.c b/src/interface/uart.c new file mode 100644 index 0000000..34ff11e --- /dev/null +++ b/src/interface/uart.c @@ -0,0 +1,465 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "uart.h" +#include "peripheral_common.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, + B1800, B2400, B4800, B9600, B19200, + B38400, B57600, B115200, B230400 +}; + +static const int byteinfo[4] = {CS5, CS6, CS7, CS8}; + +int uart_open(int port, int *file_hndl) +{ + int i, fd; + char uart_dev[PATH_BUF_MAX] = {0}; + + _D("port : %d", port); + + for (i = 0; i < ARRAY_SIZE(sysfs_uart_path); i++) { + snprintf(uart_dev, PATH_BUF_MAX, "%s%d", sysfs_uart_path[i], port); + if (access(uart_dev, F_OK) == 0) + break; + } + _D("uart_dev : %s", uart_dev); + if ((fd = open(uart_dev, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("can't open %s, errmsg : %s", uart_dev, errmsg); + return -ENXIO; + } + *file_hndl = fd; + return 0; +} + +int uart_close(int file_hndl) +{ + int status; + + _D("file_hndl : %d", file_hndl); + + if (file_hndl < 0) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + status = uart_flush(file_hndl); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to close fd : %d, errmsg : %s", file_hndl, errmsg); + return -EIO; + } + + status = close(file_hndl); + if (status < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("Failed to close fd : %d, errmsg : %s", file_hndl, errmsg); + return -EIO; + } + + return 0; +} + +int uart_flush(int file_hndl) +{ + int ret; + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = tcflush(file_hndl, TCIOFLUSH); + if (ret < 0) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcflush failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, baud : %d", file_hndl, baud); + + memset(&tio, 0, sizeof(tio)); + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + if (baud > UART_BAUD_RATE_230400) { + _E("Invalid parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg : %s", errmsg); + return -1; + } + tio.c_cflag = peripheral_uart_br[baud]; + tio.c_iflag = IGNPAR; + tio.c_oflag = 0; + tio.c_lflag = 0; + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 0; + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg: %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", file_hndl, byte_size, parity, stop_bits); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + if (byte_size > UART_BYTE_SIZE_8BIT) { + _E("Invalid bytesize parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set byte size */ + tio.c_cflag &= ~CSIZE; + tio.c_cflag |= byteinfo[byte_size]; + tio.c_cflag |= (CLOCAL | CREAD); + + /* set parity info */ + switch (parity) { + case UART_PARITY_EVEN: + tio.c_cflag |= PARENB; + tio.c_cflag &= ~PARODD; + break; + case UART_PARITY_ODD: + tio.c_cflag |= PARENB; + tio.c_cflag |= PARODD; + break; + case UART_PARITY_NONE: + default: + tio.c_cflag &= ~PARENB; + tio.c_cflag &= ~PARODD; + break; + } + + /* set stop bit */ + switch (stop_bits) { + case UART_STOP_BITS_1BIT: + tio.c_cflag &= ~CSTOPB; + break; + case UART_STOP_BITS_2BIT: + tio.c_cflag |= CSTOPB; + break; + default: + _E("Invalid parameter stop_bits"); + return -EINVAL; + } + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, bytesize : %d", file_hndl, byte_size); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + if (byte_size > UART_BYTE_SIZE_8BIT) { + _E("Invalid bytesize parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set byte size */ + tio.c_cflag &= ~CSIZE; + tio.c_cflag |= byteinfo[byte_size]; + tio.c_cflag |= (CLOCAL | CREAD); + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_parity(int file_hndl, uart_parity_e parity) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, parity : %d", file_hndl, parity); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set parity info */ + switch (parity) { + case UART_PARITY_EVEN: + tio.c_cflag |= PARENB; + tio.c_cflag &= ~PARODD; + break; + case UART_PARITY_ODD: + tio.c_cflag |= PARENB; + tio.c_cflag |= PARODD; + break; + case UART_PARITY_NONE: + default: + tio.c_cflag &= ~PARENB; + tio.c_cflag &= ~PARODD; + break; + } + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, stopbits : %d", file_hndl, stop_bits); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg: %s", errmsg); + return -1; + } + + /* set stop bit */ + switch (stop_bits) { + case UART_STOP_BITS_1BIT: + tio.c_cflag &= ~CSTOPB; + break; + case UART_STOP_BITS_2BIT: + tio.c_cflag |= CSTOPB; + break; + default: + _E("Invalid parameter stop_bits"); + return -EINVAL; + } + + uart_flush(file_hndl); + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts) +{ + int ret; + struct termios tio; + + _D("file_hndl : %d, xonxoff : %d, rtscts : %d", file_hndl, xonxoff, rtscts); + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = tcgetattr(file_hndl, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcgetattr failed, errmsg : %s", errmsg); + return -1; + } + + /* rtscts => 1: rts/cts on, 0: off */ + if (rtscts) + tio.c_cflag |= CRTSCTS; + else + tio.c_cflag &= ~CRTSCTS; + + /* xonxoff => 1: xon/xoff on, 0: off */ + if (xonxoff) + tio.c_iflag |= (IXON | IXOFF | IXANY); + else + tio.c_iflag &= ~(IXON | IXOFF | IXANY); + + ret = tcsetattr(file_hndl, TCSANOW, &tio); + if (ret) { + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("tcsetattr failed, errmsg : %s", errmsg); + return -1; + } + + return 0; +} + +int uart_read(int file_hndl, uint8_t *buf, unsigned int length) +{ + int ret; + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = read(file_hndl, (void *)buf, length); + if (ret <= 0) { + if (errno == EAGAIN) + return -EAGAIN; + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("read failed, errmsg : %s", errmsg); + return -EIO; + } + + return ret; +} + +int uart_write(int file_hndl, uint8_t *buf, unsigned int length) +{ + int ret; + + if (!file_hndl) { + _E("Invalid NULL parameter"); + return -EINVAL; + } + + ret = write(file_hndl, buf, length); + if (ret <= 0) { + if (errno == EAGAIN) + return -EAGAIN; + char errmsg[MAX_ERR_LEN]; + strerror_r(errno, errmsg, MAX_ERR_LEN); + _E("write failed, errmsg : %s", errmsg); + return -EIO; + } + + return ret; +} -- 2.7.4 From 682d82c41643130b0966cf6ff7cf8612b1419c14 Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 14:31:31 +0900 Subject: [PATCH 12/16] interface: move interface header files to top level include folder. - seperated for readability. - included interface files when running build. Signed-off-by: Segwon Change-Id: I4847dc8a7cf5f81de098a730c640229dfbc8a560 --- CMakeLists.txt | 6 ++++++ {src/interface/include => include/interface}/gpio.h | 0 {src/interface/include => include/interface}/i2c.h | 0 {src/interface/include => include/interface}/pwm.h | 0 {src/interface/include => include/interface}/spi.h | 0 {src/interface/include => include/interface}/uart.h | 0 6 files changed, 6 insertions(+) rename {src/interface/include => include/interface}/gpio.h (100%) rename {src/interface/include => include/interface}/i2c.h (100%) rename {src/interface/include => include/interface}/pwm.h (100%) rename {src/interface/include => include/interface}/spi.h (100%) rename {src/interface/include => include/interface}/uart.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29d9721..714f3d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) +INCLUDE_DIRECTORIES(${INC_DIR}/interface) INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) @@ -47,6 +48,11 @@ SET(SOURCES src/peripheral_gpio.c src/peripheral_pwm.c src/peripheral_uart.c src/peripheral_spi.c + src/interface/gpio.c + src/interface/i2c.c + src/interface/pwm.c + src/interface/spi.c + src/interface/uart.c src/peripheral_gdbus_gpio.c src/peripheral_gdbus_i2c.c src/peripheral_gdbus_pwm.c diff --git a/src/interface/include/gpio.h b/include/interface/gpio.h similarity index 100% rename from src/interface/include/gpio.h rename to include/interface/gpio.h diff --git a/src/interface/include/i2c.h b/include/interface/i2c.h similarity index 100% rename from src/interface/include/i2c.h rename to include/interface/i2c.h diff --git a/src/interface/include/pwm.h b/include/interface/pwm.h similarity index 100% rename from src/interface/include/pwm.h rename to include/interface/pwm.h diff --git a/src/interface/include/spi.h b/include/interface/spi.h similarity index 100% rename from src/interface/include/spi.h rename to include/interface/spi.h diff --git a/src/interface/include/uart.h b/include/interface/uart.h similarity index 100% rename from src/interface/include/uart.h rename to include/interface/uart.h -- 2.7.4 From af70ff10619d5c1caeb1ee629284f00ca14635c0 Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 15:17:29 +0900 Subject: [PATCH 13/16] [2/6] fd passing: add member variable for file descriptor in handle. Signed-off-by: Segwon Change-Id: Ic82127b5a4426872b11da5434a8feddf53f4244e --- include/peripheral_internal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/peripheral_internal.h b/include/peripheral_internal.h index ae4f47e..5c62dee 100644 --- a/include/peripheral_internal.h +++ b/include/peripheral_internal.h @@ -23,6 +23,9 @@ struct _peripheral_gpio_s { int pin; uint handle; + int fd_direction; + int fd_edge; + int fd_value; }; /** @@ -30,6 +33,7 @@ struct _peripheral_gpio_s { */ struct _peripheral_i2c_s { uint handle; + int fd; }; /** @@ -37,6 +41,10 @@ struct _peripheral_i2c_s { */ struct _peripheral_pwm_s { uint handle; + int fd_period; + int fd_duty_cycle; + int fd_polarity; + int fd_enable; }; /** @@ -44,6 +52,7 @@ struct _peripheral_pwm_s { */ struct _peripheral_uart_s { uint handle; + int fd; }; /** @@ -51,6 +60,7 @@ struct _peripheral_uart_s { */ struct _peripheral_spi_s { uint handle; + int fd; }; #endif /* __PERIPHERAL_INTERNAL_H__ */ -- 2.7.4 From 6eb41d84cbb42d160d30585309f5aab7b6374afe Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 18:13:45 +0900 Subject: [PATCH 14/16] [3/6] fd passing: use fd directly without opening it - delete open function - change parameter fd to handle because handle can have multiple fd - remove unnecessary functions. Change-Id: I6a326d7047e4602604d3becf61dd5b1342666edf Signed-off-by: Segwon --- include/interface/gpio.h | 20 ++-- include/interface/i2c.h | 13 ++- include/interface/pwm.h | 59 ++-------- include/interface/spi.h | 20 ++-- include/interface/uart.h | 39 ++----- src/interface/gpio.c | 298 ++++++++--------------------------------------- src/interface/i2c.c | 66 ++++------- src/interface/pwm.c | 264 +++++------------------------------------ src/interface/spi.c | 117 ++++++------------- src/interface/uart.c | 126 +++++++++----------- 10 files changed, 236 insertions(+), 786 deletions(-) diff --git a/include/interface/gpio.h b/include/interface/gpio.h index b0b7c5b..b4d6ccc 100644 --- a/include/interface/gpio.h +++ b/include/interface/gpio.h @@ -17,6 +17,8 @@ #ifndef __GPIO_H__ #define __GPIO_H__ +#include "peripheral_io.h" + #define SYSFS_GPIO_DIR "/sys/class/gpio" #define GPIO_BUFFER_MAX 64 @@ -33,16 +35,12 @@ typedef enum { GPIO_EDGE_BOTH = 3, } gpio_edge_e; -int gpio_open(int gpiopin); -int gpio_close(int gpiopin); -int gpio_set_edge_mode(int gpiopin, gpio_edge_e edge); -int gpio_get_edge_mode(int gpiopin, gpio_edge_e *edge); -int gpio_set_direction(int gpiopin, gpio_direction_e dir); -int gpio_get_direction(int gpiopin, gpio_direction_e *dir); -int gpio_write(int gpiopin, int value); -int gpio_read(int gpiopin, int *value); +int gpio_close(peripheral_gpio_h gpio); +int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge); +int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir); +int gpio_write(peripheral_gpio_h gpio, int value); +int gpio_read(peripheral_gpio_h gpio, int *value); -int gpio_open_isr(int gpiopin); -int gpio_close_isr(int file_hndl); -int gpio_read_isr(void *fdset, char *rev_buf, int length); +int gpio_open_isr(peripheral_gpio_h gpio); +int gpio_close_isr(peripheral_gpio_h gpio); #endif/*__GPIO_H__*/ diff --git a/include/interface/i2c.h b/include/interface/i2c.h index f0d4668..6846649 100644 --- a/include/interface/i2c.h +++ b/include/interface/i2c.h @@ -19,6 +19,8 @@ #include +#include "peripheral_io.h" + #define SYSFS_I2C_DIR "/dev/i2c" #define I2C_BUFFER_MAX 64 @@ -55,11 +57,10 @@ struct i2c_smbus_ioctl_data { union i2c_smbus_data *data; }; -int i2c_open(int bus, int *fd); -int i2c_close(int fd); -int i2c_set_address(int fd, int address); -int i2c_read(int fd, unsigned char *data, int length); -int i2c_write(int fd, const unsigned char *data, int length); -int i2c_smbus_ioctl(int fd, struct i2c_smbus_ioctl_data *data); +int i2c_close(peripheral_i2c_h i2c); +int i2c_set_address(peripheral_i2c_h i2c, int address); +int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length); +int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length); +int i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data); #endif/* __I2C_H__ */ diff --git a/include/interface/pwm.h b/include/interface/pwm.h index 26243d3..7a9f0d0 100644 --- a/include/interface/pwm.h +++ b/include/interface/pwm.h @@ -17,6 +17,8 @@ #ifndef __PWM_H__ #define __PWM_H__ +#include "peripheral_io.h" + /** * @brief Enumeration for Polarity */ @@ -25,14 +27,6 @@ typedef enum { PWM_POLARITY_INVERSED, } pwm_polarity_e; -/** -* @brief pwm_open() init pwm pin. -* -* @param[in] chip pwm chip number -* @param[in] pin pwm pin number -* @return On success, 0 is returned. On failure, a negative value is returned. -*/ -int pwm_open(int chip, int pin); /** * @brief pwm_close() deinit pwm pin. @@ -41,7 +35,7 @@ int pwm_open(int chip, int pin); * @param[in] pin pwm pin number * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_close(int chip, int pin); +int pwm_close(peripheral_pwm_h pwm); /** * @brief pwm_set_period() sets the pwm period. @@ -51,17 +45,7 @@ int pwm_close(int chip, int pin); * @param[in] period pwm period * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_period(int chip, int pin, int period); - -/** -* @brief pwm_get_period() gets the pwm period. -* -* @param[in] chip pwm chip number -* @param[in] pin pwm pin number -* @param[out] period pwm period -* @return On success, 0 is returned. On failure, a negative value is returned. -*/ -int pwm_get_period(int chip, int pin, int *period); +int pwm_set_period(peripheral_pwm_h pwm, int period); /** * @brief pwm_set_duty_cycle() sets the pwm duty cycle. @@ -71,17 +55,7 @@ int pwm_get_period(int chip, int pin, int *period); * @param[in] duty_cycle pwm duty cycle * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_duty_cycle(int chip, int pin, int duty_cycle); - -/** -* @brief pwm_get_duty_cycle() gets the pwm duty cycle. -* -* @param[in] chip pwm chip number -* @param[in] pin pwm pin number -* @param[out] duty_cycle pwm duty cycle -* @return On success, 0 is returned. On failure, a negative value is returned. -*/ -int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle); +int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); /** * @brief pwm_set_polarity() sets the pwm polarity. @@ -91,16 +65,7 @@ int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle); * @param[in] polarity pwm polarity * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_polarity(int chip, int pin, pwm_polarity_e polarity); -/** -* @brief pwm_get_polarity() gets the pwm polarity. -* -* @param[in] chip pwm chip number -* @param[in] pin pwm pin number -* @param[out] polarity pwm polarity -* @return On success, 0 is returned. On failure, a negative value is returned. -*/ -int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity); +int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity); /** * @brief pwm_set_enable() sets the pwm state. @@ -110,16 +75,6 @@ int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity); * @param[in] enable pwm enable/disabled state value * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_enable(int chip, int pin, bool enable); - -/** -* @brief pwm_get_enable() checks if pwm state is enabled. -* -* @param[in] chip pwm chip number -* @param[in] pin pwm pin number -* @param[out] enable pwm enable/disabled state value -* @return On success, 0 is returned. On failure, a negative value is returned. -*/ -int pwm_get_enable(int chip, int pin, bool *enable); +int pwm_set_enable(peripheral_pwm_h pwm, bool enable); #endif /* __PWM_H__ */ diff --git a/include/interface/spi.h b/include/interface/spi.h index 9937c41..3708363 100644 --- a/include/interface/spi.h +++ b/include/interface/spi.h @@ -17,15 +17,15 @@ #ifndef __SPI_H__ #define __SPI_H__ -int spi_open(int bus, int cs, int *fd); -int spi_close(int fd); -int spi_set_mode(int fd, unsigned char mode); -int spi_set_bit_order(int fd, unsigned char lsb); -int spi_set_bits_per_word(int fd, unsigned char bits); -int spi_set_frequency(int fd, unsigned int freq); -int spi_get_buffer_size(int *bufsiz); -int spi_read(int fd, unsigned char *rxbuf, int length); -int spi_write(int fd, unsigned char *txbuf, int length); -int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length); +#include "peripheral_io.h" + +int spi_close(peripheral_spi_h spi); +int spi_set_mode(peripheral_spi_h spi, unsigned char mode); +int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb); +int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); +int spi_set_frequency(peripheral_spi_h spi, unsigned int freq); +int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length); +int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length); +int spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length); #endif /* __SPI_H__ */ diff --git a/include/interface/uart.h b/include/interface/uart.h index 413b23e..a0505ee 100644 --- a/include/interface/uart.h +++ b/include/interface/uart.h @@ -17,6 +17,8 @@ #ifndef __UART_H__ #define __UART_H__ +#include "peripheral_io.h" + #include /** @@ -72,29 +74,12 @@ typedef enum { } uart_stop_bits_e; /** -* @brief uart_valid_baudrate() validation check of input baudrate -* -* @param[in] baudrate baudrate for uart -* @return On success, valid input. On failure, NULL is returned. -*/ -int uart_valid_baud_rate(unsigned int baud_rate); - -/** -* @brief uart_open() initializes uart port. -* -* @param[in] port uart port -* @param[in] file_hndl handle of uart port -* @return On success, handle of uart_context is returned. On failure, NULL is returned. -*/ -int uart_open(int port, int *file_hndl); - -/** * @brief uart_close() closes uart port. * * @param[in] file_hndl handle of uart_context * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_close(int file_hndl); +int uart_close(peripheral_uart_h uart); /** * @brief uart_flush() flushes uart buffer. @@ -102,7 +87,7 @@ int uart_close(int file_hndl); * @param[in] file_hndl handle of uart_context * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_flush(int file_hndl); +int uart_flush(peripheral_uart_h uart); /** * @brief uart_set_baudrate() sets uart baud rate. @@ -111,7 +96,7 @@ int uart_flush(int file_hndl); * @param[in] baud uart baud rate * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud); +int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud); /** * @brief uart_set_mode() sets byte size, parity bit and stop bits. @@ -122,7 +107,7 @@ int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud); * @param[in] stop_bits uart stop bits * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); +int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); /** * @brief peripheral_bus_uart_set_byte_size() set byte size. @@ -131,7 +116,7 @@ int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parit * @param[in] byte_size uart byte size * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size); +int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size); /** * @brief peripheral_bus_uart_set_parity() set parity bit. @@ -140,7 +125,7 @@ int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size); * @param[in] parity uart parity type (even/odd/none) * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_parity(int file_hndl, uart_parity_e parity); +int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity); /** * @brief peripheral_bus_uart_set_stop_bits() set stop bits. @@ -149,7 +134,7 @@ int uart_set_parity(int file_hndl, uart_parity_e parity); * @param[in] stop_bits uart stop bits * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits); +int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits); /** * @brief uart_set_flow_control() set flow control settings. @@ -159,7 +144,7 @@ int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits); * @param[in] rtscts rts/cts * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts); +int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); /** * @brief uart_read() reads data over uart bus. @@ -169,7 +154,7 @@ int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts); * @param[in] length size to read * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_read(int file_hndl, uint8_t *buf, unsigned int length); +int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length); /** * @brief uart_write() writes data over uart bus. @@ -179,7 +164,7 @@ int uart_read(int file_hndl, uint8_t *buf, unsigned int length); * @param[in] length size to write * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_write(int file_hndl, uint8_t *buf, unsigned int length); +int uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length); #endif /* __UART_H__ */ diff --git a/src/interface/gpio.c b/src/interface/gpio.c index 77c73c8..352e8c9 100644 --- a/src/interface/gpio.c +++ b/src/interface/gpio.c @@ -24,252 +24,85 @@ #include "gpio.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #define MAX_ERR_LEN 255 -int gpio_open(int gpiopin) +int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir) { - int fd, len, status; - char gpio_export[GPIO_BUFFER_MAX] = {0, }; - - _D("gpiopin : %d", gpiopin); - - fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/export :%s\n", errmsg); - return -ENXIO; - } - - len = snprintf(gpio_export, GPIO_BUFFER_MAX, "%d", gpiopin); - status = write(fd, gpio_export, len); - - if (status != len) { - close(fd); - _E("Error: gpio open error \n"); - return -EIO; - } - - close(fd); - - return 0; -} - -int gpio_set_direction(int gpiopin, gpio_direction_e dir) -{ - int fd, status; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - - _D("gpiopin : %d, dir : %d", gpiopin, dir); - - snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/direction", gpiopin); - fd = open(gpio_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d/direction: %s\n", gpiopin, errmsg); - return -ENXIO; - } + int status; if (dir == GPIO_DIRECTION_IN) - status = write(fd, "in", strlen("in")+1); + status = write(gpio->fd_direction, "in", strlen("in")+1); else if (dir == GPIO_DIRECTION_OUT_HIGH) - status = write(fd, "high", strlen("high")+1); + status = write(gpio->fd_direction, "high", strlen("high")+1); else if (dir == GPIO_DIRECTION_OUT_LOW) - status = write(fd, "low", strlen("low")+1); + status = write(gpio->fd_direction, "low", strlen("low")+1); else { - close(fd); _E("Error: gpio direction is wrong\n"); return -EIO; } if (status <= 0) { - close(fd); _E("Error: gpio direction set error\n"); return -EIO; } - close(fd); - return 0; } -int gpio_get_direction(int gpiopin, gpio_direction_e *dir) +int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge) { - int fd, len; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - char gpio_buf[GPIO_BUFFER_MAX] = {0, }; - - snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/direction", gpiopin); - fd = open(gpio_dev, O_RDONLY); - - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d/direction: %s\n", gpiopin, errmsg); - return -ENXIO; - } - - len = read(fd, &gpio_buf, GPIO_BUFFER_MAX); - if (len <= 0) { - close(fd); - _E("Error: gpio direction read error\n"); - return -EIO; - } - - if (0 == strncmp(gpio_buf, "in", strlen("in"))) - *dir = GPIO_DIRECTION_IN; - else if (0 == strncmp(gpio_buf, "out", strlen("out"))) - *dir = GPIO_DIRECTION_OUT_LOW; - else { - close(fd); - _E("Error: gpio direction is wrong\n"); - return -EIO; - } - - close(fd); - - return 0; -} - -int gpio_set_edge_mode(int gpiopin, gpio_edge_e edge) -{ - int fd, status; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - - _D("gpiopin : %d, edge : %d", gpiopin, edge); - - snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/edge", gpiopin); - fd = open(gpio_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d/edge: %s\n", gpiopin, errmsg); - return -ENXIO; - } + int status; if (edge == GPIO_EDGE_NONE) - status = write(fd, "none", strlen("none")+1); + status = write(gpio->fd_edge, "none", strlen("none")+1); else if (edge == GPIO_EDGE_RISING) - status = write(fd, "rising", strlen("rising")+1); + status = write(gpio->fd_edge, "rising", strlen("rising")+1); else if (edge == GPIO_EDGE_FALLING) - status = write(fd, "falling", strlen("falling")+1); + status = write(gpio->fd_edge, "falling", strlen("falling")+1); else if (edge == GPIO_EDGE_BOTH) - status = write(fd, "both", strlen("both")+1); + status = write(gpio->fd_edge, "both", strlen("both")+1); else { - close(fd); _E("Error: gpio edge is wrong\n"); return -EIO; } if (status <= 0) { - close(fd); _E("Error: gpio edge set error\n"); return -EIO; } - close(fd); - - return 0; -} - -int gpio_get_edge_mode(int gpiopin, gpio_edge_e *edge) -{ - int fd, len; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - char gpio_buf[GPIO_BUFFER_MAX] = {0, }; - - snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/edge", gpiopin); - fd = open(gpio_dev, O_RDONLY); - - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d/edge: %s\n", gpiopin, errmsg); - return -ENXIO; - } - - len = read(fd, &gpio_buf, GPIO_BUFFER_MAX); - if (len <= 0) { - close(fd); - _E("Error: gpio edge read error\n"); - return -EIO; - } - - if (0 == strncmp(gpio_buf, "none", strlen("none"))) - *edge = GPIO_EDGE_NONE; - else if (0 == strncmp(gpio_buf, "both", strlen("both"))) - *edge = GPIO_EDGE_BOTH; - else if (0 == strncmp(gpio_buf, "rising", strlen("rising"))) - *edge = GPIO_EDGE_RISING; - else if (0 == strncmp(gpio_buf, "falling", strlen("falling"))) - *edge = GPIO_EDGE_FALLING; - else { - close(fd); - _E("Error: gpio edge is wrong\n"); - return -EIO; - } - - close(fd); - return 0; } -int gpio_write(int gpiopin, int value) +int gpio_write(peripheral_gpio_h gpio, int value) { - int fd, status; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - - snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); - fd = open(gpio_dev, O_WRONLY); - - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d/value: %s\n", gpiopin, errmsg); - return -ENXIO; - } + int status; if (value == 1) - status = write(fd, "1", strlen("1")+1); + status = write(gpio->fd_value, "1", strlen("1")+1); else if (value == 0) - status = write(fd, "0", strlen("0")+1); + status = write(gpio->fd_value, "0", strlen("0")+1); else { - close(fd); _E("Error: gpio write value error \n"); return -EIO; } if (status <= 0) { - close(fd); _E("Error: gpio write error\n"); return -EIO; } - close(fd); - return 0; } -int gpio_read(int gpiopin, int *value) +int gpio_read(peripheral_gpio_h gpio, int *value) { - int fd, len; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; + int len; char gpio_buf[GPIO_BUFFER_MAX] = {0, }; - snprintf(gpio_dev, GPIO_BUFFER_MAX, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); - fd = open(gpio_dev, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg); - return -ENXIO; - } - - len = read(fd, &gpio_buf, 1); - close(fd); - + len = read(gpio->fd_value, &gpio_buf, 1); if (len <= 0) { _E("Error: gpio read error \n"); return -EIO; @@ -287,87 +120,58 @@ int gpio_read(int gpiopin, int *value) return 0; } -int gpio_close(int gpiopin) +int gpio_close(peripheral_gpio_h gpio) { - int fd, len, status; - char gpio_unexport[GPIO_BUFFER_MAX] = {0, }; - - _D("gpiopin : %d", gpiopin); + int status; - fd = open(SYSFS_GPIO_DIR "/unexport", O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/unexport %s\n", errmsg); - return -ENXIO; + status = close(gpio->fd_direction); + if (status < 0) { + _E("Error: gpio direction fd close error \n"); + return -EIO; } - len = snprintf(gpio_unexport, GPIO_BUFFER_MAX, "%d", gpiopin); - status = write(fd, gpio_unexport, len); - - if (status != len) { - close(fd); - _E("Error: gpio close error \n"); + status = close(gpio->fd_edge); + if (status < 0) { + _E("Error: gpio edge fd close error \n"); return -EIO; } - close(fd); + status = close(gpio->fd_value); + if (status < 0) { + _E("Error: gpio value fd close error \n"); + return -EIO; + } return 0; } -int gpio_open_isr(int gpiopin) +int gpio_open_isr(peripheral_gpio_h gpio) { - int fd; - char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - - snprintf(gpio_dev, sizeof(gpio_dev)-1, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); + // int fd; + // char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - _D("open isr string [%s]", gpio_dev); + // snprintf(gpio_dev, sizeof(gpio_dev)-1, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); - fd = open(gpio_dev, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg); - return -ENXIO; - } - - return fd; -} + // _D("open isr string [%s]", gpio_dev); -int gpio_close_isr(int fd) -{ - if (fd <= 0) return -EINVAL; + // fd = open(gpio_dev, O_RDONLY); + // if (fd < 0) { + // char errmsg[MAX_ERR_LEN]; + // strerror_r(errno, errmsg, MAX_ERR_LEN); + // _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg); + // return -ENXIO; + // } - close(fd); + // return fd; return 0; } -int gpio_read_isr(void *fdset, char *rev_buf, int length) +int gpio_close_isr(peripheral_gpio_h gpio) { - int poll_state = 0; - int len; - struct pollfd poll_events; - - poll_events.fd = ((struct pollfd*)fdset)->fd; - poll_events.events = POLLPRI; - poll_events.revents = ((struct pollfd*)fdset)->revents; - - poll_state = poll((struct pollfd*)&poll_events, 1, -1); // 0 is going to return directly. - - if (poll_state < 0) { - _E("poll() failed!\n"); - return -EIO; - } +// if (fd <= 0) return -EINVAL; - if (poll_events.revents & POLLPRI) { - lseek(poll_events.fd, 0, SEEK_SET); - len = read(poll_events.fd, rev_buf, length); - if (len == -1) - return -EIO; - } +// close(fd); - return poll_state; -} + return 0; +} \ No newline at end of file diff --git a/src/interface/i2c.c b/src/interface/i2c.c index 0907cce..fec6ea2 100644 --- a/src/interface/i2c.c +++ b/src/interface/i2c.c @@ -24,111 +24,91 @@ #include "i2c.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #define MAX_ERR_LEN 255 -int i2c_open(int bus, int *fd) -{ - int new_fd; - char i2c_dev[I2C_BUFFER_MAX] = {0,}; - - _D("bus : %d", bus); - - snprintf(i2c_dev, sizeof(i2c_dev)-1, SYSFS_I2C_DIR"-%d", bus); - new_fd = open(i2c_dev, O_RDWR); - if (new_fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s : %s", i2c_dev, errmsg); - return -ENXIO; - } - _D("fd : %d", new_fd); - *fd = new_fd; - - return 0; -} - -int i2c_close(int fd) +int i2c_close(peripheral_i2c_h i2c) { int status; - _D("fd : %d", fd); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d", i2c->fd); + RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); - status = close(fd); + status = close(i2c->fd); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d", fd); + _E("Failed to close fd : %d", i2c->fd); return -EIO; } return 0; } -int i2c_set_address(int fd, int address) +int i2c_set_address(peripheral_i2c_h i2c, int address) { int status; - _D("fd : %d, slave address : 0x%x", fd, address); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d, slave address : 0x%x", i2c->fd, address); + RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); - status = ioctl(fd, I2C_SLAVE, address); + status = ioctl(i2c->fd, I2C_SLAVE, address); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set slave address(%x), fd : %d, errmsg : %s", address, fd, errmsg); + _E("Failed to set slave address(%x), fd : %d, errmsg : %s", address, i2c->fd, errmsg); return status; } return 0; } -int i2c_read(int fd, unsigned char *data, int length) +int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length) { int status; - RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - status = read(fd, data, length); + status = read(i2c->fd, data, length); if (status != length) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("i2c read failed, fd : %d, errmsg : %s", fd, errmsg); + _E("i2c read failed, fd : %d, errmsg : %s", i2c->fd, errmsg); return -EIO; } return 0; } -int i2c_write(int fd, const unsigned char *data, int length) +int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length) { int status; - RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - status = write(fd, data, length); + status = write(i2c->fd, data, length); if (status != length) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("i2c write failed fd : %d, errmsg : %s", fd, errmsg); + _E("i2c write failed fd : %d, errmsg : %s", i2c->fd, errmsg); return -EIO; } return 0; } -int i2c_smbus_ioctl(int fd, struct i2c_smbus_ioctl_data *data) +int i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) { int status; - RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - status = ioctl(fd, I2C_SMBUS, data); + status = ioctl(i2c->fd, I2C_SMBUS, data); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("i2c transaction failed fd : %d, errmsg : %s", fd, errmsg); + _E("i2c transaction failed fd : %d, errmsg : %s", i2c->fd, errmsg); return -EIO; } diff --git a/src/interface/pwm.c b/src/interface/pwm.c index 2b6ebd8..2d34ec7 100644 --- a/src/interface/pwm.c +++ b/src/interface/pwm.c @@ -24,6 +24,7 @@ #include "pwm.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #define SYSFS_PWM_PATH "/sys/class/pwm" @@ -31,304 +32,99 @@ #define PWM_BUF_MAX 16 #define MAX_ERR_LEN 255 -int pwm_open(int chip, int pin) +int pwm_close(peripheral_pwm_h pwm) { - int fd, len, status; - char pwm_dev[PATH_BUF_MAX] = {0}; - char pwm_buf[PWM_BUF_MAX] = {0}; - - _D("chip : %d, pin : %d", chip, pin); + int status; - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/export", chip); - fd = open(pwm_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", pin); - status = write(fd, pwm_buf, len); + status = close(pwm->fd_period); if (status < 0) { - _E("Failed to export pwmchip%d, pwm%d", chip, pin); - close(fd); + _E("Error: pwm period fd close error \n"); return -EIO; } - close(fd); - - return 0; -} - -int pwm_close(int chip, int pin) -{ - int fd, len, status; - char pwm_dev[PATH_BUF_MAX] = {0}; - char pwm_buf[PWM_BUF_MAX] = {0}; - _D("chip : %d, pin : %d", chip, pin); - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/unexport", chip); - fd = open(pwm_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", pin); - status = write(fd, pwm_buf, len); + status = close(pwm->fd_duty_cycle); if (status < 0) { - _E("Failed to unexport pwmchip%d, pwm%", chip, pin); - close(fd); + _E("Error: pwm duty cycle fd close error \n"); return -EIO; } - close(fd); - - return 0; -} - -int pwm_set_period(int chip, int pin, int period) -{ - int fd, len, status; - char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - _D("chip : %d, pin : %d, period : %d", chip, pin, period); - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", chip, pin); - fd = open(pwm_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period); - status = write(fd, pwm_buf, len); + status = close(pwm->fd_polarity); if (status < 0) { - close(fd); - _E("Failed to set period, path : %s", pwm_dev); + _E("Error: pwm polarity fd close error \n"); return -EIO; } - close(fd); - - return 0; -} - -int pwm_get_period(int chip, int pin, int *period) -{ - int fd, result, status; - char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/period", chip, pin); - fd = open(pwm_dev, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - status = read(fd, pwm_buf, PWM_BUF_MAX); + status = close(pwm->fd_enable); if (status < 0) { - close(fd); - _E("Failed to get period, path : %s", pwm_dev); + _E("Error: pwm enable fd close error \n"); return -EIO; } - result = atoi(pwm_buf); - *period = result; - close(fd); return 0; } -int pwm_set_duty_cycle(int chip, int pin, int duty_cycle) +int pwm_set_period(peripheral_pwm_h pwm, int period) { - int fd, len, status; + int len, status; char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - _D("chip : %d, pin : %d, duty_cycle : %d", chip, pin, duty_cycle); - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", chip, pin); - fd = open(pwm_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - - len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle); - status = write(fd, pwm_buf, len); + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period); + status = write(pwm->fd_period, pwm_buf, len); if (status < 0) { - close(fd); - _E("Failed to set duty cycle, path : %s", pwm_dev); + _E("Failed to set period"); return -EIO; } - close(fd); return 0; } -int pwm_get_duty_cycle(int chip, int pin, int *duty_cycle) +int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) { - int fd, result, status; + int len, status; char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/duty_cycle", chip, pin); - fd = open(pwm_dev, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - status = read(fd, pwm_buf, PWM_BUF_MAX); + len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle); + status = write(pwm->fd_duty_cycle, pwm_buf, len); if (status < 0) { - close(fd); - _E("Failed to get duty cycle, path : %s", pwm_dev); + _E("Failed to set duty cycle"); return -EIO; } - result = atoi(pwm_buf); - *duty_cycle = result; - close(fd); return 0; } -int pwm_set_polarity(int chip, int pin, pwm_polarity_e polarity) +int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity) { - int fd, status; - char pwm_dev[PATH_BUF_MAX] = {0}; - - _D("chip : %d, pin : %d, polarity : %d", chip, pin, polarity); - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", chip, pin); - fd = open(pwm_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } + int status; if (polarity == PWM_POLARITY_NORMAL) - status = write(fd, "normal", strlen("normal")+1); + status = write(pwm->fd_polarity, "normal", strlen("normal")+1); else if (polarity == PWM_POLARITY_INVERSED) - status = write(fd, "inversed", strlen("inversed")+1); + status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1); else { _E("Invalid pwm polarity : %d", polarity); - close(fd); return -EINVAL; } if (status <= 0) { - close(fd); - _E("Failed to set polarity, path : %s", pwm_dev); + _E("Failed to set polarity"); return -EIO; } - close(fd); return 0; } -int pwm_get_polarity(int chip, int pin, pwm_polarity_e *polarity) +int pwm_set_enable(peripheral_pwm_h pwm, bool enable) { - int fd, status; + int len, status; char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/polarity", chip, pin); - fd = open(pwm_dev, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - - status = read(fd, pwm_buf, PWM_BUF_MAX); - if (status < 0) { - _E("Failed to get polarity, path : %s", pwm_dev); - close(fd); - return -EIO; - } - - if (0 == strncmp(pwm_buf, "normal", strlen("normal"))) - *polarity = PWM_POLARITY_NORMAL; - else if (0 == strncmp(pwm_buf, "inversed", strlen("inversed"))) - *polarity = PWM_POLARITY_INVERSED; - else { - close(fd); - _E("Invalid pwm polarity : %d", pwm_buf); - return -EIO; - } - close(fd); - - return 0; -} - -int pwm_set_enable(int chip, int pin, bool enable) -{ - int fd, len, status; - char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - - _D("chip : %d, pin : %d, enable : %d", chip, pin, enable); - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", chip, pin); - fd = open(pwm_dev, O_WRONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable); - status = write(fd, pwm_buf, len); - if (status < 0) { - close(fd); - _E("Failed to set enable, path : %s", pwm_dev); - return -EIO; - } - close(fd); - - return 0; -} - -int pwm_get_enable(int chip, int pin, bool *enable) -{ - int fd, result, status; - char pwm_buf[PWM_BUF_MAX] = {0}; - char pwm_dev[PATH_BUF_MAX] = {0}; - - snprintf(pwm_dev, PATH_BUF_MAX, SYSFS_PWM_PATH "/pwmchip%d/pwm%d/enable", chip, pin); - fd = open(pwm_dev, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", pwm_dev, errmsg); - return -ENXIO; - } - - status = read(fd, pwm_buf, PWM_BUF_MAX); + status = write(pwm->fd_enable, pwm_buf, len); if (status < 0) { - close(fd); - _E("Failed to get enable, path : %s", pwm_dev); + _E("Failed to set enable"); return -EIO; } - result = atoi(pwm_buf); - *enable = !!result; - close(fd); return 0; } - diff --git a/src/interface/spi.c b/src/interface/spi.c index 1016a9e..c212792 100644 --- a/src/interface/spi.c +++ b/src/interface/spi.c @@ -25,60 +25,39 @@ #include "spi.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #define SYSFS_SPI_DIR "/dev/spidev" #define SYSFS_SPI_BUFSIZ "/sys/module/spidev/parameters/bufsiz" #define SPI_BUFFER_MAX 64 #define MAX_ERR_LEN 255 -int spi_open(int bus, int cs, int *fd) -{ - int new_fd = 0; - char spi_dev[SPI_BUFFER_MAX] = {0,}; - - _D("bus : %d, cs : %d", bus, cs); - - snprintf(spi_dev, sizeof(spi_dev)-1, SYSFS_SPI_DIR"%d.%d", bus, cs); - - new_fd = open(spi_dev, O_RDWR); - if (new_fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", spi_dev, errmsg); - return -ENXIO; - } - _D("fd : %d", new_fd); - *fd = new_fd; - - return 0; -} - -int spi_close(int fd) +int spi_close(peripheral_spi_h spi) { int status; - _D("fd : %d", fd); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d", spi->fd); + RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - status = close(fd); + status = close(spi->fd); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d", fd); + _E("Failed to close fd : %d", spi->fd); return -EIO; } return 0; } -int spi_set_mode(int fd, unsigned char mode) +int spi_set_mode(peripheral_spi_h spi, unsigned char mode) { int status; - _D("fd : %d, mode : %d", fd, mode); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d, mode : %d", spi->fd, mode); + RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - status = ioctl(fd, SPI_IOC_WR_MODE, &mode); + status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -89,120 +68,94 @@ int spi_set_mode(int fd, unsigned char mode) return 0; } -int spi_set_bit_order(int fd, unsigned char lsb) +int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb) { int status; - _D("fd : %d, lsb : %d", fd, lsb); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d, lsb : %d", spi->fd, lsb); + RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - status = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb); + status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &lsb); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", lsb, fd, errmsg); + _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", lsb, spi->fd, errmsg); return -EIO; } return 0; } -int spi_set_bits_per_word(int fd, unsigned char bits) +int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) { int status; - _D("fd : %d, bits : %d", fd, bits); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d, bits : %d", spi->fd, bits); + RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - status = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); + status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set bits(%d), fd : %d, errmsg : %s", bits, fd, errmsg); + _E("Failed to set bits(%d), fd : %d, errmsg : %s", bits, spi->fd, errmsg); return -EIO; } return 0; } -int spi_set_frequency(int fd, unsigned int freq) +int spi_set_frequency(peripheral_spi_h spi, unsigned int freq) { int status; - _D("fd : %d, freq : %d", fd, freq); - RETVM_IF(fd < 0, -EINVAL, "Invalid fd"); + _D("fd : %d, freq : %d", spi->fd, freq); + RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - status = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); + status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to set frequency(%d), fd : %d, errmsg : %s", freq, fd, errmsg); - return -EIO; - } - - return 0; -} - -int spi_get_buffer_size(int *bufsiz) -{ - int fd, result, status; - char spi_buf[SPI_BUFFER_MAX] = {0,}; - - fd = open(SYSFS_SPI_BUFSIZ, O_RDONLY); - if (fd < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Can't Open %s, errmsg : %s", SYSFS_SPI_BUFSIZ, errmsg); - return -ENXIO; - } - - status = read(fd, spi_buf, SPI_BUFFER_MAX); - if (status < 0) { - _E("Failed to get buffer size, path : %s", SYSFS_SPI_BUFSIZ); - close(fd); + _E("Failed to set frequency(%d), fd : %d, errmsg : %s", freq, spi->fd, errmsg); return -EIO; } - result = atoi(spi_buf); - *bufsiz = result; - close(fd); return 0; } -int spi_read(int fd, unsigned char *rxbuf, int length) +int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length) { int status; struct spi_ioc_transfer xfer; - RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + 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; - status = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer); + status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to read data, fd : %d, length : %d, errmsg : %s", fd, length, errmsg); + _E("Failed to read data, fd : %d, length : %d, errmsg : %s", spi->fd, length, errmsg); return -EIO; } return 0; } -int spi_write(int fd, unsigned char *txbuf, int length) +int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length) { int status; struct spi_ioc_transfer xfer; - RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + 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; - status = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer); + status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -213,12 +166,12 @@ int spi_write(int fd, unsigned char *txbuf, int length) return 0; } -int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length) +int spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length) { int status; struct spi_ioc_transfer xfer; - RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd); + RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); if (!txbuf || !rxbuf || length < 0) return -EINVAL; @@ -227,7 +180,7 @@ int spi_transfer(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length) xfer.rx_buf = (unsigned long)rxbuf; xfer.len = length; - status = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer); + status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); diff --git a/src/interface/uart.c b/src/interface/uart.c index 34ff11e..fcddde9 100644 --- a/src/interface/uart.c +++ b/src/interface/uart.c @@ -26,6 +26,7 @@ #include "uart.h" #include "peripheral_common.h" +#include "peripheral_internal.h" #define PATH_BUF_MAX 64 #define UART_BUF_MAX 16 @@ -52,69 +53,46 @@ static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = { static const int byteinfo[4] = {CS5, CS6, CS7, CS8}; -int uart_open(int port, int *file_hndl) -{ - int i, fd; - char uart_dev[PATH_BUF_MAX] = {0}; - - _D("port : %d", port); - - for (i = 0; i < ARRAY_SIZE(sysfs_uart_path); i++) { - snprintf(uart_dev, PATH_BUF_MAX, "%s%d", sysfs_uart_path[i], port); - if (access(uart_dev, F_OK) == 0) - break; - } - _D("uart_dev : %s", uart_dev); - if ((fd = open(uart_dev, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("can't open %s, errmsg : %s", uart_dev, errmsg); - return -ENXIO; - } - *file_hndl = fd; - return 0; -} - -int uart_close(int file_hndl) +int uart_close(peripheral_uart_h uart) { int status; - _D("file_hndl : %d", file_hndl); + _D("file_hndl : %d", uart->fd); - if (file_hndl < 0) { + if (uart->fd < 0) { _E("Invalid NULL parameter"); return -EINVAL; } - status = uart_flush(file_hndl); + status = uart_flush(uart); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d, errmsg : %s", file_hndl, errmsg); + _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg); return -EIO; } - status = close(file_hndl); + status = close(uart->fd); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("Failed to close fd : %d, errmsg : %s", file_hndl, errmsg); + _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg); return -EIO; } return 0; } -int uart_flush(int file_hndl) +int uart_flush(peripheral_uart_h uart) { int ret; - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } - ret = tcflush(file_hndl, TCIOFLUSH); + ret = tcflush(uart->fd, TCIOFLUSH); if (ret < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -125,15 +103,15 @@ int uart_flush(int file_hndl) return 0; } -int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud) +int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud) { int ret; struct termios tio; - _D("file_hndl : %d, baud : %d", file_hndl, baud); + _D("file_hndl : %d, baud : %d", uart->fd, baud); memset(&tio, 0, sizeof(tio)); - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } @@ -143,7 +121,7 @@ int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud) return -EINVAL; } - ret = tcgetattr(file_hndl, &tio); + ret = tcgetattr(uart->fd, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -157,8 +135,8 @@ int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud) tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; - uart_flush(file_hndl); - ret = tcsetattr(file_hndl, TCSANOW, &tio); + uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -169,14 +147,14 @@ int uart_set_baud_rate(int file_hndl, uart_baud_rate_e baud) return 0; } -int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) +int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) { int ret; struct termios tio; - _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", file_hndl, byte_size, parity, stop_bits); + _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", uart->fd, byte_size, parity, stop_bits); - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } @@ -186,7 +164,7 @@ int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parit return -EINVAL; } - ret = tcgetattr(file_hndl, &tio); + ret = tcgetattr(uart->fd, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -229,8 +207,8 @@ int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parit return -EINVAL; } - uart_flush(file_hndl); - ret = tcsetattr(file_hndl, TCSANOW, &tio); + uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -241,14 +219,14 @@ int uart_set_mode(int file_hndl, uart_byte_size_e byte_size, uart_parity_e parit return 0; } -int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size) +int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size) { int ret; struct termios tio; - _D("file_hndl : %d, bytesize : %d", file_hndl, byte_size); + _D("file_hndl : %d, bytesize : %d", uart->fd, byte_size); - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } @@ -258,7 +236,7 @@ int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size) return -EINVAL; } - ret = tcgetattr(file_hndl, &tio); + ret = tcgetattr(uart->fd, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -271,8 +249,8 @@ int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size) tio.c_cflag |= byteinfo[byte_size]; tio.c_cflag |= (CLOCAL | CREAD); - uart_flush(file_hndl); - ret = tcsetattr(file_hndl, TCSANOW, &tio); + uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -283,19 +261,19 @@ int uart_set_byte_size(int file_hndl, uart_byte_size_e byte_size) return 0; } -int uart_set_parity(int file_hndl, uart_parity_e parity) +int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity) { int ret; struct termios tio; - _D("file_hndl : %d, parity : %d", file_hndl, parity); + _D("file_hndl : %d, parity : %d", uart->fd, parity); - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } - ret = tcgetattr(file_hndl, &tio); + ret = tcgetattr(uart->fd, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -320,8 +298,8 @@ int uart_set_parity(int file_hndl, uart_parity_e parity) break; } - uart_flush(file_hndl); - ret = tcsetattr(file_hndl, TCSANOW, &tio); + uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -332,19 +310,19 @@ int uart_set_parity(int file_hndl, uart_parity_e parity) return 0; } -int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits) +int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits) { int ret; struct termios tio; - _D("file_hndl : %d, stopbits : %d", file_hndl, stop_bits); + _D("file_hndl : %d, stopbits : %d", uart->fd, stop_bits); - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } - ret = tcgetattr(file_hndl, &tio); + ret = tcgetattr(uart->fd, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -365,8 +343,8 @@ int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits) return -EINVAL; } - uart_flush(file_hndl); - ret = tcsetattr(file_hndl, TCSANOW, &tio); + uart_flush(uart); + ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -377,19 +355,19 @@ int uart_set_stop_bits(int file_hndl, uart_stop_bits_e stop_bits) return 0; } -int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts) +int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) { int ret; struct termios tio; - _D("file_hndl : %d, xonxoff : %d, rtscts : %d", file_hndl, xonxoff, rtscts); + _D("file_hndl : %d, xonxoff : %d, rtscts : %d", uart->fd, xonxoff, rtscts); - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } - ret = tcgetattr(file_hndl, &tio); + ret = tcgetattr(uart->fd, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -409,7 +387,7 @@ int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts) else tio.c_iflag &= ~(IXON | IXOFF | IXANY); - ret = tcsetattr(file_hndl, TCSANOW, &tio); + ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -420,16 +398,16 @@ int uart_set_flow_control(int file_hndl, bool xonxoff, bool rtscts) return 0; } -int uart_read(int file_hndl, uint8_t *buf, unsigned int length) +int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length) { int ret; - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } - ret = read(file_hndl, (void *)buf, length); + ret = read(uart->fd, (void *)buf, length); if (ret <= 0) { if (errno == EAGAIN) return -EAGAIN; @@ -442,16 +420,16 @@ int uart_read(int file_hndl, uint8_t *buf, unsigned int length) return ret; } -int uart_write(int file_hndl, uint8_t *buf, unsigned int length) +int uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length) { int ret; - if (!file_hndl) { + if (!uart->fd) { _E("Invalid NULL parameter"); return -EINVAL; } - ret = write(file_hndl, buf, length); + ret = write(uart->fd, buf, length); if (ret <= 0) { if (errno == EAGAIN) return -EAGAIN; -- 2.7.4 From 8c6dae8d1ae8a7e9741603539f30b99cdf0b2670 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 12:26:22 +0900 Subject: [PATCH 15/16] interface: add prefix 'peripheral_interface' to file and function name. Change-Id: I23b6fe4aa850e4a713aa6e419ab334681e596d39 Signed-off-by: Segwon --- CMakeLists.txt | 10 +++--- .../{gpio.h => peripheral_interface_gpio.h} | 21 ++++++------ .../{i2c.h => peripheral_interface_i2c.h} | 16 +++++----- .../{pwm.h => peripheral_interface_pwm.h} | 16 +++++----- include/interface/peripheral_interface_spi.h | 31 ++++++++++++++++++ .../{uart.h => peripheral_interface_uart.h} | 26 +++++++-------- include/interface/spi.h | 31 ------------------ .../{gpio.c => peripheral_interface_gpio.c} | 37 ++++++---------------- .../{i2c.c => peripheral_interface_i2c.c} | 12 +++---- .../{pwm.c => peripheral_interface_pwm.c} | 12 +++---- .../{spi.c => peripheral_interface_spi.c} | 18 +++++------ .../{uart.c => peripheral_interface_uart.c} | 34 ++++++++++---------- 12 files changed, 124 insertions(+), 140 deletions(-) rename include/interface/{gpio.h => peripheral_interface_gpio.h} (60%) rename include/interface/{i2c.h => peripheral_interface_i2c.h} (74%) rename include/interface/{pwm.h => peripheral_interface_pwm.h} (79%) create mode 100644 include/interface/peripheral_interface_spi.h rename include/interface/{uart.h => peripheral_interface_uart.h} (79%) delete mode 100644 include/interface/spi.h rename src/interface/{gpio.c => peripheral_interface_gpio.c} (77%) rename src/interface/{i2c.c => peripheral_interface_i2c.c} (84%) rename src/interface/{pwm.c => peripheral_interface_pwm.c} (86%) rename src/interface/{spi.c => peripheral_interface_spi.c} (85%) rename src/interface/{uart.c => peripheral_interface_uart.c} (87%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 714f3d0..335e42a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,11 +48,11 @@ SET(SOURCES src/peripheral_gpio.c src/peripheral_pwm.c src/peripheral_uart.c src/peripheral_spi.c - src/interface/gpio.c - src/interface/i2c.c - src/interface/pwm.c - src/interface/spi.c - src/interface/uart.c + src/interface/peripheral_interface_gpio.c + src/interface/peripheral_interface_i2c.c + src/interface/peripheral_interface_pwm.c + src/interface/peripheral_interface_spi.c + src/interface/peripheral_interface_uart.c src/peripheral_gdbus_gpio.c src/peripheral_gdbus_i2c.c src/peripheral_gdbus_pwm.c diff --git a/include/interface/gpio.h b/include/interface/peripheral_interface_gpio.h similarity index 60% rename from include/interface/gpio.h rename to include/interface/peripheral_interface_gpio.h index b4d6ccc..cf5d76c 100644 --- a/include/interface/gpio.h +++ b/include/interface/peripheral_interface_gpio.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __GPIO_H__ -#define __GPIO_H__ +#ifndef __PERIPHERAL_INTERFACE_GPIO_H__ +#define __PERIPHERAL_INTERFACE_GPIO_H__ #include "peripheral_io.h" @@ -35,12 +35,13 @@ typedef enum { GPIO_EDGE_BOTH = 3, } gpio_edge_e; -int gpio_close(peripheral_gpio_h gpio); -int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge); -int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir); -int gpio_write(peripheral_gpio_h gpio, int value); -int gpio_read(peripheral_gpio_h gpio, int *value); +int peripheral_interface_gpio_close(peripheral_gpio_h gpio); +int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge); +int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir); +int peripheral_interface_gpio_write(peripheral_gpio_h gpio, int value); +int peripheral_interface_gpio_read(peripheral_gpio_h gpio, int *value); -int gpio_open_isr(peripheral_gpio_h gpio); -int gpio_close_isr(peripheral_gpio_h gpio); -#endif/*__GPIO_H__*/ +int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio); +int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio); + +#endif/*__PERIPHERAL_INTERFACE_GPIO_H__*/ \ No newline at end of file diff --git a/include/interface/i2c.h b/include/interface/peripheral_interface_i2c.h similarity index 74% rename from include/interface/i2c.h rename to include/interface/peripheral_interface_i2c.h index 6846649..b41c555 100644 --- a/include/interface/i2c.h +++ b/include/interface/peripheral_interface_i2c.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __I2C_H__ -#define __I2C_H__ +#ifndef __PERIPHERAL_INTERFACE_I2C_H__ +#define __PERIPHERAL_INTERFACE_I2C_H__ #include @@ -57,10 +57,10 @@ struct i2c_smbus_ioctl_data { union i2c_smbus_data *data; }; -int i2c_close(peripheral_i2c_h i2c); -int i2c_set_address(peripheral_i2c_h i2c, int address); -int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length); -int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length); -int i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data); +int peripheral_interface_i2c_close(peripheral_i2c_h i2c); +int peripheral_interface_i2c_set_address(peripheral_i2c_h i2c, int address); +int peripheral_interface_i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length); +int peripheral_interface_i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length); +int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data); -#endif/* __I2C_H__ */ +#endif/* __PERIPHERAL_INTERFACE_I2C_H__ */ diff --git a/include/interface/pwm.h b/include/interface/peripheral_interface_pwm.h similarity index 79% rename from include/interface/pwm.h rename to include/interface/peripheral_interface_pwm.h index 7a9f0d0..833de2b 100644 --- a/include/interface/pwm.h +++ b/include/interface/peripheral_interface_pwm.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PWM_H__ -#define __PWM_H__ +#ifndef __PERIPHERAL_INTERFACE_PWM_H__ +#define __PERIPHERAL_INTERFACE_PWM_H__ #include "peripheral_io.h" @@ -35,7 +35,7 @@ typedef enum { * @param[in] pin pwm pin number * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_close(peripheral_pwm_h pwm); +int peripheral_interface_pwm_close(peripheral_pwm_h pwm); /** * @brief pwm_set_period() sets the pwm period. @@ -45,7 +45,7 @@ int pwm_close(peripheral_pwm_h pwm); * @param[in] period pwm period * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_period(peripheral_pwm_h pwm, int period); +int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, int period); /** * @brief pwm_set_duty_cycle() sets the pwm duty cycle. @@ -55,7 +55,7 @@ int pwm_set_period(peripheral_pwm_h pwm, int period); * @param[in] duty_cycle pwm duty cycle * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); +int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); /** * @brief pwm_set_polarity() sets the pwm polarity. @@ -65,7 +65,7 @@ int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); * @param[in] polarity pwm polarity * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity); +int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity); /** * @brief pwm_set_enable() sets the pwm state. @@ -75,6 +75,6 @@ int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity); * @param[in] enable pwm enable/disabled state value * @return On success, 0 is returned. On failure, a negative value is returned. */ -int pwm_set_enable(peripheral_pwm_h pwm, bool enable); +int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable); -#endif /* __PWM_H__ */ +#endif /* __PERIPHERAL_INTERFACE_PWM_H__ */ diff --git a/include/interface/peripheral_interface_spi.h b/include/interface/peripheral_interface_spi.h new file mode 100644 index 0000000..937caa7 --- /dev/null +++ b/include/interface/peripheral_interface_spi.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __PERIPHERAL_INTERFACE_SPI_H__ +#define __PERIPHERAL_INTERFACE_SPI_H__ + +#include "peripheral_io.h" + +int peripheral_interface_spi_close(peripheral_spi_h spi); +int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode); +int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb); +int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); +int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, unsigned int freq); +int peripheral_interface_spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length); +int peripheral_interface_spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length); +int peripheral_interface_spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length); + +#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */ diff --git a/include/interface/uart.h b/include/interface/peripheral_interface_uart.h similarity index 79% rename from include/interface/uart.h rename to include/interface/peripheral_interface_uart.h index a0505ee..f5273fe 100644 --- a/include/interface/uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __UART_H__ -#define __UART_H__ +#ifndef __PERIPHERAL_INTERFACE_UART_H__ +#define __PERIPHERAL_INTERFACE_UART_H__ #include "peripheral_io.h" @@ -79,7 +79,7 @@ typedef enum { * @param[in] file_hndl handle of uart_context * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_close(peripheral_uart_h uart); +int peripheral_interface_uart_close(peripheral_uart_h uart); /** * @brief uart_flush() flushes uart buffer. @@ -87,7 +87,7 @@ int uart_close(peripheral_uart_h uart); * @param[in] file_hndl handle of uart_context * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_flush(peripheral_uart_h uart); +int peripheral_interface_uart_flush(peripheral_uart_h uart); /** * @brief uart_set_baudrate() sets uart baud rate. @@ -96,7 +96,7 @@ int uart_flush(peripheral_uart_h uart); * @param[in] baud uart baud rate * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud); +int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud); /** * @brief uart_set_mode() sets byte size, parity bit and stop bits. @@ -107,7 +107,7 @@ int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud); * @param[in] stop_bits uart stop bits * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); +int peripheral_interface_uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); /** * @brief peripheral_bus_uart_set_byte_size() set byte size. @@ -116,7 +116,7 @@ int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parit * @param[in] byte_size uart byte size * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size); +int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size); /** * @brief peripheral_bus_uart_set_parity() set parity bit. @@ -125,7 +125,7 @@ int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size); * @param[in] parity uart parity type (even/odd/none) * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity); +int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e parity); /** * @brief peripheral_bus_uart_set_stop_bits() set stop bits. @@ -134,7 +134,7 @@ int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity); * @param[in] stop_bits uart stop bits * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits); +int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits); /** * @brief uart_set_flow_control() set flow control settings. @@ -144,7 +144,7 @@ int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits); * @param[in] rtscts rts/cts * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); +int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); /** * @brief uart_read() reads data over uart bus. @@ -154,7 +154,7 @@ int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); * @param[in] length size to read * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length); +int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length); /** * @brief uart_write() writes data over uart bus. @@ -164,7 +164,7 @@ int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length); * @param[in] length size to write * @return On success, 0 is returned. On failure, a negative value is returned. */ -int uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length); +int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length); -#endif /* __UART_H__ */ +#endif /* __PERIPHERAL_INTERFACE_UART_H__ */ diff --git a/include/interface/spi.h b/include/interface/spi.h deleted file mode 100644 index 3708363..0000000 --- a/include/interface/spi.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __SPI_H__ -#define __SPI_H__ - -#include "peripheral_io.h" - -int spi_close(peripheral_spi_h spi); -int spi_set_mode(peripheral_spi_h spi, unsigned char mode); -int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb); -int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); -int spi_set_frequency(peripheral_spi_h spi, unsigned int freq); -int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length); -int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length); -int spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length); - -#endif /* __SPI_H__ */ diff --git a/src/interface/gpio.c b/src/interface/peripheral_interface_gpio.c similarity index 77% rename from src/interface/gpio.c rename to src/interface/peripheral_interface_gpio.c index 352e8c9..e4620ca 100644 --- a/src/interface/gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -22,13 +22,13 @@ #include #include -#include "gpio.h" +#include "peripheral_interface_gpio.h" #include "peripheral_common.h" #include "peripheral_internal.h" #define MAX_ERR_LEN 255 -int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir) +int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir) { int status; @@ -51,7 +51,7 @@ int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir) return 0; } -int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge) +int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge) { int status; @@ -76,7 +76,7 @@ int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge) return 0; } -int gpio_write(peripheral_gpio_h gpio, int value) +int peripheral_interface_gpio_write(peripheral_gpio_h gpio, int value) { int status; @@ -97,7 +97,7 @@ int gpio_write(peripheral_gpio_h gpio, int value) return 0; } -int gpio_read(peripheral_gpio_h gpio, int *value) +int peripheral_interface_gpio_read(peripheral_gpio_h gpio, int *value) { int len; char gpio_buf[GPIO_BUFFER_MAX] = {0, }; @@ -120,7 +120,7 @@ int gpio_read(peripheral_gpio_h gpio, int *value) return 0; } -int gpio_close(peripheral_gpio_h gpio) +int peripheral_interface_gpio_close(peripheral_gpio_h gpio) { int status; @@ -145,33 +145,16 @@ int gpio_close(peripheral_gpio_h gpio) return 0; } -int gpio_open_isr(peripheral_gpio_h gpio) +int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio) { - // int fd; - // char gpio_dev[GPIO_BUFFER_MAX] = {0, }; - - // snprintf(gpio_dev, sizeof(gpio_dev)-1, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin); - - // _D("open isr string [%s]", gpio_dev); - - // fd = open(gpio_dev, O_RDONLY); - // if (fd < 0) { - // char errmsg[MAX_ERR_LEN]; - // strerror_r(errno, errmsg, MAX_ERR_LEN); - // _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg); - // return -ENXIO; - // } - - // return fd; + // TODO: set interrupted callback function return 0; } -int gpio_close_isr(peripheral_gpio_h gpio) +int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio) { -// if (fd <= 0) return -EINVAL; - -// close(fd); + // TODO: unset interrupted callback function return 0; } \ No newline at end of file diff --git a/src/interface/i2c.c b/src/interface/peripheral_interface_i2c.c similarity index 84% rename from src/interface/i2c.c rename to src/interface/peripheral_interface_i2c.c index fec6ea2..9da17bd 100644 --- a/src/interface/i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -22,13 +22,13 @@ #include #include -#include "i2c.h" +#include "peripheral_interface_i2c.h" #include "peripheral_common.h" #include "peripheral_internal.h" #define MAX_ERR_LEN 255 -int i2c_close(peripheral_i2c_h i2c) +int peripheral_interface_i2c_close(peripheral_i2c_h i2c) { int status; @@ -46,7 +46,7 @@ int i2c_close(peripheral_i2c_h i2c) return 0; } -int i2c_set_address(peripheral_i2c_h i2c, int address) +int peripheral_interface_i2c_set_address(peripheral_i2c_h i2c, int address) { int status; @@ -64,7 +64,7 @@ int i2c_set_address(peripheral_i2c_h i2c, int address) return 0; } -int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length) +int peripheral_interface_i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length) { int status; @@ -81,7 +81,7 @@ int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length) return 0; } -int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length) +int peripheral_interface_i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length) { int status; @@ -98,7 +98,7 @@ int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length) return 0; } -int i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) +int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) { int status; diff --git a/src/interface/pwm.c b/src/interface/peripheral_interface_pwm.c similarity index 86% rename from src/interface/pwm.c rename to src/interface/peripheral_interface_pwm.c index 2d34ec7..a5cae4d 100644 --- a/src/interface/pwm.c +++ b/src/interface/peripheral_interface_pwm.c @@ -22,7 +22,7 @@ #include #include -#include "pwm.h" +#include "peripheral_interface_pwm.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -32,7 +32,7 @@ #define PWM_BUF_MAX 16 #define MAX_ERR_LEN 255 -int pwm_close(peripheral_pwm_h pwm) +int peripheral_interface_pwm_close(peripheral_pwm_h pwm) { int status; @@ -63,7 +63,7 @@ int pwm_close(peripheral_pwm_h pwm) return 0; } -int pwm_set_period(peripheral_pwm_h pwm, int period) +int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, int period) { int len, status; char pwm_buf[PWM_BUF_MAX] = {0}; @@ -78,7 +78,7 @@ int pwm_set_period(peripheral_pwm_h pwm, int period) return 0; } -int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) +int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) { int len, status; char pwm_buf[PWM_BUF_MAX] = {0}; @@ -93,7 +93,7 @@ int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) return 0; } -int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity) +int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity) { int status; @@ -114,7 +114,7 @@ int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity) return 0; } -int pwm_set_enable(peripheral_pwm_h pwm, bool enable) +int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable) { int len, status; char pwm_buf[PWM_BUF_MAX] = {0}; diff --git a/src/interface/spi.c b/src/interface/peripheral_interface_spi.c similarity index 85% rename from src/interface/spi.c rename to src/interface/peripheral_interface_spi.c index c212792..1296d9f 100644 --- a/src/interface/spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -23,7 +23,7 @@ #include #include -#include "spi.h" +#include "peripheral_interface_spi.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -32,7 +32,7 @@ #define SPI_BUFFER_MAX 64 #define MAX_ERR_LEN 255 -int spi_close(peripheral_spi_h spi) +int peripheral_interface_spi_close(peripheral_spi_h spi) { int status; @@ -50,7 +50,7 @@ int spi_close(peripheral_spi_h spi) return 0; } -int spi_set_mode(peripheral_spi_h spi, unsigned char mode) +int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode) { int status; @@ -68,7 +68,7 @@ int spi_set_mode(peripheral_spi_h spi, unsigned char mode) return 0; } -int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb) +int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb) { int status; @@ -86,7 +86,7 @@ int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb) return 0; } -int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) +int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) { int status; @@ -104,7 +104,7 @@ int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) return 0; } -int spi_set_frequency(peripheral_spi_h spi, unsigned int freq) +int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) { int status; @@ -122,7 +122,7 @@ int spi_set_frequency(peripheral_spi_h spi, unsigned int freq) return 0; } -int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length) +int peripheral_interface_spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length) { int status; struct spi_ioc_transfer xfer; @@ -144,7 +144,7 @@ int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length) return 0; } -int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length) +int peripheral_interface_spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length) { int status; struct spi_ioc_transfer xfer; @@ -166,7 +166,7 @@ int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length) return 0; } -int spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length) +int peripheral_interface_spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length) { int status; struct spi_ioc_transfer xfer; diff --git a/src/interface/uart.c b/src/interface/peripheral_interface_uart.c similarity index 87% rename from src/interface/uart.c rename to src/interface/peripheral_interface_uart.c index fcddde9..92fffce 100644 --- a/src/interface/uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -24,7 +24,7 @@ #include #include -#include "uart.h" +#include "peripheral_interface_uart.h" #include "peripheral_common.h" #include "peripheral_internal.h" @@ -53,7 +53,7 @@ static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = { static const int byteinfo[4] = {CS5, CS6, CS7, CS8}; -int uart_close(peripheral_uart_h uart) +int peripheral_interface_uart_close(peripheral_uart_h uart) { int status; @@ -64,7 +64,7 @@ int uart_close(peripheral_uart_h uart) return -EINVAL; } - status = uart_flush(uart); + status = peripheral_interface_uart_flush(uart); if (status < 0) { char errmsg[MAX_ERR_LEN]; strerror_r(errno, errmsg, MAX_ERR_LEN); @@ -83,7 +83,7 @@ int uart_close(peripheral_uart_h uart) return 0; } -int uart_flush(peripheral_uart_h uart) +int peripheral_interface_uart_flush(peripheral_uart_h uart) { int ret; @@ -103,7 +103,7 @@ int uart_flush(peripheral_uart_h uart) return 0; } -int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud) +int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud) { int ret; struct termios tio; @@ -135,7 +135,7 @@ int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud) tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; - uart_flush(uart); + peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; @@ -147,7 +147,7 @@ int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud) return 0; } -int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) +int peripheral_interface_uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) { int ret; struct termios tio; @@ -207,7 +207,7 @@ int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parit return -EINVAL; } - uart_flush(uart); + peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; @@ -219,7 +219,7 @@ int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parit return 0; } -int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size) +int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size) { int ret; struct termios tio; @@ -249,7 +249,7 @@ int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size) tio.c_cflag |= byteinfo[byte_size]; tio.c_cflag |= (CLOCAL | CREAD); - uart_flush(uart); + peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; @@ -261,7 +261,7 @@ int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size) return 0; } -int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity) +int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e parity) { int ret; struct termios tio; @@ -298,7 +298,7 @@ int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity) break; } - uart_flush(uart); + peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; @@ -310,7 +310,7 @@ int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity) return 0; } -int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits) +int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits) { int ret; struct termios tio; @@ -343,7 +343,7 @@ int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits) return -EINVAL; } - uart_flush(uart); + peripheral_interface_uart_flush(uart); ret = tcsetattr(uart->fd, TCSANOW, &tio); if (ret) { char errmsg[MAX_ERR_LEN]; @@ -355,7 +355,7 @@ int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits) return 0; } -int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) +int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) { int ret; struct termios tio; @@ -398,7 +398,7 @@ int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) return 0; } -int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length) +int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length) { int ret; @@ -420,7 +420,7 @@ int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length) return ret; } -int uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length) +int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length) { int ret; -- 2.7.4 From 51613a796376575bd56788548453136486d7c1c5 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 14 Nov 2017 12:43:07 +0900 Subject: [PATCH 16/16] uart: remove unused interface function that peripheral_interface_uart_set_mode(). Change-Id: I9e1c5a7326d65598e2ce326162abd9c5c0b4806e Signed-off-by: Segwon --- include/interface/peripheral_interface_uart.h | 11 ---- src/interface/peripheral_interface_uart.c | 72 --------------------------- 2 files changed, 83 deletions(-) diff --git a/include/interface/peripheral_interface_uart.h b/include/interface/peripheral_interface_uart.h index f5273fe..c9a8c30 100644 --- a/include/interface/peripheral_interface_uart.h +++ b/include/interface/peripheral_interface_uart.h @@ -99,17 +99,6 @@ int peripheral_interface_uart_flush(peripheral_uart_h uart); int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud); /** -* @brief uart_set_mode() sets byte size, parity bit and stop bits. -* -* @param[in] file_hndl handle of uart_context -* @param[in] byte_size uart byte size -* @param[in] parity uart parity type (even/odd/none) -* @param[in] stop_bits uart stop bits -* @return On success, 0 is returned. On failure, a negative value is returned. -*/ -int peripheral_interface_uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits); - -/** * @brief peripheral_bus_uart_set_byte_size() set byte size. * * @param[in] file_hndl handle of uart_context diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 92fffce..c563fc6 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -147,78 +147,6 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_ra return 0; } -int peripheral_interface_uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits) -{ - int ret; - struct termios tio; - - _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", uart->fd, byte_size, parity, stop_bits); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (byte_size > UART_BYTE_SIZE_8BIT) { - _E("Invalid bytesize parameter"); - return -EINVAL; - } - - ret = tcgetattr(uart->fd, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcgetattr failed, errmsg: %s", errmsg); - return -1; - } - - /* set byte size */ - tio.c_cflag &= ~CSIZE; - tio.c_cflag |= byteinfo[byte_size]; - tio.c_cflag |= (CLOCAL | CREAD); - - /* set parity info */ - switch (parity) { - case UART_PARITY_EVEN: - tio.c_cflag |= PARENB; - tio.c_cflag &= ~PARODD; - break; - case UART_PARITY_ODD: - tio.c_cflag |= PARENB; - tio.c_cflag |= PARODD; - break; - case UART_PARITY_NONE: - default: - tio.c_cflag &= ~PARENB; - tio.c_cflag &= ~PARODD; - break; - } - - /* set stop bit */ - switch (stop_bits) { - case UART_STOP_BITS_1BIT: - tio.c_cflag &= ~CSTOPB; - break; - case UART_STOP_BITS_2BIT: - tio.c_cflag |= CSTOPB; - break; - default: - _E("Invalid parameter stop_bits"); - return -EINVAL; - } - - peripheral_interface_uart_flush(uart); - ret = tcsetattr(uart->fd, TCSANOW, &tio); - if (ret) { - char errmsg[MAX_ERR_LEN]; - strerror_r(errno, errmsg, MAX_ERR_LEN); - _E("tcsetattr failed, errmsg : %s", errmsg); - return -1; - } - - return 0; -} - int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size) { int ret; -- 2.7.4