xiaoxiang781216 commented on code in PR #18510:
URL: https://github.com/apache/nuttx/pull/18510#discussion_r2902952959


##########
include/nuttx/wireless/cc1101.h:
##########
@@ -236,6 +237,11 @@
 #define CC1101_GDO_CLK_XOSC128                  0x3e
 #define CC1101_GDO_CLK_XOSC192                  0x3f
 
+#define CC1101_FIRST             (GS2200M_FIRST + GS2200M_NCMDS)
+
+#define CC1101IOC_SETOPMODE      _WLCIOC(CC1101_FIRST + 0)

Review Comment:
   align the third column to line 238



##########
drivers/wireless/cc1101.c:
##########
@@ -560,9 +560,73 @@ static ssize_t cc1101_file_read(FAR struct file *filep, 
FAR char *buffer,
       return ret;
     }
 
-  buflen = fifo_get(dev, (FAR uint8_t *)buffer, buflen);
+  /* If in serial mode, return not supported directly, because data does
+   * not go over SPI and FIFO.
+   */
+
+  if (dev->opmode == CC1101_OPMODE_SYNC_SERIAL ||
+      dev->opmode == CC1101_OPMODE_ASYNC_SERIAL)
+    {
+      nxmutex_unlock(&dev->devlock);
+      return -EOPNOTSUPP;
+    }
+
+  /* Verify if the user-passed buffer is a valid struct pointer. */
+
+  if (buflen != sizeof(struct wlioc_rx_hdr_s))
+    {
+      nxmutex_unlock(&dev->devlock);
+      return -EINVAL;
+    }
+
+  FAR struct wlioc_rx_hdr_s *hdr = (FAR struct wlioc_rx_hdr_s *)buffer;
+
+  /* Get the user-provided max capacity of the receive buffer. */
+
+  size_t user_max_len = hdr->payload_length;
+  if (hdr->payload_buffer == NULL)
+    {
+      nxmutex_unlock(&dev->devlock);
+      return -EINVAL;
+    }
+
+  uint8_t raw_buf[CC1101_PACKET_MAXTOTALLEN];
+  uint8_t pktlen = fifo_get(dev, raw_buf, sizeof(raw_buf));
+
+  if (pktlen == 0)
+    {
+      nxmutex_unlock(&dev->devlock);
+      return 0;
+    }
+
+  /* pktlen contains the payload plus 2 bytes of status. */
+
+  size_t actual_payload_len = (size_t)(pktlen - 2);
+
+  /* Fill metadata (fixed index: subtract 2 and 1). */
+
+  int raw_rssi = raw_buf[pktlen - 2];

Review Comment:
   ALL local variables definition need keep at the begin of function



##########
drivers/wireless/cc1101.c:
##########
@@ -1914,6 +2003,106 @@ static int cc1101_file_ioctl(FAR struct file *filep, 
int cmd,
         ret = -ENOSYS;
         break;
 
+      case CC1101IOC_SETOPMODE:
+        {
+          enum cc1101_opmode_e new_mode = (enum cc1101_opmode_e)arg;
+          uint8_t pktctrl0;
+          uint8_t pktctrl1;
+          uint8_t iocfg0;
+          uint8_t iocfg2;
+
+          /* 1. Restore baseline settings (read from rfsettings). */
+
+          /* Clear PKT_FORMAT bits. */
+
+          pktctrl0 = dev->rfsettings->PKTCTRL0 & ~0x30;
+          pktctrl1 = dev->rfsettings->PKTCTRL1;
+
+          /* 2. Modify registers depending on mode. */
+
+          switch (new_mode)
+            {
+              case CC1101_OPMODE_NORMAL:
+
+                /* Default behavior: Use FIFO, keep rfsettings filtering
+                 * rules.
+                 */
+
+                break;
+
+              case CC1101_OPMODE_PROMISCUOUS:
+
+                /* Promiscuous mode: Still use FIFO (PKT_FORMAT=0).
+                 * Disable address check (ADR_CHK=00), enable append status
+                 * (APPEND_STATUS=1). Disable CRC autoflush
+                 * (CRC_AUTOFLUSH=0).
+                 */
+
+                pktctrl1 = (pktctrl1 & ~0x0b) | 0x04;
+                break;
+
+              case CC1101_OPMODE_SYNC_SERIAL:
+
+                /* Synchronous serial: PKT_FORMAT=1.
+                 * Configure GDO pins to output clock and data.
+                 */
+
+                pktctrl0 |= 0x10;
+
+                /* GDO0 outputs synchronous clock. */
+
+                iocfg0 = CC1101_GDO_SSCLK;
+
+                /* GDO2 outputs synchronous data. */
+
+                iocfg2 = CC1101_GDO_SSDO;
+
+                cc1101_setgdo(dev, CC1101_PIN_GDO0, iocfg0);
+                cc1101_setgdo(dev, CC1101_PIN_GDO2, iocfg2);
+                break;
+
+              case CC1101_OPMODE_ASYNC_SERIAL:
+
+                /* Asynchronous serial: PKT_FORMAT=3. */
+
+                pktctrl0 |= 0x30;
+
+                /* GDO2 outputs asynchronous data. */
+
+                iocfg2 = CC1101_GDO_ASDO;
+
+                cc1101_setgdo(dev, CC1101_PIN_GDO2, iocfg2);
+                break;
+
+              default:
+                ret = -EINVAL;
+                goto ioctl_out;
+            }
+
+          /* 3. Pre-load configuration to registers. */
+
+          if (cc1101_access(dev, CC1101_PKTCTRL0, &pktctrl0, -1) >= 0 &&
+              cc1101_access(dev, CC1101_PKTCTRL1, &pktctrl1, -1) >= 0)
+            {
+              dev->opmode = new_mode;
+              ret = OK;
+            }
+          else
+            {
+              ret = -EIO;
+            }
+
+ioctl_out:
+          break;
+        }
+
+      case CC1101IOC_GETOPMODE:
+        {
+          *(enum cc1101_opmode_e *)arg = dev->opmode;

Review Comment:
   add FAR for ALL pointers



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to