/** * Interrupt handler for the USART1 peripheral. * * If the interrupt was caused by a received character, the handler adds the * chararacter to the rx_buffer. If the interrupt was caused by the peripheral * being ready to send a character, the handler takes one from the tx_buffer, * and writes it to the peripheral. In case the interrupt was caused by a USART * peripheral buffer overrun (typically happens during debugging), the handler * clears that interrupt flag. */ void usart1_isr(void) { if (usart_get_flag(USART1, USART_ISR_RXNE)) { char ch = (char) usart_recv(USART1); os_char_buffer_write_ch(&bsp_rx_buffer, ch); } else if (usart_get_flag(USART1, USART_ISR_TXE)) { char ch = '\0'; if (os_char_buffer_read_ch(&bsp_tx_buffer, &ch)) { usart_send(USART1, (uint8_t) ch); } else { usart_disable_tx_interrupt(USART1); } } else if (usart_get_flag(USART1, USART_ISR_ORE)) { USART_ICR(USART1) |= USART_ICR_ORECF; } }
void usart_clear_rx_interrupt(uint32_t usart_base) { USART_ICR(usart_base) |= USART_ICR_ORECF; }
void usart_clear_tx_interrupt(uint32_t usart_base) { USART_ICR(usart_base) |= USART_ICR_TCCF; }