Skip to content

Fixed interrupt handler in serial_api.c for the Nordic NRF51. The last b... #1047

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

Merged
merged 1 commit into from
Apr 20, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
obj->uart->TXD = 0;

obj->index = 0;

obj->uart->PSELRTS = RTS_PIN_NUMBER;
obj->uart->PSELTXD = tx; //TX_PIN_NUMBER;
obj->uart->PSELCTS = CTS_PIN_NUMBER;
Expand Down Expand Up @@ -162,14 +162,20 @@ extern "C" {
#endif
void UART0_IRQHandler()
{
uint32_t irtype = 0;

if((NRF_UART0->INTENSET & 0x80) && NRF_UART0->EVENTS_TXDRDY) {
irtype = 1;
} else if((NRF_UART0->INTENSET & 0x04) && NRF_UART0->EVENTS_RXDRDY) {
irtype = 2;
if((NRF_UART0->INTENSET & UART_INTENSET_TXDRDY_Msk) && NRF_UART0->EVENTS_TXDRDY)
{
uart_irq(1, 0);

/* Explicitly clear TX flag to prevent interrupt from firing
immediately after returning from ISR. This ensures that the
last interrupt in a transmission sequence is correcly handled.
*/
NRF_UART0->EVENTS_TXDRDY = 0;
}
else if((NRF_UART0->INTENSET & UART_INTENSET_RXDRDY_Msk) && NRF_UART0->EVENTS_RXDRDY)
{
uart_irq(2, 0);
}
uart_irq(irtype, 0);
}

#ifdef __cplusplus
Expand Down Expand Up @@ -239,11 +245,24 @@ int serial_getc(serial_t *obj)

void serial_putc(serial_t *obj, int c)
{
while (!serial_writable(obj)) {
/* In interrupt mode, send character immediately. Otherwise, block until
UART is ready to receive next character before sending.

The TXDRDY flag is cleared in interrupt handler to ensure that it is
cleared even if there are no more characters to send.
*/
if (NRF_UART0->INTENSET & UART_INTENSET_TXDRDY_Msk)
{
obj->uart->TXD = (uint8_t)c;
}
else
{
while (!serial_writable(obj)) {
}

obj->uart->EVENTS_TXDRDY = 0;
obj->uart->TXD = (uint8_t)c;
obj->uart->EVENTS_TXDRDY = 0;
obj->uart->TXD = (uint8_t)c;
}
}

int serial_readable(serial_t *obj)
Expand Down