You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/11/13 14:42:37 UTC

[GitHub] [incubator-nuttx] ghn-certi commented on a change in pull request #2294: [WIP] xtensa/esp32: Refactor ESP32 Wi-Fi driver

ghn-certi commented on a change in pull request #2294:
URL: https://github.com/apache/incubator-nuttx/pull/2294#discussion_r522993141



##########
File path: arch/xtensa/src/esp32/esp32_wlan.c
##########
@@ -307,76 +361,204 @@ static inline bool esp_isfreebuffer(FAR struct esp_dev_s *priv)
  *
  ****************************************************************************/
 
-static int esp_transmit(FAR struct esp_dev_s *priv)
+static int wlan_transmit(FAR struct wlan_priv_s *priv)
 {
-  int ret = 0;
-  uint8_t *buffer;
-  uint32_t buffer_len;
-
-  /* Set up all but the last TX descriptor */
+  int ret;
+  struct net_driver_s *dev = &priv->dev;
+  void *buffer = dev->d_buf;
+  uint32_t len = dev->d_len;
 
-  buffer = priv->esp_dev.d_buf;
-  buffer_len = priv->esp_dev.d_len;
-  ret = esp_wifi_sta_send_data(buffer, buffer_len);
+  if (!wifi_tx_available(priv))
+    {
+      return -ENOBUFS;
+    }
 
-  if (ret != 0)
+  ret = esp_wifi_sta_send_data(buffer, len);
+  if (ret)
     {
-      wlerr("ERROR: Failed to transmit frame\n");
-      (void)wd_start(&priv->esp_txtimeout, ESP_TXTIMEOUT,
-                     esp_txtimeout_expiry, (uint32_t)priv);
+      priv->tx_rst = len;
+      if (buffer != priv->txbuf)
+        {
+          memcpy(priv->txbuf, buffer, len);
+        }
+
+      wd_start(&priv->txtimeout, WLAN_TXTIMEOUT,
+               wlan_txtimeout_expiry, (uint32_t)priv);
+
       return -EIO;
     }
+  else
+    {
+      priv->tx_rst = 0;
+    }
 
   return OK;
 }
 
 /****************************************************************************
- * Function: esp_recvframe
+ * Function: wlan_recvframe
  *
  * Description:
- *   It scans the RX descriptors of the received frame.
- *
- *   NOTE: This function will silently discard any packets containing errors.
+ *   Try to receive RX buffer from RX done buffer list.
  *
  * Input Parameters:
  *   priv  - Reference to the driver state structure
  *
  * Returned Value:
- *   OK if a packet was successfully returned; -EAGAIN if there are no
- *   further packets available
+ *   RX buffer if success or NULl if no buffer in list.
  *
  ****************************************************************************/
 
-static int esp_recvframe(FAR struct esp_dev_s *priv)
+static struct wlan_rxbuf *wlan_recvframe(FAR struct wlan_priv_s *priv)
 {
-  struct net_driver_s *dev = &priv->esp_dev;
-  uint8_t *buffer;
-  uint32_t buffer_len = 0;
-  buffer = dev->d_buf;
-  buffer_len = dev->d_len;
-
-  /* Check if there are free buffers.  We cannot receive new frames in this
-   * design unless there is at least one free buffer.
-   */
+  irqstate_t flags;
+  sq_entry_t *entry;
+  struct wlan_rxbuf *rxbuf;
+
+  flags = enter_critical_section();
 
-  if (!esp_isfreebuffer(priv))
+  entry = sq_remfirst(&priv->rxb);
+  if (entry)
+    {
+      rxbuf = container_of(entry, struct wlan_rxbuf, entry);
+    }
+  else
     {
-      wlerr("ERROR: No free buffers\n");
-      return -ENOMEM;
+      rxbuf = NULL;
     }
 
-  /* Check if any errors are reported in the frame */
+  leave_critical_section(flags);
+
+  return rxbuf;
+}
 
-  if (buffer == NULL || buffer_len == 0)
+/****************************************************************************
+ * Name: wlan_tx_done
+ *
+ * Description:
+ *   TxDone callback function type.
+ *
+ * Input Parameters:
+ *   ifidx  - The interface id that the tx callback has been triggered from.
+ *   data   - Pointer to the data transmitted.
+ *   len    - Length of the data transmitted.
+ *   status - True if data was transmitted sucessfully or false if failed.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static void wlan_tx_done(uint8_t ifidx, uint8_t *data,
+                         uint16_t *len, bool status)
+{
+  FAR struct wlan_priv_s *priv = &g_wlan_priv; 
+
+  wd_cancel(&priv->txtimeout);
+
+  wlan_txavail(&priv->dev);
+}
+
+/****************************************************************************
+ * Function: wlan_rx_done
+ *
+ * Description:
+ *   This function should be called when a packet is ready to be read
+ *   from the interface. It uses the function low_level_input() that
+ *   should handle the actual reception of bytes from the network
+ *   interface. Then the type of the received packet is determined and
+ *   the appropriate input function is called.
+ *
+ * Input Parameters:
+ *   buffer - WiFi receive buffer
+ *   len    - Length of receive buffer
+ *   eb     - WiFi receive callback input eb pointer
+ *
+ * Returned Value:
+ *   OK on success; a negated errno on failure
+ *
+ ****************************************************************************/
+
+static int wlan_rx_done(void *buffer, uint16_t len, void *eb)
+{
+  struct wlan_rxbuf *rxbuf;
+  irqstate_t flags;
+  FAR struct wlan_priv_s *priv = &g_wlan_priv;
+
+  if (len > WLAN_BUF_SIZE)
     {
-      return -EAGAIN;
+      wlerr("ERROR: Wlan receive %d larger than %d\n",
+            len, WLAN_BUF_SIZE);
     }
 
-  return OK;
+  rxbuf = wlan_alloc_buffer(priv);
+  if (!rxbuf)
+    {
+      if (eb)
+        {
+          esp_wifi_free_eb(eb);
+        }
+  
+      return -ENOBUFS;
+    }
+
+  memcpy(rxbuf->buffer, buffer, len);
+  rxbuf->len = len;
+
+  if (eb)
+    {
+      esp_wifi_free_eb(eb);
+    }
+
+  flags = enter_critical_section();
+  sq_addlast(&rxbuf->entry, &priv->rxb);
+  leave_critical_section(flags);
+
+  if (work_available(&priv->rxwork))
+    {
+      work_queue(WLAN_WORK, &priv->rxwork, wlan_rxpoll, priv, 0);
+    }
+
+  return 0;

Review comment:
       ```suggestion
     return OK;
   ```




----------------------------------------------------------------
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.

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