changeset 3917:be528ec327d7

drivers/cdc_acm: Avoid spamming listener For one single line coding change, OS would send many messages. Filter out multiple identical configs.
author Nicolas Pouillon <nipo@ssji.net>
date Fri, 20 Apr 2018 09:04:46 +0200
parents feb8372ead09
children 29ea8c7fcb19
files drivers/char/usbdev_acm/usbdev_acm.c
diffstat 1 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/drivers/char/usbdev_acm/usbdev_acm.c	Thu Apr 19 08:55:23 2018 +0200
+++ b/drivers/char/usbdev_acm/usbdev_acm.c	Fri Apr 20 09:04:46 2018 +0200
@@ -464,8 +464,27 @@
   struct device_s *dev = rq->pvdata;
   struct usbdev_acm_private_s *pv = dev->drv_pv;
 
-  /* Update coding parameters */
-  memcpy(&pv->coding, rq->ctrl.buffer, sizeof(struct usbdev_cdc_line_coding_s));
+  if (memcmp(&pv->coding, rq->ctrl.buffer,
+             sizeof(struct usbdev_cdc_line_coding_s))) {
+    /* Update coding parameters */
+    memcpy(&pv->coding, rq->ctrl.buffer, sizeof(struct usbdev_cdc_line_coding_s));
+
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
+    struct dev_uart_config_s config;
+
+    cdc_line_coding_parse(&pv->coding, &config);
+
+    /* Notify listeners */
+    GCT_FOREACH(dev_request_queue, &pv->coding_notify_queue, item, {
+        struct dev_valio_rq_s *rq = dev_valio_rq_s_cast(item);
+
+        dev_request_queue_remove(&pv->coding_notify_queue, &rq->base);
+        rq->error = 0;
+        memcpy(rq->data, &config, sizeof(config));
+        kroutine_exec(&rq->base.kr);
+      });
+#endif
+  }
 
   rq->type = USBDEV_GET_COMMAND;
   rq->error = 0;
@@ -474,18 +493,6 @@
 
   /* Push request on stack */
   usbdev_stack_request(&pv->usb, &pv->service, &pv->rq);
-
-#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
-  /* Notify listeners */
-  GCT_FOREACH(dev_request_queue, &pv->coding_notify_queue, item, {
-      struct dev_valio_rq_s *rq = dev_valio_rq_s_cast(item);
-
-      dev_request_queue_remove(&pv->coding_notify_queue, &rq->base);
-      rq->error = 0;
-      cdc_line_coding_parse(&pv->coding, rq->data);
-      kroutine_exec(&rq->base.kr);
-    });
-#endif
 }
 
 static