tests: boards: nrf: qdec: Add device runtime PM configuration
Add configuration to the test which is using runtime PM on qdec. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
7fc73619b4
commit
5371effda8
8 changed files with 170 additions and 19 deletions
|
|
@ -31,12 +31,27 @@
|
|||
<NRF_PSEL(QDEC_B, 1, 3)>; /* Arduino D2 */
|
||||
};
|
||||
};
|
||||
|
||||
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(QDEC_A, 1, 1)>, /* Ardiuno D0 */
|
||||
<NRF_PSEL(QDEC_B, 1, 3)>; /* Arduino D2 */
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&qdec0 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&qdec_pinctrl>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-1 = <&qdec_sleep_pinctrl>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
steps = < 127 >;
|
||||
led-pre = < 500 >;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
||||
/* To prevent enabling console receiver. */
|
||||
&uart0 {
|
||||
disable-rx;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,12 +30,27 @@
|
|||
<NRF_PSEL(QDEC_B, 0, 6)>; /* Arduino A2 */
|
||||
};
|
||||
};
|
||||
|
||||
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(QDEC_A, 0, 4)>,
|
||||
<NRF_PSEL(QDEC_B, 0, 6)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&qdec1 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&qdec_pinctrl>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-1 = <&qdec_sleep_pinctrl>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
steps = < 127 >;
|
||||
led-pre = < 500 >;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
||||
/* To prevent enabling console receiver. */
|
||||
&uart0 {
|
||||
disable-rx;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@
|
|||
<NRF_PSEL(QDEC_B, 1, 2)>;
|
||||
};
|
||||
};
|
||||
|
||||
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(QDEC_A, 1, 0)>,
|
||||
<NRF_PSEL(QDEC_B, 1, 2)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&gpio1 {
|
||||
|
|
@ -41,7 +49,14 @@
|
|||
&qdec130 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&qdec_pinctrl>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-1 = <&qdec_sleep_pinctrl>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
steps = <127>;
|
||||
led-pre = <500>;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
||||
/* To prevent enabling console receiver. */
|
||||
&uart136 {
|
||||
disable-rx;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,3 +4,8 @@
|
|||
*/
|
||||
|
||||
#include "nrf54l15pdk_nrf54l15_common.dtsi"
|
||||
|
||||
/* To prevent enabling console receiver. */
|
||||
&uart20 {
|
||||
disable-rx;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,3 +4,8 @@
|
|||
*/
|
||||
|
||||
#include "nrf54l15pdk_nrf54l15_common.dtsi"
|
||||
|
||||
/* To prevent enabling console receiver. */
|
||||
&uart30 {
|
||||
disable-rx;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@
|
|||
<NRF_PSEL(QDEC_B, 1, 10)>;
|
||||
};
|
||||
};
|
||||
|
||||
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(QDEC_A, 1, 8)>,
|
||||
<NRF_PSEL(QDEC_B, 1, 10)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
&gpio1 {
|
||||
|
|
@ -37,7 +45,9 @@
|
|||
&qdec20 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&qdec_pinctrl>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-1 = <&qdec_sleep_pinctrl>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
steps = <127>;
|
||||
led-pre = <500>;
|
||||
zephyr,pm-device-runtime-auto;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
|
||||
static K_SEM_DEFINE(sem, 0, 1);
|
||||
static const struct gpio_dt_spec phase_a = GPIO_DT_SPEC_GET(DT_ALIAS(qenca), gpios);
|
||||
|
|
@ -144,6 +145,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable)
|
|||
{
|
||||
int rc;
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
qdec_trigger.type = SENSOR_TRIG_DATA_READY;
|
||||
qdec_trigger.chan = SENSOR_CHAN_ALL;
|
||||
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
|
||||
|
|
@ -162,10 +167,18 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable)
|
|||
/* emulation not working, but there maybe old trigger, ignore */
|
||||
rc = k_sem_take(&sem, K_MSEC(200));
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
|
||||
/* there should be no triggers now*/
|
||||
rc = k_sem_take(&sem, K_MSEC(200));
|
||||
zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
/* register empty trigger - disable trigger */
|
||||
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, NULL);
|
||||
zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc);
|
||||
|
|
@ -175,6 +188,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable)
|
|||
/* emulation working, but handler not set, thus should not be called */
|
||||
rc = k_sem_take(&sem, K_MSEC(200));
|
||||
zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,6 +205,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
|
|||
int rc;
|
||||
struct sensor_value val = {0};
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
qdec_trigger.type = SENSOR_TRIG_DATA_READY;
|
||||
qdec_trigger.chan = SENSOR_CHAN_ROTATION;
|
||||
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
|
||||
|
|
@ -209,6 +230,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
|
|||
|
||||
TC_PRINT("QDEC reading: %d\n", val.val1);
|
||||
zassert_true(val.val1 != 0, "No readings from QDEC");
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -221,6 +246,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative)
|
|||
{
|
||||
int rc;
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
|
||||
zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported");
|
||||
|
||||
|
|
@ -235,6 +264,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative)
|
|||
|
||||
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
|
||||
zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid channel");
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -245,11 +278,19 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative)
|
|||
*/
|
||||
ZTEST(qdec_sensor, test_qdec_readings)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
qenc_emulate_verify_reading(10, 100, true, false);
|
||||
qenc_emulate_verify_reading(2, 500, true, false);
|
||||
qenc_emulate_verify_reading(10, 200, false, false);
|
||||
qenc_emulate_verify_reading(1, 1000, false, true);
|
||||
qenc_emulate_verify_reading(1, 1000, true, true);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -263,9 +304,16 @@ ZTEST(qdec_sensor, test_sensor_channel_get_empty)
|
|||
int rc;
|
||||
struct sensor_value val = {0};
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
rc = sensor_sample_fetch(qdec_dev);
|
||||
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
|
||||
|
||||
/* wait for potential new readings */
|
||||
k_msleep(100);
|
||||
|
||||
/* get readings but ignore them, as they may include reading from time
|
||||
* when emulation was still working (i.e. during previous test)
|
||||
*/
|
||||
|
|
@ -283,6 +331,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_empty)
|
|||
zassert_true(rc == 0, "Failed to get sample (%d)", rc);
|
||||
zassert_true(val.val1 == 0, "Expected no readings but got: %d", val.val1);
|
||||
zassert_true(val.val2 == 0, "Expected no readings but got: %d", val.val2);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -297,6 +349,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
|
|||
struct sensor_value val_first = {0};
|
||||
struct sensor_value val_second = {0};
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
qenc_emulate_start(K_MSEC(10), true);
|
||||
|
||||
/* wait for some readings*/
|
||||
|
|
@ -328,6 +384,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
|
|||
"Expected the same readings: %d vs %d",
|
||||
val_first.val2,
|
||||
val_second.val2);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -341,6 +401,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative)
|
|||
int rc;
|
||||
struct sensor_value val = {0};
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
qenc_emulate_start(K_MSEC(10), true);
|
||||
|
||||
/* wait for some readings*/
|
||||
|
|
@ -353,6 +417,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative)
|
|||
zassert_true(rc < 0, "Should failed to get sample (%d)", rc);
|
||||
zassert_true(val.val1 == 0, "Some readings from QDEC: %d", val.val1);
|
||||
zassert_true(val.val2 == 0, "Some readings from QDEC: %d", val.val2);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -365,6 +433,10 @@ ZTEST(qdec_sensor, test_sensor_sample_fetch)
|
|||
{
|
||||
int rc;
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_get(qdec_dev);
|
||||
}
|
||||
|
||||
rc = sensor_sample_fetch(qdec_dev);
|
||||
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
|
||||
|
||||
|
|
@ -373,6 +445,10 @@ ZTEST(qdec_sensor, test_sensor_sample_fetch)
|
|||
|
||||
rc = sensor_sample_fetch_chan(qdec_dev, SENSOR_CHAN_MAX);
|
||||
zassert_true(rc < 0, "Should fail to fetch sample from invalid channel (%d)", rc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
|
||||
pm_device_runtime_put(qdec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void *setup(void)
|
||||
|
|
|
|||
|
|
@ -1,21 +1,31 @@
|
|||
common:
|
||||
platform_allow:
|
||||
- nrf52840dk/nrf52840
|
||||
- nrf5340dk/nrf5340/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuflpr
|
||||
- nrf54h20dk/nrf54h20/cpuapp
|
||||
integration_platforms:
|
||||
- nrf52840dk/nrf52840
|
||||
- nrf5340dk/nrf5340/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuflpr
|
||||
- nrf54h20dk/nrf54h20/cpuapp
|
||||
harness: ztest
|
||||
harness_config:
|
||||
fixture: gpio_loopback
|
||||
tests:
|
||||
drivers.sensor.qdec:
|
||||
tags:
|
||||
- drivers
|
||||
- sensors
|
||||
- qdec
|
||||
platform_allow:
|
||||
- nrf52840dk/nrf52840
|
||||
- nrf5340dk/nrf5340/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuflpr
|
||||
- nrf54h20dk/nrf54h20/cpuapp
|
||||
integration_platforms:
|
||||
- nrf52840dk/nrf52840
|
||||
- nrf5340dk/nrf5340/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuapp
|
||||
- nrf54l15dk/nrf54l15/cpuflpr
|
||||
- nrf54h20dk/nrf54h20/cpuapp
|
||||
harness: ztest
|
||||
harness_config:
|
||||
fixture: gpio_loopback
|
||||
drivers.sensor.qdec.pm_runtime:
|
||||
tags:
|
||||
- drivers
|
||||
- sensors
|
||||
- qdec
|
||||
- pm
|
||||
extra_configs:
|
||||
- CONFIG_PM_DEVICE=y
|
||||
- CONFIG_PM_DEVICE_RUNTIME=y
|
||||
|
|
|
|||
Loading…
Reference in a new issue