Esempio n. 1
0
/******************************************************************************
 * FunctionName : uart0_rx_intr_handler
 * Description  : Internal used function
 *                UART0 interrupt handler, add self handle code inside
 * Parameters   : void *para - point to ETS_UART_INTR_ATTACH's arg
 * Returns      : NONE
*******************************************************************************/
static void // must not use ICACHE_FLASH_ATTR !
uart0_rx_intr_handler(void *para)
{
  // we assume that uart1 has interrupts disabled (it uses the same interrupt vector)
  uint8 uart_no = UART0;
  const uint32 one_sec = 1000000; // one second in usecs

  // we end up largely ignoring framing errors and we just print a warning every second max
  if (READ_PERI_REG(UART_INT_RAW(uart_no)) & UART_FRM_ERR_INT_RAW) {
    uint32 now = system_get_time();
    if (last_frm_err == 0 || (now - last_frm_err) > one_sec) {
      os_printf("UART framing error (bad baud rate?)\n");
      last_frm_err = now;
    }
    // clear rx fifo (apparently this is not optional at this point)
    SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST);
    CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST);
    // reset framing error
    WRITE_PERI_REG(UART_INT_CLR(UART0), UART_FRM_ERR_INT_CLR);
  // once framing errors are gone for 10 secs we forget about having seen them
  } else if (last_frm_err != 0 && (system_get_time() - last_frm_err) > 10*one_sec) {
    last_frm_err = 0;
  }

  if (UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST)
  ||  UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST))
  {
    //DBG_UART("stat:%02X",*(uint8 *)UART_INT_ENA(uart_no));
    ETS_UART_INTR_DISABLE();
    post_usr_task(uart_recvTaskNum, 0);
  }
}
Esempio n. 2
0
void esp_uart_print_status(void *arg) {
  struct esp_uart_state *us = (struct esp_uart_state *) arg;
  struct esp_uart_stats *s = &us->stats;
  struct esp_uart_stats *ps = &us->prev_stats;
  int uart_no = us->cfg->uart_no;
  fprintf(
      stderr,
      "UART%d ints %u/%u/%u; rx en %d bytes %u buf %u fifo %u, ovf %u, lcs %u; "
      "tx %u %u %u, thr %u; hf %u i 0x%03x ie 0x%03x cts %d\n",
      uart_no, s->ints - ps->ints, s->rx_ints - ps->rx_ints,
      s->tx_ints - ps->tx_ints, us->rx_enabled, s->rx_bytes - ps->rx_bytes,
      us->rx_buf.used, rx_fifo_len(us->cfg->uart_no),
      s->rx_overflows - ps->rx_overflows,
      s->rx_linger_conts - ps->rx_linger_conts, s->tx_bytes - ps->tx_bytes,
      us->tx_buf.used, tx_fifo_len(us->cfg->uart_no),
      s->tx_throttles - ps->tx_throttles, system_get_free_heap_size(),
      READ_PERI_REG(UART_INT_RAW(uart_no)),
      READ_PERI_REG(UART_INT_ENA(uart_no)), cts(uart_no));
  memcpy(ps, s, sizeof(*s));
}
Esempio n. 3
0
uint32_t esp_uart_raw_ints(int uart_no) {
  return READ_PERI_REG(UART_INT_RAW(uart_no));
}