[riot-notifications] [RIOT-OS/RIOT] [WIP] USBUS: Initial work towards an USB stack (#10916)

Kaspar Schleiser notifications at github.com
Fri Feb 1 23:10:09 CET 2019


kaspar030 commented on this pull request.



> +                break;
+        }
+    }
+    return NULL;
+}
+
+/* USB event callback */
+void _event_cb(usbdev_t *usbdev, usbdev_event_t event)
+{
+    usbus_t *usbus = (usbus_t *)usbdev->context;
+    if (event == USBDEV_EVENT_ESR) {
+        msg_t msg = { .type = USBUS_MSG_TYPE_EVENT,
+                      .content = { .ptr = usbdev } };
+
+        if (msg_send(&msg, usbus->pid) <= 0) {
+            puts("usbus: possibly lost interrupt.");

I'd seriously consider using thread flags for this. You'd disable this failure case entirely, thread flags cannot get lost.

An arriving message also sets a thread flag, so a thread can wait for both:

```
thread_flag_t flags = thread_flag_wait_any(0xffff);
if (flags & THREAD_FLAG_MSG_WAITING) {
  msg_t msg
  while (msg_try_receive(&msg) == 1) {
     // handle netapi messages
  }
}
  if (flags & YOUR_FLAG_SET_BY_ISR) {
    /// handle
  }
}
```

> +                break;
+        }
+    }
+    return NULL;
+}
+
+/* USB event callback */
+void _event_cb(usbdev_t *usbdev, usbdev_event_t event)
+{
+    usbus_t *usbus = (usbus_t *)usbdev->context;
+    if (event == USBDEV_EVENT_ESR) {
+        msg_t msg = { .type = USBUS_MSG_TYPE_EVENT,
+                      .content = { .ptr = usbdev } };
+
+        if (msg_send(&msg, usbus->pid) <= 0) {
+            puts("usbus: possibly lost interrupt.");

I understand if you'd rather not go into this for now, can be changed later.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10916#pullrequestreview-199286870
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190201/f09715c4/attachment.html>


More information about the notifications mailing list