我只是回顾了这段代码,注意到在中断代码中有一个bug。您的用例导致这个bug出现。
错误是在FIFO中读取数据之前清除RX FIFO非空中断。在代码示例中,在中断被清除之后,FIFO被直接读取,我相信它足够快,不会导致中断重新触发。在您的情况下,在中断清除和实际读取之间插入代码,这会导致中断再次触发。因此,ISR再次进入,导致它从空FIFO中读出…
为了解决这个问题,在FIFO的读取下移动中断清除代码:
Read数据=UARTHYHW-gt;
*从终端获取字符*
RealthDATA=CysScBuUARTHEGET(UARTHYHW);
/*清除UART“RX FIFO不空中断”*/
UARTHY-HW-GT;InTyrx=UARTHY-HW-GT;
但是,对于这个代码,仍然存在一个问题,它引起了中断,因为一个不同的原因,我还没有调试过。因此,对于您的用例充分工作,你需要改变你的ISR看起来像:
空隙ISRUUART(无效)
{
*检查“RX FIFO不是空中断”*/
如果(UARTHI HW-GT;InthRx掩码和SCBIInrxRxMaskddNoToPosiTyjyMSK)!= 0)
{
Read数据=UARTHYHW-gt;
*从终端获取字符*
RealthDATA=CysScBuUARTHEGET(UARTHYHW);
/*清除UART“RX FIFO不空中断”*/
UARTHY-HW-GT;InTyrx=UARTHY-HW-GT;
/*更新DATAY接收标志*/
DATAY接收=1;
}
其他的
{
/*如果发生任何其他中断* *
//UARTHARE错误=1;
}
}
当我考虑中断是如何导致错误代码运行时,我会回过头来。我猜是下溢。
以上来自于百度翻译
以下为原文
I was just reviewing this code and noticed that there is a bug in the interrupt code. Your use case caused this bug to show up.
The bug is that the RX fifo not empty interrupt is cleared before data is read out of the FIFO. In the code example the FIFO was read directly after the interrupt was cleared which I believe was fast enough to not cause the interrupt to retrigger. In your case you inserted code between the interrupt clear and the actual read, which causes the interrupt to fire again. So the ISR gets entered again which causes it to read out of an empty fifo...
To fix the issue move the interrupt clear code below the read of the FIFO:
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
However with this code there is still an issue which causes the interrupt to fire for a different reason I haven't debugged yet. So for your use case to fully work you need to change your ISR to look like:
void ISR_UART(void)
{
/* Check for "RX fifo not empty interrupt" */
if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)
{
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
/* Update data_received flag */
data_received = 1;
}
else
{
/* Error if any other interrupt occurs */
//uart_error = 1;
}
}
I'll post back when I figure how which interrupt is causing the error code to run. My guess is that it is underflow.
我只是回顾了这段代码,注意到在中断代码中有一个bug。您的用例导致这个bug出现。
错误是在FIFO中读取数据之前清除RX FIFO非空中断。在代码示例中,在中断被清除之后,FIFO被直接读取,我相信它足够快,不会导致中断重新触发。在您的情况下,在中断清除和实际读取之间插入代码,这会导致中断再次触发。因此,ISR再次进入,导致它从空FIFO中读出…
为了解决这个问题,在FIFO的读取下移动中断清除代码:
Read数据=UARTHYHW-gt;
*从终端获取字符*
RealthDATA=CysScBuUARTHEGET(UARTHYHW);
/*清除UART“RX FIFO不空中断”*/
UARTHY-HW-GT;InTyrx=UARTHY-HW-GT;
但是,对于这个代码,仍然存在一个问题,它引起了中断,因为一个不同的原因,我还没有调试过。因此,对于您的用例充分工作,你需要改变你的ISR看起来像:
空隙ISRUUART(无效)
{
*检查“RX FIFO不是空中断”*/
如果(UARTHI HW-GT;InthRx掩码和SCBIInrxRxMaskddNoToPosiTyjyMSK)!= 0)
{
Read数据=UARTHYHW-gt;
*从终端获取字符*
RealthDATA=CysScBuUARTHEGET(UARTHYHW);
/*清除UART“RX FIFO不空中断”*/
UARTHY-HW-GT;InTyrx=UARTHY-HW-GT;
/*更新DATAY接收标志*/
DATAY接收=1;
}
其他的
{
/*如果发生任何其他中断* *
//UARTHARE错误=1;
}
}
当我考虑中断是如何导致错误代码运行时,我会回过头来。我猜是下溢。
以上来自于百度翻译
以下为原文
I was just reviewing this code and noticed that there is a bug in the interrupt code. Your use case caused this bug to show up.
The bug is that the RX fifo not empty interrupt is cleared before data is read out of the FIFO. In the code example the FIFO was read directly after the interrupt was cleared which I believe was fast enough to not cause the interrupt to retrigger. In your case you inserted code between the interrupt clear and the actual read, which causes the interrupt to fire again. So the ISR gets entered again which causes it to read out of an empty fifo...
To fix the issue move the interrupt clear code below the read of the FIFO:
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
However with this code there is still an issue which causes the interrupt to fire for a different reason I haven't debugged yet. So for your use case to fully work you need to change your ISR to look like:
void ISR_UART(void)
{
/* Check for "RX fifo not empty interrupt" */
if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)
{
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
/* Update data_received flag */
data_received = 1;
}
else
{
/* Error if any other interrupt occurs */
//uart_error = 1;
}
}
I'll post back when I figure how which interrupt is causing the error code to run. My guess is that it is underflow.
举报