Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed syslink unhandled overrun bug #121

Merged
merged 1 commit into from
Jun 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/drivers/src/uart_syslink.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* uart_syslink.c - Uart syslink to nRF51 and raw access functions
*/
#include <stdint.h>
#include <string.h>

/*ST includes */
Expand Down Expand Up @@ -308,9 +309,17 @@ void uartslkDmaIsr(void)
void uartslkIsr(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
uint8_t rxDataInterrupt;

if (USART_GetITStatus(UARTSLK_TYPE, USART_IT_TXE))
// the following if statement replaces:
// if (USART_GetITStatus(UARTSLK_TYPE, USART_IT_RXNE) == SET)
// we do this check as fast as possible to minimize the chance of an overrun,
// which occasionally cause problems and cause packet loss at high CPU usage
if ((UARTSLK_TYPE->SR & (1<<5)) != 0) // if the RXNE interrupt has occurred
{
uint8_t rxDataInterrupt = (uint8_t)(UARTSLK_TYPE->DR & 0xFF);
xQueueSendFromISR(uartslkDataDelivery, &rxDataInterrupt, &xHigherPriorityTaskWoken);
}
else if (USART_GetITStatus(UARTSLK_TYPE, USART_IT_TXE) == SET)
{
if (outDataIsr && (dataIndexIsr < dataSizeIsr))
{
Expand All @@ -324,11 +333,15 @@ void uartslkIsr(void)
xSemaphoreGiveFromISR(waitUntilSendDone, &xHigherPriorityTaskWoken);
}
}
USART_ClearITPendingBit(UARTSLK_TYPE, USART_IT_TXE);
if (USART_GetITStatus(UARTSLK_TYPE, USART_IT_RXNE))
else
{
rxDataInterrupt = USART_ReceiveData(UARTSLK_TYPE) & 0x00FF;
xQueueSendFromISR(uartslkDataDelivery, &rxDataInterrupt, &xHigherPriorityTaskWoken);
/** if we get here, the error is most likely caused by an overrun!
* - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun error)
* - and IDLE (Idle line detected) pending bits are cleared by software sequence:
* - reading USART_SR register followed reading the USART_DR register.
*/
asm volatile ("" : "=m" (UARTSLK_TYPE->SR) : "r" (UARTSLK_TYPE->SR)); // force non-optimizable reads
asm volatile ("" : "=m" (UARTSLK_TYPE->DR) : "r" (UARTSLK_TYPE->DR)); // of these two registers
}
}

Expand Down