Skip to content

Commit 9b18b84

Browse files
congnguyenhuummahadevan108
authored andcommitted
tests/samples: drivers: create test, sample for psi5 driver
Create test, sample for psi5 driver Signed-off-by: Cong Nguyen Huu <[email protected]>
1 parent 13ad0fa commit 9b18b84

File tree

13 files changed

+457
-0
lines changed

13 files changed

+457
-0
lines changed

samples/drivers/psi5/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(psi5)
7+
8+
target_sources(app PRIVATE src/main.c)

samples/drivers/psi5/README.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. zephyr:code-sample:: psi5
2+
:name: PSI5 interface
3+
:relevant-api: psi5_interface
4+
5+
Use the PSI5 (Peripheral Sensor Interface) driver.
6+
7+
Overview
8+
********
9+
10+
The sample application shows how to use the :ref:`PSI5 API <psi5_api>`:
11+
12+
* Receive data
13+
* Transmit data
14+
15+
Requirements
16+
************
17+
18+
This sample requires a PSI5 sensor to be connected and exposed as ``psi5-0`` Devicetree alias.
19+
20+
Building, Flashing and Running
21+
******************************
22+
23+
.. zephyr-app-commands::
24+
:zephyr-app: samples/drivers/psi5
25+
:board: s32z2xxdc2/s32z270/rtu0
26+
:goals: build flash
27+
28+
Sample Output:
29+
30+
.. code-block:: console
31+
32+
Transmitted data on channel 1
33+
34+
Received a frame on channel 1
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
psi5-0 = &psi5_0;
10+
};
11+
};
12+
13+
&pinctrl {
14+
psi5_0_default: psi5_0_default {
15+
group1 {
16+
pinmux = <PA7_PSI5_0_SDOUT1>;
17+
output-enable;
18+
};
19+
group2 {
20+
pinmux = <PA6_PSI5_0_SDIN1>;
21+
input-enable;
22+
};
23+
};
24+
};
25+
26+
&psi5_0 {
27+
pinctrl-0 = <&psi5_0_default>;
28+
pinctrl-names = "default";
29+
status = "okay";
30+
};
31+
32+
&psi5_0_ch1 {
33+
period-sync-pulse-us = <500>;
34+
decoder-start-offset-us = <0>;
35+
pulse-width-0-us = <100>;
36+
pulse-width-1-us = <127>;
37+
tx-frame = "long-31-1s";
38+
num-rx-buf = <32>;
39+
rx-bitrate-kbps = <189>;
40+
status = "okay";
41+
};
42+
43+
&psi5_0_ch1_rx_slot0 {
44+
duration-us = <150>;
45+
start-offset-us = <110>;
46+
data-length = <16>;
47+
status = "okay";
48+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "s32z2xxdc2_s32z270_rtu0.overlay"

samples/drivers/psi5/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_PSI5=y
2+
CONFIG_PSI5_LOG_LEVEL_DBG=y
3+
CONFIG_LOG=y

samples/drivers/psi5/sample.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sample:
2+
name: PSI5 driver sample
3+
4+
tests:
5+
sample.drivers.psi5:
6+
tags:
7+
- drivers
8+
- psi5
9+
depends_on: psi5
10+
filter: dt_alias_exists("psi5-0")
11+
harness: sensor

samples/drivers/psi5/src/main.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(psi5_sample, LOG_LEVEL_DBG);
9+
10+
#include <zephyr/kernel.h>
11+
12+
#include <zephyr/drivers/psi5/psi5.h>
13+
14+
#define PSI5_NODE DT_ALIAS(psi5_0)
15+
#define PSI5_CHANNEL 1
16+
#define PSI5_MAX_RX_BUFFER 1
17+
18+
struct psi5_frame serial_frame[PSI5_MAX_RX_BUFFER];
19+
20+
struct psi5_frame data_frame[PSI5_MAX_RX_BUFFER];
21+
22+
void tx_cb(const struct device *dev, uint8_t channel_id, int status, void *user_data)
23+
{
24+
LOG_INF("Transmitted data on channel %d", channel_id);
25+
}
26+
27+
void rx_serial_frame_cb(const struct device *dev, uint8_t channel_id, uint32_t num_frame,
28+
void *user_data)
29+
{
30+
31+
if (num_frame == PSI5_MAX_RX_BUFFER) {
32+
LOG_INF("Received a frame on channel %d, "
33+
"id: %d, data: 0x%X, timestamp: 0x%X, slot: %d",
34+
channel_id, serial_frame->serial.id, serial_frame->serial.data,
35+
serial_frame->timestamp, serial_frame->slot_number);
36+
} else {
37+
LOG_INF("Error received on channel %d", channel_id);
38+
}
39+
}
40+
41+
void rx_data_frame_cb(const struct device *dev, uint8_t channel_id, uint32_t num_frame,
42+
void *user_data)
43+
{
44+
45+
if (num_frame == PSI5_MAX_RX_BUFFER) {
46+
LOG_INF("Received a frame on channel %d, "
47+
"data: 0x%X, timestamp: 0x%X",
48+
channel_id, data_frame->data, data_frame->timestamp);
49+
} else {
50+
LOG_INF("Error received on channel %d", channel_id);
51+
}
52+
}
53+
54+
struct psi5_rx_callback_config serial_cb_cfg = {
55+
.callback = rx_serial_frame_cb,
56+
.frame = &serial_frame[0],
57+
.max_num_frame = PSI5_MAX_RX_BUFFER,
58+
.user_data = NULL,
59+
};
60+
61+
struct psi5_rx_callback_config data_cb_cfg = {
62+
.callback = rx_data_frame_cb,
63+
.frame = &data_frame[0],
64+
.max_num_frame = PSI5_MAX_RX_BUFFER,
65+
.user_data = NULL,
66+
};
67+
68+
struct psi5_rx_callback_configs callback_configs = {
69+
.serial_frame = &serial_cb_cfg,
70+
.data_frame = &data_cb_cfg,
71+
};
72+
73+
int main(void)
74+
{
75+
const struct device *const dev = DEVICE_DT_GET(PSI5_NODE);
76+
uint64_t send_data = 0x1234;
77+
78+
psi5_register_callback(dev, PSI5_CHANNEL, callback_configs);
79+
80+
psi5_start_sync(dev, PSI5_CHANNEL);
81+
82+
psi5_send(dev, PSI5_CHANNEL, send_data, K_MSEC(100), tx_cb, NULL);
83+
84+
while (true) {
85+
/* To transmit and receive data */
86+
}
87+
88+
return 0;
89+
}
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.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(psi5)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
psi5-0 = &psi5_0;
10+
};
11+
};
12+
13+
&pinctrl {
14+
psi5_0_default: psi5_0_default {
15+
group1 {
16+
pinmux = <PA7_PSI5_0_SDOUT1>;
17+
output-enable;
18+
};
19+
group2 {
20+
pinmux = <PA6_PSI5_0_SDIN1>;
21+
input-enable;
22+
};
23+
};
24+
};
25+
26+
&psi5_0 {
27+
pinctrl-0 = <&psi5_0_default>;
28+
pinctrl-names = "default";
29+
status = "okay";
30+
};
31+
32+
&psi5_0_ch1 {
33+
period-sync-pulse-us = <500>;
34+
decoder-start-offset-us = <0>;
35+
pulse-width-0-us = <100>;
36+
pulse-width-1-us = <127>;
37+
tx-frame = "long-31-1s";
38+
num-rx-buf = <32>;
39+
rx-bitrate-kbps = <189>;
40+
status = "okay";
41+
};
42+
43+
&psi5_0_ch1_rx_slot0 {
44+
duration-us = <150>;
45+
start-offset-us = <110>;
46+
data-length = <16>;
47+
status = "okay";
48+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "s32z2xxdc2_s32z270_rtu0.overlay"

tests/drivers/psi5/psi5_api/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_PSI5=y

0 commit comments

Comments
 (0)