程序目的是将输入的音频数据从rx buf取出,做一定处理后,放到tx buf播放
使能收发的DMA中断后,不会进入中断dma_irq_handler,初始化代码如下
dma_chain_config_t tx_dma_list_config[2];
dma_chain_config_t rx_dma_list_config[2];
signed short AUDIO_TX_DMA_BUFF[2][AUDIO_BUFF_SIZE] __attribute__((aligned(4)));
signed short AUDIO_RX_DMA_BUFF[2][AUDIO_BUFF_SIZE] __attribute__((aligned(4)));
_attribute_ram_code_sec_ void dma_irq_handler(void)
{
COMM_DEBUG_D("\n");
}
PLIC_ISR_REGISTER(dma_irq_handler, IRQ_DMA)
static void s_audio_init(void)
{
core_interrupt_enable();
plic_interrupt_enable(IRQ_DMA);
dma_set_irq_mask(TX_DMA_CHN, TC_MASK);
dma_set_irq_mask(RX_DMA_CHN, TC_MASK);
audio_init(LINE_IN_TO_BUF_TO_LINE_OUT, AUDIO_16K, STEREO_BIT_16);
audio_rx_dma_config(RX_DMA_CHN, (unsigned short *)(&AUDIO_RX_DMA_BUFF[0]), AUDIO_BUFF_SIZE, &rx_dma_list_config[0]);
audio_rx_dma_add_list_element(&rx_dma_list_config[0], &rx_dma_list_config[1],
(unsigned short *)(&AUDIO_RX_DMA_BUFF[0]), AUDIO_BUFF_SIZE);
audio_rx_dma_add_list_element(&rx_dma_list_config[1], &rx_dma_list_config[0],
(unsigned short *)(&AUDIO_RX_DMA_BUFF[1]), AUDIO_BUFF_SIZE);
audio_tx_dma_config(TX_DMA_CHN, (unsigned short *)(&AUDIO_TX_DMA_BUFF[0]), AUDIO_BUFF_SIZE, &tx_dma_list_config[0]);
audio_tx_dma_add_list_element(&tx_dma_list_config[0], &tx_dma_list_config[1],
(unsigned short *)(&AUDIO_TX_DMA_BUFF[0]), AUDIO_BUFF_SIZE);
audio_tx_dma_add_list_element(&tx_dma_list_config[1], &tx_dma_list_config[0],
(unsigned short *)(&AUDIO_TX_DMA_BUFF[1]), AUDIO_BUFF_SIZE);
audio_rx_dma_en();
audio_tx_dma_en();
// plic_set_pending(IRQ_DMA); // 手动触发是可以进入中断的
}
只能轮询对数据做处理,怎样才能在每个fifo的数据满的时候产生中断
_attribute_ram_code_sec_ void audio_data_fifo(void)
{
unsigned int rx_wptr = audio_get_rx_dma_wptr(RX_DMA_CHN);
if (rx_wptr == (unsigned int)(&AUDIO_RX_DMA_BUFF[0][0])) {
memcpy(&AUDIO_TX_DMA_BUFF[1][0], &AUDIO_RX_DMA_BUFF[1][0], AUDIO_BUFF_SIZE);
} else if (rx_wptr == (unsigned int)(&AUDIO_RX_DMA_BUFF[1][0])) {
memcpy(&AUDIO_TX_DMA_BUFF[0][0], &AUDIO_RX_DMA_BUFF[0][0], AUDIO_BUFF_SIZE);
}
}
void bsp_audio_loop(void)
{
audio_data_fifo();
}
|