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 the current buffer is full, we need to switch it with an empty one
|
||||||
if (buffer->byte_index >= buffer->buffer_size) {
|
if (buffer->byte_index >= buffer->buffer_size) {
|
||||||
|
|
||||||
//if all buffer full, simply wait for the DMA to empty one
|
//if all buffer full, give up
|
||||||
dma_exit_critical(buffer->dma, buffer->channel);
|
if (buffer->free_buffer_nb == 0) {
|
||||||
while (buffer->free_buffer_nb == 0) {}
|
dma_exit_critical(buffer->dma, buffer->channel);
|
||||||
dma_enter_critical(buffer->dma, buffer->channel);
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
++buffer->buffer_index;
|
++buffer->buffer_index;
|
||||||
if (buffer->buffer_index >= buffer->buffer_nb) {
|
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->free_buffer_nb;
|
||||||
|
|
||||||
buffer->byte_index = 0;
|
buffer->byte_index = 0;
|
||||||
} else {
|
|
||||||
dma_enter_critical(buffer->dma, buffer->channel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//write the byte
|
//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);
|
return dma_mbuf_write_byte(buffer, byte);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (regs->SR.TXE == 0) {}
|
//only write data if the tx register it empty, give up otherwise
|
||||||
reg_write(regs->DR, USART_DR_DR, byte);
|
if (regs->SR.TXE) {
|
||||||
return 0;
|
reg_write(regs->DR, USART_DR_DR, byte);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user