rework #4

Merged
Steins7 merged 88 commits from rework into dev 2024-04-20 18:20:23 +00:00
2 changed files with 12 additions and 9 deletions
Showing only changes of commit 256e3f30ab - Show all commits

View File

@ -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

View File

@ -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;
}
} }
} }