diff --git a/support/platform/src/i2s_core.c b/support/platform/src/i2s_core.c index 3a67600231235a5523e9d2ae84a16866eb4b874e..f4e5fddb74ca92bf4168b95e58bea25e570d1788 100644 --- a/support/platform/src/i2s_core.c +++ b/support/platform/src/i2s_core.c @@ -9,7 +9,6 @@ #include "i2s_core.h" #include "hdf_log.h" #include "osal_mem.h" -#include "i2s_if.h" #define HDF_LOG_TAG i2s_core diff --git a/test/unittest/platform/common/i2s_test.c b/test/unittest/platform/common/i2s_test.c index 09935381d57968a30665cc3a7859f0f8e8737e75..0dcf7ba62a21134a5ca564b8dce78a7aae2115a4 100644 --- a/test/unittest/platform/common/i2s_test.c +++ b/test/unittest/platform/common/i2s_test.c @@ -11,11 +11,11 @@ #include "device_resource_if.h" #include "hdf_base.h" #include "hdf_log.h" -#include "osal_mem.h" -#include "osal_time.h" +#include "i2s_if.h" #include "osal_file.h" +#include "osal_mem.h" #include "osal_test_type.h" -#include "i2s_if.h" +#include "osal_time.h" #define HDF_LOG_TAG i2s_test_c @@ -35,10 +35,10 @@ static int32_t I2sSetCfgTest(struct I2sTest *test) return HDF_ERR_INVALID_OBJECT; } - HDF_LOGE("%s:sampleRate[%u], type[%u], channelMode[%u], samplePrecision[%u], \ - channelIfMode[%u], mclk[%u], bclk[%u], writeChannel[%u], i2slFsSel[%u]", __func__, - test->sampleRate, test->type, test->channelMode, test->samplePrecision, - test->channelIfMode, test->mclk, test->bclk, test->writeChannel, test->i2slFsSel); + HDF_LOGE("%s:sampleRate[%u], type[%u], channelMode[%u], samplePrecision[%u],\ + channelIfMode[%u], mclk[%u], bclk[%u], writeChannel[%u], i2slFsSel[%u]", __func__, + test->sampleRate, test->type, test->channelMode, test->samplePrecision, + test->channelIfMode, test->mclk, test->bclk, test->writeChannel, test->i2slFsSel); struct I2sCfg cfg; cfg.sampleRate = test->sampleRate; @@ -66,8 +66,8 @@ static int32_t I2sGetCfgTest(struct I2sTest *test) struct I2sCfg cfg; I2sGetCfg(test->handle, &cfg); - HDF_LOGE("%s:sampleRate[%u], type[%u], channelMode[%u], samplePrecision[%u], \ - channelIfMode[%u], mclk[%u], bclk[%u], writeChannel[%u], i2slFsSel[%u]", __func__, + HDF_LOGE("%s:sampleRate[%u], type[%u], channelMode[%u], samplePrecision[%u],\ + channelIfMode[%u], mclk[%u], bclk[%u], writeChannel[%u], i2slFsSel[%u]", __func__, test->sampleRate, test->type, test->channelMode, test->samplePrecision, test->channelIfMode, test->mclk, test->bclk, test->writeChannel, test->i2slFsSel); return HDF_SUCCESS; @@ -137,10 +137,6 @@ static int32_t I2sPlayTest(struct I2sTest *test) printf("[%s] read file size[%d]", __func__, size); if (size > 0) { totalLen += size; - printf("[%s] I2sPlayTest:len[0x%x] [0x%x] wbuf[0x%x][0x%x][0x%x] [0x%x][0x%x][0x%x]\n", __func__, - size, totalLen, test->wbuf[0], test->wbuf[1], test->wbuf[2], - test->wbuf[size - 3], test->wbuf[size - 2], test->wbuf[size - 1]); - uint32_t wlen = 0; int ret = I2sWrite(test->handle, test->wbuf, size, &wlen); if (ret != HDF_SUCCESS) { @@ -177,7 +173,7 @@ static int32_t I2sRecordTest(struct I2sTest *test) uint32_t totalLen = 0; while ((i <= READ_TEST_TIMES) && (totalLen <= READ_TEST_FILE_SIZE)) { test->len = I2S_DATA_BUF_SIZE; - memset_s( test->rbuf, I2S_DATA_BUF_SIZE, 0xee, I2S_DATA_BUF_SIZE); + memset_s(test->rbuf, I2S_DATA_BUF_SIZE, 0xee, I2S_DATA_BUF_SIZE); if (I2sRead(test->handle, test->rbuf, test->len, &test->len) != HDF_SUCCESS) { HDF_LOGE("%s: I2sRecordTest error \n", __func__); return HDF_FAILURE; @@ -213,7 +209,11 @@ static int32_t I2sReadTest(struct I2sTest *test) return HDF_FAILURE; } - memcpy_s(test->wbuf, test->len, test->rbuf, test->len); + if (memcpy_s(test->wbuf, test->len, test->rbuf, test->len) != EOK) { + HDF_LOGE("%s: memcpy buf failed", __func__); + return HDF_ERR_IO; + } + return HDF_SUCCESS; } @@ -360,9 +360,31 @@ static int32_t I2sTestBind(struct HdfDeviceObject *device) return HDF_SUCCESS; } -static int32_t I2sTestInitFromHcs(struct I2sTest *test, const struct DeviceResourceNode *node) +static int32_t I2sTestInitBuf(struct I2sTest *test) +{ + if (test == NULL) { + HDF_LOGE("%s: test is null", __func__); + return HDF_FAILURE; + } + + test->len = I2S_DATA_BUF_SIZE; + test->wbuf = (uint8_t *)OsalMemCalloc(test->len); + if (test->wbuf == NULL) { + HDF_LOGE("%s: wbuf OsalMemCalloc error\n", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + test->rbuf = (uint8_t *)OsalMemCalloc(test->len); + if (test->rbuf == NULL) { + HDF_LOGE("%s: rbuf OsalMemCalloc error\n", __func__); + OsalMemFree(test->wbuf); + return HDF_ERR_MALLOC_FAIL; + } + + return HDF_SUCCESS; +} +static int32_t I2sTestInitCodecFromHcs(struct I2sTest *test, const struct DeviceResourceNode *node) { - int32_t ret; struct DeviceResourceIface *face = NULL; face = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); @@ -370,11 +392,8 @@ static int32_t I2sTestInitFromHcs(struct I2sTest *test, const struct DeviceResou HDF_LOGE("%s: face is null", __func__); return HDF_FAILURE; } - if (face->GetUint32 == NULL || face->GetUint32Array == NULL) { - HDF_LOGE("%s: GetUint32 or GetUint32Array not support", __func__); - return HDF_ERR_NOT_SUPPORT; - } - ret = face->GetUint8(node, "writeChannel", &test->writeChannel, 0); + + int32_t ret = face->GetUint8(node, "writeChannel", &test->writeChannel, 0); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: read writeChannel fail", __func__); return HDF_FAILURE; @@ -384,24 +403,43 @@ static int32_t I2sTestInitFromHcs(struct I2sTest *test, const struct DeviceResou HDF_LOGE("%s: read i2slFsSel fail", __func__); return HDF_FAILURE; } - ret = face->GetUint8(node, "sampleRate", &test->sampleRate, 0); + + ret = face->GetUint8(node, "channelMode", &test->channelMode, 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read sampleRate fail", __func__); + HDF_LOGE("%s: read channelMode fail", __func__); return HDF_FAILURE; } - ret = face->GetUint8(node, "type", &test->type, 0); + ret = face->GetUint8(node, "channelIfMode", &test->channelIfMode, 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read type fail", __func__); + HDF_LOGE("%s: read channelIfMode fail", __func__); return HDF_FAILURE; } - ret = face->GetUint8(node, "channelMode", &test->channelMode, 0); + + return HDF_SUCCESS; +} + +static int32_t I2sTestInitFromHcs(struct I2sTest *test, const struct DeviceResourceNode *node) +{ + int32_t ret; + struct DeviceResourceIface *face = NULL; + + face = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (face == NULL) { + HDF_LOGE("%s: face is null", __func__); + return HDF_FAILURE; + } + if (face->GetUint32 == NULL || face->GetUint32Array == NULL) { + HDF_LOGE("%s: GetUint32 or GetUint32Array not support", __func__); + return HDF_ERR_NOT_SUPPORT; + } + ret = face->GetUint8(node, "sampleRate", &test->sampleRate, 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read channelMode fail", __func__); + HDF_LOGE("%s: read sampleRate fail", __func__); return HDF_FAILURE; } - ret = face->GetUint8(node, "channelIfMode", &test->channelIfMode, 0); + ret = face->GetUint8(node, "type", &test->type, 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read channelIfMode fail", __func__); + HDF_LOGE("%s: read type fail", __func__); return HDF_FAILURE; } ret = face->GetUint8(node, "samplePrecision", &test->samplePrecision, 0); @@ -420,18 +458,12 @@ static int32_t I2sTestInitFromHcs(struct I2sTest *test, const struct DeviceResou return HDF_FAILURE; } - test->len = I2S_DATA_BUF_SIZE; - test->wbuf = (uint8_t *)OsalMemCalloc(test->len); - if (test->wbuf == NULL) { - HDF_LOGE("%s: wbuf OsalMemCalloc error\n", __func__); - return HDF_ERR_MALLOC_FAIL; + if (I2sTestInitCodecFromHcs (test, node) != HDF_SUCCESS) { + return HDF_FAILURE; } - test->rbuf = (uint8_t *)OsalMemCalloc(test->len); - if (test->rbuf == NULL) { - HDF_LOGE("%s: rbuf OsalMemCalloc error\n", __func__); - OsalMemFree(test->wbuf); - return HDF_ERR_MALLOC_FAIL; + if (I2sTestInitBuf (test) != HDF_SUCCESS) { + return HDF_FAILURE; } return HDF_SUCCESS; }