You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/12/28 09:38:48 UTC

[incubator-nuttx] branch master updated (d85cf99 -> c612c06)

This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from d85cf99  bt_uart: Retry the lower half operation if -EINTR is returned
     new aec3220  bt_uart_shim: Correct the prototype of bt_uart_shim_getdevice
     new c0cd125  bt_uart_shim: Support the multiple instances
     new 8ce2d37  bt_uart_shim: Don't hardcode the thread stack size
     new 9f463fd  bt_uart_shim: Remove g_lowerstatic static variable
     new c258fe0  bt_uart_shim: Make CONFIG_SERIAL_TERMIOS optional
     new c612c06  bt_uart_shim: Setup pollfd with file* correctly

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 drivers/wireless/bluetooth/bt_uart_shim.c       | 144 ++++++++++--------------
 include/nuttx/wireless/bluetooth/bt_uart_shim.h |   5 +-
 2 files changed, 59 insertions(+), 90 deletions(-)


[incubator-nuttx] 02/06: bt_uart_shim: Support the multiple instances

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c0cd125bf37a4a30c0d67a1d4c4654fc0f54f54e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 27 17:16:21 2020 +0800

    bt_uart_shim: Support the multiple instances
    
    by removing the global variables(g_n)
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/wireless/bluetooth/bt_uart_shim.c | 45 ++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c
index 4c92a85..2d6146f 100644
--- a/drivers/wireless/bluetooth/bt_uart_shim.c
+++ b/drivers/wireless/bluetooth/bt_uart_shim.c
@@ -126,10 +126,6 @@ static struct btuart_lowerhalf_s g_lowerstatic =
   .rxdrain = hciuart_rxdrain
 };
 
-/* This is held global because its inconvenient to pass to the task */
-
-static FAR struct hciuart_config_s *g_n;
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -353,7 +349,12 @@ static ssize_t hciuart_rxdrain(FAR const struct btuart_lowerhalf_s *lower)
 
 static int hcicollecttask(int argc, FAR char **argv)
 {
-  FAR struct hciuart_state_s *s = &g_n->state;
+  FAR struct hciuart_config_s *n;
+  FAR struct hciuart_state_s *s;
+
+  n = (FAR struct hciuart_config_s *)
+    ((uintptr_t)strtoul(argv[1], NULL, 0));
+  s = &n->state;
 
   file_poll(&s->f, (struct pollfd *)&s->p, true);
 
@@ -390,19 +391,19 @@ static int hcicollecttask(int argc, FAR char **argv)
               /* We aren't expected to be listening, so drop these data */
 
               wlwarn("Dropping data\n");
-              hciuart_rxdrain(&g_n->lower);
+              hciuart_rxdrain(&n->lower);
             }
           else
             {
               if (s->callback != NULL)
                 {
                   wlinfo("Activating callback\n");
-                  s->callback(&g_n->lower, s->arg);
+                  s->callback(&n->lower, s->arg);
                 }
               else
                 {
                   wlwarn("Dropping data (no CB)\n");
-                  hciuart_rxdrain(&g_n->lower);
+                  hciuart_rxdrain(&n->lower);
                 }
             }
         }
@@ -432,32 +433,34 @@ static int hcicollecttask(int argc, FAR char **argv)
 
 FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path)
 {
+  FAR struct hciuart_config_s *n;
   FAR struct hciuart_state_s *s;
+  FAR char *argv[2];
+  char arg1[16];
   int ret;
 
   /* Get the memory for this shim instance */
 
-  g_n = (FAR struct hciuart_config_s *)
+  n = (FAR struct hciuart_config_s *)
     kmm_zalloc(sizeof(struct hciuart_config_s));
 
-  if (!g_n)
+  if (!n)
     {
-      return 0;
+      return NULL;
     }
 
-  s = &g_n->state;
+  s = &n->state;
 
   ret = file_open(&s->f, path, O_RDWR | O_BINARY);
   if (ret < 0)
     {
-      kmm_free(g_n);
-      g_n = 0;
-      return 0;
+      kmm_free(n);
+      return NULL;
     }
 
   /* Hook the routines in */
 
-  memcpy(&g_n->lower, &g_lowerstatic, sizeof(struct btuart_lowerhalf_s));
+  memcpy(&n->lower, &g_lowerstatic, sizeof(struct btuart_lowerhalf_s));
 
   /* Put materials into poll structure */
 
@@ -469,9 +472,15 @@ FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path)
 
   s->enabled = true;
 
+  /* Create the monitor thread */
+
+  snprintf(arg1, 16, "%p", n);
+  argv[0] = arg1;
+  argv[1] = NULL;
+
   s->serialmontask = kthread_create("BT HCI Rx",
                                     CONFIG_BLUETOOTH_TXCONN_PRIORITY,
-                                    1024, hcicollecttask, NULL);
+                                    1024, hcicollecttask, argv);
 
-  return (FAR struct btuart_lowerhalf_s *)g_n;
+  return (FAR struct btuart_lowerhalf_s *)n;
 }


[incubator-nuttx] 04/06: bt_uart_shim: Remove g_lowerstatic static variable

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 9f463fd3da190c5a49946bda9c6f73d20b99386a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 27 18:54:24 2020 +0800

    bt_uart_shim: Remove g_lowerstatic static variable
    
    let's initialize the callback directly to save the memory
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/wireless/bluetooth/bt_uart_shim.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c
index 40d7d57..7b91396 100644
--- a/drivers/wireless/bluetooth/bt_uart_shim.c
+++ b/drivers/wireless/bluetooth/bt_uart_shim.c
@@ -111,22 +111,6 @@ static ssize_t hciuart_write(FAR const struct btuart_lowerhalf_s *lower,
 static ssize_t hciuart_rxdrain(FAR const struct btuart_lowerhalf_s *lower);
 
 /****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/* This structure is the configuration of the HCI UART shim */
-
-static struct btuart_lowerhalf_s g_lowerstatic =
-{
-  .rxattach = hciuart_rxattach,
-  .rxenable = hciuart_rxenable,
-  .setbaud = hciuart_setbaud,
-  .read = hciuart_read,
-  .write = hciuart_write,
-  .rxdrain = hciuart_rxdrain
-};
-
-/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
@@ -460,7 +444,12 @@ FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path)
 
   /* Hook the routines in */
 
-  memcpy(&n->lower, &g_lowerstatic, sizeof(struct btuart_lowerhalf_s));
+  n->lower.rxattach = hciuart_rxattach;
+  n->lower.rxenable = hciuart_rxenable;
+  n->lower.setbaud  = hciuart_setbaud;
+  n->lower.read     = hciuart_read;
+  n->lower.write    = hciuart_write;
+  n->lower.rxdrain  = hciuart_rxdrain;
 
   /* Put materials into poll structure */
 


[incubator-nuttx] 01/06: bt_uart_shim: Correct the prototype of bt_uart_shim_getdevice

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit aec3220fae4e933f9a1a5d90e571b4d80283f3d3
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 27 02:53:32 2020 +0800

    bt_uart_shim: Correct the prototype of bt_uart_shim_getdevice
    
    1.Add const to the path argument
    2.Return the explicit type(struct btuart_lowerhalf_s *)
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/wireless/bluetooth/bt_uart_shim.c       | 5 ++---
 include/nuttx/wireless/bluetooth/bt_uart_shim.h | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c
index 8d9ac8f..4c92a85 100644
--- a/drivers/wireless/bluetooth/bt_uart_shim.c
+++ b/drivers/wireless/bluetooth/bt_uart_shim.c
@@ -58,7 +58,6 @@
 #include <nuttx/kthread.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/serial/tioctl.h>
-#include <nuttx/wireless/bluetooth/bt_uart.h>
 #include <nuttx/wireless/bluetooth/bt_uart_shim.h>
 #include <termios.h>
 
@@ -431,7 +430,7 @@ static int hcicollecttask(int argc, FAR char **argv)
  *
  ****************************************************************************/
 
-FAR void *bt_uart_shim_getdevice(FAR char *path)
+FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path)
 {
   FAR struct hciuart_state_s *s;
   int ret;
@@ -474,5 +473,5 @@ FAR void *bt_uart_shim_getdevice(FAR char *path)
                                     CONFIG_BLUETOOTH_TXCONN_PRIORITY,
                                     1024, hcicollecttask, NULL);
 
-  return g_n;
+  return (FAR struct btuart_lowerhalf_s *)g_n;
 }
diff --git a/include/nuttx/wireless/bluetooth/bt_uart_shim.h b/include/nuttx/wireless/bluetooth/bt_uart_shim.h
index dcf94d2..536335f 100644
--- a/include/nuttx/wireless/bluetooth/bt_uart_shim.h
+++ b/include/nuttx/wireless/bluetooth/bt_uart_shim.h
@@ -41,8 +41,7 @@
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/config.h>
-#include <nuttx/compiler.h>
+#include <nuttx/wireless/bluetooth/bt_uart.h>
 
 #ifdef CONFIG_BLUETOOTH_UART_SHIM
 
@@ -50,7 +49,7 @@
  * Public Function Prototypes
  ****************************************************************************/
 
-FAR void *bt_uart_shim_getdevice(FAR char *path);
+FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path);
 
 #endif
 #endif


[incubator-nuttx] 03/06: bt_uart_shim: Don't hardcode the thread stack size

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 8ce2d376cc1d6c3657754ad5075f8babf1837f10
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 27 17:31:31 2020 +0800

    bt_uart_shim: Don't hardcode the thread stack size
    
    so let's change 1024 to CONFIG_DEFAULT_TASKSIZE
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/wireless/bluetooth/bt_uart_shim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c
index 2d6146f..40d7d57 100644
--- a/drivers/wireless/bluetooth/bt_uart_shim.c
+++ b/drivers/wireless/bluetooth/bt_uart_shim.c
@@ -480,7 +480,8 @@ FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path)
 
   s->serialmontask = kthread_create("BT HCI Rx",
                                     CONFIG_BLUETOOTH_TXCONN_PRIORITY,
-                                    1024, hcicollecttask, argv);
+                                    CONFIG_DEFAULT_TASK_STACKSIZE,
+                                    hcicollecttask, argv);
 
   return (FAR struct btuart_lowerhalf_s *)n;
 }


[incubator-nuttx] 05/06: bt_uart_shim: Make CONFIG_SERIAL_TERMIOS optional

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c258fe0f85bb3f27362656eba70aedc3e8a3c0f4
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 27 19:15:58 2020 +0800

    bt_uart_shim: Make CONFIG_SERIAL_TERMIOS optional
    
    since the caller don't always need to use setbaud callback
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/wireless/bluetooth/bt_uart_shim.c | 41 ++++++++++++-------------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c
index 7b91396..24c5797 100644
--- a/drivers/wireless/bluetooth/bt_uart_shim.c
+++ b/drivers/wireless/bluetooth/bt_uart_shim.c
@@ -49,6 +49,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <termios.h>
 #include <unistd.h>
 
 #include <nuttx/arch.h>
@@ -59,7 +60,6 @@
 #include <nuttx/semaphore.h>
 #include <nuttx/serial/tioctl.h>
 #include <nuttx/wireless/bluetooth/bt_uart_shim.h>
-#include <termios.h>
 
 /****************************************************************************
  * Private Types
@@ -132,7 +132,7 @@ static void
 hciuart_rxattach(FAR const struct btuart_lowerhalf_s *lower,
                  btuart_rxcallback_t callback, FAR void *arg)
 {
-  struct hciuart_config_s *config = (struct hciuart_config_s *)lower;
+  struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
   struct hciuart_state_s *state;
   irqstate_t flags;
 
@@ -153,7 +153,6 @@ hciuart_rxattach(FAR const struct btuart_lowerhalf_s *lower,
 
   else
     {
-      state->callback = NULL;
       state->arg = arg;
       state->callback = callback;
     }
@@ -183,7 +182,7 @@ static void hciuart_rxenable(FAR const struct btuart_lowerhalf_s *lower,
   irqstate_t flags = spin_lock_irqsave();
   if (enable != s->enabled)
     {
-      wlinfo(enable?"Enable\n":"Disable\n");
+      wlinfo(enable ? "Enable\n" : "Disable\n");
     }
 
   s->enabled = enable;
@@ -208,15 +207,11 @@ static void hciuart_rxenable(FAR const struct btuart_lowerhalf_s *lower,
 static int
 hciuart_setbaud(FAR const struct btuart_lowerhalf_s *lower, uint32_t baud)
 {
+#ifdef CONFIG_SERIAL_TERMIOS
   FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
   FAR struct hciuart_state_s *state = &config->state;
-  int ret;
-
   struct termios tio;
-
-#ifndef CONFIG_SERIAL_TERMIOS
-#  error TERMIOS Support needed for hciuart_setbaud
-#endif
+  int ret;
 
   ret = file_ioctl(&state->f, TCGETS, (long unsigned int)&tio);
   if (ret)
@@ -234,8 +229,7 @@ hciuart_setbaud(FAR const struct btuart_lowerhalf_s *lower, uint32_t baud)
 
   tio.c_cflag |= CRTS_IFLOW | CCTS_OFLOW;
 
-  ret = file_ioctl(&state->f, TCSETS, (long unsigned int)&tio);
-
+  ret = file_ioctl(&state->f, TCSETS, (unsigned long int)&tio);
   if (ret)
     {
       wlerr("ERROR during TCSETS, does UART support CTS/RTS?\n");
@@ -243,6 +237,9 @@ hciuart_setbaud(FAR const struct btuart_lowerhalf_s *lower, uint32_t baud)
     }
 
   return OK;
+#else
+  return -ENOSYS;
+#endif
 }
 
 /****************************************************************************
@@ -263,17 +260,15 @@ hciuart_read(FAR const struct btuart_lowerhalf_s *lower,
 {
   FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
   FAR struct hciuart_state_s *state = &config->state;
-  size_t ntotal;
 
   wlinfo("config %p buffer %p buflen %lu\n",
-         config, buffer, (size_t) buflen);
+         config, buffer, (unsigned long)buflen);
 
   /* NOTE: This assumes that the caller has exclusive access to the Rx
    * buffer, i.e., one lower half instance can server only one upper half!
    */
 
-  ntotal = file_read(&state->f, buffer, buflen);
-  return ntotal;
+  return file_read(&state->f, buffer, buflen);
 }
 
 /****************************************************************************
@@ -294,16 +289,13 @@ static ssize_t
 hciuart_write(FAR const struct btuart_lowerhalf_s *lower,
               FAR const void *buffer, size_t buflen)
 {
-  FAR const struct hciuart_config_s *config
-    = (FAR const struct hciuart_config_s *)lower;
-  FAR const struct hciuart_state_s *state = &config->state;
+  FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
+  FAR struct hciuart_state_s *state = &config->state;
 
   wlinfo("config %p buffer %p buflen %lu\n",
-         config, buffer, (size_t) buflen);
-
-  buflen = file_write((struct file *)&state->f, buffer, buflen);
+         config, buffer, (unsigned long)buflen);
 
-  return buflen;
+  return file_write(&state->f, buffer, buflen);
 }
 
 /****************************************************************************
@@ -319,8 +311,7 @@ static ssize_t hciuart_rxdrain(FAR const struct btuart_lowerhalf_s *lower)
   FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
   FAR struct hciuart_state_s *s = &config->state;
 
-  file_ioctl(&s->f, TCDRN, 0);
-  return 0;
+  return file_ioctl(&s->f, TCDRN, 0);
 }
 
 /****************************************************************************


[incubator-nuttx] 06/06: bt_uart_shim: Setup pollfd with file* correctly

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c612c068e1f70797ea515f351fcbe3da2fdaec36
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 27 23:02:13 2020 +0800

    bt_uart_shim: Setup pollfd with file* correctly
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/wireless/bluetooth/bt_uart_shim.c | 37 ++++++++-----------------------
 1 file changed, 9 insertions(+), 28 deletions(-)

diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c
index 24c5797..8f1cb15 100644
--- a/drivers/wireless/bluetooth/bt_uart_shim.c
+++ b/drivers/wireless/bluetooth/bt_uart_shim.c
@@ -74,14 +74,10 @@ struct hciuart_state_s
   btuart_rxcallback_t callback; /* Rx callback function */
   FAR void *arg;                /* Rx callback argument */
 
-  int h;                        /* File handle to serial device */
-  struct file f;                /* File structure, detached */
-
-  sem_t dready;                 /* Semaphore used by the poll operation */
+  struct file f;                /* File structure */
   bool enabled;                 /* Flag indicating that reception is enabled */
 
   int serialmontask;            /* The receive serial octets task handle */
-  volatile struct pollfd p;     /* Polling structure for serial monitor task */
 };
 
 struct hciuart_config_s
@@ -326,40 +322,35 @@ static int hcicollecttask(int argc, FAR char **argv)
 {
   FAR struct hciuart_config_s *n;
   FAR struct hciuart_state_s *s;
+  struct pollfd p;
 
   n = (FAR struct hciuart_config_s *)
     ((uintptr_t)strtoul(argv[1], NULL, 0));
   s = &n->state;
 
-  file_poll(&s->f, (struct pollfd *)&s->p, true);
+  /* Put materials into poll structure */
+
+  p.ptr = &s->f;
+  p.events = POLLIN | POLLFILE;
 
   for (; ; )
     {
       /* Wait for data to arrive */
 
-      int ret = nxsem_wait(s->p.sem);
+      int ret = nx_poll(&p, 1, -1);
       if (ret < 0)
         {
           wlwarn("Poll interrupted %d\n", ret);
           continue;
         }
 
-      /* These flags can change dynamically as new events occur, so
-       * snapshot.
-       */
-
-      irqstate_t flags = enter_critical_section();
-      uint32_t tevents = s->p.revents;
-      s->p.revents = 0;
-      leave_critical_section(flags);
-
-      wlinfo("Poll completed %d\n", tevents);
+      wlinfo("Poll completed %d\n", p.revents);
 
       /* Given the nature of file_poll, there are multiple reasons why
        * we might be here, so make sure we only consider the read.
        */
 
-      if (tevents & POLLIN)
+      if (p.revents & POLLIN)
         {
           if (!s->enabled)
             {
@@ -442,16 +433,6 @@ FAR struct btuart_lowerhalf_s *bt_uart_shim_getdevice(FAR const char *path)
   n->lower.write    = hciuart_write;
   n->lower.rxdrain  = hciuart_rxdrain;
 
-  /* Put materials into poll structure */
-
-  nxsem_set_protocol(&s->dready, SEM_PRIO_NONE);
-
-  s->p.fd = s->h;
-  s->p.events = POLLIN;
-  s->p.sem = &s->dready;
-
-  s->enabled = true;
-
   /* Create the monitor thread */
 
   snprintf(arg1, 16, "%p", n);