int uart_send(uint8_t num, char c) { /* if cannot send the char */ if (uart_send_nowait(num, c) == -1) { /* if irq lock are masked and interrupt mode is on, we * have to poll the status register */ if (GLOBAL_IRQ_ARE_MASKED() && (*uart_regs[num].REGISTER_FOR_UART_IE & (1 << RXCIE)) ) { while( !(*uart_regs[num].ucsra & (1 << UDRE)) ); /* send the next char in the fifo to free a * place */ uart_send_next_char(num); cirbuf_add_head(&g_tx_fifo[num], c); } else { /* if irq are not locked, we can loop to emit */ while(uart_send_nowait(num, c) == -1); } } return 0; }
int uart_send(uart_t *u, uint8_t v) { while(uart_send_nowait(u, v) < 0) { if( !(CPU_SREG & CPU_I_bm) || !(PMIC.CTRL & INTLVL_BM(UART_INTLVL)) || (PMIC.STATUS & INTLVL_BM(UART_INTLVL)) ) { // UART interrupt disabled or blocked, avoid deadlock while( !(u->usart->STATUS & USART_DREIF_bm) ) ; // pop one byte from the buffer, should be the last iteration uart_send_buf_byte(u); } } return 0; }