thermosphere: add TransportInterface abstraction layer
This commit is contained in:
@@ -87,7 +87,6 @@ void uartInit(UartDevice dev, u32 baudRate, u32 flags)
|
||||
|
||||
// Enable tx, rx, and uart overall
|
||||
uart->cr = PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN;
|
||||
//uart->imsc = PL011_RTI | PL011_RXI | PL011_RXI;
|
||||
}
|
||||
|
||||
void uartWriteData(UartDevice dev, const void *buffer, size_t size)
|
||||
@@ -129,6 +128,24 @@ size_t uartReadDataMax(UartDevice dev, void *buffer, size_t maxSize)
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t uartReadDataUntil(UartDevice dev, char *buffer, size_t maxSize, char delimiter)
|
||||
{
|
||||
volatile PL011UartRegisters *uart = uartGetRegisters(dev);
|
||||
|
||||
size_t count = 0;
|
||||
|
||||
for (size_t i = 0; i < maxSize; i++) {
|
||||
while (uart->fr & PL011_UARTFR_RXFE);
|
||||
buffer[i] = uart->dr;
|
||||
++count;
|
||||
if (buffer[i] == delimiter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
ReadWriteDirection uartGetInterruptDirection(UartDevice dev)
|
||||
{
|
||||
volatile PL011UartRegisters *uart = uartGetRegisters(dev);
|
||||
|
||||
@@ -132,6 +132,8 @@ void uartInit(UartDevice dev, u32 baudRate, u32 flags);
|
||||
void uartWriteData(UartDevice dev, const void *buffer, size_t size);
|
||||
void uartReadData(UartDevice dev, void *buffer, size_t size);
|
||||
size_t uartReadDataMax(UartDevice dev, void *buffer, size_t maxSize);
|
||||
size_t uartReadDataUntil(UartDevice dev, char *buffer, size_t maxSize, char delimiter);
|
||||
|
||||
ReadWriteDirection uartGetInterruptDirection(UartDevice dev);
|
||||
void uartSetInterruptStatus(UartDevice dev, ReadWriteDirection direction, bool enable);
|
||||
|
||||
|
||||
@@ -192,6 +192,24 @@ size_t uartReadDataMax(UartDevice dev, void *buffer, size_t maxSize)
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t uartReadDataUntil(UartDevice dev, char *buffer, size_t maxSize, char delimiter)
|
||||
{
|
||||
volatile tegra_uart_t *uart = uartGetRegisters(dev);
|
||||
size_t count = 0;
|
||||
|
||||
for (size_t i = 0; i < maxSize && (uart->lsr & UART_LSR_RDR); i++) {
|
||||
while (!(uart->lsr & UART_LSR_RDR)) // Wait until it's possible to receive data.
|
||||
|
||||
buffer[i] = uart->rbr;
|
||||
++count;
|
||||
if (buffer[i] == delimiter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
ReadWriteDirection uartGetInterruptDirection(UartDevice dev)
|
||||
{
|
||||
volatile tegra_uart_t *uart = uartGetRegisters(dev);
|
||||
|
||||
@@ -195,6 +195,8 @@ void uartInit(UartDevice dev, u32 baud, u32 flags);
|
||||
void uartWriteData(UartDevice dev, const void *buffer, size_t size);
|
||||
void uartReadData(UartDevice dev, void *buffer, size_t size);
|
||||
size_t uartReadDataMax(UartDevice dev, void *buffer, size_t maxSize);
|
||||
size_t uartReadDataUntil(UartDevice dev, char *buffer, size_t maxSize, char delimiter);
|
||||
|
||||
ReadWriteDirection uartGetInterruptDirection(UartDevice dev);
|
||||
void uartSetInterruptStatus(UartDevice dev, ReadWriteDirection direction, bool enable);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user