Skip to content

Commit b7feffc

Browse files
committed
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 b39e4df commit b7feffc

13 files changed

+428
-0
lines changed

samples/drivers/psi5/CMakeLists.txt

+8
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

+34
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 Peripheral Sensor Interface (PSI5) driver.
6+
7+
Overview
8+
********
9+
10+
The sample application shows how to use the Peripheral Sensor Interface (PSI5) driver:
11+
12+
* Receive data
13+
* Transmit data
14+
15+
Requirements
16+
************
17+
18+
This sample requires a PSI5 sensor to be connected.
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
psi5-node = &psi5_0;
10+
};
11+
};
12+
13+
&pinctrl {
14+
psi5_0_default: psi5_0_default {
15+
group1 {
16+
pinmux = <PA7_PSI5_0_SDOUT1>, <PB3_PSI5_0_SDOUT2>;
17+
output-enable;
18+
};
19+
group2 {
20+
pinmux = <PA6_PSI5_0_SDIN1>, <PB2_PSI5_0_SDIN2>;
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-mode = "long-frame-31";
38+
num-rx-buf = <32>;
39+
rx-bitrate-kbps = <189>;
40+
array-slot-duration-us = <150>;
41+
array-slot-start-offset-us = <110>;
42+
array-slot-data-length = <16>;
43+
array-slot-data-msb-first = <0>;
44+
array-slot-has-smc = <0>;
45+
array-slot-has-parity = <0>;
46+
status = "okay";
47+
};
48+
49+
&psi5_0_ch2 {
50+
period-sync-pulse-us = <8>;
51+
decoder-start-offset-us = <0>;
52+
pulse-width-0-us = <2>;
53+
pulse-width-1-us = <6>;
54+
tx-mode = "long-frame-31";
55+
num-rx-buf = <32>;
56+
rx-bitrate-kbps = <189>;
57+
array-slot-duration-us = <500>;
58+
array-slot-start-offset-us = <0>;
59+
array-slot-data-length = <16>;
60+
array-slot-data-msb-first = <0>;
61+
array-slot-has-smc = <0>;
62+
array-slot-has-parity = <0>;
63+
status = "okay";
64+
};
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

+3
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

+11
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-node")
11+
harness: sensor

samples/drivers/psi5/src/main.c

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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_node)
15+
#define PSI5_CHANNEL 1
16+
17+
void tx_cb(const struct device *dev, uint8_t channel_id, enum psi5_status status, void *user_data)
18+
{
19+
LOG_INF("Transmitted data on channel %d", channel_id);
20+
}
21+
22+
void rx_serial_frame_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame,
23+
enum psi5_status status, void *user_data)
24+
{
25+
26+
if (status == PSI5_RX_SERIAL_FRAME) {
27+
LOG_INF("Received a frame on channel %d, "
28+
"id: %d, data: %d, timestamp: %d, slot: %d",
29+
channel_id, frame->serial.id, frame->serial.data, frame->timestamp,
30+
frame->slot_number);
31+
} else {
32+
LOG_INF("Error received on channel %d", channel_id);
33+
}
34+
}
35+
36+
void rx_data_frame_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame,
37+
enum psi5_status status, void *user_data)
38+
{
39+
40+
if (status == PSI5_RX_DATA_FRAME) {
41+
LOG_INF("Received a frame on channel %d, "
42+
"data: %d, timestamp: %d",
43+
channel_id, frame->data, frame->timestamp);
44+
} else {
45+
LOG_INF("Error received on channel %d", channel_id);
46+
}
47+
}
48+
49+
int main(void)
50+
{
51+
const struct device *const dev = DEVICE_DT_GET(PSI5_NODE);
52+
uint64_t send_data = 0x1234;
53+
54+
psi5_add_rx_callback(dev, PSI5_CHANNEL, rx_serial_frame_cb, rx_data_frame_cb, NULL);
55+
56+
psi5_start_sync(dev, PSI5_CHANNEL);
57+
58+
psi5_send(dev, PSI5_CHANNEL, send_data, K_MSEC(100), tx_cb, NULL);
59+
60+
while (true) {
61+
/* To transmit and receive data */
62+
}
63+
64+
return 0;
65+
}
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})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
psi5-node = &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-mode = "long-frame-31";
38+
num-rx-buf = <32>;
39+
rx-bitrate-kbps = <189>;
40+
array-slot-duration-us = <150>;
41+
array-slot-start-offset-us = <110>;
42+
array-slot-data-length = <16>;
43+
array-slot-data-msb-first = <0>;
44+
array-slot-has-smc = <0>;
45+
array-slot-has-parity = <0>;
46+
status = "okay";
47+
};
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

+2
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)