mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
[DeviceDriver][wlan] add new wlan framework
This commit is contained in:
1 parent
2c6c4a747b
commit
324bfc5897
16 files changed
+5349
-1064
No files matched your search
+64
-22
@@ -194,32 +194,74 @@ config RT_USING_WDT
|
||||
bool "Using Watch Dog device drivers"
|
||||
default n
|
||||
|
||||
config RT_USING_WIFI
|
||||
bool "Using Wi-Fi network"
|
||||
default n
|
||||
|
||||
if RT_USING_WIFI
|
||||
config RT_USING_WLAN_STA
|
||||
bool "Using station mode"
|
||||
default y
|
||||
|
||||
config RT_USING_WLAN_AP
|
||||
bool "Using ap mode"
|
||||
default n
|
||||
|
||||
config WIFI_DEVICE_STA_NAME
|
||||
string "the wifi device name for station"
|
||||
default "w0"
|
||||
|
||||
config WIFI_DEVICE_AP_NAME
|
||||
string "the wifi device name for ap"
|
||||
default "ap"
|
||||
endif
|
||||
|
||||
config RT_USING_AUDIO
|
||||
bool "Using Audio device drivers"
|
||||
default n
|
||||
|
||||
menu "Using WiFi"
|
||||
config RT_USING_WIFI
|
||||
bool "Using Wi-Fi framework"
|
||||
default n
|
||||
|
||||
if RT_USING_WIFI
|
||||
config RT_WLAN_DEVICE_STA_NAME
|
||||
string "the WiFi device name for station"
|
||||
default "wlan0"
|
||||
|
||||
config RT_WLAN_DEVICE_AP_NAME
|
||||
string "the WiFi device name for ap"
|
||||
default "wlan1"
|
||||
|
||||
config RT_WLAN_DEFAULT_PROT
|
||||
string "Default transport protocol"
|
||||
default "lwip"
|
||||
|
||||
config RT_WLAN_SCAN_WAIT_MS
|
||||
int "Scan timeout time"
|
||||
default 10000;
|
||||
|
||||
config RT_WLAN_CONNECT_WAIT_MS
|
||||
int "connect timeout time"
|
||||
default 10000;
|
||||
|
||||
config RT_WLAN_SSID_MAX_LENGTH
|
||||
int "SSID name maximum length"
|
||||
default 32
|
||||
|
||||
config RT_WLAN_PASSWORD_MAX_LENGTH
|
||||
int "Maximum password length"
|
||||
default 32
|
||||
|
||||
config RT_WLAN_SCAN_SORT
|
||||
bool "Automatic sorting of scan results"
|
||||
default y
|
||||
|
||||
config RT_WLAN_CFG_INFO_MAX
|
||||
int "Maximum number of WiFi information automatically saved"
|
||||
default 3
|
||||
|
||||
config RT_WLAN_WORKQUEUE_THREAD_NAME
|
||||
string "WiFi work queue thread name"
|
||||
default "wlan_job"
|
||||
|
||||
config RT_WLAN_WORKQUEUE_THREAD_SIZE
|
||||
int "wifi work queue thread size"
|
||||
default 2048
|
||||
|
||||
config RT_WLAN_WORKQUEUE_THREAD_PRIO
|
||||
int "WiFi work queue thread priority"
|
||||
default 22
|
||||
|
||||
config RT_WLAN_DEV_EVENT_NUM
|
||||
int "Maximum number of driver events"
|
||||
default 2
|
||||
|
||||
config RT_WLAN_PROT_LWIP_PBUF_FORCE
|
||||
bool "Forced use of PBUF transmission"
|
||||
default n
|
||||
endif
|
||||
endmenu
|
||||
|
||||
menu "Using USB"
|
||||
config RT_USING_USB_HOST
|
||||
bool "Using USB host"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-09-15 tyx the first version
|
||||
*/
|
||||
|
||||
#ifndef __WLAN_H__
|
||||
#define __WLAN_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <wlan_dev.h>
|
||||
#include <wlan_cfg.h>
|
||||
#include <wlan_mgnt.h>
|
||||
#include <wlan_prot.h>
|
||||
#include <wlan_workqueue.h>
|
||||
|
||||
#endif
|
||||
@@ -117,6 +117,10 @@ extern "C" {
|
||||
#include "drivers/rt_drv_pwm.h"
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_WIFI
|
||||
#include "drivers/wlan.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-08-06 tyx the first version
|
||||
*/
|
||||
|
||||
#ifndef __WLAN_CFG_H__
|
||||
#define __WLAN_CFG_H__
|
||||
|
||||
#include <wlan_dev.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_CFG_INFO_MAX
|
||||
#define RT_WLAN_CFG_INFO_MAX (3) /* min is 1 */
|
||||
#endif
|
||||
|
||||
#if RT_WLAN_CFG_INFO_MAX < 1
|
||||
#error "The minimum configuration is 1"
|
||||
#endif
|
||||
|
||||
#define RT_WLAN_CFG_MAGIC (0x426f6d62)
|
||||
|
||||
struct rt_wlan_cfg_info
|
||||
{
|
||||
struct rt_wlan_info info;
|
||||
struct rt_wlan_key key;
|
||||
};
|
||||
|
||||
typedef int (*rt_wlan_wr)(void *buff, int len);
|
||||
|
||||
struct rt_wlan_cfg_ops
|
||||
{
|
||||
int (*read_cfg)(void *buff, int len);
|
||||
int (*get_len)(void);
|
||||
int (*write_cfg)(void *buff, int len);
|
||||
};
|
||||
|
||||
void rt_wlan_cfg_init(void);
|
||||
|
||||
void rt_wlan_cfg_set_ops(const struct rt_wlan_cfg_ops *ops);
|
||||
|
||||
int rt_wlan_cfg_get_num(void);
|
||||
|
||||
int rt_wlan_cfg_read(struct rt_wlan_cfg_info *cfg_info, int num);
|
||||
|
||||
int rt_wlan_cfg_read_index(struct rt_wlan_cfg_info *cfg_info, int index);
|
||||
|
||||
rt_err_t rt_wlan_cfg_save(struct rt_wlan_cfg_info *cfg_info);
|
||||
|
||||
rt_err_t rt_wlan_cfg_cache_refresh(void);
|
||||
|
||||
rt_err_t rt_wlan_cfg_cache_save(void);
|
||||
|
||||
int rt_wlan_cfg_delete_index(int index);
|
||||
|
||||
void rt_wlan_cfg_delete_all(void);
|
||||
|
||||
void rt_wlan_cfg_dump(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+470
-443
File diff suppressed because it is too large.
Load diff
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* File : wlan_cmd.h
|
||||
* Wi-Fi common commands
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-06-05 RT-Thread first version
|
||||
*/
|
||||
|
||||
#ifndef WLAN_CMD_H__
|
||||
#define WLAN_CMD_H__
|
||||
|
||||
struct netif;
|
||||
|
||||
int wifi_get_mode(void);
|
||||
int wifi_set_mode(int mode);
|
||||
|
||||
/* do the wifi default action: read wifi setting and then join or start soft-AP */
|
||||
int wifi_default(void);
|
||||
/* setup netif for soft-ap */
|
||||
int wifi_softap_setup_netif(struct netif *netif);
|
||||
|
||||
int wifi_set_setting(const char *ssid, const char *pwd);
|
||||
|
||||
#ifdef PKG_USING_CJSON
|
||||
int wifi_read_cfg(const char *filename);
|
||||
int wifi_save_cfg(const char *filename);
|
||||
#endif
|
||||
/* save wifi setting with default storage file */
|
||||
int wifi_save_setting(void);
|
||||
|
||||
extern struct rt_wlan_info info;
|
||||
|
||||
#endif
|
||||
+673
-256
File diff suppressed because it is too large.
Load diff
+512
-157
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+1873
-114
File diff suppressed because it is too large.
Load diff
@@ -1,34 +1,154 @@
|
||||
/*
|
||||
* RT-Thread Wi-Fi Device
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-02-27 EvalZero the first verion
|
||||
* 2018-08-06 tyx the first version
|
||||
*/
|
||||
|
||||
#ifndef __WLAN_MGNT_H__
|
||||
#define __WLAN_MGNT_H__
|
||||
|
||||
int rt_wlan_mgnt_attach(struct rt_wlan_device *device, void *user_data);
|
||||
#include <wlan_dev.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_SCAN_WAIT_MS
|
||||
#define RT_WLAN_SCAN_WAIT_MS (10 * 1000)
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_SCAN_CACHE_NUM
|
||||
#define RT_WLAN_SCAN_CACHE_NUM (50)
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_CONNECT_WAIT_MS
|
||||
#define RT_WLAN_CONNECT_WAIT_MS (10 * 1000)
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_START_AP_WAIT_MS
|
||||
#define RT_WLAN_START_AP_WAIT_MS (10 * 1000)
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_EBOX_NUM
|
||||
#define RT_WLAN_EBOX_NUM (10)
|
||||
#endif
|
||||
|
||||
#if RT_WLAN_EBOX_NUM < 1
|
||||
#error "event box num Too little"
|
||||
#endif
|
||||
|
||||
/*state fot station*/
|
||||
#define RT_WLAN_STATE_CONNECT (0x1 << 0)
|
||||
#define RT_WLAN_STATE_CONNECTING (0x1 << 1)
|
||||
#define RT_WLAN_STATE_READY (0x1 << 2)
|
||||
#define RT_WLAN_STATE_POWERSAVE (0x1 << 3)
|
||||
|
||||
/*flags fot station*/
|
||||
#define RT_WLAN_STATE_AUTOEN (0x1 << 0)
|
||||
|
||||
/*state fot ap*/
|
||||
#define RT_WLAN_STATE_ACTIVE (0x1 << 0)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RT_WLAN_EVT_READY = 0, /* connect and prot is ok, You can send data*/
|
||||
RT_WLAN_EVT_SCAN_DONE, /* Scan a info */
|
||||
RT_WLAN_EVT_SCAN_REPORT, /* Scan end */
|
||||
RT_WLAN_EVT_STA_CONNECTED, /* connect success */
|
||||
RT_WLAN_EVT_STA_CONNECTED_FAIL, /* connection failed */
|
||||
RT_WLAN_EVT_STA_DISCONNECTED, /* disconnect */
|
||||
RT_WLAN_EVT_AP_START, /* AP start */
|
||||
RT_WLAN_EVT_AP_STOP, /* AP stop */
|
||||
RT_WLAN_EVT_AP_ASSOCIATED, /* sta associated */
|
||||
RT_WLAN_EVT_AP_DISASSOCIATED, /* sta disassociated */
|
||||
RT_WLAN_EVT_MAX
|
||||
} rt_wlan_event_t;
|
||||
|
||||
typedef void (*rt_wlan_event_handler)(int event, struct rt_wlan_buff *buff, void *parameter);
|
||||
|
||||
struct rt_wlan_scan_result
|
||||
{
|
||||
rt_int32_t num;
|
||||
struct rt_wlan_info *info;
|
||||
};
|
||||
|
||||
/*
|
||||
* wifi init interface
|
||||
*/
|
||||
int rt_wlan_init(void);
|
||||
rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode);
|
||||
rt_wlan_mode_t rt_wlan_get_mode(const char *dev_name);
|
||||
|
||||
/*
|
||||
* wifi station mode interface
|
||||
*/
|
||||
rt_err_t rt_wlan_connect(const char *ssid, const char *password);
|
||||
rt_err_t rt_wlan_connect_adv(struct rt_wlan_info *info, const char *password);
|
||||
rt_err_t rt_wlan_disconnect(void);
|
||||
int rt_wlan_is_connected(void);
|
||||
int rt_wlan_is_ready(void);
|
||||
rt_err_t rt_wlan_set_mac(rt_uint8_t *mac);
|
||||
rt_err_t rt_wlan_get_mac(rt_uint8_t *mac);
|
||||
rt_err_t rt_wlan_get_info(struct rt_wlan_info *info);
|
||||
int rt_wlan_get_rssi(void);
|
||||
|
||||
/*
|
||||
* wifi ap mode interface
|
||||
*/
|
||||
rt_err_t rt_wlan_start_ap(const char *ssid, const char *password);
|
||||
rt_err_t rt_wlan_start_ap_adv(struct rt_wlan_info *info, const char *password);
|
||||
int rt_wlan_ap_is_active(void);
|
||||
rt_err_t rt_wlan_ap_stop(void);
|
||||
rt_err_t rt_wlan_ap_get_info(struct rt_wlan_info *info);
|
||||
int rt_wlan_ap_get_sta_num(void);
|
||||
int rt_wlan_ap_get_sta_info(struct rt_wlan_info *info, int num);
|
||||
rt_err_t rt_wlan_ap_deauth_sta(rt_uint8_t *mac);
|
||||
rt_err_t rt_wlan_ap_set_country(rt_country_code_t country_code);
|
||||
rt_country_code_t rt_wlan_ap_get_country(void);
|
||||
|
||||
/*
|
||||
* wifi scan interface
|
||||
*/
|
||||
rt_err_t rt_wlan_scan(void);
|
||||
struct rt_wlan_scan_result *rt_wlan_scan_sync(void);
|
||||
struct rt_wlan_scan_result *rt_wlan_scan_with_info(struct rt_wlan_info *info);
|
||||
int rt_wlan_scan_get_info_num(void);
|
||||
int rt_wlan_scan_get_info(struct rt_wlan_info *info, int num);
|
||||
struct rt_wlan_scan_result *rt_wlan_scan_get_result(void);
|
||||
void rt_wlan_scan_result_clean(void);
|
||||
int rt_wlan_scan_find_cache(struct rt_wlan_info *info, struct rt_wlan_info *out_info, int num);
|
||||
rt_bool_t rt_wlan_find_best_by_cache(const char *ssid, struct rt_wlan_info *info);
|
||||
|
||||
/*
|
||||
* wifi auto connect interface
|
||||
*/
|
||||
void rt_wlan_config_autoreconnect(rt_bool_t enable);
|
||||
rt_bool_t rt_wlan_get_autoreconnect_mode(void);
|
||||
|
||||
/*
|
||||
* wifi power management interface
|
||||
*/
|
||||
rt_err_t rt_wlan_enable_powersave(void);
|
||||
rt_err_t rt_wlan_disable_powersave(void);
|
||||
|
||||
/*
|
||||
* wifi event management interface
|
||||
*/
|
||||
rt_err_t rt_wlan_register_event_handler(rt_wlan_event_t event, rt_wlan_event_handler handler, void *parameter);
|
||||
rt_err_t rt_wlan_unregister_event_handler(rt_wlan_event_t event);
|
||||
|
||||
/*
|
||||
* wifi management lock interface
|
||||
*/
|
||||
void rt_wlan_mgnt_lock(void);
|
||||
void rt_wlan_mgnt_unlock(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-08-14 tyx the first version
|
||||
*/
|
||||
|
||||
#ifndef __WLAN_PROT_H__
|
||||
#define __WLAN_PROT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_PROT_NAME_LEN
|
||||
#define RT_WLAN_PROT_NAME_LEN (8)
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_PROT_MAX
|
||||
#define RT_WLAN_PROT_MAX (1)
|
||||
#endif
|
||||
|
||||
#define RT_LWAN_ID_PREFIX (0x5054)
|
||||
|
||||
#if RT_WLAN_PROT_NAME_LEN < 4
|
||||
#error "The name is too short"
|
||||
#endif
|
||||
|
||||
#define RT_WLAN_PROT_LWIP ("lwip")
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RT_WLAN_PROT_EVT_INIT_DONE = 0,
|
||||
RT_WLAN_PROT_EVT_CONNECT,
|
||||
RT_WLAN_PROT_EVT_DISCONNECT,
|
||||
RT_WLAN_PROT_EVT_AP_START,
|
||||
RT_WLAN_PROT_EVT_AP_STOP,
|
||||
RT_WLAN_PROT_EVT_AP_ASSOCIATED,
|
||||
RT_WLAN_PROT_EVT_AP_DISASSOCIATED,
|
||||
RT_WLAN_PROT_EVT_MAX,
|
||||
} rt_wlan_prot_event_t;
|
||||
|
||||
struct rt_wlan_prot;
|
||||
struct rt_wlan_prot_ops
|
||||
{
|
||||
rt_err_t (*prot_recv)(struct rt_wlan_device *wlan, void *buff, int len);
|
||||
struct rt_wlan_prot *(*dev_reg_callback)(struct rt_wlan_prot *prot, struct rt_wlan_device *wlan);
|
||||
void (*dev_unreg_callback)(struct rt_wlan_prot *prot, struct rt_wlan_device *wlan);
|
||||
};
|
||||
|
||||
struct rt_wlan_prot
|
||||
{
|
||||
char name[RT_WLAN_PROT_NAME_LEN];
|
||||
rt_uint32_t id;
|
||||
const struct rt_wlan_prot_ops *ops;
|
||||
};
|
||||
|
||||
typedef void (*rt_wlan_prot_event_handler)(struct rt_wlan_prot *port, struct rt_wlan_device *wlan, int event);
|
||||
|
||||
rt_err_t rt_wlan_prot_attach(const char *dev_name, const char *prot_name);
|
||||
|
||||
rt_err_t rt_wlan_prot_attach_dev(struct rt_wlan_device *wlan, const char *prot_name);
|
||||
|
||||
rt_err_t rt_wlan_prot_detach(const char *dev_name);
|
||||
|
||||
rt_err_t rt_wlan_prot_detach_dev(struct rt_wlan_device *wlan);
|
||||
|
||||
rt_err_t rt_wlan_prot_regisetr(struct rt_wlan_prot *prot);
|
||||
|
||||
rt_err_t rt_wlan_prot_transfer_dev(struct rt_wlan_device *wlan, void *buff, int len);
|
||||
|
||||
rt_err_t rt_wlan_dev_transfer_prot(struct rt_wlan_device *wlan, void *buff, int len);
|
||||
|
||||
rt_err_t rt_wlan_prot_event_register(struct rt_wlan_prot *prot, rt_wlan_prot_event_t event, rt_wlan_prot_event_handler handler);
|
||||
|
||||
rt_err_t rt_wlan_prot_event_unregister(struct rt_wlan_prot *prot, rt_wlan_prot_event_t event);
|
||||
|
||||
int rt_wlan_prot_ready(struct rt_wlan_device *wlan, struct rt_wlan_buff *buff);
|
||||
|
||||
void rt_wlan_prot_dump(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-08-19 tyx the first version
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <wlan_workqueue.h>
|
||||
#include <ipc/workqueue.h>
|
||||
|
||||
#define DBG_ENABLE
|
||||
#define DBG_LEVEL DBG_INFO
|
||||
#define DBG_SECTION_NAME "WLAN.work"
|
||||
#define DBG_COLOR
|
||||
#include <rtdbg.h>
|
||||
|
||||
struct rt_wlan_work
|
||||
{
|
||||
struct rt_work work;
|
||||
void (*fun)(void *parameter);
|
||||
void *parameter;
|
||||
};
|
||||
|
||||
static struct rt_workqueue *wlan_workqueue;
|
||||
|
||||
static void rt_wlan_workqueue_fun(struct rt_work *work, void *work_data)
|
||||
{
|
||||
struct rt_wlan_work *wlan_work = work_data;
|
||||
|
||||
wlan_work->fun(wlan_work->parameter);
|
||||
rt_free(wlan_work);
|
||||
}
|
||||
|
||||
struct rt_workqueue *rt_wlan_get_workqueue(void)
|
||||
{
|
||||
return wlan_workqueue;
|
||||
}
|
||||
|
||||
rt_err_t rt_wlan_workqueue_dowork(void (*func)(void *parameter), void *parameter)
|
||||
{
|
||||
struct rt_wlan_work *wlan_work;
|
||||
rt_err_t err = RT_EOK;
|
||||
|
||||
LOG_D("F:%s is run", __FUNCTION__);
|
||||
if (func == RT_NULL)
|
||||
{
|
||||
LOG_E("F:%s L:%d func is null", __FUNCTION__, __LINE__);
|
||||
return -RT_EINVAL;
|
||||
}
|
||||
|
||||
if (wlan_workqueue == RT_NULL)
|
||||
{
|
||||
LOG_E("F:%s L:%d not init wlan work queue", __FUNCTION__, __LINE__);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
wlan_work = rt_malloc(sizeof(struct rt_wlan_work));
|
||||
if (wlan_work == RT_NULL)
|
||||
{
|
||||
LOG_E("F:%s L:%d create work failed", __FUNCTION__, __LINE__);
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
wlan_work->fun = func;
|
||||
wlan_work->parameter = parameter;
|
||||
rt_work_init(&wlan_work->work, rt_wlan_workqueue_fun, wlan_work);
|
||||
err = rt_workqueue_dowork(wlan_workqueue, &wlan_work->work);
|
||||
if (err != RT_EOK)
|
||||
{
|
||||
LOG_E("F:%s L:%d do work failed", __FUNCTION__, __LINE__);
|
||||
rt_free(wlan_work);
|
||||
return err;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int rt_wlan_workqueue_init(void)
|
||||
{
|
||||
static rt_int8_t _init_flag = 0;
|
||||
|
||||
if (_init_flag == 0)
|
||||
{
|
||||
wlan_workqueue = rt_workqueue_create(RT_WLAN_WORKQUEUE_THREAD_NAME, RT_WLAN_WORKQUEUE_THREAD_SIZE,
|
||||
RT_WLAN_WORKQUEUE_THREAD_PRIO);
|
||||
if (wlan_workqueue == RT_NULL)
|
||||
{
|
||||
LOG_E("F:%s L:%d wlan work queue create failed", __FUNCTION__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
_init_flag = 1;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
INIT_PREV_EXPORT(rt_wlan_workqueue_init);
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-08-19 tyx the first version
|
||||
*/
|
||||
|
||||
#ifndef __WLAN_WORKQUEUE_H__
|
||||
#define __WLAN_WORKQUEUE_H__
|
||||
|
||||
#include <ipc/workqueue.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_WORKQUEUE_THREAD_NAME
|
||||
#define RT_WLAN_WORKQUEUE_THREAD_NAME ("wlan_job")
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_WORKQUEUE_THREAD_SIZE
|
||||
#define RT_WLAN_WORKQUEUE_THREAD_SIZE (2048)
|
||||
#endif
|
||||
|
||||
#ifndef RT_WLAN_WORKQUEUE_THREAD_PRIO
|
||||
#define RT_WLAN_WORKQUEUE_THREAD_PRIO (20)
|
||||
#endif
|
||||
|
||||
int rt_wlan_workqueue_init(void);
|
||||
|
||||
rt_err_t rt_wlan_workqueue_dowork(void (*func)(void *parameter), void *parameter);
|
||||
|
||||
struct rt_workqueue *rt_wlan_get_workqueue(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user