You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "raiden00pl (via GitHub)" <gi...@apache.org> on 2023/07/23 09:25:04 UTC

[GitHub] [nuttx] raiden00pl commented on a diff in pull request #9873: nrf91: improvements for modem and support for modem sockets

raiden00pl commented on code in PR #9873:
URL: https://github.com/apache/nuttx/pull/9873#discussion_r1271413410


##########
arch/arm/src/nrf91/nrf91_modem.h:
##########
@@ -32,12 +34,17 @@
 
 #define NRF91_SHMEM_CTRL_SIZE  (0x4e8)
 
+/* REVISIT: heap overhead */
+
+#define HEAP_OVERHEAD          (400)
+
 /* Shared memory configuration */
 
 #define NRF91_SHMEM_START_ADDR (CONFIG_RAM_START)
 #define NRF91_SHMEM_CTRL_BASE  (NRF91_SHMEM_START_ADDR)
 #define NRF91_SHMEM_TX_BASE    (NRF91_SHMEM_CTRL_BASE+NRF91_SHMEM_CTRL_SIZE)
-#define NRF91_SHMEM_TX_SIZE    (CONFIG_NRF91_MODEM_SHMEM_TX_SIZE)
+#define NRF91_SHMEM_TX_SIZE    (CONFIG_NRF91_MODEM_SHMEM_TX_SIZE\
+                                - HEAP_OVERHEAD)

Review Comment:
   done



##########
arch/arm/src/nrf91/nrf91_modem_at.c:
##########
@@ -112,140 +157,215 @@ static void nrf91_modem_at_notify_handler(const char *notif)
 
 static void nrf91_modem_at_resp_handler(const char *resp)
 {
-  struct nrf91_modem_at_s *dev = &g_nrf91_modem_at;
+  struct uart_dev_s       *dev  = &g_nrf91_modem_at;
+  struct nrf91_modem_at_s *priv = (struct nrf91_modem_at_s *)dev->priv;
+
+  priv->resp_i       = 0;
+  priv->resp         = resp;
+  priv->resp_len     = strlen(resp);
+
+  uart_recvchars(dev);
+}
+
+/****************************************************************************
+ * Name: nrf91_modem_at_setup
+ ****************************************************************************/
+
+static int nrf91_modem_at_setup(struct uart_dev_s *dev)
+{
+  struct nrf91_modem_at_s *priv = (struct nrf91_modem_at_s *)dev->priv;
+
+  /* Reset private data */
+
+  memset(priv, 0, sizeof(struct nrf91_modem_at_s));
+
+  /* Initialize AT modem */
+
+  nrf_modem_at_notif_handler_set(nrf91_modem_at_notify_handler);
+  nrf_modem_at_cmd_custom_set(NULL, 0);
 
-  /* Copy response */
+  return OK;
+}
 
-  strncpy(&dev->rxbuf[dev->rx_i], resp, NRF91_MODEM_AT_RX - dev->rx_i);
-  dev->rx_i += strlen(resp);
+/****************************************************************************
+ * Name: nrf91_modem_at_shutdown
+ ****************************************************************************/
 
-  /* Wake-up any thread waiting in recv */
+static void nrf91_modem_at_shutdown(struct uart_dev_s *dev)
+{
+  nrf_modem_at_notif_handler_set(NULL);
+}
 
-  nxsem_post(&dev->rx_sem);
+/****************************************************************************
+ * Name: nrf91_modem_at_attach
+ ****************************************************************************/
+
+static int nrf91_modem_at_attach(struct uart_dev_s *dev)
+{
+  return OK;
 }
 
 /****************************************************************************
- * Name: nrf91_modem_at_read
+ * Name: nrf91_modem_at_detach
  ****************************************************************************/
 
-static ssize_t nrf91_modem_at_read(struct file *filep, char *buffer,
-                                   size_t len)
+static void nrf91_modem_at_detach(struct uart_dev_s *dev)
 {
-  struct nrf91_modem_at_s *dev   = NULL;
-  struct inode            *inode = NULL;
-  int                      ret   = 0;
+}
 
-  DEBUGASSERT(filep);
-  inode = filep->f_inode;
+/****************************************************************************
+ * Name: nrf91_modem_at_ioct
+ ****************************************************************************/
 
-  DEBUGASSERT(inode && inode->i_private);
-  dev = (struct nrf91_modem_at_s *)inode->i_private;
+static int nrf91_modem_at_ioctl(struct file *filep, int cmd,
+                                unsigned long arg)
+{
+  return OK;
+}
 
-  ret = nxmutex_lock(&dev->lock);
-  if (ret < 0)
-    {
-      return ret;
-    }
+/****************************************************************************
+ * Name: nrf91_modem_at_receive
+ ****************************************************************************/
+
+static int nrf91_modem_at_receive(struct uart_dev_s *dev,
+                                  unsigned int *status)
+{
+  struct nrf91_modem_at_s *priv = (struct nrf91_modem_at_s *)dev->priv;
+  char ch = 0;
 
-  if ((filep->f_oflags & O_NONBLOCK) != 0)
+  *status = 0;
+
+  if (priv->resp != NULL && priv->notif_now == false)
     {
-      nxsem_trywait(&dev->rx_sem);
-      ret = 0;
+      priv->resp_now = true;
+      ch = priv->resp[priv->resp_i++];
+      if (priv->resp_i >= priv->resp_len)
+        {
+          priv->resp     = NULL;
+          priv->resp_now = false;
+        }
     }
-  else
+  else if (priv->notif != NULL && priv->resp_now == false)
     {
-      ret = nxsem_wait(&dev->rx_sem);
+      priv->notif_now = true;
+      ch = priv->notif[priv->notif_i++];
+      if (priv->notif_i >= priv->notif_len)
+        {
+          priv->notif     = NULL;
+          priv->notif_now = false;
+        }
     }
 
-  if (ret < 0)
-    {
-      return ret;
-    }
+  return (int)ch;
+}
 
-  /* Get response data */
+/****************************************************************************
+ * Name: nrf91_modem_at_rxint
+ ****************************************************************************/
 
-  if (len > dev->rx_i)
-    {
-      len = dev->rx_i;
-    }
+static void nrf91_modem_at_rxint(struct uart_dev_s *dev, bool enable)
+{
+}
 
-  strncpy(buffer, dev->rxbuf, len);
-  dev->rx_i = 0;
-  ret = len;
+/****************************************************************************
+ * Name: nrf91_modem_at_rxavailable
+ ****************************************************************************/
 
-  nxmutex_unlock(&dev->lock);
-  return ret;
+static bool nrf91_modem_at_rxavailable(struct uart_dev_s *dev)
+{
+  struct nrf91_modem_at_s *priv = (struct nrf91_modem_at_s *)dev->priv;
+  return (priv->notif || priv->resp);

Review Comment:
   done



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org