Beispiel #1
0
/**
 * @brief   UART common service routine.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 */
static void uart_serve_interrupt(UARTDriver *uartp)
{
  uint32_t dmachis = HWREG(UDMA_CHIS);
  uint32_t mis = HWREG(uartp->uart + UART_O_MIS);

  if (mis & UART_MIS_TXMIS) {
    /* End of transfer */
    _uart_tx2_isr_code(uartp);
  }

  if (mis & (UART_MIS_OEMIS | UART_MIS_BEMIS | UART_MIS_PEMIS | UART_MIS_FEMIS)) {
    /* Error occurred */
    _uart_rx_error_isr_code(uartp, translate_errors(mis));
  }

  if (dmachis & (1 << uartp->dmarxnr)) {
    if (uartp->rxstate == UART_RX_IDLE) {
      /* Receiver in idle state, a callback is generated, if enabled, for each
         received character and then the driver stays in the same state.*/
      _uart_rx_idle_code(uartp);
      uart_enter_rx_idle_loop(uartp);
    }
    else {
      /* Receiver in active state, a callback is generated, if enabled, after
         a completed transfer.*/
      _uart_rx_complete_isr_code(uartp);
    }
  }

  if (dmachis & (1 << uartp->dmatxnr)) {
    /* A callback is generated, if enabled, after a completed transfer.*/
    _uart_tx1_isr_code(uartp);
  }
}
Beispiel #2
0
/**
 * @brief   USART common service routine.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 */
static void serve_usart_irq(UARTDriver *uartp) {
  uint32_t isr;
  USART_TypeDef *u = uartp->usart;
  uint32_t cr1 = u->CR1;
  
  /* Reading and clearing status.*/
  isr = u->ISR;
  u->ICR = isr;

  if (isr & (USART_ISR_LBDF | USART_ISR_ORE | USART_ISR_NE |
             USART_ISR_FE   | USART_ISR_PE)) {
    _uart_rx_error_isr_code(uartp, translate_errors(isr));
  }

  if ((isr & USART_ISR_TC) && (cr1 & USART_CR1_TCIE)) {
    /* TC interrupt disabled.*/
    u->CR1 = cr1 & ~USART_CR1_TCIE;

    /* End of transmission, a callback is generated.*/
    _uart_tx2_isr_code(uartp);
  }
}
Beispiel #3
0
/**
 * @brief   USART common service routine.
 *
 * @param[in] uartp     pointer to the @p UARTDriver object
 */
static void serve_usart_irq(UARTDriver *uartp) {
  uint16_t sr;
  USART_TypeDef *u = uartp->usart;
  uint32_t cr1 = u->CR1;

  sr = u->SR;   /* SR reset step 1.*/
  (void)u->DR;  /* SR reset step 2.*/

  if (sr & (USART_SR_LBD | USART_SR_ORE | USART_SR_NE |
            USART_SR_FE  | USART_SR_PE)) {
    u->SR = ~USART_SR_LBD;
    _uart_rx_error_isr_code(uartp, translate_errors(sr));
  }

  if ((sr & USART_SR_TC) && (cr1 & USART_CR1_TCIE)) {
    /* TC interrupt cleared and disabled.*/
    u->SR = ~USART_SR_TC;
    u->CR1 = cr1 & ~USART_CR1_TCIE;

    /* End of transmission, a callback is generated.*/
    _uart_tx2_isr_code(uartp);
  }
}