From 8dd8d5ded058a3e8583d2b4626e76b42e9a523eb Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 09:51:33 +0900 Subject: [PATCH 01/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.34.1 From ca6e6994b7c0be79156d53d0c69e7eb8b97fdb86 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 12:12:41 +0900 Subject: [PATCH 02/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; @@ -167,23 +162,6 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) return ret; } -/** - * @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. */ @@ -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.34.1 From fdd8f279b4780d5fcf799c38d2c892cfb7a73dd1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 12:21:38 +0900 Subject: [PATCH 03/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.34.1 From 1acdf7369bb787e121481f34dbfc16276e1d1876 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 21 Sep 2017 16:37:46 +0900 Subject: [PATCH 04/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.34.1 From 9aad6d71ed47fbab256dfceb490f6b913fb43d64 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 26 Sep 2017 10:59:53 +0900 Subject: [PATCH 05/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.34.1 From 8872887249edaecc3fecab972941512e4cb9db4b Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 27 Sep 2017 18:31:42 +0900 Subject: [PATCH 06/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.34.1 From c6fb7365864887ccf0e0e2c456c3d57ff031e9bd Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 27 Sep 2017 20:43:41 +0900 Subject: [PATCH 07/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.34.1 From 59eb4ca48a82865ea9fbeb51572f750ac15d8f6e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 10 Oct 2017 20:28:43 +0900 Subject: [PATCH 08/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.34.1 From 543435fb7e505e2afb739a4d2b2f064fb508a129 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 16 Oct 2017 17:59:30 +0900 Subject: [PATCH 09/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.34.1 From 9ca0cbee549562738ac79c21b1470d568e5cab09 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 25 Oct 2017 15:49:54 +0900 Subject: [PATCH 10/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.34.1 From 82f0d4234bc1b29c6929ef7a68b27bd6b63022b1 Mon Sep 17 00:00:00 2001 From: Segwon Date: Fri, 27 Oct 2017 00:01:36 +0900 Subject: [PATCH 11/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.34.1 From 2d4b5403cd00e808324def97a8d56800e3a9b4c2 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 7 Nov 2017 16:04:04 +0900 Subject: [PATCH 12/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.34.1 From dc0be3157a3a53c82f5a0c5008baf14521196d91 Mon Sep 17 00:00:00 2001 From: Segwon Date: Tue, 7 Nov 2017 16:06:19 +0900 Subject: [PATCH 13/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.34.1 From c606f0ab36778e64b5da531bf1e2704195dfb38e Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 13:30:38 +0900 Subject: [PATCH 14/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.34.1 From 682d82c41643130b0966cf6ff7cf8612b1419c14 Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 14:31:31 +0900 Subject: [PATCH 15/16] interface: move interface header files to top level include folder. - seperated for readability. - included interface files when running build. Signed-off-by: Segwon Change-Id: I4847dc8a7cf5f81de098a730c640229dfbc8a560 --- CMakeLists.txt | 6 ++++++ {src/interface/include => include/interface}/gpio.h | 0 {src/interface/include => include/interface}/i2c.h | 0 {src/interface/include => include/interface}/pwm.h | 0 {src/interface/include => include/interface}/spi.h | 0 {src/interface/include => include/interface}/uart.h | 0 6 files changed, 6 insertions(+) rename {src/interface/include => include/interface}/gpio.h (100%) rename {src/interface/include => include/interface}/i2c.h (100%) rename {src/interface/include => include/interface}/pwm.h (100%) rename {src/interface/include => include/interface}/spi.h (100%) rename {src/interface/include => include/interface}/uart.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29d9721..714f3d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) +INCLUDE_DIRECTORIES(${INC_DIR}/interface) INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) @@ -47,6 +48,11 @@ SET(SOURCES src/peripheral_gpio.c src/peripheral_pwm.c src/peripheral_uart.c src/peripheral_spi.c + src/interface/gpio.c + src/interface/i2c.c + src/interface/pwm.c + src/interface/spi.c + src/interface/uart.c src/peripheral_gdbus_gpio.c src/peripheral_gdbus_i2c.c src/peripheral_gdbus_pwm.c diff --git a/src/interface/include/gpio.h b/include/interface/gpio.h similarity index 100% rename from src/interface/include/gpio.h rename to include/interface/gpio.h diff --git a/src/interface/include/i2c.h b/include/interface/i2c.h similarity index 100% rename from src/interface/include/i2c.h rename to include/interface/i2c.h diff --git a/src/interface/include/pwm.h b/include/interface/pwm.h similarity index 100% rename from src/interface/include/pwm.h rename to include/interface/pwm.h diff --git a/src/interface/include/spi.h b/include/interface/spi.h similarity index 100% rename from src/interface/include/spi.h rename to include/interface/spi.h diff --git a/src/interface/include/uart.h b/include/interface/uart.h similarity index 100% rename from src/interface/include/uart.h rename to include/interface/uart.h -- 2.34.1 From af70ff10619d5c1caeb1ee629284f00ca14635c0 Mon Sep 17 00:00:00 2001 From: Segwon Date: Mon, 13 Nov 2017 15:17:29 +0900 Subject: [PATCH 16/16] [2/6] fd passing: add member variable for file descriptor in handle. Signed-off-by: Segwon Change-Id: Ic82127b5a4426872b11da5434a8feddf53f4244e --- include/peripheral_internal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/peripheral_internal.h b/include/peripheral_internal.h index ae4f47e..5c62dee 100644 --- a/include/peripheral_internal.h +++ b/include/peripheral_internal.h @@ -23,6 +23,9 @@ struct _peripheral_gpio_s { int pin; uint handle; + int fd_direction; + int fd_edge; + int fd_value; }; /** @@ -30,6 +33,7 @@ struct _peripheral_gpio_s { */ struct _peripheral_i2c_s { uint handle; + int fd; }; /** @@ -37,6 +41,10 @@ struct _peripheral_i2c_s { */ struct _peripheral_pwm_s { uint handle; + int fd_period; + int fd_duty_cycle; + int fd_polarity; + int fd_enable; }; /** @@ -44,6 +52,7 @@ struct _peripheral_pwm_s { */ struct _peripheral_uart_s { uint handle; + int fd; }; /** @@ -51,6 +60,7 @@ struct _peripheral_uart_s { */ struct _peripheral_spi_s { uint handle; + int fd; }; #endif /* __PERIPHERAL_INTERNAL_H__ */ -- 2.34.1