Skip to content

Commit

Permalink
tests/samples: drivers: create test, sample for psi5 driver
Browse files Browse the repository at this point in the history
Create test, sample for psi5 driver

Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
  • Loading branch information
congnguyenhuu committed Jan 16, 2025
1 parent 3b4bec4 commit 8c5a2c3
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 0 deletions.
8 changes: 8 additions & 0 deletions samples/drivers/psi5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(psi5)

target_sources(app PRIVATE src/main.c)
34 changes: 34 additions & 0 deletions samples/drivers/psi5/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. zephyr:code-sample:: psi5
:name: PSI5 interface
:relevant-api: psi5_interface

Use the Peripheral Sensor Interface (PSI5) driver.

Overview
********

The sample application shows how to use the Peripheral Sensor Interface (PSI5) driver:

* Receive data
* Transmit data

Requirements
************

This sample requires a PSI5 sensor to be connected.

Building, Flashing and Running
******************************

.. zephyr-app-commands::
:zephyr-app: samples/drivers/psi5
:board: s32z2xxdc2/s32z270/rtu0
:goals: build flash

Sample Output:

.. code-block:: console
Rx channel 1 completed
Tx channel 2 completed
64 changes: 64 additions & 0 deletions samples/drivers/psi5/boards/s32z2xxdc2_s32z270_rtu0.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
psi5-node = &psi5_0;
};
};

&pinctrl {
psi5_0_default: psi5_0_default {
group1 {
pinmux = <PA7_PSI5_0_SDOUT1>, <PB3_PSI5_0_SDOUT2>;
output-enable;
};
group2 {
pinmux = <PA6_PSI5_0_SDIN1>, <PB2_PSI5_0_SDIN2>;
input-enable;
};
};
};

&psi5_0 {
pinctrl-0 = <&psi5_0_default>;
pinctrl-names = "default";
status = "okay";
};

&psi5_0_ch1 {
period-sync-pulse-us = <500>;
decoder-start-offset-us = <0>;
pulse-width-0-us = <100>;
pulse-width-1-us = <127>;
tx-mode = "long-frame-31";
num-rx-buf = <32>;
rx-bitrate-kbps = <189>;
array-slot-duration-us = <150>;
array-slot-start-offset-us = <110>;
array-slot-data-length = <16>;
array-slot-data-msb-first = <0>;
array-slot-has-smc = <0>;
array-slot-has-parity = <0>;
status = "okay";
};

&psi5_0_ch2 {
period-sync-pulse-us = <8>;
decoder-start-offset-us = <0>;
pulse-width-0-us = <2>;
pulse-width-1-us = <6>;
tx-mode = "long-frame-31";
num-rx-buf = <32>;
rx-bitrate-kbps = <189>;
array-slot-duration-us = <500>;
array-slot-start-offset-us = <0>;
array-slot-data-length = <16>;
array-slot-data-msb-first = <0>;
array-slot-has-smc = <0>;
array-slot-has-parity = <0>;
status = "okay";
};
7 changes: 7 additions & 0 deletions samples/drivers/psi5/boards/s32z2xxdc2_s32z270_rtu1.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "s32z2xxdc2_s32z270_rtu0.overlay"
3 changes: 3 additions & 0 deletions samples/drivers/psi5/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_PSI5=y
CONFIG_PSI5_LOG_LEVEL_DBG=y
CONFIG_LOG=y
11 changes: 11 additions & 0 deletions samples/drivers/psi5/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sample:
name: PSI5 driver sample

tests:
sample.drivers.psi5:
tags:
- drivers
- psi5
depends_on: psi5
filter: dt_alias_exists("psi5-node")
harness: sensor
54 changes: 54 additions & 0 deletions samples/drivers/psi5/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(psi5_sample, LOG_LEVEL_DBG);

#include <zephyr/kernel.h>

#include <zephyr/drivers/psi5/psi5.h>

#define PSI5_NODE DT_ALIAS(psi5_node)
#define PSI5_CHANNEL_RX 1
#define PSI5_CHANNEL_TX 2

void tx_cb(const struct device *dev, uint8_t channel_id, enum psi5_status status, void *user_data)
{
LOG_INF("Tx channel %d completed\n", channel_id);
}

void rx_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame,
enum psi5_status status, void *user_data)
{

LOG_INF("Rx channel %d completed\n", channel_id);
}

int main(void)
{
const struct device *const dev = DEVICE_DT_GET(PSI5_NODE);
uint64_t send_data = 0x1234;

/* Test receive data */
psi5_add_rx_callback(dev, PSI5_CHANNEL_RX, rx_cb, NULL);

psi5_start_sync(dev, PSI5_CHANNEL_RX);

k_sleep(K_MSEC(100));

psi5_stop_sync(dev, PSI5_CHANNEL_RX);

/* Test send data */
psi5_start_sync(dev, PSI5_CHANNEL_TX);

psi5_send(dev, PSI5_CHANNEL_TX, send_data, K_MSEC(100), tx_cb, NULL);

k_sleep(K_MSEC(100));

psi5_stop_sync(dev, PSI5_CHANNEL_TX);

return 0;
}
9 changes: 9 additions & 0 deletions tests/drivers/psi5/psi5_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(psi5)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
47 changes: 47 additions & 0 deletions tests/drivers/psi5/psi5_api/boards/s32z2xxdc2_s32z270_rtu0.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
psi5-node = &psi5_0;
};
};

&pinctrl {
psi5_0_default: psi5_0_default {
group1 {
pinmux = <PA7_PSI5_0_SDOUT1>;
output-enable;
};
group2 {
pinmux = <PA6_PSI5_0_SDIN1>;
input-enable;
};
};
};

&psi5_0 {
pinctrl-0 = <&psi5_0_default>;
pinctrl-names = "default";
status = "okay";
};

&psi5_0_ch1 {
period-sync-pulse-us = <500>;
decoder-start-offset-us = <0>;
pulse-width-0-us = <100>;
pulse-width-1-us = <127>;
tx-mode = "long-frame-31";
num-rx-buf = <32>;
rx-bitrate-kbps = <189>;
array-slot-duration-us = <150>;
array-slot-start-offset-us = <110>;
array-slot-data-length = <16>;
array-slot-data-msb-first = <0>;
array-slot-has-smc = <0>;
array-slot-has-parity = <0>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "s32z2xxdc2_s32z270_rtu0.overlay"
2 changes: 2 additions & 0 deletions tests/drivers/psi5/psi5_api/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_PSI5=y
Loading

0 comments on commit 8c5a2c3

Please sign in to comment.