From 0609e18e0c1a8ff40829ed691e31ac86d1b2afb1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 09:24:11 +0900 Subject: [PATCH 01/16] test: remove console local test app. - It will be replace to new something. - The reason is many apis changed. Signed-off-by: Segwon Change-Id: I142c413ff220aca1752a701998117d39dfedf22d --- CMakeLists.txt | 2 - packaging/capi-system-peripheral-io.spec | 1 - test/CMakeLists.txt | 30 - test/peripheral-io-test.c | 1097 ------------------------------ test/samples/include/mma7455.h | 60 -- test/samples/mma7455.c | 351 ---------- 6 files changed, 1541 deletions(-) delete mode 100644 test/CMakeLists.txt delete mode 100644 test/peripheral-io-test.c delete mode 100644 test/samples/include/mma7455.h delete mode 100644 test/samples/mma7455.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 725fed5..9455ddb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,5 +85,3 @@ 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 1dbb5d2..130bd54 100644 --- a/packaging/capi-system-peripheral-io.spec +++ b/packaging/capi-system-peripheral-io.spec @@ -46,7 +46,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %manifest %{name}.manifest %defattr(-,root,root,-) %{_libdir}/lib%{name}.so* -%{_bindir}/peripheral-io-test %license LICENSE.APLv2 %files devel diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index e1ba67c..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -PROJECT(peripheral-io-test C) -SET(fw_test "${fw_name}-test") - -INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_test} REQUIRED dlog) -FOREACH(flag ${${fw_test}_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") - MESSAGE(${flag}) -ENDFOREACH() - -SET(SAMPLE_INC_DIR ./samples/include) -INCLUDE_DIRECTORIES(${SAMPLE_INC_DIR}) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") - -AUX_SOURCE_DIRECTORY(samples sample_sources) -FOREACH(src ${sample_sources}) - SET(sample_src ${src}) -ENDFOREACH() - -AUX_SOURCE_DIRECTORY(. sources) -FOREACH(src ${sources}) - GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) - MESSAGE("${src_name}") - ADD_EXECUTABLE(${src_name} ${src} ${sample_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/peripheral-io-test.c b/test/peripheral-io-test.c deleted file mode 100644 index 167a7a9..0000000 --- a/test/peripheral-io-test.c +++ /dev/null @@ -1,1097 +0,0 @@ -/* - * 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 -#include -#include - -#include "peripheral_io.h" - -#include "mma7455.h" - -#define BUFFER_LEN 32 - -typedef struct { - int cnt; - peripheral_gpio_h gpio_trig; - peripheral_gpio_h gpio_echo; -} gpio_hcsr04_module_s; - -typedef struct { - const char *tc_name; - int tc_code; - int (*tc_func)(void); -} tc_table_t; - -tc_table_t *tc_table; - -GMainLoop *main_loop; -GList *gpio_list; -GList *i2c_list; -GList *pwm_list; -GList *adc_list; -GList *uart_list; -GList *spi_list; - -int read_int_input(int *input) -{ - char buf[BUFFER_LEN]; - int rv; - - rv = read(0, buf, BUFFER_LEN); - - /* Ignore Enter without value */ - if (*buf == '\n' || *buf == '\r') { - printf("No input value\n"); - return -1; - } - - if (rv < 0) return -1; - *input = atoi(buf); - - return 0; -} - -int gpio_led_test(void) -{ - int num, ret; - int cnt = 0; - peripheral_gpio_h handle = NULL; - - printf(" %s()\n", __func__); - printf("Enter GPIO pin number "); - - if (scanf("%d", &num) < 0) - return -1; - printf("num %d\n", num); - - if ((ret = peripheral_gpio_open(num, &handle)) < PERIPHERAL_ERROR_NONE) { - printf("Failed to open\n"); - return ret; - } - - if ((ret = peripheral_gpio_set_direction(handle, PERIPHERAL_GPIO_DIRECTION_OUT)) < PERIPHERAL_ERROR_NONE) { - printf("Failed to set direction!!\n"); - goto error; - } - - while (cnt++ < 5) { - printf("Writing..\n"); - peripheral_gpio_write(handle, 1); - sleep(1); - peripheral_gpio_write(handle, 0); - sleep(1); - } - printf("Write finish\n"); - if ((ret = peripheral_gpio_close(handle)) < PERIPHERAL_ERROR_NONE) { - printf("Failed to close the pin\n"); - return ret; - } - - return 0; - -error: - peripheral_gpio_close(handle); - return ret; -} - -void gpio_irq_test_isr(gpio_isr_cb_s *data, void *user_data) -{ - int pin; - peripheral_gpio_h gpio = user_data; - - peripheral_gpio_get_pin(gpio, &pin); - - printf("%s: GPIO %d interrupt occurs.\n", __func__, pin); -} - -int gpio_irq_register(void) -{ - peripheral_gpio_h gpio = NULL; - int pin, ret; - - printf(" %s()\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if ((ret = peripheral_gpio_open(pin, &gpio)) < 0) { - printf(">>>>> Failed to open GPIO pin, ret : %d\n", ret); - return -1; - } - gpio_list = g_list_append(gpio_list, gpio); - - if ((ret = peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_IN)) < 0) { - printf(">>>>> Failed to set direction, ret : %d\n", ret); - goto error; - } - peripheral_gpio_set_edge_mode(gpio, PERIPHERAL_GPIO_EDGE_BOTH); - peripheral_gpio_register_cb(gpio, gpio_irq_test_isr, gpio); - - return 0; - -error: - gpio_list = g_list_remove(gpio_list, gpio); - peripheral_gpio_close(gpio); - return -1; -} - -int gpio_irq_unregister(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - int gpio_test_get_handle_by_pin(int pin, peripheral_gpio_h *gpio); - - printf(" %s()\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> cannot find handle. please open the gpio pin.\n"); - return -1; - } - - if ((ret = peripheral_gpio_unregister_cb(gpio)) < 0) { - printf(">>>>> failed to unregister callback function, ret : %d\n", ret); - return -1; - } - - gpio_list = g_list_remove(gpio_list, gpio); - peripheral_gpio_close(gpio); - - return 0; -} - -/* Address of GY30 light sensor */ -#define GY30_ADDR 0x23 - -/* Start measurement at 11x resolution. Measurement time is approx 120ms. */ -#define GY30_CONT_HIGH_RES_MODE 0x10 - -#define GY30_READ_INTENSITY(buf) ((buf[0] << 8 | buf[1]) / 1.2) - -int i2c_gy30_test(void) -{ - int cnt = 0; - unsigned char buf[10]; - peripheral_i2c_h i2c; - struct timeval tv_1, tv_2; - int bus_num, ret, result, interval; - - printf(" %s()\n", __func__); - printf("Enter I2C bus number\n"); - - if (read_int_input(&bus_num) < 0) - return -1; - - if ((ret = peripheral_i2c_open(bus_num, GY30_ADDR, &i2c)) < 0) { - printf("Failed to open I2C communication, ret : %d\n", ret); - return -1; - } - - if ((ret = peripheral_i2c_write_byte(i2c, GY30_CONT_HIGH_RES_MODE)) < 0) { - printf("Failed to write, ret : %d\n", ret); - goto error; - } - - gettimeofday(&tv_1, NULL); - while (cnt++ < 1000) { - ret = peripheral_i2c_read(i2c, buf, 2); - if (ret < 0) - printf("Failed to read, ret : %d\n", ret); - result = GY30_READ_INTENSITY(buf); - printf("Light intensity : %d\n", result); - } - gettimeofday(&tv_2, NULL); - interval = (tv_2.tv_sec - tv_1.tv_sec) * 1000 + (int)(tv_2.tv_usec - tv_1.tv_usec)/1000; - printf("1000 i2c read calls took %d ms\n", interval); - - peripheral_i2c_close(i2c); - return 0; - -error: - peripheral_i2c_close(i2c); - return -1; -} - -static void i2c_mma7455_isr(gpio_isr_cb_s *data, void *user_data) -{ - mma7455_axes result; - - mma7455_i2c_get_measurement_3(&result); - printf("Result X : %d, Y : %d, Z : %d\n", result.x_pos, result.y_pos, result.z_pos); - - /* Reset interrupt flags */ - mma7455_i2c_reset_isr(); - - return; -} - -int i2c_mma7455_test(void) -{ - static int gpio_num; - static bool enable; - int bus_num; - int cnt = 0; - - printf(" %s()\n", __func__); - if (enable) { - printf("Disabling the test\n"); - - mma7455_i2c_unregister_isr(); - mma7455_i2c_close(); - printf("mma7455 is closed\n"); - - enable = FALSE; - - return 0; - } - - printf("Enter I2C bus number\n"); - - if (read_int_input(&bus_num) < 0) - return -1; - - if (mma7455_i2c_init(bus_num) < 0) - return -1; - - printf("Enter GPIO pin number for Interrupt\n"); - if (read_int_input(&gpio_num) < 0) - gpio_num = -1; - - if (gpio_num > 0) { - if (mma7455_i2c_register_isr(gpio_num, i2c_mma7455_isr) != 0) - return -1; - - /* Reset interrupt flags */ - mma7455_i2c_reset_isr(); - - enable = TRUE; - - printf("callback is registered on gpio pin %d\n", gpio_num); - printf("i2c(bus = %d address = %d) handle is open\n", bus_num, MMA7455_ADDRESS); - } else { - while (cnt++ < 10) { - mma7455_axes result; - - sleep(1); - - /* Get measurement data with different APIs */ - mma7455_i2c_get_measurement_1(&result); - printf("Result X : %d, Y : %d, Z : %d (peripheral_i2c_read)\n", - result.x_pos, result.y_pos, result.z_pos); - - mma7455_i2c_get_measurement_2(&result); - printf("Result X : %d, Y : %d, Z : %d (peripheral_i2c_read_byte)\n", - result.x_pos, result.y_pos, result.z_pos); - - mma7455_i2c_get_measurement_3(&result); - printf("Result X : %d, Y : %d, Z : %d (peripheral_i2c_read_register_byte)\n", - result.x_pos, result.y_pos, result.z_pos); - } - mma7455_i2c_close(); - printf("i2c(bus = %d address = %d) handle is closed\n", bus_num, MMA7455_ADDRESS); - } - return 0; -} - -int pwm_test_led(void) -{ - int device, channel, ret; - int period = 1 * 1000; - int duty_cycle = 1 * 1000 / 100; - int cnt = 0; - - int set_duty_cycle; - int get_period, get_duty_cycle; - peripheral_pwm_h dev; - - printf(" %s()\n", __func__); - printf("Enter PWM device number\n"); - if (read_int_input(&device) < 0) - return -1; - - printf("Enter PWM channel number\n"); - if (read_int_input(&channel) < 0) - return -1; - - ret = peripheral_pwm_open(device, channel, &dev); - if (ret != PERIPHERAL_ERROR_NONE) { - printf("Failed to open\n"); - return ret; - } - peripheral_pwm_set_period(dev, period); /* period: nanosecond */ - peripheral_pwm_set_duty_cycle(dev, duty_cycle); /* duty_cycle: nanosecond */ - peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */ - - while (cnt < 2) { - for (set_duty_cycle = period; set_duty_cycle > 0; set_duty_cycle -= 50) { - /* set duty cycle */ - peripheral_pwm_set_duty_cycle(dev, set_duty_cycle); - peripheral_pwm_get_period(dev, &get_period); - peripheral_pwm_get_duty_cycle(dev, &get_duty_cycle); - printf("period(%d), duty_cycle(%d)\n", get_period, get_duty_cycle); - usleep(500000); - } - for (set_duty_cycle = 0; set_duty_cycle < period; set_duty_cycle += 50) { - /* set duty cycle */ - peripheral_pwm_set_duty_cycle(dev, set_duty_cycle); - peripheral_pwm_get_period(dev, &get_period); - peripheral_pwm_get_duty_cycle(dev, &get_duty_cycle); - printf("period(%d), duty_cycle(%d)\n", get_period, get_duty_cycle); - usleep(500000); - } - cnt++; - } - peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */ - peripheral_pwm_close(dev); - - return 0; -} - -int pwm_test_motor(void) -{ - int device, channel, ret; - int period = 20000000; - int duty_cycle = 1500000; - int cnt = 0, idx = 0; - int degree[3] = {0, 45, 90}; - peripheral_pwm_h dev; - - printf(" %s()\n", __func__); - printf("Enter PWM device number\n"); - if (read_int_input(&device) < 0) - return -1; - - printf("Enter PWM channel number\n"); - if (read_int_input(&channel) < 0) - return -1; - - ret = peripheral_pwm_open(device, channel, &dev); - if (ret != PERIPHERAL_ERROR_NONE) { - printf("Failed to open\n"); - return ret; - } - for (cnt = 0; cnt < 5; cnt++) { - for (idx = 0; idx < 3; idx++) { - switch (degree[idx]) { - case 0: - duty_cycle = 1000000; - break; - case 45: - duty_cycle = 1500000; - break; - case 90: - duty_cycle = 2000000; - break; - default: - duty_cycle = 2000000; - break; - } - printf("set degree: %d\n", degree[idx]); - peripheral_pwm_set_period(dev, period); - peripheral_pwm_set_duty_cycle(dev, duty_cycle); - peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */ - usleep(500000); - } - } - - peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */ - peripheral_pwm_close(dev); - - return 0; -} - - -int uart_test_accelerometer(void) -{ - peripheral_uart_h uart; - int ret; - int port; - int loop = 100; - unsigned char buf[1024]; - - printf(" %s()\n", __func__); - printf("Enter port number"); - - if (scanf("%d", &port) < 0) - return -1; - - ret = peripheral_uart_open(port, &uart); - if (ret < 0) - goto err_open; - - ret = peripheral_uart_set_baudrate(uart, PERIPHERAL_UART_BAUDRATE_4800); - if (ret < 0) - goto out; - - ret = peripheral_uart_set_mode(uart, - PERIPHERAL_UART_BYTESIZE_8BIT, - PERIPHERAL_UART_PARITY_NONE, - PERIPHERAL_UART_STOPBITS_1BIT); - if (ret < 0) - goto out; - - ret = peripheral_uart_set_flowcontrol(uart, true, false); - if (ret < 0) - goto out; - - sleep(1); - ret = peripheral_uart_flush(uart); - if (ret < 0) - goto out; - - while (loop--) { - ret = peripheral_uart_read(uart, buf, 13); - if (ret < 0) { - if (ret == PERIPHERAL_ERROR_NO_DATA) - printf("No data to read (%d)\n", ret); - else - printf("Failed to read (%d)\n", ret); - continue; - } - buf[ret] = 0; - printf("%s", buf); - usleep(100000); - } - - peripheral_uart_close(uart); - return 0; - -out: - peripheral_uart_close(uart); - -err_open: - return -1; -} - -int spi_mma7455_module_test(void) -{ - int cnt = 0; - int bus_num, cs_num; - mma7455_axes result; - - printf(" %s()\n", __func__); - printf("Enter SPI bus number : "); - if (scanf("%d", &bus_num) < 0) - return -1; - - printf("Enter SPI cs number : "); - if (scanf("%d", &cs_num) < 0) - return -1; - - if (mma7455_spi_init(bus_num, cs_num) < 0) - return -1; - - while (cnt++ < 15) { - sleep(1); - mma7455_spi_get_measurement(&result); - printf("Result X : %d, Y : %d, Z : %d\n", - result.x_pos, result.y_pos, result.z_pos); - } - - mma7455_spi_close(); - - return 0; -} - -void gpio_hcsr04_isr(gpio_isr_cb_s *data, void *user_data) -{ - float dist = 0; - static unsigned long long timestamp = 0; - - if (timestamp > 0 && data->value == 0) { - dist = data->timestamp - timestamp; - dist = (dist * 34300) / 2000000; - printf("%s: Measured Distance : %0.2fcm\n", __func__, dist); - } - - timestamp = data->timestamp; -} - -gboolean gpio_hcsr04_timeout_cb(gpointer data) -{ - gpio_hcsr04_module_s *dev = (gpio_hcsr04_module_s*)data; - - if (dev->cnt--) { - peripheral_gpio_write(dev->gpio_trig, 1); - peripheral_gpio_write(dev->gpio_trig, 0); - } else - return FALSE; - - return TRUE; -} - -void gpio_hcsr04_destroy(gpointer data) -{ - gpio_hcsr04_module_s *dev = (gpio_hcsr04_module_s*)data; - - peripheral_gpio_unregister_cb(dev->gpio_echo); - peripheral_gpio_close(dev->gpio_echo); - peripheral_gpio_close(dev->gpio_trig); - free(dev); -} - -int gpio_hcsr04_ultrasonic_ranging_module(void) -{ - gpio_hcsr04_module_s *dev; - int pin_trig, pin_echo, ret; - - printf(" %s()\n", __func__); - printf("Enter triger gpio pin number\n"); - if (read_int_input(&pin_trig) < 0) - return -1; - - printf("Enter echo gpio pin number\n"); - if (read_int_input(&pin_echo) < 0) - return -1; - - dev = calloc(1, sizeof(gpio_hcsr04_module_s)); - if (dev == NULL) { - printf("failed to allocate gpio_hcsr04_module_s\n"); - return -1; - } - - if ((ret = peripheral_gpio_open(pin_trig, &dev->gpio_trig)) < 0) { - printf(">>>>> Failed to open GPIO pin, ret : %d\n", ret); - goto err; - } - - if ((ret = peripheral_gpio_open(pin_echo, &dev->gpio_echo)) < 0) { - printf(">>>>> Failed to open GPIO pin, ret : %d\n", ret); - peripheral_gpio_close(dev->gpio_trig); - goto err; - } - - peripheral_gpio_set_direction(dev->gpio_echo, PERIPHERAL_GPIO_DIRECTION_IN); - peripheral_gpio_set_edge_mode(dev->gpio_echo, PERIPHERAL_GPIO_EDGE_BOTH); - peripheral_gpio_register_cb(dev->gpio_echo, gpio_hcsr04_isr, NULL); - peripheral_gpio_set_direction(dev->gpio_trig, PERIPHERAL_GPIO_DIRECTION_OUT); - - dev->cnt = 20; - - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, - 1, - gpio_hcsr04_timeout_cb, - dev, - gpio_hcsr04_destroy); - - return 0; - -err: - free(dev); - return -1; -} - -int gpio_test_get_handle_by_pin(int pin, peripheral_gpio_h *gpio) -{ - peripheral_gpio_h handle; - GList *cursor; - int cur_pin; - - cursor = gpio_list; - while (cursor) { - handle = (peripheral_gpio_h)cursor->data; - peripheral_gpio_get_pin(handle, &cur_pin); - if (pin == cur_pin) - break; - cursor = g_list_next(cursor); - } - if (!cursor) return -1; - - *gpio = handle; - - return 0; -} - -int print_gpio_handle(void) -{ - peripheral_gpio_h gpio; - GList *cursor; - peripheral_gpio_direction_e direction; - peripheral_gpio_edge_e edge; - int pin, value; - char *dir_str, *edge_str; - - printf("--- GPIO handle info. -------------------------------------------\n"); - printf(" No Pin Direction Value Edge mode\n"); - - cursor = gpio_list; - while (cursor) { - gpio = (peripheral_gpio_h)cursor->data; - - if (peripheral_gpio_get_pin(gpio, &pin) < 0) - continue; - if (peripheral_gpio_get_direction(gpio, &direction) < 0) - continue; - if (peripheral_gpio_get_edge_mode(gpio, &edge) < 0) - continue; - - if (direction == PERIPHERAL_GPIO_DIRECTION_IN) - dir_str = "IN"; - else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_LOW) - dir_str = "OUT_LOW"; - else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_HIGH) - dir_str = "OUT_HIGH"; - else - dir_str = "UNKNOWN"; - - if (edge == PERIPHERAL_GPIO_EDGE_NONE) - edge_str = "NONE"; - else if (edge == PERIPHERAL_GPIO_EDGE_RISING) - edge_str = "RISING"; - else if (edge == PERIPHERAL_GPIO_EDGE_FALLING) - edge_str = "FALLING"; - else if (edge == PERIPHERAL_GPIO_EDGE_BOTH) - edge_str = "BOTH"; - else - edge_str = "UNKNOWN"; - - if (direction == PERIPHERAL_GPIO_DIRECTION_IN) { - if (peripheral_gpio_read(gpio, &value) < 0) - continue; - printf("%8d%8d%12s%8d%12s\n", g_list_position(gpio_list, cursor), - pin, dir_str, value, edge_str); - } else - printf("%8d%8d%12s%20s\n", g_list_position(gpio_list, cursor), - pin, dir_str, edge_str); - - cursor = g_list_next(cursor); - } - printf("-----------------------------------------------------------------\n"); - - return 0; -} - -int gpio_test_open(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - - printf("%s\n", __func__); - printf("Enter GPIO pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if ((ret = peripheral_gpio_open(pin, &gpio)) < 0) { - printf(">>>>> GPIO open failed, ret : %d\n", ret); - return -1; - } - gpio_list = g_list_append(gpio_list, gpio); - print_gpio_handle(); - - return 0; -} - -int gpio_test_close(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - - printf("%s\n", __func__); - printf("Enter GPIO pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> Cannot find handle. Please open the GPIO pin\n"); - return -1; - } - gpio_list = g_list_remove(gpio_list, gpio); - - if ((ret = peripheral_gpio_close(gpio)) < 0) { - printf(">>>>> GPIO close failed, ret : %d\n", ret); - return -1; - } - print_gpio_handle(); - - return 0; -} - -int gpio_test_set_direction(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - int direction; - - printf("%s\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> Cannot find handle. Please open the GPIO pin\n"); - return -1; - } - - printf("Enter direction (0:IN, 1:OUT_LOW, 2:OUT_HIGH)\n"); - if (read_int_input(&direction) < 0) - return -1; - - if (direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH || - direction < PERIPHERAL_GPIO_DIRECTION_IN) { - printf(">>>>> Wrong input value\n"); - return -1; - } - - if ((ret = peripheral_gpio_set_direction(gpio, (peripheral_gpio_direction_e)direction)) < 0) { - printf(">>>>> Failed to set direction, ret : %d\n", ret); - return -1; - } - - return 0; -} - -int gpio_test_write(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - int value; - - printf("%s\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> Cannot find handle. Please open the GPIO pin\n"); - return -1; - } - - printf("Enter value (0:LOW, 1:HIGH)\n"); - if (read_int_input(&value) < 0) - return -1; - - if (value < 0 || value > 1) { - printf(">>>>> Wrong input value\n"); - return -1; - } - - if ((ret = peripheral_gpio_write(gpio, value)) < 0) { - printf(">>>>> Failed to write value, ret : %d\n", ret); - return -1; - } - - return 0; -} - -int gpio_test_set_edge_mode(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - int edge; - - printf("%s\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> Cannot find handle. Please open the GPIO pin\n"); - return -1; - } - - printf("Enter edge mode (0:NONE, 1:RISING, 2:FALLING, 3:BOTH)\n"); - if (read_int_input(&edge) < 0) - return -1; - - if (edge < PERIPHERAL_GPIO_EDGE_NONE || edge > PERIPHERAL_GPIO_EDGE_BOTH) { - printf(">>>>> Wrong input value\n"); - return -1; - } - - if ((ret = peripheral_gpio_set_edge_mode(gpio, (peripheral_gpio_edge_e)edge)) < 0) { - printf(">>>>> Failed to set edge mode, ret : %d\n", ret); - return -1; - } - - return 0; -} - -int gpio_test_set_register_cb(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - - printf("%s\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> Cannot find handle. Please open the GPIO pin\n"); - return -1; - } - - if ((ret = peripheral_gpio_register_cb(gpio, gpio_irq_test_isr, gpio)) < 0) { - printf(">>>>> Failed to register callback function, ret : %d\n", ret); - return -1; - } - return 0; -} - -int gpio_test_set_unregister_cb(void) -{ - peripheral_gpio_h gpio; - int pin, ret; - - printf("%s\n", __func__); - printf("Enter gpio pin number\n"); - - if (read_int_input(&pin) < 0) - return -1; - - if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) { - printf(">>>>> Cannot find handle. Please open the GPIO pin\n"); - return -1; - } - - if ((ret = peripheral_gpio_unregister_cb(gpio)) < 0) { - printf(">>>>> failed to unregister callback function, ret : %d\n", ret); - return -1; - } - - return 0; -} - -int enter_main(void); - -tc_table_t gpio_tc_table[] = { - {"Open GPIO pin", 1, gpio_test_open}, - {"Close GPIO pin", 2, gpio_test_close}, - {"Set direction GPIO pin", 3, gpio_test_set_direction}, - {"Write value to GPIO pin", 4, gpio_test_write}, - {"Set edge mode", 5, gpio_test_set_edge_mode}, - {"Register callback", 6, gpio_test_set_register_cb}, - {"Unregister callback", 7, gpio_test_set_unregister_cb}, - {"Print GPIO handle", 9, print_gpio_handle}, - {"Go back to main", 0, enter_main}, - {NULL, 0, NULL}, -}; - -int enter_gpio_test(void) -{ - tc_table = gpio_tc_table; - print_gpio_handle(); - - return 0; -} - -int enter_i2c_test(void) -{ - return 0; -} - -int enter_pwm_test(void) -{ - return 0; -} - -int adc_read_channel(void) -{ - int device, channel, ret; - int value; - - printf("%s\n", __func__); - - printf("Enter adc device number\n"); - if (read_int_input(&device) < 0) - return -1; - - printf("Enter adc channel number\n"); - if (read_int_input(&channel) < 0) - return -1; - - if ((ret = peripheral_adc_read(device, channel, &value)) < 0) { - printf(">>>>> Failed to read adc value, ret : %d\n", ret); - return -1; - } - printf("ADC(%d,%d) Value = %d\n", device, channel, value); - - return 0; -} - -tc_table_t adc_tc_table[] = { - {"Read ADC Channel", 1, adc_read_channel}, - {"Go back to main", 0, enter_main}, - {NULL, 0, NULL}, -}; - -int enter_adc_test(void) -{ - tc_table = adc_tc_table; - - return 0; -} - -int enter_uart_test(void) -{ - return 0; -} - -int enter_spi_test(void) -{ - return 0; -} - -tc_table_t preset_tc_table[] = { - {"[Preset Test] GPIO LED", 1, gpio_led_test}, - {"[Preset Test] I2C GY30 Light sensor", 2, i2c_gy30_test}, - {"[Preset Test] I2C MMA7455 Accel. sensor", 3, i2c_mma7455_test}, - {"[Preset Test] PWM LED", 4, pwm_test_led}, - {"[Preset Test] PWM Motor", 5, pwm_test_motor}, - {"[Preset Test] Uart Accelerometer", 6, uart_test_accelerometer}, - {"[Preset Test] SPI MMA7455 Accel. sensor", 7, spi_mma7455_module_test}, - {"[Preset Test] GPIO HC-SR04 Range sensor", 8, gpio_hcsr04_ultrasonic_ranging_module}, - {"[Preset Test] GPIO IRQ register", 10, gpio_irq_register}, - {"[Preset Test] GPIO IRQ unregister", 11, gpio_irq_unregister}, - {"Go back to main", 0, enter_main}, - {NULL, 0, NULL}, -}; - -int enter_preset_test(void) -{ - tc_table = preset_tc_table; - return 0; -} - -int terminate_test(void) -{ - int ret = 0; - - printf("Terminate test\n"); - g_main_loop_quit(main_loop); - - exit(1); - - return ret; -} - -tc_table_t main_tc_table[] = { - {"GPIO Test Menu", 1, enter_gpio_test}, - {"I2C Test Menu", 2, enter_i2c_test}, - {"PWM Test Menu", 3, enter_pwm_test}, - {"ADC Test Menu", 4, enter_adc_test}, - {"UART Test Menu", 5, enter_uart_test}, - {"SPI Test Menu", 6, enter_spi_test}, - {"Preset Test", 10, enter_preset_test}, - {"Exit Test", 0, terminate_test}, - {NULL, 0, NULL}, -}; - -int enter_main(void) -{ - tc_table = main_tc_table; - - return 0; -} - -static int test_input_callback(void *data) -{ - tc_table_t *tc; - long test_id = (long)data; - int ret = PERIPHERAL_ERROR_NONE; - int i = 0; - - tc = tc_table; - - while (tc[i].tc_name) { - if (tc[i].tc_code == test_id && tc[i].tc_func) { - ret = tc[i].tc_func(); - if (ret != PERIPHERAL_ERROR_NONE) - printf(">>>>> Test Error Returned !!! : %d\n", ret); - - break; - } - i++; - } - if (!tc[i].tc_name) { - printf(">>>>> Wrong input value!\n"); - return -1; - } - - return 0; -} - -static void print_tc_usage(void) -{ - int i = 0; - - printf("===========================================\n"); - while (tc_table[i].tc_name) { - printf(" %2d : %s\n", tc_table[i].tc_code, tc_table[i].tc_name); - i++; - } - printf("===========================================\n"); - printf("Enter TC number\n"); -} - -static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data) -{ - char buf[BUFFER_LEN] = {0,}; - long test_id; - int rv = 0; - - memset(buf, 0, sizeof(buf)); - - rv = read(0, buf, BUFFER_LEN); - - if (*buf == '\n' || *buf == '\r') { - print_tc_usage(); - return TRUE; - } - - if (rv < 0) return FALSE; - - test_id = atoi(buf); - - test_input_callback((void *)test_id); - print_tc_usage(); - - return TRUE; -} - -int main(int argc, char **argv) -{ - GIOChannel *key_io; - - main_loop = g_main_loop_new(NULL, FALSE); - key_io = g_io_channel_unix_new(0); - - tc_table = main_tc_table; - - print_tc_usage(); - g_io_add_watch(key_io, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), key_event_cb, NULL); - - g_main_loop_run(main_loop); - - g_io_channel_unref(key_io); - g_main_loop_unref(main_loop); - - return 0; -} diff --git a/test/samples/include/mma7455.h b/test/samples/include/mma7455.h deleted file mode 100644 index bbf75f0..0000000 --- a/test/samples/include/mma7455.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -/* Userspace driver for MMA7455 Accelerometer */ - -#define MMA7455_ADDRESS 0x1D //I2C Address of MMA7455 - -#define MMA7455_MCTL 0x16 // Mode Control(register) -#define MMA7455_MCTL_STANDBY_MODE 0x0 // [1:0] Standby mode -#define MMA7455_MCTL_MEASUREMENT_MODE 0x01 // [1:0] Measurement mode -#define MMA7455_MCTL_LEVEL_DETECTION_MODE 0x02 // [1:0] Level detection mode -#define MMA7455_MCTL_PULSE_DETECTION_MODE 0x03 // [1:0] Pulse detection mode -#define MMA7455_MCTL_2G 0x04 // [3:2] Set Sensitivity to 2g -#define MMA7455_MCTL_4G 0x08 // [3:2] Set Sensitivity to 4g -#define MMA7455_MCTL_8G 0x00 // [3:2] Set Sensitivity to 8g -#define MMA7455_MCTL_STON 0x10 // Self-test is enabled -#define MMA7455_MCTL_SPI3W 0x20 // SPI is 3 wire mode -#define MMA7455_MCTL_DRPD 0x40 // Data ready status is not output to INT1/DRDY PIN - -#define MMA7455_INTRST 0x17 // Interrupt latch reset(register) -#define MMA7455_INTRST_CLRINT 0x03 -#define MMA7445_INTRST_DONOTCLR 0x00 - -#define MMA7455_XOUT8 0x06 // 8 bits output value X (register) -#define MMA7455_YOUT8 0x07 // 8 bits output value Y (register) -#define MMA7455_ZOUT8 0x08 // 8 bits output value Z (register) - -#define MMA7455_SPI_REGISTER_WRITE 0x80 - -typedef struct { - uint8_t x_pos; - uint8_t y_pos; - uint8_t z_pos; -} mma7455_axes; - -int mma7455_i2c_init(int bus_num); -int mma7455_i2c_close(); -int mma7455_i2c_reset_isr(); -int mma7455_i2c_get_measurement_1(mma7455_axes *result); -int mma7455_i2c_get_measurement_2(mma7455_axes *result); -int mma7455_i2c_get_measurement_3(mma7455_axes *result); -int mma7455_i2c_register_isr(const int gpio_num, gpio_isr_cb cb_func); -int mma7455_i2c_unregister_isr(); - -int mma7455_spi_init(int bus_num, int cs_num); -int mma7455_spi_close(); -int mma7455_spi_get_measurement(mma7455_axes *result); diff --git a/test/samples/mma7455.c b/test/samples/mma7455.c deleted file mode 100644 index 1930b74..0000000 --- a/test/samples/mma7455.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * 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. - */ - -/* Userspace driver for MMA7455 Accelerometer */ - -#include - -#include "peripheral_io.h" -#include "mma7455.h" - -static peripheral_i2c_h mma7455_i2c; -static peripheral_gpio_h isr_gpio; -static peripheral_spi_h mma7455_spi; - -#define LOG(...) printf(__VA_ARGS__) - -int mma7455_i2c_init(int bus_num) -{ - int ret; - - /* Return if it's already initialized */ - if (mma7455_i2c) { - LOG("Device was already initialized\n"); - return -1; - } - - /* Open I2c communication */ - ret = peripheral_i2c_open(bus_num, MMA7455_ADDRESS, &mma7455_i2c); - if (ret < PERIPHERAL_ERROR_NONE) { - LOG(">>>>> Failed to open I2C communication, ret : %d \n", ret); - return -1; - } - - /* Set mode control register */ - ret = peripheral_i2c_write_register_byte(mma7455_i2c, MMA7455_MCTL, - MMA7455_MCTL_2G | MMA7455_MCTL_PULSE_DETECTION_MODE); - if (ret < PERIPHERAL_ERROR_NONE) { - LOG(">>>>> Failed to write, ret : %d\n", ret); - peripheral_i2c_close(mma7455_i2c); - mma7455_i2c = NULL; - - return -1; - } - - return 0; -} - -int mma7455_i2c_close() -{ - int ret; - - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Set the device to standby mode */ - peripheral_i2c_write_register_byte(mma7455_i2c, MMA7455_MCTL, MMA7455_MCTL_STANDBY_MODE); - - /* Close I2C communication */ - ret = peripheral_i2c_close(mma7455_i2c); - if (ret < PERIPHERAL_ERROR_NONE) - LOG("Failed to close i2c communication, continue anyway\n"); - - mma7455_i2c = NULL; - - /* If gpio for interrupt was registered, unregister it */ - if (isr_gpio) { - peripheral_gpio_unregister_cb(isr_gpio); - peripheral_gpio_close(isr_gpio); - - isr_gpio = NULL; - } - - return ret; -} - -int mma7455_i2c_reset_isr() -{ - int ret; - - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Reset interrupt flags */ - ret = peripheral_i2c_write_register_byte(mma7455_i2c, MMA7455_INTRST, MMA7455_INTRST_CLRINT); - if (ret < PERIPHERAL_ERROR_NONE) - goto error; - - ret = peripheral_i2c_write_register_byte(mma7455_i2c, MMA7455_INTRST, MMA7445_INTRST_DONOTCLR); - if (ret < PERIPHERAL_ERROR_NONE) - goto error; - - return 0; - -error: - LOG(">>>>> Failed to reset interrupt flags\n"); - return ret; -} - -int mma7455_i2c_get_measurement_1(mma7455_axes *result) -{ - unsigned char buf[4]; - - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Read measurement data from register respectively */ - buf[0] = MMA7455_XOUT8; - peripheral_i2c_write(mma7455_i2c, buf, 0x1); - peripheral_i2c_read(mma7455_i2c, &result->x_pos, 0x1); - - buf[0] = MMA7455_YOUT8; - peripheral_i2c_write(mma7455_i2c, buf, 0x1); - peripheral_i2c_read(mma7455_i2c, &result->y_pos, 0x1); - - buf[0] = MMA7455_ZOUT8; - peripheral_i2c_write(mma7455_i2c, buf, 0x1); - peripheral_i2c_read(mma7455_i2c, &result->z_pos, 0x1); - - return 0; -} - -int mma7455_i2c_get_measurement_2(mma7455_axes *result) -{ - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Read measurement data by using i2c_write_byte and i2c_read_byte (SMBUS ioctl) */ - peripheral_i2c_write_byte(mma7455_i2c, MMA7455_XOUT8); - peripheral_i2c_read_byte(mma7455_i2c, &result->x_pos); - - peripheral_i2c_write_byte(mma7455_i2c, MMA7455_YOUT8); - peripheral_i2c_read_byte(mma7455_i2c, &result->y_pos); - - peripheral_i2c_write_byte(mma7455_i2c, MMA7455_ZOUT8); - peripheral_i2c_read_byte(mma7455_i2c, &result->z_pos); - - return 0; -} - -int mma7455_i2c_get_measurement_3(mma7455_axes *result) -{ - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Read measurement data by using i2c_read_register_byte (SMBUS ioctl) */ - peripheral_i2c_read_register_byte(mma7455_i2c, MMA7455_XOUT8, &result->x_pos); - peripheral_i2c_read_register_byte(mma7455_i2c, MMA7455_YOUT8, &result->y_pos); - peripheral_i2c_read_register_byte(mma7455_i2c, MMA7455_ZOUT8, &result->z_pos); - - return 0; -} - -int mma7455_i2c_register_isr(const int gpio_num, gpio_isr_cb cb_func) -{ - int ret; - - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - LOG("mma7455_i2c_register_isr\n"); - - if (gpio_num < 0) { - LOG(">>>>> Wrong gpio number\n"); - return -EINVAL; - } - - if (isr_gpio != NULL) { - LOG(">>>>> GPIO ISR is already registered\n"); - return -EBUSY; - } - - ret = peripheral_gpio_open(gpio_num, &isr_gpio); - if (ret < PERIPHERAL_ERROR_NONE) { - LOG(">>>> Failed to open the GPIO pin\n"); - return ret; - } - - peripheral_gpio_set_direction(isr_gpio, PERIPHERAL_GPIO_DIRECTION_IN); - peripheral_gpio_set_edge_mode(isr_gpio, PERIPHERAL_GPIO_EDGE_RISING); - - ret = peripheral_gpio_register_cb(isr_gpio, cb_func, NULL); - if (ret < PERIPHERAL_ERROR_NONE) { - LOG(">>>> Failed to register gpio callback\n"); - goto error; - } - - return 0; - -error: - peripheral_gpio_close(isr_gpio); - isr_gpio = NULL; - - return ret; -} - -int mma7455_i2c_unregister_isr() -{ - if (!mma7455_i2c) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Check whether GPIO ISR is registered */ - if (isr_gpio == NULL) { - LOG("GPIO ISR is not registered\n"); - return -1; - } - - /* Unregister callback and close the pin */ - peripheral_gpio_unregister_cb(isr_gpio); - peripheral_gpio_close(isr_gpio); - - isr_gpio = NULL; - - return 0; -} - -static int mma7455_spi_mctl_write_byte(unsigned char value) -{ - unsigned char tx_buf[2]; - int ret; - - if (!mma7455_spi) { - LOG("Device is not initialized\n"); - return PERIPHERAL_ERROR_INVALID_OPERATION; - } - - tx_buf[0] = MMA7455_SPI_REGISTER_WRITE | (MMA7455_MCTL << 1); - tx_buf[1] = value; - - if ((ret = peripheral_spi_write(mma7455_spi, tx_buf, 2)) < 0) - return ret; - - return PERIPHERAL_ERROR_NONE; -} - -int mma7455_spi_init(int bus_num, int cs_num) -{ - peripheral_spi_mode_e spi_mode; - bool spi_lsb; - unsigned char spi_bits; - unsigned int spi_freq; - int ret; - - /* Return if it's already initialized */ - if (mma7455_spi) { - LOG("Device was already initialized\n"); - return -1; - } - - /* Open SPI communication */ - ret = peripheral_spi_open(bus_num, cs_num, &mma7455_spi); - if (ret < PERIPHERAL_ERROR_NONE) { - LOG("Failed to open SPI communication, ret : %d\n", ret); - return -1; - } - - peripheral_spi_set_mode(mma7455_spi, PERIPHERAL_SPI_MODE_0); - peripheral_spi_set_lsb_first(mma7455_spi, false); - peripheral_spi_set_bits_per_word(mma7455_spi, 8); - peripheral_spi_set_frequency(mma7455_spi, 8*1024*1024); - - peripheral_spi_get_mode(mma7455_spi, &spi_mode); - peripheral_spi_get_lsb_first(mma7455_spi, &spi_lsb); - peripheral_spi_get_bits_per_word(mma7455_spi, &spi_bits); - peripheral_spi_get_frequency(mma7455_spi, &spi_freq); - LOG("bus : %d, cs : %d, mode : %d, lsb first : %d, bits : %d, max frequency : %d\n", - bus_num, cs_num, spi_mode, spi_lsb, spi_bits, spi_freq); - - /* Set mode control register */ - ret = mma7455_spi_mctl_write_byte(MMA7455_MCTL_SPI3W - | MMA7455_MCTL_2G - | MMA7455_MCTL_MEASUREMENT_MODE); - if (ret < PERIPHERAL_ERROR_NONE) { - LOG("Failed to write, ret : %d\n", ret); - peripheral_spi_close(mma7455_spi); - mma7455_spi = NULL; - - return -1; - } - - return 0; -} - -int mma7455_spi_close() -{ - int ret; - - if (!mma7455_spi) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Set the device to standby mode */ - ret = mma7455_spi_mctl_write_byte(MMA7455_MCTL_STANDBY_MODE); - if (ret < PERIPHERAL_ERROR_NONE) - LOG("Failed to set the device to standby mode\n"); - - ret = peripheral_spi_close(mma7455_spi); - if (ret < PERIPHERAL_ERROR_NONE) - LOG("Failed to close i2c communication, continue anyway\n"); - - mma7455_spi = NULL; - - return 0; -} - -int mma7455_spi_get_measurement(mma7455_axes *result) -{ - unsigned char tx_data; - - if (!mma7455_spi) { - LOG("Device is not initialized\n"); - return -1; - } - - /* Read measurement value */ - tx_data = MMA7455_XOUT8 << 1; - peripheral_spi_read_write(mma7455_spi, &tx_data, &(result->x_pos), 1); - tx_data = MMA7455_YOUT8 << 1; - peripheral_spi_read_write(mma7455_spi, &tx_data, &(result->y_pos), 1); - tx_data = MMA7455_ZOUT8 << 1; - peripheral_spi_read_write(mma7455_spi, &tx_data, &(result->z_pos), 1); - - return 0; -} -- 2.7.4 From 24831d9548318f4707a4d98a603952287fbeeb70 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 24 Aug 2017 19:39:51 +0900 Subject: [PATCH 02/16] api: modified with new API set. - ADC not supported - Provides get list API to get necessary for open APIs - Remove unnecessary and uncertain APIs - Terminology unification - Add peripheral_io_doc.h for doxygen - Add feature key and privilege level to doxygen Signed-off-by: Segwon Change-Id: Ie104753f270fdcc37df62e538c9ee06d254c2db2 --- doc/peripheral_io_doc.h | 173 ++++++++ include/peripheral_io.h | 1096 +++++++++++++++++++++++++---------------------- 2 files changed, 753 insertions(+), 516 deletions(-) create mode 100644 doc/peripheral_io_doc.h diff --git a/doc/peripheral_io_doc.h b/doc/peripheral_io_doc.h new file mode 100644 index 0000000..8c373bf --- /dev/null +++ b/doc/peripheral_io_doc.h @@ -0,0 +1,173 @@ +/* + * 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. + */ + +/** + * @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. + * + * @section CAPI_SYSTEM_PERIPHERAL_IO_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_SYSTEM_PERIPHERAL_IO_MODULE_OVERVIEW Overview + * This @ref CAPI_SYSTEM_PERIPHERAL_IO_MODULE API provides access to the low level device providers, + * including GPIO, I2C, PWM, UART and SPI. + */ + + +/** + * @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. + * + * @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. + * + * @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 + * + * 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 + * 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 + * 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. + */ + + +/** + * @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. + * + * @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. + * + * @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 + * + * 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 + * 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 + * 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. + */ + + +/** + * @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. + * + * @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. + * + * @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 + * + * 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 + * 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 + * 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. + */ + + +/** + * @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. + * + * @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. + * + * @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 + * + * 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 + * 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 + * 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. + */ + + +/** + * @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. + * + * @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. + * + * @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 + * + * 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 + * 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 + * 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 d697a55..7ff48d4 100644 --- a/include/peripheral_io.h +++ b/include/peripheral_io.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PERIPHERAL_IO_H__ -#define __PERIPHERAL_IO_H__ +#ifndef __TIZEN_SYSTEM_PERIPHERAL_IO_H__ +#define __TIZEN_SYSTEM_PERIPHERAL_IO_H__ #include #include @@ -25,1105 +25,1169 @@ extern "C" { #endif /** + * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE + * @{ + */ + +/** * @file peripheral_io.h - * @brief This file contains the peripheral-io API + * @brief This file contains the peripheral-io API. */ /** * @brief Enumeration for peripheral-io error. - * @since_tizen + * @since_tizen 4.0 */ typedef enum { PERIPHERAL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ PERIPHERAL_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ PERIPHERAL_ERROR_NO_DEVICE = TIZEN_ERROR_NO_SUCH_DEVICE, /**< No such device */ + PERIPHERAL_ERROR_TRY_AGAIN = TIZEN_ERROR_TRY_AGAIN, /**< Try again */ PERIPHERAL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ PERIPHERAL_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ PERIPHERAL_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ PERIPHERAL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - PERIPHERAL_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */ - PERIPHERAL_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented */ - PERIPHERAL_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */ PERIPHERAL_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ PERIPHERAL_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown error */ } peripheral_error_e; /** - * @addtogroup CAPI_SYSTEM_PERIPHERAL_GPIO_MODULE +* @} +*/ + +/** + * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE * @{ */ /** - * @brief Enumeration of gpio direction + * @brief Enumeration of GPIO direction options. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_GPIO_DIRECTION_IN = 0, /**< Input Mode */ - PERIPHERAL_GPIO_DIRECTION_OUT, /**< Output mode with low value */ - PERIPHERAL_GPIO_DIRECTION_OUT_LOW = PERIPHERAL_GPIO_DIRECTION_OUT, /**< Same as above */ - PERIPHERAL_GPIO_DIRECTION_OUT_HIGH, /**< Output mode with high value */ + PERIPHERAL_GPIO_DIRECTION_IN = 0, /**< Input Mode */ + PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH, /**< Output mode with high value */ + PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, /**< Output mode with low value */ } peripheral_gpio_direction_e; /** - * @brief Enumeration of edge type for gpio interrupt + * @brief Enumeration of edge types for the GPIO interrupt. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_GPIO_EDGE_NONE = 0, /**< No interrupt on Gpio */ + PERIPHERAL_GPIO_EDGE_NONE = 0, /**< No interrupt on GPIO */ PERIPHERAL_GPIO_EDGE_RISING, /**< Interrupt on rising only */ PERIPHERAL_GPIO_EDGE_FALLING, /**< Interrupt on falling only */ PERIPHERAL_GPIO_EDGE_BOTH, /**< Interrupt on rising & falling */ } peripheral_gpio_edge_e; /** - * @brief Gpio isr callback data delivered via gpio_isr_cb(). - * @details A gpio isr callback data is delivered as a structure, which contains - * the pin number, the pin value, and the timestamp of the gpio interrupt - * in microseconds. + * @brief The handle of a GPIO pin. * @since_tizen 4.0 */ -typedef struct { - int pin; - int value; - unsigned long long timestamp; -} gpio_isr_cb_s; +typedef struct _peripheral_gpio_s *peripheral_gpio_h; /** - * @brief The handle to the gpio pin - * @since_tizen 4.0 - */ -typedef struct _peripheral_gpio_s* peripheral_gpio_h; - -/** - * @brief Initializes(export) gpio pin and creates gpio handle. + * @platform + * @brief Opens a GPIO pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * @remarks @a gpio should be released with peripheral_gpio_close() * - * @param[in] gpio_pin The gpio pin number - * @param[out] gpio The gpio handle is created on success + * @param[in] gpio_pin The GPIO pin number + * @param[out] gpio The GPIO handle is created on success * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied + * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use + * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_gpio_close() + * @post peripheral_gpio_close() */ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio); /** - * @brief Releases the gpio handle and finalize(unexport) the gpio pin. + * @platform + * @brief Closes a GPIO pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin to release + * @param[in] gpio The GPIO handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_gpio_open() + * @pre peripheral_gpio_open() */ int peripheral_gpio_close(peripheral_gpio_h gpio); /** - * @brief Gets direction of the gpio. + * @platform + * @brief Sets the GPIO direction. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin - * @param[out] value The direction(value) type of the gpio + * @param[in] gpio The GPIO handle + * @param[in] direction The direction of the GPIO pin * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_gpio_set_direction() - */ -int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); - -/** - * @brief Sets direction of the gpio pin. - * @since_tizen 4.0 - * - * @param[in] gpio The handle to the gpio pin to set - * @param[in] direction Direction(value) type of the gpio pin - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * @see peripheral_gpio_direction_e */ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); /** - * @brief Reads value of the gpio. + * @platform + * @brief Sets the GPIO edge mode. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin - * @param[out] value The value of the gpio (zero or non-zero) + * @param[in] gpio The GPIO handle + * @param[in] edge The edge mode of the GPIO pin * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_gpio_write() + * @see peripheral_gpio_edge_e */ -int peripheral_gpio_read(peripheral_gpio_h gpio, int *value); +int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); /** - * @brief Writes value to the gpio. + * @platform + * @brief The GPIO interrupted callback called when the GPIO interrupt is triggered. * @since_tizen 4.0 * - * @param[in] gpio The handle to the gpio pin - * @param[in] value Value to be written to the gpio (muse be zero or non-zero) - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * @param[in] gpio The GPIO handle + * @param[in] error The GPIO error + * @param[in] user_data The user data passed from the callback registration function * - * @see peripheral_gpio_read() + * @see peripheral_gpio_set_interrupted_cb() */ -int peripheral_gpio_write(peripheral_gpio_h gpio, int value); +typedef void(*peripheral_gpio_interrupted_cb)(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data); /** - * @brief Gets the edge mode of the gpio. + * @platform + * @brief Sets the GPIO interrupted callback to be invoked when the GPIO interrupt is triggered. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin - * @param[out] gpio_pin The edge mode of the gpio + * @param[in] gpio The GPIO handle + * @param[in] callback The GPIO interrupted callback function to set + * @param[in] user_data The user data to be passed to the callback function * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * + * @post peripheral_gpio_unset_interrupted_cb() * @see peripheral_gpio_set_edge_mode() */ -int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); +int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); /** - * @brief Sets the edge mode of the gpio pin. + * @platform + * @brief Unsets the GPIO interrupted callback. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin to set - * @param[in] edge The edge mode of the gpio pin + * @param[in] gpio The GPIO handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - * - * @see peripheral_gpio_get_edge_mode() - */ -int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); - -/** - * @brief Called when the gpio interrupt is triggered. - * @since_tizen 4.0 + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * - * @param[in] data The gpio isr callback data - * @param[in] user_data The user data passed from the callback registration function - * - * @see peripheral_gpio_register_cb() - * @see peripheral_gpio_unregister_cb() + * @pre peripheral_gpio_set_interrupted_cb() */ -typedef void(*gpio_isr_cb)(gpio_isr_cb_s *data, void *user_data); +int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); /** - * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. + * @platform + * @brief Gets the current value of the GPIO pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin to set - * @param[in] edge The edge type of the gpio pin - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function + * @param[in] gpio The GPIO handle + * @param[out] value The value to get * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported + * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * - * @see peripheral_gpio_set_edge_mode() - * @see peripheral_gpio_unregister_cb() + * @see peripheral_gpio_write() */ -int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); +int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value); /** - * @brief Unregisters the callback function for the gpio handler. + * @platform + * @brief Sets the value of the GPIO pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] gpio The handle to the gpio pin + * @param[in] gpio The GPIO handle + * @param[in] value The value to set (must be 0 or 1) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported + * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * - * @see peripheral_gpio_register_cb() - */ -int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio); - -/** - * @brief Gets pin number of the gpio handle. - * @since_tizen 4.0 - * - * @param[in] gpio The handle to the gpio pin - * @param[out] gpio_pin The pin number of the gpio - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @see peripheral_gpio_read() */ -int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin); +int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value); /** * @} */ /** - * @addtogroup CAPI_SYSTEM_PERIPHERAL_I2C_MODULE + * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE * @{ */ /** - * @brief The handle to the i2c device + * @brief The handle of the I2C slave device. * @since_tizen 4.0 */ typedef struct _peripheral_i2c_s *peripheral_i2c_h; /** - * @brief Initializes i2c communication and creates i2c handle. + * @platform + * @brief Opens an I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * @remarks @a i2c should be released with peripheral_i2c_close() * - * @param[in] bus The i2c bus number that the slave device is connected + * @param[in] bus The I2C bus number that the slave device is connected * @param[in] address The address of the slave device - * @param[out] i2c The i2c handle is created on success + * @param[out] i2c The I2C handle is created on success * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied + * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_i2c_close() + * @post peripheral_i2c_close() */ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c); /** - * @brief Destory the i2c handle and release the communication. + * @platform + * @brief Closes an I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The i2c handle + * @param[in] i2c The I2C handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * - * @see peripheral_i2c_open() + * @pre peripheral_i2c_open() */ int peripheral_i2c_close(peripheral_i2c_h i2c); /** - * @brief Reads data from the i2c slave device. + * @platform + * @brief Reads the bytes data from the I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The handle to the i2c device - * @param[out] data The address of data buffer to read + * @param[in] i2c The I2C handle + * @param[out] data The data buffer to read * @param[in] length The size of data buffer (in bytes) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_i2c_write() */ -int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length); +int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length); /** - * @brief Write data to the i2c slave device. + * @platform + * @brief Writes the bytes data to the I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The handle to the i2c device - * @param[in] data The address of data buffer to write + * @param[in] i2c The I2C handle + * @param[in] data The data buffer to write * @param[in] length The size of data buffer (in bytes) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - */ -int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length); - -/** - * @brief Reads single byte data from the i2c slave device. - * @since_tizen 4.0 * - * @param[in] i2c The handle to the i2c device - * @param[out] data The address of data buffer to read - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * @see peripheral_i2c_read() */ -int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data); +int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length); /** - * @brief Write single byte data to the i2c slave device. + * @platform + * @brief Reads single byte data from the register of the I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The handle to the i2c device - * @param[in] data The byte value to write + * @param[in] i2c The I2C handle + * @param[in] reg The register address of the I2C slave device to read + * @param[out] data The single byte data to read * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - */ -int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data); - -/** - * @brief Reads byte data from the register of i2c slave device. - * @since_tizen 4.0 * - * @param[in] i2c The handle to the i2c device - * @param[in] address The register address of the i2c slave device to read - * @param[out] data The byte output of slave device(register value) - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * @see peripheral_i2c_write_register_byte() */ -int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data); +int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data); /** - * @brief Write byte data to the register of i2c slave device. + * @platform + * @brief Writes single byte data to the register of the I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The handle to the i2c device - * @param[in] address The register address of the i2c slave device to write - * @param[in] data The byte value to write + * @param[in] i2c The I2C handle + * @param[in] reg The register address of the I2C slave device to write + * @param[in] data The single byte data to write * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_i2c_read_register_byte() */ -int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data); +int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data); /** - * @brief Reads word data from the register of i2c slave device. + * @platform + * @brief Reads word data from the register of the I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The handle to the i2c device - * @param[in] address The register address of the i2c slave device to read - * @param[out] data The word output(2 bytes) of slave device(register value) + * @param[in] i2c The I2C handle + * @param[in] reg The register address of the I2C slave device to read + * @param[out] data The word(2 bytes) data to read * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_i2c_write_register_word() */ -int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data); +int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data); /** - * @brief Write byte data to the register of i2c slave device. + * @platform + * @brief Writes word data to the register of the I2C slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] i2c The handle to the i2c device - * @param[in] address The register address of the i2c slave device to write - * @param[in] data The word(2 bytes) value to write + * @param[in] i2c The I2C handle + * @param[in] reg The register address of the I2C slave device to write + * @param[in] data The word(2 bytes) data to write * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_i2c_read_register_word() */ -int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data); +int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data); /** * @} */ /** - * @addtogroup CAPI_SYSTEM_PERIPHERAL_PWM_MODULE + * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE * @{ */ /** - * @brief The handle to the pwm device + * @brief The handle of the PWM device. * @since_tizen 4.0 */ typedef struct _peripheral_pwm_s *peripheral_pwm_h; /** * @brief Enumeration for Polarity. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_PWM_POLARITY_NORMAL = 0, - PERIPHERAL_PWM_POLARITY_INVERSED, + PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH = 0, /**< PWM signal start in the active high state (Normal) */ + PERIPHERAL_PWM_POLARITY_ACTIVE_LOW, /**< PWM signal start in the active low state (Inversed) */ } peripheral_pwm_polarity_e; /** - * @brief Initializes(export) pwm device and creates pwm handle. + * @platform + * @brief Opens the PWM pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * @remarks @a pwm should be released with peripheral_pwm_close() * - * @param[in] device The pwm chip number - * @param[in] channel The pwm channel number to control - * @param[out] pwm The pwm handle is created on success + * @param[in] chip The PWM chip number + * @param[in] pin The PWM pin(channel) number to control + * @param[out] pwm The PWM handle is created on success * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_pwm_close() + * @post peripheral_pwm_close() */ -int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm); +int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm); /** - * @brief Destory the pwm handle and finalize(unexport) the pwm device. + * @platform + * @brief Closes the PWM pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] pwm The handle to the pwm device + * @param[in] pwm The PWM handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_pwm_open() + * @pre peripheral_pwm_open() */ int peripheral_pwm_close(peripheral_pwm_h pwm); /** - * @brief Sets Period of the pwm device. - * @since_tizen 4.0 - * - * @param[in] pwm The handle to the pwm device - * @param[in] period The total period of the PWM signal (in nanoseconds) - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - */ -int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period); - -/** - * @brief Gets Period of the pwm device. + * @platform + * @brief Sets period of the PWM pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] pwm The handle to the pwm device - * @param[out] period The total period of the PWM signal (in nanoseconds) + * @param[in] pwm The PWM handle + * @param[in] period_ns The total period of the PWM pin (in nanoseconds) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period); +int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns); /** - * @brief Sets Duty Cycle of the pwm device. + * @platform + * @brief Sets duty cycle of the PWM pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] pwm The handle to the pwm device - * @param[in] duty_cycle The active time of the pwm signal (in nanoseconds) + * @param[in] pwm The PWM handle + * @param[in] duty_cycle_ns The duty cycle of the PWM pin (in nanoseconds) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); +int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns); /** - * @brief Gets Duty Cycle of the pwm device. + * @platform + * @brief Sets polarity of the PWM pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] pwm The handle to the pwm device - * @param[out] duty_cycle The active time of the pwm signal (in nanoseconds) + * @param[in] pwm The PWM handle + * @param[in] polarity The polarity of the PWM pin * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - */ -int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle); - -/** - * @brief Sets Polarity of the pwm device. - * @since_tizen 4.0 - * - * @param[in] pwm The handle to the pwm device - * @param[in] polarity The polarity of the pwm signal * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * @see peripheral_pwm_polarity_e */ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity); /** - * @brief Gets Polarity of the pwm device. + * @platform + * @brief Enables the PWM pin. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] pwm The handle to the pwm device - * @param[out] polarity The polarity of the pwm signal - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - */ -int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity); - -/** - * @brief Enable of the pwm device. - * @since_tizen 4.0 - * - * @param[in] pwm The handle to the pwm device - * @param[in] enable Enable/disable the pwm signal - * true - enable - * false - disable - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - */ -int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable); - -/** - * @brief Gets Enable status of the pwm device. - * @since_tizen 4.0 - * - * @param[in] pwm The handle to the pwm device - * @param[out] enable Enable/disable the pwm signal + * @param[in] pwm The PWM handle + * @param[in] enabled Enable/disable the PWM pin * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable); +int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enabled); /** * @} */ /** - * @addtogroup CAPI_SYSTEM_PERIPHERAL_ADC_MODULE + * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE * @{ */ /** - * @brief Reads data from the adc device. + * @brief The handle to the UART device. * @since_tizen 4.0 - * - * @param[in] device The device number of the adc device - * @param[in] channel The channel number to read - * @param[out] data The address of buffer to read - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_adc_read(unsigned int device, unsigned int channel, int *data); - -/** -* @} -*/ +typedef struct _peripheral_uart_s *peripheral_uart_h; /** - * @addtogroup CAPI_SYSTEM_PERIPHERAL_UART_MODULE - * @{ + * @brief Enumeration for baud rate. + * @since_tizen 4.0 */ - -/** - * @brief The handle to the uart device +typedef enum { + PERIPHERAL_UART_BAUD_RATE_0 = 0, /**< The number of signal in one second is 0 */ + PERIPHERAL_UART_BAUD_RATE_50, /**< The number of signal in one second is 50 */ + PERIPHERAL_UART_BAUD_RATE_75, /**< The number of signal in one second is 75 */ + PERIPHERAL_UART_BAUD_RATE_110, /**< The number of signal in one second is 110 */ + PERIPHERAL_UART_BAUD_RATE_134, /**< The number of signal in one second is 134 */ + PERIPHERAL_UART_BAUD_RATE_150, /**< The number of signal in one second is 150 */ + PERIPHERAL_UART_BAUD_RATE_200, /**< The number of signal in one second is 200 */ + PERIPHERAL_UART_BAUD_RATE_300, /**< The number of signal in one second is 300 */ + PERIPHERAL_UART_BAUD_RATE_600, /**< The number of signal in one second is 600 */ + PERIPHERAL_UART_BAUD_RATE_1200, /**< The number of signal in one second is 1200 */ + PERIPHERAL_UART_BAUD_RATE_1800, /**< The number of signal in one second is 1800 */ + PERIPHERAL_UART_BAUD_RATE_2400, /**< The number of signal in one second is 2400 */ + PERIPHERAL_UART_BAUD_RATE_4800, /**< The number of signal in one second is 4800 */ + PERIPHERAL_UART_BAUD_RATE_9600, /**< The number of signal in one second is 9600 */ + PERIPHERAL_UART_BAUD_RATE_19200, /**< The number of signal in one second is 19200 */ + PERIPHERAL_UART_BAUD_RATE_38400, /**< The number of signal in one second is 38400 */ + PERIPHERAL_UART_BAUD_RATE_57600, /**< The number of signal in one second is 57600 */ + PERIPHERAL_UART_BAUD_RATE_115200, /**< The number of signal in one second is 115200 */ + PERIPHERAL_UART_BAUD_RATE_230400, /**< The number of signal in one second is 230400 */ +} peripheral_uart_baud_rate_e; + +/** + * @brief Enumeration for byte size. * @since_tizen 4.0 */ -typedef struct _peripheral_uart_s *peripheral_uart_h; +typedef enum { + PERIPHERAL_UART_BYTE_SIZE_5BIT = 0, /**< 5 data bits */ + PERIPHERAL_UART_BYTE_SIZE_6BIT, /**< 6 data bits */ + PERIPHERAL_UART_BYTE_SIZE_7BIT, /**< 7 data bits */ + PERIPHERAL_UART_BYTE_SIZE_8BIT, /**< 8 data bits */ +} peripheral_uart_byte_size_e; /** - * @brief Enumeration for Baud Rate. + * @brief Enumeration for parity bit. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_UART_BAUDRATE_0 = 0, - PERIPHERAL_UART_BAUDRATE_50, - PERIPHERAL_UART_BAUDRATE_75, - PERIPHERAL_UART_BAUDRATE_110, - PERIPHERAL_UART_BAUDRATE_134, - PERIPHERAL_UART_BAUDRATE_150, - PERIPHERAL_UART_BAUDRATE_200, - PERIPHERAL_UART_BAUDRATE_300, - PERIPHERAL_UART_BAUDRATE_600, - PERIPHERAL_UART_BAUDRATE_1200, - PERIPHERAL_UART_BAUDRATE_1800, - PERIPHERAL_UART_BAUDRATE_2400, - PERIPHERAL_UART_BAUDRATE_4800, - PERIPHERAL_UART_BAUDRATE_9600, - PERIPHERAL_UART_BAUDRATE_19200, - PERIPHERAL_UART_BAUDRATE_38400, - PERIPHERAL_UART_BAUDRATE_57600, - PERIPHERAL_UART_BAUDRATE_115200, - PERIPHERAL_UART_BAUDRATE_230400 -} peripheral_uart_baudrate_e; - -/** - * @brief Enumeration for Byte Size. + PERIPHERAL_UART_PARITY_NONE = 0, /**< No parity is used */ + PERIPHERAL_UART_PARITY_EVEN, /**< Even parity is used */ + PERIPHERAL_UART_PARITY_ODD, /**< ODD parity is used */ +} peripheral_uart_parity_e; + +/** + * @brief Enumeration for stop bits. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_UART_BYTESIZE_5BIT = 0, - PERIPHERAL_UART_BYTESIZE_6BIT, - PERIPHERAL_UART_BYTESIZE_7BIT, - PERIPHERAL_UART_BYTESIZE_8BIT -} peripheral_uart_bytesize_e; + PERIPHERAL_UART_STOP_BITS_1BIT = 0, /**< One stop bit */ + PERIPHERAL_UART_STOP_BITS_2BIT, /**< Two stop bits */ +} peripheral_uart_stop_bits_e; /** - * @brief Enumeration for Parity Bit. + * @brief Enumeration for hardware flow control. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_UART_PARITY_NONE = 0, - PERIPHERAL_UART_PARITY_EVEN, - PERIPHERAL_UART_PARITY_ODD -} peripheral_uart_parity_e; + PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE = 0, /**< No hardware flow control */ + PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS, /**< Automatic RTS/CTS hardware flow control*/ +} peripheral_uart_hardware_flow_control_e; /** - * @brief Enumeration for Stop Bits. + * @brief Enumeration for software flow control. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_UART_STOPBITS_1BIT = 0, - PERIPHERAL_UART_STOPBITS_2BIT -} peripheral_uart_stopbits_e; + PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE = 0, /**< No software flow control */ + PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, /**< XON/XOFF software flow control */ +} peripheral_uart_software_flow_control_e; /** - * @brief Initializes uart communication and creates uart handle. + * @platform + * @brief Opens the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * @remarks @a uart should be released with peripheral_uart_close() * - * @param[in] port The uart port number that the slave device is connected - * @param[out] uart The uart handle is created on success + * @param[in] port The UART port number that the slave device is connected + * @param[out] uart The UART handle is created on success * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied + * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed * - * @see peripheral_uart_close() + * @post peripheral_uart_close() */ int peripheral_uart_open(int port, peripheral_uart_h *uart); /** - * @brief Destory the uart handle and release the communication. + * @platform + * @brief Closes the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The handle to the uart device + * @param[in] uart The UART handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * - * @see peripheral_uart_open() + * @pre peripheral_uart_open() */ int peripheral_uart_close(peripheral_uart_h uart); /** - * @brief Flush all input that has received but not yet been read by the uart - * device, or all output written but not transmitted to the uart device. + * @platform + * @brief Sets baud rate of the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The uart handle + * @param[in] uart The UART handle + * @param[in] baud Baud rate of the UART device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_uart_baud_rate_e */ -int peripheral_uart_flush(peripheral_uart_h uart); +int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud); /** - * @brief Sets baudrate of the uart device. + * @platform + * @brief Sets byte size of the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The handle to the uart device to set - * @param[in] baud Baudrate of the uart device + * @param[in] uart The UART handle + * @param[in] byte_size Byte size of the UART device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_uart_byte_size_e */ -int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud); +int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size); /** - * @brief Sets mode of the uart device. + * @platform + * @brief Sets parity bit of the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The handle to the uart device to set - * @param[in] bytesize Byte size of the uart device - * @param[in] parity Parity bits of the uart device - * @param[in] stopbits Stop bits of the uart device + * @param[in] uart The UART handle + * @param[in] parity Parity bit of the UART device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_uart_parity_e */ -int peripheral_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits); +int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity); /** - * @brief Sets flow control of the uart device. + * @platform + * @brief Sets stop bits of the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The handle to the uart device to set - * @param[in] xonxoff Turns a transmitter on or off - * @param[in] rtscts Turns "Request to Send/Clear to Send" on or off + * @param[in] uart The UART handle + * @param[in] stop_bits Stop bits of the UART device * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_uart_stop_bits_e */ -int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts); +int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits); /** - * @brief Reads data from the uart device. + * @platform + * @brief Sets flow control of the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The handle to the uart device - * @param[out] data The address of read buffer - * @param[out] length The size of data buffer (in bytes) + * @param[in] uart The UART handle + * @param[in] sw_flow_control Software flow control (Turns a transmitter on or off) + * @param[in] hw_flow_control Hardware flow control (Turns "Request to Send/Clear to Send" on or off) + * + * @return 0 on success, otherwise a negative error value + * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied + * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported + * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_uart_software_flow_control_e + * @see peripheral_uart_hardware_flow_control_e + */ +int peripheral_uart_set_flow_control(peripheral_uart_h uart, + peripheral_uart_software_flow_control_e sw_flow_control, + peripheral_uart_hardware_flow_control_e hw_flow_control); + +/** + * @platform + * @brief Reads data from the UART slave device. + * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * + * @param[in] uart The UART handle + * @param[out] data The buffer to read + * @param[out] length The size of buffer (in bytes) * * @return the number of bytes read on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_uart_write() */ -int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length); +int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length); /** - * @brief Write data to the uart device. + * @platform + * @brief Writes data to the UART slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] uart The handle to the uart device - * @param[in] data The address of buffer to write - * @param[in] length The size of data (in bytes) + * @param[in] uart The UART handle + * @param[in] data The buffer to write + * @param[in] length The size of buffer (in bytes) * * @return the number of bytes write on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_uart_read() */ -int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length); +int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length); /** * @} */ /** - * @addtogroup CAPI_SYSTEM_PERIPHERAL_SPI_MODULE + * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE * @{ */ /** - * @brief The handle to the spi device + * @brief The handle of a SPI device. * @since_tizen 4.0 */ -typedef struct _peripheral_spi_s* peripheral_spi_h; +typedef struct _peripheral_spi_s *peripheral_spi_h; /** - * @brief Enumeration for SPI mode. + * @brief Enumeration of SPI transfer modes. + * @since_tizen 4.0 */ typedef enum { - PERIPHERAL_SPI_MODE_0 = 0, - PERIPHERAL_SPI_MODE_1, - PERIPHERAL_SPI_MODE_2, - PERIPHERAL_SPI_MODE_3 + PERIPHERAL_SPI_MODE_0 = 0, /**< CPOL = 0, CPHa = 0 Mode */ + PERIPHERAL_SPI_MODE_1, /**< CPOL = 0, CPHa = 1 Mode */ + PERIPHERAL_SPI_MODE_2, /**< CPOL = 1, CPHa = 0 Mode */ + PERIPHERAL_SPI_MODE_3, /**< CPOL = 1, CPHa = 1 Mode */ } peripheral_spi_mode_e; /** - * @brief Initializes spi communication and creates spi handle. + * @brief Enumeration of bit orders. * @since_tizen 4.0 - * - * @param[in] bus The spi bus number that the slave device is connected - * @param[in] cs The spi chip select number that the slave device is connected - * @param[out] spi The spi handle is created on success - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * - * @see peripheral_spi_close() */ -int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi); +typedef enum { + PERIPHERAL_SPI_BIT_ORDER_MSB = 0, /**< Use most siginificant bit first */ + PERIPHERAL_SPI_BIT_ORDER_LSB, /**< Use least significant bit first */ +} peripheral_spi_bit_order_e; /** - * @brief Destory the spi handle and release the communication. + * @platform + * @brief Opens a SPI slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * @remarks @a spi should be released with peripheral_spi_close() * - * @param[in] spi The handle to the spi device + * @param[in] bus The SPI bus number + * @param[in] cs The SPI chip select number + * @param[out] spi The SPI device handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful + * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied + * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error * - * @see peripheral_spi_open() + * @post peripheral_spi_close() */ -int peripheral_spi_close(peripheral_spi_h spi); +int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi); /** - * @brief Sets mode of the spi device. + * @platform + * @brief Closes the SPI slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device - * @param[in] mode The mode of the spi device + * @param[in] spi The SPI device handle * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - */ -int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); - -/** - * @brief Gets mode of the spi device. - * @since_tizen 4.0 - * - * @param[in] spi The handle to the spi device - * @param[out] mode The mode of the spi device * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * @see peripheral_spi_open() */ -int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode); +int peripheral_spi_close(peripheral_spi_h spi); /** - * @brief Sets bits justification of the spi device. + * @platform + * @brief Sets the SPI transfer mode. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device - * @param[in] lsb The bit position to be transmitted first - * true - LSB first - * false - MSB first + * @param[in] spi The SPI device handle + * @param[in] mode The SPI transfer mode * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_spi_mode_e */ -int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb); +int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); /** - * @brief Gets bits justification of the spi device. + * @platform + * @brief Sets the SPI bit order. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device - * @param[out] lsb The bit position to be transmitted first + * @param[in] spi The SPI device handle + * @param[in] bit_order The transfer bit order * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * + * @see peripheral_spi_bit_order_e */ -int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb); +int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order); /** - * @brief Sets the number of bits per word of the spi device + * @platform + * @brief Sets the number of bits per word. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device + * @param[in] spi The SPI device handle * @param[in] bits The number of bits per word (in bits) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); +int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits); /** - * @brief Gets the number of bits per word of the spi device + * @platform + * @brief Sets the frequency of the SPI bus. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio + * @remarks The frequencies supported are board dependent. * - * @param[in] spi The handle to the spi device - * @param[out] bits The number of bits per word (in bits) + * @param[in] spi The SPI device handle + * @param[in] freq_hz Frequency to set (in Hz) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed */ -int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits); +int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz); /** - * @brief Sets default max speed of the spi device. + * @platform + * @brief Reads the bytes data from the SPI slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device - * @param[in] freq Max speed (in hz) + * @param[in] spi The SPI device handle + * @param[out] data The data buffer to read + * @param[in] length The size of data buffer (in bytes) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed - */ -int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq); - -/** - * @brief Gets default max speed of the spi device. - * @since_tizen 4.0 - * - * @param[in] spi The handle to the spi device - * @param[out] freq Max speed (in hz) * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed + * @see peripheral_spi_write() */ - -int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq); +int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length); /** - * @brief Reads data from the slave device. + * @platform + * @brief Writes the bytes data to the SPI slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device - * @param[out] data The address of buffer to read + * @param[in] spi The SPI device handle + * @param[in] data The data buffer to write * @param[in] length The size of data buffer (in bytes) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error - */ -int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length); - -/** - * @brief Write data to the slave device. - * @since_tizen 4.0 * - * @param[in] spi The handle to the spi device - * @param[in] data The address of buffer to write - * @param[in] length The size of data (in bytes) - * - * @return 0 on success, otherwise a negative error value - * @retval #PERIPHERAL_ERROR_NONE Successful - * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed - * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * @see peripheral_spi_read() */ -int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length); +int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length); /** - * @brief Exchange data with the slave device. + * @platform + * @brief Exchanges the bytes data to the SPI slave device. * @since_tizen 4.0 + * @privlevel platform + * @privilege http://tizen.org/privilege/peripheralio * - * @param[in] spi The handle to the spi device - * @param[in] txdata The address of buffer to write - * @param[out] rxdata The address of buffer to read - * @param[in] length The size of data (in bytes) + * @param[in] spi The SPI 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) * * @return 0 on success, otherwise a negative error value * @retval #PERIPHERAL_ERROR_NONE Successful * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed + * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed + * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error + * + * @see peripheral_spi_read() + * @see peripheral_spi_write() */ -int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length); +int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length); /** * @} @@ -1133,4 +1197,4 @@ int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsig } #endif -#endif /* __PERIPHERAL_IO_H__ */ +#endif /* __TIZEN_SYSTEM_PERIPHERAL_IO_H__ */ -- 2.7.4 From 8dd8d5ded058a3e8583d2b4626e76b42e9a523eb Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 09:51:33 +0900 Subject: [PATCH 03/16] adc: the adc interface is not supported. Signed-off-by: Segwon Change-Id: I47b529fecb5820fcb633d990b76ee3d01f1aa74f --- CMakeLists.txt | 2 -- include/peripheral_gdbus.h | 1 - include/peripheral_gdbus_adc.h | 25 -------------- src/peripheral_adc.c | 32 ------------------ src/peripheral_gdbus_adc.c | 76 ------------------------------------------ src/peripheral_io.xml | 8 ----- 6 files changed, 144 deletions(-) delete mode 100644 include/peripheral_gdbus_adc.h delete mode 100644 src/peripheral_adc.c delete mode 100644 src/peripheral_gdbus_adc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9455ddb..931ace5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,13 +45,11 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=%{_libdir}") SET(SOURCES src/peripheral_gpio.c src/peripheral_i2c.c src/peripheral_pwm.c - src/peripheral_adc.c src/peripheral_uart.c src/peripheral_spi.c src/peripheral_gdbus_gpio.c src/peripheral_gdbus_i2c.c src/peripheral_gdbus_pwm.c - src/peripheral_gdbus_adc.c src/peripheral_gdbus_uart.c src/peripheral_gdbus_spi.c src/peripheral_io_gdbus.c diff --git a/include/peripheral_gdbus.h b/include/peripheral_gdbus.h index 0e4f15a..ff726de 100644 --- a/include/peripheral_gdbus.h +++ b/include/peripheral_gdbus.h @@ -22,7 +22,6 @@ #define PERIPHERAL_GDBUS_GPIO_PATH "/Org/Tizen/Peripheral_io/Gpio" #define PERIPHERAL_GDBUS_I2C_PATH "/Org/Tizen/Peripheral_io/I2c" #define PERIPHERAL_GDBUS_PWM_PATH "/Org/Tizen/Peripheral_io/Pwm" -#define PERIPHERAL_GDBUS_ADC_PATH "/Org/Tizen/Peripheral_io/Adc" #define PERIPHERAL_GDBUS_UART_PATH "/Org/Tizen/Peripheral_io/Uart" #define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi" #define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io" diff --git a/include/peripheral_gdbus_adc.h b/include/peripheral_gdbus_adc.h deleted file mode 100644 index 2f90ecf..0000000 --- a/include/peripheral_gdbus_adc.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 __PERIPHERAL_GDBUS_ADC_H__ -#define __PERIPHERAL_GDBUS_ADC_H__ - -void adc_proxy_init(void); -void adc_proxy_deinit(void); - -int peripheral_gdbus_adc_read(unsigned int device, unsigned int channel, int *data); - -#endif /* __PERIPHERAL_GDBUS_ADC_H__ */ diff --git a/src/peripheral_adc.c b/src/peripheral_adc.c deleted file mode 100644 index 5997ad1..0000000 --- a/src/peripheral_adc.c +++ /dev/null @@ -1,32 +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. - */ - -#include "peripheral_io.h" -#include "peripheral_gdbus_adc.h" -#include "peripheral_common.h" - -int peripheral_adc_read(unsigned int device, unsigned int channel, int *data) -{ - int ret; - - adc_proxy_init(); - - ret = peripheral_gdbus_adc_read(device, channel, data); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read, ret : %d", ret); - - return ret; -} diff --git a/src/peripheral_gdbus_adc.c b/src/peripheral_gdbus_adc.c deleted file mode 100644 index f52c0b8..0000000 --- a/src/peripheral_gdbus_adc.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 "peripheral_gdbus.h" -#include "peripheral_common.h" -#include "peripheral_io_gdbus.h" - -PeripheralIoGdbusAdc *adc_proxy = NULL; - -void adc_proxy_init(void) -{ - GError *error = NULL; - - if (adc_proxy != NULL) - return; - - adc_proxy = peripheral_io_gdbus_adc_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - PERIPHERAL_GDBUS_NAME, - PERIPHERAL_GDBUS_ADC_PATH, - NULL, - &error); -} - -void adc_proxy_deinit() -{ - if (adc_proxy) { - g_object_unref(adc_proxy); - if (!G_IS_OBJECT(adc_proxy)) - adc_proxy = NULL; - } -} - -int peripheral_gdbus_adc_read(unsigned int device, unsigned int channel, int *data) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value; - - if (adc_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_adc_call_read_sync( - adc_proxy, - device, - channel, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *data = value; - - return ret; -} diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml index 878fb5c..ad80f04 100644 --- a/src/peripheral_io.xml +++ b/src/peripheral_io.xml @@ -143,14 +143,6 @@ - - - - - - - - -- 2.7.4 From ca6e6994b7c0be79156d53d0c69e7eb8b97fdb86 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 12:12:41 +0900 Subject: [PATCH 04/16] api: sync functions name with changed apis name. Signed-off-by: Segwon Change-Id: I12c8dcc1a850b182b791674d0fe4891f74d3717a --- include/peripheral_gdbus_gpio.h | 8 +- include/peripheral_gdbus_pwm.h | 8 +- include/peripheral_gdbus_spi.h | 12 +-- include/peripheral_gdbus_uart.h | 9 +- src/peripheral_gdbus_gpio.c | 118 ++++++------------------- src/peripheral_gdbus_pwm.c | 117 ++----------------------- src/peripheral_gdbus_spi.c | 119 ++----------------------- src/peripheral_gdbus_uart.c | 43 ++++++--- src/peripheral_gpio.c | 188 +++++++++++++++------------------------- src/peripheral_i2c.c | 54 +++--------- src/peripheral_io.xml | 102 ++++++---------------- src/peripheral_pwm.c | 74 +++------------- src/peripheral_spi.c | 77 +++------------- src/peripheral_uart.c | 65 ++++++++------ 14 files changed, 254 insertions(+), 740 deletions(-) diff --git a/include/peripheral_gdbus_gpio.h b/include/peripheral_gdbus_gpio.h index 0d23b91..39c67c5 100644 --- a/include/peripheral_gdbus_gpio.h +++ b/include/peripheral_gdbus_gpio.h @@ -22,13 +22,11 @@ void gpio_proxy_deinit(void); int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction); int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction); +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); +int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data); +int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio); int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value); int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value); -int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge); -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge); -int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data); -int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/peripheral_gdbus_pwm.h b/include/peripheral_gdbus_pwm.h index 3fc3cab..f6d4c1c 100644 --- a/include/peripheral_gdbus_pwm.h +++ b/include/peripheral_gdbus_pwm.h @@ -20,15 +20,11 @@ void pwm_proxy_init(void); void pwm_proxy_deinit(void); -int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel); +int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period); -int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period); -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle); -int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle); +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns); int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity); -int peripheral_gdbus_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity); int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable); -int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/peripheral_gdbus_spi.h b/include/peripheral_gdbus_spi.h index 78e7e97..7ab743a 100644 --- a/include/peripheral_gdbus_spi.h +++ b/include/peripheral_gdbus_spi.h @@ -22,15 +22,11 @@ void spi_proxy_deinit(); int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); int peripheral_gdbus_spi_close(peripheral_spi_h spi); int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode); -int peripheral_gdbus_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode); -int peripheral_gdbus_spi_set_lsb_first(peripheral_spi_h spi, bool lsb); -int peripheral_gdbus_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb); -int peripheral_gdbus_spi_set_bits(peripheral_spi_h spi, unsigned char bits); -int peripheral_gdbus_spi_get_bits(peripheral_spi_h spi, unsigned char *bits); -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq); -int peripheral_gdbus_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq); +int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb); +int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits); +int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz); int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length); int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int length); -int peripheral_gdbus_spi_read_write(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); +int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/peripheral_gdbus_uart.h b/include/peripheral_gdbus_uart.h index 7c7f8e7..15b5d06 100644 --- a/include/peripheral_gdbus_uart.h +++ b/include/peripheral_gdbus_uart.h @@ -21,10 +21,11 @@ void uart_proxy_deinit(); int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); int peripheral_gdbus_uart_close(peripheral_uart_h uart); -int peripheral_gdbus_uart_flush(peripheral_uart_h uart); -int peripheral_gdbus_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud); -int peripheral_gdbus_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits); -int peripheral_gdbus_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts); +int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud); +int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size); +int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity); +int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits); +int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts); int peripheral_gdbus_uart_read(peripheral_uart_h uart, uint8_t *data, int length); int peripheral_gdbus_uart_write(peripheral_uart_h uart, uint8_t *data, int length); diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c index b476e47..be01654 100644 --- a/src/peripheral_gdbus_gpio.c +++ b/src/peripheral_gdbus_gpio.c @@ -23,17 +23,19 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -extern int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestamp); - -void handle_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, - gint value, - guint64 timestamp, - gpointer user_data); +extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); PeripheralIoGdbusGpio *gpio_proxy = NULL; +static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data) +{ + int err = PERIPHERAL_ERROR_NONE; + if (!gpio) + err = PERIPHERAL_ERROR_IO_ERROR; + + peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err); +} + void gpio_proxy_init(void) { GError *error = NULL; @@ -57,8 +59,8 @@ void gpio_proxy_init(void) } g_signal_connect(gpio_proxy, - "gpio-changed", - G_CALLBACK(handle_gpio_changed), + "interrupted-cb", + G_CALLBACK(__peripheral_gpio_interrupted_cb), NULL); } @@ -71,19 +73,6 @@ void gpio_proxy_deinit() } } -void handle_gpio_changed( - PeripheralIoGdbusGpio *gpio, - gint pin, - gint value, - guint64 timestamp, - gpointer user_data) -{ - if (!gpio) - return; - - peripheral_gpio_isr_callback(pin, value, timestamp); -} - int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) { GError *error = NULL; @@ -127,33 +116,6 @@ int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) return ret; } -int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_get_direction_sync( - gpio_proxy, - gpio->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - } - - if (value >= PERIPHERAL_GPIO_DIRECTION_IN && value <= PERIPHERAL_GPIO_DIRECTION_OUT_HIGH) - *direction = value; - else - return PERIPHERAL_ERROR_UNKNOWN; - - return ret; -} - int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) { GError *error = NULL; @@ -176,39 +138,17 @@ int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_ return ret; } -int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_gpio_call_read_sync( - gpio_proxy, - gpio->handle, - value, - &ret, - NULL, - &error) == FALSE) { - _E("Error in %s() : %s", __func__, error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - return ret; -} - -int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) +int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_write_sync( + if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( gpio_proxy, gpio->handle, - value, + edge, &ret, NULL, &error) == FALSE) { @@ -220,18 +160,16 @@ int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) return ret; } -int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) +int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_get_edge_mode_sync( + if (peripheral_io_gdbus_gpio_call_set_interrupted_cb_sync( gpio_proxy, gpio->handle, - &value, &ret, NULL, &error) == FALSE) { @@ -240,25 +178,19 @@ int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_ return PERIPHERAL_ERROR_UNKNOWN; } - if (value >= PERIPHERAL_GPIO_EDGE_NONE && value <= PERIPHERAL_GPIO_EDGE_BOTH) - *edge = value; - else - return PERIPHERAL_ERROR_UNKNOWN; - return ret; } -int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge) +int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync( + if (peripheral_io_gdbus_gpio_call_unset_interrupted_cb_sync( gpio_proxy, gpio->handle, - edge, &ret, NULL, &error) == FALSE) { @@ -270,16 +202,17 @@ int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_ return ret; } -int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) +int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_register_irq_sync( + if (peripheral_io_gdbus_gpio_call_read_sync( gpio_proxy, gpio->handle, + value, &ret, NULL, &error) == FALSE) { @@ -291,16 +224,17 @@ int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callba return ret; } -int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio) +int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_gpio_call_unregister_irq_sync( + if (peripheral_io_gdbus_gpio_call_write_sync( gpio_proxy, gpio->handle, + value, &ret, NULL, &error) == FALSE) { @@ -310,4 +244,4 @@ int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio) } return ret; -} +} \ No newline at end of file diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c index b32074e..5d83882 100644 --- a/src/peripheral_gdbus_pwm.c +++ b/src/peripheral_gdbus_pwm.c @@ -52,7 +52,7 @@ void pwm_proxy_deinit() } } -int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel) +int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -61,8 +61,8 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel) if (peripheral_io_gdbus_pwm_call_open_sync( pwm_proxy, - device, - channel, + chip, + pin, &pwm->handle, &ret, NULL, @@ -118,32 +118,7 @@ int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period) return ret; } -int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_period_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *period = value; - - return ret; -} - -int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) +int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle_ns) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -153,7 +128,7 @@ int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync( pwm_proxy, pwm->handle, - duty_cycle, + duty_cycle_ns, &ret, NULL, &error) == FALSE) { @@ -165,31 +140,6 @@ int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) return ret; } -int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *duty_cycle = value; - - return ret; -} - int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { GError *error = NULL; @@ -212,34 +162,6 @@ int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polar return ret; } -int peripheral_gdbus_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gint value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_polarity_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (!value) - *polarity = PERIPHERAL_PWM_POLARITY_NORMAL; - else - *polarity = PERIPHERAL_PWM_POLARITY_INVERSED; - - return ret; -} - int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) { GError *error = NULL; @@ -261,32 +183,3 @@ int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable) return ret; } - -int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gboolean value = 0; - - if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_pwm_call_get_enable_sync( - pwm_proxy, - pwm->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (!value) - *enable = false; - else - *enable = true; - - return ret; -} - diff --git a/src/peripheral_gdbus_spi.c b/src/peripheral_gdbus_spi.c index b42e926..ae01e87 100644 --- a/src/peripheral_gdbus_spi.c +++ b/src/peripheral_gdbus_spi.c @@ -118,42 +118,14 @@ int peripheral_gdbus_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mo return ret; } -int peripheral_gdbus_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode) +int peripheral_gdbus_spi_set_bit_order(peripheral_spi_h spi, bool lsb) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - guchar value; if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_spi_call_get_mode_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (value <= PERIPHERAL_SPI_MODE_3) - *mode = value; - else - _E("Invalid mode : %d", value); - - return ret; -} - -int peripheral_gdbus_spi_set_lsb_first(peripheral_spi_h spi, bool lsb) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_set_lsb_first_sync( + if (peripheral_io_gdbus_spi_call_set_bit_order_sync( spi_proxy, spi->handle, lsb, @@ -168,39 +140,14 @@ int peripheral_gdbus_spi_set_lsb_first(peripheral_spi_h spi, bool lsb) return ret; } -int peripheral_gdbus_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - gboolean value; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_get_lsb_first_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *lsb = value ? true : false; - - return ret; -} - -int peripheral_gdbus_spi_set_bits(peripheral_spi_h spi, unsigned char bits) +int peripheral_gdbus_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_spi_call_set_bits_sync( + if (peripheral_io_gdbus_spi_call_set_bits_per_word_sync( spi_proxy, spi->handle, bits, @@ -215,32 +162,7 @@ int peripheral_gdbus_spi_set_bits(peripheral_spi_h spi, unsigned char bits) return ret; } -int peripheral_gdbus_spi_get_bits(peripheral_spi_h spi, unsigned char *bits) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - guchar value; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_get_bits_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *bits = (unsigned char)value; - - return ret; -} - -int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) +int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq_hz) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -250,7 +172,7 @@ int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) if (peripheral_io_gdbus_spi_call_set_frequency_sync( spi_proxy, spi->handle, - freq, + freq_hz, &ret, NULL, &error) == FALSE) { @@ -262,31 +184,6 @@ int peripheral_gdbus_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) return ret; } -int peripheral_gdbus_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq) -{ - GError *error = NULL; - peripheral_error_e ret = PERIPHERAL_ERROR_NONE; - guint value; - - if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - - if (peripheral_io_gdbus_spi_call_get_frequency_sync( - spi_proxy, - spi->handle, - &value, - &ret, - NULL, - &error) == FALSE) { - _E("%s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - *freq = (unsigned int)value; - - return ret; -} - int peripheral_gdbus_spi_read(peripheral_spi_h spi, unsigned char *data, int length) { GError *error = NULL; @@ -357,7 +254,7 @@ int peripheral_gdbus_spi_write(peripheral_spi_h spi, unsigned char *data, int le return ret; } -int peripheral_gdbus_spi_read_write(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) +int peripheral_gdbus_spi_transfer(peripheral_spi_h spi, unsigned char *tx_data, unsigned char *rx_data, int length) { GError *error = NULL; peripheral_error_e ret = PERIPHERAL_ERROR_NONE; @@ -379,7 +276,7 @@ int peripheral_gdbus_spi_read_write(peripheral_spi_h spi, unsigned char *tx_data tx_data_array = g_variant_new("a(y)", builder); g_variant_builder_unref(builder); - if (peripheral_io_gdbus_spi_call_read_write_sync( + if (peripheral_io_gdbus_spi_call_transfer_sync( spi_proxy, spi->handle, length, diff --git a/src/peripheral_gdbus_uart.c b/src/peripheral_gdbus_uart.c index 81b77c1..aa3b364 100644 --- a/src/peripheral_gdbus_uart.c +++ b/src/peripheral_gdbus_uart.c @@ -95,16 +95,17 @@ int peripheral_gdbus_uart_close(peripheral_uart_h uart) return ret; } -int peripheral_gdbus_uart_flush(peripheral_uart_h uart) +int peripheral_gdbus_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_flush_sync( + if (peripheral_io_gdbus_uart_call_set_baud_rate_sync( uart_proxy, uart->handle, + baud, &ret, NULL, &error) == FALSE) { @@ -116,17 +117,17 @@ int peripheral_gdbus_uart_flush(peripheral_uart_h uart) return ret; } -int peripheral_gdbus_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud) +int peripheral_gdbus_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_set_baudrate_sync( + if (peripheral_io_gdbus_uart_call_set_byte_size_sync( uart_proxy, uart->handle, - baud, + byte_size, &ret, NULL, &error) == FALSE) { @@ -138,19 +139,17 @@ int peripheral_gdbus_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_b return ret; } -int peripheral_gdbus_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits) +int peripheral_gdbus_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_set_mode_sync( + if (peripheral_io_gdbus_uart_call_set_parity_sync( uart_proxy, uart->handle, - bytesize, parity, - stopbits, &ret, NULL, &error) == FALSE) { @@ -162,14 +161,36 @@ int peripheral_gdbus_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytes return ret; } -int peripheral_gdbus_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts) +int peripheral_gdbus_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) +{ + GError *error = NULL; + gint32 ret = PERIPHERAL_ERROR_NONE; + + if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; + + if (peripheral_io_gdbus_uart_call_set_stop_bits_sync( + uart_proxy, + uart->handle, + stop_bits, + &ret, + NULL, + &error) == FALSE) { + _E("Error in %s() : %s", __func__, error->message); + g_error_free(error); + return PERIPHERAL_ERROR_UNKNOWN; + } + + return ret; +} + +int peripheral_gdbus_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts) { GError *error = NULL; gint32 ret = PERIPHERAL_ERROR_NONE; if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN; - if (peripheral_io_gdbus_uart_call_set_flowcontrol_sync( + if (peripheral_io_gdbus_uart_call_set_flow_control_sync( uart_proxy, uart->handle, xonxoff, diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 8a7ccdf..f7b68ee 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -26,29 +26,24 @@ #include "peripheral_io_gdbus.h" typedef struct { - int pin; - gpio_isr_cb callback; + peripheral_gpio_h handle; + peripheral_gpio_interrupted_cb callback; void *user_data; -} gpio_isr_data_s; +} interrupted_cb_info_s; -static GList *gpio_isr_list = NULL; +static GList *interrupted_cb_info_list = NULL; -int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestamp) +int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int error) { GList *link; - gpio_isr_data_s *isr_data; - gpio_isr_cb_s cb_data; + interrupted_cb_info_s *cb_info; - link = gpio_isr_list; + link = interrupted_cb_info_list; while (link) { - isr_data = (gpio_isr_data_s*)link->data; - - if (isr_data->pin == pin) { - cb_data.pin = pin; - cb_data.value = value; - cb_data.timestamp = timestamp; - if (isr_data->callback) - isr_data->callback(&cb_data, isr_data->user_data); + cb_info = (interrupted_cb_info_s*)link->data; + if (cb_info->handle->pin == pin) { + if (cb_info->callback) + cb_info->callback(cb_info->handle, error, cb_info->user_data); return PERIPHERAL_ERROR_NONE; } link = g_list_next(link); @@ -57,50 +52,50 @@ int peripheral_gpio_isr_callback(int pin, int value, unsigned long long timestam return PERIPHERAL_ERROR_NONE; } -int peripheral_gpio_isr_set(int pin, gpio_isr_cb callback, void *user_data) +static int __interrupted_cb_info_list_append(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { GList *link; - gpio_isr_data_s *isr_data = NULL; + interrupted_cb_info_s *cb_info = NULL; - link = gpio_isr_list; + link = interrupted_cb_info_list; while (link) { - gpio_isr_data_s *tmp; - tmp = (gpio_isr_data_s*)link->data; - if (tmp->pin == pin) { - isr_data = tmp; + interrupted_cb_info_s *tmp; + tmp = (interrupted_cb_info_s*)link->data; + if (tmp->handle == gpio) { + cb_info = tmp; break; } link = g_list_next(link); } - if (isr_data == NULL) { - isr_data = (gpio_isr_data_s*)calloc(1, sizeof(gpio_isr_data_s)); - if (isr_data == NULL) { - _E("failed to allocate gpio_isr_data_s"); + if (cb_info == NULL) { + cb_info = (interrupted_cb_info_s*)calloc(1, sizeof(interrupted_cb_info_s)); + if (cb_info == NULL) { + _E("failed to allocate interrupted_cb_info_s"); return PERIPHERAL_ERROR_OUT_OF_MEMORY; } - gpio_isr_list = g_list_append(gpio_isr_list, isr_data); + link = g_list_append(link, cb_info); } - isr_data->pin = pin; - isr_data->callback = callback; - isr_data->user_data = user_data; + cb_info->handle = gpio; + cb_info->callback = callback; + cb_info->user_data = user_data; return PERIPHERAL_ERROR_NONE; } -int peripheral_gpio_isr_unset(int pin) +static int __interrupted_cb_info_list_remove(peripheral_gpio_h gpio) { GList *link; - gpio_isr_data_s *isr_data; + interrupted_cb_info_s *cb_info; - link = gpio_isr_list; + link = interrupted_cb_info_list; while (link) { - isr_data = (gpio_isr_data_s*)link->data; + cb_info = (interrupted_cb_info_s*)link->data; - if (isr_data->pin == pin) { - gpio_isr_list = g_list_remove_link(gpio_isr_list, link); + if (cb_info->handle == gpio) { + interrupted_cb_info_list = g_list_remove_link(interrupted_cb_info_list, link); free(link->data); g_list_free(link); break; @@ -168,23 +163,6 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) } /** - * @brief Gets direction of the gpio. - */ -int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - ret = peripheral_gdbus_gpio_get_direction(gpio, direction); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get direction of the gpio pin, ret : %d", ret); - - return ret; -} - - -/** * @brief Sets direction of the gpio pin. */ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction) @@ -192,8 +170,6 @@ 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_OUT_HIGH, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid direction input"); /* call gpio_set_direction */ ret = peripheral_gdbus_gpio_set_direction(gpio, direction); @@ -203,55 +179,6 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct return ret; } -/** - * @brief Reads value of the gpio. - */ -int peripheral_gpio_read(peripheral_gpio_h gpio, int *value) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - /* call gpio_read */ - ret = peripheral_gdbus_gpio_read(gpio, value); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read value of the gpio pin, ret : %d", ret); - - return ret; -} - -/** - * @brief Writes value to the gpio. - */ -int peripheral_gpio_write(peripheral_gpio_h gpio, int value) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - /* call gpio_write */ - ret = peripheral_gdbus_gpio_write(gpio, value); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write to the gpio pin, ret : %d", ret); - - return ret; -} - -/** - * @brief Gets the edge mode of the gpio. - */ -int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge) -{ - int ret = PERIPHERAL_ERROR_NONE; - - RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - - ret = peripheral_gdbus_gpio_get_edge_mode(gpio, edge); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get edge mode of the gpio pin, ret : %d", ret); - - return ret; -} /** * @brief Sets the edge mode of the gpio pin. @@ -275,22 +202,22 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e /** * @brief Registers a callback function to be invoked when the gpio interrupt is triggered. */ -int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data) +int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data) { int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - ret = peripheral_gdbus_gpio_register_cb(gpio, callback, user_data); + ret = peripheral_gdbus_gpio_set_interrupted_cb(gpio, callback, user_data); if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to register cb, ret : %d", ret); + _E("Failed to set gpio interrupted cb, ret : %d", ret); return ret; } /* set isr */ - ret = peripheral_gpio_isr_set(gpio->pin, callback, user_data); + ret = __interrupted_cb_info_list_append(gpio, callback, user_data); if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to register gpio isr, ret : %d", ret); + _E("Failed to append gpio interrupt callback info, ret : %d", ret); return ret; } @@ -298,32 +225,55 @@ int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, vo /** * @brief Unregisters the callback function for the gpio handler. */ -int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio) +int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { int ret = PERIPHERAL_ERROR_NONE; RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); - ret = peripheral_gdbus_gpio_unregister_cb(gpio); + ret = peripheral_gdbus_gpio_unset_interrupted_cb(gpio); if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to unregister gpio isr, ret : %d", ret); + _E("Failed to unset gpio interrupt callback, ret : %d", ret); return ret; } - /* clean up isr */ - ret = peripheral_gpio_isr_unset(gpio->pin); + ret = __interrupted_cb_info_list_remove(gpio); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to remove gpio interrupt callback info, ret : %d", ret); return ret; } /** - * @brief Gets pin number of the gpio handle. + * @brief Reads value of the gpio. */ -int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin) +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"); - *gpio_pin = gpio->pin; + /* call gpio_read */ + ret = peripheral_gdbus_gpio_read(gpio, (int *)value); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to read value of the gpio pin, ret : %d", ret); - return PERIPHERAL_ERROR_NONE; + return ret; +} + +/** + * @brief Writes value to the gpio. + */ +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"); + + /* call gpio_write */ + ret = peripheral_gdbus_gpio_write(gpio, (int)value); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to write to the gpio pin, ret : %d", ret); + + return ret; } diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 4035eb6..f52b9b4 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -79,72 +79,42 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) return ret; } -int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length) +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"); - ret = peripheral_gdbus_i2c_read(i2c, data, length); + ret = peripheral_gdbus_i2c_read(i2c, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to read data from device, ret : %d", ret); return ret; } -int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length) +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"); - ret = peripheral_gdbus_i2c_write(i2c, data, length); + ret = peripheral_gdbus_i2c_write(i2c, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to write data to device, ret : %d", ret); return ret; } -int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data) +int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data) { int ret; uint16_t w_data, dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, 0x0, I2C_SMBUS_BYTE, dummy, &w_data); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to read, ret : %d", ret); - - *data = (uint8_t)w_data; - - return ret; -} - -int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data) -{ - int ret = PERIPHERAL_ERROR_NONE; - uint16_t dummy = 0; - - RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, dummy, I2C_SMBUS_BYTE, (uint16_t)data, &dummy); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to write, ret : %d", ret); - - return ret; -} - -int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data) -{ - int ret; - uint16_t w_data, dummy = 0; - - RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_BYTE_DATA, dummy, &w_data); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, dummy, &w_data); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); @@ -153,28 +123,28 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uin return ret; } -int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data) +int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data) { int ret; uint16_t dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); return ret; } -int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data) +int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data) { int ret; uint16_t dummy = 0, data_out; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_WORD_DATA, dummy, &data_out); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, dummy, &data_out); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); @@ -183,14 +153,14 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uin return ret; } -int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data) +int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data) { int ret; uint16_t dummy = 0; RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_WORD_DATA, data, &dummy); + ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, data, &dummy); if (ret != PERIPHERAL_ERROR_NONE) _E("Smbus transaction failed, ret : %d", ret); diff --git a/src/peripheral_io.xml b/src/peripheral_io.xml index ad80f04..9b556d6 100644 --- a/src/peripheral_io.xml +++ b/src/peripheral_io.xml @@ -10,49 +10,39 @@ - - - - - - - - - - - - - - - - - - - - - + - + - + + + + + + + + + + + @@ -93,8 +83,8 @@ - - + + @@ -107,41 +97,21 @@ - - - - - - - - - - - - - - - - - - - - @@ -153,23 +123,27 @@ - + + - + - + - + - + + + + - + @@ -208,41 +182,21 @@ - - - - - - + - - - - - - + - - - - - - - - - - @@ -259,7 +213,7 @@ - + diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index e3718ee..be18d45 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -24,12 +24,12 @@ #include "peripheral_common.h" #include "peripheral_internal.h" -int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm) +int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm) { peripheral_pwm_h handle; int ret = PERIPHERAL_ERROR_NONE; - RETVM_IF(device < 0 || channel < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); /* Initialize */ handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s)); @@ -41,10 +41,10 @@ int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm) pwm_proxy_init(); - ret = peripheral_gdbus_pwm_open(handle, device, channel); + ret = peripheral_gdbus_pwm_open(handle, chip, pin); if (ret != PERIPHERAL_ERROR_NONE) { - _E("Failed to open PWM device : %d, channel : %d", device, channel); + _E("Failed to open PWM chip : %d, pin : %d", chip, pin); free(handle); handle = NULL; } @@ -60,7 +60,7 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0) - _E("Failed to close PWM device, continuing anyway, ret : %d", ret); + _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); pwm_proxy_deinit(); free(pwm); @@ -68,65 +68,37 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) return ret; } -int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period) +int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns) { int ret; RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - ret = peripheral_gdbus_pwm_set_period(pwm, period); + ret = peripheral_gdbus_pwm_set_period(pwm, (int)period_ns); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set period, ret : %d", ret); return ret; } -int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period) +int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns) { int ret; RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - ret = peripheral_gdbus_pwm_get_period(pwm, period); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get period, ret : %d", ret); - - return ret; -} - -int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle); + ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, (int)duty_cycle_ns); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set duty cycle, ret : %d", ret); return ret; } -int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get duty cycle, ret : %d", ret); - - return ret; -} - int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity) { int ret; RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - RETVM_IF(polarity > PERIPHERAL_PWM_POLARITY_INVERSED, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid polarity parameter"); ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity); if (ret != PERIPHERAL_ERROR_NONE) @@ -135,20 +107,7 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e return ret; } -int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_get_polarity(pwm, polarity); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get polarity, ret : %d", ret); - - return ret; -} - -int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable) +int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enable) { int ret; @@ -160,16 +119,3 @@ int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable) return ret; } - -int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable) -{ - int ret; - - RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - - ret = peripheral_gdbus_pwm_get_enable(pwm, enable); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get enable, ret : %d", ret); - - return ret; -} diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index eff8f23..7b2baf7 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -85,130 +85,79 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) return ret; } -int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode) +int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_get_mode(spi, mode); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get spi mode, ret : %d", ret); - - return ret; -} - -int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_set_lsb_first(spi, lsb); + bool lsb = (bit_order == PERIPHERAL_SPI_BIT_ORDER_LSB) ? true : false; + ret = peripheral_gdbus_spi_set_bit_order(spi, lsb); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set lsb first, ret : %d", ret); return ret; } -int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_get_lsb_first(spi, lsb); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get lsb first, ret : %d", ret); - - return ret; -} - -int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits) +int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_set_bits(spi, bits); + ret = peripheral_gdbus_spi_set_bits_per_word(spi, (unsigned char)bits); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set bits per word, ret : %d", ret); return ret; } -int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits) +int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_get_bits(spi, bits); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get bits per word, ret : %d", ret); - - return ret; -} - -int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_set_frequency(spi, freq); + ret = peripheral_gdbus_spi_set_frequency(spi, (unsigned int)freq_hz); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set frequency, ret : %d", ret); return ret; } -int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq) -{ - int ret; - - RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - - ret = peripheral_gdbus_spi_get_frequency(spi, freq); - if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to get spi frequency, ret : %d", ret); - - return ret; -} - -int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length) +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"); - ret = peripheral_gdbus_spi_read(spi, data, length); + ret = peripheral_gdbus_spi_read(spi, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to read from spi device, ret : %d", ret); return ret; } -int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length) +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"); - ret = peripheral_gdbus_spi_write(spi, data, length); + ret = peripheral_gdbus_spi_write(spi, data, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to write to spi device, ret : %d", ret); return ret; } -int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length) +int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length) { int ret; RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_read_write(spi, txdata, rxdata, length); + ret = peripheral_gdbus_spi_transfer(spi, txdata, rxdata, (int)length); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to read and write, ret : %d", ret); diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index 1b18c17..cb62b52 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -76,70 +76,79 @@ int peripheral_uart_close(peripheral_uart_h uart) } /** - * @brief Flush all input that has received but not yet been read by the uart - * device, or all output written but not transmitted to the uart device. + * @brief Sets baudrate of the uart device. */ -int peripheral_uart_flush(peripheral_uart_h uart) +int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud) { 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"); - ret = peripheral_gdbus_uart_flush(uart); + ret = peripheral_gdbus_uart_set_baud_rate(uart, baud); if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to flush, ret : %d", ret); + _E("Failed to set baudrate, ret : %d", ret); return ret; } -/** - * @brief Sets baudrate of the uart device. - */ -int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud) +int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(baud > PERIPHERAL_UART_BAUDRATE_230400, PERIPHERAL_ERROR_INVALID_PARAMETER, - "Invalid baud input"); + RETVM_IF((byte_size < PERIPHERAL_UART_BYTE_SIZE_5BIT) || (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_uart_set_baudrate(uart, baud); + ret = peripheral_gdbus_uart_set_byte_size(uart, byte_size); if (ret != PERIPHERAL_ERROR_NONE) - _E("Failed to set baudrate, ret : %d", ret); + _E("Failed to set uart mode, ret : %d", ret); return ret; } -/** - * @brief Sets baudrate of the uart device. - */ -int peripheral_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits) +int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - RETVM_IF(bytesize > PERIPHERAL_UART_BYTESIZE_8BIT - || parity > PERIPHERAL_UART_PARITY_ODD - || stopbits > PERIPHERAL_UART_STOPBITS_2BIT, - PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + RETVM_IF((parity < PERIPHERAL_UART_PARITY_NONE) || (parity > PERIPHERAL_UART_PARITY_ODD), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter"); - ret = peripheral_gdbus_uart_set_mode(uart, bytesize, parity, stopbits); + ret = peripheral_gdbus_uart_set_parity(uart, parity); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set uart mode, ret : %d", ret); return ret; } +int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits) +{ + int ret; + + 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"); + + ret = peripheral_gdbus_uart_set_stop_bits(uart, stop_bits); + if (ret != PERIPHERAL_ERROR_NONE) + _E("Failed to set uart mode, ret : %d", ret); + + return ret; +} + + /** * @brief Sets baudrate of the uart device. */ -int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts) +int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_software_flow_control_e sw_flow_control, peripheral_uart_hardware_flow_control_e hw_flow_control) { int ret; RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - ret = peripheral_gdbus_uart_set_flowcontrol(uart, xonxoff, rtscts); + 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; + + ret = peripheral_gdbus_uart_set_flow_control(uart, xonxoff, rtscts); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to set flocontrol, ret : %d", ret); @@ -149,14 +158,14 @@ int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool r /** * @brief Reads data from the uart device. */ -int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length) +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"); - ret = peripheral_gdbus_uart_read(uart, data, length); + ret = peripheral_gdbus_uart_read(uart, data, (int)length); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to read from uart device, ret : %d", ret); @@ -166,14 +175,14 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length) /** * @brief Write data to the uart device. */ -int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length) +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"); - ret = peripheral_gdbus_uart_write(uart, data, length); + ret = peripheral_gdbus_uart_write(uart, data, (int)length); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to write to uart device, ret : %d", ret); -- 2.7.4 From fdd8f279b4780d5fcf799c38d2c892cfb7a73dd1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 12:21:38 +0900 Subject: [PATCH 05/16] naming: added static keword at static variable. Signed-off-by: Segwon Change-Id: Ia8e14e8164311f7b40bb146a185eb08d8aabafa7 --- src/peripheral_gdbus_gpio.c | 4 ++-- src/peripheral_gdbus_i2c.c | 2 +- src/peripheral_gdbus_pwm.c | 2 +- src/peripheral_gdbus_spi.c | 2 +- src/peripheral_gdbus_uart.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c index be01654..42025de 100644 --- a/src/peripheral_gdbus_gpio.c +++ b/src/peripheral_gdbus_gpio.c @@ -25,7 +25,7 @@ extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err); -PeripheralIoGdbusGpio *gpio_proxy = NULL; +static PeripheralIoGdbusGpio *gpio_proxy = NULL; static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data) { @@ -244,4 +244,4 @@ int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value) } return ret; -} \ No newline at end of file +} diff --git a/src/peripheral_gdbus_i2c.c b/src/peripheral_gdbus_i2c.c index cc3de07..e0a39ac 100644 --- a/src/peripheral_gdbus_i2c.c +++ b/src/peripheral_gdbus_i2c.c @@ -23,7 +23,7 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -PeripheralIoGdbusI2c *i2c_proxy = NULL; +static PeripheralIoGdbusI2c *i2c_proxy = NULL; void i2c_proxy_init(void) { diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c index 5d83882..e1fdae9 100644 --- a/src/peripheral_gdbus_pwm.c +++ b/src/peripheral_gdbus_pwm.c @@ -23,7 +23,7 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -PeripheralIoGdbusPwm *pwm_proxy = NULL; +static PeripheralIoGdbusPwm *pwm_proxy = NULL; void pwm_proxy_init(void) { diff --git a/src/peripheral_gdbus_spi.c b/src/peripheral_gdbus_spi.c index ae01e87..cc7a8a5 100644 --- a/src/peripheral_gdbus_spi.c +++ b/src/peripheral_gdbus_spi.c @@ -23,7 +23,7 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -PeripheralIoGdbusSpi *spi_proxy = NULL; +static PeripheralIoGdbusSpi *spi_proxy = NULL; void spi_proxy_init(void) { diff --git a/src/peripheral_gdbus_uart.c b/src/peripheral_gdbus_uart.c index aa3b364..78bc0c0 100644 --- a/src/peripheral_gdbus_uart.c +++ b/src/peripheral_gdbus_uart.c @@ -23,7 +23,7 @@ #include "peripheral_internal.h" #include "peripheral_io_gdbus.h" -PeripheralIoGdbusUart *uart_proxy = NULL; +static PeripheralIoGdbusUart *uart_proxy = NULL; void uart_proxy_init(void) { -- 2.7.4 From 1acdf7369bb787e121481f34dbfc16276e1d1876 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 16:37:46 +0900 Subject: [PATCH 06/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 07/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 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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