From 06c102030478f579e51fc88104075c536a1df098 Mon Sep 17 00:00:00 2001 From: Mahesh Mahadevan Date: Thu, 4 Feb 2021 16:39:23 -0600 Subject: [PATCH] tests: i2s: Update i2s_speed test 1. Allow loopback over different I2S ports 2. Add a config option to indicate if the ports are separate Signed-off-by: Mahesh Mahadevan --- tests/drivers/i2s/i2s_speed/Kconfig | 14 ++++ .../i2s_speed/boards/mimxrt685_evk_cm33.conf | 7 ++ .../i2s/i2s_speed/src/test_i2s_speed.c | 76 +++++++++++-------- 3 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 tests/drivers/i2s/i2s_speed/Kconfig create mode 100644 tests/drivers/i2s/i2s_speed/boards/mimxrt685_evk_cm33.conf diff --git a/tests/drivers/i2s/i2s_speed/Kconfig b/tests/drivers/i2s/i2s_speed/Kconfig new file mode 100644 index 00000000000..1af3d1b6de1 --- /dev/null +++ b/tests/drivers/i2s/i2s_speed/Kconfig @@ -0,0 +1,14 @@ +# +# Copyright (c) 2021, NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +mainmenu "I2S Speed Test" + +source "Kconfig.zephyr" + +config I2S_TEST_SEPARATE_DEVICES + bool "Use two separate I2S ports for loopback" + help + Use separate I2S ports for transmit and receive. diff --git a/tests/drivers/i2s/i2s_speed/boards/mimxrt685_evk_cm33.conf b/tests/drivers/i2s/i2s_speed/boards/mimxrt685_evk_cm33.conf new file mode 100644 index 00000000000..f39c5265a47 --- /dev/null +++ b/tests/drivers/i2s/i2s_speed/boards/mimxrt685_evk_cm33.conf @@ -0,0 +1,7 @@ +# +# Copyright (c) 2021, NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_I2S_TEST_SEPARATE_DEVICES=y diff --git a/tests/drivers/i2s/i2s_speed/src/test_i2s_speed.c b/tests/drivers/i2s/i2s_speed/src/test_i2s_speed.c index e0f0b18ed12..321a33a0008 100644 --- a/tests/drivers/i2s/i2s_speed/src/test_i2s_speed.c +++ b/tests/drivers/i2s/i2s_speed/src/test_i2s_speed.c @@ -9,7 +9,13 @@ #include #include -#define I2S_DEV_NAME "I2S_0" +#define I2S_DEV_NAME_RX "I2S_0" +#ifdef CONFIG_I2S_TEST_SEPARATE_DEVICES +#define I2S_DEV_NAME_TX "I2S_1" +#else +#define I2S_DEV_NAME_TX "I2S_0" +#endif + #define NUM_BLOCKS 20 #define SAMPLE_NO 64 @@ -80,15 +86,16 @@ void test_i2s_tx_transfer_configure(void) struct i2s_config i2s_cfg; int ret; - dev_i2s = device_get_binding(I2S_DEV_NAME); - zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found"); + dev_i2s = device_get_binding(I2S_DEV_NAME_TX); + zassert_not_null(dev_i2s, "device " I2S_DEV_NAME_TX " not found"); /* Configure */ i2s_cfg.word_size = 16U; i2s_cfg.channels = 2U; i2s_cfg.format = I2S_FMT_DATA_FORMAT_I2S; - i2s_cfg.options = I2S_OPT_FRAME_CLK_SLAVE | I2S_OPT_BIT_CLK_SLAVE; + /* Configure the Transmit port as Master */ + i2s_cfg.options = I2S_OPT_FRAME_CLK_MASTER | I2S_OPT_BIT_CLK_MASTER; i2s_cfg.frame_clk_freq = FRAME_CLK_FREQ; i2s_cfg.block_size = BLOCK_SIZE; i2s_cfg.mem_slab = &tx_0_mem_slab; @@ -106,14 +113,15 @@ void test_i2s_rx_transfer_configure(void) struct i2s_config i2s_cfg; int ret; - dev_i2s = device_get_binding(I2S_DEV_NAME); - zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found"); + dev_i2s = device_get_binding(I2S_DEV_NAME_RX); + zassert_not_null(dev_i2s, "device " I2S_DEV_NAME_RX " not found"); /* Configure */ i2s_cfg.word_size = 16U; i2s_cfg.channels = 2U; i2s_cfg.format = I2S_FMT_DATA_FORMAT_I2S; + /* Configure the Receive port as Slave */ i2s_cfg.options = I2S_OPT_FRAME_CLK_SLAVE | I2S_OPT_BIT_CLK_SLAVE; i2s_cfg.frame_clk_freq = FRAME_CLK_FREQ; i2s_cfg.block_size = BLOCK_SIZE; @@ -135,14 +143,18 @@ void test_i2s_rx_transfer_configure(void) */ void test_i2s_transfer_short(void) { - const struct device *dev_i2s; + const struct device *dev_i2s_rx; + const struct device *dev_i2s_tx; void *rx_block[3]; void *tx_block; size_t rx_size; int ret; - dev_i2s = device_get_binding(I2S_DEV_NAME); - zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found"); + dev_i2s_rx = device_get_binding(I2S_DEV_NAME_RX); + zassert_not_null(dev_i2s_rx, "device " I2S_DEV_NAME_RX " not found"); + + dev_i2s_tx = device_get_binding(I2S_DEV_NAME_TX); + zassert_not_null(dev_i2s_tx, "device " I2S_DEV_NAME_TX " not found"); /* Prefill TX queue */ for (int i = 0; i < 3; i++) { @@ -150,37 +162,37 @@ void test_i2s_transfer_short(void) zassert_equal(ret, 0, NULL); fill_buf((uint16_t *)tx_block, i); - ret = i2s_write(dev_i2s, tx_block, BLOCK_SIZE); + ret = i2s_write(dev_i2s_tx, tx_block, BLOCK_SIZE); zassert_equal(ret, 0, NULL); TC_PRINT("%d->OK\n", i); } /* Start reception */ - ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_START); + ret = i2s_trigger(dev_i2s_rx, I2S_DIR_RX, I2S_TRIGGER_START); zassert_equal(ret, 0, "RX START trigger failed"); /* Start transmission */ - ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_START); + ret = i2s_trigger(dev_i2s_tx, I2S_DIR_TX, I2S_TRIGGER_START); zassert_equal(ret, 0, "TX START trigger failed"); /* All data written, drain TX queue and stop the transmission */ - ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_DRAIN); + ret = i2s_trigger(dev_i2s_tx, I2S_DIR_TX, I2S_TRIGGER_DRAIN); zassert_equal(ret, 0, "TX DRAIN trigger failed"); - ret = i2s_read(dev_i2s, &rx_block[0], &rx_size); + ret = i2s_read(dev_i2s_rx, &rx_block[0], &rx_size); zassert_equal(ret, 0, NULL); zassert_equal(rx_size, BLOCK_SIZE, NULL); - ret = i2s_read(dev_i2s, &rx_block[1], &rx_size); + ret = i2s_read(dev_i2s_rx, &rx_block[1], &rx_size); zassert_equal(ret, 0, NULL); zassert_equal(rx_size, BLOCK_SIZE, NULL); /* All but one data block read, stop reception */ - ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_STOP); + ret = i2s_trigger(dev_i2s_rx, I2S_DIR_RX, I2S_TRIGGER_STOP); zassert_equal(ret, 0, "RX STOP trigger failed"); - ret = i2s_read(dev_i2s, &rx_block[2], &rx_size); + ret = i2s_read(dev_i2s_rx, &rx_block[2], &rx_size); zassert_equal(ret, 0, NULL); zassert_equal(rx_size, BLOCK_SIZE, NULL); @@ -211,7 +223,8 @@ void test_i2s_transfer_short(void) */ void test_i2s_transfer_long(void) { - const struct device *dev_i2s; + const struct device *dev_i2s_rx; + const struct device *dev_i2s_tx; void *rx_block[NUM_BLOCKS]; void *tx_block[NUM_BLOCKS]; size_t rx_size; @@ -220,8 +233,11 @@ void test_i2s_transfer_long(void) int num_verified; int ret; - dev_i2s = device_get_binding(I2S_DEV_NAME); - zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found"); + dev_i2s_rx = device_get_binding(I2S_DEV_NAME_RX); + zassert_not_null(dev_i2s_rx, "device " I2S_DEV_NAME_RX " not found"); + + dev_i2s_tx = device_get_binding(I2S_DEV_NAME_TX); + zassert_not_null(dev_i2s_tx, "device " I2S_DEV_NAME_TX " not found"); /* Prepare TX data blocks */ for (tx_idx = 0; tx_idx < NUM_BLOCKS; tx_idx++) { @@ -234,42 +250,42 @@ void test_i2s_transfer_long(void) tx_idx = 0; /* Prefill TX queue */ - ret = i2s_write(dev_i2s, tx_block[tx_idx++], BLOCK_SIZE); + ret = i2s_write(dev_i2s_tx, tx_block[tx_idx++], BLOCK_SIZE); zassert_equal(ret, 0, NULL); - ret = i2s_write(dev_i2s, tx_block[tx_idx++], BLOCK_SIZE); + ret = i2s_write(dev_i2s_tx, tx_block[tx_idx++], BLOCK_SIZE); zassert_equal(ret, 0, NULL); /* Start reception */ - ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_START); + ret = i2s_trigger(dev_i2s_rx, I2S_DIR_RX, I2S_TRIGGER_START); zassert_equal(ret, 0, "RX START trigger failed"); /* Start transmission */ - ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_START); + ret = i2s_trigger(dev_i2s_tx, I2S_DIR_TX, I2S_TRIGGER_START); zassert_equal(ret, 0, "TX START trigger failed"); for (; tx_idx < NUM_BLOCKS; ) { - ret = i2s_write(dev_i2s, tx_block[tx_idx++], BLOCK_SIZE); + ret = i2s_write(dev_i2s_tx, tx_block[tx_idx++], BLOCK_SIZE); zassert_equal(ret, 0, NULL); - ret = i2s_read(dev_i2s, &rx_block[rx_idx++], &rx_size); + ret = i2s_read(dev_i2s_rx, &rx_block[rx_idx++], &rx_size); zassert_equal(ret, 0, NULL); zassert_equal(rx_size, BLOCK_SIZE, NULL); } /* All data written, flush TX queue and stop the transmission */ - ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_DRAIN); + ret = i2s_trigger(dev_i2s_tx, I2S_DIR_TX, I2S_TRIGGER_DRAIN); zassert_equal(ret, 0, "TX DRAIN trigger failed"); - ret = i2s_read(dev_i2s, &rx_block[rx_idx++], &rx_size); + ret = i2s_read(dev_i2s_rx, &rx_block[rx_idx++], &rx_size); zassert_equal(ret, 0, NULL); zassert_equal(rx_size, BLOCK_SIZE, NULL); /* All but one data block read, stop reception */ - ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_STOP); + ret = i2s_trigger(dev_i2s_rx, I2S_DIR_RX, I2S_TRIGGER_STOP); zassert_equal(ret, 0, "RX STOP trigger failed"); - ret = i2s_read(dev_i2s, &rx_block[rx_idx++], &rx_size); + ret = i2s_read(dev_i2s_rx, &rx_block[rx_idx++], &rx_size); zassert_equal(ret, 0, NULL); zassert_equal(rx_size, BLOCK_SIZE, NULL);