Skip to content

Commit dfebc33

Browse files
committed
samples: boards: nxp: add sample for using psi5 driver
Add sample for using psi5 driver on s32z Signed-off-by: Cong Nguyen Huu <[email protected]>
1 parent ce2eff6 commit dfebc33

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed
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)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&pinctrl {
8+
psi5_0_default: psi5_0_default {
9+
group1 {
10+
pinmux = <PA7_PSI5_0_SDOUT1>, <PB3_PSI5_0_SDOUT2>;
11+
output-enable;
12+
};
13+
group2 {
14+
pinmux = <PA6_PSI5_0_SDIN1>, <PB2_PSI5_0_SDIN2>;
15+
input-enable;
16+
};
17+
};
18+
};
19+
20+
&psi5_0 {
21+
pinctrl-0 = <&psi5_0_default>;
22+
pinctrl-names = "default";
23+
status = "okay";
24+
};
25+
26+
&psi5_0_ch1 {
27+
target-pulse-us = <8>;
28+
decoder-offset-us = <0>;
29+
low-pulse-width-us = <4>;
30+
high-pulse-width-us = <4>;
31+
tx-mode = "short-frame-31";
32+
rx-buf-size = <32>;
33+
bitrate-kbps = <125>;
34+
array-slot-duration-us = <1000 1000>;
35+
array-slot-start-offset-us = <0 0>;
36+
array-slot-data-length = <16 16>;
37+
status = "okay";
38+
};
39+
40+
&psi5_0_ch2 {
41+
target-pulse-us = <8>;
42+
decoder-offset-us = <0>;
43+
low-pulse-width-us = <4>;
44+
high-pulse-width-us = <4>;
45+
tx-mode = "short-frame-31";
46+
rx-buf-size = <32>;
47+
bitrate-kbps = <125>;
48+
array-slot-duration-us = <1000 1000>;
49+
array-slot-start-offset-us = <0 0>;
50+
array-slot-data-length = <16 16>;
51+
status = "okay";
52+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&pinctrl {
8+
psi5_0_default: psi5_0_default {
9+
group1 {
10+
pinmux = <PA7_PSI5_0_SDOUT1>, <PB3_PSI5_0_SDOUT2>;
11+
output-enable;
12+
};
13+
group2 {
14+
pinmux = <PA6_PSI5_0_SDIN1>, <PB2_PSI5_0_SDIN2>;
15+
input-enable;
16+
};
17+
};
18+
};
19+
20+
&psi5_0 {
21+
pinctrl-0 = <&psi5_0_default>;
22+
pinctrl-names = "default";
23+
status = "okay";
24+
};
25+
26+
&psi5_0_ch1 {
27+
target-pulse-us = <8>;
28+
decoder-offset-us = <0>;
29+
low-pulse-width-us = <4>;
30+
high-pulse-width-us = <4>;
31+
tx-mode = "short-frame-31";
32+
rx-buf-size = <32>;
33+
bitrate-kbps = <125>;
34+
array-slot-duration-us = <1000 1000>;
35+
array-slot-start-offset-us = <0 0>;
36+
array-slot-data-length = <16 16>;
37+
status = "okay";
38+
};
39+
40+
&psi5_0_ch2 {
41+
target-pulse-us = <8>;
42+
decoder-offset-us = <0>;
43+
low-pulse-width-us = <4>;
44+
high-pulse-width-us = <4>;
45+
tx-mode = "short-frame-31";
46+
rx-buf-size = <32>;
47+
bitrate-kbps = <125>;
48+
array-slot-duration-us = <1000 1000>;
49+
array-slot-start-offset-us = <0 0>;
50+
array-slot-data-length = <16 16>;
51+
status = "okay";
52+
};
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sample:
2+
description: Sample for using PSI5 driver
3+
name: NXP S32 PSI5 sample
4+
5+
tests:
6+
sample.boards.nxp_s32.psi5:
7+
platform_allow:
8+
- s32z2xxdc2/s32z270/rtu0
9+
- s32z2xxdc2/s32z270/rtu1
10+
- s32z2xxdc2@D/s32z270/rtu0
11+
- s32z2xxdc2@D/s32z270/rtu1
12+
depends_on: psi5
13+
tags: psi5
14+
harness: console
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(nxp_s32_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_INST(0, nxp_s32_psi5)
15+
16+
void tx_cb(const struct device *dev, uint8_t channel_id, enum psi5_state state, void *user_data)
17+
{
18+
LOG_INF("tx ch %d", channel_id);
19+
}
20+
21+
void rx_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame,
22+
enum psi5_state state, void *user_data)
23+
{
24+
LOG_INF("rx ch %d", channel_id);
25+
}
26+
27+
int main(void)
28+
{
29+
const struct device *const dev = DEVICE_DT_GET(PSI5_NODE);
30+
uint64_t send_data = 0x123456789ABCDEF;
31+
32+
psi5_add_rx_callback(dev, 2, rx_cb, NULL);
33+
34+
psi5_start(dev, 1);
35+
36+
psi5_send(dev, 1, send_data, K_MSEC(100), tx_cb, NULL);
37+
38+
psi5_stop(dev, 1);
39+
40+
k_sleep(K_MSEC(100));
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)