fdcavalcanti commented on code in PR #17008:
URL: https://github.com/apache/nuttx/pull/17008#discussion_r2343988365


##########
arch/xtensa/src/common/espressif/esp_wifi_api.c:
##########
@@ -0,0 +1,2158 @@
+/****************************************************************************
+ * arch/xtensa/src/common/espressif/esp_wifi_api.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <inttypes.h>
+#include <assert.h>
+#include <debug.h>
+#include <math.h>
+
+#include "esp_mac.h"
+#include "esp_wifi_types_generic.h"
+#include "esp_wifi.h"
+#include "esp_private/wifi.h"
+
+#include "esp_wifi_utils.h"
+#include "esp_wifi_api.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WIFI_CONNECT_TIMEOUT   CONFIG_ESPRESSIF_WIFI_CONNECT_TIMEOUT
+#define WIFI_CONNECT_RETRY_CNT 3
+
+#define ESP_WIFI_11B_MAX_BITRATE       11
+#define ESP_WIFI_11G_MAX_BITRATE       54
+#define ESP_WIFI_11N_MCS7_HT20_BITRATE 72
+#define ESP_WIFI_11N_MCS7_HT40_BITRATE 150
+
+/* Number of fractional bits in values returned by rtc_clk_cal */
+
+#define RTC_CLK_CAL_FRACT 19
+
+#define PWD_MAX_LEN                 (64)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp_wifi_api_adapter_deinit
+ *
+ * Description:
+ *   De-initialize Wi-Fi adapter, freeing all resources allocated by
+ *   esp_wifi_init. Also stops the Wi-Fi task.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   OK on success; Negated errno on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_api_adapter_deinit(void)
+{
+  int ret;
+
+  ret = esp_wifi_deinit();
+  if (ret)
+    {
+      ret = esp_wifi_to_errno(ret);
+      wlerr("Failed to deinitialize Wi-Fi error=%d\n", ret);
+      return ret;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp_wifi_api_adapter_init
+ *
+ * Description:
+ *   Initialize the Wi-Fi driver, control structure, buffers and Wi-Fi task.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   OK on success; Negated errno on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_api_adapter_init(void)
+{
+  int ret;
+  wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
+
+  esp_wifi_lock(true);
+
+  esp_evt_work_init();
+
+  wifi_cfg.nvs_enable = 0;
+
+#ifdef CONFIG_ESPRESSIF_WIFI_AMPDU_TX_ENABLED
+  wifi_cfg.ampdu_tx_enable = 1;
+#else
+  wifi_cfg.ampdu_tx_enable = 0;
+#endif
+
+#ifdef CONFIG_ESPRESSIF_WIFI_AMPDU_RX_ENABLED
+  wifi_cfg.ampdu_rx_enable = 1;
+#else
+  wifi_cfg.ampdu_rx_enable = 0;
+#endif
+
+#ifdef CONFIG_ESPRESSIF_WIFI_STA_DISCONNECT_PM
+  wifi_cfg.sta_disconnected_pm = true;
+#else
+  wifi_cfg.sta_disconnected_pm = false;
+#endif
+
+  wifi_cfg.rx_ba_win          = CONFIG_ESPRESSIF_WIFI_TX_BA_WIN;
+  wifi_cfg.static_rx_buf_num  = CONFIG_ESPRESSIF_WIFI_STATIC_RX_BUFFER_NUM;
+  wifi_cfg.static_tx_buf_num  = CONFIG_ESPRESSIF_WIFI_STATIC_TX_BUFFER_NUM;
+  wifi_cfg.dynamic_rx_buf_num = CONFIG_ESPRESSIF_WIFI_DYNAMIC_RX_BUFFER_NUM;
+  wifi_cfg.dynamic_tx_buf_num = CONFIG_ESPRESSIF_WIFI_DYNAMIC_TX_BUFFER_NUM;
+  wifi_cfg.tx_buf_type        = CONFIG_ESPRESSIF_WIFI_TX_BUFFER_TYPE;
+
+  ret = esp_wifi_init(&wifi_cfg);
+  if (ret)
+    {
+      wlerr("Failed to initialize Wi-Fi error=%d\n", ret);
+      ret = esp_wifi_to_errno(ret);
+      goto errout_init_wifi;
+    }
+
+  wlinfo("Wi-Fi adapter initialized\n");
+
+  /* Set Wi-Fi mode to NULL, this way it requires ifup call to set
+   * the proper wifi mode. Otherwise, it starts as STA mode.
+   */
+
+  ret = esp_wifi_set_mode(WIFI_MODE_NULL);
+  if (ret)
+    {
+      wlerr("Failed to set Wi-Fi mode to NULL ret=%d\n", ret);
+      ret = esp_wifi_to_errno(ret);
+      goto errout_init_wifi;
+    }
+
+  esp_wifi_lock(false);
+
+  return OK;
+
+errout_init_wifi:
+  esp_wifi_lock(false);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp_wifi_api_start
+ *
+ * Description:
+ *   Start Wi-Fi station. This will start the proper Wi-Fi mode based on
+ *   the AP/Station configuration.
+ *
+ * Input Parameters:
+ *   start_mode - The Wi-Fi mode to start from
+ *                nuttx/include/nuttx/wireless/wireless.h.
+ *
+ * Returned Value:
+ *   OK on success; Negated errno on failure.
+ *
+ ****************************************************************************/
+
+int esp_wifi_api_start(uint32_t start_mode)
+{
+  int ret;
+  wifi_mode_t mode;
+  wifi_mode_t current_mode;
+
+  ret = esp_wifi_get_mode(&current_mode);
+  if (ret)

Review Comment:
   Will change. Thanks Alan!



-- 
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-unsubscr...@nuttx.apache.org

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

Reply via email to