Skip to content

Commit c3b0868

Browse files
tests: i2s: align to nRF54H20 TDM
Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent f762835 commit c3b0868

File tree

6 files changed

+124
-11
lines changed

6 files changed

+124
-11
lines changed

tests/drivers/i2s/i2s_api/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ config I2S_TEST_SEPARATE_DEVICES
1515

1616
config I2S_TEST_USE_I2S_DIR_BOTH
1717
bool "Use I2S_DIR_BOTH value to perform RX/TX transfers"
18-
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED
18+
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED || DT_HAS_NORDIC_NRF_TDM_ENABLED
1919
help
2020
Use the I2S_DIR_BOTH enumeration value to trigger commands in test
2121
cases involving both reception and transmission. Use of this option
@@ -24,15 +24,15 @@ config I2S_TEST_USE_I2S_DIR_BOTH
2424

2525
config I2S_TEST_USE_GPIO_LOOPBACK
2626
bool "Use GPIO loopback"
27-
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED
27+
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED || DT_HAS_NORDIC_NRF_TDM_ENABLED
2828
help
2929
Use wiring between the data-out and data-in pins for looping back
3030
data. This option is intended to be used for devices that do not
3131
provide the internal loopback functionality.
3232

3333
config I2S_TEST_ALLOWED_DATA_OFFSET
3434
int "Allowed offset in received data"
35-
default 2 if DT_HAS_NORDIC_NRF_I2S_ENABLED
35+
default 10 if DT_HAS_NORDIC_NRF_I2S_ENABLED || DT_HAS_NORDIC_NRF_TDM_ENABLED
3636
default 0
3737
help
3838
Maximum allowed offset between sent and received samples. Non-zero
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* i2s-node0 is the transmitter/receiver */
8+
9+
/ {
10+
aliases {
11+
i2s-node0 = &tdm130;
12+
};
13+
};
14+
15+
&pinctrl {
16+
tdm130_default_alt: tdm130_default_alt {
17+
group1 {
18+
psels = <NRF_PSEL(TDM_SCK_M, 1, 3)>,
19+
<NRF_PSEL(TDM_FSYNC_M, 1, 6)>,
20+
<NRF_PSEL(TDM_SDOUT, 1, 4)>,
21+
<NRF_PSEL(TDM_SDIN, 1, 5)>,
22+
<NRF_PSEL(TDM_MCK, 1, 2)>;
23+
};
24+
};
25+
};
26+
27+
&tdm130 {
28+
status = "okay";
29+
pinctrl-0 = <&tdm130_default_alt>;
30+
pinctrl-names = "default";
31+
memory-regions = <&cpuapp_dma_region>;
32+
mck-frequency = <1000000>;
33+
};
34+
35+
&cpuapp_dma_region {
36+
status = "okay";
37+
};
38+

tests/drivers/i2s/i2s_api/src/common.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,32 @@
88
#include <zephyr/ztest.h>
99
#include <zephyr/drivers/i2s.h>
1010
#include "i2s_api_test.h"
11+
#include <zephyr/linker/devicetree_regions.h>
1112

12-
K_MEM_SLAB_DEFINE(rx_mem_slab, BLOCK_SIZE, NUM_RX_BLOCKS, 32);
13-
K_MEM_SLAB_DEFINE(tx_mem_slab, BLOCK_SIZE, NUM_TX_BLOCKS, 32);
13+
#define TDM(idx) DT_NODELABEL(tdm##idx)
14+
#define TDM_PROP(idx, prop) DT_PROP(TDM(idx), prop)
15+
#define TDM_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(TDM(idx), prop)
16+
17+
18+
#define TDM_MEMORY_SECTION(idx) \
19+
COND_CODE_1(TDM_HAS_PROP(idx, memory_regions), \
20+
(__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \
21+
DT_PHANDLE(TDM(idx), memory_regions)))))), \
22+
())
23+
24+
#define BUFFER_MEM_REGION __attribute__((__section__("cpuapp_dma_region")))
25+
26+
char __aligned(WB_UP(32))
27+
_k_mem_slab_buf_rx_mem_slab[(NUM_RX_BLOCKS + 2) * WB_UP(BLOCK_SIZE)] TDM_MEMORY_SECTION(130);
28+
STRUCT_SECTION_ITERABLE(k_mem_slab, rx_mem_slab) =
29+
Z_MEM_SLAB_INITIALIZER(rx_mem_slab, _k_mem_slab_buf_rx_mem_slab,
30+
WB_UP(BLOCK_SIZE), NUM_RX_BLOCKS + 2);
31+
32+
char __aligned(WB_UP(32))
33+
_k_mem_slab_buf_tx_mem_slab[(NUM_TX_BLOCKS) * WB_UP(BLOCK_SIZE)] TDM_MEMORY_SECTION(130);
34+
STRUCT_SECTION_ITERABLE(k_mem_slab, tx_mem_slab) =
35+
Z_MEM_SLAB_INITIALIZER(tx_mem_slab, _k_mem_slab_buf_tx_mem_slab,
36+
WB_UP(BLOCK_SIZE), NUM_TX_BLOCKS);
1437

1538
/* The data_l represent a sine wave */
1639
ZTEST_DMEM int16_t data_l[SAMPLE_NO] = {

tests/drivers/i2s/i2s_speed/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ config I2S_TEST_SEPARATE_DEVICES
1515

1616
config I2S_TEST_USE_I2S_DIR_BOTH
1717
bool "Use I2S_DIR_BOTH value to perform RX/TX transfers"
18-
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED
18+
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED || DT_HAS_NORDIC_NRF_TDM_ENABLED
1919
help
2020
Use the I2S_DIR_BOTH enumeration value to trigger commands in test
2121
cases involving both reception and transmission. Use of this option
@@ -24,15 +24,15 @@ config I2S_TEST_USE_I2S_DIR_BOTH
2424

2525
config I2S_TEST_USE_GPIO_LOOPBACK
2626
bool "Use GPIO loopback"
27-
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED
27+
default y if DT_HAS_NORDIC_NRF_I2S_ENABLED || DT_HAS_NORDIC_NRF_TDM_ENABLED
2828
help
2929
Use wiring between the data-out and data-in pins for looping back
3030
data. This option is intended to be used for devices that do not
3131
provide the internal loopback functionality.
3232

3333
config I2S_TEST_ALLOWED_DATA_OFFSET
3434
int "Allowed offset in received data"
35-
default 2 if DT_HAS_NORDIC_NRF_I2S_ENABLED
35+
default 2 if DT_HAS_NORDIC_NRF_I2S_ENABLED || DT_HAS_NORDIC_NRF_TDM_ENABLED
3636
default 0
3737
help
3838
Maximum allowed offset between sent and received samples. Non-zero
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* i2s-node0 is the transmitter/receiver */
8+
9+
/ {
10+
aliases {
11+
i2s-node0 = &tdm130;
12+
};
13+
};
14+
15+
&pinctrl {
16+
tdm130_default_alt: tdm130_default_alt {
17+
group1 {
18+
psels = <NRF_PSEL(TDM_SCK_M, 1, 3)>,
19+
<NRF_PSEL(TDM_FSYNC_M, 1, 6)>,
20+
<NRF_PSEL(TDM_SDOUT, 1, 4)>,
21+
<NRF_PSEL(TDM_SDIN, 1, 5)>,
22+
<NRF_PSEL(TDM_MCK, 1, 2)>;
23+
};
24+
};
25+
};
26+
27+
&tdm130 {
28+
status = "okay";
29+
pinctrl-0 = <&tdm130_default_alt>;
30+
pinctrl-names = "default";
31+
memory-regions = <&cpuapp_dma_region>;
32+
mck-frequency = <1000000>;
33+
};
34+
35+
&cpuapp_dma_region {
36+
status = "okay";
37+
};
38+

tests/drivers/i2s/i2s_speed/src/test_i2s_speed.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/ztest.h>
1010
#include <zephyr/drivers/i2s.h>
1111
#include <zephyr/sys/iterable_sections.h>
12+
#include <zephyr/linker/devicetree_regions.h>
1213

1314
#define I2S_DEV_NODE_RX DT_ALIAS(i2s_node0)
1415
#ifdef CONFIG_I2S_TEST_SEPARATE_DEVICES
@@ -17,7 +18,7 @@
1718
#define I2S_DEV_NODE_TX DT_ALIAS(i2s_node0)
1819
#endif
1920

20-
#define NUM_BLOCKS 20
21+
#define NUM_BLOCKS 5
2122
#define SAMPLE_NO 64
2223

2324
/* The data_l represent a sine wave */
@@ -58,14 +59,27 @@ static int16_t data_r[SAMPLE_NO] = {
5859
* RX blocks to satisfy this requirement
5960
*/
6061

62+
#define TDM(idx) DT_NODELABEL(tdm##idx)
63+
#define TDM_PROP(idx, prop) DT_PROP(TDM(idx), prop)
64+
#define TDM_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(TDM(idx), prop)
65+
66+
67+
#define TDM_MEMORY_SECTION(idx) \
68+
COND_CODE_1(TDM_HAS_PROP(idx, memory_regions), \
69+
(__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \
70+
DT_PHANDLE(TDM(idx), memory_regions)))))), \
71+
())
72+
73+
#define BUFFER_MEM_REGION __attribute__((__section__("cpuapp_dma_region")))
74+
6175
char MEM_SLAB_CACHE_ATTR __aligned(WB_UP(32))
62-
_k_mem_slab_buf_rx_0_mem_slab[(NUM_BLOCKS + 2) * WB_UP(BLOCK_SIZE)];
76+
_k_mem_slab_buf_rx_0_mem_slab[(NUM_BLOCKS + 2) * WB_UP(BLOCK_SIZE)] TDM_MEMORY_SECTION(130);
6377
STRUCT_SECTION_ITERABLE(k_mem_slab, rx_0_mem_slab) =
6478
Z_MEM_SLAB_INITIALIZER(rx_0_mem_slab, _k_mem_slab_buf_rx_0_mem_slab,
6579
WB_UP(BLOCK_SIZE), NUM_BLOCKS + 2);
6680

6781
char MEM_SLAB_CACHE_ATTR __aligned(WB_UP(32))
68-
_k_mem_slab_buf_tx_0_mem_slab[(NUM_BLOCKS) * WB_UP(BLOCK_SIZE)];
82+
_k_mem_slab_buf_tx_0_mem_slab[(NUM_BLOCKS) * WB_UP(BLOCK_SIZE)] TDM_MEMORY_SECTION(130);
6983
STRUCT_SECTION_ITERABLE(k_mem_slab, tx_0_mem_slab) =
7084
Z_MEM_SLAB_INITIALIZER(tx_0_mem_slab, _k_mem_slab_buf_tx_0_mem_slab,
7185
WB_UP(BLOCK_SIZE), NUM_BLOCKS);

0 commit comments

Comments
 (0)