|
|
@ -13,7 +13,7 @@ |
|
|
|
* |
|
|
|
* FilePath: i2s_rx_example.c |
|
|
|
* Created Date: 2023-07-10 10:25:00 |
|
|
|
* Last Modified: 2024-03-22 14:51:22 |
|
|
|
* Last Modified: 2024-03-29 15:22:41 |
|
|
|
* Description: This file is for I2S RX example function implmentation. |
|
|
|
* |
|
|
|
* Modify History: |
|
|
@ -58,7 +58,8 @@ static FDdmaChanConfig rx_config = {0}; |
|
|
|
static FDdmaChanConfig tx_config = {0}; |
|
|
|
/* 音频文件存放地址 */ |
|
|
|
#define buffer_length 16384 |
|
|
|
static u32 rx_buf = 0xa0000000; |
|
|
|
static u32 rx_channel = 1; /* 接收通道为DDMA通道1 */ |
|
|
|
static u32 tx_channel = 0; /* 接收通道为DDMA通道0 */ |
|
|
|
static uint8_t Data_Buff[2][buffer_length]; |
|
|
|
volatile static uint8_t buff_using_num = 0; |
|
|
|
|
|
|
@ -68,8 +69,8 @@ FError FI2sDdmaDeviceTx(u32 chan_id, u32 work_mode, uintptr src, fsize_t total_b |
|
|
|
/************************** Function *****************************************/ |
|
|
|
static void FDdmaRxDMADone() |
|
|
|
{ |
|
|
|
FI2sDdmaDeviceRX(1, 0, (uintptr)Data_Buff[!buff_using_num], buffer_length, buffer_length); |
|
|
|
FI2sDdmaDeviceTx(0, 1, (uintptr)Data_Buff[buff_using_num], buffer_length, buffer_length); |
|
|
|
FI2sDdmaDeviceRX(rx_channel, AUDIO_PCM_STREAM_CAPTURE, (uintptr)Data_Buff[!buff_using_num], buffer_length, buffer_length); |
|
|
|
FI2sDdmaDeviceTx(tx_channel, AUDIO_PCM_STREAM_PLAYBACK, (uintptr)Data_Buff[buff_using_num], buffer_length, buffer_length); |
|
|
|
buff_using_num = !buff_using_num; |
|
|
|
return; |
|
|
|
} |
|
|
@ -213,7 +214,7 @@ FError FI2sDdmaDeviceTx(u32 chan_id, u32 work_mode, uintptr src, fsize_t total_b |
|
|
|
} |
|
|
|
|
|
|
|
tx_config.slave_id = 0U, |
|
|
|
tx_config.req_mode = 1; |
|
|
|
tx_config.req_mode = AUDIO_PCM_STREAM_PLAYBACK; |
|
|
|
tx_config.ddr_addr = (uintptr)src; |
|
|
|
tx_config.dev_addr = i2s_config.base_addr + FI2S_TXDMA ; |
|
|
|
tx_config.trans_len = total_bytes; |
|
|
@ -221,7 +222,7 @@ FError FI2sDdmaDeviceTx(u32 chan_id, u32 work_mode, uintptr src, fsize_t total_b |
|
|
|
tx_config.first_desc_addr = (uintptr)bdl_desc_list; |
|
|
|
tx_config.valid_desc_num = bdl_num; |
|
|
|
|
|
|
|
ret = FDdmaChanBdlConfigure(&ddmac, 0, &tx_config); |
|
|
|
ret = FDdmaChanBdlConfigure(&ddmac, tx_channel, &tx_config); |
|
|
|
if (ret != FI2S_SUCCESS) |
|
|
|
{ |
|
|
|
printf("DDMA BDL configure failer.\r\n"); |
|
|
@ -278,7 +279,7 @@ FError FI2sDdmaDeviceRX(u32 chan_id, u32 work_mode, uintptr src, fsize_t total_b |
|
|
|
} |
|
|
|
|
|
|
|
rx_config.slave_id = 0U, |
|
|
|
rx_config.req_mode = 0; |
|
|
|
rx_config.req_mode = AUDIO_PCM_STREAM_CAPTURE; |
|
|
|
rx_config.ddr_addr = (uintptr)src; |
|
|
|
rx_config.dev_addr = i2s_config.base_addr + FI2S_RXDMA ; |
|
|
|
rx_config.trans_len = total_bytes; |
|
|
@ -286,7 +287,7 @@ FError FI2sDdmaDeviceRX(u32 chan_id, u32 work_mode, uintptr src, fsize_t total_b |
|
|
|
rx_config.first_desc_addr = (uintptr)bdl_desc_list; |
|
|
|
rx_config.valid_desc_num = bdl_num; |
|
|
|
|
|
|
|
ret = FDdmaChanBdlConfigure(&ddmac, 1, &rx_config); |
|
|
|
ret = FDdmaChanBdlConfigure(&ddmac, rx_channel, &rx_config); |
|
|
|
|
|
|
|
if (ret != FI2S_SUCCESS) |
|
|
|
{ |
|
|
@ -301,10 +302,8 @@ FError FI2sDdmaPlayExample(void) |
|
|
|
{ |
|
|
|
FError ret = FES8336_SUCCESS; |
|
|
|
const u32 ddma_id = FDDMA2_I2S_ID; /* I2S所绑定的DDMA默认是DDMA-2 */ |
|
|
|
const u32 channel = 1; /* 接收通道为DDMA通道1 */ |
|
|
|
u32 total_byte = buffer_length; /* 接收音频的最大长度,超过此长度将覆盖原有音频,此值为自定义 */ |
|
|
|
u32 per_buffer_len = buffer_length; /* 每一个BDL描述符所负责的数据长度,请保持total_byte是per_buffer_len的倍数 */ |
|
|
|
u32 work_mode = AUDIO_PCM_STREAM_CAPTURE; /* capture mode */ |
|
|
|
u32 word_length = AUDIO_PCM_STREAM_WORD_LENGTH_16; /* 16-bits word length */ |
|
|
|
|
|
|
|
ret = FI2sRxEs8336Init(word_length); |
|
|
@ -327,17 +326,17 @@ FError FI2sDdmaPlayExample(void) |
|
|
|
printf("Init the I2S failed.\r\n"); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
ret = FI2sDdmaDeviceRX(1, 0, (uintptr)Data_Buff[0], total_byte, per_buffer_len); |
|
|
|
ret = FI2sDdmaDeviceTx(0, 1, (uintptr)Data_Buff[1], total_byte, per_buffer_len); |
|
|
|
ret = FI2sDdmaDeviceRX(rx_channel, AUDIO_PCM_STREAM_CAPTURE, (uintptr)Data_Buff[0], total_byte, per_buffer_len); |
|
|
|
ret = FI2sDdmaDeviceTx(tx_channel, AUDIO_PCM_STREAM_PLAYBACK, (uintptr)Data_Buff[1], total_byte, per_buffer_len); |
|
|
|
if (FI2S_SUCCESS != ret) |
|
|
|
{ |
|
|
|
printf("I2S trans failed.\r\n"); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
FDdmaSetupInterrupt(&ddmac); |
|
|
|
FDdmaRegisterChanEvtHandler(&ddmac, 1, FDDMA_CHAN_EVT_REQ_DONE, FDdmaRxDMADone, NULL); |
|
|
|
FDdmaChanActive(&ddmac, 1); |
|
|
|
FDdmaChanActive(&ddmac, 0); |
|
|
|
FDdmaRegisterChanEvtHandler(&ddmac, rx_channel, FDDMA_CHAN_EVT_REQ_DONE, FDdmaRxDMADone, NULL); |
|
|
|
FDdmaChanActive(&ddmac, rx_channel); |
|
|
|
FDdmaChanActive(&ddmac, tx_channel); |
|
|
|
FDdmaStart(&ddmac); |
|
|
|
return ret; |
|
|
|
} |
|
|
|