2018-08-10 03:38:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <i2s.h>
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
int z_impl_i2s_buf_read(struct device *dev, void *buf, size_t *size)
|
2018-08-10 03:38:18 +08:00
|
|
|
{
|
|
|
|
void *mem_block;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2s_read((struct device *)dev, &mem_block, size);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
struct i2s_config *rx_cfg =
|
|
|
|
i2s_config_get((struct device *)dev, I2S_DIR_RX);
|
|
|
|
|
|
|
|
memcpy(buf, mem_block, *size);
|
2018-11-16 05:51:26 +08:00
|
|
|
k_mem_slab_free(rx_cfg->mem_slab, &mem_block);
|
2018-08-10 03:38:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
int z_impl_i2s_buf_write(struct device *dev, void *buf, size_t size)
|
2018-08-10 03:38:18 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct i2s_config *tx_cfg;
|
|
|
|
void *mem_block;
|
|
|
|
|
|
|
|
tx_cfg = i2s_config_get((struct device *)dev, I2S_DIR_TX);
|
|
|
|
if (!tx_cfg) {
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > tx_cfg->block_size) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = k_mem_slab_alloc(tx_cfg->mem_slab, &mem_block, K_FOREVER);
|
|
|
|
if (ret < 0) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(mem_block, (void *)buf, size);
|
|
|
|
|
2018-11-16 05:11:36 +08:00
|
|
|
ret = i2s_write((struct device *)dev, mem_block, size);
|
|
|
|
if (ret != 0) {
|
|
|
|
k_mem_slab_free(tx_cfg->mem_slab, &mem_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-08-10 03:38:18 +08:00
|
|
|
}
|