uart: Decreases timeouts to reduce latency

This commit is contained in:
CTCaer 2020-06-14 13:21:59 +03:00
parent 48f84c5cf4
commit 157e415636
2 changed files with 12 additions and 18 deletions

View file

@ -85,27 +85,24 @@ void uart_send(u32 idx, const u8 *buf, u32 len)
u32 uart_recv(u32 idx, u8 *buf, u32 len) u32 uart_recv(u32 idx, u8 *buf, u32 len)
{ {
uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]); uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]);
u32 timeout = get_tmr_us() + 1000; u32 timeout = get_tmr_us() + 250;
u32 i; u32 i;
for (i = 0; ; i++) for (i = 0; ; i++)
{ {
while (!(uart->UART_LSR & UART_LSR_RDR)) while (!(uart->UART_LSR & UART_LSR_RDR))
{
if (!len)
{ {
if (timeout < get_tmr_us()) if (timeout < get_tmr_us())
break; break;
} if (len && len < i)
else if (len < i)
break; break;
} }
if (timeout < get_tmr_us()) if (timeout < get_tmr_us())
break; break;
buf[i] = uart->UART_THR_DLAB; buf[i] = uart->UART_THR_DLAB;
timeout = get_tmr_us() + 1000; timeout = get_tmr_us() + 250;
}; }
return i ? (len ? (i - 1) : i) : 0; return i ? (len ? (i - 1) : i) : 0;
} }

View file

@ -85,27 +85,24 @@ void uart_send(u32 idx, const u8 *buf, u32 len)
u32 uart_recv(u32 idx, u8 *buf, u32 len) u32 uart_recv(u32 idx, u8 *buf, u32 len)
{ {
uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]); uart_t *uart = (uart_t *)(UART_BASE + uart_baseoff[idx]);
u32 timeout = get_tmr_us() + 1000; u32 timeout = get_tmr_us() + 250;
u32 i; u32 i;
for (i = 0; ; i++) for (i = 0; ; i++)
{ {
while (!(uart->UART_LSR & UART_LSR_RDR)) while (!(uart->UART_LSR & UART_LSR_RDR))
{
if (!len)
{ {
if (timeout < get_tmr_us()) if (timeout < get_tmr_us())
break; break;
} if (len && len < i)
else if (len < i)
break; break;
} }
if (timeout < get_tmr_us()) if (timeout < get_tmr_us())
break; break;
buf[i] = uart->UART_THR_DLAB; buf[i] = uart->UART_THR_DLAB;
timeout = get_tmr_us() + 1000; timeout = get_tmr_us() + 250;
}; }
return i ? (len ? (i - 1) : i) : 0; return i ? (len ? (i - 1) : i) : 0;
} }