-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/samples: drivers: create test, sample for SENT driver
Create test, sample for SENT driver Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
- Loading branch information
1 parent
49be922
commit 4fc328c
Showing
13 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(sent) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.. zephyr:code-sample:: sent | ||
:name: SENT interface | ||
:relevant-api: sent_interface | ||
|
||
Use the Single Edge Nibble Transmission (SENT) driver. | ||
|
||
Overview | ||
******** | ||
|
||
The sample application shows how to use the Single Edge Nibble Transmission (SENT) driver: | ||
|
||
* Receive data | ||
|
||
Requirements | ||
************ | ||
|
||
This sample requires a SENT sensor to be connected. | ||
|
||
Building, Flashing and Running | ||
****************************** | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/drivers/sent | ||
:board: s32z2xxdc2/s32z270/rtu0 | ||
:goals: build flash | ||
|
||
Sample Output: | ||
|
||
.. code-block:: console | ||
Rx channel 1 completed |
34 changes: 34 additions & 0 deletions
34
samples/drivers/sent/boards/s32z2xxdc2_s32z270_rtu0.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
aliases { | ||
sent-node = &sent1; | ||
}; | ||
}; | ||
|
||
&pinctrl { | ||
sent1_default: sent1_default { | ||
group1 { | ||
pinmux = <PK2_SENT_1_CH1_I>; | ||
input-enable; | ||
}; | ||
}; | ||
}; | ||
|
||
&sent1 { | ||
pinctrl-0 = <&sent1_default>; | ||
pinctrl-names = "default"; | ||
status = "okay"; | ||
}; | ||
|
||
&sent1_ch1 { | ||
num-data-nibbles = <6>; | ||
tick-time-prescaler-us = <3>; | ||
bus-timeout-cycles = <256>; | ||
calib-method-low-latency; | ||
status = "okay"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_SENT=y | ||
CONFIG_SENT_LOG_LEVEL_DBG=y | ||
CONFIG_LOG=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
sample: | ||
name: SENT driver sample | ||
|
||
tests: | ||
sample.drivers.sent: | ||
tags: | ||
- drivers | ||
- sent | ||
depends_on: sent | ||
filter: dt_alias_exists("sent-node") | ||
harness: sensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(sent_sample, LOG_LEVEL_DBG); | ||
|
||
#include <zephyr/kernel.h> | ||
|
||
#include <zephyr/drivers/sent/sent.h> | ||
|
||
#define SENT_NODE DT_ALIAS(sent_node) | ||
#define SENT_CHANNEL 1 | ||
|
||
void rx_cb(const struct device *dev, uint8_t channel_id, struct sent_frame *frame, | ||
enum sent_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(SENT_NODE); | ||
|
||
sent_add_rx_callback(dev, SENT_CHANNEL, rx_cb, NULL); | ||
|
||
sent_start_rx(dev, SENT_CHANNEL); | ||
|
||
k_sleep(K_MSEC(100)); | ||
|
||
sent_stop_rx(dev, SENT_CHANNEL); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(sent) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
34 changes: 34 additions & 0 deletions
34
tests/drivers/sent/sent_api/boards/s32z2xxdc2_s32z270_rtu0.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
aliases { | ||
sent-node = &sent1; | ||
}; | ||
}; | ||
|
||
&pinctrl { | ||
sent1_default: sent1_default { | ||
group1 { | ||
pinmux = <PK2_SENT_1_CH1_I>; | ||
input-enable; | ||
}; | ||
}; | ||
}; | ||
|
||
&sent1 { | ||
pinctrl-0 = <&sent1_default>; | ||
pinctrl-names = "default"; | ||
status = "okay"; | ||
}; | ||
|
||
&sent1_ch1 { | ||
num-data-nibbles = <6>; | ||
tick-time-prescaler-us = <3>; | ||
bus-timeout-cycles = <256>; | ||
calib-method-low-latency; | ||
status = "okay"; | ||
}; |
7 changes: 7 additions & 0 deletions
7
tests/drivers/sent/sent_api/boards/s32z2xxdc2_s32z270_rtu1.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_SENT=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/ztest.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/sent/sent.h> | ||
|
||
#define SENT_NODE DT_ALIAS(sent_node) | ||
#define SENT_CHANNEL 1 | ||
|
||
const struct device *dev = DEVICE_DT_GET(SENT_NODE); | ||
|
||
static void *sent_setup(void) | ||
{ | ||
zassert_true(device_is_ready(dev), "SENT device is not ready"); | ||
|
||
return NULL; | ||
} | ||
|
||
void rx_cb(const struct device *dev, uint8_t channel_id, struct sent_frame *frame, | ||
enum sent_status status, void *user_data) | ||
{ | ||
ARG_UNUSED(dev); | ||
ARG_UNUSED(channel_id); | ||
ARG_UNUSED(frame); | ||
ARG_UNUSED(status); | ||
ARG_UNUSED(user_data); | ||
} | ||
|
||
/** | ||
* @brief Test starting rx is not allowed while started. | ||
*/ | ||
ZTEST_USER(sent_api, test_start_rx_while_started) | ||
{ | ||
int err; | ||
|
||
err = sent_start_rx(dev, SENT_CHANNEL); | ||
zassert_equal(err, 0, "Failed to start rx (err %d)", err); | ||
|
||
err = sent_start_rx(dev, SENT_CHANNEL); | ||
zassert_not_equal(err, 0, "Started rx while started"); | ||
zassert_equal(err, -EALREADY, "Wrong error return code (err %d)", err); | ||
} | ||
|
||
/** | ||
* @brief Test stopping rx is not allowed while stopped. | ||
*/ | ||
ZTEST_USER(sent_api, test_stop_rx_while_stoped) | ||
{ | ||
int err; | ||
|
||
err = sent_stop_rx(dev, SENT_CHANNEL); | ||
zassert_equal(err, 0, "Failed to stop rx (err %d)", err); | ||
|
||
err = sent_stop_rx(dev, SENT_CHANNEL); | ||
zassert_not_equal(err, 0, "Stopped rx while stopped"); | ||
zassert_equal(err, -EALREADY, "Wrong error return code (err %d)", err); | ||
|
||
err = sent_start_rx(dev, SENT_CHANNEL); | ||
zassert_equal(err, 0, "Failed to start rx (err %d)", err); | ||
} | ||
|
||
/** | ||
* @brief Test setting the SENT rx callback. | ||
*/ | ||
ZTEST(sent_api, test_set_rx_callback) | ||
{ | ||
int err; | ||
|
||
err = sent_add_rx_callback(dev, SENT_CHANNEL, rx_cb, NULL); | ||
zassert_equal(err, 0, "Failed to set rx callback (err %d)", err); | ||
|
||
sent_add_rx_callback(dev, SENT_CHANNEL, NULL, NULL); | ||
zassert_equal(err, 0, "Failed to set rx callback (err %d)", err); | ||
|
||
err = sent_add_rx_callback(dev, SENT_CHANNEL, rx_cb, NULL); | ||
zassert_equal(err, 0, "Failed to set rx callback (err %d)", err); | ||
} | ||
|
||
ZTEST_SUITE(sent_api, NULL, sent_setup, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tests: | ||
drivers.sent: | ||
tags: | ||
- drivers | ||
- sent | ||
depends_on: sent | ||
filter: dt_alias_exists("sent-node") |