mehrdadh commented on a change in pull request #8021:
URL: https://github.com/apache/tvm/pull/8021#discussion_r641831869
##########
File path: apps/microtvm/zephyr/host_driven/src/main.c
##########
@@ -214,33 +216,37 @@ tvm_crt_error_t TVMPlatformTimerStop(double*
elapsed_time_seconds) {
}
// Ring buffer used to store data read from the UART on rx interrupt.
-#define RING_BUF_SIZE_BYTES 4 * 1024
-RING_BUF_DECLARE(uart_rx_rbuf, RING_BUF_SIZE_BYTES);
-
-// Small buffer used to read data from the UART into the ring buffer.
-static uint8_t uart_data[8];
+// TODO(mehrdadh): Explore why offset is required.
+#define RING_BUF_SIZE_BYTES (TVM_CRT_MAX_PACKET_SIZE_BYTES + 100)
+RING_BUF_ITEM_DECLARE_SIZE(uart_rx_rbuf, RING_BUF_SIZE_BYTES);
// UART interrupt callback.
void uart_irq_cb(const struct device* dev, void* user_data) {
- while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
+ uart_irq_update(dev);
+ if (uart_irq_is_pending(dev)) {
struct ring_buf* rbuf = (struct ring_buf*)user_data;
if (uart_irq_rx_ready(dev) != 0) {
- for (;;) {
- // Read a small chunk of data from the UART.
- int bytes_read = uart_fifo_read(dev, uart_data, sizeof(uart_data));
- if (bytes_read < 0) {
- TVMPlatformAbort((tvm_crt_error_t)0xbeef1);
- } else if (bytes_read == 0) {
- break;
- }
- // Write it into the ring buffer.
- int bytes_written = ring_buf_put(rbuf, uart_data, bytes_read);
- if (bytes_read != bytes_written) {
- TVMPlatformAbort((tvm_crt_error_t)0xbeef2);
- }
- // CHECK_EQ(bytes_read, bytes_written, "bytes_read: %d; bytes_written:
%d", bytes_read,
- // bytes_written);
+ uint8_t* data;
+ uint32_t size;
+ size = ring_buf_put_claim(rbuf, &data, RING_BUF_SIZE_BYTES);
Review comment:
This is because in this case we don't need to use an intermediate buffer
and we can read/write directly from/to the ring buffer. This is specially
important for reading from ring buffer, because before this we had to allocate
an extra array and do extra an extra copy of a large array.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]