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

Non-blocking UART transmit #139

Closed
dvv opened this issue Jan 27, 2015 · 2 comments
Closed

Non-blocking UART transmit #139

dvv opened this issue Jan 27, 2015 · 2 comments

Comments

@dvv
Copy link
Contributor

dvv commented Jan 27, 2015

https://github.com/nodemcu/nodemcu-firmware/blob/master/app/driver/uart.c#L79-L85 essentially polls for TX buffer empty in manner they do with AVR:

// char gone on wire
OS_INTERRUPT void USART_UDRE_vect(void)
{
  // anything else in output buffer?
  if (txhead != txtail) {
    uint8_t tmptail = (txtail + 1) & UART_TX_BUFFER_MASK;
    txtail = tmptail;
    // disable reader
    UCSR0B &= ~_BV(RXEN0);
    // load next char from output buffer
    UDR0 = uart_tx_buf[tmptail];
  // output buffer empty
  } else {
    // disable TX ready interrupt
    UCSR0B &= ~_BV(UDRIE0);
  }
}

OS_INTERRUPT void USART_TX_vect(void)
{
  // char transmitted, enable reader
  UCSR0B |= _BV(RXEN0);
}

static void uart_putc(char c)
{
  // put to output buffer
  uint8_t tmphead = (txhead + 1) & UART_TX_BUFFER_MASK;
  while (tmphead == txtail) {}
  uart_tx_buf[tmphead] = c;
  txhead = tmphead;
  // enable TX ready interrupt
  UCSR0B |= _BV(UDRIE0);
}

Otherwise printing long lines (e.g. TCP payload) hangs the CPU.

@vowstar
Copy link
Member

vowstar commented Feb 16, 2015

We are doing RTOS version NodeMCU, it may solve this issue.

@jmattsson
Copy link
Member

Closing, see #719.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants