alanmacd commented on code in PR #13885:
URL: https://github.com/apache/tvm/pull/13885#discussion_r1093808157


##########
apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc:
##########
@@ -162,3 +173,62 @@ int8_t QuantizeFloatToInt8(float value, float scale, int 
zero_point) {
   }
   return (int8_t)(result);
 }
+
+// UART interrupt callback.
+void uart_irq_cb(const struct device* dev, void* user_data) {
+  while (uart_irq_update(dev) && 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));
+        }
+      }
+    }
+  }
+}
+
+// Initialize the UART receiver.
+void uart_rx_init(struct ring_buf* rbuf, const struct device* dev) {

Review Comment:
   and if not, is `uart_irq_cb()`



##########
apps/microtvm/zephyr/template_project/src/mlperftiny/platform.cc:
##########
@@ -162,3 +173,62 @@ int8_t QuantizeFloatToInt8(float value, float scale, int 
zero_point) {
   }
   return (int8_t)(result);
 }
+
+// UART interrupt callback.
+void uart_irq_cb(const struct device* dev, void* user_data) {
+  while (uart_irq_update(dev) && 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));
+        }
+      }
+    }
+  }
+}
+
+// Initialize the UART receiver.
+void uart_rx_init(struct ring_buf* rbuf, const struct device* dev) {

Review Comment:
   is `uart_rx_init()` called by anyone here?



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to