Skip to content

Commit

Permalink
tests: drivers: pwm: add PWM loopback test
Browse files Browse the repository at this point in the history
Add test cases for the PWM capture API using PWM signal loopback.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
  • Loading branch information
henrikbrixandersen authored and carlescufi committed Jan 12, 2021
1 parent 54fed42 commit 90825a8
Show file tree
Hide file tree
Showing 8 changed files with 501 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/drivers/pwm/pwm_loopback/CMakeLists.txt
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(pwm_loopback)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
15 changes: 15 additions & 0 deletions tests/drivers/pwm/pwm_loopback/boards/frdm_k64f.overlay
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020-2021 Vestas Wind Systems A/S
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <dt-bindings/pwm/pwm.h>

/ {
pwm_loopback_0 {
compatible = "test,pwm_loopback";
pwms = <&ftm0 0 0 PWM_POLARITY_NORMAL>, /* PTC1, J1 pin 5 */
<&ftm3 4 0 PWM_POLARITY_NORMAL>; /* PTC8, J1 pin 7 */
};
};
22 changes: 22 additions & 0 deletions tests/drivers/pwm/pwm_loopback/dts/bindings/test,pwm_loopback.yaml
@@ -0,0 +1,22 @@
#
# Copyright (c) 2020-2021 Vestas Wind Systems A/S
#
# SPDX-License-Identifier: Apache-2.0
#

description: |
This binding provides resources required to build and run the
tests/drivers/pwm/pwm_loopback test in Zephyr.
compatible: "test,pwm_loopback"

properties:
pwms:
type: phandle-array
required: true
description: |
PWM pins that will be used for generating and capturing a pulse-width
modulated signal. The pin at the first index will be used for signal
generation while the pin at the second index will be used for capuring
the generated signal. The two pins must be physically connected to
each other.
5 changes: 5 additions & 0 deletions tests/drivers/pwm/pwm_loopback/prj.conf
@@ -0,0 +1,5 @@
CONFIG_ZTEST=y
CONFIG_TEST_USERSPACE=y

CONFIG_PWM=y
CONFIG_PWM_CAPTURE=y
32 changes: 32 additions & 0 deletions tests/drivers/pwm/pwm_loopback/src/main.c
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2020-2021 Vestas Wind Systems A/S
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <ztest.h>

#include "test_pwm_loopback.h"

void test_main(void)
{
struct test_pwm in;
struct test_pwm out;

get_test_pwms(&in, &out);

k_object_access_grant(out.dev, k_current_get());
k_object_access_grant(in.dev, k_current_get());

ztest_test_suite(pwm_loopback_test,
ztest_user_unit_test(test_pulse_capture),
ztest_user_unit_test(test_pulse_capture_inverted),
ztest_user_unit_test(test_period_capture),
ztest_user_unit_test(test_period_capture_inverted),
ztest_user_unit_test(test_pulse_and_period_capture),
ztest_user_unit_test(test_capture_timeout),
ztest_unit_test(test_continuous_capture),
ztest_unit_test(test_capture_busy));
ztest_run_test_suite(pwm_loopback_test);
}

0 comments on commit 90825a8

Please sign in to comment.