Virus-V commented on a change in pull request #2991: URL: https://github.com/apache/incubator-nuttx/pull/2991#discussion_r592202675
########## File path: arch/risc-v/src/bl602/bl602_netdev.c ########## @@ -0,0 +1,2103 @@ +/**************************************************************************** + * arch/risc-v/src/bl602/bl602_netdev.c + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> +#include <time.h> +#include <string.h> +#include <errno.h> +#include <assert.h> +#include <debug.h> +#include <sched.h> +#include <semaphore.h> +#include <nuttx/nuttx.h> +#include <nuttx/kmalloc.h> +#include <nuttx/list.h> +#include <nuttx/signal.h> + +#include <sys/types.h> + +#include <arpa/inet.h> + +#include <nuttx/arch.h> +#include <nuttx/irq.h> +#include <nuttx/wdog.h> +#include <nuttx/wqueue.h> +#include <nuttx/net/arp.h> +#include <nuttx/net/net.h> +#include <nuttx/net/netdev.h> +#include <nuttx/wireless/wireless.h> + +#ifdef CONFIG_NET_PKT +#include <nuttx/net/pkt.h> +#endif + +#include "wifi_manager/include/bitset.h" +#include "wifi_manager/wifi_mgmr.h" +#include "wifi_manager/wifi_mgmr_api.h" +#include "wifi_manager/bl_wifi.h" +#include "wifi_manager/include/wifi_mgmr_ext.h" +#include "wifi_driver/os_hal.h" +#include "bl602_netdev.h" + +#ifdef CONFIG_BL602_WIRELESS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Work queue support is required. */ + +#if !defined(CONFIG_SCHED_WORKQUEUE) +#error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE) +#endif + +/* The low priority work queue is preferred. If it is not enabled, LPWORK + * will be the same as HPWORK. + * + * NOTE: However, the network should NEVER run on the high priority work + * queue! That queue is intended only to service short back end interrupt + * processing that never suspends. Suspending the high priority work queue + * may bring the system to its knees! + */ + +/* FIXME According to some network IO throughput tests, using HPWORK will + * get higher throughput. + */ + +#define ETHWORK HPWORK + +/* CONFIG_BL602_NET_NINTERFACES determines the number of physical interfaces + * that will be supported. + */ + +#ifndef CONFIG_BL602_NET_NINTERFACES +#define CONFIG_BL602_NET_NINTERFACES 1 +#endif + +/* TX poll delay = 1 seconds. + * CLK_TCK is the number of clock ticks per second + */ + +#define BL602_NET_WDDELAY (1 * CLK_TCK) + +#define BL602_NET_TXBUFF_NUM 6 +#define BL602_NET_TXBUFF_SIZE (1650) + +#define BL602_TXDESC_THRESHOLD 3 + +#define WIFI_MTU_SIZE 1514 + +#if BL602_NET_TXBUFF_SIZE & 0x3 != 0 +#error "BL602_NET_TXBUFF_SIZE must be aligned to 4 bytes" +#endif + +#if !(BL602_TXDESC_THRESHOLD > 0) +#error "BL602_TXDESC_THRESHOLD invalid." +#endif + +#define TX_BUFF_BIT_SIZE BL602_NET_TXBUFF_NUM + +/* This is a helper pointer for accessing the contents of Ethernet header */ + +#define BUF ((struct eth_hdr_s *)priv->net_dev.d_buf) + +#define WIFI_MGMR wifiMgmr + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* The bl602_net_driver_s encapsulates all state information for a single + * hardware interface + */ + +struct bl602_net_driver_s +{ + struct wdog_s txpoll; /* TX poll timer */ + struct work_s pollwork; /* For deferring poll work to the work queue */ + struct work_s availwork; + + /* wifi manager */ + + struct wlan_netif *wlan; + + /* there is impossble to concurrency access these fields, so + * we use bit-field to save some little space :) + */ + + unsigned int current_mode : 2; /* current mode */ + unsigned int scan_result_len : 6; /* max 64 */ + unsigned int push_cnt : 4; /* max 16 */ + unsigned int prev_connectd : 1; /* mark of prev connection status */ + + uint16_t channel; /* FIXME freq number. eg. 3, 0 is not set */ + + char bssid[18]; /* AP mac address */ + + /* This holds the information visible to the NuttX network */ + + struct net_driver_s net_dev; /* Interface understood by the network */ +}; + +struct scan_parse_param_s +{ + FAR struct bl602_net_driver_s *priv; + + int flags; + struct iw_scan_req scan_req; +}; + +BITSET_DEFINE(tx_buf_ind_s, TX_BUFF_BIT_SIZE); + +typedef uint8_t (*tx_buff_t)[BL602_NET_TXBUFF_SIZE]; + +/* When a data packet is received, the NuttX protocol stack may use this + * RX buffer to construct a response data packet. However, the WiFi Firmware + * does not support using the RX buffer as the TX buffer directly, so it is + * necessary to allocate a TX buffer to make a copy. + * If there is no TX buffer, the response packet will be discarded. + * Therefore, when a data packet is received, it will check whether there is + * an available TX buffer. If not, it will hang the RX packet in this linked + * list, and wait until TX buffer is available before submitting it to the + * NuttX protocol stack. + */ + +struct rx_pending_item_s +{ + struct list_node node; + uint8_t * data; + int len; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Driver state structure */ + +struct bl602_net_driver_s g_bl602_net[CONFIG_BL602_NET_NINTERFACES]; + +static struct tx_buf_ind_s g_tx_buf_indicator = + BITSET_T_INITIALIZER((1 << BL602_NET_TXBUFF_NUM) - 1); + +static uint8_t __attribute__((section(".wifi_ram.txbuff"))) +g_tx_buff[BL602_NET_TXBUFF_NUM][BL602_NET_TXBUFF_SIZE]; + +static sem_t g_wifi_scan_sem; /* wifi scan complete semaphore */ +static sem_t g_wifi_connect_sem; + +/* Rx Pending List */ + +static struct list_node g_rx_pending; + +static wifi_conf_t g_conf = +{ + .country_code = "CN", Review comment: > > > We will add the WAPI command to configure the country code next. @xiaoxiang781216 This feature is in progress, Kconfig only specifies the default country code ---------------------------------------------------------------- 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: us...@infra.apache.org