在LM3S9B96的驱动函数库文件sound.c中,中断处理函数:
void
SoundIntHandler(void)
{
unsigned long ulStatus;
unsigned long *pulTemp;
//
// Get the interrupt status and clear any pending interrupts.
//
ulStatus = ROM_I2SIntStatus(I2S0_BASE, 1);
//
// Clear out any interrupts.
//
ROM_I2SIntClear(I2S0_BASE, ulStatus);
//
// Handle the RX channel interrupt
//
if(HWREGBITW(&g_ulDMAFlags, FLAG_RX_PENDING))
{
//
// If the RX DMA is done, then start another one using the same
// RX buffer. This keeps the RX running continuously.
//
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0RX | UDMA_PRI_SELECT) ==
UDMA_MODE_STOP)
{
//
// Save a temp pointer so that the current pointer can be set to
// zero before calling the callback.
//
pulTemp = g_sInBuffers[0].pulData;
//
// If at the mid point the refill the first half of the buffer.
//
if(g_sInBuffers[0].pfnBufferCallback)
{
g_sInBuffers[0].pulData = 0;
g_sInBuffers[0].pfnBufferCallback(pulTemp, BUFFER_EVENT_FULL);
}
}
else if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0RX | UDMA_ALT_SELECT) ==
UDMA_MODE_STOP)
{
//
// Save a temp pointer so that the current pointer can be set to
// zero before calling the callback.
//
pulTemp = g_sInBuffers[1].pulData;
//
// If at the mid point the refill the first half of the buffer.
//
if(g_sInBuffers[1].pfnBufferCallback)
{
g_sInBuffers[1].pulData = 0;
g_sInBuffers[1].pfnBufferCallback(pulTemp, BUFFER_EVENT_FULL);
}
}
//
// If there are no more scheduled buffers then there are no more
// pending DMA transfers.
//
if((g_sInBuffers[0].pulData == 0) && (g_sInBuffers[1].pulData == 0))
{
HWREGBITW(&g_ulDMAFlags, FLAG_RX_PENDING) = 0;
}
}
//
// Handle the TX channel interrupt
//
if(HWREGBITW(&g_ulDMAFlags, FLAG_TX_PENDING))
{
//
// If the TX DMA is done, then call the callback if present.
//
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0TX | UDMA_PRI_SELECT) ==
UDMA_MODE_STOP)
{
//
// Save a temp pointer so that the current pointer can be set to
// zero before calling the callback.
//
pulTemp = g_sOutBuffers[0].pulData;
//
// If at the mid point then refill the first half of the buffer.
//
if((g_sOutBuffers[0].pfnBufferCallback) &&
(g_sOutBuffers[0].pulData != 0))
{
g_sOutBuffers[0].pulData = 0;
g_sOutBuffers[0].pfnBufferCallback(pulTemp, BUFFER_EVENT_FREE);
}
}
//
// If the TX DMA is done, then call the callback if present.
//
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0TX | UDMA_ALT_SELECT) ==
UDMA_MODE_STOP)
{
//
// Save a temporary pointer so that the current pointer can be set
// to zero before calling the callback.
//
pulTemp = g_sOutBuffers[1].pulData;
//
// If at the mid point then refill the first half of the buffer.
//
if((g_sOutBuffers[1].pfnBufferCallback) &&
(g_sOutBuffers[1].pulData != 0))
{
g_sOutBuffers[1].pulData = 0;
g_sOutBuffers[1].pfnBufferCallback(pulTemp, BUFFER_EVENT_FREE);
}
}
//
// If no more buffers are pending then clear the flag.
//
if((g_sOutBuffers[0].pulData == 0) && (g_sOutBuffers[1].pulData == 0))
{
HWREGBITW(&g_ulDMAFlags, FLAG_TX_PENDING) = 0;
}
}
}
在系统启动后,只启动录音时,中断服务程序只执行
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0RX | UDMA_PRI_SELECT) ==
UDMA_MODE_STOP) {... ......}
中的内容,而在启动语音播放后,录音部分的
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0RX | UDMA_PRI_SELECT) ==
UDMA_MODE_STOP){ .... }
和else if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0RX | UDMA_ALT_SELECT) ==
UDMA_MODE_STOP){ .... }才会交替被执行,这事问什么?
另外为什么录音的2个中断处理的if语句之间使用else语句,而播放的
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0TX | UDMA_PRI_SELECT) ==
UDMA_MODE_STOP) { ... }
和
if(ROM_uDMAChannelModeGet(UDMA_CHANNEL_I2S0TX | UDMA_ALT_SELECT) ==
UDMA_MODE_STOP) { ... }之间不需要使用else语句?