예제 #1
0
파일: serial_api.c 프로젝트: oscarh/mbed-os
/** The asynchronous TX and RX handler.
 *
 * @param obj The serial object
 * @return Returns event flags if an RX transfer termination condition was met; otherwise returns 0
 */
int serial_irq_handler_asynch(serial_t *obj)
{
    struct serial_s *p_obj = GET_SERIAL_S(obj);
    volatile uint8_t i = 0;
    volatile int return_val = 0;
    uint8_t *p_buf = (uint8_t *)(obj->rx_buff.buffer);

    if (usart_interrupt_flag_get(p_obj->uart, USART_INT_FLAG_PERR) != RESET) {
        /* clear PERR error flag by reading USART DATA register */
        USART_DATA(p_obj->uart);

        return_val |= (SERIAL_EVENT_RX_PARITY_ERROR & p_obj->events);
        p_obj->error_code |= USART_ERROR_CODE_PERR;
    }

    if (usart_interrupt_flag_get(p_obj->uart, USART_INT_FLAG_ERR_FERR) != RESET) {
        /* clear FERR error flag by reading USART DATA register */
        USART_DATA(p_obj->uart);

        return_val |= (SERIAL_EVENT_RX_FRAMING_ERROR & p_obj->events);
        p_obj->error_code |= USART_ERROR_CODE_FERR;
    }

    if (usart_interrupt_flag_get(p_obj->uart, USART_INT_FLAG_ERR_ORERR) != RESET) {
        /* clear ORERR error flag by reading USART DATA register */
        USART_DATA(p_obj->uart);

        return_val |= (SERIAL_EVENT_RX_OVERRUN_ERROR & p_obj->events);
        p_obj->error_code |= USART_ERROR_CODE_ORERR;
    }

    if (return_val & (SERIAL_EVENT_RX_PARITY_ERROR | SERIAL_EVENT_RX_FRAMING_ERROR |
                      SERIAL_EVENT_RX_OVERRUN_ERROR)) {
        return return_val;
    }

    if (usart_interrupt_flag_get(p_obj->uart, USART_INT_FLAG_TC) != RESET) {
        if ((p_obj->events & SERIAL_EVENT_TX_COMPLETE) != 0) {
            return_val |= (SERIAL_EVENT_TX_COMPLETE & p_obj->events);
        }
    }

    usart_irq_handler(p_obj);

    if (p_obj->rx_size != 0) {
        obj->rx_buff.pos = p_obj->rx_size - p_obj->rx_count;
    }

    if ((p_obj->rx_count == 0) && (obj->rx_buff.pos >= (obj->rx_buff.length - 1))) {
        return_val |= (SERIAL_EVENT_RX_COMPLETE & p_obj->events);
    }

    if (p_obj->events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
        if (p_buf != NULL) {
            for (i = 0; i < obj->rx_buff.pos; i++) {
                if (p_buf[i] == obj->char_match) {
                    obj->rx_buff.pos = i;
                    return_val |= (SERIAL_EVENT_RX_CHARACTER_MATCH & p_obj->events);
                    serial_rx_abort_asynch(obj);
                    break;
                }
            }
        }
    }

    return return_val;
}
예제 #2
0
void usart5_irq_handler(void) { usart_irq_handler(&uart5); }
예제 #3
0
void usart2_irq_handler(void) { usart_irq_handler(&uart2); }
예제 #4
0
void usart3_irq_handler(void) { usart_irq_handler(&uart3); }
예제 #5
0
void usart1_irq_handler(void) { usart_irq_handler(&uart1); }