Skip to content

Commit 90825a8

Browse files
henrikbrixandersencarlescufi
authored andcommitted
tests: drivers: pwm: add PWM loopback test
Add test cases for the PWM capture API using PWM signal loopback. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 54fed42 commit 90825a8

File tree

8 files changed

+501
-0
lines changed

8 files changed

+501
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(pwm_loopback)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2020-2021 Vestas Wind Systems A/S
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <dt-bindings/pwm/pwm.h>
8+
9+
/ {
10+
pwm_loopback_0 {
11+
compatible = "test,pwm_loopback";
12+
pwms = <&ftm0 0 0 PWM_POLARITY_NORMAL>, /* PTC1, J1 pin 5 */
13+
<&ftm3 4 0 PWM_POLARITY_NORMAL>; /* PTC8, J1 pin 7 */
14+
};
15+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright (c) 2020-2021 Vestas Wind Systems A/S
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: |
8+
This binding provides resources required to build and run the
9+
tests/drivers/pwm/pwm_loopback test in Zephyr.
10+
11+
compatible: "test,pwm_loopback"
12+
13+
properties:
14+
pwms:
15+
type: phandle-array
16+
required: true
17+
description: |
18+
PWM pins that will be used for generating and capturing a pulse-width
19+
modulated signal. The pin at the first index will be used for signal
20+
generation while the pin at the second index will be used for capuring
21+
the generated signal. The two pins must be physically connected to
22+
each other.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_TEST_USERSPACE=y
3+
4+
CONFIG_PWM=y
5+
CONFIG_PWM_CAPTURE=y
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2020-2021 Vestas Wind Systems A/S
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <ztest.h>
9+
10+
#include "test_pwm_loopback.h"
11+
12+
void test_main(void)
13+
{
14+
struct test_pwm in;
15+
struct test_pwm out;
16+
17+
get_test_pwms(&in, &out);
18+
19+
k_object_access_grant(out.dev, k_current_get());
20+
k_object_access_grant(in.dev, k_current_get());
21+
22+
ztest_test_suite(pwm_loopback_test,
23+
ztest_user_unit_test(test_pulse_capture),
24+
ztest_user_unit_test(test_pulse_capture_inverted),
25+
ztest_user_unit_test(test_period_capture),
26+
ztest_user_unit_test(test_period_capture_inverted),
27+
ztest_user_unit_test(test_pulse_and_period_capture),
28+
ztest_user_unit_test(test_capture_timeout),
29+
ztest_unit_test(test_continuous_capture),
30+
ztest_unit_test(test_capture_busy));
31+
ztest_run_test_suite(pwm_loopback_test);
32+
}

0 commit comments

Comments
 (0)