Skip to content

Commit 46c37b5

Browse files
committed
feat(srv/stm32-uart): Disable EOT processing, optimize queue writing
1 parent 108c80b commit 46c37b5

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

services/stm32-uart/stm32-uart.c

+21-26
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,20 @@ static stream_ret_t stream_read_timeout(Stream *self, void *buf, size_t size, si
227227
}
228228
return i ? STREAM_RET_OK : STREAM_RET_TIMEOUT;
229229
} else {
230-
if (c == 0x1b) {
230+
//if (c == 0x1b) {
231231
/* Do not handle timeout. We are sure there is another byte ready
232232
* when ESC is received. Read the next byte after the ESC. */
233-
r = xStreamBufferReceive(stm32_uart->rxbuf, &c, sizeof(c), timeout_ms);
234-
((uint8_t *)buf)[i] = c;
235-
} else if (c == 0x17) {
233+
//r = xStreamBufferReceive(stm32_uart->rxbuf, &c, sizeof(c), timeout_ms);
234+
//((uint8_t *)buf)[i] = c;
235+
//} else if (c == 0x17) {
236236
/* Handle end of block (signalled by RTO interrupt). */
237-
if (read != NULL) {
238-
*read = i;
239-
}
240-
return STREAM_RET_EOT;
241-
} else {
237+
//if (read != NULL) {
238+
//*read = i;
239+
//}
240+
//return STREAM_RET_EOT;
241+
//} else {
242242
((uint8_t *)buf)[i] = c;
243-
}
243+
//}
244244
}
245245
}
246246
if (read != NULL) {
@@ -349,6 +349,7 @@ stm32_uart_ret_t stm32_uart_interrupt_handler(Stm32Uart *self) {
349349

350350
while ((USART_ISR(self->port) & USART_ISR_TXE)) {
351351
uint8_t b = 0;
352+
/** @todo 1 us! */
352353
size_t r = xStreamBufferReceiveFromISR(self->txbuf, &b, sizeof(b), 0);
353354
if (r > 0) {
354355
usart_send(self->port, b);
@@ -369,25 +370,19 @@ stm32_uart_ret_t stm32_uart_interrupt_handler(Stm32Uart *self) {
369370
USART_ICR(self->port) |= USART_ICR_TCCF;
370371
}
371372

372-
while ((USART_ISR(self->port) & USART_ISR_RXNE)) {
373-
uint8_t b = usart_recv(self->port);
374-
375-
/* For any character < 0x20, prepend ESC */
376-
if (b < 0x20) {
377-
const uint8_t esc = 0x1b;
378-
xStreamBufferSendFromISR(self->rxbuf, &esc, sizeof(esc), &woken);
379-
}
380-
/* Do not check the return value. If there was not enough space to save
381-
* the received byte, we have nothing else to do. */
382-
xStreamBufferSendFromISR(self->rxbuf, &b, sizeof(b), &woken);
373+
/* Aggregate multiple receptions until the FIFO is empty or bbuf full. */
374+
uint8_t bbuf[32];
375+
size_t bbuf_len = 0;
376+
while ((USART_ISR(self->port) & USART_ISR_RXNE) && (bbuf_len < sizeof(bbuf))) {
377+
bbuf[bbuf_len] = usart_recv(self->port);
378+
bbuf_len++;
379+
}
380+
if (bbuf_len > 0) {
381+
xStreamBufferSendFromISR(self->rxbuf, bbuf, bbuf_len, &woken);
383382
}
384383

385384
if (USART_ISR(self->port) & USART_ISR_RTOF) {
386385
USART_ICR(self->port) |= USART_ICR_RTOCF;
387-
388-
const uint8_t etb = 0x17;
389-
xStreamBufferSendFromISR(self->rxbuf, &etb, sizeof(etb), &woken);
390-
portYIELD_FROM_ISR(woken);
391386
}
392387

393388
/* Enabling the RXNE interrupt also enables ORE. We must handle it properly. */
@@ -413,7 +408,7 @@ stm32_uart_ret_t stm32_uart_set_rto(Stm32Uart *self, bool rto) {
413408
if (rto) {
414409
/* Set receiver timeout enable. 3 character time. */
415410
USART_CR2(self->port) |= USART_CR2_RTOEN;
416-
USART_RTOR(self->port) = 20L;
411+
USART_RTOR(self->port) = 200L;
417412

418413
/* Enable timeout interrupt. */
419414
USART_CR1(self->port) |= USART_CR1_RTOIE;

0 commit comments

Comments
 (0)