新手入门
- 积分
- 16
- 金钱
- 16
- 注册时间
- 2020-11-3
- 在线时间
- 3 小时
|
1金钱
dma的配置(是内存到I2S数据寄存器的方式)
hdma_spi3_tx.Instance = DMA1_Stream5;
hdma_spi3_tx.Init.Channel = DMA_CHANNEL_0;
hdma_spi3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_spi3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi3_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_spi3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_spi3_tx.Init.Mode = DMA_CIRCULAR;
hdma_spi3_tx.Init.Priority = DMA_PRIORITY_LOW;
hdma_spi3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_spi3_tx.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_spi3_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
中断处理函数内容:
void DMA1_Stream5_IRQHandler(void)
{
rollback();
UBaseType_t uxSavedInterruptStatus;
static uint32_t count = 2;
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
uxSavedInterruptStatus = pdFALSE;
xSemaphoreTakeFromISR(isrSwitchTaskSem,&xHigherPriorityTaskWoken);
if(__HAL_DMA_GET_FLAG(&hdma_spi3_tx,DMA_FLAG_TCIF1_5)!=RESET) //DMA传输完成
{
__HAL_DMA_CLEAR_FLAG(&hdma_spi3_tx,DMA_FLAG_TCIF1_5); //清除DMA传输完成中断标志位
if(DMA1_Stream5->CR&(1<<19)) //填数据buf1
{
printf("2\r\n");
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
if(count%3 == 0)
{
//wav_pack1_buf = recvpack2;
for(int i = 0 ; i<(WAV_BUF_SIZE/2) ;i++)
{
wav_pack1_buf[i] = audio1khz[i];
}
count++;
}
else if(count%3 == 1)
{
//wav_pack1_buf = recvpack3;
for(int i = 0 ; i<(WAV_BUF_SIZE/2) ;i++)
{
wav_pack1_buf[i] = audio1khz[i];
}
count++;
}
else if(count%3 == 2)
{
//wav_pack1_buf = recvpack4;
for(int i = 0 ; i<(WAV_BUF_SIZE/2) ;i++)
{
wav_pack1_buf[i] =audio1khz[i];
}
count++;
}
taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
}
else //buf2
{
printf("3\r\n");
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
if(count%3 == 0)
{
//wav_pack2_buf = recvpack2;
for(int i = 0 ; i<(WAV_BUF_SIZE/2) ;i++)
{
wav_pack2_buf[i] = audio1khz[i];
}
count++;
}
else if(count%3 == 1)
{
//wav_pack2_buf = recvpack3;
for(int i = 0 ; i<(WAV_BUF_SIZE/2) ;i++)
{
wav_pack2_buf[i] = audio1khz[i];
}
count++;
}
else if(count%3 == 2)
{
//wav_pack2_buf = recvpack4;
for(int i = 0 ; i<(WAV_BUF_SIZE/2) ;i++)
{
wav_pack2_buf[i] = audio1khz[i];
}
count++;
}
taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
}
//-----------------------------------------------
//taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
|
|