tests: i2s_api: run in user mode
Now all tests are additionally run in user mode. Test now all use the i2s_buf_read/write APIs, which are themselves implemented in terms of i2s_read/write. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
9dc6c77bb0
commit
2d8b86d2c2
5 changed files with 235 additions and 243 deletions
120
tests/drivers/i2s/i2s_api/src/common.c
Normal file
120
tests/drivers/i2s/i2s_api/src/common.c
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 comsuisse AG
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <ztest.h>
|
||||||
|
#include <i2s.h>
|
||||||
|
#include "i2s_api_test.h"
|
||||||
|
|
||||||
|
/* The data_l represent a sine wave */
|
||||||
|
s16_t data_l[SAMPLE_NO] = {
|
||||||
|
6392, 12539, 18204, 23169, 27244, 30272, 32137, 32767, 32137,
|
||||||
|
30272, 27244, 23169, 18204, 12539, 6392, 0, -6393, -12540,
|
||||||
|
-18205, -23170, -27245, -30273, -32138, -32767, -32138, -30273, -27245,
|
||||||
|
-23170, -18205, -12540, -6393, -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The data_r represent a sine wave with double the frequency of data_l */
|
||||||
|
s16_t data_r[SAMPLE_NO] = {
|
||||||
|
12539, 23169, 30272, 32767, 30272, 23169, 12539, 0, -12540,
|
||||||
|
-23170, -30273, -32767, -30273, -23170, -12540, -1, 12539, 23169,
|
||||||
|
30272, 32767, 30272, 23169, 12539, 0, -12540, -23170, -30273,
|
||||||
|
-32767, -30273, -23170, -12540, -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void fill_buf(s16_t *tx_block, int att)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < SAMPLE_NO; i++) {
|
||||||
|
tx_block[2 * i] = data_l[i] >> att;
|
||||||
|
tx_block[2 * i + 1] = data_r[i] >> att;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int verify_buf(s16_t *rx_block, int att)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < SAMPLE_NO; i++) {
|
||||||
|
if (rx_block[2 * i] != data_l[i] >> att) {
|
||||||
|
TC_PRINT("Error: att %d: data_l mismatch at position "
|
||||||
|
"%d, expected %d, actual %d\n",
|
||||||
|
att, i, data_l[i] >> att, rx_block[2 * i]);
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
if (rx_block[2 * i + 1] != data_r[i] >> att) {
|
||||||
|
TC_PRINT("Error: att %d: data_r mismatch at position "
|
||||||
|
"%d, expected %d, actual %d\n",
|
||||||
|
att, i, data_r[i] >> att, rx_block[2 * i + 1]);
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TC_PASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_buf_const(s16_t *tx_block, s16_t val_l, s16_t val_r)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < SAMPLE_NO; i++) {
|
||||||
|
tx_block[2 * i] = val_l;
|
||||||
|
tx_block[2 * i + 1] = val_r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int verify_buf_const(s16_t *rx_block, s16_t val_l, s16_t val_r)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < SAMPLE_NO; i++) {
|
||||||
|
if (rx_block[2 * i] != val_l) {
|
||||||
|
TC_PRINT("Error: data_l mismatch at position "
|
||||||
|
"%d, expected %d, actual %d\n",
|
||||||
|
i, val_l, rx_block[2 * i]);
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
if (rx_block[2 * i + 1] != val_r) {
|
||||||
|
TC_PRINT("Error: data_r mismatch at position "
|
||||||
|
"%d, expected %d, actual %d\n",
|
||||||
|
i, val_r, rx_block[2 * i + 1]);
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TC_PASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tx_block_write_slab(struct device *dev_i2s, int att, int err,
|
||||||
|
struct k_mem_slab *slab)
|
||||||
|
{
|
||||||
|
char tx_block[BLOCK_SIZE];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
fill_buf((u16_t *)tx_block, att);
|
||||||
|
ret = i2s_buf_write(dev_i2s, tx_block, BLOCK_SIZE);
|
||||||
|
if (ret != err) {
|
||||||
|
TC_PRINT("Error: i2s_write failed expected %d, actual %d\n",
|
||||||
|
err, ret);
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TC_PASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rx_block_read_slab(struct device *dev_i2s, int att,
|
||||||
|
struct k_mem_slab *slab)
|
||||||
|
{
|
||||||
|
char rx_block[BLOCK_SIZE];
|
||||||
|
size_t rx_size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = i2s_buf_read(dev_i2s, rx_block, &rx_size);
|
||||||
|
if (ret < 0 || rx_size != BLOCK_SIZE) {
|
||||||
|
TC_PRINT("Error: Read failed\n");
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
ret = verify_buf((u16_t *)rx_block, att);
|
||||||
|
if (ret < 0) {
|
||||||
|
TC_PRINT("Error: Verify failed\n");
|
||||||
|
return -TC_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TC_PASS;
|
||||||
|
}
|
54
tests/drivers/i2s/i2s_api/src/i2s_api_test.h
Normal file
54
tests/drivers/i2s/i2s_api/src/i2s_api_test.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 comsuisse AG
|
||||||
|
* Copyright (c) 2018 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef I2S_API_TEST_H
|
||||||
|
#define I2S_API_TEST_H
|
||||||
|
|
||||||
|
#include <kernel.h>
|
||||||
|
|
||||||
|
void test_i2s_tx_transfer_configure_0(void);
|
||||||
|
void test_i2s_rx_transfer_configure_0(void);
|
||||||
|
void test_i2s_transfer_short(void);
|
||||||
|
void test_i2s_transfer_long(void);
|
||||||
|
void test_i2s_rx_sync_start(void);
|
||||||
|
void test_i2s_rx_empty_timeout(void);
|
||||||
|
void test_i2s_transfer_restart(void);
|
||||||
|
void test_i2s_transfer_rx_overrun(void);
|
||||||
|
void test_i2s_transfer_tx_underrun(void);
|
||||||
|
|
||||||
|
void test_i2s_tx_transfer_configure_1(void);
|
||||||
|
void test_i2s_rx_transfer_configure_1(void);
|
||||||
|
void test_i2s_state_not_ready_neg(void);
|
||||||
|
void test_i2s_state_ready_neg(void);
|
||||||
|
void test_i2s_state_running_neg(void);
|
||||||
|
void test_i2s_state_stopping_neg(void);
|
||||||
|
void test_i2s_state_error_neg(void);
|
||||||
|
|
||||||
|
extern struct k_mem_slab rx_0_mem_slab;
|
||||||
|
extern struct k_mem_slab tx_0_mem_slab;
|
||||||
|
extern struct k_mem_slab rx_1_mem_slab;
|
||||||
|
extern struct k_mem_slab tx_1_mem_slab;
|
||||||
|
|
||||||
|
#define SAMPLE_NO 32
|
||||||
|
#define TIMEOUT 2000
|
||||||
|
#define FRAME_CLK_FREQ 8000
|
||||||
|
|
||||||
|
extern s16_t data_l[SAMPLE_NO];
|
||||||
|
extern s16_t data_r[SAMPLE_NO];
|
||||||
|
|
||||||
|
#define I2S_DEV_NAME "I2S_0"
|
||||||
|
#define BLOCK_SIZE (2 * sizeof(data_l))
|
||||||
|
|
||||||
|
int rx_block_read_slab(struct device *dev_i2s, int att,
|
||||||
|
struct k_mem_slab *slab);
|
||||||
|
int tx_block_write_slab(struct device *dev_i2s, int att, int err,
|
||||||
|
struct k_mem_slab *slab);
|
||||||
|
|
||||||
|
void fill_buf_const(s16_t *tx_block, s16_t val_l, s16_t val_r);
|
||||||
|
int verify_buf_const(s16_t *rx_block, s16_t val_l, s16_t val_r);
|
||||||
|
|
||||||
|
#endif
|
|
@ -14,27 +14,22 @@
|
||||||
|
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
|
#include <device.h>
|
||||||
void test_i2s_tx_transfer_configure_0(void);
|
#include "i2s_api_test.h"
|
||||||
void test_i2s_rx_transfer_configure_0(void);
|
|
||||||
void test_i2s_transfer_short(void);
|
|
||||||
void test_i2s_transfer_long(void);
|
|
||||||
void test_i2s_rx_sync_start(void);
|
|
||||||
void test_i2s_rx_empty_timeout(void);
|
|
||||||
void test_i2s_transfer_restart(void);
|
|
||||||
void test_i2s_transfer_rx_overrun(void);
|
|
||||||
void test_i2s_transfer_tx_underrun(void);
|
|
||||||
|
|
||||||
void test_i2s_tx_transfer_configure_1(void);
|
|
||||||
void test_i2s_rx_transfer_configure_1(void);
|
|
||||||
void test_i2s_state_not_ready_neg(void);
|
|
||||||
void test_i2s_state_ready_neg(void);
|
|
||||||
void test_i2s_state_running_neg(void);
|
|
||||||
void test_i2s_state_stopping_neg(void);
|
|
||||||
void test_i2s_state_error_neg(void);
|
|
||||||
|
|
||||||
void test_main(void)
|
void test_main(void)
|
||||||
{
|
{
|
||||||
|
struct device *dev_i2s;
|
||||||
|
|
||||||
|
k_thread_access_grant(k_current_get(),
|
||||||
|
&rx_0_mem_slab, &tx_0_mem_slab,
|
||||||
|
&rx_1_mem_slab, &tx_1_mem_slab,
|
||||||
|
NULL);
|
||||||
|
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
||||||
|
if (dev_i2s != NULL) {
|
||||||
|
k_object_access_grant(dev_i2s, k_current_get());
|
||||||
|
}
|
||||||
|
|
||||||
ztest_test_suite(i2s_loopback_test,
|
ztest_test_suite(i2s_loopback_test,
|
||||||
ztest_unit_test(test_i2s_tx_transfer_configure_0),
|
ztest_unit_test(test_i2s_tx_transfer_configure_0),
|
||||||
ztest_unit_test(test_i2s_rx_transfer_configure_0),
|
ztest_unit_test(test_i2s_rx_transfer_configure_0),
|
||||||
|
@ -56,4 +51,27 @@ void test_main(void)
|
||||||
ztest_unit_test(test_i2s_state_stopping_neg),
|
ztest_unit_test(test_i2s_state_stopping_neg),
|
||||||
ztest_unit_test(test_i2s_state_error_neg));
|
ztest_unit_test(test_i2s_state_error_neg));
|
||||||
ztest_run_test_suite(i2s_states_test);
|
ztest_run_test_suite(i2s_states_test);
|
||||||
|
|
||||||
|
/* Now run all tests in user mode */
|
||||||
|
ztest_test_suite(i2s_user_loopback_test,
|
||||||
|
ztest_user_unit_test(test_i2s_tx_transfer_configure_0),
|
||||||
|
ztest_user_unit_test(test_i2s_rx_transfer_configure_0),
|
||||||
|
ztest_user_unit_test(test_i2s_transfer_short),
|
||||||
|
ztest_user_unit_test(test_i2s_transfer_long),
|
||||||
|
ztest_user_unit_test(test_i2s_rx_sync_start),
|
||||||
|
ztest_user_unit_test(test_i2s_rx_empty_timeout),
|
||||||
|
ztest_user_unit_test(test_i2s_transfer_restart),
|
||||||
|
ztest_user_unit_test(test_i2s_transfer_tx_underrun),
|
||||||
|
ztest_user_unit_test(test_i2s_transfer_rx_overrun));
|
||||||
|
ztest_run_test_suite(i2s_user_loopback_test);
|
||||||
|
|
||||||
|
ztest_test_suite(i2s_user_states_test,
|
||||||
|
ztest_user_unit_test(test_i2s_tx_transfer_configure_1),
|
||||||
|
ztest_user_unit_test(test_i2s_rx_transfer_configure_1),
|
||||||
|
ztest_user_unit_test(test_i2s_state_not_ready_neg),
|
||||||
|
ztest_user_unit_test(test_i2s_state_ready_neg),
|
||||||
|
ztest_user_unit_test(test_i2s_state_running_neg),
|
||||||
|
ztest_user_unit_test(test_i2s_state_stopping_neg),
|
||||||
|
ztest_user_unit_test(test_i2s_state_error_neg));
|
||||||
|
ztest_run_test_suite(i2s_user_states_test);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,137 +15,22 @@
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
#include <i2s.h>
|
#include <i2s.h>
|
||||||
|
#include "i2s_api_test.h"
|
||||||
|
|
||||||
#define I2S_DEV_NAME "I2S_0"
|
|
||||||
#define NUM_RX_BLOCKS 2
|
#define NUM_RX_BLOCKS 2
|
||||||
#define NUM_TX_BLOCKS 2
|
#define NUM_TX_BLOCKS 2
|
||||||
#define SAMPLE_NO 32
|
|
||||||
|
|
||||||
/* The data_l represent a sine wave */
|
|
||||||
static s16_t data_l[SAMPLE_NO] = {
|
|
||||||
6392, 12539, 18204, 23169, 27244, 30272, 32137, 32767, 32137,
|
|
||||||
30272, 27244, 23169, 18204, 12539, 6392, 0, -6393, -12540,
|
|
||||||
-18205, -23170, -27245, -30273, -32138, -32767, -32138, -30273, -27245,
|
|
||||||
-23170, -18205, -12540, -6393, -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The data_r represent a sine wave with double the frequency of data_l */
|
|
||||||
static s16_t data_r[SAMPLE_NO] = {
|
|
||||||
12539, 23169, 30272, 32767, 30272, 23169, 12539, 0, -12540,
|
|
||||||
-23170, -30273, -32767, -30273, -23170, -12540, -1, 12539, 23169,
|
|
||||||
30272, 32767, 30272, 23169, 12539, 0, -12540, -23170, -30273,
|
|
||||||
-32767, -30273, -23170, -12540, -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define BLOCK_SIZE (2 * sizeof(data_l))
|
|
||||||
|
|
||||||
K_MEM_SLAB_DEFINE(rx_0_mem_slab, BLOCK_SIZE, NUM_RX_BLOCKS, 1);
|
K_MEM_SLAB_DEFINE(rx_0_mem_slab, BLOCK_SIZE, NUM_RX_BLOCKS, 1);
|
||||||
K_MEM_SLAB_DEFINE(tx_0_mem_slab, BLOCK_SIZE, NUM_TX_BLOCKS, 1);
|
K_MEM_SLAB_DEFINE(tx_0_mem_slab, BLOCK_SIZE, NUM_TX_BLOCKS, 1);
|
||||||
|
|
||||||
static void fill_buf(s16_t *tx_block, int att)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < SAMPLE_NO; i++) {
|
|
||||||
tx_block[2 * i] = data_l[i] >> att;
|
|
||||||
tx_block[2 * i + 1] = data_r[i] >> att;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int verify_buf(s16_t *rx_block, int att)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < SAMPLE_NO; i++) {
|
|
||||||
if (rx_block[2 * i] != data_l[i] >> att) {
|
|
||||||
TC_PRINT("Error: att %d: data_l mismatch at position "
|
|
||||||
"%d, expected %d, actual %d\n",
|
|
||||||
att, i, data_l[i] >> att, rx_block[2 * i]);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
if (rx_block[2 * i + 1] != data_r[i] >> att) {
|
|
||||||
TC_PRINT("Error: att %d: data_r mismatch at position "
|
|
||||||
"%d, expected %d, actual %d\n",
|
|
||||||
att, i, data_r[i] >> att, rx_block[2 * i + 1]);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fill_buf_const(s16_t *tx_block, s16_t val_l, s16_t val_r)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < SAMPLE_NO; i++) {
|
|
||||||
tx_block[2 * i] = val_l;
|
|
||||||
tx_block[2 * i + 1] = val_r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int verify_buf_const(s16_t *rx_block, s16_t val_l, s16_t val_r)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < SAMPLE_NO; i++) {
|
|
||||||
if (rx_block[2 * i] != val_l) {
|
|
||||||
TC_PRINT("Error: data_l mismatch at position "
|
|
||||||
"%d, expected %d, actual %d\n",
|
|
||||||
i, val_l, rx_block[2 * i]);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
if (rx_block[2 * i + 1] != val_r) {
|
|
||||||
TC_PRINT("Error: data_r mismatch at position "
|
|
||||||
"%d, expected %d, actual %d\n",
|
|
||||||
i, val_r, rx_block[2 * i + 1]);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tx_block_write(struct device *dev_i2s, int att, int err)
|
static int tx_block_write(struct device *dev_i2s, int att, int err)
|
||||||
{
|
{
|
||||||
void *tx_block;
|
return tx_block_write_slab(dev_i2s, att, err, &tx_0_mem_slab);
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = k_mem_slab_alloc(&tx_0_mem_slab, &tx_block, K_FOREVER);
|
|
||||||
if (ret < 0) {
|
|
||||||
TC_PRINT("Error: Failed to allocate tx_block\n");
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
fill_buf((u16_t *)tx_block, att);
|
|
||||||
ret = i2s_write(dev_i2s, tx_block, BLOCK_SIZE);
|
|
||||||
if (ret < 0) {
|
|
||||||
k_mem_slab_free(&tx_0_mem_slab, &tx_block);
|
|
||||||
}
|
|
||||||
if (ret != err) {
|
|
||||||
TC_PRINT("Error: i2s_write failed expected %d, actual %d\n",
|
|
||||||
err, ret);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rx_block_read(struct device *dev_i2s, int att)
|
static int rx_block_read(struct device *dev_i2s, int att)
|
||||||
{
|
{
|
||||||
void *rx_block;
|
return rx_block_read_slab(dev_i2s, att, &rx_0_mem_slab);
|
||||||
size_t rx_size;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
|
||||||
if (ret < 0 || rx_size != BLOCK_SIZE) {
|
|
||||||
TC_PRINT("Error: Read failed\n");
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
ret = verify_buf((u16_t *)rx_block, att);
|
|
||||||
if (ret < 0) {
|
|
||||||
TC_PRINT("Error: Verify failed\n");
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
k_mem_slab_free(&rx_0_mem_slab, &rx_block);
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TIMEOUT 2000
|
|
||||||
#define FRAME_CLK_FREQ 8000
|
|
||||||
|
|
||||||
/** Configure I2S TX transfer. */
|
/** Configure I2S TX transfer. */
|
||||||
void test_i2s_tx_transfer_configure_0(void)
|
void test_i2s_tx_transfer_configure_0(void)
|
||||||
{
|
{
|
||||||
|
@ -325,20 +210,17 @@ void test_i2s_transfer_long(void)
|
||||||
void test_i2s_rx_sync_start(void)
|
void test_i2s_rx_sync_start(void)
|
||||||
{
|
{
|
||||||
struct device *dev_i2s;
|
struct device *dev_i2s;
|
||||||
void *tx_block;
|
|
||||||
void *rx_block;
|
|
||||||
size_t rx_size;
|
size_t rx_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
char buf[BLOCK_SIZE];
|
||||||
|
|
||||||
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
||||||
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
||||||
|
|
||||||
/* Prefill TX queue */
|
/* Prefill TX queue */
|
||||||
for (int n = 0; n < NUM_TX_BLOCKS; n++) {
|
for (int n = 0; n < NUM_TX_BLOCKS; n++) {
|
||||||
ret = k_mem_slab_alloc(&tx_0_mem_slab, &tx_block, K_FOREVER);
|
fill_buf_const((u16_t *)buf, 1, 2);
|
||||||
zassert_equal(ret, TC_PASS, NULL);
|
ret = i2s_buf_write(dev_i2s, buf, BLOCK_SIZE);
|
||||||
fill_buf_const((u16_t *)tx_block, 1, 2);
|
|
||||||
ret = i2s_write(dev_i2s, tx_block, BLOCK_SIZE);
|
|
||||||
zassert_equal(ret, TC_PASS, NULL);
|
zassert_equal(ret, TC_PASS, NULL);
|
||||||
TC_PRINT("%d->OK\n", n);
|
TC_PRINT("%d->OK\n", n);
|
||||||
}
|
}
|
||||||
|
@ -352,11 +234,10 @@ void test_i2s_rx_sync_start(void)
|
||||||
/* Start reception */
|
/* Start reception */
|
||||||
ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_START);
|
ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_START);
|
||||||
zassert_equal(ret, 0, "RX START trigger failed");
|
zassert_equal(ret, 0, "RX START trigger failed");
|
||||||
|
ret = i2s_buf_read(dev_i2s, buf, &rx_size);
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
|
||||||
zassert_equal(ret, TC_PASS, NULL);
|
zassert_equal(ret, TC_PASS, NULL);
|
||||||
ret = verify_buf_const((u16_t *)rx_block, 1, 2);
|
ret = verify_buf_const((u16_t *)buf, 1, 2);
|
||||||
k_mem_slab_free(&rx_0_mem_slab, &rx_block);
|
|
||||||
zassert_equal(ret, TC_PASS, NULL);
|
zassert_equal(ret, TC_PASS, NULL);
|
||||||
TC_PRINT("%d<-OK\n", 1);
|
TC_PRINT("%d<-OK\n", 1);
|
||||||
|
|
||||||
|
@ -379,14 +260,14 @@ void test_i2s_rx_sync_start(void)
|
||||||
void test_i2s_rx_empty_timeout(void)
|
void test_i2s_rx_empty_timeout(void)
|
||||||
{
|
{
|
||||||
struct device *dev_i2s;
|
struct device *dev_i2s;
|
||||||
void *rx_block;
|
|
||||||
size_t rx_size;
|
size_t rx_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
char buf[BLOCK_SIZE];
|
||||||
|
|
||||||
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
||||||
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
||||||
|
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
ret = i2s_buf_read(dev_i2s, buf, &rx_size);
|
||||||
zassert_equal(ret, -EAGAIN, "i2s_read did not timed out");
|
zassert_equal(ret, -EAGAIN, "i2s_read did not timed out");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,9 +367,9 @@ void test_i2s_transfer_restart(void)
|
||||||
void test_i2s_transfer_rx_overrun(void)
|
void test_i2s_transfer_rx_overrun(void)
|
||||||
{
|
{
|
||||||
struct device *dev_i2s;
|
struct device *dev_i2s;
|
||||||
void *rx_block;
|
|
||||||
size_t rx_size;
|
size_t rx_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
char rx_buf[BLOCK_SIZE];
|
||||||
|
|
||||||
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
||||||
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
||||||
|
@ -524,7 +405,8 @@ void test_i2s_transfer_rx_overrun(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attempt to read one more data block, expect an error */
|
/* Attempt to read one more data block, expect an error */
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
ret = i2s_buf_read(dev_i2s, rx_buf, &rx_size);
|
||||||
|
|
||||||
zassert_equal(ret, -EIO, "RX overrun error not detected");
|
zassert_equal(ret, -EIO, "RX overrun error not detected");
|
||||||
|
|
||||||
ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_PREPARE);
|
ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_PREPARE);
|
||||||
|
@ -590,6 +472,8 @@ void test_i2s_transfer_tx_underrun(void)
|
||||||
ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_PREPARE);
|
ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_PREPARE);
|
||||||
zassert_equal(ret, 0, "TX PREPARE trigger failed");
|
zassert_equal(ret, 0, "TX PREPARE trigger failed");
|
||||||
|
|
||||||
|
k_sleep(200);
|
||||||
|
|
||||||
/* Transmit and receive two more data blocks */
|
/* Transmit and receive two more data blocks */
|
||||||
ret = tx_block_write(dev_i2s, 1, 0);
|
ret = tx_block_write(dev_i2s, 1, 0);
|
||||||
zassert_equal(ret, TC_PASS, NULL);
|
zassert_equal(ret, TC_PASS, NULL);
|
||||||
|
|
|
@ -16,109 +16,23 @@
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <ztest.h>
|
#include <ztest.h>
|
||||||
#include <i2s.h>
|
#include <i2s.h>
|
||||||
|
#include "i2s_api_test.h"
|
||||||
|
|
||||||
#define I2S_DEV_NAME "I2S_0"
|
|
||||||
#define NUM_RX_BLOCKS 4
|
#define NUM_RX_BLOCKS 4
|
||||||
#define NUM_TX_BLOCKS 4
|
#define NUM_TX_BLOCKS 4
|
||||||
#define SAMPLE_NO 32
|
|
||||||
|
|
||||||
/* The data_l represent a sine wave */
|
|
||||||
static s16_t data_l[SAMPLE_NO] = {
|
|
||||||
6392, 12539, 18204, 23169, 27244, 30272, 32137, 32767, 32137,
|
|
||||||
30272, 27244, 23169, 18204, 12539, 6392, 0, -6393, -12540,
|
|
||||||
-18205, -23170, -27245, -30273, -32138, -32767, -32138, -30273, -27245,
|
|
||||||
-23170, -18205, -12540, -6393, -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The data_r represent a sine wave with double the frequency of data_l */
|
|
||||||
static s16_t data_r[SAMPLE_NO] = {
|
|
||||||
12539, 23169, 30272, 32767, 30272, 23169, 12539, 0, -12540,
|
|
||||||
-23170, -30273, -32767, -30273, -23170, -12540, -1, 12539, 23169,
|
|
||||||
30272, 32767, 30272, 23169, 12539, 0, -12540, -23170, -30273,
|
|
||||||
-32767, -30273, -23170, -12540, -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define BLOCK_SIZE (2 * sizeof(data_l))
|
|
||||||
|
|
||||||
K_MEM_SLAB_DEFINE(rx_1_mem_slab, BLOCK_SIZE, NUM_RX_BLOCKS, 1);
|
K_MEM_SLAB_DEFINE(rx_1_mem_slab, BLOCK_SIZE, NUM_RX_BLOCKS, 1);
|
||||||
K_MEM_SLAB_DEFINE(tx_1_mem_slab, BLOCK_SIZE, NUM_TX_BLOCKS, 1);
|
K_MEM_SLAB_DEFINE(tx_1_mem_slab, BLOCK_SIZE, NUM_TX_BLOCKS, 1);
|
||||||
|
|
||||||
static void fill_buf(s16_t *tx_block, int att)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < SAMPLE_NO; i++) {
|
|
||||||
tx_block[2 * i] = data_l[i] >> att;
|
|
||||||
tx_block[2 * i + 1] = data_r[i] >> att;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int verify_buf(s16_t *rx_block, int att)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < SAMPLE_NO; i++) {
|
|
||||||
if (rx_block[2 * i] != data_l[i] >> att) {
|
|
||||||
TC_PRINT("Error: att %d: data_l mismatch at position "
|
|
||||||
"%d, expected %d, actual %d\n",
|
|
||||||
att, i, data_l[i] >> att, rx_block[2 * i]);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
if (rx_block[2 * i + 1] != data_r[i] >> att) {
|
|
||||||
TC_PRINT("Error: att %d: data_r mismatch at position "
|
|
||||||
"%d, expected %d, actual %d\n",
|
|
||||||
att, i, data_r[i] >> att, rx_block[2 * i + 1]);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tx_block_write(struct device *dev_i2s, int att, int err)
|
static int tx_block_write(struct device *dev_i2s, int att, int err)
|
||||||
{
|
{
|
||||||
void *tx_block;
|
return tx_block_write_slab(dev_i2s, att, err, &tx_1_mem_slab);
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = k_mem_slab_alloc(&tx_1_mem_slab, &tx_block, K_FOREVER);
|
|
||||||
if (ret < 0) {
|
|
||||||
TC_PRINT("Error: Failed to allocate tx_block\n");
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
fill_buf((u16_t *)tx_block, att);
|
|
||||||
ret = i2s_write(dev_i2s, tx_block, BLOCK_SIZE);
|
|
||||||
if (ret < 0) {
|
|
||||||
k_mem_slab_free(&tx_1_mem_slab, &tx_block);
|
|
||||||
}
|
|
||||||
if (ret != err) {
|
|
||||||
TC_PRINT("Error: i2s_write failed expected %d, actual %d\n",
|
|
||||||
err, ret);
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rx_block_read(struct device *dev_i2s, int att)
|
static int rx_block_read(struct device *dev_i2s, int att)
|
||||||
{
|
{
|
||||||
void *rx_block;
|
return rx_block_read_slab(dev_i2s, att, &rx_1_mem_slab);
|
||||||
size_t rx_size;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
|
||||||
if (ret < 0 || rx_size != BLOCK_SIZE) {
|
|
||||||
TC_PRINT("Error: Read failed\n");
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
ret = verify_buf((u16_t *)rx_block, att);
|
|
||||||
if (ret < 0) {
|
|
||||||
TC_PRINT("Error: Verify failed\n");
|
|
||||||
return -TC_FAIL;
|
|
||||||
}
|
|
||||||
k_mem_slab_free(&rx_1_mem_slab, &rx_block);
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TIMEOUT 2000
|
|
||||||
#define FRAME_CLK_FREQ 8000
|
|
||||||
|
|
||||||
/** Configure I2S TX transfer. */
|
/** Configure I2S TX transfer. */
|
||||||
void test_i2s_tx_transfer_configure_1(void)
|
void test_i2s_tx_transfer_configure_1(void)
|
||||||
{
|
{
|
||||||
|
@ -182,14 +96,15 @@ void test_i2s_state_not_ready_neg(void)
|
||||||
{
|
{
|
||||||
struct device *dev_i2s;
|
struct device *dev_i2s;
|
||||||
struct i2s_config i2s_cfg;
|
struct i2s_config i2s_cfg;
|
||||||
void *rx_block;
|
|
||||||
size_t rx_size;
|
size_t rx_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
char rx_buf[BLOCK_SIZE];
|
||||||
|
|
||||||
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
||||||
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
||||||
|
|
||||||
i2s_cfg.frame_clk_freq = 0;
|
i2s_cfg.frame_clk_freq = 0;
|
||||||
|
i2s_cfg.mem_slab = &rx_1_mem_slab;
|
||||||
|
|
||||||
ret = i2s_configure(dev_i2s, I2S_DIR_RX, &i2s_cfg);
|
ret = i2s_configure(dev_i2s, I2S_DIR_RX, &i2s_cfg);
|
||||||
zassert_equal(ret, 0, "Failed to configure I2S RX stream");
|
zassert_equal(ret, 0, "Failed to configure I2S RX stream");
|
||||||
|
@ -209,10 +124,11 @@ void test_i2s_state_not_ready_neg(void)
|
||||||
ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_PREPARE);
|
ret = i2s_trigger(dev_i2s, I2S_DIR_RX, I2S_TRIGGER_PREPARE);
|
||||||
zassert_equal(ret, -EIO, NULL);
|
zassert_equal(ret, -EIO, NULL);
|
||||||
|
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
ret = i2s_buf_read(dev_i2s, rx_buf, &rx_size);
|
||||||
zassert_equal(ret, -EIO, NULL);
|
zassert_equal(ret, -EIO, NULL);
|
||||||
|
|
||||||
i2s_cfg.frame_clk_freq = 0;
|
i2s_cfg.frame_clk_freq = 0;
|
||||||
|
i2s_cfg.mem_slab = &tx_1_mem_slab;
|
||||||
|
|
||||||
ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
|
ret = i2s_configure(dev_i2s, I2S_DIR_TX, &i2s_cfg);
|
||||||
zassert_equal(ret, 0, "Failed to configure I2S TX stream");
|
zassert_equal(ret, 0, "Failed to configure I2S TX stream");
|
||||||
|
@ -422,9 +338,9 @@ void test_i2s_state_stopping_neg(void)
|
||||||
void test_i2s_state_error_neg(void)
|
void test_i2s_state_error_neg(void)
|
||||||
{
|
{
|
||||||
struct device *dev_i2s;
|
struct device *dev_i2s;
|
||||||
void *rx_block;
|
|
||||||
size_t rx_size;
|
size_t rx_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
char rx_buf[BLOCK_SIZE];
|
||||||
|
|
||||||
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
dev_i2s = device_get_binding(I2S_DEV_NAME);
|
||||||
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
zassert_not_null(dev_i2s, "device " I2S_DEV_NAME " not found");
|
||||||
|
@ -456,7 +372,7 @@ void test_i2s_state_error_neg(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attempt to read one more data block, expect an error */
|
/* Attempt to read one more data block, expect an error */
|
||||||
ret = i2s_read(dev_i2s, &rx_block, &rx_size);
|
ret = i2s_buf_read(dev_i2s, rx_buf, &rx_size);
|
||||||
zassert_equal(ret, -EIO, "RX overrun error not detected");
|
zassert_equal(ret, -EIO, "RX overrun error not detected");
|
||||||
|
|
||||||
/* Send invalid triggers, expect failure */
|
/* Send invalid triggers, expect failure */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue