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:54 UTC

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

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);