Make USART writes non-blocking
The application should be the one to decide if a write should be blocking or not
This commit is contained in:
parent
7a660c29d2
commit
256e3f30ab
@ -49,10 +49,11 @@ uint32_t dma_mbuf_write_byte(volatile struct DmaMultiBuffer* buffer,
|
||||
//if the current buffer is full, we need to switch it with an empty one
|
||||
if (buffer->byte_index >= buffer->buffer_size) {
|
||||
|
||||
//if all buffer full, simply wait for the DMA to empty one
|
||||
dma_exit_critical(buffer->dma, buffer->channel);
|
||||
while (buffer->free_buffer_nb == 0) {}
|
||||
dma_enter_critical(buffer->dma, buffer->channel);
|
||||
//if all buffer full, give up
|
||||
if (buffer->free_buffer_nb == 0) {
|
||||
dma_exit_critical(buffer->dma, buffer->channel);
|
||||
return 1;
|
||||
}
|
||||
|
||||
++buffer->buffer_index;
|
||||
if (buffer->buffer_index >= buffer->buffer_nb) {
|
||||
@ -61,8 +62,6 @@ uint32_t dma_mbuf_write_byte(volatile struct DmaMultiBuffer* buffer,
|
||||
--buffer->free_buffer_nb;
|
||||
|
||||
buffer->byte_index = 0;
|
||||
} else {
|
||||
dma_enter_critical(buffer->dma, buffer->channel);
|
||||
}
|
||||
|
||||
//write the byte
|
||||
|
||||
@ -134,9 +134,13 @@ uint32_t usart_write_byte(enum UsartPeriph periph, uint8_t byte)
|
||||
return dma_mbuf_write_byte(buffer, byte);
|
||||
}
|
||||
} else {
|
||||
while (regs->SR.TXE == 0) {}
|
||||
reg_write(regs->DR, USART_DR_DR, byte);
|
||||
return 0;
|
||||
//only write data if the tx register it empty, give up otherwise
|
||||
if (regs->SR.TXE) {
|
||||
reg_write(regs->DR, USART_DR_DR, byte);
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user