Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOPIC-GPIO] convert 2-pin test to new API #19249

Merged
merged 3 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@
/tests/crypto/mbedtls/ @nashif @ceolin
/tests/drivers/can/ @alexanderwachter
/tests/drivers/flash_simulator/ @nvlsianpu
/tests/drivers/gpio/ @mnkp @pabigot
/tests/drivers/hwinfo/ @alexanderwachter
/tests/drivers/spi/ @tbursztyka
/tests/drivers/uart/uart_async_api/ @Mierunski
Expand Down
13 changes: 13 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/boards/efr32mg_sltb004a.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
resources {
compatible = "test,gpio_basic_api";
out-gpios = <&gpiof 6 0>; /* Arduino D0 */
in-gpios = <&gpiof 5 0>; /* Arduino D1 */
};
};
13 changes: 13 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/boards/frdm_k64f.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
resources {
compatible = "test,gpio_basic_api";
out-gpios = <&gpioc 16 0>; /* Arduino D0 */
in-gpios = <&gpioc 17 0>; /* Arduino D1 */
};
};
13 changes: 13 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/boards/nrf52840_pca10056.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
resources {
compatible = "test,gpio_basic_api";
out-gpios = <&gpio1 1 0>; /* Arduino D0 */
in-gpios = <&gpio1 2 0>; /* Arduino D1 */
};
};
13 changes: 13 additions & 0 deletions tests/drivers/gpio/gpio_basic_api/boards/sam_e70_xplained.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
resources {
compatible = "test,gpio_basic_api";
out-gpios = <&portd 21 0>;
in-gpios = <&portd 20 0>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

title: Hardware resources required for the gpio_basic_api test.

description: >
This binding provides resources required to build and run the
tests/drivers/gpio/gpio_basic_api test in Zephyr.

compatible: "test,gpio_basic_api"

properties:
out-gpios:
type: phandle-array
required: true
description: >
Identity of a GPIO that will be configured as an output. This
must be on the same device as in-gpios, and physically
connected to in-gpios.

in-gpios:
type: phandle-array
required: true
description: >
Identity of a GPIO that will be configured as an input. This
must be on the same device as out-gpios,and physically
connected to out-gpios.
1 change: 1 addition & 0 deletions tests/drivers/gpio/gpio_basic_api/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ CONFIG_GPIO=y
CONFIG_ZTEST=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
#CONFIG_TEST_USERSPACE=y
36 changes: 32 additions & 4 deletions tests/drivers/gpio/gpio_basic_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,44 @@

#include "test_gpio.h"

/* Grotesque hack for pinmux boards */
#ifdef CONFIG_BOARD_FRDM_K64F
#include <drivers/pinmux.h>
#include <fsl_port.h>
#endif

static void board_setup(void)
{
#ifdef DT_INST_0_TEST_GPIO_BASIC_API
/* PIN_IN and PIN_OUT must be on same controller. */
if (strcmp(DT_INST_0_TEST_GPIO_BASIC_API_OUT_GPIOS_CONTROLLER,
DT_INST_0_TEST_GPIO_BASIC_API_IN_GPIOS_CONTROLLER) != 0) {
printk("FATAL: output controller %s != input controller %s\n",
DT_INST_0_TEST_GPIO_BASIC_API_OUT_GPIOS_CONTROLLER,
DT_INST_0_TEST_GPIO_BASIC_API_IN_GPIOS_CONTROLLER);
k_panic();
}
#endif

#ifdef CONFIG_BOARD_FRDM_K64F
/* TODO figure out how to get this from "GPIO_2" */
const char *pmx_name = "portc";
struct device *pmx = device_get_binding(pmx_name);

pinmux_pin_set(pmx, PIN_OUT, PORT_PCR_MUX(kPORT_MuxAsGpio));
pinmux_pin_set(pmx, PIN_IN, PORT_PCR_MUX(kPORT_MuxAsGpio));
#endif
}

void test_main(void)
{
board_setup();
ztest_test_suite(gpio_basic_test,
ztest_unit_test(test_gpio_port),
ztest_unit_test(test_gpio_pin_read_write),
ztest_unit_test(test_gpio_callback_edge_high),
ztest_unit_test(test_gpio_callback_edge_low),
ztest_unit_test(test_gpio_callback_level_high),
ztest_unit_test(test_gpio_callback_add_remove),
ztest_unit_test(test_gpio_callback_self_remove),
ztest_unit_test(test_gpio_callback_enable_disable),
ztest_unit_test(test_gpio_callback_level_low));
ztest_unit_test(test_gpio_callback_variants));
ztest_run_test_suite(gpio_basic_test);
}
92 changes: 62 additions & 30 deletions tests/drivers/gpio/gpio_basic_api/src/test_callback_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,54 @@ static void callback_remove_self(struct device *dev,
dd->aux = gpio_remove_callback(dev, gpio_cb);
}

static void init_callback(struct device *dev,
gpio_callback_handler_t handler_1,
gpio_callback_handler_t handler_2)
static int init_callback(struct device *dev,
gpio_callback_handler_t handler_1,
gpio_callback_handler_t handler_2)
{
gpio_pin_disable_callback(dev, PIN_IN);
gpio_pin_disable_callback(dev, PIN_OUT);
int rc = gpio_pin_interrupt_configure(dev, PIN_IN, GPIO_INT_DISABLE);

/* 1. set PIN_OUT */
gpio_pin_configure(dev, PIN_OUT, GPIO_DIR_OUT);
gpio_pin_write(dev, PIN_OUT, 0);
if (rc == 0) {
rc = gpio_pin_interrupt_configure(dev, PIN_OUT, GPIO_INT_DISABLE);
}
if (rc == 0) {
/* 1. set PIN_OUT */
rc = gpio_pin_configure(dev, PIN_OUT, GPIO_OUTPUT_LOW);
}

if (rc == 0) {
/* 2. configure PIN_IN callback, but don't enable */
rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT);
}

/* 2. configure PIN_IN callback and trigger condition */
gpio_pin_configure(dev, PIN_IN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | \
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
if (rc == 0) {
gpio_init_callback(&cb_data[0].gpio_cb, handler_1, BIT(PIN_IN));
rc = gpio_add_callback(dev, &cb_data[0].gpio_cb);
}

gpio_init_callback(&cb_data[0].gpio_cb, handler_1, BIT(PIN_IN));
gpio_add_callback(dev, &cb_data[0].gpio_cb);
if (rc == 0) {
gpio_init_callback(&cb_data[1].gpio_cb, handler_2, BIT(PIN_IN));
rc = gpio_add_callback(dev, &cb_data[1].gpio_cb);
}

gpio_init_callback(&cb_data[1].gpio_cb, handler_2, BIT(PIN_IN));
gpio_add_callback(dev, &cb_data[1].gpio_cb);
return rc;
}

static void trigger_callback(struct device *dev, int enable_cb)
{
gpio_pin_write(dev, PIN_OUT, 0);
gpio_pin_set(dev, PIN_OUT, 0);
k_sleep(100);

cb_cnt[0] = 0;
cb_cnt[1] = 0;
if (enable_cb == 1) {
gpio_pin_enable_callback(dev, PIN_IN);
gpio_pin_interrupt_configure(dev, PIN_IN,
GPIO_INT_EDGE_RISING
| GPIO_INT_DEBOUNCE);
} else {
gpio_pin_disable_callback(dev, PIN_IN);
gpio_pin_interrupt_configure(dev, PIN_IN, GPIO_INT_DISABLE);
}
k_sleep(100);
gpio_pin_write(dev, PIN_OUT, 1);
gpio_pin_set(dev, PIN_OUT, 1);
k_sleep(1000);
}

Expand All @@ -84,7 +95,14 @@ static int test_callback_add_remove(void)
struct device *dev = device_get_binding(DEV_NAME);

/* SetUp: initialize environment */
init_callback(dev, callback_1, callback_2);
int rc = init_callback(dev, callback_1, callback_2);

if (rc == -ENOTSUP) {
TC_PRINT("%s not supported\n", __func__);
return TC_PASS;
}
zassert_equal(rc, 0,
"init_callback failed");

/* 3. enable callback, trigger PIN_IN interrupt by operate PIN_OUT */
trigger_callback(dev, 1);
Expand Down Expand Up @@ -126,9 +144,16 @@ static int test_callback_self_remove(void)
struct device *dev = device_get_binding(DEV_NAME);

/* SetUp: initialize environment */
init_callback(dev, callback_1, callback_remove_self);
int rc = init_callback(dev, callback_1, callback_remove_self);

if (rc == -ENOTSUP) {
TC_PRINT("%s not supported\n", __func__);
return TC_PASS;
}
zassert_equal(rc, 0,
"init_callback failed");

gpio_pin_write(dev, PIN_OUT, 0);
gpio_pin_set(dev, PIN_OUT, 0);
k_sleep(100);

cb_data[0].aux = INT_MAX;
Expand Down Expand Up @@ -171,7 +196,14 @@ static int test_callback_enable_disable(void)
struct device *dev = device_get_binding(DEV_NAME);

/* SetUp: initialize environment */
init_callback(dev, callback_1, callback_2);
int rc = init_callback(dev, callback_1, callback_2);

if (rc == -ENOTSUP) {
TC_PRINT("%s not supported\n", __func__);
return TC_PASS;
}
zassert_equal(rc, 0,
"init_callback failed");

/* 3. enable callback, trigger PIN_IN interrupt by operate PIN_OUT */
trigger_callback(dev, 1);
Expand Down Expand Up @@ -208,18 +240,18 @@ static int test_callback_enable_disable(void)

void test_gpio_callback_add_remove(void)
{
zassert_true(
test_callback_add_remove() == TC_PASS, NULL);
zassert_equal(test_callback_add_remove(), TC_PASS,
NULL);
}

void test_gpio_callback_self_remove(void)
{
zassert_true(
test_callback_self_remove() == TC_PASS, NULL);
zassert_equal(test_callback_self_remove(), TC_PASS,
NULL);
}

void test_gpio_callback_enable_disable(void)
{
zassert_true(
test_callback_enable_disable() == TC_PASS, NULL);
zassert_equal(test_callback_enable_disable(), TC_PASS,
NULL);
}
Loading