Skip to content

Commit

Permalink
tests: drivers: gpio: Add loopback test for eGPIO SDP
Browse files Browse the repository at this point in the history
Added a loopback test for the software-defined eGPIO peripheral.
The test verifies proper operation of the eGPIO output by using
a different processor hardware GPIO input pin.

Signed-off-by: Jakub Zymelka <[email protected]>
  • Loading branch information
jaz1-nordic committed Sep 13, 2024
1 parent e6c7e89 commit ebfddd5
Show file tree
Hide file tree
Showing 9 changed files with 653 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/drivers/gpio/egpio_basic_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(egpio_basic_api)

FILE(GLOB app_sources src/test*.c)
target_sources(app PRIVATE ${app_sources})
18 changes: 18 additions & 0 deletions tests/drivers/gpio/egpio_basic_api/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
eGPIO 2-Pin Test
###############

This application tests the eGPIO subsystem using a hardware configuration
where two GPIOs are directly wired together. The test pins are
identified through a test-specific devicetree binding in the `dts/`
subdirectory, implemented for specific boards by overlay files in the
`boards/` directory.

Only boards for which an overlay is present can pass this test. Boards
without an overlay, or for which the required wiring is not provided,
will fail with an error like this:

Validate device GPIO_0
Check GPIO_1 output 7 connected to GPIO_2 input 3
FATAL output pin not wired to input pin? (out high => in low)

No special build options are required to make use of the overlay.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
resources {
compatible = "test-egpio";
out-gpios = <&egpio 10 0>;
in-gpios = <&gpio1 14 0>;
};
};

&gpiote20 {
status = "okay";
};

&gpio1 {
status = "okay";
};
28 changes: 28 additions & 0 deletions tests/drivers/gpio/egpio_basic_api/dts/bindings/test-egpio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

description: |
This binding provides resources required to build and run the
tests/drivers/gpio/egpio_basic_api test in Zephyr.
compatible: "test-egpio"

properties:
out-gpios:
type: phandle-array
required: true
description: |
Identity of a eGPIO that will be configured as an output.
This must be on the instance to which FLPR has access, and physically
connected to in-gpios.
in-gpios:
type: phandle-array
required: true
description: |
Identity of a hardware GPIO that will be configured as an input.
This must be on the same instance as out-gpios, and physically
connected to out-gpios.
4 changes: 4 additions & 0 deletions tests/drivers/gpio/egpio_basic_api/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_GPIO=y
CONFIG_ZTEST=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
56 changes: 56 additions & 0 deletions tests/drivers/gpio/egpio_basic_api/src/test_egpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef __TEST_EGPIO_H__
#define __TEST_EGPIO_H__

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/util.h>
#include <zephyr/ztest.h>

#if DT_NODE_HAS_STATUS(DT_INST(0, test_egpio), okay)

/* Execution of the test requires hardware configuration described in
* devicetree. See the test, egpio_basic_api binding local to this test
* for details.
*/
#define DEV_OUT DT_GPIO_CTLR(DT_INST(0, test_egpio), out_gpios)
#define DEV_IN DT_GPIO_CTLR(DT_INST(0, test_egpio), in_gpios)
#define DEV DEV_OUT
#define PIN_OUT DT_GPIO_PIN(DT_INST(0, test_egpio), out_gpios)
#define PIN_OUT_FLAGS DT_GPIO_FLAGS(DT_INST(0, test_egpio), out_gpios)
#define PIN_IN DT_GPIO_PIN(DT_INST(0, test_egpio), in_gpios)
#define PIN_IN_FLAGS DT_GPIO_FLAGS(DT_INST(0, test_egpio), in_gpios)
#else
#error Unsupported board
#endif

#ifndef PIN_OUT
/* For build-only testing use fixed pins. */
#define PIN_OUT 10
#define PIN_IN 14
#endif

#define MAX_INT_CNT 3
struct drv_data {
struct gpio_callback gpio_cb;
gpio_flags_t mode;
int index;
int aux;
};

void test_egpio_pin_read_write(void);
void test_egpio_callback_add_remove(void);
void test_egpio_callback_self_remove(void);
void test_egpio_callback_enable_disable(void);
void test_egpio_callback_variants(void);

void test_egpio_port(void);

void test_egpio_deprecated(void);

#endif /* __TEST_EGPIO_H__ */
Loading

0 comments on commit ebfddd5

Please sign in to comment.